content stringlengths 23 1.05M |
|---|
----------------------------------------------------------------------------
-- Permission to use, copy, modify, and distribute this software for any
-- purpose with or without fee is hereby granted, provided that the above
-- copyright notice and this permission notice appear in all copies.
--
-- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
-- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
-- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
-- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
-- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
----------------------------------------------------------------------------
with Interfaces.C; use Interfaces.C;
with Interfaces.C.Strings; use Interfaces.C.Strings;
package body AdaAugeas is
pragma Linker_Options ("-laugeas");
use Interfaces;
--
-- Close this Augeas instance and free any storage associated with it.
--
procedure Aug_Close (aug : Augeas_Type);
pragma Import (C, Aug_Close, "aug_close");
procedure Close (Aug : in out Augeas_Type) is
begin
if Aug /= Null_Augeas then
Aug_Close (Aug);
end if;
Aug := Null_Augeas;
end Close;
--
-- Copy the node SRC to DST.
-- 0 on success and -1 on failure.
--
function Aug_Cp
(Aug : Augeas_Type; src : chars_ptr; dst : chars_ptr)
return Interfaces.C.int;
pragma Import (C, Aug_Cp, "aug_cp");
function Copy (Aug : Augeas_Type; Src : String; Dst : String) return Integer
is
MySrc : chars_ptr := New_String (Src);
MyDst : chars_ptr := New_String (Dst);
Result : Interfaces.C.int;
begin
if Aug = Null_Augeas then
Free (MySrc);
Free (MyDst);
return -1;
end if;
Result := Aug_Cp (Aug, MySrc, MyDst);
Free (MySrc);
Free (MyDst);
return Integer (Result);
end Copy;
--
-- Lookup the value associated with PATH.
--
function Aug_Get
(aug : Augeas_Type; path : chars_ptr; value : access chars_ptr)
return int;
pragma Import (C, Aug_Get, "aug_get");
function Get (Aug : Augeas_Type; Path : String) return String is
MyPath : chars_ptr := New_String (Path);
Value_Ptr : aliased chars_ptr;
Result : Interfaces.C.int;
begin
if Aug = Null_Augeas then
Free (MyPath);
return "";
end if;
Result := Aug_Get (Aug, MyPath, Value_Ptr'Access);
Free (MyPath);
if Result <= 0 then
return "";
end if;
-- VALUE can be NULL.
if Value_Ptr = Null_Ptr then
return "";
else
return Value (Value_Ptr, Strlen (Value_Ptr));
end if;
end Get;
--
-- Initialize the library.
--
function Aug_Init
(root : chars_ptr; loadpath : chars_ptr; flag : aug_flags)
return Augeas_Type;
pragma Import (C, Aug_Init, "aug_init");
function Init
(Aug : out Augeas_Type; Root : String; Loadpath : String;
Flag : aug_flags) return Integer
is
MyRoot : chars_ptr := New_String (Root);
MyLoadpath : chars_ptr := New_String (Loadpath);
begin
Aug := Aug_Init (MyRoot, MyLoadpath, Flag);
Free (MyRoot);
Free (MyLoadpath);
if Aug = Null_Augeas then
return -1;
end if;
return 0;
end Init;
--
-- Match the number of matches of the path expression PATH in AUG.
--
function Aug_Match
(Aug : Augeas_Type; path : chars_ptr; matches : access Chars_Ptr_Ptr)
return Interfaces.C.int;
pragma Import (C, Aug_Match, "aug_match");
procedure Free_Chars_Ptr (Ptr : Chars_Ptr_Ptr) with
Import => True,
Convention => C,
External_Name => "free";
function Match
(Aug : Augeas_Type; Path : String) return String_Vectors.Vector
is
MyPath : chars_ptr := New_String (Path);
Array_Ptr : aliased Chars_Ptr_Ptr;
Match_Ptr : aliased Chars_Ptr_Ptr;
Result : Interfaces.C.int;
VString : String_Vectors.Vector;
begin
if Aug = Null_Augeas then
Free (MyPath);
return VString;
end if;
--
-- If MATCHES is non-NULL, an array with the returned
-- number of elements will be allocated and filled with
-- the paths of the matches. The caller must free both
-- the array and the entries in it.
--
Result := Aug_Match (Aug, MyPath, Match_Ptr'Access);
Free (MyPath);
if Result > 0 then
Array_Ptr := Match_Ptr;
for J in 0 .. Result - 1 loop
if Match_Ptr.all /= Interfaces.C.Strings.Null_Ptr then
VString.Append (Interfaces.C.Strings.Value (Match_Ptr.all));
Free (Match_Ptr.all);
end if;
Match_Pointer.Increment (Match_Ptr);
end loop;
Free_Chars_Ptr (Array_Ptr);
end if;
return VString;
end Match;
--
-- Move the node SRC to DST.
-- 0 on success and -1 on failure.
--
function Aug_Mv
(Aug : Augeas_Type; src : chars_ptr; dst : chars_ptr)
return Interfaces.C.int;
pragma Import (C, Aug_Mv, "aug_mv");
function Move (Aug : Augeas_Type; Src : String; Dst : String) return Integer
is
MySrc : chars_ptr := New_String (Src);
MyDst : chars_ptr := New_String (Dst);
Result : Interfaces.C.int;
begin
if Aug = Null_Augeas then
Free (MySrc);
Free (MyDst);
return -1;
end if;
Result := Aug_Mv (Aug, MySrc, MyDst);
Free (MySrc);
Free (MyDst);
return Integer (Result);
end Move;
--
-- Remove path and all its children.
-- Returns the number of entries removed.
--
function Aug_Rm
(Aug : Augeas_Type; path : chars_ptr) return Interfaces.C.int;
pragma Import (C, Aug_Rm, "aug_rm");
function Remove (Aug : Augeas_Type; Path : String) return Integer is
MyPath : chars_ptr := New_String (Path);
Result : Interfaces.C.int;
begin
if Aug = Null_Augeas then
Free (MyPath);
return -1;
end if;
Result := Aug_Rm (Aug, MyPath);
Free (MyPath);
return Integer (Result);
end Remove;
--
-- Write all pending changes to disk.
-- -1 if an error is encountered, 0 on success.
--
function Aug_Save (Aug : Augeas_Type) return Interfaces.C.int;
pragma Import (C, Aug_Save, "aug_save");
function Save (Aug : Augeas_Type) return Integer is
Result : Interfaces.C.int;
begin
if Aug = Null_Augeas then
return -1;
end if;
Result := Aug_Save (Aug);
return Integer (Result);
end Save;
--
-- Set the value associated with PATH to VALUE.
-- Neec check: The string *VALUE must not be freed by the caller,
-- and is valid as long as its node remains unchanged.
--
function Aug_Set
(Aug : Augeas_Type; path : chars_ptr; value : chars_ptr)
return Interfaces.C.int;
pragma Import (C, Aug_Set, "aug_set");
function Set
(Aug : Augeas_Type; Path : String; Value : String) return Integer
is
MyPath : chars_ptr := New_String (Path);
MyValue : chars_ptr := New_String (Value);
Result : Interfaces.C.int;
begin
if Aug = Null_Augeas then
Free (MyPath);
Free (MyValue);
return -1;
end if;
Result := Aug_Set (Aug, MyPath, MyValue);
Free (MyPath);
Free (MyValue);
return Integer (Result);
end Set;
--
-- Set the value associated with PATH to VALUE.
-- Neec check: The string *VALUE must not be freed by the caller,
-- and is valid as long as its node remains unchanged.
--
function Aug_Setm
(Aug : Augeas_Type; base : chars_ptr; sub : chars_ptr; value : chars_ptr)
return Interfaces.C.int;
pragma Import (C, Aug_Setm, "aug_setm");
function Setm
(Aug : Augeas_Type; Base : String; Sub : String; Value : String)
return Integer
is
MyBase : chars_ptr := New_String (Base);
MySub : chars_ptr := New_String (Sub);
MyValue : chars_ptr := New_String (Value);
Result : Interfaces.C.int;
begin
if Aug = Null_Augeas then
Free (MyBase);
Free (MySub);
Free (MyValue);
return -1;
end if;
Result := Aug_Setm (Aug, MyBase, MySub, MyValue);
Free (MyBase);
Free (MySub);
Free (MyValue);
return Integer (Result);
end Setm;
begin
begin
null;
end;
end AdaAugeas;
|
-- part of OpenGLAda, (c) 2017 Felix Krause
-- released under the terms of the MIT license, see the file "COPYING"
with GL.Enums.Textures;
with GL.Helpers;
with GL.API;
package body GL.Fixed.Textures is
procedure Set_Tex_Function (Func : Texture_Function) is
begin
API.Tex_Env_Tex_Func (Enums.Textures.Texture_Env, Enums.Textures.Env_Mode,
Func);
Raise_Exception_On_OpenGL_Error;
end Set_Tex_Function;
function Tex_Function return Texture_Function is
Ret : Texture_Function := Texture_Function'Val (0);
begin
API.Get_Tex_Env_Tex_Func (Enums.Textures.Texture_Env, Enums.Textures.Env_Mode,
Ret);
Raise_Exception_On_OpenGL_Error;
return Ret;
end Tex_Function;
procedure Set_RGB_Combine (Func : Combine_Function) is
begin
API.Tex_Env_Combine_Func (Enums.Textures.Texture_Env, Enums.Textures.Combine_RGB,
Func);
Raise_Exception_On_OpenGL_Error;
end Set_RGB_Combine;
function RGB_Combine return Combine_Function is
Ret : Combine_Function := Combine_Function'Val (0);
begin
API.Get_Tex_Env_Combine_Func (Enums.Textures.Texture_Env,
Enums.Textures.Combine_RGB, Ret);
Raise_Exception_On_OpenGL_Error;
return Ret;
end RGB_Combine;
procedure Set_Alpha_Combine (Func : Alpha_Combine_Function) is
begin
API.Tex_Env_Combine_Func (Enums.Textures.Texture_Env,
Enums.Textures.Combine_Alpha, Func);
Raise_Exception_On_OpenGL_Error;
end Set_Alpha_Combine;
function Alpha_Combine return Alpha_Combine_Function is
Ret : Combine_Function := Combine_Function'Val (0);
begin
API.Get_Tex_Env_Combine_Func (Enums.Textures.Texture_Env,
Enums.Textures.Combine_Alpha, Ret);
Raise_Exception_On_OpenGL_Error;
return Ret;
end Alpha_Combine;
procedure Set_RGB_Source (Source : Source_Kind; Index : Source_Index) is
Param : Enums.Textures.Env_Parameter;
begin
case Index is
when 0 => Param := Enums.Textures.Src0_RGB;
when 1 => Param := Enums.Textures.Src1_RGB;
when 2 => Param := Enums.Textures.Src2_RGB;
end case;
API.Tex_Env_Source (Enums.Textures.Texture_Env, Param, Source);
Raise_Exception_On_OpenGL_Error;
end Set_RGB_Source;
function RGB_Source (Index : Source_Index) return Source_Kind is
Param : Enums.Textures.Env_Parameter;
Ret : Source_Kind := Source_Kind'Val (0);
begin
case Index is
when 0 => Param := Enums.Textures.Src0_RGB;
when 1 => Param := Enums.Textures.Src1_RGB;
when 2 => Param := Enums.Textures.Src2_RGB;
end case;
API.Get_Tex_Env_Source (Enums.Textures.Texture_Env, Param, Ret);
Raise_Exception_On_OpenGL_Error;
return Ret;
end RGB_Source;
procedure Set_Alpha_Source (Source : Source_Kind; Index : Source_Index) is
Param : Enums.Textures.Env_Parameter;
begin
case Index is
when 0 => Param := Enums.Textures.Src0_Alpha;
when 1 => Param := Enums.Textures.Src1_Alpha;
when 2 => Param := Enums.Textures.Src2_Alpha;
end case;
API.Tex_Env_Source (Enums.Textures.Texture_Env, Param, Source);
Raise_Exception_On_OpenGL_Error;
end Set_Alpha_Source;
function Alpha_Source (Index : Source_Index) return Source_Kind is
Param : Enums.Textures.Env_Parameter;
Ret : Source_Kind := Source_Kind'Val (0);
begin
case Index is
when 0 => Param := Enums.Textures.Src0_Alpha;
when 1 => Param := Enums.Textures.Src1_Alpha;
when 2 => Param := Enums.Textures.Src2_Alpha;
end case;
API.Get_Tex_Env_Source (Enums.Textures.Texture_Env, Param, Ret);
Raise_Exception_On_OpenGL_Error;
return Ret;
end Alpha_Source;
procedure Set_RGB_Scale (Value : Scaling_Factor) is
begin
API.Tex_Env_Float (Enums.Textures.Texture_Env,
Enums.Textures.RGB_Scale, Single (Value));
Raise_Exception_On_OpenGL_Error;
end Set_RGB_Scale;
function RGB_Scale return Scaling_Factor is
Ret : Single := 0.0;
begin
API.Get_Tex_Env_Float (Enums.Textures.Texture_Env,
Enums.Textures.RGB_Scale, Ret);
Raise_Exception_On_OpenGL_Error;
return Double (Ret);
end RGB_Scale;
procedure Set_Alpha_Scale (Value : Scaling_Factor) is
begin
API.Tex_Env_Float (Enums.Textures.Texture_Env,
Enums.Textures.Alpha_Scale, Single (Value));
Raise_Exception_On_OpenGL_Error;
end Set_Alpha_Scale;
function Alpha_Scale return Scaling_Factor is
Ret : Single := 0.0;
begin
API.Get_Tex_Env_Float (Enums.Textures.Texture_Env,
Enums.Textures.Alpha_Scale, Ret);
Raise_Exception_On_OpenGL_Error;
return Double (Ret);
end Alpha_Scale;
procedure Set_LoD_Bias (Value : Double) is
begin
API.Tex_Env_Float (Enums.Textures.Filter_Control,
Enums.Textures.LoD_Bias, Single (Value));
Raise_Exception_On_OpenGL_Error;
end Set_LoD_Bias;
function LoD_Bias return Double is
Ret : Single := 0.0;
begin
API.Get_Tex_Env_Float (Enums.Textures.Filter_Control,
Enums.Textures.LoD_Bias, Ret);
Raise_Exception_On_OpenGL_Error;
return Double (Ret);
end LoD_Bias;
procedure Set_Env_Color (Value : Colors.Color) is
Float_Colors : constant Single_Array
:= Helpers.Float_Array (Value);
begin
API.Tex_Env_Arr (Enums.Textures.Texture_Env,
Enums.Textures.Env_Color, Float_Colors);
Raise_Exception_On_OpenGL_Error;
end Set_Env_Color;
function Env_Color return Colors.Color is
Ret : Single_Array (1 .. 4);
begin
API.Get_Tex_Env_Arr (Enums.Textures.Texture_Env,
Enums.Textures.Env_Color, Ret);
Raise_Exception_On_OpenGL_Error;
return Helpers.Color (Ret);
end Env_Color;
procedure Toggle_Point_Sprite_Coord_Replace (Enabled : Boolean) is
begin
API.Tex_Env_Bool (Enums.Textures.Point_Sprite,
Enums.Textures.Coord_Replace, Low_Level.Bool (Enabled));
Raise_Exception_On_OpenGL_Error;
end Toggle_Point_Sprite_Coord_Replace;
function Point_Sprite_Coord_Replace return Boolean is
Ret : Low_Level.Bool := Low_Level.False;
begin
API.Get_Tex_Env_Bool (Enums.Textures.Point_Sprite,
Enums.Textures.Coord_Replace, Ret);
Raise_Exception_On_OpenGL_Error;
return Boolean (Ret);
end Point_Sprite_Coord_Replace;
end GL.Fixed.Textures;
|
with Ada.Containers.Indefinite_Ordered_Sets;
package String_Sets is new Ada.Containers.Indefinite_Ordered_Sets
(Element_Type => String);
|
procedure All_Source_Text is
beGin
Some_Code;
-- Both branches of the #if have a style violation (extra space before
-- semicolon) that must be reported.
#if Some_Condition then
Do_Something ;
#else
Do_Something_else ;
#end if;
Some_More_Code;
end All_Source_Text;
|
-- Copyright (C) 2019 Thierry Rascle <thierr26@free.fr>
-- MIT license. Please refer to the LICENSE file.
package body Apsepp.Generic_Fixture is
-- Default_Allocator is referenced by Creator child package only.
pragma Unreferenced (Default_Allocator);
----------------------------------------------------------------------------
function Instance return Fixture_Type_Access
is (Fixture_Type_Access (Shared_Instance.Instance));
----------------------------------------------------------------------------
end Apsepp.Generic_Fixture;
|
-- { dg-do compile }
-- { dg-options "-O" }
package body Slice2 is
function F (I : R1) return R2 is
Val : R2;
begin
Val.Text (1 .. 8) := I.Text (1 .. 8);
return Val;
end F;
end Slice2;
|
with Ada.Containers.Vectors;
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
procedure OneTwo is
package Seen_Vecs is new Ada.Containers.Vectors(Element_Type => Integer, Index_Type => Natural);
use Seen_Vecs;
Position : Seen_Vecs.Cursor;
SeenFrequencies : Seen_Vecs.Vector;
ResultFrequency : Integer := 0;
CurrentFrequency : Integer := 0;
InputFile : File_Type;
FileName : String := "input.txt";
Found : Boolean := False;
begin
loop
Seen_Vecs.Append(SeenFrequencies, 0);
begin
Open(File => InputFile, Mode => In_File, Name => FileName);
loop
Get(File => InputFile, Item => CurrentFrequency);
ResultFrequency := ResultFrequency + CurrentFrequency;
Position := Seen_Vecs.First(SeenFrequencies);
if Seen_Vecs.Contains(SeenFrequencies, ResultFrequency) then
Put(ResultFrequency);
Found := True;
exit;
end if;
exit when End_Of_File(File => InputFile);
Seen_Vecs.Append(SeenFrequencies, ResultFrequency);
Skip_Line(File => InputFile);
end loop;
end;
Close(File => InputFile);
exit when Found;
end loop;
end OneTwo; |
package eGL.Pointers
is
type Display_Pointer is access all eGL.Display;
type NativeWindowType_Pointer is access all eGL.NativeWindowType;
type NativePixmapType_Pointer is access all eGL.NativePixmapType;
type EGLint_Pointer is access all eGL.EGLint;
type EGLBoolean_Pointer is access all eGL.EGLBoolean;
type EGLenum_Pointer is access all eGL.EGLenum;
type EGLConfig_Pointer is access all eGL.EGLConfig;
type EGLContext_Pointer is access all eGL.EGLContext;
type EGLDisplay_Pointer is access all eGL.EGLDisplay;
type EGLSurface_Pointer is access all eGL.EGLSurface;
type EGLClientBuffer_Pointer is access all eGL.EGLClientBuffer;
type Display_Pointer_array is array (C.size_t range <>) of aliased Display_Pointer;
type NativeWindowType_Pointer_array is array (C.size_t range <>) of aliased NativeWindowType_Pointer;
type NativePixmapType_Pointer_array is array (C.size_t range <>) of aliased NativePixmapType_Pointer;
type EGLint_Pointer_array is array (C.size_t range <>) of aliased EGLint_Pointer;
type EGLBoolean_Pointer_array is array (C.size_t range <>) of aliased EGLBoolean_Pointer;
type EGLenum_Pointer_array is array (C.size_t range <>) of aliased EGLenum_Pointer;
type EGLConfig_Pointer_array is array (C.size_t range <>) of aliased EGLConfig_Pointer;
type EGLContext_Pointer_array is array (C.size_t range <>) of aliased EGLContext_Pointer;
type EGLDisplay_Pointer_array is array (C.size_t range <>) of aliased EGLDisplay_Pointer;
type EGLSurface_Pointer_array is array (C.size_t range <>) of aliased EGLSurface_Pointer;
type EGLClientBuffer_Pointer_array is array (C.size_t range <>) of aliased EGLClientBuffer_Pointer;
end eGL.Pointers;
|
pragma License (Unrestricted);
-- runtime unit
with System.Long_Long_Integer_Types;
package System.Formatting is
pragma Pure;
subtype Number_Base is Integer range 2 .. 16; -- same as Text_IO.Number_Base
subtype Digit is Integer range 0 .. 15;
type Type_Set is (Lower_Case, Upper_Case); -- same as Text_IO.Type_Set
pragma Discard_Names (Type_Set);
function Digits_Width (
Value : Long_Long_Integer_Types.Word_Unsigned;
Base : Number_Base := 10)
return Positive;
function Digits_Width (
Value : Long_Long_Integer_Types.Long_Long_Unsigned;
Base : Number_Base := 10)
return Positive;
procedure Image (
Value : Digit;
Item : out Character;
Set : Type_Set := Upper_Case);
procedure Image (
Value : Long_Long_Integer_Types.Word_Unsigned;
Item : out String;
Last : out Natural;
Base : Number_Base := 10;
Set : Type_Set := Upper_Case;
Width : Positive := 1;
Fill : Character := '0';
Error : out Boolean);
procedure Image (
Value : Long_Long_Integer_Types.Long_Long_Unsigned;
Item : out String;
Last : out Natural;
Base : Number_Base := 10;
Set : Type_Set := Upper_Case;
Width : Positive := 1;
Fill : Character := '0';
Error : out Boolean);
procedure Value (
Item : Character;
Result : out Digit;
Error : out Boolean);
procedure Value (
Item : String;
Last : out Natural;
Result : out Long_Long_Integer_Types.Word_Unsigned;
Base : Number_Base := 10;
Skip_Underscore : Boolean := False;
Error : out Boolean);
procedure Value (
Item : String;
Last : out Natural;
Result : out Long_Long_Integer_Types.Long_Long_Unsigned;
Base : Number_Base := 10;
Skip_Underscore : Boolean := False;
Error : out Boolean);
-- sign marks, compatible with Ada.Formatting
type Sign_Marks is record
Minus, Zero, Plus : Character;
end record;
for Sign_Marks'Size use Character'Size * 4;
pragma Suppress_Initialization (Sign_Marks);
No_Sign : constant Character := Character'Val (16#ff#);
-- Note: Literals of array of Character make undesirable static strings.
-- Literals of word-size record can be expected to be immediate values.
-- utility
procedure Fill_Padding (Item : out String; Pad : Character);
end System.Formatting;
|
------------------------------------------------------------------------------
-- --
-- GNAT RUN-TIME LIBRARY (GNARL) COMPONENTS --
-- --
-- A D A . I N T E R R U P T S . N A M E S --
-- --
-- S p e c --
-- --
-- Copyright (C) 1991-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/>. --
-- --
-- GNARL was developed by the GNARL team at Florida State University. --
-- Extensive contributions were provided by Ada Core Technologies, Inc. --
-- --
------------------------------------------------------------------------------
-- This is the version for Cortex R4F TMS570 targets
-- See Table 4-3 in the TMS570LS3137 datasheet, TI document SPNS162A.
package Ada.Interrupts.Names is
-- All identifiers in this unit are implementation defined
pragma Implementation_Defined;
RTI_Compare_Interrupt_0 : constant Interrupt_ID := 2;
RTI_Compare_Interrupt_1 : constant Interrupt_ID := 3;
RTI_Compare_Interrupt_2 : constant Interrupt_ID := 4;
RTI_Compare_Interrupt_3 : constant Interrupt_ID := 5;
RTI_Overflow_Interrupt_0 : constant Interrupt_ID := 6;
RTI_Overflow_Interrupt_1 : constant Interrupt_ID := 7;
RTI_Timebase_Interrupt : constant Interrupt_ID := 8;
GIO_High_Level_Interrupt : constant Interrupt_ID := 9;
N2HET1_Level_0_Interrupt : constant Interrupt_ID := 10;
HET_TU1_Level_0_Interrupt : constant Interrupt_ID := 11;
MIBSPI1_Level_0_Interrupt : constant Interrupt_ID := 12;
LIN_Level_0_Interrupt : constant Interrupt_ID := 13;
MIBADC1_Event_Group_Interrupt : constant Interrupt_ID := 14;
MIBADC1_SW_Group_1_Interrupt : constant Interrupt_ID := 15;
DCAN1_Level_0_Interrupt : constant Interrupt_ID := 16;
SPI2_Level_0_Interrupt : constant Interrupt_ID := 17;
FlexRay_Level_0_Interrupt : constant Interrupt_ID := 18;
CRC_Interrupt : constant Interrupt_ID := 19;
ESM_Low_Level_Interrupt : constant Interrupt_ID := 20;
Software_Interrupt : constant Interrupt_ID := 21;
PMU_Interrupt : constant Interrupt_ID := 22;
GIO_Low_Level_Interrupt : constant Interrupt_ID := 23;
N2HET1_Level_1_Interrupt : constant Interrupt_ID := 24;
HET_TU1_Level_1_Interrupt : constant Interrupt_ID := 25;
MIBSPI1_Level_1_Interrupt : constant Interrupt_ID := 26;
LIN_Level_1_Interrupt : constant Interrupt_ID := 27;
MIBADC1_SW_Group_2_Interrupt : constant Interrupt_ID := 28;
DCAN1_Level_1_Interrupt : constant Interrupt_ID := 29;
SPI2_Level_1_Interrupt : constant Interrupt_ID := 30;
MIBADC1_Magnitude_Compare_Interrupt : constant Interrupt_ID := 31;
FlexRay_Level_1_Interrupt : constant Interrupt_ID := 32;
FTCA_Interrupt : constant Interrupt_ID := 33;
LFSA_Interrupt : constant Interrupt_ID := 34;
DCAN2_Level_0_Interrupt : constant Interrupt_ID := 35;
DMM_Level_0_Interrupt : constant Interrupt_ID := 36;
MIBSPI3_Level_0_Interrupt : constant Interrupt_ID := 37;
MIBSPI3_Level_1_Interrupt : constant Interrupt_ID := 38;
HBCA_Interrupt : constant Interrupt_ID := 39;
BTCA_Interrupt : constant Interrupt_ID := 40;
AEMIFINT3 : constant Interrupt_ID := 41;
DCAN2_Level_1_Interrupt : constant Interrupt_ID := 42;
DMM_Level_1_Interrupt : constant Interrupt_ID := 43;
DCAN1_IF3_Interrupt : constant Interrupt_ID := 44;
DCAN3_Level_0_Interrupt : constant Interrupt_ID := 45;
DCAN2_IF3_Interrupt : constant Interrupt_ID := 46;
FPU_Interrupt : constant Interrupt_ID := 47;
FlexRay_TU_Transfer_Status_Interrupt : constant Interrupt_ID := 48;
SPI4_Level_0_Interrupt : constant Interrupt_ID := 49;
MIBADC2_Event_Group_Interrupt : constant Interrupt_ID := 50;
MIBADC2_SW_Group_1_Interrupt : constant Interrupt_ID := 51;
FlexRay_T0C_Interrupt : constant Interrupt_ID := 52;
MIBSPI5_Level_0_Interrupt : constant Interrupt_ID := 53;
SPI4_Level_1_Interrupt : constant Interrupt_ID := 54;
DCAN3_Level_1_Interrupt : constant Interrupt_ID := 55;
MIBSPI5_Level_1_Interrupt : constant Interrupt_ID := 56;
MIBADC2_SW_Group_2_Interrupt : constant Interrupt_ID := 57;
FlexRay_TU_Error_Interrupt : constant Interrupt_ID := 58;
MIBADC2_Magnitude_Compare_Interrupt : constant Interrupt_ID := 59;
DCAN3_IF3_Interrupt : constant Interrupt_ID := 60;
FSM_Done_Interrupt : constant Interrupt_ID := 61;
FlexRay_T1C_Interrupt : constant Interrupt_ID := 62;
NHET2_Level_0_Interrupt : constant Interrupt_ID := 63;
SCI_Level_0_Interrupt : constant Interrupt_ID := 64;
HET_TU2_Level_0_Interrupt : constant Interrupt_ID := 65;
I2C_Level_0_Interrupt : constant Interrupt_ID := 66;
N2HET2_Level_1_Interrupt : constant Interrupt_ID := 73;
SCI_Level_1_Interrupt : constant Interrupt_ID := 74;
HET_TU2_Level_1_Interrupt : constant Interrupt_ID := 75;
C0_Misc_Pulse_Interrupt : constant Interrupt_ID := 76;
C0_Tx_Pulse_Interrupt : constant Interrupt_ID := 77;
C0_Thresh_Pulse_Interrupt : constant Interrupt_ID := 78;
C0_RX_Pulse_Interrupt : constant Interrupt_ID := 79;
HWAG1_Int_Req_H_Interrupt : constant Interrupt_ID := 80;
HWAG2_Int_Req_H_Interrupt : constant Interrupt_ID := 81;
DCC_Done_Interrupt : constant Interrupt_ID := 82;
DCC2_Done_Interrupt : constant Interrupt_ID := 83;
HWAG1_Int_Req_L_Interrupt : constant Interrupt_ID := 88;
HWAG2_Int_Req_L_Interrupt : constant Interrupt_ID := 89;
end Ada.Interrupts.Names;
|
------------------------------------------------------------------------------
-- --
-- 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. --
-- --
------------------------------------------------------------------------------
package body CS43L22 is
---------------
-- I2C_Write --
---------------
procedure I2C_Write (This : in out CS43L22_Device;
Reg : UInt8;
Value : UInt8)
is
Status : I2C_Status with Unreferenced;
begin
This.Port.Mem_Write
(Addr => CS43L22_I2C_Addr,
Mem_Addr => UInt16 (Reg),
Mem_Addr_Size => Memory_Size_8b,
Data => (1 => Value),
Status => Status);
end I2C_Write;
--------------
-- I2C_Read --
--------------
function I2C_Read (This : in out CS43L22_Device;
Reg : UInt8)
return UInt8
is
Status : I2C_Status;
Data : I2C_Data (1 .. 1);
begin
This.Port.Mem_Read
(Addr => CS43L22_I2C_Addr,
Mem_Addr => UInt16 (Reg),
Mem_Addr_Size => Memory_Size_8b,
Data => Data,
Status => Status);
return Data (1);
end I2C_Read;
----------
-- Init --
----------
procedure Init
(This : in out CS43L22_Device;
Output : Output_Device;
Volume : Volume_Level;
Frequency : Audio_Frequency)
is
pragma Unreferenced (Frequency);
begin
-- Codec set to power OFF
This.I2C_Write (CS43L22_REG_POWER_CTL1, 16#01#);
-- Save output device for mute ON/OFF procedure
This.Set_Output_Mode (Output);
-- Clock configuration: auto detection
This.I2C_Write (CS43L22_REG_CLOCKING_CTL, 16#81#);
-- Set the Slave Mode and the audio Standard
This.I2C_Write (CS43L22_REG_INTERFACE_CTL1, 16#04#);
-- Set the Master volume */
This.Set_Volume (Volume);
-- If the Speaker is enabled, set the Mono mode and volume attenuation
-- level
if (Output /= Headphone) then
-- Set the Speaker Mono mode
This.I2C_Write (CS43L22_REG_PLAYBACK_CTL2, 16#06#);
-- Set the Speaker attenuation level
This.I2C_Write (CS43L22_REG_SPEAKER_A_VOL, 16#00#);
This.I2C_Write (CS43L22_REG_SPEAKER_B_VOL, 16#00#);
end if;
-- Additional configuration for the CODEC. These configurations are
-- done to reduce the time needed for the Codec to power off. If these
-- configurations are removed, then a long delay should be added between
-- powering off the Codec and switching off the I2S peripheral MCLK
-- clock (which is the operating clock for Codec).
-- If this delay is not inserted, then the codec will not shut down
-- properly and it results in high noise after shut down.
-- Disable the analog soft ramp
This.I2C_Write (CS43L22_REG_ANALOG_ZC_SR_SETT, 16#00#);
-- Disable the digital soft ramp
This.I2C_Write (CS43L22_REG_MISC_CTL, 16#04#);
-- Disable the limiter attack level
This.I2C_Write (CS43L22_REG_LIMIT_CTL1, 16#00#);
-- Adjust Bass and Treble levels */
This.I2C_Write (CS43L22_REG_TONE_CTL, 16#0F#);
-- Adjust PCM volume level */
This.I2C_Write (CS43L22_REG_PCMA_VOL, 16#0A#);
This.I2C_Write (CS43L22_REG_PCMB_VOL, 16#0A#);
end Init;
-------------
-- Read_ID --
-------------
function Read_ID (This : in out CS43L22_Device) return UInt8 is
begin
return This.I2C_Read (CS43L22_REG_ID) and CS43L22_ID_MASK;
end Read_ID;
----------
-- Play --
----------
procedure Play (This : in out CS43L22_Device) is
begin
if not This.Output_Enabled then
-- Enable the digital soft ramp
This.I2C_Write (CS43L22_REG_MISC_CTL, 16#06#);
-- Enable output device
This.Set_Mute (Mute_Off);
-- Power on the Codec
This.I2C_Write (CS43L22_REG_POWER_CTL1, 16#9E#);
This.Output_Enabled := True;
end if;
end Play;
-----------
-- Pause --
-----------
procedure Pause (This : in out CS43L22_Device) is
begin
-- Pause the audio playing
This.Set_Mute (Mute_On);
-- CODEC in powersave mode
This.I2C_Write (CS43L22_REG_POWER_CTL1, 16#01#);
end Pause;
------------
-- Resume --
------------
procedure Resume (This : in out CS43L22_Device) is
begin
-- Unmute the output first
This.Set_Mute (Mute_Off);
This.Time.Delay_Milliseconds (1);
This.I2C_Write (CS43L22_REG_POWER_CTL2, This.Output_Dev);
-- Exit the power save mode
This.I2C_Write (CS43L22_REG_POWER_CTL1, 16#9E#);
end Resume;
----------
-- Stop --
----------
procedure Stop (This : in out CS43L22_Device) is
begin
if This.Output_Enabled then
-- Mute the output first
This.Set_Mute (Mute_On);
-- Disable the digital soft ramp
This.I2C_Write (CS43L22_REG_MISC_CTL, 16#04#);
-- Power down the DAC and the speaker
This.I2C_Write (CS43L22_REG_POWER_CTL1, 16#9F#);
This.Output_Enabled := False;
end if;
end Stop;
----------------
-- Set_Volume --
----------------
procedure Set_Volume (This : in out CS43L22_Device; Volume : Volume_Level)
is
-- Actual Volume in range 0 .. 16#3F#
Converted_Volume : UInt8 :=
UInt8 (UInt16 (Volume) * 200 / 100);
begin
-- range goes the following:
-- 0 dB .. +12 dB: coded from 0 to 24
-- -102 dB .. -0.5 dB: coded from 52 to 255
-- -102 dB: applied for values in range 25 .. 52
-- so we have a valid range of volume from -102 to +12 in steps of 0.5
-- which means 225 significant values
-- 200 .. 224 for positive dB
-- 0 .. 199 for negative dB
-- However positive values may lead to saturated output. We thus limit
-- the volume to the -102 .. 0dB range
if Converted_Volume >= 200 then
Converted_Volume := Converted_Volume - 200;
else
Converted_Volume := Converted_Volume + 52;
end if;
This.I2C_Write (CS43L22_REG_MASTER_A_VOL, Converted_Volume);
This.I2C_Write (CS43L22_REG_MASTER_B_VOL, Converted_Volume);
end Set_Volume;
--------------
-- Set_Mute --
--------------
procedure Set_Mute (This : in out CS43L22_Device; Cmd : Mute) is
begin
if This.Output_Enabled then
case Cmd is
when Mute_On =>
This.I2C_Write (CS43L22_REG_POWER_CTL2, 16#FF#);
This.I2C_Write (CS43L22_REG_HEADPHONE_A_VOL, 16#01#);
This.I2C_Write (CS43L22_REG_HEADPHONE_B_VOL, 16#01#);
when Mute_Off =>
This.I2C_Write (CS43L22_REG_HEADPHONE_A_VOL, 16#00#);
This.I2C_Write (CS43L22_REG_HEADPHONE_B_VOL, 16#00#);
This.I2C_Write (CS43L22_REG_POWER_CTL2, This.Output_Dev);
end case;
end if;
end Set_Mute;
---------------------
-- Set_Output_Mode --
---------------------
procedure Set_Output_Mode (This : in out CS43L22_Device;
Device : Output_Device)
is
begin
case Device is
when No_Output =>
This.Output_Dev := 0;
when Speaker =>
This.Output_Dev := 16#FA#;
when Headphone =>
This.Output_Dev := 16#AF#;
when Both =>
This.Output_Dev := 16#AA#;
when Auto =>
This.Output_Dev := 16#05#;
end case;
This.I2C_Write (CS43L22_REG_POWER_CTL2, This.Output_Dev);
end Set_Output_Mode;
-------------------
-- Set_Frequency --
-------------------
procedure Set_Frequency (This : in out CS43L22_Device;
Freq : Audio_Frequency)
is
pragma Unreferenced (This, Freq);
begin
-- CODEC is automatically detecting the frequency. No need to do
-- anything here.
null;
end Set_Frequency;
-----------
-- Reset --
-----------
procedure Reset (This : in out CS43L22_Device)
is
pragma Unreferenced (This);
begin
null;
end Reset;
end CS43L22;
|
-----------------------------------------------------------------------
-- util-events-timers -- Timer list management
-- Copyright (C) 2017 Stephane Carrez
-- Written by Stephane Carrez (Stephane.Carrez@gmail.com)
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-----------------------------------------------------------------------
with Ada.Real_Time;
with Ada.Exceptions;
private with Ada.Finalization;
private with Util.Concurrent.Counters;
-- == Timer Management ==
-- The <tt>Util.Events.Timers</tt> package provides a timer list that allows to have
-- operations called on regular basis when a deadline has expired. It is very close to
-- the <tt>Ada.Real_Time.Timing_Events</tt> package but it provides more flexibility
-- by allowing to have several timer lists that run independently. Unlike the GNAT
-- implementation, this timer list management does not use tasks at all. The timer list
-- can therefore be used in a mono-task environment by the main process task. Furthermore
-- you can control your own task priority by having your own task that uses the timer list.
--
-- The timer list is created by an instance of <tt>Timer_List</tt>:
--
-- Manager : Util.Events.Timers.Timer_List;
--
-- The timer list is protected against concurrent accesses so that timing events can be
-- setup by a task but the timer handler is executed by another task.
--
-- === Timer Creation ===
-- A timer handler is defined by implementing the <tt>Timer</tt> interface with the
-- <tt>Time_Handler</tt> procedure. A typical timer handler could be declared as follows:
--
-- type Timeout is new Timer with null record;
-- overriding procedure Time_Handler (T : in out Timeout);
--
-- My_Timeout : aliased Timeout;
--
-- The timer instance is represented by the <tt>Timer_Ref</tt> type that describes the handler
-- to be called as well as the deadline time. The timer instance is initialized as follows:
--
-- T : Util.Events.Timers.Timer_Ref;
-- Manager.Set_Timer (T, My_Timeout'Access, Ada.Real_Time.Seconds (1));
--
-- === Timer Main Loop ===
-- Because the implementation does not impose any execution model, the timer management must
-- be called regularly by some application's main loop. The <tt>Process</tt> procedure
-- executes the timer handler that have ellapsed and it returns the deadline to wait for the
-- next timer to execute.
--
-- Deadline : Ada.Real_Time.Time;
-- loop
-- ...
-- Manager.Process (Deadline);
-- delay until Deadline;
-- end loop;
--
package Util.Events.Timers is
type Timer_Ref is tagged private;
-- The timer interface that must be implemented by applications.
type Timer is limited interface;
type Timer_Access is access all Timer'Class;
-- The timer handler executed when the timer deadline has passed.
procedure Time_Handler (T : in out Timer;
Event : in out Timer_Ref'Class) is abstract;
-- Repeat the timer.
procedure Repeat (Event : in out Timer_Ref;
In_Time : in Ada.Real_Time.Time_Span);
-- Cancel the timer.
procedure Cancel (Event : in out Timer_Ref);
-- Check if the timer is ready to be executed.
function Is_Scheduled (Event : in Timer_Ref) return Boolean;
-- Returns the deadline time for the timer execution.
-- Returns Time'Last if the timer is not scheduled.
function Time_Of_Event (Event : in Timer_Ref) return Ada.Real_Time.Time;
type Timer_List is tagged limited private;
-- Set a timer to be called at the given time.
procedure Set_Timer (List : in out Timer_List;
Handler : in Timer_Access;
Event : in out Timer_Ref'Class;
At_Time : in Ada.Real_Time.Time);
-- Set a timer to be called after the given time span.
procedure Set_Timer (List : in out Timer_List;
Handler : in Timer_Access;
Event : in out Timer_Ref'Class;
In_Time : in Ada.Real_Time.Time_Span);
-- Process the timer handlers that have passed the deadline and return the next
-- deadline. The <tt>Max_Count</tt> parameter allows to limit the number of timer handlers
-- that are called by operation. The default is not limited.
procedure Process (List : in out Timer_List;
Timeout : out Ada.Real_Time.Time;
Max_Count : in Natural := Natural'Last);
-- Procedure called when a timer handler raises an exception.
-- The default operation reports an error in the logs. This procedure can be
-- overriden to implement specific error handling.
procedure Error (List : in out Timer_List;
Handler : in Timer_Access;
E : in Ada.Exceptions.Exception_Occurrence);
private
type Timer_Manager;
type Timer_Manager_Access is access all Timer_Manager;
type Timer_Node;
type Timer_Node_Access is access all Timer_Node;
type Timer_Ref is new Ada.Finalization.Controlled with record
Value : Timer_Node_Access;
end record;
overriding
procedure Adjust (Object : in out Timer_Ref);
overriding
procedure Finalize (Object : in out Timer_Ref);
type Timer_Node is limited record
Next : Timer_Node_Access;
Prev : Timer_Node_Access;
List : Timer_Manager_Access;
Counter : Util.Concurrent.Counters.Counter := Util.Concurrent.Counters.ONE;
Handler : Timer_Access;
Deadline : Ada.Real_Time.Time;
end record;
protected type Timer_Manager is
-- Add a timer.
procedure Add (Timer : in Timer_Node_Access;
Deadline : in Ada.Real_Time.Time);
-- Cancel a timer.
procedure Cancel (Timer : in out Timer_Node_Access);
-- Find the next timer to be executed before the given time or return the next deadline.
procedure Find_Next (Before : in Ada.Real_Time.Time;
Deadline : out Ada.Real_Time.Time;
Timer : in out Timer_Ref);
private
List : Timer_Node_Access;
end Timer_Manager;
type Timer_List is new Ada.Finalization.Limited_Controlled with record
Manager : aliased Timer_Manager;
end record;
overriding
procedure Finalize (Object : in out Timer_List);
end Util.Events.Timers;
|
--------------------------------------------------------------------------------
-- Copyright (c) 2013, Felix Krause <contact@flyx.org>
--
-- Permission to use, copy, modify, and/or distribute this software for any
-- purpose with or without fee is hereby granted, provided that the above
-- copyright notice and this permission notice appear in all copies.
--
-- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
-- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
-- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
-- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
-- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
--------------------------------------------------------------------------------
with CL.Platforms;
with CL.Contexts;
with CL.Programs;
package CL.Kernels is
type Kernel is new Runtime_Object with null record;
type Kernel_List is array (Positive range <>) of Kernel;
package Constructors is
function Create (Source : Programs.Program'Class; Name : String) return Kernel;
function Create_All_In_Program (Source : Programs.Program'Class)
return Kernel_List;
end Constructors;
overriding procedure Adjust (Object : in out Kernel);
overriding procedure Finalize (Object : in out Kernel);
-- Only use the types declared in CL for Argument_Type.
-- Do not use with CL tagged types; use Set_Kernel_Argument_Object instead
generic
type Argument_Type is private;
Argument_Index : UInt;
procedure Set_Kernel_Argument (Target : Kernel; Value : Argument_Type);
procedure Set_Kernel_Argument_Object (Target : Kernel;
Index : UInt;
Value : Runtime_Object'Class);
function Function_Name (Source : Kernel) return String;
function Argument_Number (Source : Kernel) return UInt;
function Reference_Count (Source : Kernel) return UInt;
function Context (Source : Kernel) return Contexts.Context;
function Program (Source : Kernel) return Programs.Program;
function Work_Group_Size (Source : Kernel; Device : Platforms.Device)
return Size;
function Compile_Work_Group_Size (Source : Kernel; Device : Platforms.Device)
return Size_List;
function Local_Memory_Size (Source : Kernel; Device : Platforms.Device)
return ULong;
end CL.Kernels;
|
-----------------------------------------------------------------------
-- events-tests -- Unit tests for AWA events
-- Copyright (C) 2012 Stephane Carrez
-- Written by Stephane Carrez (Stephane.Carrez@gmail.com)
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-----------------------------------------------------------------------
with Util.Test_Caller;
with Util.Beans.Methods;
with Util.Log.Loggers;
with Util.Measures;
with Util.Concurrent.Counters;
with EL.Beans;
with EL.Expressions;
with EL.Contexts.Default;
with ASF.Applications;
with ASF.Servlets.Faces;
with AWA.Applications;
with AWA.Applications.Configs;
with AWA.Applications.Factory;
with AWA.Events.Action_Method;
with AWA.Services.Contexts;
with AWA.Events.Queues;
with AWA.Events.Services;
package body AWA.Events.Services.Tests is
use AWA.Events.Services;
use Util.Log;
Log : constant Loggers.Logger := Loggers.Create ("AWA.Events.Tests");
package Event_Test_4 is new AWA.Events.Definition (Name => "event-test-4");
package Event_Test_1 is new AWA.Events.Definition (Name => "event-test-1");
package Event_Test_3 is new AWA.Events.Definition (Name => "event-test-3");
package Event_Test_2 is new AWA.Events.Definition (Name => "event-test-2");
package Event_Test_5 is new AWA.Events.Definition (Name => "event-test-5");
package Caller is new Util.Test_Caller (Test, "Events.Tests");
procedure Add_Tests (Suite : in Util.Tests.Access_Test_Suite) is
begin
Caller.Add_Test (Suite, "Test AWA.Events.Get_Event_Name",
Test_Get_Event_Name'Access);
Caller.Add_Test (Suite, "Test AWA.Events.Find_Event_Index",
Test_Find_Event'Access);
Caller.Add_Test (Suite, "Test AWA.Events.Initialize",
Test_Initialize'Access);
Caller.Add_Test (Suite, "Test AWA.Events.Add_Action",
Test_Add_Action'Access);
Caller.Add_Test (Suite, "Test AWA.Events.Dispatch_Synchronous",
Test_Dispatch_Synchronous'Access);
Caller.Add_Test (Suite, "Test AWA.Events.Dispatch_Fifo",
Test_Dispatch_Fifo'Access);
Caller.Add_Test (Suite, "Test AWA.Events.Dispatch_Persist",
Test_Dispatch_Persist'Access);
Caller.Add_Test (Suite, "Test AWA.Events.Dispatch_Synchronous_Dyn",
Test_Dispatch_Synchronous_Dyn'Access);
Caller.Add_Test (Suite, "Test AWA.Events.Dispatch_Synchronous_Raise",
Test_Dispatch_Synchronous_Raise'Access);
end Add_Tests;
type Action_Bean is new Util.Beans.Basic.Bean
and Util.Beans.Methods.Method_Bean with record
Count : Natural := 0;
Priority : Integer := 0;
Raise_Exception : Boolean := False;
end record;
type Action_Bean_Access is access all Action_Bean'Class;
-- Get the value identified by the name.
-- If the name cannot be found, the method should return the Null object.
overriding
function Get_Value (From : in Action_Bean;
Name : in String) return Util.Beans.Objects.Object;
-- Set the value identified by the name.
-- If the name cannot be found, the method should raise the No_Value
-- exception.
overriding
procedure Set_Value (From : in out Action_Bean;
Name : in String;
Value : in Util.Beans.Objects.Object);
overriding
function Get_Method_Bindings (From : in Action_Bean)
return Util.Beans.Methods.Method_Binding_Array_Access;
procedure Event_Action (From : in out Action_Bean;
Event : in AWA.Events.Module_Event'Class);
function Create_Action_Bean return Util.Beans.Basic.Readonly_Bean_Access;
package Event_Action_Binding is
new AWA.Events.Action_Method.Bind (Bean => Action_Bean,
Method => Event_Action,
Name => "send");
Binding_Array : aliased constant Util.Beans.Methods.Method_Binding_Array
:= (1 => Event_Action_Binding.Proxy'Access);
-- ------------------------------
-- Get the value identified by the name.
-- If the name cannot be found, the method should return the Null object.
-- ------------------------------
overriding
function Get_Value (From : in Action_Bean;
Name : in String) return Util.Beans.Objects.Object is
pragma Unreferenced (From, Name);
begin
return Util.Beans.Objects.Null_Object;
end Get_Value;
-- ------------------------------
-- Set the value identified by the name.
-- If the name cannot be found, the method should raise the No_Value
-- exception.
-- ------------------------------
overriding
procedure Set_Value (From : in out Action_Bean;
Name : in String;
Value : in Util.Beans.Objects.Object) is
begin
if Name = "priority" then
From.Priority := Util.Beans.Objects.To_Integer (Value);
elsif Name = "raise_exception" then
From.Raise_Exception := Util.Beans.Objects.To_Boolean (Value);
end if;
end Set_Value;
overriding
function Get_Method_Bindings (From : in Action_Bean)
return Util.Beans.Methods.Method_Binding_Array_Access is
pragma Unreferenced (From);
begin
return Binding_Array'Access;
end Get_Method_Bindings;
Action_Exception : exception;
Global_Counter : Util.Concurrent.Counters.Counter;
procedure Event_Action (From : in out Action_Bean;
Event : in AWA.Events.Module_Event'Class) is
pragma Unreferenced (Event);
begin
if From.Raise_Exception then
raise Action_Exception with "Raising an exception from the event action bean";
end if;
From.Count := From.Count + 1;
Util.Concurrent.Counters.Increment (Global_Counter);
end Event_Action;
function Create_Action_Bean return Util.Beans.Basic.Readonly_Bean_Access is
Result : constant Action_Bean_Access := new Action_Bean;
begin
return Result.all'Access;
end Create_Action_Bean;
-- ------------------------------
-- Test searching an event name in the definition list.
-- ------------------------------
procedure Test_Find_Event (T : in out Test) is
begin
Util.Tests.Assert_Equals (T, Integer (Event_Test_4.Kind),
Integer (Find_Event_Index ("event-test-4")), "Find_Event");
Util.Tests.Assert_Equals (T, Integer (Event_Test_5.Kind),
Integer (Find_Event_Index ("event-test-5")), "Find_Event");
Util.Tests.Assert_Equals (T, Integer (Event_Test_1.Kind),
Integer (Find_Event_Index ("event-test-1")), "Find_Event");
end Test_Find_Event;
-- ------------------------------
-- Test the Get_Event_Type_Name internal operation.
-- ------------------------------
procedure Test_Get_Event_Name (T : in out Test) is
begin
Util.Tests.Assert_Equals (T, "event-test-1", Get_Event_Type_Name (Event_Test_1.Kind).all,
"Get_Event_Type_Name");
Util.Tests.Assert_Equals (T, "event-test-2", Get_Event_Type_Name (Event_Test_2.Kind).all,
"Get_Event_Type_Name");
Util.Tests.Assert_Equals (T, "event-test-3", Get_Event_Type_Name (Event_Test_3.Kind).all,
"Get_Event_Type_Name");
Util.Tests.Assert_Equals (T, "event-test-4", Get_Event_Type_Name (Event_Test_4.Kind).all,
"Get_Event_Type_Name");
Util.Tests.Assert_Equals (T, "event-test-5", Get_Event_Type_Name (Event_Test_5.Kind).all,
"Get_Event_Type_Name");
end Test_Get_Event_Name;
-- ------------------------------
-- Test creation and initialization of event manager.
-- ------------------------------
procedure Test_Initialize (T : in out Test) is
App : constant AWA.Applications.Application_Access := AWA.Tests.Get_Application;
Manager : Event_Manager;
begin
Manager.Initialize (App.all'Access);
T.Assert (Manager.Actions /= null, "Initialization failed");
end Test_Initialize;
-- ------------------------------
-- Test adding an action.
-- ------------------------------
procedure Test_Add_Action (T : in out Test) is
App : constant AWA.Applications.Application_Access := AWA.Tests.Get_Application;
Manager : Event_Manager;
Ctx : EL.Contexts.Default.Default_Context;
Action : constant EL.Expressions.Method_Expression
:= EL.Expressions.Create_Expression ("#{a.send}", Ctx);
Props : EL.Beans.Param_Vectors.Vector;
Queue : Queue_Ref;
Index : constant Event_Index := Find_Event_Index ("event-test-4");
begin
Manager.Initialize (App.all'Access);
Queue := AWA.Events.Queues.Create_Queue ("test", "fifo", Props, Ctx);
Manager.Add_Queue (Queue);
for I in 1 .. 10 loop
Manager.Add_Action (Event => "event-test-4",
Queue => Queue,
Action => Action,
Params => Props);
Util.Tests.Assert_Equals (T, 1, Integer (Manager.Actions (Index).Queues.Length),
"Add_Action failed");
end loop;
end Test_Add_Action;
-- ------------------------------
-- Test dispatching events
-- ------------------------------
procedure Dispatch_Event (T : in out Test;
Kind : in Event_Index;
Expect_Count : in Natural;
Expect_Prio : in Natural) is
Factory : AWA.Applications.Factory.Application_Factory;
Conf : ASF.Applications.Config;
Ctx : aliased EL.Contexts.Default.Default_Context;
Path : constant String := Util.Tests.Get_Test_Path ("regtests/config/event-test.xml");
Action : aliased Action_Bean;
begin
Conf.Set ("database", Util.Tests.Get_Parameter ("database"));
declare
App : aliased AWA.Tests.Test_Application;
S : Util.Measures.Stamp;
Faces : aliased ASF.Servlets.Faces.Faces_Servlet;
SC : AWA.Services.Contexts.Service_Context;
begin
App.Initialize (Conf => Conf,
Factory => Factory);
App.Set_Global ("event_test",
Util.Beans.Objects.To_Object (Action'Unchecked_Access,
Util.Beans.Objects.STATIC));
SC.Set_Context (App'Unchecked_Access, null);
App.Add_Servlet (Name => "faces", Server => Faces'Unchecked_Access);
App.Register_Class ("AWA.Events.Tests.Event_Action",
Create_Action_Bean'Access);
AWA.Applications.Configs.Read_Configuration (App => App,
File => Path,
Context => Ctx'Unchecked_Access);
Util.Measures.Report (S, "Initialize AWA application and read config");
App.Start;
Util.Measures.Report (S, "Start event tasks");
for I in 1 .. 100 loop
declare
Event : Module_Event;
begin
Event.Set_Event_Kind (Kind);
Event.Set_Parameter ("prio", "3");
Event.Set_Parameter ("template", "def");
App.Send_Event (Event);
end;
end loop;
Util.Measures.Report (S, "Send 100 events");
-- Wait for the dispatcher to process the events but do not wait more than 10 secs.
for I in 1 .. 10_000 loop
exit when Action.Count = Expect_Count;
delay 0.1;
end loop;
end;
Log.Info ("Action count: {0}", Natural'Image (Action.Count));
Log.Info ("Priority: {0}", Integer'Image (Action.Priority));
Util.Tests.Assert_Equals (T, Expect_Count, Action.Count,
"invalid number of calls for the action (global bean)");
Util.Tests.Assert_Equals (T, Expect_Prio, Action.Priority,
"prio parameter not transmitted (global bean)");
end Dispatch_Event;
-- ------------------------------
-- Test dispatching synchronous event to a global bean.
-- ------------------------------
procedure Test_Dispatch_Synchronous (T : in out Test) is
begin
T.Dispatch_Event (Event_Test_1.Kind, 500, 3);
end Test_Dispatch_Synchronous;
-- ------------------------------
-- Test dispatching event through a fifo queue.
-- ------------------------------
procedure Test_Dispatch_Fifo (T : in out Test) is
begin
T.Dispatch_Event (Event_Test_2.Kind, 200, 3);
end Test_Dispatch_Fifo;
-- ------------------------------
-- Test dispatching event through a database queue.
-- ------------------------------
procedure Test_Dispatch_Persist (T : in out Test) is
begin
T.Dispatch_Event (Event_Test_5.Kind, 100, 3);
end Test_Dispatch_Persist;
-- ------------------------------
-- Test dispatching synchronous event to a dynamic bean (created on demand).
-- ------------------------------
procedure Test_Dispatch_Synchronous_Dyn (T : in out Test) is
begin
T.Dispatch_Event (Event_Test_3.Kind, 0, 0);
end Test_Dispatch_Synchronous_Dyn;
-- ------------------------------
-- Test dispatching synchronous event to a dynamic bean and raise an exception in the action.
-- ------------------------------
procedure Test_Dispatch_Synchronous_Raise (T : in out Test) is
begin
T.Dispatch_Event (Event_Test_4.Kind, 0, 0);
end Test_Dispatch_Synchronous_Raise;
end AWA.Events.Services.Tests;
|
------------------------------------------------------------------------------
-- G E L A A S I S --
-- ASIS implementation for Gela project, a portable Ada compiler --
-- http://gela.ada-ru.org --
-- - - - - - - - - - - - - - - - --
-- Read copyright and license at the end of this file --
------------------------------------------------------------------------------
-- $Revision: 209 $ $Date: 2013-11-30 21:03:24 +0200 (Сб., 30 нояб. 2013) $:
with Asis.Elements;
with Asis.Declarations;
with Asis.Gela.Utils;
with Asis.Gela.Implicit;
with Asis.Gela.Inheritance;
with Ada.Wide_Text_IO;
package body Asis.Gela.Private_Operations is
procedure Create_Type_Data
(Data : in Package_Data;
Info : in Classes.Type_Info);
procedure Check_Dependent
(Tipe : in Asis.Declaration;
Exist : in Type_Data_Access;
Data : in Package_Data;
Info : in Classes.Type_Info;
Point : in out Visibility.Point);
procedure Fill_Dependencies
(Element : in Asis.Declaration;
Data : in Package_Data;
Info : in Classes.Type_Info);
function Find
(Data : in Package_Data;
Info : in Classes.Type_Info) return Type_Data_Access;
------------------------
-- Check_Derived_Type --
------------------------
procedure Check_Derived_Type
(Tipe_Decl : in Asis.Declaration;
From : in Asis.Element;
Point : in out Visibility.Point)
is
use Asis.Elements;
Def : Asis.Definition;
begin
case Declaration_Kind (Tipe_Decl) is
when An_Ordinary_Type_Declaration
| A_Private_Type_Declaration
| A_Formal_Type_Declaration
=>
Def := Asis.Declarations.Type_Declaration_View (Tipe_Decl);
case Type_Kind (Def) is
when A_Derived_Type_Definition |
A_Derived_Record_Extension_Definition =>
Inheritance.Check_Inherited_Subprograms
(Tipe_Decl, From, Point);
when others =>
null;
end case;
when others =>
null;
end case;
end Check_Derived_Type;
---------------------
-- Check_Dependent --
---------------------
procedure Check_Dependent
(Tipe : in Asis.Declaration;
Exist : in Type_Data_Access;
Data : in Package_Data;
Info : in Classes.Type_Info;
Point : in out Visibility.Point)
is
use Type_Info_Lists;
use Asis.Gela.Classes;
Dependent : Cursor;
Found : Type_Data_Access;
Refreshed : Type_Info;
begin
Dependent := First (Exist.Dependent);
while Has_Element (Dependent) loop
Found := Find (Data, Type_Info_Lists.Element (Dependent));
if Found = null then
raise Internal_Error;
end if;
Refreshed := Type_From_Declaration
(Get_Declaration (Found.Info), Tipe);
if not Is_Equal_Class (Found.Info, Refreshed) or
Is_Limited (Found.Info) /= Is_Limited (Refreshed)
then
Implicit.Make_Operations
(Tipe => Refreshed,
Was => Found.Info,
Point => Point);
Found.Info := Refreshed;
Check_Dependent (Tipe, Found, Data, Refreshed, Point);
end if;
Dependent := Next (Dependent);
end loop;
end Check_Dependent;
------------
-- Greate --
------------
function Create (Element : in Asis.Declaration) return Package_Data is
Result : constant Package_Data := new Package_Data_Node;
begin
Result.Element := Element;
return Result;
end Create;
----------------
-- Check_Type --
----------------
procedure Check_Type
(Element : in Asis.Declaration;
Data : in Package_Data;
Point : in out Visibility.Point)
is
use Asis.Elements;
use Asis.Gela.Classes;
Info : constant Type_Info := Type_From_Declaration (Element, Element);
Found : Type_Data_Access;
begin
if Declaration_Kind (Element) = Asis.A_Private_Type_Declaration then
Create_Type_Data (Data, Info);
else
Found := Find (Data, Info);
if Found /= null then
if not Is_Equal_Class (Found.Info, Info) or
Is_Limited (Found.Info) /= Is_Limited (Info)
then
Found.Info := Info;
Check_Dependent (Element, Found, Data, Info, Point);
end if;
elsif Is_Composite (Info) then
Fill_Dependencies (Element, Data, Info);
end if;
end if;
end Check_Type;
----------------------
-- Create_Type_Data --
----------------------
procedure Create_Type_Data
(Data : in Package_Data;
Info : in Classes.Type_Info)
is
Result : constant Type_Data_Access := new Type_Data;
begin
Result.Info := Info;
Type_Data_List.Append (Data.Types, Result);
end Create_Type_Data;
-----------------------
-- Fill_Dependencies --
-----------------------
procedure Fill_Dependencies
(Element : in Asis.Declaration;
Data : in Package_Data;
Info : in Classes.Type_Info)
is
procedure Check_Component (Component_Type : Classes.Type_Info) is
use Type_Info_Lists;
Found : constant Type_Data_Access := Find (Data, Component_Type);
begin
-- If component type is subject to change:
if Found /= null then
-- If not in dependencies list yet:
if not Contains (Found.Dependent, Info) then
Append (Found.Dependent, Info);
-- If new type not in subject_to_change list
if Find (Data, Info) = null then
-- Add it to the list
Create_Type_Data (Data, Info);
end if;
end if;
end if;
end Check_Component;
procedure Walk_Variant
(Item : in Asis.Variant;
Continue : out Boolean) is
begin
Continue := True;
end Walk_Variant;
procedure Walk_Companent
(Item : in Asis.Declaration;
Continue : out Boolean)
is
Component_Type : constant Classes.Type_Info :=
Classes.Type_Of_Declaration (Item, Element);
begin
Check_Component (Component_Type);
Continue := True;
end Walk_Companent;
procedure Walk_Components is new
Utils.Walk_Components (Element, Walk_Variant, Walk_Companent);
Continue : Boolean;
begin
if Classes.Is_Array (Info) then
Check_Component (Classes.Get_Array_Element_Type (Info));
-- elsif Derived?
else
Walk_Components (Element, Continue);
end if;
end Fill_Dependencies;
----------
-- Find --
----------
function Find
(Data : in Package_Data;
Info : in Classes.Type_Info) return Type_Data_Access
is
use Type_Data_List;
Next : aliased Type_Data_Access;
begin
while Iterate (Data.Types, Next'Access) loop
if Classes.Is_Equal (Next.Info, Info) then
return Next;
end if;
end loop;
return null;
end Find;
---------------------
-- On_Package_Body --
---------------------
procedure On_Package_Body
(Element : in Asis.Declaration;
Point : in out Visibility.Point)
is
use Asis.Gela.Classes;
function Specification (Element : Asis.Declaration)
return Asis.Declaration
is
use Asis.Declarations;
Item : Asis.Declaration := Element;
begin
if Is_Subunit(Item) then
Item := Corresponding_Body_Stub (Item);
end if;
return Corresponding_Declaration (Item);
end Specification;
Spec : constant Asis.Declaration := Specification (Element);
List : constant Asis.Declarative_Item_List :=
Asis.Declarations.Visible_Part_Declarative_Items (Spec);
Priv : constant Asis.Declarative_Item_List :=
Asis.Declarations.Private_Part_Declarative_Items (Spec);
From : Type_Info;
To : Type_Info;
Body_View : constant Asis.Element :=
Visibility.End_Of_Package (Element);
Spec_View : Asis.Element;
begin
if Priv'Length = 0 then
Spec_View := Visibility.End_Of_Package (Spec);
else
Spec_View := Priv (Priv'Last);
end if;
for J in List'Range loop
From := Type_From_Declaration (List (J), Spec_View);
To := Type_From_Declaration (List (J), Body_View);
if not Is_Equal_Class (From, To) or
Is_Limited (From) /= Is_Limited (To)
then
-- Ada.Wide_Text_IO.Put_Line ("Old:" & Debug_Image (From));
-- Ada.Wide_Text_IO.Put_Line ("New:" & Debug_Image (To));
Implicit.Make_Operations
(Tipe => To,
Was => From,
Point => Point);
end if;
Check_Derived_Type (List (J), Body_View, Point);
end loop;
end On_Package_Body;
---------------------
-- On_Private_Part --
---------------------
procedure On_Private_Part
(Element : in Asis.Declaration;
Point : in out Visibility.Point)
is
use Asis.Gela.Classes;
List : constant Asis.Declarative_Item_List :=
Asis.Declarations.Visible_Part_Declarative_Items (Element);
Priv : constant Asis.Declarative_Item_List :=
Asis.Declarations.Private_Part_Declarative_Items (Element);
From : Type_Info;
To : Type_Info;
Spec_View : Asis.Element;
begin
if Priv'Length = 0 then
Spec_View := Visibility.End_Of_Package (Element);
else
Spec_View := Priv (Priv'Last);
end if;
for J in List'Range loop
From := Type_From_Declaration (List (J), List (List'Last));
To := Type_From_Declaration (List (J), Spec_View);
if not Is_Equal_Class (From, To) or
Is_Limited (From) /= Is_Limited (To)
then
Implicit.Make_Operations
(Tipe => To,
Was => From,
Point => Point);
end if;
Check_Derived_Type (List (J), Spec_View, Point);
end loop;
end On_Private_Part;
----------
-- Push --
----------
procedure Push
(Stack : in out Package_Data_Stack;
Item : in Package_Data)
is
begin
Prepend (Stack, Item);
end Push;
procedure Pop (Stack : in out Package_Data_Stack) is
Item : Package_Data;
begin
Delete_First (Stack, Item);
end Pop;
function Top (Stack : Package_Data_Stack) return Package_Data is
begin
return First (Stack);
end Top;
function Get_Next (Item : Package_Data) return Package_Data is
begin
return Item.Next;
end Get_Next;
function Get_Next (Item : Type_Data_Access) return Type_Data_Access is
begin
return Item.Next;
end Get_Next;
procedure Set_Next (Item, Next : Package_Data) is
begin
Item.Next := Next;
end Set_Next;
procedure Set_Next (Item, Next : Type_Data_Access) is
begin
Item.Next := Next;
end Set_Next;
end Asis.Gela.Private_Operations;
------------------------------------------------------------------------------
-- Copyright (c) 2008-2013, Maxim Reznik
-- All rights reserved.
--
-- Redistribution and use in source and binary forms, with or without
-- modification, are permitted provided that the following conditions are met:
--
-- * Redistributions of source code must retain the above copyright notice,
-- this list of conditions and the following disclaimer.
-- * Redistributions in binary form must reproduce the above copyright
-- notice, this list of conditions and the following disclaimer in the
-- documentation and/or other materials provided with the distribution.
-- * Neither the name of the Maxim Reznik, IE nor the names of its
-- contributors may be used to endorse or promote products derived from
-- this software without specific prior written permission.
--
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
-- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-- POSSIBILITY OF SUCH DAMAGE.
------------------------------------------------------------------------------
|
------------------------------------------------------------------------------
-- --
-- Copyright (C) 2017, AdaCore --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions are --
-- met: --
-- 1. Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- 2. Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in --
-- the documentation and/or other materials provided with the --
-- distribution. --
-- 3. Neither the name of the copyright holder nor the names of its --
-- contributors may be used to endorse or promote products derived --
-- from this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT --
-- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, --
-- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY --
-- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT --
-- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE --
-- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
with HAL; use HAL;
with HAL.I2C; use HAL.I2C;
with HAL.Time;
package SGTL5000 is
type SGTL5000_DAC (Port : not null Any_I2C_Port;
Time : not null HAL.Time.Any_Delays) is
tagged limited private;
function Valid_Id (This : SGTL5000_DAC) return Boolean;
-- Glossary:
-- DAP : Digital Audio Processing
-- ZCD : Zero Cross Detector
-------------
-- Volumes --
-------------
subtype DAC_Volume is UInt8 range 16#3C# .. 16#F0#;
-- 16#3C# => 0 dB
-- 16#3D# => -0.5 dB
-- ...
-- 16#F0# => -90 dB
procedure Set_DAC_Volume (This : in out SGTL5000_DAC;
Left, Right : DAC_Volume);
subtype ADC_Volume is UInt4;
-- 16#0# => 0 dB
-- 16#1# => +1.5 dB
-- ...
-- 16#F# => +22.5 dB
procedure Set_ADC_Volume (This : in out SGTL5000_DAC;
Left, Right : ADC_Volume;
Minus_6db : Boolean);
subtype HP_Volume is UInt7;
-- 16#00# => +12 dB
-- 16#01# => +11.5 dB
-- 16#18# => 0 dB
-- ...
-- 16#7F# => -51.5 dB
procedure Set_Headphones_Volume (This : in out SGTL5000_DAC;
Left, Right : HP_Volume);
subtype Line_Out_Volume is UInt5;
procedure Set_Line_Out_Volume (This : in out SGTL5000_DAC;
Left, Right : Line_Out_Volume);
procedure Mute_Headphones (This : in out SGTL5000_DAC;
Mute : Boolean := True);
procedure Mute_Line_Out (This : in out SGTL5000_DAC;
Mute : Boolean := True);
procedure Mute_ADC (This : in out SGTL5000_DAC;
Mute : Boolean := True);
procedure Mute_DAC (This : in out SGTL5000_DAC;
Mute : Boolean := True);
-------------------
-- Power control --
-------------------
type Power_State is (On, Off);
procedure Set_Power_Control (This : in out SGTL5000_DAC;
ADC : Power_State;
DAC : Power_State;
DAP : Power_State;
I2S_Out : Power_State;
I2S_In : Power_State);
type Analog_Ground_Voltage is new UInt5;
-- 25mv steps
-- 16#00# => 0.800 V
-- 16#1F# => 1.575 V
type Current_Bias is new UInt3;
-- 16#0# => Nominal
-- 16#1#-16#3# => +12.5%
-- 16#4# => -12.5%
-- 16#5# => -25%
-- 16#6# => -37.5%
-- 16#7# => -50%
procedure Set_Reference_Control (This : in out SGTL5000_DAC;
VAG : Analog_Ground_Voltage;
Bias : Current_Bias;
Slow_VAG_Ramp : Boolean);
type Short_Detector_Level is new UInt3;
-- 16#3# => 25 mA
-- 16#2# => 50 mA
-- 16#1# => 75 mA
-- 16#0# => 100 mA
-- 16#4# => 125 mA
-- 16#5# => 150 mA
-- 16#6# => 175 mA
-- 16#7# => 200 mA
procedure Set_Short_Detectors (This : in out SGTL5000_DAC;
Right_HP : Short_Detector_Level;
Left_HP : Short_Detector_Level;
Center_HP : Short_Detector_Level;
Mode_LR : UInt2;
Mode_CM : UInt2);
type Linear_Regulator_Out_Voltage is new UInt4;
-- 16#0# => 1.60
-- 16#F# => 0.85
type Charge_Pump_Source is (VDDA, VDDIO);
procedure Set_Linereg_Control (This : in out SGTL5000_DAC;
Charge_Pump_Src_Override : Boolean;
Charge_Pump_Src : Charge_Pump_Source;
Linereg_Out_Voltage : Linear_Regulator_Out_Voltage);
type Lineout_Current is (C_0_18ma, C_0_27ma, C_0_36ma, C_0_45ma, C_0_54ma)
with Size => 4;
for Lineout_Current use (C_0_18ma => 0,
C_0_27ma => 1,
C_0_36ma => 3,
C_0_45ma => 7,
C_0_54ma => 15);
procedure Set_Lineout_Control (This : in out SGTL5000_DAC;
Out_Current : Lineout_Current;
Amp_Analog_GND_Voltage : UInt6);
-- Amp_Analog_GND_Voltage (15mV steps), usually VDDIO/2:
-- 0x00 = 0.800 V
-- ...
-- 0x1F = 1.575 V
-- ...
-- 0x23 = 1.675 V
-- 0x24-0x3F are invalid
procedure Set_Analog_Power (This : in out SGTL5000_DAC;
DAC_Mono : Boolean := False;
Linreg_Simple_PowerUp : Boolean := False;
Startup_PowerUp : Boolean := False;
VDDC_Charge_Pump_PowerUp : Boolean := False;
PLL_PowerUp : Boolean := False;
Linereg_D_PowerUp : Boolean := False;
VCOAmp_PowerUp : Boolean := False;
VAG_PowerUp : Boolean := False;
ADC_Mono : Boolean := False;
Reftop_PowerUp : Boolean := False;
Headphone_PowerUp : Boolean := False;
DAC_PowerUp : Boolean := False;
Capless_Headphone_PowerUp : Boolean := False;
ADC_PowerUp : Boolean := False;
Linout_PowerUp : Boolean := False);
-----------------
-- I2S control --
-----------------
type Rate_Mode is (SYS_FS,
Half_SYS_FS,
Quarter_SYS_FS,
Sixth_SYS_FS);
type SYS_FS_Freq is (SYS_FS_32kHz,
SYS_FS_44kHz,
SYS_FS_48kHz,
SYS_FS_96kHz);
type MCLK_Mode is (MCLK_256FS,
MCLK_384FS,
MCLK_512FS,
Use_PLL);
procedure Set_Clock_Control (This : in out SGTL5000_DAC;
Rate : Rate_Mode;
FS : SYS_FS_Freq;
MCLK : MCLK_Mode);
procedure Set_PLL (This : in out SGTL5000_DAC;
PLL_Output_Freq : Natural;
MCLK_Freq : Natural);
-- If sampling frequency = 44.1kHz then PLL_Output_Freq should be 180.6336
-- MHz else PLL_Output_Freq should be 196.608 MHz
type SCLKFREQ_Mode is (SCLKFREQ_64FS,
SCLKFREQ_32FS);
type Data_Len_Mode is (Data_32b,
Data_24b,
Data_20b,
Data_16b);
type I2S_Mode is (I2S_Left_Justified,
Right_Justified,
PCM);
procedure Set_I2S_Control (This : in out SGTL5000_DAC;
SCLKFREQ : SCLKFREQ_Mode;
Invert_SCLK : Boolean;
Master_Mode : Boolean;
Data_Len : Data_Len_Mode;
I2S : I2S_Mode;
LR_Align : Boolean;
LR_Polarity : Boolean);
------------------
-- Audio Switch --
------------------
type ADC_Source is (Microphone, Line_In);
type DAP_Source is (ADC, I2S_In);
type DAP_Mix_Source is (ADC, I2S_In);
type DAC_Source is (ADC, I2S_In, DAP);
type HP_Source is (Line_In, DAC);
type I2S_Out_Source is (ADC, I2S_In, DAP);
procedure Select_ADC_Source (This : in out SGTL5000_DAC;
Source : ADC_Source;
Enable_ZCD : Boolean);
procedure Select_DAP_Source (This : in out SGTL5000_DAC;
Source : DAP_Source);
procedure Select_DAP_Mix_Source (This : in out SGTL5000_DAC;
Source : DAP_Mix_Source);
procedure Select_DAC_Source (This : in out SGTL5000_DAC;
Source : DAC_Source);
procedure Select_HP_Source (This : in out SGTL5000_DAC;
Source : HP_Source;
Enable_ZCD : Boolean);
procedure Select_I2S_Out_Source (This : in out SGTL5000_DAC;
Source : I2S_Out_Source);
private
SGTL5000_Chip_ID : constant := 16#A000#;
SGTL5000_QFN20_I2C_Addr : constant I2C_Address := 20;
type SGTL5000_DAC (Port : not null Any_I2C_Port;
Time : not null HAL.Time.Any_Delays) is
tagged limited null record;
procedure I2C_Write (This : in out SGTL5000_DAC;
Reg : UInt16;
Value : UInt16);
function I2C_Read (This : SGTL5000_DAC;
Reg : UInt16)
return UInt16;
procedure Modify (This : in out SGTL5000_DAC;
Reg : UInt16;
Mask : UInt16;
Value : UInt16);
------------------------
-- Register addresses --
------------------------
Chip_ID_Reg : constant := 16#0000#;
DIG_POWER_REG : constant := 16#0002#;
CLK_CTRL_REG : constant := 16#0004#;
I2S_CTRL_REG : constant := 16#0006#;
SSS_CTRL_REG : constant := 16#000A#;
ADCDAC_CTRL_REG : constant := 16#000E#;
DAC_VOL_REG : constant := 16#0010#;
PAD_STRENGTH_REG : constant := 16#0014#;
ANA_ADC_CTRL_REG : constant := 16#0020#;
ANA_HP_CTRL_REG : constant := 16#0022#;
ANA_CTRL_REG : constant := 16#0024#;
LINREG_CTRL_REG : constant := 16#0026#;
REF_CTRL_REG : constant := 16#0028#;
MIC_CTRL_REG : constant := 16#002A#;
LINE_OUT_CTRL_REG : constant := 16#002C#;
LINE_OUT_VOL_REG : constant := 16#002E#;
ANA_POWER_REG : constant := 16#0030#;
PLL_CTRL_REG : constant := 16#0032#;
CLK_TOP_CTRL_REG : constant := 16#0034#;
ANA_STATUS_REG : constant := 16#0036#;
ANA_TEST1_REG : constant := 16#0038#;
ANA_TEST2_REG : constant := 16#003A#;
SHORT_CTRL_REG : constant := 16#003C#;
DAP_CONTROL_REG : constant := 16#0100#;
DAP_PEQ_REG : constant := 16#0102#;
DAP_BASS_ENHANCE_REG : constant := 16#0104#;
DAP_BASS_ENHANCE_CTRL_REG : constant := 16#0106#;
DAP_AUDIO_EQ_REG : constant := 16#0108#;
DAP_SGTL_SURROUND_REG : constant := 16#010A#;
DAP_FILTER_COEF_ACCESS_REG : constant := 16#010C#;
DAP_COEF_WR_B0_MSB_REG : constant := 16#010E#;
DAP_COEF_WR_B0_LSB_REG : constant := 16#0110#;
DAP_AUDIO_EQ_BASS_BAND0_REG : constant := 16#0116#;
DAP_AUDIO_EQ_BAND1_REG : constant := 16#0118#;
DAP_AUDIO_EQ_BAND2_REG : constant := 16#011A#;
DAP_AUDIO_EQ_BAND3_REG : constant := 16#011C#;
DAP_AUDIO_EQ_TREBLE_BAND4_REG : constant := 16#011E#;
DAP_MAIN_CHAN_REG : constant := 16#0120#;
DAP_MIX_CHAN_REG : constant := 16#0122#;
DAP_AVC_CTRL_REG : constant := 16#0124#;
DAP_AVC_THRESHOLD_REG : constant := 16#0126#;
DAP_AVC_ATTACK_REG : constant := 16#0128#;
DAP_AVC_DECAY_REG : constant := 16#012A#;
DAP_COEF_WR_B1_MSB_REG : constant := 16#012C#;
DAP_COEF_WR_B1_LSB_REG : constant := 16#012E#;
DAP_COEF_WR_B2_MSB_REG : constant := 16#0130#;
DAP_COEF_WR_B2_LSB_REG : constant := 16#0132#;
DAP_COEF_WR_A1_MSB_REG : constant := 16#0134#;
DAP_COEF_WR_A1_LSB_REG : constant := 16#0136#;
DAP_COEF_WR_A2_MSB_REG : constant := 16#0138#;
DAP_COEF_WR_A2_LSB_REG : constant := 16#013A#;
end SGTL5000;
|
-- This file is covered by the Internet Software Consortium (ISC) License
-- Reference: License.txt
with Ada.Command_Line;
with Ada.Text_IO;
with Parameters;
with Pilot;
with Unix;
procedure Ravenadm is
package CLI renames Ada.Command_Line;
package TIO renames Ada.Text_IO;
type mandate_type is (unset, help, dev, build, build_everything, force, test, test_everything,
status, status_everything, configure, locate, purge, changeopts,
checkports, portsnap, repository, list_subpackages, website, purgelogs);
type dev_mandate is (unset, dump, makefile, distinfo, buildsheet, template, genindex, web,
repatch, sort_plist, confinfo, genconspiracy, jump);
procedure scan_first_command_word;
function scan_dev_command_word return dev_mandate;
function get_arg (arg_number : Positive) return String;
mandate : mandate_type := unset;
low_rights : Boolean := False;
reg_user : Boolean;
reg_error : constant String := "This command requires root permissions to execute.";
procedure scan_first_command_word
is
first : constant String := CLI.Argument (1);
begin
if first = "help" then
mandate := help;
elsif first = "dev" then
mandate := dev;
elsif first = "build" then
mandate := build;
elsif first = "build-everything" then
mandate := build_everything;
elsif first = "force" then
mandate := force;
elsif first = "test" then
mandate := test;
elsif first = "test-everything" then
mandate := test_everything;
elsif first = "status" then
mandate := status;
elsif first = "status-everything" then
mandate := status_everything;
elsif first = "configure" then
mandate := configure;
elsif first = "locate" then
mandate := locate;
elsif first = "purge-distfiles" then
mandate := purge;
elsif first = "purge-logs" then
mandate := purgelogs;
elsif first = "set-options" then
mandate := changeopts;
elsif first = "check-ports" then
mandate := checkports;
elsif first = "update-ports" then
mandate := portsnap;
elsif first = "generate-repository" then
mandate := repository;
elsif first = "subpackages" then
mandate := list_subpackages;
elsif first = "generate-website" then
mandate := website;
end if;
end scan_first_command_word;
function scan_dev_command_word return dev_mandate
is
-- Check argument count before calling
second : constant String := CLI.Argument (2);
begin
if second = "dump" then
return dump;
elsif second = "makefile" then
return makefile;
elsif second = "distinfo" then
return distinfo;
elsif second = "buildsheet" then
return buildsheet;
elsif second = "template" then
return template;
elsif second = "generate-index" then
return genindex;
elsif second = "generate-conspiracy" then
return genconspiracy;
elsif second = "web" then
return web;
elsif second = "repatch" then
return repatch;
elsif second = "sort" then
return sort_plist;
elsif second = "info" then
return confinfo;
elsif second = "jump" then
return jump;
else
return unset;
end if;
end scan_dev_command_word;
function get_arg (arg_number : Positive) return String is
begin
if CLI.Argument_Count >= arg_number then
return CLI.Argument (arg_number);
else
return "";
end if;
end get_arg;
begin
if CLI.Argument_Count = 0 then
Pilot.display_usage;
return;
end if;
scan_first_command_word;
if mandate = unset then
Pilot.react_to_unknown_first_level_command (CLI.Argument (1));
return;
end if;
--------------------------------------------------------------------------------------------
-- Validation block start
--------------------------------------------------------------------------------------------
case mandate is
when help | locate | list_subpackages =>
low_rights := True;
when others =>
if Pilot.already_running then
return;
end if;
end case;
reg_user := Pilot.insufficient_privileges;
if not Parameters.configuration_exists and then reg_user then
TIO.Put_Line ("No configuration file found.");
TIO.Put_Line ("Please switch to root permissions and retry the command.");
return;
end if;
if not Parameters.load_configuration then
return;
end if;
case mandate is
when build | force | build_everything | test | status | status_everything =>
-- All commands involving replicant slaves
if Pilot.launch_clash_detected then
return;
end if;
when others => null;
end case;
case mandate is
when build | force | build_everything | test =>
if Parameters.configuration.avec_ncurses and then
not Pilot.TERM_defined_in_environment
then
return;
end if;
when others => null;
end case;
case mandate is
when configure | help => null;
when portsnap =>
if not Parameters.all_paths_valid (skip_mk_check => True) then
return;
end if;
when others =>
if not Parameters.all_paths_valid (skip_mk_check => False) then
return;
end if;
end case;
case mandate is
when help | locate | list_subpackages =>
null;
when dev =>
declare
dev_subcmd : dev_mandate := unset;
begin
if CLI.Argument_Count > 1 then
dev_subcmd := scan_dev_command_word;
end if;
case dev_subcmd is
when template | sort_plist | confinfo | jump | unset =>
low_rights := True;
when dump | makefile | distinfo | buildsheet | web | repatch |
genindex | genconspiracy =>
if reg_user then
TIO.Put_Line (reg_error);
return;
end if;
end case;
end;
when others =>
if reg_user then
TIO.Put_Line (reg_error);
return;
end if;
end case;
if not low_rights then
if Pilot.previous_run_mounts_detected and then
not Pilot.old_mounts_successfully_removed
then
return;
end if;
if Pilot.previous_realfs_work_detected and then
not Pilot.old_realfs_work_successfully_removed
then
return;
end if;
if Pilot.ravenexec_missing then
return;
end if;
end if;
case mandate is
when build | force | test | changeopts | list_subpackages =>
if not Pilot.store_origins (start_from => 2) then
return;
end if;
when status =>
if CLI.Argument_Count > 1 then
if not Pilot.store_origins (start_from => 2) then
return;
end if;
end if;
when others => null;
end case;
case mandate is
when build | build_everything | force |
test | test_everything |
status | status_everything =>
Pilot.check_that_ravenadm_is_modern_enough;
if not Pilot.slave_platform_determined then
return;
end if;
when others => null;
end case;
if not low_rights then
Pilot.create_pidfile;
Unix.ignore_background_tty;
end if;
if mandate /= configure then
Unix.cone_of_silence (deploy => True);
end if;
--------------------------------------------------------------------------------------------
-- Validation block end
--------------------------------------------------------------------------------------------
case mandate is
when status =>
--------------------------------
-- status command
--------------------------------
if CLI.Argument_Count > 1 then
if Pilot.install_compiler_packages and then
Pilot.scan_stack_of_single_ports (always_build => False) and then
Pilot.sanity_check_then_prefail (delete_first => False, dry_run => True)
then
Pilot.display_results_of_dry_run;
end if;
else
null; -- reserved for upgrade_system_everything maybe
end if;
when status_everything =>
--------------------------------
-- status_everything command
--------------------------------
if Pilot.install_compiler_packages and then
Pilot.fully_scan_ports_tree and then
Pilot.sanity_check_then_prefail (delete_first => False, dry_run => True)
then
Pilot.display_results_of_dry_run;
end if;
when build =>
--------------------------------
-- build command
--------------------------------
if Pilot.install_compiler_packages and then
Pilot.scan_stack_of_single_ports (always_build => False) and then
Pilot.sanity_check_then_prefail (delete_first => False, dry_run => False)
then
Pilot.perform_bulk_run (testmode => False);
end if;
when build_everything =>
--------------------------------
-- build-everything command
--------------------------------
if Pilot.install_compiler_packages and then
Pilot.fully_scan_ports_tree and then
Pilot.sanity_check_then_prefail (delete_first => False, dry_run => False)
then
Pilot.perform_bulk_run (testmode => False);
end if;
when test_everything =>
--------------------------------
-- test-everything command
--------------------------------
if Pilot.install_compiler_packages and then
Pilot.fully_scan_ports_tree and then
Pilot.sanity_check_then_prefail (delete_first => True, dry_run => False)
then
Pilot.perform_bulk_run (testmode => True);
end if;
when website =>
--------------------------------
-- generate-website command
--------------------------------
Pilot.generate_website;
when force =>
--------------------------------
-- force command
--------------------------------
if Pilot.install_compiler_packages and then
Pilot.scan_stack_of_single_ports (always_build => False) and then
Pilot.sanity_check_then_prefail (delete_first => True, dry_run => False)
then
Pilot.perform_bulk_run (testmode => False);
end if;
when dev =>
--------------------------------
-- dev command
--------------------------------
if CLI.Argument_Count > 1 then
declare
dev_subcmd : dev_mandate := scan_dev_command_word;
begin
case dev_subcmd is
when unset =>
Pilot.react_to_unknown_second_level_command (CLI.Argument (1),
CLI.Argument (2));
when dump =>
Pilot.dump_ravensource (get_arg (3));
when distinfo =>
Pilot.generate_distinfo;
when buildsheet =>
Pilot.generate_buildsheet (get_arg (3), get_arg (4));
when makefile =>
Pilot.generate_makefile (get_arg (3), get_arg (4));
when web =>
Pilot.generate_webpage (get_arg (3), get_arg (4));
when repatch =>
Pilot.regenerate_patches (get_arg (3), get_arg (4));
when sort_plist =>
Pilot.resort_manifests (get_arg (3));
when template =>
Pilot.print_spec_template (get_arg (3));
when genindex =>
Pilot.generate_ports_index;
when genconspiracy =>
Pilot.generate_conspiracy (get_arg (3));
when confinfo =>
Pilot.show_config_value (get_arg (3));
when jump =>
Pilot.jump (get_arg (3));
end case;
end;
else
Pilot.react_to_unknown_second_level_command (CLI.Argument (1), "");
end if;
when help =>
--------------------------------
-- help command
--------------------------------
if CLI.Argument_Count > 1 then
Pilot.launch_man_page (CLI.Argument (2));
else
Pilot.show_short_help;
end if;
when test =>
--------------------------------
-- test command
--------------------------------
if Pilot.install_compiler_packages and then
Pilot.scan_stack_of_single_ports (always_build => True) and then
Pilot.sanity_check_then_prefail (delete_first => True, dry_run => False)
then
if Pilot.interact_with_single_builder then
Pilot.bulk_run_then_interact_with_final_port;
else
Pilot.perform_bulk_run (testmode => True);
end if;
end if;
when configure =>
--------------------------------
-- configure
--------------------------------
Pilot.launch_configure_menu;
when locate =>
--------------------------------
-- locate
--------------------------------
Pilot.locate (get_arg (2));
when list_subpackages =>
--------------------------------
-- subpackages
--------------------------------
Pilot.list_subpackages;
when purge =>
--------------------------------
-- purge-distfiles
--------------------------------
Pilot.purge_distfiles;
when purgelogs =>
--------------------------------
-- purge-logs
--------------------------------
Pilot.purge_logs;
when changeopts =>
--------------------------------
-- set-options
--------------------------------
Pilot.change_options;
when checkports =>
--------------------------------
-- check-ports
--------------------------------
Pilot.check_ravenports_version;
when portsnap =>
--------------------------------
-- update-ports
--------------------------------
Pilot.update_to_latest_ravenports;
when repository =>
--------------------------------
-- generate-repository
--------------------------------
Pilot.generate_repository;
when unset => null;
end case;
Unix.cone_of_silence (deploy => False);
if not low_rights then
Pilot.destroy_pidfile;
end if;
end Ravenadm;
|
------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- U S A G E --
-- --
-- B o d y --
-- --
-- Copyright (C) 1992-2020, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
-- for more details. You should have received a copy of the GNU General --
-- Public License distributed with GNAT; see file COPYING3. If not, go to --
-- http://www.gnu.org/licenses for a complete copy of the license. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
-- Warning: the output of this usage for warnings is duplicated in the GNAT
-- reference manual. Be sure to update that if you change the warning list.
with Namet; use Namet;
with Opt; use Opt;
with Osint; use Osint;
with Output; use Output;
with System.WCh_Con; use System.WCh_Con;
procedure Usage is
procedure Write_Switch_Char (Sw : String; Prefix : String := "gnat");
-- Output two spaces followed by the switch character minus followed
-- Prefix, followed by the string given as the argument, and then enough
-- blanks to tab to column 13, i.e. assuming Sw is not longer than 5
-- characters, the maximum allowed, Write_Switch_Char will always output
-- exactly 12 characters.
-----------------------
-- Write_Switch_Char --
-----------------------
procedure Write_Switch_Char (Sw : String; Prefix : String := "gnat") is
begin
Write_Str (" -");
Write_Str (Prefix);
Write_Str (Sw);
for J in 1 .. 12 - 3 - Prefix'Length - Sw'Length loop
Write_Char (' ');
end loop;
end Write_Switch_Char;
-- Start of processing for Usage
begin
Find_Program_Name;
-- For gnatmake, we are appending this information to the end of
-- the normal gnatmake output, so generate appropriate header
if Name_Len >= 8
and then (Name_Buffer (Name_Len - 7 .. Name_Len) = "gnatmake"
or else
Name_Buffer (Name_Len - 7 .. Name_Len) = "GNATMAKE")
then
Write_Eol;
Write_Line ("Compiler switches (passed to the compiler by gnatmake):");
else
-- Usage line
Write_Str ("Usage: ");
Write_Program_Name;
Write_Char (' ');
Write_Str ("switches sfile");
Write_Eol;
Write_Eol;
-- Line for sfile
Write_Line (" sfile Source file name");
end if;
Write_Eol;
-- Common switches available everywhere
Write_Switch_Char ("g ", "");
Write_Line ("Generate debugging information");
Write_Switch_Char ("Idir ", "");
Write_Line ("Specify source files search path");
Write_Switch_Char ("I- ", "");
Write_Line ("Do not look for sources in current directory");
Write_Switch_Char ("O[0123] ", "");
Write_Line ("Control the optimization level");
Write_Eol;
-- Individual lines for switches. Write_Switch_Char outputs fourteen
-- characters, so the remaining message is allowed to be a maximum of
-- 65 characters to be comfortable in an 80 character window.
-- Line for -gnata switch
Write_Switch_Char ("a");
Write_Line ("Assertions enabled. Pragma Assert/Debug to be activated");
-- Line for -gnatA switch
Write_Switch_Char ("A");
Write_Line ("Avoid processing gnat.adc, if present file will be ignored");
-- Line for -gnatb switch
Write_Switch_Char ("b");
Write_Line ("Generate brief messages to stderr even if verbose mode set");
-- Line for -gnatB switch
Write_Switch_Char ("B");
Write_Line ("Assume no bad (invalid) values except in 'Valid attribute");
-- Line for -gnatc switch
Write_Switch_Char ("c");
Write_Line ("Check syntax and semantics only (no code generation)");
-- Line for -gnatC switch
Write_Switch_Char ("C");
Write_Line ("Generate CodePeer intermediate format (no code generation)");
-- Line for -gnatd switch
Write_Switch_Char ("d?");
Write_Line ("Compiler debug option ? ([.]a-z,A-Z,0-9), see debug.adb");
-- Line for -gnatD switch
Write_Switch_Char ("D");
Write_Line ("Debug expanded generated code (max line length = 72)");
Write_Switch_Char ("Dnn");
Write_Line ("Debug expanded generated code (max line length = nn)");
-- No line for -gnatea : internal switch
-- Line for -gnateA switch
Write_Switch_Char ("eA");
Write_Line ("Aliasing checks on subprogram parameters");
-- Line for -gnatec switch
Write_Switch_Char ("ec=?");
Write_Line ("Specify configuration pragmas file, e.g. -gnatec=/x/f.adc");
-- Line for -gnateC switch
Write_Switch_Char ("eC");
Write_Line ("Generate CodePeer messages (ignored without -gnatcC)");
-- Line for -gnated switch
Write_Switch_Char ("ed");
Write_Line ("Disable synchronization of atomic variables");
-- Line for -gnateD switch
Write_Switch_Char ("eD?");
Write_Line ("Define or redefine preprocessing symbol, e.g. -gnateDsym=val");
-- Line for -gnateE switch
Write_Switch_Char ("eE");
Write_Line ("Generate extra information in exception messages");
-- Line for -gnatef switch
Write_Switch_Char ("ef");
Write_Line ("Full source path in brief error messages");
-- Line for -gnateF switch
Write_Switch_Char ("eF");
Write_Line ("Check overflow on predefined Float types");
-- Line for -gnateG switch
Write_Switch_Char ("eG");
Write_Line ("Generate preprocessed source");
-- Line for -gnatei switch
Write_Switch_Char ("einn");
Write_Line ("Set maximum number of instantiations to nn");
-- Line for -gnateI switch
Write_Switch_Char ("eInn");
Write_Line ("Index in multi-unit source, e.g. -gnateI2");
-- Line for -gnatel switch
Write_Switch_Char ("el");
Write_Line ("Turn on info messages on generated Elaborate[_All] pragmas");
-- Line for -gnateL switch
Write_Switch_Char ("eL");
Write_Line ("Turn off info messages on generated Elaborate[_All] pragmas");
-- Line for -gnatem switch
Write_Switch_Char ("em=?");
Write_Line ("Specify mapping file, e.g. -gnatem=mapping");
-- No line for -gnateO=? : internal switch
-- Line for -gnatep switch
Write_Switch_Char ("ep=?");
Write_Line ("Specify preprocessing data file, e.g. -gnatep=prep.data");
-- Line for -gnateP switch
Write_Switch_Char ("eP");
Write_Line ("Pure/Prelaborate errors generate warnings rather than errors");
-- No line for -gnates=? : internal switch
-- Line for -gnateS switch
Write_Switch_Char ("eS");
Write_Line ("Generate SCO (Source Coverage Obligation) information");
-- Line for -gnatet switch
Write_Switch_Char ("et=?");
Write_Line ("Write target dependent information file ?, e.g. gnatet=tdf");
-- Line for -gnateT switch
Write_Switch_Char ("eT=?");
Write_Line ("Read target dependent information file ?, e.g. gnateT=tdf");
-- Line for -gnateu switch
Write_Switch_Char ("eu");
Write_Line ("Ignore unrecognized style/validity/warning switches");
-- Line for -gnateV switch
Write_Switch_Char ("eV");
Write_Line ("Validity checks on subprogram parameters");
-- Line for -gnateY switch
Write_Switch_Char ("eY");
Write_Line ("Ignore all Style_Checks pragmas in source");
-- No line for -gnatez : internal switch
-- Line for -gnatE switch
Write_Switch_Char ("E");
Write_Line ("Dynamic elaboration checking mode enabled");
-- Line for -gnatf switch
Write_Switch_Char ("f");
Write_Line ("Full errors. Verbose details, all undefined references");
-- Line for -gnatF switch
Write_Switch_Char ("F");
Write_Line ("Force all import/export external names to all uppercase");
-- Line for -gnatg switch
Write_Switch_Char ("g");
Write_Line ("GNAT implementation mode (used for compiling GNAT units)");
-- Lines for -gnatG switch
Write_Switch_Char ("G");
Write_Line ("Output generated expanded code (max line length = 72)");
Write_Switch_Char ("Gnn");
Write_Line ("Output generated expanded code (max line length = nn)");
-- Line for -gnath switch
Write_Switch_Char ("h");
Write_Line ("Output this usage (help) information");
-- Line for -gnatH switch
Write_Switch_Char ("H");
Write_Line ("Legacy elaboration checking mode enabled");
-- Line for -gnati switch
Write_Switch_Char ("i?");
Write_Line ("Identifier char set (?=1/2/3/4/5/8/9/p/f/n/w)");
-- Line for -gnatI switch
Write_Switch_Char ("I");
Write_Line ("Ignore all representation clauses");
-- Line for -gnatj switch
Write_Switch_Char ("jnn");
Write_Line ("Format error and warning messages to fit nn character lines");
-- Line for -gnatJ switch
Write_Switch_Char ("J");
Write_Line ("Relaxed elaboration checking mode enabled");
-- Line for -gnatk switch
Write_Switch_Char ("k");
Write_Line ("Limit file names to nn characters (k = krunch)");
-- Lines for -gnatl switch
Write_Switch_Char ("l");
Write_Line ("Output full source listing with embedded error messages");
Write_Switch_Char ("l=f");
Write_Line ("Output full source listing to specified file");
-- Line for -gnatL switch
Write_Switch_Char ("L");
Write_Line ("List corresponding source text in -gnatG or -gnatD output");
-- Line for -gnatm switch
Write_Switch_Char ("mnn");
Write_Line ("Limit number of detected errors/warnings to nn (1-999999)");
-- Line for -gnatn switch
Write_Switch_Char ("n[?]");
Write_Line ("Enable pragma Inline across units (?=1/2 for moderate/full)");
-- Line for -gnato switch
Write_Switch_Char ("o0");
Write_Line ("Disable overflow checking");
Write_Switch_Char ("o");
Write_Line ("Enable overflow checking in STRICT (-gnato1) mode (default)");
-- Lines for -gnato? switches
Write_Switch_Char ("o?");
Write_Line
("Enable overflow checks in STRICT/MINIMIZED/ELIMINATED (1/2/3) mode ");
Write_Switch_Char ("o??");
Write_Line
("Set mode for general/assertion expressions separately");
-- No line for -gnatO : internal switch
-- Line for -gnatp switch
Write_Switch_Char ("p");
Write_Line ("Suppress all checks");
-- Line for -gnatq switch
Write_Switch_Char ("q");
Write_Line ("Don't quit, try semantics, even if parse errors");
-- Line for -gnatQ switch
Write_Switch_Char ("Q");
Write_Line ("Don't quit, write ali/tree file even if compile errors");
-- Line for -gnatr switch
Write_Switch_Char ("r");
Write_Line ("Treat pragma Restrictions as Restriction_Warnings");
-- Lines for -gnatR switch
Write_Switch_Char ("R?");
Write_Line
("List rep info (?=0/1/2/3/4/e/m for none/types/all/sym/cg/ext/mech)");
Write_Switch_Char ("R?j");
Write_Line ("List rep info in the JSON data interchange format");
Write_Switch_Char ("R?s");
Write_Line ("List rep info to file.rep instead of standard output");
-- Line for -gnats switch
Write_Switch_Char ("s");
Write_Line ("Syntax check only");
-- Line for -gnatS switch
Write_Switch_Char ("S");
Write_Line ("Print listing of package Standard");
-- Line for -gnatTnn switch
Write_Switch_Char ("Tnn");
Write_Line ("All compiler tables start at nn times usual starting size");
-- Line for -gnatu switch
Write_Switch_Char ("u");
Write_Line ("List units for this compilation");
-- Line for -gnatU switch
Write_Switch_Char ("U");
Write_Line ("Enable unique tag for error messages");
-- Line for -gnatv switch
Write_Switch_Char ("v");
Write_Line ("Verbose mode. Full error output with source lines to stdout");
-- Lines for -gnatV switch
Write_Switch_Char ("Vxx");
Write_Line
("Enable selected validity checking mode, xx = list of parameters:");
Write_Line (" a turn on all validity checking options");
Write_Line (" c turn on checking for copies");
Write_Line (" C turn off checking for copies");
Write_Line (" d turn on default (RM) checking");
Write_Line (" D turn off default (RM) checking");
Write_Line (" e turn on checking for elementary components");
Write_Line (" E turn off checking for elementary components");
Write_Line (" f turn on checking for floating-point");
Write_Line (" F turn off checking for floating-point");
Write_Line (" i turn on checking for in params");
Write_Line (" I turn off checking for in params");
Write_Line (" m turn on checking for in out params");
Write_Line (" M turn off checking for in out params");
Write_Line (" n turn off all validity checks (including RM)");
Write_Line (" o turn on checking for operators/attributes");
Write_Line (" O turn off checking for operators/attributes");
Write_Line (" p turn on checking for parameters");
Write_Line (" P turn off checking for parameters");
Write_Line (" r turn on checking for returns");
Write_Line (" R turn off checking for returns");
Write_Line (" s turn on checking for subscripts");
Write_Line (" S turn off checking for subscripts");
Write_Line (" t turn on checking for tests");
Write_Line (" T turn off checking for tests");
-- Lines for -gnatw switch
Write_Switch_Char ("wxx");
Write_Line ("Enable selected warning modes, xx = list of parameters:");
Write_Line (" * indicates default setting");
Write_Line (" + indicates warning flag included in -gnatwa");
Write_Line (" a turn on all info/warnings marked below with +");
Write_Line (" A turn off all optional info/warnings");
Write_Line (" .a*+ turn on warnings for failing assertion");
Write_Line (" .A turn off warnings for failing assertion");
Write_Line (" _a*+ turn on warnings for anonymous allocators");
Write_Line (" _A turn off warnings for anonymous allocators");
Write_Line (" b+ turn on warnings for bad fixed value " &
"(not multiple of small)");
Write_Line (" B* turn off warnings for bad fixed value " &
"(not multiple of small)");
Write_Line (" .b*+ turn on warnings for biased representation");
Write_Line (" .B turn off warnings for biased representation");
Write_Line (" c+ turn on warnings for constant conditional");
Write_Line (" C* turn off warnings for constant conditional");
Write_Line (" .c+ turn on warnings for unrepped components");
Write_Line (" .C* turn off warnings for unrepped components");
Write_Line (" _c* turn on warnings for unknown " &
"Compile_Time_Warning");
Write_Line (" _C turn off warnings for unknown " &
"Compile_Time_Warning");
Write_Line (" d turn on warnings for implicit dereference");
Write_Line (" D* turn off warnings for implicit dereference");
Write_Line (" .d turn on tagging of warnings with -gnatw switch");
Write_Line (" .D* turn off tagging of warnings with -gnatw switch");
Write_Line (" e treat all warnings (but not info) as errors");
Write_Line (" .e turn on every optional info/warning " &
"(no exceptions)");
Write_Line (" E treat all run-time warnings as errors");
Write_Line (" f+ turn on warnings for unreferenced formal");
Write_Line (" F* turn off warnings for unreferenced formal");
Write_Line (" .f turn on warnings for suspicious Subp'Access");
Write_Line (" .F* turn off warnings for suspicious Subp'Access");
Write_Line (" g*+ turn on warnings for unrecognized pragma");
Write_Line (" G turn off warnings for unrecognized pragma");
Write_Line (" .g turn on GNAT warnings");
Write_Line (" h turn on warnings for hiding declarations");
Write_Line (" H* turn off warnings for hiding declarations");
Write_Line (" .h turn on warnings for holes in records");
Write_Line (" .H* turn off warnings for holes in records");
Write_Line (" i*+ turn on warnings for implementation unit");
Write_Line (" I turn off warnings for implementation unit");
Write_Line (" .i*+ turn on warnings for overlapping actuals");
Write_Line (" .I turn off warnings for overlapping actuals");
Write_Line (" j+ turn on warnings for obsolescent " &
"(annex J) feature");
Write_Line (" J* turn off warnings for obsolescent " &
"(annex J) feature");
Write_Line (" .j+ turn on warnings for late dispatching " &
"primitives");
Write_Line (" .J* turn off warnings for late dispatching " &
"primitives");
Write_Line (" k+ turn on warnings on constant variable");
Write_Line (" K* turn off warnings on constant variable");
Write_Line (" .k turn on warnings for standard redefinition");
Write_Line (" .K* turn off warnings for standard redefinition");
Write_Line (" l turn on warnings for elaboration problems");
Write_Line (" L* turn off warnings for elaboration problems");
Write_Line (" .l turn on info messages for inherited aspects");
Write_Line (" .L* turn off info messages for inherited aspects");
Write_Line (" m+ turn on warnings for variable assigned " &
"but not read");
Write_Line (" M* turn off warnings for variable assigned " &
"but not read");
Write_Line (" .m*+ turn on warnings for suspicious modulus value");
Write_Line (" .M turn off warnings for suspicious modulus value");
Write_Line (" n* normal warning mode (cancels -gnatws/-gnatwe)");
Write_Line (" .n turn on info messages for atomic " &
"synchronization");
Write_Line (" .N* turn off info messages for atomic " &
"synchronization");
Write_Line (" o* turn on warnings for address clause overlay");
Write_Line (" O turn off warnings for address clause overlay");
Write_Line (" .o turn on warnings for out parameters assigned " &
"but not read");
Write_Line (" .O* turn off warnings for out parameters assigned " &
"but not read");
Write_Line (" p+ turn on warnings for ineffective pragma " &
"Inline in frontend");
Write_Line (" P* turn off warnings for ineffective pragma " &
"Inline in frontend");
Write_Line (" .p+ turn on warnings for suspicious parameter " &
"order");
Write_Line (" .P* turn off warnings for suspicious parameter " &
"order");
Write_Line (" q*+ turn on warnings for questionable " &
"missing parenthesis");
Write_Line (" Q turn off warnings for questionable " &
"missing parenthesis");
Write_Line (" .q+ turn on warnings for questionable layout of " &
"record types");
Write_Line (" .Q* turn off warnings for questionable layout of " &
"record types");
Write_Line (" r+ turn on warnings for redundant construct");
Write_Line (" R* turn off warnings for redundant construct");
Write_Line (" .r+ turn on warnings for object renaming function");
Write_Line (" .R* turn off warnings for object renaming function");
Write_Line (" _r turn on warnings for components out of order");
Write_Line (" _R turn off warnings for components out of order");
Write_Line (" s suppress all info/warnings");
Write_Line (" .s turn on warnings for overridden size clause");
Write_Line (" .S* turn off warnings for overridden size clause");
Write_Line (" t turn on warnings for tracking deleted code");
Write_Line (" T* turn off warnings for tracking deleted code");
Write_Line (" .t*+ turn on warnings for suspicious contract");
Write_Line (" .T turn off warnings for suspicious contract");
Write_Line (" u+ turn on warnings for unused entity");
Write_Line (" U* turn off warnings for unused entity");
Write_Line (" .u turn on warnings for unordered enumeration");
Write_Line (" .U* turn off warnings for unordered enumeration");
Write_Line (" v*+ turn on warnings for unassigned variable");
Write_Line (" V turn off warnings for unassigned variable");
Write_Line (" .v*+ turn on info messages for reverse bit order");
Write_Line (" .V turn off info messages for reverse bit order");
Write_Line (" w*+ turn on warnings for wrong low bound assumption");
Write_Line (" W turn off warnings for wrong low bound " &
"assumption");
Write_Line (" .w turn on warnings on pragma Warnings Off");
Write_Line (" .W* turn off warnings on pragma Warnings Off");
Write_Line (" x*+ turn on warnings for export/import");
Write_Line (" X turn off warnings for export/import");
Write_Line (" .x+ turn on warnings for non-local exception");
Write_Line (" .X* turn off warnings for non-local exception");
Write_Line (" y*+ turn on warnings for Ada compatibility issues");
Write_Line (" Y turn off warnings for Ada compatibility issues");
Write_Line (" .y turn on info messages for why pkg body needed");
Write_Line (" .Y* turn off info messages for why pkg body needed");
Write_Line (" z*+ turn on warnings for suspicious " &
"unchecked conversion");
Write_Line (" Z turn off warnings for suspicious " &
"unchecked conversion");
Write_Line (" .z*+ turn on warnings for record size not a " &
"multiple of alignment");
Write_Line (" .Z turn off warnings for record size not a " &
"multiple of alignment");
-- Line for -gnatW switch
Write_Switch_Char ("W?");
Write_Str ("Wide character encoding method (?=");
for J in WC_Encoding_Method loop
Write_Char (WC_Encoding_Letters (J));
if J = WC_Encoding_Method'Last then
Write_Char (')');
else
Write_Char ('/');
end if;
end loop;
Write_Eol;
-- Line for -gnatx switch
Write_Switch_Char ("x");
Write_Line ("Suppress output of cross-reference information");
-- Line for -gnatX switch
Write_Switch_Char ("X");
Write_Line ("Language extensions permitted");
-- Lines for -gnaty switch
Write_Switch_Char ("y");
Write_Line ("Enable default style checks (same as -gnaty3abcefhiklmnprst)");
Write_Switch_Char ("yxx");
Write_Line ("Enable selected style checks xx = list of parameters:");
Write_Line (" 1-9 check indentation");
Write_Line (" a check attribute casing");
Write_Line (" A check array attribute indexes");
Write_Line (" b check no blanks at end of lines");
Write_Line (" B check no use of AND/OR for boolean expressions");
Write_Line (" c check comment format (two spaces)");
Write_Line (" C check comment format (one space)");
Write_Line (" d check no DOS line terminators");
Write_Line (" e check end/exit labels present");
Write_Line (" f check no form feeds/vertical tabs in source");
Write_Line (" g check standard GNAT style rules, same as ydISux");
Write_Line (" h check no horizontal tabs in source");
Write_Line (" i check if-then layout");
Write_Line (" I check mode in");
Write_Line (" k check casing rules for keywords");
Write_Line (" l check reference manual layout");
Write_Line (" Lnn check max nest level < nn ");
Write_Line (" m check line length <= 79 characters");
Write_Line (" Mnn check line length <= nn characters");
Write_Line (" n check casing of package Standard identifiers");
Write_Line (" N turn off all checks");
Write_Line (" o check subprogram bodies in alphabetical order");
Write_Line (" O check overriding indicators");
Write_Line (" p check pragma casing");
Write_Line (" r check casing for identifier references");
Write_Line (" s check separate subprogram specs present");
Write_Line (" S check separate lines after THEN or ELSE");
Write_Line (" t check token separation rules");
Write_Line (" u check no unnecessary blank lines");
Write_Line (" x check extra parentheses around conditionals");
Write_Line (" y turn on default style checks");
Write_Line (" - subtract (turn off) subsequent checks");
Write_Line (" + add (turn on) subsequent checks");
-- Lines for -gnatyN switch
Write_Switch_Char ("yN");
Write_Line ("Cancel all previously set style checks");
-- Lines for -gnatzc switch
Write_Switch_Char ("zc");
Write_Line ("Distribution stub generation for caller stubs");
-- Lines for -gnatzr switch
Write_Switch_Char ("zr");
Write_Line ("Distribution stub generation for receiver stubs");
if not Latest_Ada_Only then
-- Line for -gnat83 switch
Write_Switch_Char ("83");
Write_Line ("Ada 83 mode");
-- Line for -gnat95 switch
Write_Switch_Char ("95");
if Ada_Version_Default = Ada_95 then
Write_Line ("Ada 95 mode (default)");
else
Write_Line ("Ada 95 mode");
end if;
-- Line for -gnat2005 switch
Write_Switch_Char ("2005");
if Ada_Version_Default = Ada_2005 then
Write_Line ("Ada 2005 mode (default)");
else
Write_Line ("Ada 2005 mode");
end if;
end if;
-- Line for -gnat2012 switch
Write_Switch_Char ("2012");
if Ada_Version_Default = Ada_2012 then
Write_Line ("Ada 2012 mode (default)");
else
Write_Line ("Ada 2012 mode");
end if;
-- Line for -gnat-p switch
Write_Switch_Char ("-p");
Write_Line ("Cancel effect of previous -gnatp switch");
end Usage;
|
package body gel.Camera.forge
is
function new_Camera return gel.Camera.item
is
begin
return the_Camera : gel.Camera.item
do
define (the_Camera);
end return;
end new_Camera;
function new_Camera return gel.Camera.view
is
Self : constant gel.Camera.view := new gel.Camera.item;
begin
Self.define;
return Self;
end new_Camera;
end gel.Camera.forge;
|
------------------------------------------------------------------------------
-- --
-- GNAT RUN-TIME LIBRARY (GNARL) COMPONENTS --
-- --
-- S Y S T E M . T A S K I N G . P R O T E C T E D _ O B J E C T S . --
-- M U L T I P R O C E S S O R S --
-- --
-- B o d y --
-- --
-- Copyright (C) 2010-2015, AdaCore --
-- --
-- GNARL is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. GNARL is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. --
-- --
-- --
-- --
-- --
-- --
-- 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/>. --
-- --
-- GNARL was developed by the GNARL team at Florida State University. --
-- Extensive contributions were provided by Ada Core Technologies, Inc. --
-- --
------------------------------------------------------------------------------
with System.Task_Primitives.Operations;
with System.Multiprocessors;
with System.Multiprocessors.Fair_Locks;
with System.Multiprocessors.Spin_Locks;
with System.OS_Interface;
with System.BB.Protection;
with System.BB.CPU_Primitives.Multiprocessors;
with System.BB.Threads.Queues;
package body System.Tasking.Protected_Objects.Multiprocessors is
use System.Multiprocessors;
use System.Multiprocessors.Spin_Locks;
use System.Multiprocessors.Fair_Locks;
package STPO renames System.Task_Primitives.Operations;
package BCPRMU renames System.BB.CPU_Primitives.Multiprocessors;
type Entry_Call_List is limited record
List : Entry_Call_Link;
Lock : Fair_Lock;
end record;
Served_Entry_Call : array (CPU) of Entry_Call_List :=
(others =>
(List => null,
Lock => (Spinning => (others => False),
Lock => (Flag => Unlocked))));
-- List of served Entry_Call for each CPU
------------
-- Served --
------------
procedure Served (Entry_Call : Entry_Call_Link) is
Caller : constant Task_Id := Entry_Call.Self;
Caller_CPU : constant CPU := STPO.Get_CPU (Caller);
begin
-- The entry caller is on a different CPU
-- We have to signal that the caller task is ready to be rescheduled,
-- but we are not allowed modify the ready queue of the other CPU. We
-- use the Served_Entry_Call list and a poke interrupt to signal that
-- the task is ready.
-- Disabled IRQ ensure atomicity of the operation. Atomicity plus Fair
-- locks ensure bounded execution time.
System.BB.CPU_Primitives.Disable_Interrupts;
Lock (Served_Entry_Call (Caller_CPU).Lock);
-- Add the entry call to the served list
Entry_Call.Next := Served_Entry_Call (Caller_CPU).List;
Served_Entry_Call (Caller_CPU).List := Entry_Call;
Unlock (Served_Entry_Call (Caller_CPU).Lock);
-- Enable interrupts
-- We need to set the hardware interrupt masking level equal to
-- the software priority of the task that is executing.
if System.BB.Threads.Queues.Running_Thread.Active_Priority in
Interrupt_Priority'Range
then
-- We need to mask some interrupts because we are executing at a
-- hardware interrupt priority.
System.BB.CPU_Primitives.Enable_Interrupts
(System.BB.Threads.Queues.Running_Thread.Active_Priority -
System.Interrupt_Priority'First + 1);
else
-- We are neither within an interrupt handler nor within task
-- that has a priority in the range of Interrupt_Priority, so
-- that no interrupt should be masked.
System.BB.CPU_Primitives.Enable_Interrupts (0);
end if;
if STPO.Get_Priority (Entry_Call.Self) >
System.OS_Interface.Current_Priority (Caller_CPU)
then
-- Poke the caller's CPU if the task has a higher priority
System.BB.CPU_Primitives.Multiprocessors.Poke_CPU (Caller_CPU);
end if;
end Served;
-------------------------
-- Wakeup_Served_Entry --
-------------------------
procedure Wakeup_Served_Entry is
CPU_Id : constant CPU := BCPRMU.Current_CPU;
Entry_Call : Entry_Call_Link;
begin
-- Interrupts are always disabled when entering here
Lock (Served_Entry_Call (CPU_Id).Lock);
Entry_Call := Served_Entry_Call (CPU_Id).List;
Served_Entry_Call (CPU_Id).List := null;
Unlock (Served_Entry_Call (CPU_Id).Lock);
while Entry_Call /= null loop
STPO.Wakeup (Entry_Call.Self, Entry_Caller_Sleep);
Entry_Call := Entry_Call.Next;
end loop;
end Wakeup_Served_Entry;
begin
System.BB.Protection.Wakeup_Served_Entry_Callback :=
Wakeup_Served_Entry'Access;
end System.Tasking.Protected_Objects.Multiprocessors;
|
pragma License (Unrestricted);
-- implementation unit
with Ada.Exceptions;
with System.Native_Tasks;
with System.Storage_Elements;
with System.Synchronous_Objects;
private with System.Unwind.Mapping;
package System.Tasks is
pragma Preelaborate;
-- same as somethings of Tasking
subtype Master_Level is Integer;
Foreign_Task_Level : constant Master_Level := 0;
Environment_Task_Level : constant Master_Level := 1;
Independent_Task_Level : constant Master_Level := 2;
Library_Task_Level : constant Master_Level := 3;
subtype Task_Entry_Index is Integer range 0 .. Integer'Last;
type Activation_Chain is limited private;
type Activation_Chain_Access is access all Activation_Chain;
for Activation_Chain_Access'Storage_Size use 0;
pragma No_Strict_Aliasing (Activation_Chain_Access);
procedure Raise_Abort_Signal;
pragma No_Return (Raise_Abort_Signal);
-- this shold be called when Standard'Abort_Signal
procedure When_Abort_Signal;
pragma Inline (When_Abort_Signal);
type Task_Record (<>) is limited private;
type Task_Id is access all Task_Record;
function Current_Task_Id return Task_Id
with Export, Convention => Ada, External_Name => "__drake_current_task";
function Environment_Task_Id return Task_Id;
pragma Pure_Function (Environment_Task_Id);
type Master_Record is limited private;
type Master_Access is access all Master_Record;
type Boolean_Access is access all Boolean;
for Boolean_Access'Storage_Size use 0;
procedure Create (
T : out Task_Id;
Params : Address;
Process : not null access procedure (Params : Address);
-- name
Name : String := "";
-- activation
Chain : Activation_Chain_Access := null;
Elaborated : Boolean_Access := null;
-- completion
Master : Master_Access := null;
-- rendezvous
Entry_Last_Index : Task_Entry_Index := 0);
procedure Wait (T : in out Task_Id; Aborted : out Boolean);
procedure Detach (T : in out Task_Id);
function Terminated (T : Task_Id) return Boolean;
function Activated (T : Task_Id) return Boolean;
type Free_Mode is (Wait, Detach);
pragma Discard_Names (Free_Mode);
function Preferred_Free_Mode (T : not null Task_Id) return Free_Mode;
procedure Set_Preferred_Free_Mode (
T : not null Task_Id;
Mode : Free_Mode);
pragma Inline (Preferred_Free_Mode);
procedure Get_Stack (
T : not null Task_Id;
Addr : out Address;
Size : out Storage_Elements.Storage_Count);
-- name
function Name (T : not null Task_Id)
return not null access constant String;
-- abort
procedure Send_Abort (T : not null Task_Id);
procedure Enable_Abort;
procedure Disable_Abort (Aborted : Boolean); -- check and disable
procedure Lock_Abort;
procedure Unlock_Abort;
function Is_Aborted return Boolean;
function Abort_Event return access Synchronous_Objects.Event;
-- for manual activation (Chain /= null)
function Elaborated (T : not null Task_Id) return Boolean;
procedure Accept_Activation (Aborted : out Boolean);
procedure Activate (
Chain : not null Activation_Chain_Access;
Aborted : out Boolean);
-- activate all task
procedure Activate (T : not null Task_Id); -- activate single task
procedure Move (
From, To : not null Activation_Chain_Access;
New_Master : Master_Access);
-- for manual completion (Master /= null)
function Parent (T : not null Task_Id) return Task_Id;
function Master_Level_Of (T : not null Task_Id) return Master_Level;
function Master_Within return Master_Level;
procedure Enter_Master;
procedure Leave_Master;
procedure Leave_All_Masters; -- for System.Tasking.Stages.Complete_Task
function Master_Of_Parent (Level : Master_Level) return Master_Access;
pragma Inline (Master_Level_Of);
-- for rendezvous
procedure Cancel_Calls; -- for System.Tasking.Stages.Complete_Task
procedure Call (
T : not null Task_Id;
Item : not null Synchronous_Objects.Queue_Node_Access);
procedure Uncall (
T : not null Task_Id;
Item : not null Synchronous_Objects.Queue_Node_Access;
Already_Taken : out Boolean);
procedure Accept_Call (
Item : out Synchronous_Objects.Queue_Node_Access;
Params : Address;
Filter : Synchronous_Objects.Queue_Filter;
Aborted : out Boolean);
function Call_Count (
T : not null Task_Id;
Params : Address;
Filter : Synchronous_Objects.Queue_Filter)
return Natural;
function Callable (T : not null Task_Id) return Boolean;
type Cancel_Call_Handler is access procedure (
X : in out Synchronous_Objects.Queue_Node_Access);
pragma Favor_Top_Level (Cancel_Call_Handler);
Cancel_Call_Hook : Cancel_Call_Handler := null;
-- attribute for Ada.Task_Attributes
type Attribute_Index is limited private;
procedure Allocate (Index : in out Attribute_Index);
procedure Free (Index : in out Attribute_Index);
procedure Query (
T : not null Task_Id;
Index : aliased in out Attribute_Index;
Process : not null access procedure (Item : Address));
procedure Set (
T : not null Task_Id;
Index : aliased in out Attribute_Index;
New_Item : not null access function return Address;
Finalize : not null access procedure (Item : Address));
procedure Reference (
T : not null Task_Id;
Index : aliased in out Attribute_Index;
New_Item : not null access function return Address;
Finalize : not null access procedure (Item : Address);
Result : out Address);
procedure Clear (
T : not null Task_Id;
Index : aliased in out Attribute_Index);
-- termination handler for Task_Termination
type Cause_Of_Termination is (Normal, Abnormal, Unhandled_Exception);
-- same as Ada.Task_Termination.Cause_Of_Termination
pragma Discard_Names (Cause_Of_Termination);
type Termination_Handler is access protected procedure (
Cause : Cause_Of_Termination;
T : Task_Id;
X : Ada.Exceptions.Exception_Occurrence);
-- same as Ada.Task_Termination.Termination_Handler
procedure Set_Dependents_Fallback_Handler (
T : Task_Id;
Handler : Termination_Handler);
function Dependents_Fallback_Handler (T : Task_Id)
return Termination_Handler;
pragma Inline (Dependents_Fallback_Handler);
procedure Set_Specific_Handler (
T : Task_Id;
Handler : Termination_Handler);
function Specific_Handler (T : Task_Id) return Termination_Handler;
pragma Inline (Specific_Handler);
private
type String_Access is access String;
type Counter is mod 2 ** 32;
for Counter'Size use 32;
type Activation_Error is (None, Any_Exception, Elaboration_Error);
pragma Discard_Names (Activation_Error);
type Activation_Chain_Data;
type Activation_Chain is access all Activation_Chain_Data;
for Activation_Chain'Size use Standard'Address_Size;
type Activation_Chain_Data is limited record
List : Task_Id;
Task_Count : Counter;
Activated_Count : aliased Counter;
Release_Count : aliased Counter;
Mutex : Synchronous_Objects.Mutex;
Condition_Variable : Synchronous_Objects.Condition_Variable;
Error : Activation_Error;
Merged : Activation_Chain;
Self : Activation_Chain_Access;
end record;
pragma Suppress_Initialization (Activation_Chain_Data);
type Task_Kind is (Environment, Sub);
pragma Discard_Names (Task_Kind);
type Finalize_Handler is access procedure (Params : Address);
type Attribute is record
Index : access Attribute_Index;
Item : Address;
Finalize : Finalize_Handler;
Previous : Task_Id;
Next : Task_Id;
end record;
pragma Suppress_Initialization (Attribute);
type Fixed_Attribute_Array is array (Natural) of Attribute;
pragma Suppress_Initialization (Fixed_Attribute_Array);
type Attribute_Array_Access is access all Fixed_Attribute_Array;
type Activation_State is range 0 .. 4;
for Activation_State'Size use 8;
pragma Atomic (Activation_State);
AS_Suspended : constant Activation_State := 0;
AS_Created : constant Activation_State := 1;
AS_Active_Before_Activation : Activation_State := 2;
AS_Active : constant Activation_State := 3;
AS_Error : constant Activation_State := 4;
type Termination_State is range 0 .. 2;
for Termination_State'Size use 8;
pragma Atomic (Termination_State);
TS_Active : constant Termination_State := 0;
TS_Detached : constant Termination_State := 1;
TS_Terminated : constant Termination_State := 2;
type Rendezvous_Record is limited record
Mutex : aliased Synchronous_Objects.Mutex;
Calling : aliased Synchronous_Objects.Queue;
end record;
pragma Suppress_Initialization (Rendezvous_Record);
type Rendezvous_Access is access Rendezvous_Record;
type Abort_Handler is access procedure (T : Task_Id);
pragma Favor_Top_Level (Abort_Handler);
type Process_Handler is access procedure (Params : Address);
type Task_Record (Kind : Task_Kind) is limited record
Handle : aliased Native_Tasks.Handle_Type;
Aborted : Boolean;
pragma Atomic (Aborted);
Abort_Handler : Tasks.Abort_Handler;
Abort_Locking : Natural;
Abort_Event : aliased Synchronous_Objects.Event;
Attributes : Attribute_Array_Access;
Attributes_Length : Natural;
-- activation / completion
Activation_State : aliased Tasks.Activation_State;
Termination_State : aliased Tasks.Termination_State;
Master_Level : Tasks.Master_Level; -- level of self
Master_Top : Master_Access; -- stack
-- termination handler
Dependents_Fallback_Handler : Termination_Handler;
-- for sub task
case Kind is
when Environment =>
null;
when Sub =>
Params : Address;
Process : not null Process_Handler;
-- free mode
Preferred_Free_Mode : Free_Mode;
-- name
Name : String_Access;
-- manual activation
Activation_Chain : Tasks.Activation_Chain;
Next_Of_Activation_Chain : Task_Id;
Activation_Chain_Living : Boolean;
Elaborated : Boolean_Access;
-- manual completion
Master_Of_Parent : Master_Access;
Previous_At_Same_Level : Task_Id;
Next_At_Same_Level : Task_Id;
Auto_Detach : Boolean;
-- rendezvous
Rendezvous : Rendezvous_Access;
-- termination handler
Specific_Handler : Termination_Handler;
-- signal alt stack
Signal_Stack : aliased Unwind.Mapping.Signal_Stack_Type;
end case;
end record;
pragma Suppress_Initialization (Task_Record);
type Master_Record is limited record
Previous : Master_Access; -- previous item in stack
Parent : Task_Id;
Within : Master_Level; -- level of stack
List : Task_Id; -- ringed list
Mutex : aliased Synchronous_Objects.Mutex;
end record;
pragma Suppress_Initialization (Master_Record);
-- type TLS_Index is new C.pthread.pthread_key_t;
type Attribute_Index is limited record
Index : Integer range -1 .. Integer'Last;
List : aliased Task_Id;
Mutex : aliased Synchronous_Objects.Mutex;
end record;
pragma Suppress_Initialization (Attribute_Index);
end System.Tasks;
|
-----------------------------------------------------------------------
-- keystore-buffers -- Buffer management for the keystore
-- Copyright (C) 2019, 2020 Stephane Carrez
-- Written by Stephane Carrez (Stephane.Carrez@gmail.com)
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-----------------------------------------------------------------------
with Ada.Streams;
with Ada.Containers.Ordered_Maps;
with Util.Refs;
with Util.Strings;
private package Keystore.Buffers is
use Ada.Streams;
BT_HMAC_HEADER_SIZE : constant := 32;
-- Data block size defined to a 4K to map system page.
Block_Size : constant := 4096;
BT_DATA_SIZE : constant := Block_Size - BT_HMAC_HEADER_SIZE;
subtype Buffer_Size is Stream_Element_Offset range 0 .. BT_DATA_SIZE;
subtype Block_Index is Stream_Element_Offset range 1 .. BT_DATA_SIZE;
subtype IO_Block_Type is Stream_Element_Array (1 .. Block_Size);
subtype Block_Type is Stream_Element_Array (Block_Index);
function Image (Value : Block_Index) return String is
(Util.Strings.Image (Natural (Value)));
type Block_Count is new Interfaces.Unsigned_32;
subtype Block_Number is Block_Count range 1 .. Block_Count'Last;
type Storage_Identifier is new Interfaces.Unsigned_32;
type Storage_Block is record
Storage : Storage_Identifier := 0;
Block : Block_Number := Block_Number'First;
end record;
-- Get a printable representation of storage block for the logs.
function To_String (Value : in Storage_Block) return String;
-- Order the two values on the storage and block number.
function "<" (Left, Right : in Storage_Block) return Boolean is
(Left.Storage < Right.Storage or else
(Left.Storage = Right.Storage and then Left.Block < Right.Block));
type Data_Buffer_Type is limited record
Data : Block_Type;
end record;
package Buffer_Refs is new Util.Refs.General_References (Data_Buffer_Type);
subtype Buffer_Type is Buffer_Refs.Ref;
subtype Buffer_Accessor is Buffer_Refs.Element_Accessor;
type Storage_Buffer is record
Block : Storage_Block;
Data : Buffer_Type;
end record;
function Is_Null (Buffer : in Storage_Buffer) return Boolean is (Buffer.Data.Is_Null);
-- Order the two buffers on the storage and block number.
function "<" (Left, Right : in Storage_Buffer) return Boolean is (Left.Block < Right.Block);
-- A set of buffers ordered by storage and block number.
package Buffer_Maps is
new Ada.Containers.Ordered_Maps (Key_Type => Storage_Block,
Element_Type => Buffer_Type,
"<" => "<",
"=" => Buffer_Refs."=");
subtype Buffer_Map is Buffer_Maps.Map;
subtype Buffer_Cursor is Buffer_Maps.Cursor;
-- Find a buffer from the container.
function Find (Container : in Buffer_Map;
Block : in Storage_Block) return Storage_Buffer;
-- Allocate a buffer for the storage block.
function Allocate (Block : in Storage_Block) return Storage_Buffer;
end Keystore.Buffers;
|
with STM32.Board; use STM32.Board;
with Circles; use Circles;
with Rectangles; use Rectangles;
package body Renderer is
procedure Render(W : in out World; Cue : VisualCue)
is
begin
RenderList(W.GetEnvironments);
RenderList(W.GetEntities, Cue.Selected);
RenderLinksList(W.GetLinks);
RenderCue(Cue);
Display.Update_Layer(1, Copy_Back => True);
end Render;
-- TODO implement GetRandomBezierPointFor & make one for springs (maybe)
procedure RenderLinksList(L : LinksListAcc)
is
use LinksList;
Curs : LinksList.Cursor := L.First;
CurLink : LinkAcc;
begin
while Curs /= LinksList.No_Element loop
CurLink := LinksList.Element(Curs);
Display.Hidden_Buffer(1).Set_Source(GetLinkColor(CurLink));
case CurLink.LinkType is
when LTRope => DrawRope(CurLink);
when LTSpring => DrawSpring(CurLink);
end case;
Curs := LinksList.Next(Curs);
end loop;
end RenderLinksList;
procedure DrawRope(Link : LinkAcc)
is
begin
Display.Hidden_Buffer(1).Bezier((GetCenteredPos(Link.A),
GetBezierPoint(Link, 1, 3),
GetBezierPoint(Link, 2, 3),
GetCenteredPos(Link.B)), 20, 1);
end DrawRope;
procedure DrawSpring(Link : LinkAcc)
is
Dist : constant Float := 10.0; -- Dist > 0.0
N : constant Natural := Natural(Link.RestLen / Dist);
PLast : Point := GetBezierPoint(Link, 0, N, Dist);
PNext : Point;
begin
if N = 0 then
Display.Hidden_Buffer(1).Draw_Line(PLast, GetCenteredPos(Link.B), 1);
else
for I in 1 .. N loop
PNext := GetBezierPoint(Link, I, N, Dist);
Display.Hidden_Buffer(1).Draw_Line(PLast, PNext, 1);
PLast := PNext;
end loop;
end if;
end DrawSpring;
function GetCenteredPos(E : EntityClassAcc) return Point
is
begin
return GetIntCoords(E.GetPosition);
end GetCenteredPos;
function GetBezierPoint(Link : LinkAcc; i : Natural; n : Positive; UseMul : Float := 0.0) return Point
is
P0 : constant Vec2D := Link.A.GetPosition;
Pn : constant Vec2D := Link.B.GetPosition;
Len : constant Float := Mag(Pn - P0);
Dir : constant Vec2D := (1.0 / Len) * (Pn - P0);
Normal : constant Vec2D := Dir.Normal;
X : constant Float := (if UseMul = 0.0 then Link.RestLen - Len else UseMul);
Pi : Vec2D := ((Len / Float(n)) * Float(i) * Dir) + P0;
begin
if i = 0 then return GetIntCoords(P0); end if;
if i = n then return GetIntCoords(Pn); end if;
if X < 0.0 and UseMul = 0.0 then return GetIntCoords(P0); end if;
Pi := ((if i mod 2 = 0 then 1.0 else -1.0) * Normal * X) + Pi;
return GetIntCoords(Pi);
end GetBezierPoint;
procedure RenderCue(Cue : VisualCue) is
begin
if Cue.R >= 0 then
Display.Hidden_Buffer(1).Set_Source(GetColor(Cue.Mat));
case Cue.EntType is
when EntCircle =>
Display.Hidden_Buffer(1).Draw_Circle((Cue.X, Cue.Y), Cue.R);
when EntRectangle =>
Display.Hidden_Buffer(1).Draw_Rect(((Cue.X, Cue.Y), Cue.R, Cue.R));
end case;
end if;
end RenderCue;
procedure RenderList(L : EntsListAcc; Selected : EntityClassAcc := null)
is
use EntsList;
Curs : EntsList.Cursor := L.First;
E : EntityClassAcc;
begin
while Curs /= EntsList.No_Element loop
E := EntsList.Element(Curs);
if E /= Selected then
Display.Hidden_Buffer(1).Set_Source(GetColor(E.Mat));
else
Display.Hidden_Buffer(1).Set_Source(Opposite(GetColor(E.Mat)));
end if;
case E.all.EntityType is
when EntCircle =>
declare
C : constant CircleAcc := CircleAcc(E);
begin
if C.all.InvMass = 0.0 or else not IsSolidMaterial(C.Mat) then
Display.Hidden_Buffer(1).Fill_Circle
(
Center => GetIntCoords(C.all.Coords),
Radius => Integer(C.all.Radius)
);
else
Display.Hidden_Buffer(1).Draw_Circle
(
Center => GetIntCoords(C.all.Coords),
Radius => Integer(C.all.Radius)
);
end if;
end;
when EntRectangle =>
declare
R : constant RectangleAcc := RectangleAcc(E);
begin
if R.all.InvMass = 0.0 or else not IsSolidMaterial(R.Mat) then
Display.Hidden_Buffer(1).Fill_Rect
(
Area => (Position => GetIntCoords(R.all.Coords),
Height => Natural(R.all.GetHeight),
Width => Natural(R.all.GetWidth))
);
else
Display.Hidden_Buffer(1).Draw_Rect
(
Area => (Position => GetIntCoords(R.all.Coords),
Height => Natural(R.all.GetHeight),
Width => Natural(R.all.GetWidth))
);
end if;
end;
end case;
Curs := EntsList.Next(Curs);
end loop;
end RenderList;
function GetColor(Mat : in Material) return Bitmap_Color
is
begin
case Mat.MType is
when MTStatic => return Green;
when MTSteel => return Silver;
when MTIce => return Blue;
when MTConcrete => return Grey;
when MTRubber => return Red;
when MTWood => return Brown;
when MTBalloon => return White;
when ETVacuum => return Black;
when ETAir => return Dim_Grey;
when ETWater => return Aqua;
end case;
end GetColor;
function GetLinkColor(L : LinkAcc) return Bitmap_Color
is
begin
if L.Factor = LinkTypesFactors(LTRope) then
return Red;
elsif L.Factor = LinkTypesFactors(LTSpring) then
return Orange;
end if;
return White;
end GetLinkColor;
function InvalidEnt(E : EntityClassAcc) return Boolean
is
begin
if E = null then return True; end if;
if E.Coords.x < 0.0 or E.Coords.x > 240.0 then return True; end if;
if E.Coords.y < 0.0 or E.Coords.y > 320.0 then return True; end if;
return False;
end InvalidEnt;
function GetIntCoords(flCoords : Vec2D) return Point
is
retCoords : Vec2D;
begin
retCoords := flCoords;
if retCoords.x < 0.0 or retCoords.x > 240.0 then
retCoords.x := 0.0;
end if;
if retCoords.y < 0.0 or retCoords.y > 320.0 then
retCoords.y := 0.0;
end if;
return Point'(Natural(retCoords.x), Natural(retCoords.y));
end getIntCoords;
end Renderer;
|
-----------------------------------------------------------------------
-- gen-model-mappings -- Type mappings for Code Generator
-- Copyright (C) 2011, 2012 Stephane Carrez
-- Written by Stephane Carrez (Stephane.Carrez@gmail.com)
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-----------------------------------------------------------------------
with Ada.Strings.Unbounded;
with Ada.Containers.Hashed_Maps;
with Ada.Strings.Unbounded.Hash;
with Util.Beans.Objects;
-- The <b>Gen.Model.Mappings</b> package controls the mappings to convert an XML
-- type into the Ada type.
package Gen.Model.Mappings is
ADA_MAPPING : constant String := "Ada05";
MySQL_MAPPING : constant String := "MySQL";
SQLite_MAPPING : constant String := "SQLite";
type Basic_Type is (T_BOOLEAN, T_INTEGER, T_DATE, T_ENUM, T_IDENTIFIER, T_STRING, T_BLOB,
T_BEAN, T_TABLE);
-- ------------------------------
-- Mapping Definition
-- ------------------------------
type Mapping_Definition is new Definition with record
Target : Ada.Strings.Unbounded.Unbounded_String;
Kind : Basic_Type := T_INTEGER;
end record;
type Mapping_Definition_Access is access all Mapping_Definition'Class;
-- Get the value identified by the name.
-- If the name cannot be found, the method should return the Null object.
overriding
function Get_Value (From : Mapping_Definition;
Name : String) return Util.Beans.Objects.Object;
-- Find the mapping for the given type name.
function Find_Type (Name : in Ada.Strings.Unbounded.Unbounded_String)
return Mapping_Definition_Access;
procedure Register_Type (Name : in String;
Mapping : in Mapping_Definition_Access;
Kind : in Basic_Type);
-- Register a type mapping <b>From</b> that is mapped to <b>Target</b>.
procedure Register_Type (Target : in String;
From : in String;
Kind : in Basic_Type);
-- Setup the type mapping for the language identified by the given name.
procedure Set_Mapping_Name (Name : in String);
package Mapping_Maps is
new Ada.Containers.Hashed_Maps (Key_Type => Ada.Strings.Unbounded.Unbounded_String,
Element_Type => Mapping_Definition_Access,
Hash => Ada.Strings.Unbounded.Hash,
Equivalent_Keys => Ada.Strings.Unbounded."=");
subtype Map is Mapping_Maps.Map;
subtype Cursor is Mapping_Maps.Cursor;
end Gen.Model.Mappings;
|
-----------------------------------------------------------------------
-- ASF testsuite - Ada Server Faces Test suite
-- Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2018 Stephane Carrez
-- Written by Stephane Carrez (Stephane.Carrez@gmail.com)
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-----------------------------------------------------------------------
with ASF.Contexts.Writer.Tests;
with ASF.Views.Facelets.Tests;
with ASF.Applications.Views.Tests;
with ASF.Applications.Main.Tests;
with ASF.Contexts.Faces.Tests;
with ASF.Applications.Tests;
with ASF.Lifecycles.Tests;
with ASF.Navigations.Tests;
with ASF.Models.Selects.Tests;
with ASF.Converters.Tests;
package body ASF.Testsuite is
Tests : aliased Util.Tests.Test_Suite;
function Suite return Util.Tests.Access_Test_Suite is
Ret : constant Util.Tests.Access_Test_Suite := Tests'Access;
begin
ASF.Contexts.Writer.Tests.Add_Tests (Ret);
ASF.Contexts.Faces.Tests.Add_Tests (Ret);
ASF.Converters.Tests.Add_Tests (Ret);
ASF.Models.Selects.Tests.Add_Tests (Ret);
ASF.Views.Facelets.Tests.Add_Tests (Ret);
ASF.Lifecycles.Tests.Add_Tests (Ret);
ASF.Navigations.Tests.Add_Tests (Ret);
ASF.Applications.Main.Tests.Add_Tests (Ret);
ASF.Applications.Views.Tests.Add_Tests (Ret);
-- Run the application tests at the end.
ASF.Applications.Tests.Add_Tests (Ret);
return Ret;
end Suite;
end ASF.Testsuite;
|
with System.Debug; -- assertions
with C.errno;
with C.sched;
with C.signal;
package body System.Native_Tasks is
use type C.signed_int;
use type C.unsigned_int;
type sigaction_Wrapper is record -- ??? for No_Elaboration_Code
Handle : aliased C.signal.struct_sigaction;
end record;
pragma Suppress_Initialization (sigaction_Wrapper);
Old_SIGTERM_Action : aliased sigaction_Wrapper; -- uninitialized
Installed_Abort_Handler : Abort_Handler;
procedure SIGTERM_Handler (
Signal_Number : C.signed_int;
Info : access C.signal.siginfo_t;
Context : C.void_ptr)
with Convention => C;
procedure SIGTERM_Handler (
Signal_Number : C.signed_int;
Info : access C.signal.siginfo_t;
Context : C.void_ptr)
is
pragma Unreferenced (Signal_Number);
pragma Unreferenced (Info);
pragma Unreferenced (Context);
begin
Installed_Abort_Handler.all;
end SIGTERM_Handler;
procedure Mask_SIGTERM (How : C.signed_int);
procedure Mask_SIGTERM (How : C.signed_int) is
Mask : aliased C.signal.sigset_t;
errno : C.signed_int;
Dummy_R : C.signed_int;
begin
Dummy_R := C.signal.sigemptyset (Mask'Access);
Dummy_R := C.signal.sigaddset (Mask'Access, C.signal.SIGTERM);
errno := C.pthread.pthread_sigmask (How, Mask'Access, null);
pragma Check (Debug,
Check =>
errno = 0 or else Debug.Runtime_Error ("pthread_sigmask failed"));
end Mask_SIGTERM;
-- implementation of thread
procedure Create (
Handle : aliased out Handle_Type;
Parameter : Parameter_Type;
Thread_Body : Thread_Body_Type;
Error : out Boolean) is
begin
Error := C.pthread.pthread_create (
Handle'Access,
null,
Thread_Body.all'Access, -- type is different between platforms
Parameter) /= 0;
end Create;
procedure Join (
Handle : Handle_Type; -- of target thread
Current_Abort_Event : access Synchronous_Objects.Event;
Result : aliased out Result_Type;
Error : out Boolean)
is
pragma Unreferenced (Current_Abort_Event);
begin
Error := C.pthread.pthread_join (Handle, Result'Access) /= 0;
end Join;
procedure Detach (
Handle : Handle_Type;
Error : out Boolean) is
begin
Error := C.pthread.pthread_detach (Handle) /= 0;
end Detach;
-- implementation of stack
function Info_Block (Handle : Handle_Type) return C.pthread.pthread_t is
begin
return Handle;
end Info_Block;
-- implementation of signals
procedure Install_Abort_Handler (Handler : Abort_Handler) is
act : aliased C.signal.struct_sigaction := (
(Unchecked_Tag => 1, sa_sigaction => SIGTERM_Handler'Access),
others => <>); -- uninitialized
R : C.signed_int;
Dummy_R : C.signed_int;
begin
Installed_Abort_Handler := Handler;
act.sa_flags := C.signal.SA_SIGINFO;
Dummy_R := C.signal.sigemptyset (act.sa_mask'Access);
R := C.signal.sigaction (
C.signal.SIGTERM,
act'Access,
Old_SIGTERM_Action.Handle'Access);
pragma Check (Debug,
Check =>
not (R < 0) or else Debug.Runtime_Error ("sigaction failed"));
end Install_Abort_Handler;
procedure Uninstall_Abort_Handler is
R : C.signed_int;
begin
R := C.signal.sigaction (
C.signal.SIGTERM,
Old_SIGTERM_Action.Handle'Access,
null);
pragma Check (Debug,
Check =>
not (R < 0) or else Debug.Runtime_Error ("sigaction failed"));
end Uninstall_Abort_Handler;
procedure Send_Abort_Signal (
Handle : Handle_Type;
Abort_Event : in out Synchronous_Objects.Event;
Error : out Boolean) is
begin
-- write to the pipe
Synchronous_Objects.Set (Abort_Event);
-- send SIGTERM
Resend_Abort_Signal (Handle, Error => Error);
end Send_Abort_Signal;
procedure Resend_Abort_Signal (Handle : Handle_Type; Error : out Boolean) is
begin
case C.pthread.pthread_kill (Handle, C.signal.SIGTERM) is
when 0 =>
Yield;
Error := False;
when C.errno.ESRCH =>
Error := False; -- it is already terminated, C9A003A
when others =>
Error := True;
end case;
end Resend_Abort_Signal;
procedure Block_Abort_Signal (Abort_Event : Synchronous_Objects.Event) is
pragma Unreferenced (Abort_Event);
begin
Mask_SIGTERM (C.signal.SIG_BLOCK);
end Block_Abort_Signal;
procedure Unblock_Abort_Signal is
begin
Mask_SIGTERM (C.signal.SIG_UNBLOCK);
end Unblock_Abort_Signal;
procedure Yield is
R : C.signed_int;
begin
R := C.sched.sched_yield;
pragma Check (Debug,
Check =>
not (R < 0) or else Debug.Runtime_Error ("sched_yield failed"));
end Yield;
end System.Native_Tasks;
|
-- { dg-do run }
procedure Sizetype2 is
function Ident_Int (X : Integer) return Integer is
begin
return X;
end;
type A is array (Integer range <>) of Boolean;
subtype T1 is A (Ident_Int (- 6) .. Ident_Int (Integer'Last - 4));
subtype T2 is A (- 6 .. Ident_Int (Integer'Last - 4));
subtype T3 is A (Ident_Int (- 6) .. Integer'Last - 4);
begin
if T1'Size /= 17179869200 then
raise Program_Error;
end if;
if T2'Size /= 17179869200 then
raise Program_Error;
end if;
if T3'Size /= 17179869200 then
raise Program_Error;
end if;
end;
|
-- Copyright 2018-2021 Bartek thindil Jasicki
--
-- This file is part of Steam Sky.
--
-- Steam Sky 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.
--
-- Steam Sky 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 Steam Sky. If not, see <http://www.gnu.org/licenses/>.
with Ada.Containers.Hashed_Maps; use Ada.Containers;
with Ada.Strings.Unbounded.Hash;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
with DOM.Readers; use DOM.Readers;
with Game; use Game;
-- ****h* Careers/Careers
-- FUNCTION
-- Provide code for characters careers
-- SOURCE
package Careers is
-- ****
-- ****s* Careers/Careers.Career_Record
-- FUNCTION
-- Data structure for player career
-- PARAMETERS
-- Name - Name of career, displayed to player
-- Skills - List of skills which have bonuses to experience if player
-- select this career
-- SOURCE
type Career_Record is record
Name: Unbounded_String;
Skills: UnboundedString_Container.Vector;
end record;
-- ****
-- ****t* Careers/Careers.Careers_Container
-- FUNCTION
-- Used to store all available careers
-- SOURCE
package Careers_Container is new Hashed_Maps
(Key_Type => Unbounded_String, Element_Type => Career_Record,
Hash => Ada.Strings.Unbounded.Hash, Equivalent_Keys => "=");
-- ****
-- ****v* Careers/Careers.Careers_List
-- FUNCTION
-- List of all available careers for player
-- SOURCE
Careers_List: Careers_Container.Map;
-- ****
-- ****f* Careers/Careers.Load_Careers
-- FUNCTION
-- Load player careers from file
-- PARAMETERS
-- Reader - XML Reader from which careers will be read
-- SOURCE
procedure Load_Careers(Reader: Tree_Reader);
-- ****
end Careers;
|
-- This file is covered by the Internet Software Consortium (ISC) License
-- Reference: ../License.txt
with Ada.Text_IO;
package body Options_Dialog_Console is
package TIO renames Ada.Text_IO;
--------------------------------------------------------------------------------------------
-- check_ravenports_version
--------------------------------------------------------------------------------------------
function launch_dialog (specification : in out PSP.Portspecs) return Boolean
is
pragma Unreferenced (specification);
begin
TIO.Put_Line ("ravenadm has been built without curses support.");
TIO.Put_Line ("The ability to change standard options is therefore disabled.");
return False;
end launch_dialog;
end Options_Dialog_Console;
|
-- BSD 2-Clause License
--
-- Copyright (c) 2017, Zack Boll
-- 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.
--
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
-- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-- POSSIBILITY OF SUCH DAMAGE.
with Ada.Finalization;
with Interfaces.C.Extensions;
package Interfaces_CPP.Strings is
--
-- Ada friendly representation of C++ string
--
type CPP_String is new Ada.Finalization.Controlled with private;
--
-- Type to be used when interfacing with external binding code
--
type CPP_String_External is new Interfaces.C.Extensions.void_ptr;
-- equivalent to empty string constructor
overriding procedure Initialize (Object : in out CPP_String);
-- copy constructor
overriding procedure Adjust (Object : in out CPP_String);
-- deconstructor
overriding procedure Finalize (Object : in out CPP_String);
-- Returns Ada String representation
function To_Ada (Object: CPP_String) return String;
function To_Ada (External: CPP_String_External) return String;
-- Return C++ representation of Ada string
function To_CPP (Input: String) return CPP_String;
function To_CPP_External (Input: CPP_String) return CPP_String_External;
function Image (Object: CPP_String) return String renames To_Ada;
private
type CPP_String is new Ada.Finalization.Controlled with
record
cpp_str : CPP_String_External;
end record;
end Interfaces_CPP.Strings;
|
with RCP;
with RCP.Control;
with RCP.User;
procedure Main is
use RCP, RCP.Control, RCP.User;
-- user 1 needs 3 resources and "uses them" 8 seconds at a time
One : User_T (1, Short, 3, 8);
-- user 2 needs 2 resources and "uses them" 12 seconds at a time
Two : User_T (2, Short, 2, 12);
-- user 3 needs 4 resources and "uses them" 16 seconds at a time
Three : User_T (3, Medium, 4, 16);
-- user 4 needs 1 resource and "uses them" 20 seconds at a time
Four : User_T (4, Medium, 1, 20);
-- user 5 needs 5 resources and "uses them" 24 seconds at a time
Five : User_T (5, Long, 5, 24);
-- user 6 needs 6 resources and "uses them" 28 seconds at a time
Six : User_T (6, Long, 6, 28);
begin
null;
end Main;
|
-- Copyright (c) 2019 Maxim Reznik <reznikmm@gmail.com>
--
-- SPDX-License-Identifier: MIT
-- License-Filename: LICENSE
-------------------------------------------------------------
package body Program.Nodes.Subtype_Indications is
function Create
(Not_Token : Program.Lexical_Elements.Lexical_Element_Access;
Null_Token : Program.Lexical_Elements.Lexical_Element_Access;
Subtype_Mark : not null Program.Elements.Expressions.Expression_Access;
Constraint : Program.Elements.Constraints.Constraint_Access)
return Subtype_Indication is
begin
return Result : Subtype_Indication :=
(Not_Token => Not_Token, Null_Token => Null_Token,
Subtype_Mark => Subtype_Mark, Constraint => Constraint,
Enclosing_Element => null)
do
Initialize (Result);
end return;
end Create;
function Create
(Subtype_Mark : not null Program.Elements.Expressions
.Expression_Access;
Constraint : Program.Elements.Constraints.Constraint_Access;
Is_Part_Of_Implicit : Boolean := False;
Is_Part_Of_Inherited : Boolean := False;
Is_Part_Of_Instance : Boolean := False;
Has_Not_Null : Boolean := False)
return Implicit_Subtype_Indication is
begin
return Result : Implicit_Subtype_Indication :=
(Subtype_Mark => Subtype_Mark, Constraint => Constraint,
Is_Part_Of_Implicit => Is_Part_Of_Implicit,
Is_Part_Of_Inherited => Is_Part_Of_Inherited,
Is_Part_Of_Instance => Is_Part_Of_Instance,
Has_Not_Null => Has_Not_Null, Enclosing_Element => null)
do
Initialize (Result);
end return;
end Create;
overriding function Subtype_Mark
(Self : Base_Subtype_Indication)
return not null Program.Elements.Expressions.Expression_Access is
begin
return Self.Subtype_Mark;
end Subtype_Mark;
overriding function Constraint
(Self : Base_Subtype_Indication)
return Program.Elements.Constraints.Constraint_Access is
begin
return Self.Constraint;
end Constraint;
overriding function Not_Token
(Self : Subtype_Indication)
return Program.Lexical_Elements.Lexical_Element_Access is
begin
return Self.Not_Token;
end Not_Token;
overriding function Null_Token
(Self : Subtype_Indication)
return Program.Lexical_Elements.Lexical_Element_Access is
begin
return Self.Null_Token;
end Null_Token;
overriding function Has_Not_Null
(Self : Subtype_Indication)
return Boolean is
begin
return Self.Null_Token.Assigned;
end Has_Not_Null;
overriding function Is_Part_Of_Implicit
(Self : Implicit_Subtype_Indication)
return Boolean is
begin
return Self.Is_Part_Of_Implicit;
end Is_Part_Of_Implicit;
overriding function Is_Part_Of_Inherited
(Self : Implicit_Subtype_Indication)
return Boolean is
begin
return Self.Is_Part_Of_Inherited;
end Is_Part_Of_Inherited;
overriding function Is_Part_Of_Instance
(Self : Implicit_Subtype_Indication)
return Boolean is
begin
return Self.Is_Part_Of_Instance;
end Is_Part_Of_Instance;
overriding function Has_Not_Null
(Self : Implicit_Subtype_Indication)
return Boolean is
begin
return Self.Has_Not_Null;
end Has_Not_Null;
procedure Initialize
(Self : aliased in out Base_Subtype_Indication'Class) is
begin
Set_Enclosing_Element (Self.Subtype_Mark, Self'Unchecked_Access);
if Self.Constraint.Assigned then
Set_Enclosing_Element (Self.Constraint, Self'Unchecked_Access);
end if;
null;
end Initialize;
overriding function Is_Subtype_Indication_Element
(Self : Base_Subtype_Indication)
return Boolean is
pragma Unreferenced (Self);
begin
return True;
end Is_Subtype_Indication_Element;
overriding function Is_Definition_Element
(Self : Base_Subtype_Indication)
return Boolean is
pragma Unreferenced (Self);
begin
return True;
end Is_Definition_Element;
overriding procedure Visit
(Self : not null access Base_Subtype_Indication;
Visitor : in out Program.Element_Visitors.Element_Visitor'Class) is
begin
Visitor.Subtype_Indication (Self);
end Visit;
overriding function To_Subtype_Indication_Text
(Self : aliased in out Subtype_Indication)
return Program.Elements.Subtype_Indications
.Subtype_Indication_Text_Access is
begin
return Self'Unchecked_Access;
end To_Subtype_Indication_Text;
overriding function To_Subtype_Indication_Text
(Self : aliased in out Implicit_Subtype_Indication)
return Program.Elements.Subtype_Indications
.Subtype_Indication_Text_Access is
pragma Unreferenced (Self);
begin
return null;
end To_Subtype_Indication_Text;
end Program.Nodes.Subtype_Indications;
|
------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- P R J . N M S C --
-- --
-- S p e c --
-- --
-- Copyright (C) 2000-2011, 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. --
-- --
------------------------------------------------------------------------------
-- Find source dirs and source files for a project
with Prj.Tree;
private package Prj.Nmsc is
procedure Process_Naming_Scheme
(Tree : Project_Tree_Ref;
Root_Project : Project_Id;
Node_Tree : Prj.Tree.Project_Node_Tree_Ref;
Flags : Processing_Flags);
-- Perform consistency and semantic checks on all the projects in the tree.
-- This procedure interprets the various case statements in the project
-- based on the current external references. After checking the validity of
-- the naming scheme, it searches for all the source files of the project.
-- The result of this procedure is a filled-in data structure for
-- Project_Id which contains all the information about the project. This
-- information is only valid while the external references are preserved.
procedure Process_Aggregated_Projects
(Tree : Project_Tree_Ref;
Project : Project_Id;
Node_Tree : Prj.Tree.Project_Node_Tree_Ref;
Flags : Processing_Flags);
-- Assuming Project is an aggregate project, find out (based on the
-- current external references) what are the projects it aggregates.
-- This has to be done in phase 1 of the processing, so that we know the
-- full list of languages required for root_project and its aggregated
-- projects. As a result, it cannot be done as part of
-- Process_Naming_Scheme.
end Prj.Nmsc;
|
with
Interfaces.C.Strings,
System;
use type
Interfaces.C.int,
System.Address;
package body FLTK.Widgets.Valuators.Adjusters is
procedure adjuster_set_draw_hook
(W, D : in System.Address);
pragma Import (C, adjuster_set_draw_hook, "adjuster_set_draw_hook");
pragma Inline (adjuster_set_draw_hook);
procedure adjuster_set_handle_hook
(W, H : in System.Address);
pragma Import (C, adjuster_set_handle_hook, "adjuster_set_handle_hook");
pragma Inline (adjuster_set_handle_hook);
function new_fl_adjuster
(X, Y, W, H : in Interfaces.C.int;
Text : in Interfaces.C.char_array)
return System.Address;
pragma Import (C, new_fl_adjuster, "new_fl_adjuster");
pragma Inline (new_fl_adjuster);
procedure free_fl_adjuster
(A : in System.Address);
pragma Import (C, free_fl_adjuster, "free_fl_adjuster");
pragma Inline (free_fl_adjuster);
function fl_adjuster_is_soft
(A : in System.Address)
return Interfaces.C.int;
pragma Import (C, fl_adjuster_is_soft, "fl_adjuster_is_soft");
pragma Inline (fl_adjuster_is_soft);
procedure fl_adjuster_set_soft
(A : in System.Address;
T : in Interfaces.C.int);
pragma Import (C, fl_adjuster_set_soft, "fl_adjuster_set_soft");
pragma Inline (fl_adjuster_set_soft);
procedure fl_adjuster_draw
(W : in System.Address);
pragma Import (C, fl_adjuster_draw, "fl_adjuster_draw");
pragma Inline (fl_adjuster_draw);
function fl_adjuster_handle
(W : in System.Address;
E : in Interfaces.C.int)
return Interfaces.C.int;
pragma Import (C, fl_adjuster_handle, "fl_adjuster_handle");
pragma Inline (fl_adjuster_handle);
procedure Finalize
(This : in out Adjuster) is
begin
if This.Void_Ptr /= System.Null_Address and then
This in Adjuster'Class
then
free_fl_adjuster (This.Void_Ptr);
This.Void_Ptr := System.Null_Address;
end if;
Finalize (Valuator (This));
end Finalize;
package body Forge is
function Create
(X, Y, W, H : in Integer;
Text : in String)
return Adjuster is
begin
return This : Adjuster do
This.Void_Ptr := new_fl_adjuster
(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));
adjuster_set_draw_hook (This.Void_Ptr, Draw_Hook'Address);
adjuster_set_handle_hook (This.Void_Ptr, Handle_Hook'Address);
end return;
end Create;
end Forge;
function Is_Soft
(This : in Adjuster)
return Boolean is
begin
return fl_adjuster_is_soft (This.Void_Ptr) /= 0;
end Is_Soft;
procedure Set_Soft
(This : in out Adjuster;
To : in Boolean) is
begin
fl_adjuster_set_soft (This.Void_Ptr, Boolean'Pos (To));
end Set_Soft;
procedure Draw
(This : in out Adjuster) is
begin
fl_adjuster_draw (This.Void_Ptr);
end Draw;
function Handle
(This : in out Adjuster;
Event : in Event_Kind)
return Event_Outcome is
begin
return Event_Outcome'Val
(fl_adjuster_handle (This.Void_Ptr, Event_Kind'Pos (Event)));
end Handle;
end FLTK.Widgets.Valuators.Adjusters;
|
package body Array_Swapping
is
procedure Swap (A: in out ArrayType; I, J: in IndexType)
with Depends => (A => (A, I, J)),
Pre => I /= J,
Post => A = A'Old'Update (I => A'Old(J),
J => A'Old(I))
is
T: ElementType;
begin
T := A(I);
A(I) := A(J);
A(J) := T;
end Swap;
procedure Rotate3(A: in out ArrayType; X, Y, Z: in IndexType)
is
begin
Swap(A, X, Y);
Swap(A, Y, Z);
end Rotate3;
end Array_Swapping;
|
package Animals.Flying_Horses is
type Flying_Horse is new Animals.Animal with private;
type Color is (Snow_White, Pitch_Black, Light_Pink);
function Make (Horse_Color : Color) return Flying_Horse;
overriding
procedure Add_Wings (A : in out Flying_Horse;
N : Positive);
overriding
procedure Add_Legs (A : in out Flying_Horse;
N : Positive);
private
type Flying_Horse is new Animals.Animal with
record
Fur_Color : Color;
end record;
end Animals.Flying_Horses;
|
--------------------------------------------------------------------------------
-- Fichier : foret.ads
-- Auteur : MOUDDENE Hamza & CAZES Noa
-- Objectif : Spécification du module Ensemble
-- Crée : Dimanche Nov 10 2019
--------------------------------------------------------------------------------
generic
type T_Element is private; -- Type des éléments de l'ensemble.
package Ensemble is
type T_Ensemble is private;
----------------------------------Constuctor----------------------------------
-- Initilaiser un ensemble. L'ensemble est vide.
--
-- Param Ensemble : Ensembe qu'on va initialiser.
procedure Initialiser (Ensemble : out T_Ensemble) with
Post => Est_Vide (Ensemble);
-- Copier un ensemble dans un autre.
--
-- Param E1 : E1 dont on va lui copier un deuxième ensemble.
-- Param E2 : E2 l'ensemble copié dans E1.
procedure Copy (E1 : in out T_Ensemble; E2 : in T_Ensemble);
-- Ajouter l'élément à l'ensemble.
procedure Ajouter (Ensemble : in out T_Ensemble; Element : in T_Element) with
Pre => not(Est_Present (Ensemble, Element)),
Post => Est_Present (Ensemble, Element);
-----------------------------------Getters----------------------------------
-- Nom : Get_Element
-- Sémantique : Obtenir le noeud du pointeur.
-- Type_De_Retour : T_Element est la valeur du pointeur.
-- Paramètres
-- E : E que l'on va parcourir.
function Get_Element (E : in T_Ensemble) return T_Element;
-- Nom : Get_Next
-- Sémantique : Obtenir le pointeur suivant.
-- Type_De_Retour : T_Ensemble : Est le pointeur sur la case suivante.
-- Paramètre :
-- E -- L'ensemble qu'on va parcourir.
function Get_Next (E : in T_Ensemble) return T_Ensemble;
-----------------------------------Setters----------------------------------
-- Nom : Set_Element
-- Sémantique : Changer le noeud du pointeur.
-- Paramètres
-- E : E que l'on va parcourir.
-- Element : L'element qu'on va mettre dans Element.
procedure Set_Element (E : in T_Ensemble; Element : in T_Element);
-- Nom : Set_Next
-- Sémantique : Changer le pointeur suivant.
-- Paramètre :
-- E -- L'ensemble qu'on va parcourir.
-- Next -- Le pointeur suivant
procedure Set_Next (E : in T_Ensemble; Next : in T_Ensemble);
----------------------------------------------------------------------------
-- Détruire un ensemble (libérer les ressources qu’il utilise).
procedure Detruire (Ensemble : in out T_Ensemble) with
Post => Est_Vide (Ensemble);
-- Est-ce que l'ensemble est vide ?
function Est_Vide (Ensemble : in T_Ensemble) return Boolean;
-- Obtenir la taille d'un ensemble ?
function Taille (Ensemble : in T_Ensemble) return Integer;
-- L'élément est-il présent dans l'ensemble.
function Est_Present (Ensemble : in T_Ensemble; Element : in T_Element) return Boolean;
-- Nom : Edit_Set
-- Sémantique : Modifier un element de l'ensemble.
-- Paramètre :
-- Ensemble : L'ensemble qu'on va parcourir.
-- Old_Element : L'element qu'on va changer.
-- New_Element : L'element qu'on va mettre en place.
procedure Edit_Set (Ensemble : in T_Ensemble; Old_Element, New_Element : in T_Element);
-- Nom : Supprimer
-- Sémantique : Supprimer un element de l'ensemble.
-- Paramètre :
-- Ensemble : L'ensemble qu'on va parcourir.
-- Ab : L'arbre avant la modification.
procedure Supprimer (Ensemble : in out T_Ensemble; Element : in T_Element) with
Pre => not Est_Vide (Ensemble) and Est_Present (Ensemble, Element),
Post => not(Est_Present (Ensemble, Element));
-- Appliquer une opération sur les éléments de l'ensemble.
generic
with procedure Afficher_Elt (Un_Element: in T_Element);
procedure Afficher_Ensemble (Ensemble : in T_Ensemble);
private
type T_Cellule;
-- T_Ensemble est un pointeur sur T_Cellule.
type T_Ensemble is access T_Cellule;
type T_Cellule is record
Element: T_Element; -- la valeur de la cellule.
Suivant: T_Ensemble; -- un pointeur sur la cellule suivante.
end record;
end Ensemble;
|
with Runge_8th;
with Text_IO; use Text_IO;
with Quadrature;
with Ada.Numerics.Generic_Elementary_Functions;
procedure runge_8th_order_demo_3 is
type Real is digits 15;
package mth is new Ada.Numerics.Generic_Elementary_Functions(Real);
use mth; -- for Sin
package quadr is new Quadrature (Real, Sin);
use quadr;
package Area_Under_the_Curve is new
Runge_8th (Real, Dyn_Index, Dynamical_Variable, F, "*", "+", "-", Norm);
use Area_Under_the_Curve;
package rio is new Float_IO(Real);
use rio;
package iio is new Integer_IO(Step_Integer);
use iio;
Initial_Condition : Dynamical_Variable;
Previous_Y, Final_Y : Dynamical_Variable;
Final_Time, Starting_Time : Real;
Previous_t, Final_t : Real;
Delta_t : Real;
Steps : Step_Integer;
Error_Tolerance : Real := 1.0E-10;
Error_Control_Desired : Boolean := False;
Answer : Character := 'n';
begin
-- choose initial conditions
new_line;
put ("The test integrates (d/dt) Y(t) = Sin(t) for Y(t).");
new_line(2);
put ("Ordinary quadrature is just an area-under-the-curve problem, ");
new_line;
put ("where you solve: (d/dt) Y(t) = Sin(t) for Y.");
new_line(2);
put ("Input number of steps (try 16 with and without error control)");
new_line;
get (Steps);
new_line;
put ("Every time the integration advances this number of steps, ERROR is printed.");
new_line;
new_line;
put ("Use error control? Enter y or n:"); new_line; get (Answer);
if (Answer = 'Y') or (Answer = 'y') then
Error_Control_Desired := True;
put ("Error control it is."); new_line;
else
Error_Control_Desired := False;
put ("OK, no error control."); new_line;
end if;
Initial_Condition(0) := -1.0;
Starting_Time := 0.0;
Final_Time := 32.0;
Previous_Y := Initial_Condition;
Previous_t := Starting_Time;
Delta_t := Final_Time - Starting_Time;
for i in 1..20 loop
Final_t := Previous_t + Delta_t;
Integrate
(Final_State => Final_Y, -- the result (output).
Final_Time => Final_t, -- end integration here.
Initial_State => Previous_Y, -- the initial condition (input).
Initial_Time => Previous_t, -- start integrating here.
No_Of_Steps => Steps, -- if no err control, uses this.
Error_Control_Desired => Error_Control_Desired,
Error_Tolerance => Error_Tolerance);
Previous_Y := Final_Y;
Previous_t := Final_t;
new_line;
put ("Time = t =");
put (Final_t, Aft => 7);
put (", Error = (Cos (t) - Integrated Cos) = ");
put (Abs (-Cos(Final_t) - Final_Y(0)), Aft => 7);
end loop;
if (Answer = 'Y') or (Answer = 'y') then
new_line(2);
put ("With error control enabled, program attempted to reduce");
new_line;
put ("error *per step* to (well) under: ");
put (Error_Tolerance, Aft => 6);
new_line;
put ("Over thousands of steps, accumulated error will be much larger than that.");
new_line(2);
end if;
end;
|
with Ahven.Framework;
package My_Tests is
type Test is new Ahven.Framework.Test_Case with null record;
procedure Initialize (T : in out Test);
procedure INIT_TEST;
procedure CLOSE_TEST;
procedure SET_TEST;
procedure GET_TEST;
procedure GET_SET;
procedure SETM_TEST;
procedure RM_TEST;
procedure MV_TEST;
procedure CP_TEST;
procedure MATCH_TEST;
procedure SAVE_TEST;
end My_Tests;
|
pragma Warnings (Off);
pragma Style_Checks (Off);
package body Float_portable_binary_transfer is
inverse_scaling : constant Num := 1.0 / imposed_scaling;
-- We rely on Ada's attributes of floating - point types, RM : A.5.3
procedure Split (f : in Num; m : out Mantissa_type; e : out Exponent_type) is
begin
if imposed_mantissa then
m := Mantissa_type (imposed_scaling * Num'Fraction (f));
else
m := Mantissa_type (Num'Scaling (Num'Fraction (f), Num'Machine_Mantissa));
end if;
e := Num'Exponent (f);
end Split;
procedure Merge (m : in Mantissa_type; e : in Exponent_type; f : out Num) is
fraction : Num;
begin
if imposed_mantissa then
fraction := Num (m) * inverse_scaling;
else
fraction := Num'Scaling (Num (m), - Num'Machine_Mantissa);
end if;
-- We compose a float with the fraction and the exponent
f := Num'Compose (fraction, e);
end Merge;
-- Split / Merge in two parts --
machine_half_mantissa : constant Integer := 1 + Num'Machine_Mantissa/2;
procedure Split (f : in Num; m1, m2 : out Mantissa_type; e : out Exponent_type) is
f1, f2 : Num;
begin
if imposed_mantissa then
f1 := imposed_scaling * Num'Fraction (f);
else
f1 := Num'Scaling (Num'Fraction (f), machine_half_mantissa);
end if;
m1 := Mantissa_type (f1);
f1 := f1 - Num (m1);
if imposed_mantissa then
f2 := imposed_scaling * f1;
else
f2 := Num'Scaling (f1, machine_half_mantissa);
end if;
m2 := Mantissa_type (f2);
e := Num'Exponent (f);
end Split;
procedure Merge (m1, m2 : in Mantissa_type; e : in Exponent_type; f : out Num) is
fraction : Num;
begin
if imposed_mantissa then
fraction := (Num (m1) + Num (m2) * inverse_scaling) * inverse_scaling;
else
fraction := Num'Scaling (Num (m1) + Num'Scaling (Num (m2), - machine_half_mantissa), - machine_half_mantissa);
end if;
-- We compose a float with the fraction and the exponent
f := Num'Compose (fraction, e);
end Merge;
end Float_portable_binary_transfer;
|
package body uxas.messages.Lmcptask.TaskAutomationRequest.SPARK_Boundary with SPARK_Mode => Off is
-----------------------------------------
-- Get_EntityList_From_OriginalRequest --
-----------------------------------------
function Get_EntityList_From_OriginalRequest
(Request : TaskAutomationRequest) return Int64_Vect
is
L : constant Vect_Int64_Acc := Request.getOriginalRequest.getEntityList;
begin
return R : Int64_Vect do
for E of L.all loop
Int64_Vects.Append (R, E);
end loop;
end return;
end Get_EntityList_From_OriginalRequest;
----------------------------------------------
-- Get_OperatingRegion_From_OriginalRequest --
----------------------------------------------
function Get_OperatingRegion_From_OriginalRequest
(Request : TaskAutomationRequest) return Int64
is (Request.getOriginalRequest.getOperatingRegion);
----------------------------
-- Get_PlanningStates_Ids --
----------------------------
function Get_PlanningStates_Ids
(Request : TaskAutomationRequest) return Int64_Vect
is
L : constant Vect_PlanningState_Acc_Acc :=
Request.getPlanningStates;
begin
return R : Int64_Vect do
for E of L.all loop
Int64_Vects.Append (R, E.getEntityID);
end loop;
end return;
end Get_PlanningStates_Ids;
---------------------------------------
-- Get_TaskList_From_OriginalRequest --
---------------------------------------
function Get_TaskList_From_OriginalRequest
(Request : TaskAutomationRequest) return Int64_Vect
is
L : constant Vect_Int64_Acc := Request.getOriginalRequest.getTaskList;
begin
return R : Int64_Vect do
for E of L.all loop
Int64_Vects.Append (R, E);
end loop;
end return;
end Get_TaskList_From_OriginalRequest;
end uxas.messages.Lmcptask.TaskAutomationRequest.SPARK_Boundary;
|
-- SPDX-License-Identifier: Apache-2.0
--
-- Copyright (c) 2019 onox <denkpadje@gmail.com>
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
with GL.Types;
package Orka.Inputs.Joysticks is
pragma Preelaborate;
use type GL.Types.Single;
type Axis_Position is new GL.Types.Single range -1.0 .. 1.0;
type Button_State is (Released, Pressed);
type Hat_State is
(Centered, Up, Right, Right_Up, Down, Right_Down, Left, Left_Up, Left_Down);
type Button_States is array (Positive range <>) of Button_State with Pack;
type Axis_Positions is array (Positive range <>) of aliased Axis_Position;
type Hat_States is array (Positive range <>) of aliased Hat_State;
subtype Button_Index is Positive range 1 .. 64;
subtype Axis_Index is Positive range 1 .. 8;
subtype Hat_Index is Positive range 1 .. 8;
type Joystick_State (Button_Count, Axis_Count, Hat_Count : Natural := 0) is record
Buttons : Button_States (Button_Index) := (others => Released);
Axes : Axis_Positions (Axis_Index) := (others => 0.0);
Hats : Hat_States (Hat_Index) := (others => Centered);
end record
with Dynamic_Predicate =>
(Button_Count <= Buttons'Length or else
raise Constraint_Error with
"Joystick has too many buttons:" & Button_Count'Image) and then
(Axis_Count <= Axes'Length or else
raise Constraint_Error with
"Joystick has too many axes:" & Axis_Count'Image) and then
(Hat_Count <= Hats'Length or else
raise Constraint_Error with
"Joystick has too many hats:" & Hat_Count'Image);
-----------------------------------------------------------------------------
type Joystick_Input is limited interface;
type Joystick_Input_Access is access Joystick_Input'Class;
subtype Joystick_Input_Ptr is not null Joystick_Input_Access;
function Is_Present (Object : Joystick_Input) return Boolean is abstract;
function Is_Gamepad (Object : Joystick_Input) return Boolean is abstract;
function Name (Object : Joystick_Input) return String is abstract;
function GUID (Object : Joystick_Input) return String is abstract;
procedure Update_State
(Object : in out Joystick_Input;
Process : access procedure (Value : in out Axis_Position;
Index : Positive)) is abstract;
function Current_State (Object : Joystick_Input) return Joystick_State is abstract;
function Last_State (Object : Joystick_Input) return Joystick_State is abstract;
subtype Joystick_Button_States is Button_States (Button_Index);
type Boolean_Button_States is array (Joystick_Button_States'Range) of Boolean with Pack;
function Just_Pressed (Object : Joystick_Input'Class) return Boolean_Button_States;
function Just_Released (Object : Joystick_Input'Class) return Boolean_Button_States;
Disconnected_Error : exception;
-----------------------------------------------------------------------------
type Joystick_Manager is synchronized interface;
type Joystick_Manager_Ptr is not null access all Joystick_Manager'Class;
procedure Acquire
(Object : in out Joystick_Manager;
Joystick : out Inputs.Joysticks.Joystick_Input_Access) is abstract
with Synchronization => By_Protected_Procedure;
-- Acquire an unused joystick or null if no unused joystick is present
procedure Release
(Object : in out Joystick_Manager;
Joystick : Inputs.Joysticks.Joystick_Input_Access) is abstract
with Synchronization => By_Protected_Procedure;
-- Release a used joystick
end Orka.Inputs.Joysticks;
|
with System.Machine_Reset;
with Ada.Real_Time; use Ada.Real_Time;
with System.Task_Primitives.Operations;
with Config.Tasking;
with Bounded_Image; use Bounded_Image;
with Logger;
with NVRAM;
with HIL;
with Interfaces; use Interfaces;
with Unchecked_Conversion;
-- @summary Catches all exceptions, logs them to NVRAM and reboots.
package body Crash with SPARK_Mode => Off is
-- XXX! SPARK must be off here, otherwise this function is not being implemented.
-- Reasons see below.
function To_Unsigned is new Unchecked_Conversion (System.Address, Unsigned_32);
-- SPARK RM 6.5.1: a call to a non-returning procedure introduces the
-- obligation to prove that the statement will not be executed.
-- This is the same as a run-time check that fails unconditionally.
-- RM 11.3: ...must provably never be executed.
procedure Last_Chance_Handler(location : System.Address; line : Integer) is
now : constant Time := Clock;
line16 : constant Unsigned_16 := (if line >= 0 and line <= Integer (Unsigned_16'Last)
then Unsigned_16 (line)
else Unsigned_16'Last);
begin
-- if the task which called this handler is not flight critical,
-- silently hang here. as an effect, the system lives on without this task.
declare
use System.Task_Primitives.Operations;
prio : constant ST.Extended_Priority := Get_Priority (Self);
begin
if prio < Config.Tasking.TASK_PRIO_FLIGHTCRITICAL then
Logger.log (Logger.ERROR, "Non-critical task crashed");
loop
null;
end loop;
-- FIXME: there exists a "sleep infinite" procedure...just can't find it
-- but that'll do. at least it doesn't block flight-critical tasks
end if;
end;
-- first log to NVRAM
declare
ba : constant HIL.Byte_Array := HIL.toBytes (line16);
begin
NVRAM.Store (NVRAM.VAR_EXCEPTION_LINE_L, ba (1));
NVRAM.Store (NVRAM.VAR_EXCEPTION_LINE_H, ba (2));
NVRAM.Store (NVRAM.VAR_EXCEPTION_ADDR_A, To_Unsigned (location));
end;
-- now write to console (which might fail)
Logger.log (Logger.ERROR, "Exception: Addr: " & Unsigned_Img (To_Unsigned (location))
& ", line " & Integer_Img (line));
-- wait until write finished (interrupt based)
delay until now + Milliseconds(80);
-- DEBUG ONLY: hang here to let us read the console output
-- loop
-- null;
-- end loop;
-- XXX! A last chance handler must always terminate or suspend the
-- thread that executes the handler. Suspending cannot be used here,
-- because we cannot distinguish the tasks (?). So we reboot.
-- Abruptly stop the program.
-- On bareboard platform, this returns to the monitor or reset the board.
-- In the context of an OS, this terminates the process.
System.Machine_Reset.Stop; -- this is a non-returning function. SPARK assumes it is never executed.
-- The following junk raise of Program_Error is required because
-- this is a No_Return function, and unfortunately Suspend can
-- return (although this particular call won't).
raise Program_Error;
end Last_Chance_Handler;
end Crash;
|
with STM32_SVD.RCC; use STM32_SVD.RCC;
with STM32_SVD.PWR; use STM32_SVD.PWR;
package body STM32.SubGhzPhy is
procedure SubGhzPhy_Init
is
Config : SPI_Configuration;
begin
Enable_Clock (SubGhzPhyPort.all);
RCC_Periph.CSR.RFRST := False;
loop
exit when not RCC_Periph.CSR.RFRSTF;
end loop;
Enable (SubGhzPhyPort.all);
STM32.Device.Reset (SubGhzPhyPort.all);
-- RCC_Periph.APB3RSTR.SUBGHZSPIRST := True;
Config.Mode := Master;
Config.Baud_Rate_Prescaler := BRP_4;
Config.Clock_Polarity := Low;
Config.Clock_Phase := P1Edge;
Config.First_Bit := MSB;
Config.CRC_Poly := 7;
Config.Slave_Management := Software_Managed; -- essential!!
Config.Slave_Internal := Internal_NSS;
Config.Direction := D2Lines_FullDuplex;
Config.Data_Size := HAL.SPI.Data_Size_8b;
Config.Fifo_Level := True;
Config.Transmit_DMA := False;
Config.Receive_DMA := False;
Disable (SubGhzPhyPort.all);
Configure (SubGhzPhyPort.all, Config);
Enable (SubGhzPhyPort.all);
PWR_Periph.CR3.EWRFBUSY := True;
PWR_Periph.SCR.CWRFBUSYF := True;
end SubGhzPhy_Init;
end STM32.SubGhzPhy;
|
------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- G N A T C H O P --
-- --
-- B o d y --
-- --
-- Copyright (C) 1998-2020, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
-- for more details. You should have received a copy of the GNU General --
-- Public License distributed with GNAT; see file COPYING3. If not, go to --
-- http://www.gnu.org/licenses for a complete copy of the license. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
with Ada.Characters.Conversions; use Ada.Characters.Conversions;
with Ada.Command_Line; use Ada.Command_Line;
with Ada.Directories; use Ada.Directories;
with Ada.Streams.Stream_IO; use Ada.Streams;
with Ada.Text_IO; use Ada.Text_IO;
with System.CRTL; use System; use System.CRTL;
with GNAT.Byte_Order_Mark; use GNAT.Byte_Order_Mark;
with GNAT.Command_Line; use GNAT.Command_Line;
with GNAT.OS_Lib; use GNAT.OS_Lib;
with GNAT.Heap_Sort_G;
with GNAT.Table;
with Switch; use Switch;
with Types;
procedure Gnatchop is
Config_File_Name : constant String_Access := new String'("gnat.adc");
-- The name of the file holding the GNAT configuration pragmas
Gcc : String_Access := new String'("gcc");
-- May be modified by switch --GCC=
Gcc_Set : Boolean := False;
-- True if a switch --GCC= is used
Gnat_Cmd : String_Access;
-- Command to execute the GNAT compiler
Gnat_Args : Argument_List_Access :=
new Argument_List'
(new String'("-c"),
new String'("-x"),
new String'("ada"),
new String'("-gnats"),
new String'("-gnatu"));
-- Arguments used in Gnat_Cmd call
EOF : constant Character := Character'Val (26);
-- Special character to signal end of file. Not required in input files,
-- but properly treated if present. Not generated in output files except
-- as a result of copying input file.
BOM_Length : Natural := 0;
-- Reset to non-zero value if BOM detected at start of file
--------------------
-- File arguments --
--------------------
subtype File_Num is Natural;
subtype File_Offset is Natural;
type File_Entry is record
Name : String_Access;
-- Name of chop file or directory
SR_Name : String_Access;
-- Null unless the chop file starts with a source reference pragma
-- in which case this field points to the file name from this pragma.
end record;
package File is new GNAT.Table
(Table_Component_Type => File_Entry,
Table_Index_Type => File_Num,
Table_Low_Bound => 1,
Table_Initial => 100,
Table_Increment => 100);
Directory : String_Access;
-- Record name of directory, or a null string if no directory given
Compilation_Mode : Boolean := False;
Overwrite_Files : Boolean := False;
Preserve_Mode : Boolean := False;
Quiet_Mode : Boolean := False;
Source_References : Boolean := False;
Verbose_Mode : Boolean := False;
Exit_On_Error : Boolean := False;
-- Global options
Write_gnat_adc : Boolean := False;
-- Gets set true if we append to gnat.adc or create a new gnat.adc.
-- Used to inhibit complaint about no units generated.
---------------
-- Unit list --
---------------
type Line_Num is new Natural;
-- Line number (for source reference pragmas)
type Unit_Count_Type is new Integer;
subtype Unit_Num is Unit_Count_Type range 1 .. Unit_Count_Type'Last;
-- Used to refer to unit number in unit table
type SUnit_Num is new Integer;
-- Used to refer to entry in sorted units table. Note that entry
-- zero is only for use by Heapsort, and is not otherwise referenced.
type Unit_Kind is (Unit_Spec, Unit_Body, Config_Pragmas);
-- Structure to contain all necessary information for one unit.
-- Entries are also temporarily used to record config pragma sequences.
type Unit_Info is record
File_Name : String_Access;
-- File name from GNAT output line
Chop_File : File_Num;
-- File number in chop file sequence
Start_Line : Line_Num;
-- Line number from GNAT output line
Offset : File_Offset;
-- Offset name from GNAT output line
SR_Present : Boolean;
-- Set True if SR parameter present
Length : File_Offset;
-- A length of 0 means that the Unit is the last one in the file
Kind : Unit_Kind;
-- Indicates kind of unit
Sorted_Index : SUnit_Num;
-- Index of unit in sorted unit list
Bufferg : String_Access;
-- Pointer to buffer containing configuration pragmas to be prepended.
-- Null if no pragmas to be prepended.
end record;
-- The following table stores the unit offset information
package Unit is new GNAT.Table
(Table_Component_Type => Unit_Info,
Table_Index_Type => Unit_Count_Type,
Table_Low_Bound => 1,
Table_Initial => 500,
Table_Increment => 100);
-- The following table is used as a sorted index to the Unit.Table.
-- The entries in Unit.Table are not moved, instead we just shuffle
-- the entries in Sorted_Units. Note that the zeroeth entry in this
-- table is used by GNAT.Heap_Sort_G.
package Sorted_Units is new GNAT.Table
(Table_Component_Type => Unit_Num,
Table_Index_Type => SUnit_Num,
Table_Low_Bound => 0,
Table_Initial => 500,
Table_Increment => 100);
function Is_Duplicated (U : SUnit_Num) return Boolean;
-- Returns true if U is duplicated by a later unit.
-- Note that this function returns false for the last entry.
procedure Sort_Units;
-- Sort units and set up sorted unit table
----------------------
-- File_Descriptors --
----------------------
function dup (handle : File_Descriptor) return File_Descriptor;
function dup2 (from, to : File_Descriptor) return File_Descriptor;
---------------------
-- Local variables --
---------------------
Warning_Count : Natural := 0;
-- Count of warnings issued so far
-----------------------
-- Local subprograms --
-----------------------
procedure Error_Msg (Message : String; Warning : Boolean := False);
-- Produce an error message on standard error output
function Files_Exist return Boolean;
-- Check Unit.Table for possible file names that already exist
-- in the file system. Returns true if files exist, False otherwise
function Get_Maximum_File_Name_Length return Integer;
pragma Import (C, Get_Maximum_File_Name_Length,
"__gnat_get_maximum_file_name_length");
-- Function to get maximum file name length for system
Maximum_File_Name_Length : constant Integer := Get_Maximum_File_Name_Length;
Maximum_File_Name_Length_String : constant String :=
Integer'Image
(Maximum_File_Name_Length);
function Locate_Executable
(Program_Name : String;
Look_For_Prefix : Boolean := True) return String_Access;
-- Locate executable for given program name. This takes into account
-- the target-prefix of the current command, if Look_For_Prefix is True.
subtype EOL_Length is Natural range 0 .. 2;
-- Possible lengths of end of line sequence
type EOL_String (Len : EOL_Length := 0) is record
Str : String (1 .. Len);
end record;
function Get_EOL
(Source : not null access String;
Start : Positive) return EOL_String;
-- Return the line terminator used in the passed string
procedure Parse_EOL
(Source : not null access String;
Ptr : in out Positive);
-- On return Source (Ptr) is the first character of the next line
-- or EOF. Source.all must be terminated by EOF.
function Parse_File (Num : File_Num) return Boolean;
-- Calls the GNAT compiler to parse the given source file and parses the
-- output using Parse_Offset_Info. Returns True if parse operation
-- completes, False if some system error (e.g. failure to read the
-- offset information) occurs.
procedure Parse_Offset_Info
(Chop_File : File_Num;
Source : not null access String);
-- Parses the output of the compiler indicating the offsets and names of
-- the compilation units in Chop_File.
procedure Parse_Token
(Source : not null access String;
Ptr : in out Positive;
Token_Ptr : out Positive);
-- Skips any separators and stores the start of the token in Token_Ptr.
-- Then stores the position of the next separator in Ptr. On return
-- Source (Token_Ptr .. Ptr - 1) is the token.
procedure Read_File
(FD : File_Descriptor;
Contents : out String_Access;
Success : out Boolean);
-- Reads file associated with FS into the newly allocated string Contents.
-- Success is true iff the number of bytes read is equal to the file size.
function Report_Duplicate_Units return Boolean;
-- Output messages about duplicate units in the input files in Unit.Table
-- Returns True if any duplicates found, False if no duplicates found.
function Scan_Arguments return Boolean;
-- Scan command line options and set global variables accordingly.
-- Also scan out file and directory arguments. Returns True if scan
-- was successful, and False if the scan fails for any reason.
procedure Usage;
-- Output message on standard output describing syntax of gnatchop command
procedure Warning_Msg (Message : String);
-- Output a warning message on standard error and update warning count
function Write_Chopped_Files (Input : File_Num) return Boolean;
-- Write all units that result from chopping the Input file
procedure Write_Config_File (Input : File_Num; U : Unit_Num);
-- Call to write configuration pragmas (append them to gnat.adc). Input is
-- the file number for the chop file and U identifies the unit entry for
-- the configuration pragmas.
function Get_Config_Pragmas
(Input : File_Num;
U : Unit_Num) return String_Access;
-- Call to read configuration pragmas from given unit entry, and return a
-- buffer containing the pragmas to be appended to following units. Input
-- is the file number for the chop file and U identifies the unit entry for
-- the configuration pragmas.
procedure Write_Source_Reference_Pragma
(Info : Unit_Info;
Line : Line_Num;
File : Stream_IO.File_Type;
EOL : EOL_String;
Success : in out Boolean);
-- If Success is True on entry, writes a source reference pragma using
-- the chop file from Info, and the given line number. On return Success
-- indicates whether the write succeeded. If Success is False on entry,
-- or if the global flag Source_References is False, then the call to
-- Write_Source_Reference_Pragma has no effect. EOL indicates the end
-- of line sequence to be written at the end of the pragma.
procedure Write_Unit
(Source : not null access String;
Num : Unit_Num;
TS_Time : OS_Time;
Write_BOM : Boolean;
Success : out Boolean);
-- Write one compilation unit of the source to file. Source is the pointer
-- to the input string, Num is the unit number, TS_Time is the timestamp,
-- Write_BOM is set True to write a UTF-8 BOM at the start of the file.
-- Success is set True unless the write attempt fails.
---------
-- dup --
---------
function dup (handle : File_Descriptor) return File_Descriptor is
begin
return File_Descriptor (System.CRTL.dup (int (handle)));
end dup;
----------
-- dup2 --
----------
function dup2 (from, to : File_Descriptor) return File_Descriptor is
begin
return File_Descriptor (System.CRTL.dup2 (int (from), int (to)));
end dup2;
---------------
-- Error_Msg --
---------------
procedure Error_Msg (Message : String; Warning : Boolean := False) is
begin
Put_Line (Standard_Error, Message);
if not Warning then
Set_Exit_Status (Failure);
if Exit_On_Error then
raise Types.Terminate_Program;
end if;
end if;
end Error_Msg;
-----------------
-- Files_Exist --
-----------------
function Files_Exist return Boolean is
Exists : Boolean := False;
begin
for SNum in 1 .. SUnit_Num (Unit.Last) loop
-- Only check and report for the last instance of duplicated files
if not Is_Duplicated (SNum) then
declare
Info : constant Unit_Info :=
Unit.Table (Sorted_Units.Table (SNum));
begin
if Is_Writable_File (Info.File_Name.all) then
Error_Msg (Info.File_Name.all
& " already exists, use -w to overwrite");
Exists := True;
end if;
end;
end if;
end loop;
return Exists;
end Files_Exist;
------------------------
-- Get_Config_Pragmas --
------------------------
function Get_Config_Pragmas
(Input : File_Num;
U : Unit_Num) return String_Access
is
Info : Unit_Info renames Unit.Table (U);
FD : File_Descriptor;
Name : aliased constant String :=
File.Table (Input).Name.all & ASCII.NUL;
Length : File_Offset;
Buffer : String_Access;
Result : String_Access;
Success : Boolean;
pragma Warnings (Off, Success);
begin
FD := Open_Read (Name'Address, Binary);
if FD = Invalid_FD then
Error_Msg ("cannot open " & File.Table (Input).Name.all);
return null;
end if;
Read_File (FD, Buffer, Success);
-- A length of 0 indicates that the rest of the file belongs to
-- this unit. The actual length must be calculated now. Take into
-- account that the last character (EOF) must not be written.
if Info.Length = 0 then
Length := Buffer'Last - (Buffer'First + Info.Offset);
else
Length := Info.Length;
end if;
Result := new String'(Buffer (1 .. Length));
Close (FD);
return Result;
end Get_Config_Pragmas;
-------------
-- Get_EOL --
-------------
function Get_EOL
(Source : not null access String;
Start : Positive) return EOL_String
is
Ptr : Positive := Start;
First : Positive;
Last : Natural;
begin
-- Skip to end of line
while Source (Ptr) /= ASCII.CR and then
Source (Ptr) /= ASCII.LF and then
Source (Ptr) /= EOF
loop
Ptr := Ptr + 1;
end loop;
Last := Ptr;
if Source (Ptr) /= EOF then
-- Found CR or LF
First := Ptr;
else
First := Ptr + 1;
end if;
-- Recognize CR/LF
if Source (Ptr) = ASCII.CR and then Source (Ptr + 1) = ASCII.LF then
Last := First + 1;
end if;
return (Len => Last + 1 - First, Str => Source (First .. Last));
end Get_EOL;
-------------------
-- Is_Duplicated --
-------------------
function Is_Duplicated (U : SUnit_Num) return Boolean is
begin
return U < SUnit_Num (Unit.Last)
and then
Unit.Table (Sorted_Units.Table (U)).File_Name.all =
Unit.Table (Sorted_Units.Table (U + 1)).File_Name.all;
end Is_Duplicated;
-----------------------
-- Locate_Executable --
-----------------------
function Locate_Executable
(Program_Name : String;
Look_For_Prefix : Boolean := True) return String_Access
is
Gnatchop_Str : constant String := "gnatchop";
Current_Command : constant String := Normalize_Pathname (Command_Name);
End_Of_Prefix : Natural;
Start_Of_Prefix : Positive;
Start_Of_Suffix : Positive;
Result : String_Access;
begin
Start_Of_Prefix := Current_Command'First;
Start_Of_Suffix := Current_Command'Last + 1;
End_Of_Prefix := Start_Of_Prefix - 1;
if Look_For_Prefix then
-- Find Start_Of_Prefix
for J in reverse Current_Command'Range loop
if Current_Command (J) = '/' or else
Current_Command (J) = Directory_Separator or else
Current_Command (J) = ':'
then
Start_Of_Prefix := J + 1;
exit;
end if;
end loop;
-- Find End_Of_Prefix
for J in Start_Of_Prefix ..
Current_Command'Last - Gnatchop_Str'Length + 1
loop
if Current_Command (J .. J + Gnatchop_Str'Length - 1) =
Gnatchop_Str
then
End_Of_Prefix := J - 1;
exit;
end if;
end loop;
end if;
if End_Of_Prefix > Current_Command'First then
Start_Of_Suffix := End_Of_Prefix + Gnatchop_Str'Length + 1;
end if;
declare
Command : constant String :=
Current_Command (Start_Of_Prefix .. End_Of_Prefix)
& Program_Name
& Current_Command (Start_Of_Suffix ..
Current_Command'Last);
begin
Result := Locate_Exec_On_Path (Command);
if Result = null then
Error_Msg
(Command & ": installation problem, executable not found");
end if;
end;
return Result;
end Locate_Executable;
---------------
-- Parse_EOL --
---------------
procedure Parse_EOL
(Source : not null access String;
Ptr : in out Positive) is
begin
-- Skip to end of line
while Source (Ptr) /= ASCII.CR and then Source (Ptr) /= ASCII.LF
and then Source (Ptr) /= EOF
loop
Ptr := Ptr + 1;
end loop;
if Source (Ptr) /= EOF then
Ptr := Ptr + 1; -- skip CR or LF
end if;
-- Skip past CR/LF or LF/CR combination
if (Source (Ptr) = ASCII.CR or else Source (Ptr) = ASCII.LF)
and then Source (Ptr) /= Source (Ptr - 1)
then
Ptr := Ptr + 1;
end if;
end Parse_EOL;
----------------
-- Parse_File --
----------------
function Parse_File (Num : File_Num) return Boolean is
Chop_Name : constant String_Access := File.Table (Num).Name;
Save_Stdout : constant File_Descriptor := dup (Standout);
Offset_Name : Temp_File_Name;
Offset_FD : File_Descriptor := Invalid_FD;
Buffer : String_Access;
Success : Boolean;
Failure : exception;
begin
-- Display copy of GNAT command if verbose mode
if Verbose_Mode then
Put (Gnat_Cmd.all);
for J in 1 .. Gnat_Args'Length loop
Put (' ');
Put (Gnat_Args (J).all);
end loop;
Put (' ');
Put_Line (Chop_Name.all);
end if;
-- Create temporary file
Create_Temp_File (Offset_FD, Offset_Name);
if Offset_FD = Invalid_FD then
Error_Msg ("gnatchop: cannot create temporary file");
Close (Save_Stdout);
return False;
end if;
-- Redirect Stdout to this temporary file in the Unix way
if dup2 (Offset_FD, Standout) = Invalid_FD then
Error_Msg ("gnatchop: cannot redirect stdout to temporary file");
Close (Save_Stdout);
Close (Offset_FD);
return False;
end if;
-- Call Gnat on the source filename argument with special options
-- to generate offset information. If this special compilation completes
-- successfully then we can do the actual gnatchop operation.
Spawn (Gnat_Cmd.all, Gnat_Args.all & Chop_Name, Success);
if not Success then
Error_Msg (Chop_Name.all & ": parse errors detected");
Error_Msg (Chop_Name.all & ": chop may not be successful");
end if;
-- Restore stdout
if dup2 (Save_Stdout, Standout) = Invalid_FD then
Error_Msg ("gnatchop: cannot restore stdout");
end if;
-- Reopen the file to start reading from the beginning
Close (Offset_FD);
Close (Save_Stdout);
Offset_FD := Open_Read (Offset_Name'Address, Binary);
if Offset_FD = Invalid_FD then
Error_Msg ("gnatchop: cannot access offset info");
raise Failure;
end if;
Read_File (Offset_FD, Buffer, Success);
if not Success then
Error_Msg ("gnatchop: error reading offset info");
Close (Offset_FD);
raise Failure;
else
Parse_Offset_Info (Num, Buffer);
end if;
-- Close and delete temporary file
Close (Offset_FD);
Delete_File (Offset_Name'Address, Success);
return Success;
exception
when Failure | Types.Terminate_Program =>
if Offset_FD /= Invalid_FD then
Close (Offset_FD);
end if;
Delete_File (Offset_Name'Address, Success);
return False;
end Parse_File;
-----------------------
-- Parse_Offset_Info --
-----------------------
procedure Parse_Offset_Info
(Chop_File : File_Num;
Source : not null access String)
is
First_Unit : constant Unit_Num := Unit.Last + 1;
Bufferg : String_Access := null;
Parse_Ptr : File_Offset := Source'First;
Token_Ptr : File_Offset;
Info : Unit_Info;
function Match (Literal : String) return Boolean;
-- Checks if given string appears at the current Token_Ptr location
-- and if so, bumps Parse_Ptr past the token and returns True. If
-- the string is not present, sets Parse_Ptr to Token_Ptr and
-- returns False.
-----------
-- Match --
-----------
function Match (Literal : String) return Boolean is
begin
Parse_Token (Source, Parse_Ptr, Token_Ptr);
if Source'Last + 1 - Token_Ptr < Literal'Length
or else
Source (Token_Ptr .. Token_Ptr + Literal'Length - 1) /= Literal
then
Parse_Ptr := Token_Ptr;
return False;
end if;
Parse_Ptr := Token_Ptr + Literal'Length;
return True;
end Match;
-- Start of processing for Parse_Offset_Info
begin
loop
-- Set default values, should get changed for all
-- units/pragmas except for the last
Info.Chop_File := Chop_File;
Info.Length := 0;
-- Parse the current line of offset information into Info
-- and exit the loop if there are any errors or on EOF.
-- First case, parse a line in the following format:
-- Unit x (spec) line 7, file offset 142, [SR, ]file name x.ads
-- Note that the unit name can be an operator name in quotes.
-- This is of course illegal, but both GNAT and gnatchop handle
-- the case so that this error does not interfere with chopping.
-- The SR ir present indicates that a source reference pragma
-- was processed as part of this unit (and that therefore no
-- Source_Reference pragma should be generated.
if Match ("Unit") then
Parse_Token (Source, Parse_Ptr, Token_Ptr);
if Match ("(body)") then
Info.Kind := Unit_Body;
elsif Match ("(spec)") then
Info.Kind := Unit_Spec;
else
exit;
end if;
exit when not Match ("line");
Parse_Token (Source, Parse_Ptr, Token_Ptr);
Info.Start_Line := Line_Num'Value
(Source (Token_Ptr .. Parse_Ptr - 1));
exit when not Match ("file offset");
Parse_Token (Source, Parse_Ptr, Token_Ptr);
Info.Offset := File_Offset'Value
(Source (Token_Ptr .. Parse_Ptr - 1));
Info.SR_Present := Match ("SR, ");
exit when not Match ("file name");
Parse_Token (Source, Parse_Ptr, Token_Ptr);
Info.File_Name := new String'
(Directory.all & Source (Token_Ptr .. Parse_Ptr - 1));
Parse_EOL (Source, Parse_Ptr);
-- Second case, parse a line of the following form
-- Configuration pragmas at line 10, file offset 223
elsif Match ("Configuration pragmas at") then
Info.Kind := Config_Pragmas;
Info.File_Name := Config_File_Name;
exit when not Match ("line");
Parse_Token (Source, Parse_Ptr, Token_Ptr);
Info.Start_Line := Line_Num'Value
(Source (Token_Ptr .. Parse_Ptr - 1));
exit when not Match ("file offset");
Parse_Token (Source, Parse_Ptr, Token_Ptr);
Info.Offset := File_Offset'Value
(Source (Token_Ptr .. Parse_Ptr - 1));
Parse_EOL (Source, Parse_Ptr);
-- Third case, parse a line of the following form
-- Source_Reference pragma for file "filename"
-- This appears at the start of the file only, and indicates
-- the name to be used on any generated Source_Reference pragmas.
elsif Match ("Source_Reference pragma for file ") then
Parse_Token (Source, Parse_Ptr, Token_Ptr);
File.Table (Chop_File).SR_Name :=
new String'(Source (Token_Ptr + 1 .. Parse_Ptr - 2));
Parse_EOL (Source, Parse_Ptr);
goto Continue;
-- Unrecognized keyword or end of file
else
exit;
end if;
-- Store the data in the Info record in the Unit.Table
Unit.Increment_Last;
Unit.Table (Unit.Last) := Info;
-- If this is not the first unit from the file, calculate
-- the length of the previous unit as difference of the offsets
if Unit.Last > First_Unit then
Unit.Table (Unit.Last - 1).Length :=
Info.Offset - Unit.Table (Unit.Last - 1).Offset;
end if;
-- If not in compilation mode combine current unit with any
-- preceding configuration pragmas.
if not Compilation_Mode
and then Unit.Last > First_Unit
and then Unit.Table (Unit.Last - 1).Kind = Config_Pragmas
then
Info.Start_Line := Unit.Table (Unit.Last - 1).Start_Line;
Info.Offset := Unit.Table (Unit.Last - 1).Offset;
-- Delete the configuration pragma entry
Unit.Table (Unit.Last - 1) := Info;
Unit.Decrement_Last;
end if;
-- If in compilation mode, and previous entry is the initial
-- entry for the file and is for configuration pragmas, then
-- they are to be appended to every unit in the file.
if Compilation_Mode
and then Unit.Last = First_Unit + 1
and then Unit.Table (First_Unit).Kind = Config_Pragmas
then
Bufferg :=
Get_Config_Pragmas
(Unit.Table (Unit.Last - 1).Chop_File, First_Unit);
Unit.Table (Unit.Last - 1) := Info;
Unit.Decrement_Last;
end if;
Unit.Table (Unit.Last).Bufferg := Bufferg;
-- If in compilation mode, and this is not the first item,
-- combine configuration pragmas with previous unit, which
-- will cause an error message to be generated when the unit
-- is compiled.
if Compilation_Mode
and then Unit.Last > First_Unit
and then Unit.Table (Unit.Last).Kind = Config_Pragmas
then
Unit.Decrement_Last;
end if;
<<Continue>>
null;
end loop;
-- Find out if the loop was exited prematurely because of
-- an error or if the EOF marker was found.
if Source (Parse_Ptr) /= EOF then
Error_Msg
(File.Table (Chop_File).Name.all & ": error parsing offset info");
return;
end if;
-- Handle case of a chop file consisting only of config pragmas
if Unit.Last = First_Unit
and then Unit.Table (Unit.Last).Kind = Config_Pragmas
then
-- In compilation mode, we append such a file to gnat.adc
if Compilation_Mode then
Write_Config_File (Unit.Table (Unit.Last).Chop_File, First_Unit);
Unit.Decrement_Last;
-- In default (non-compilation) mode, this is invalid
else
Error_Msg
(File.Table (Chop_File).Name.all &
": no units found (only pragmas)");
Unit.Decrement_Last;
end if;
end if;
-- Handle case of a chop file ending with config pragmas. This can
-- happen only in default non-compilation mode, since in compilation
-- mode such configuration pragmas are part of the preceding unit.
-- We simply concatenate such pragmas to the previous file which
-- will cause a compilation error, which is appropriate.
if Unit.Last > First_Unit
and then Unit.Table (Unit.Last).Kind = Config_Pragmas
then
Unit.Decrement_Last;
end if;
end Parse_Offset_Info;
-----------------
-- Parse_Token --
-----------------
procedure Parse_Token
(Source : not null access String;
Ptr : in out Positive;
Token_Ptr : out Positive)
is
In_Quotes : Boolean := False;
begin
-- Skip separators
while Source (Ptr) = ' ' or else Source (Ptr) = ',' loop
Ptr := Ptr + 1;
end loop;
Token_Ptr := Ptr;
-- Find end-of-token
while (In_Quotes
or else not (Source (Ptr) = ' ' or else Source (Ptr) = ','))
and then Source (Ptr) >= ' '
loop
if Source (Ptr) = '"' then
In_Quotes := not In_Quotes;
end if;
Ptr := Ptr + 1;
end loop;
end Parse_Token;
---------------
-- Read_File --
---------------
procedure Read_File
(FD : File_Descriptor;
Contents : out String_Access;
Success : out Boolean)
is
Length : constant File_Offset := File_Offset (File_Length (FD));
-- Include room for EOF char
Buffer : String_Access := new String (1 .. Length + 1);
This_Read : Integer;
Read_Ptr : File_Offset := 1;
begin
loop
This_Read := Read (FD,
A => Buffer (Read_Ptr)'Address,
N => Length + 1 - Read_Ptr);
Read_Ptr := Read_Ptr + Integer'Max (This_Read, 0);
exit when This_Read <= 0;
end loop;
Buffer (Read_Ptr) := EOF;
-- Comment needed for the following ???
-- Under what circumstances can the test fail ???
-- What is copy doing in that case???
if Read_Ptr = Length then
Contents := Buffer;
else
Contents := new String (1 .. Read_Ptr);
Contents.all := Buffer (1 .. Read_Ptr);
Free (Buffer);
end if;
Success := Read_Ptr = Length + 1;
end Read_File;
----------------------------
-- Report_Duplicate_Units --
----------------------------
function Report_Duplicate_Units return Boolean is
US : SUnit_Num;
U : Unit_Num;
Duplicates : Boolean := False;
begin
US := 1;
while US < SUnit_Num (Unit.Last) loop
U := Sorted_Units.Table (US);
if Is_Duplicated (US) then
Duplicates := True;
-- Move to last two versions of duplicated file to make it clearer
-- to understand which file is retained in case of overwriting.
while US + 1 < SUnit_Num (Unit.Last) loop
exit when not Is_Duplicated (US + 1);
US := US + 1;
end loop;
U := Sorted_Units.Table (US);
if Overwrite_Files then
Warning_Msg (Unit.Table (U).File_Name.all
& " is duplicated (all but last will be skipped)");
elsif Unit.Table (U).Chop_File =
Unit.Table (Sorted_Units.Table (US + 1)).Chop_File
then
Error_Msg (Unit.Table (U).File_Name.all
& " is duplicated in "
& File.Table (Unit.Table (U).Chop_File).Name.all);
else
Error_Msg (Unit.Table (U).File_Name.all
& " in "
& File.Table (Unit.Table (U).Chop_File).Name.all
& " is duplicated in "
& File.Table
(Unit.Table
(Sorted_Units.Table (US + 1)).Chop_File).Name.all);
end if;
end if;
US := US + 1;
end loop;
if Duplicates and not Overwrite_Files then
Put_Line ("use -w to overwrite files and keep last version");
end if;
return Duplicates;
end Report_Duplicate_Units;
--------------------
-- Scan_Arguments --
--------------------
function Scan_Arguments return Boolean is
Kset : Boolean := False;
-- Set true if -k switch found
begin
Initialize_Option_Scan;
-- Scan options first
loop
case Getopt ("c gnat? h k? p q r v w x -GCC=!") is
when ASCII.NUL =>
exit;
when '-' =>
Gcc := new String'(Parameter);
Gcc_Set := True;
when 'c' =>
Compilation_Mode := True;
when 'g' =>
Gnat_Args :=
new Argument_List'(Gnat_Args.all &
new String'("-gnat" & Parameter));
when 'h' =>
Usage;
raise Types.Terminate_Program;
when 'k' =>
declare
Param : String_Access := new String'(Parameter);
begin
if Param.all /= "" then
for J in Param'Range loop
if Param (J) not in '0' .. '9' then
Error_Msg ("-k# requires numeric parameter");
return False;
end if;
end loop;
else
Param := new String'("8");
end if;
Gnat_Args :=
new Argument_List'(Gnat_Args.all &
new String'("-gnatk" & Param.all));
Kset := True;
end;
when 'p' =>
Preserve_Mode := True;
when 'q' =>
Quiet_Mode := True;
when 'r' =>
Source_References := True;
when 'v' =>
Verbose_Mode := True;
Display_Version ("GNATCHOP", "1998");
when 'w' =>
Overwrite_Files := True;
when 'x' =>
Exit_On_Error := True;
when others =>
null;
end case;
end loop;
if not Kset and then Maximum_File_Name_Length > 0 then
-- If this system has restricted filename lengths, tell gnat1
-- about them, removing the leading blank from the image string.
Gnat_Args :=
new Argument_List'(Gnat_Args.all
& new String'("-gnatk"
& Maximum_File_Name_Length_String
(Maximum_File_Name_Length_String'First + 1
.. Maximum_File_Name_Length_String'Last)));
end if;
-- Scan file names
loop
declare
S : constant String := Get_Argument (Do_Expansion => True);
begin
exit when S = "";
File.Increment_Last;
File.Table (File.Last).Name := new String'(S);
File.Table (File.Last).SR_Name := null;
end;
end loop;
-- Case of more than one file where last file is a directory
if File.Last > 1
and then Is_Directory (File.Table (File.Last).Name.all)
then
Directory := File.Table (File.Last).Name;
File.Decrement_Last;
-- Make sure Directory is terminated with a directory separator,
-- so we can generate the output by just appending a filename.
if Directory (Directory'Last) /= Directory_Separator
and then Directory (Directory'Last) /= '/'
then
Directory := new String'(Directory.all & Directory_Separator);
end if;
-- At least one filename must be given
elsif File.Last = 0 then
if Argument_Count = 0 then
Usage;
else
Try_Help;
end if;
return False;
-- No directory given, set directory to null, so that we can just
-- concatenate the directory name to the file name unconditionally.
else
Directory := new String'("");
end if;
-- Finally check all filename arguments
for File_Num in 1 .. File.Last loop
declare
F : constant String := File.Table (File_Num).Name.all;
begin
if Is_Directory (F) then
Error_Msg (F & " is a directory, cannot be chopped");
return False;
elsif not Is_Regular_File (F) then
Error_Msg (F & " not found");
return False;
end if;
end;
end loop;
return True;
exception
when Invalid_Switch =>
Error_Msg ("invalid switch " & Full_Switch);
return False;
when Invalid_Parameter =>
Error_Msg ("-k switch requires numeric parameter");
return False;
end Scan_Arguments;
----------------
-- Sort_Units --
----------------
procedure Sort_Units is
procedure Move (From : Natural; To : Natural);
-- Procedure used to sort the unit list
-- Unit.Table (To) := Unit_List (From); used by sort
function Lt (Left, Right : Natural) return Boolean;
-- Compares Left and Right units based on file name (first),
-- Chop_File (second) and Offset (third). This ordering is
-- important to keep the last version in case of duplicate files.
package Unit_Sort is new GNAT.Heap_Sort_G (Move, Lt);
-- Used for sorting on filename to detect duplicates
--------
-- Lt --
--------
function Lt (Left, Right : Natural) return Boolean is
L : Unit_Info renames
Unit.Table (Sorted_Units.Table (SUnit_Num (Left)));
R : Unit_Info renames
Unit.Table (Sorted_Units.Table (SUnit_Num (Right)));
begin
return L.File_Name.all < R.File_Name.all
or else (L.File_Name.all = R.File_Name.all
and then (L.Chop_File < R.Chop_File
or else (L.Chop_File = R.Chop_File
and then L.Offset < R.Offset)));
end Lt;
----------
-- Move --
----------
procedure Move (From : Natural; To : Natural) is
begin
Sorted_Units.Table (SUnit_Num (To)) :=
Sorted_Units.Table (SUnit_Num (From));
end Move;
-- Start of processing for Sort_Units
begin
Sorted_Units.Set_Last (SUnit_Num (Unit.Last));
for J in 1 .. Unit.Last loop
Sorted_Units.Table (SUnit_Num (J)) := J;
end loop;
-- Sort Unit.Table, using Sorted_Units.Table (0) as scratch
Unit_Sort.Sort (Natural (Unit.Last));
-- Set the Sorted_Index fields in the unit tables
for J in 1 .. SUnit_Num (Unit.Last) loop
Unit.Table (Sorted_Units.Table (J)).Sorted_Index := J;
end loop;
end Sort_Units;
-----------
-- Usage --
-----------
procedure Usage is
begin
Put_Line
("Usage: gnatchop [-c] [-h] [-k#] " &
"[-r] [-p] [-q] [-v] [-w] [-x] [--GCC=xx] file [file ...] [dir]");
New_Line;
Display_Usage_Version_And_Help;
Put_Line
(" -c compilation mode, configuration pragmas " &
"follow RM rules");
Put_Line
(" -gnatxxx passes the -gnatxxx switch to gnat parser");
Put_Line
(" -h help: output this usage information");
Put_Line
(" -k# krunch file names of generated files to " &
"no more than # characters");
Put_Line
(" -k krunch file names of generated files to " &
"no more than 8 characters");
Put_Line
(" -p preserve time stamp, output files will " &
"have same stamp as input");
Put_Line
(" -q quiet mode, no output of generated file " &
"names");
Put_Line
(" -r generate Source_Reference pragmas refer" &
"encing original source file");
Put_Line
(" -v verbose mode, output version and generat" &
"ed commands");
Put_Line
(" -w overwrite existing filenames");
Put_Line
(" -x exit on error");
Put_Line
(" --GCC=xx specify the path of the gnat parser to be used");
New_Line;
Put_Line
(" file... list of source files to be chopped");
Put_Line
(" dir directory location for split files (defa" &
"ult = current directory)");
end Usage;
-----------------
-- Warning_Msg --
-----------------
procedure Warning_Msg (Message : String) is
begin
Warning_Count := Warning_Count + 1;
Put_Line (Standard_Error, "warning: " & Message);
end Warning_Msg;
-------------------------
-- Write_Chopped_Files --
-------------------------
function Write_Chopped_Files (Input : File_Num) return Boolean is
Name : aliased constant String :=
File.Table (Input).Name.all & ASCII.NUL;
FD : File_Descriptor;
Buffer : String_Access;
Success : Boolean;
TS_Time : OS_Time;
BOM_Present : Boolean;
BOM : BOM_Kind;
-- Record presence of UTF8 BOM in input
begin
FD := Open_Read (Name'Address, Binary);
TS_Time := File_Time_Stamp (FD);
if FD = Invalid_FD then
Error_Msg ("cannot open " & File.Table (Input).Name.all);
return False;
end if;
Read_File (FD, Buffer, Success);
if not Success then
Error_Msg ("cannot read " & File.Table (Input).Name.all);
Close (FD);
return False;
end if;
if not Quiet_Mode then
Put_Line ("splitting " & File.Table (Input).Name.all & " into:");
end if;
-- Test for presence of BOM
Read_BOM (Buffer.all, BOM_Length, BOM, XML_Support => False);
BOM_Present := BOM /= Unknown;
-- Only chop those units that come from this file
for Unit_Number in 1 .. Unit.Last loop
if Unit.Table (Unit_Number).Chop_File = Input then
Write_Unit
(Source => Buffer,
Num => Unit_Number,
TS_Time => TS_Time,
Write_BOM => BOM_Present and then Unit_Number /= 1,
Success => Success);
exit when not Success;
end if;
end loop;
Close (FD);
return Success;
end Write_Chopped_Files;
-----------------------
-- Write_Config_File --
-----------------------
procedure Write_Config_File (Input : File_Num; U : Unit_Num) is
FD : File_Descriptor;
Name : aliased constant String := "gnat.adc" & ASCII.NUL;
Buffer : String_Access;
Success : Boolean;
Append : Boolean;
Buffera : String_Access;
Bufferl : Natural;
begin
Write_gnat_adc := True;
FD := Open_Read_Write (Name'Address, Binary);
if FD = Invalid_FD then
FD := Create_File (Name'Address, Binary);
Append := False;
if not Quiet_Mode then
Put_Line ("writing configuration pragmas from " &
File.Table (Input).Name.all & " to gnat.adc");
end if;
else
Append := True;
if not Quiet_Mode then
Put_Line
("appending configuration pragmas from " &
File.Table (Input).Name.all & " to gnat.adc");
end if;
end if;
Success := FD /= Invalid_FD;
if not Success then
Error_Msg ("cannot create gnat.adc");
return;
end if;
-- In append mode, acquire existing gnat.adc file
if Append then
Read_File (FD, Buffera, Success);
if not Success then
Error_Msg ("cannot read gnat.adc");
return;
end if;
-- Find location of EOF byte if any to exclude from append
Bufferl := 1;
while Bufferl <= Buffera'Last
and then Buffera (Bufferl) /= EOF
loop
Bufferl := Bufferl + 1;
end loop;
Bufferl := Bufferl - 1;
Close (FD);
-- Write existing gnat.adc to new gnat.adc file
FD := Create_File (Name'Address, Binary);
Success := Write (FD, Buffera (1)'Address, Bufferl) = Bufferl;
if not Success then
Error_Msg ("error writing gnat.adc");
return;
end if;
end if;
Buffer := Get_Config_Pragmas (Input, U);
if Buffer /= null then
Success := Write (FD, Buffer.all'Address, Buffer'Length) =
Buffer'Length;
if not Success then
Error_Msg ("disk full writing gnat.adc");
return;
end if;
end if;
Close (FD);
end Write_Config_File;
-----------------------------------
-- Write_Source_Reference_Pragma --
-----------------------------------
procedure Write_Source_Reference_Pragma
(Info : Unit_Info;
Line : Line_Num;
File : Stream_IO.File_Type;
EOL : EOL_String;
Success : in out Boolean)
is
FTE : File_Entry renames Gnatchop.File.Table (Info.Chop_File);
Nam : String_Access;
begin
if Success and then Source_References and then not Info.SR_Present then
if FTE.SR_Name /= null then
Nam := FTE.SR_Name;
else
Nam := FTE.Name;
end if;
declare
Reference : String :=
"pragma Source_Reference (000000, """
& Nam.all & """);" & EOL.Str;
Pos : Positive := Reference'First;
Lin : Line_Num := Line;
begin
while Reference (Pos + 1) /= ',' loop
Pos := Pos + 1;
end loop;
while Reference (Pos) = '0' loop
Reference (Pos) := Character'Val
(Character'Pos ('0') + Lin mod 10);
Lin := Lin / 10;
Pos := Pos - 1;
end loop;
-- Assume there are enough zeroes for any program length
pragma Assert (Lin = 0);
begin
String'Write (Stream_IO.Stream (File), Reference);
Success := True;
exception
when others =>
Success := False;
end;
end;
end if;
end Write_Source_Reference_Pragma;
----------------
-- Write_Unit --
----------------
procedure Write_Unit
(Source : not null access String;
Num : Unit_Num;
TS_Time : OS_Time;
Write_BOM : Boolean;
Success : out Boolean)
is
procedure OS_Filename
(Name : String;
W_Name : Wide_String;
OS_Name : Address;
N_Length : access Natural;
Encoding : Address;
E_Length : access Natural);
pragma Import (C, OS_Filename, "__gnat_os_filename");
-- Returns in OS_Name the proper name for the OS when used with the
-- returned Encoding value. For example on Windows this will return the
-- UTF-8 encoded name into OS_Name and set Encoding to encoding=utf8
-- (the form parameter for Stream_IO).
--
-- Name is the filename and W_Name the same filename in Unicode 16 bits
-- (this corresponds to Win32 Unicode ISO/IEC 10646). N_Length/E_Length
-- are the length returned in OS_Name/Encoding respectively.
Info : Unit_Info renames Unit.Table (Num);
Name : aliased constant String := Info.File_Name.all & ASCII.NUL;
W_Name : aliased constant Wide_String := To_Wide_String (Name);
EOL : constant EOL_String :=
Get_EOL (Source, Source'First + Info.Offset);
OS_Name : aliased String (1 .. Name'Length * 2);
O_Length : aliased Natural := OS_Name'Length;
Encoding : aliased String (1 .. 64);
E_Length : aliased Natural := Encoding'Length;
Length : File_Offset;
begin
-- Skip duplicated files
if Is_Duplicated (Info.Sorted_Index) then
Put_Line (" " & Info.File_Name.all & " skipped");
Success := Overwrite_Files;
return;
end if;
-- Get OS filename
OS_Filename
(Name, W_Name,
OS_Name'Address, O_Length'Access,
Encoding'Address, E_Length'Access);
declare
E_Name : constant String := OS_Name (1 .. O_Length);
OS_Encoding : constant String := Encoding (1 .. E_Length);
File : Stream_IO.File_Type;
begin
begin
if not Overwrite_Files and then Exists (E_Name) then
raise Stream_IO.Name_Error;
else
Stream_IO.Create
(File, Stream_IO.Out_File, E_Name, OS_Encoding);
Success := True;
end if;
exception
when Stream_IO.Name_Error | Stream_IO.Use_Error =>
Error_Msg ("cannot create " & Info.File_Name.all);
return;
end;
-- A length of 0 indicates that the rest of the file belongs to
-- this unit. The actual length must be calculated now. Take into
-- account that the last character (EOF) must not be written.
if Info.Length = 0 then
Length := Source'Last - (Source'First + Info.Offset);
else
Length := Info.Length;
end if;
-- Write BOM if required
if Write_BOM then
String'Write
(Stream_IO.Stream (File),
Source.all (Source'First .. Source'First + BOM_Length - 1));
end if;
-- Prepend configuration pragmas if necessary
if Success and then Info.Bufferg /= null then
Write_Source_Reference_Pragma (Info, 1, File, EOL, Success);
String'Write (Stream_IO.Stream (File), Info.Bufferg.all);
end if;
Write_Source_Reference_Pragma
(Info, Info.Start_Line, File, EOL, Success);
if Success then
begin
String'Write
(Stream_IO.Stream (File),
Source (Source'First + Info.Offset ..
Source'First + Info.Offset + Length - 1));
exception
when Stream_IO.Use_Error | Stream_IO.Device_Error =>
Error_Msg ("disk full writing " & Info.File_Name.all);
return;
end;
end if;
if not Quiet_Mode then
Put_Line (" " & Info.File_Name.all);
end if;
Stream_IO.Close (File);
if Preserve_Mode then
Set_File_Last_Modify_Time_Stamp (E_Name, TS_Time);
end if;
end;
end Write_Unit;
procedure Check_Version_And_Help is new Check_Version_And_Help_G (Usage);
-- Start of processing for gnatchop
begin
-- Add the directory where gnatchop is invoked in front of the path, if
-- gnatchop is invoked with directory information.
declare
Command : constant String := Command_Name;
begin
for Index in reverse Command'Range loop
if Command (Index) = Directory_Separator then
declare
Absolute_Dir : constant String :=
Normalize_Pathname
(Command (Command'First .. Index));
PATH : constant String :=
Absolute_Dir
& Path_Separator
& Getenv ("PATH").all;
begin
Setenv ("PATH", PATH);
end;
exit;
end if;
end loop;
end;
-- Process command line options and initialize global variables
-- First, scan to detect --version and/or --help
Check_Version_And_Help ("GNATCHOP", "1998");
if not Scan_Arguments then
Set_Exit_Status (Failure);
return;
end if;
-- Check presence of required executables
Gnat_Cmd := Locate_Executable (Gcc.all, not Gcc_Set);
if Gnat_Cmd = null then
goto No_Files_Written;
end if;
-- First parse all files and read offset information
for Num in 1 .. File.Last loop
if not Parse_File (Num) then
goto No_Files_Written;
end if;
end loop;
-- Check if any units have been found (assumes non-empty Unit.Table)
if Unit.Last = 0 then
if not Write_gnat_adc then
Error_Msg ("no compilation units found", Warning => True);
end if;
goto No_Files_Written;
end if;
Sort_Units;
-- Check if any duplicate files would be created. If so, emit a warning if
-- Overwrite_Files is true, otherwise generate an error.
if Report_Duplicate_Units and then not Overwrite_Files then
goto No_Files_Written;
end if;
-- Check if any files exist, if so do not write anything Because all files
-- have been parsed and checked already, there won't be any duplicates
if not Overwrite_Files and then Files_Exist then
goto No_Files_Written;
end if;
-- After this point, all source files are read in succession and chopped
-- into their destination files.
-- Source_File_Name pragmas are handled as logical file 0 so write it first
for F in 1 .. File.Last loop
if not Write_Chopped_Files (F) then
Set_Exit_Status (Failure);
return;
end if;
end loop;
if Warning_Count > 0 then
declare
Warnings_Msg : constant String := Warning_Count'Img & " warning(s)";
begin
Error_Msg (Warnings_Msg (2 .. Warnings_Msg'Last), Warning => True);
end;
end if;
return;
<<No_Files_Written>>
-- Special error exit for all situations where no files have
-- been written.
if not Write_gnat_adc then
Error_Msg ("no source files written", Warning => True);
end if;
return;
exception
when Types.Terminate_Program =>
null;
end Gnatchop;
|
package DDS.Request_Reply is
type Ref is limited interface;
type Ref_Access is access all Ref'Class;
procedure Log_Exception (Self : not null access Ref; Log : Standard.String) is null;
end DDS.Request_Reply;
|
-- parse_args-concrete.ads
-- A simple command line option parser
-- Copyright (c) 2014 - 2015, James Humphry
--
-- Permission to use, copy, modify, and/or distribute this software for any
-- purpose with or without fee is hereby granted, provided that the above
-- copyright notice and this permission notice appear in all copies.
--
-- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
-- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
-- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
-- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
-- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
-- OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
-- PERFORMANCE OF THIS SOFTWARE.
-- This private child package contains some concrete implementations of
-- different options. It is not expected that package users will create these
-- types directly. Instead the factory functions in the parent package are used,
-- as these ensure that the options will be indexed and referenced correctly.
pragma Profile(No_Implementation_Extensions);
private package Parse_Args.Concrete is
-- Concrete options are not exposed to ensure that any options are not added
-- to Argument_Parser inconsistently.
type Option_With_Argument is abstract new Option with null record;
procedure Set_Option(O : in out Option_With_Argument; A : in out Argument_Parser'Class);
type Concrete_Boolean_Option is new Option and Boolean_Option with record
Value : Boolean := False;
Default : Boolean := False;
end record;
procedure Set_Option(O : in out Concrete_Boolean_Option; A : in out Argument_Parser'Class);
function Image(O : in Concrete_Boolean_Option) return String is (Boolean'Image(O.Value));
function Value(O : in Concrete_Boolean_Option) return Boolean is (O.Value);
type Concrete_Integer_Option is new Option_With_Argument and Integer_Option with record
Value : Integer := 0;
Default : Integer := 0;
Min : Integer := Integer'First;
Max : Integer := Integer'Last;
end record;
procedure Set_Option_Argument(O : in out Concrete_Integer_Option;
Arg : in String;
A : in out Argument_Parser'Class);
function Image(O : in Concrete_Integer_Option) return String is (Integer'Image(O.Value));
function Value(O : in Concrete_Integer_Option) return Integer is (O.Value);
type Repeated_Option is new Concrete_Integer_Option with null record;
procedure Set_Option(O : in out Repeated_Option; A : in out Argument_Parser'Class);
type Concrete_String_Option is new Option_With_Argument and String_Option with record
Value : Unbounded_String := Null_Unbounded_String;
Default : Unbounded_String := Null_Unbounded_String;
end record;
procedure Set_Option_Argument(O : in out Concrete_String_Option;
Arg : in String;
A : in out Argument_Parser'Class);
function Value(O : in Concrete_String_Option) return String is (To_String(O.Value));
function Image(O : in Concrete_String_Option) return String renames Value;
overriding procedure Finalize(Object : in out Concrete_String_Option);
end Parse_Args.Concrete;
|
-- { dg-do compile }
-- { dg-options "-O2 -fstack-usage" }
with System;
procedure Stack_Usage2 is
Sink : System.Address;
pragma Import (Ada, Sink);
procedure Transmit_Data (Branch : Integer) is
pragma No_Inline (Transmit_Data);
X : Integer;
begin
case Branch is
when 1 => Sink := X'Address;
when others => null;
end case;
end;
begin
Transmit_Data (Branch => 1);
end;
-- { dg-final { scan-stack-usage-not ":Constprop" } }
-- { dg-final { cleanup-stack-usage } }
|
-- Author: A. Ireland
--
-- Address: School Mathematical & Computer Sciences
-- Heriot-Watt University
-- Edinburgh, EH14 4AS
--
-- E-mail: a.ireland@hw.ac.uk
--
-- Last modified: 13.9.2019
--
-- Filename: sensors.ads
--
-- Description: Models the 3 pressure sensors associated with the WTP system. Note that
-- a single sensor reading is calculated using a majority vote
-- algorithm.
pragma SPARK_Mode (On);
package Sensors
with
Abstract_State => State
is
subtype Sensor_Type is Integer range 0..2100;
subtype Sensor_Index_Type is Integer range 1..3;
procedure Write_Sensors(Value_1, Value_2, Value_3: in Sensor_Type)
with
Global => (Output => State),
Depends => (State => (Value_1, Value_2, Value_3));
function Read_Sensor(Sensor_Index: in Sensor_Index_Type) return Sensor_Type
with
Global => (Input => State),
Depends => (Read_Sensor'Result => (State, Sensor_Index));
function Read_Sensor_Majority return Sensor_Type
with
Global => (Input => State),
Depends => (Read_Sensor_Majority'Result => State);
end Sensors;
|
-- Generated by Snowball 2.2.0 - https://snowballstem.org/
package body Stemmer.Hungarian is
pragma Style_Checks ("-mr");
pragma Warnings (Off, "*variable*is never read and never assigned*");
pragma Warnings (Off, "*mode could be*instead of*");
pragma Warnings (Off, "*formal parameter.*is not modified*");
pragma Warnings (Off, "*this line is too long*");
pragma Warnings (Off, "*is not referenced*");
procedure R_Double (Z : in out Context_Type; Result : out Boolean);
procedure R_Undouble (Z : in out Context_Type; Result : out Boolean);
procedure R_Factive (Z : in out Context_Type; Result : out Boolean);
procedure R_Instrum (Z : in out Context_Type; Result : out Boolean);
procedure R_Plur_owner (Z : in out Context_Type; Result : out Boolean);
procedure R_Sing_owner (Z : in out Context_Type; Result : out Boolean);
procedure R_Owned (Z : in out Context_Type; Result : out Boolean);
procedure R_Plural (Z : in out Context_Type; Result : out Boolean);
procedure R_Case_other (Z : in out Context_Type; Result : out Boolean);
procedure R_Case_special (Z : in out Context_Type; Result : out Boolean);
procedure R_Case (Z : in out Context_Type; Result : out Boolean);
procedure R_V_ending (Z : in out Context_Type; Result : out Boolean);
procedure R_R1 (Z : in out Context_Type; Result : out Boolean);
procedure R_Mark_regions (Z : in out Context_Type; Result : out Boolean);
G_V : constant Grouping_Array (0 .. 279) := (
True, False, False, False, True, False, False, False,
True, False, False, False, False, False, True, False,
False, False, False, False, True, False, False, False,
False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False,
True, False, False, False, False, False, False, False,
True, False, False, False, True, False, False, False,
False, False, True, False, False, True, False, False,
False, True, False, True, False, False, False, False,
False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False,
True, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False,
True, False, False, False, False, False, False, False
);
Among_String : constant String := "cs" & "dzs" & "gy" & "ly" & "ny" & "sz"
& "ty" & "zs" & "á" & "é" & "bb" & "cc" & "dd" & "ff" & "gg" & "jj" & "kk"
& "ll" & "mm" & "nn" & "pp" & "rr" & "ccs" & "ss" & "zzs" & "tt" & "vv" & "ggy"
& "lly" & "nny" & "tty" & "ssz" & "zz" & "al" & "el" & "ba" & "ra" & "be" & "re"
& "ig" & "nak" & "nek" & "val" & "vel" & "ul" & "ből" & "ről" & "től" & "nál"
& "nél" & "ból" & "ról" & "tól" & "ül" & "n" & "an" & "ban" & "en" & "ben"
& "képpen" & "on" & "ön" & "képp" & "kor" & "t" & "at" & "et" & "ként"
& "anként" & "enként" & "onként" & "ot" & "ért" & "öt" & "hez" & "hoz"
& "höz" & "vá" & "vé" & "án" & "én" & "ánként" & "stul" & "astul"
& "ástul" & "stül" & "estül" & "éstül" & "á" & "é" & "k" & "ak" & "ek"
& "ok" & "ák" & "ék" & "ök" & "éi" & "áéi" & "ééi" & "é" & "ké"
& "aké" & "eké" & "oké" & "áké" & "éké" & "öké" & "éé" & "a" & "ja"
& "d" & "ad" & "ed" & "od" & "ád" & "éd" & "öd" & "e" & "je" & "nk" & "unk"
& "ánk" & "énk" & "ünk" & "uk" & "juk" & "ájuk" & "ük" & "jük" & "éjük"
& "m" & "am" & "em" & "om" & "ám" & "ém" & "o" & "á" & "é" & "id" & "aid"
& "jaid" & "eid" & "jeid" & "áid" & "éid" & "i" & "ai" & "jai" & "ei" & "jei"
& "ái" & "éi" & "itek" & "eitek" & "jeitek" & "éitek" & "ik" & "aik" & "jaik"
& "eik" & "jeik" & "áik" & "éik" & "ink" & "aink" & "jaink" & "eink" & "jeink"
& "áink" & "éink" & "aitok" & "jaitok" & "áitok" & "im" & "aim" & "jaim"
& "eim" & "jeim" & "áim" & "éim";
A_0 : constant Among_Array_Type (0 .. 7) := (
(1, 2, -1, -1, 0),
(3, 5, -1, -1, 0),
(6, 7, -1, -1, 0),
(8, 9, -1, -1, 0),
(10, 11, -1, -1, 0),
(12, 13, -1, -1, 0),
(14, 15, -1, -1, 0),
(16, 17, -1, -1, 0));
A_1 : constant Among_Array_Type (0 .. 1) := (
(18, 19, -1, 1, 0),
(20, 21, -1, 2, 0));
A_2 : constant Among_Array_Type (0 .. 22) := (
(22, 23, -1, -1, 0),
(24, 25, -1, -1, 0),
(26, 27, -1, -1, 0),
(28, 29, -1, -1, 0),
(30, 31, -1, -1, 0),
(32, 33, -1, -1, 0),
(34, 35, -1, -1, 0),
(36, 37, -1, -1, 0),
(38, 39, -1, -1, 0),
(40, 41, -1, -1, 0),
(42, 43, -1, -1, 0),
(44, 45, -1, -1, 0),
(46, 48, -1, -1, 0),
(49, 50, -1, -1, 0),
(51, 53, -1, -1, 0),
(54, 55, -1, -1, 0),
(56, 57, -1, -1, 0),
(58, 60, -1, -1, 0),
(61, 63, -1, -1, 0),
(64, 66, -1, -1, 0),
(67, 69, -1, -1, 0),
(70, 72, -1, -1, 0),
(73, 74, -1, -1, 0));
A_3 : constant Among_Array_Type (0 .. 1) := (
(75, 76, -1, 1, 0),
(77, 78, -1, 1, 0));
A_4 : constant Among_Array_Type (0 .. 43) := (
(79, 80, -1, -1, 0),
(81, 82, -1, -1, 0),
(83, 84, -1, -1, 0),
(85, 86, -1, -1, 0),
(87, 88, -1, -1, 0),
(89, 91, -1, -1, 0),
(92, 94, -1, -1, 0),
(95, 97, -1, -1, 0),
(98, 100, -1, -1, 0),
(101, 102, -1, -1, 0),
(103, 106, -1, -1, 0),
(107, 110, -1, -1, 0),
(111, 114, -1, -1, 0),
(115, 118, -1, -1, 0),
(119, 122, -1, -1, 0),
(123, 126, -1, -1, 0),
(127, 130, -1, -1, 0),
(131, 134, -1, -1, 0),
(135, 137, -1, -1, 0),
(138, 138, -1, -1, 0),
(139, 140, 19, -1, 0),
(141, 143, 20, -1, 0),
(144, 145, 19, -1, 0),
(146, 148, 22, -1, 0),
(149, 155, 22, -1, 0),
(156, 157, 19, -1, 0),
(158, 160, 19, -1, 0),
(161, 165, -1, -1, 0),
(166, 168, -1, -1, 0),
(169, 169, -1, -1, 0),
(170, 171, 29, -1, 0),
(172, 173, 29, -1, 0),
(174, 178, 29, -1, 0),
(179, 185, 32, -1, 0),
(186, 192, 32, -1, 0),
(193, 199, 32, -1, 0),
(200, 201, 29, -1, 0),
(202, 205, 29, -1, 0),
(206, 208, 29, -1, 0),
(209, 211, -1, -1, 0),
(212, 214, -1, -1, 0),
(215, 218, -1, -1, 0),
(219, 221, -1, -1, 0),
(222, 224, -1, -1, 0));
A_5 : constant Among_Array_Type (0 .. 2) := (
(225, 227, -1, 2, 0),
(228, 230, -1, 1, 0),
(231, 238, -1, 2, 0));
A_6 : constant Among_Array_Type (0 .. 5) := (
(239, 242, -1, 1, 0),
(243, 247, 0, 1, 0),
(248, 253, 0, 2, 0),
(254, 258, -1, 1, 0),
(259, 264, 3, 1, 0),
(265, 271, 3, 3, 0));
A_7 : constant Among_Array_Type (0 .. 1) := (
(272, 273, -1, 1, 0),
(274, 275, -1, 1, 0));
A_8 : constant Among_Array_Type (0 .. 6) := (
(276, 276, -1, 3, 0),
(277, 278, 0, 3, 0),
(279, 280, 0, 3, 0),
(281, 282, 0, 3, 0),
(283, 285, 0, 1, 0),
(286, 288, 0, 2, 0),
(289, 291, 0, 3, 0));
A_9 : constant Among_Array_Type (0 .. 11) := (
(292, 294, -1, 1, 0),
(295, 299, 0, 3, 0),
(300, 304, 0, 2, 0),
(305, 306, -1, 1, 0),
(307, 309, 3, 1, 0),
(310, 313, 4, 1, 0),
(314, 317, 4, 1, 0),
(318, 321, 4, 1, 0),
(322, 326, 4, 3, 0),
(327, 331, 4, 2, 0),
(332, 336, 4, 1, 0),
(337, 340, 3, 2, 0));
A_10 : constant Among_Array_Type (0 .. 30) := (
(341, 341, -1, 1, 0),
(342, 343, 0, 1, 0),
(344, 344, -1, 1, 0),
(345, 346, 2, 1, 0),
(347, 348, 2, 1, 0),
(349, 350, 2, 1, 0),
(351, 353, 2, 2, 0),
(354, 356, 2, 3, 0),
(357, 359, 2, 1, 0),
(360, 360, -1, 1, 0),
(361, 362, 9, 1, 0),
(363, 364, -1, 1, 0),
(365, 367, 11, 1, 0),
(368, 371, 11, 2, 0),
(372, 375, 11, 3, 0),
(376, 379, 11, 1, 0),
(380, 381, -1, 1, 0),
(382, 384, 16, 1, 0),
(385, 389, 17, 2, 0),
(390, 392, -1, 1, 0),
(393, 396, 19, 1, 0),
(397, 402, 20, 3, 0),
(403, 403, -1, 1, 0),
(404, 405, 22, 1, 0),
(406, 407, 22, 1, 0),
(408, 409, 22, 1, 0),
(410, 412, 22, 2, 0),
(413, 415, 22, 3, 0),
(416, 416, -1, 1, 0),
(417, 418, -1, 2, 0),
(419, 420, -1, 3, 0));
A_11 : constant Among_Array_Type (0 .. 41) := (
(421, 422, -1, 1, 0),
(423, 425, 0, 1, 0),
(426, 429, 1, 1, 0),
(430, 432, 0, 1, 0),
(433, 436, 3, 1, 0),
(437, 440, 0, 2, 0),
(441, 444, 0, 3, 0),
(445, 445, -1, 1, 0),
(446, 447, 7, 1, 0),
(448, 450, 8, 1, 0),
(451, 452, 7, 1, 0),
(453, 455, 10, 1, 0),
(456, 458, 7, 2, 0),
(459, 461, 7, 3, 0),
(462, 465, -1, 1, 0),
(466, 470, 14, 1, 0),
(471, 476, 15, 1, 0),
(477, 482, 14, 3, 0),
(483, 484, -1, 1, 0),
(485, 487, 18, 1, 0),
(488, 491, 19, 1, 0),
(492, 494, 18, 1, 0),
(495, 498, 21, 1, 0),
(499, 502, 18, 2, 0),
(503, 506, 18, 3, 0),
(507, 509, -1, 1, 0),
(510, 513, 25, 1, 0),
(514, 518, 26, 1, 0),
(519, 522, 25, 1, 0),
(523, 527, 28, 1, 0),
(528, 532, 25, 2, 0),
(533, 537, 25, 3, 0),
(538, 542, -1, 1, 0),
(543, 548, 32, 1, 0),
(549, 554, -1, 2, 0),
(555, 556, -1, 1, 0),
(557, 559, 35, 1, 0),
(560, 563, 36, 1, 0),
(564, 566, 35, 1, 0),
(567, 570, 38, 1, 0),
(571, 574, 35, 2, 0),
(575, 578, 35, 3, 0));
procedure R_Mark_regions (Z : in out Context_Type; Result : out Boolean) is
C : Result_Index;
A : Integer;
v_1 : Char_Index;
v_2 : Char_Index;
begin
-- (, line 44
Z.I_P1 := Z.L;
-- or, line 51
v_1 := Z.C;
-- (, line 48
In_Grouping (Z, G_V, 97, 369, False, C);
if C /= 0 then
goto lab1;
end if;
-- goto, line 48
In_Grouping (Z, G_V, 97, 369, True, C); if C < 0 then
goto lab1;
end if;
-- or, line 49
v_2 := Z.C;
-- among, line 49
if Z.C + 1 >= Z.L or else Check_Among (Z, Z.C + 1, 3, 16#6080000#) then
goto lab4;
-- among, line 49
end if;
Find_Among (Z, A_0, Among_String, null, A);
if A = 0 then
goto lab4;
end if;
goto lab3;
<<lab4>>
Z.C := v_2;
-- next, line 49
C := Skip_Utf8 (Z);
if C < 0 then
goto lab1;
end if;
Z.C := C;
<<lab3>>
-- setmark p1, line 50
Z.I_P1 := Z.C;
goto lab0;
<<lab1>>
Z.C := v_1;
-- (, line 53
Out_Grouping (Z, G_V, 97, 369, False, C);
if C /= 0 then
Result := False;
return;
end if;
-- gopast, line 53
-- grouping v, line 53
Out_Grouping (Z, G_V, 97, 369, True, C);
if C < 0 then
Result := False;
return;
end if;
Z.C := Z.C + C;
-- setmark p1, line 53
Z.I_P1 := Z.C;
<<lab0>>
Result := True;
end R_Mark_regions;
procedure R_R1 (Z : in out Context_Type; Result : out Boolean) is
begin
Result := (Z.I_P1 <= Z.C);
end R_R1;
procedure R_V_ending (Z : in out Context_Type; Result : out Boolean) is
C : Result_Index;
A : Integer;
begin
-- (, line 60
Z.Ket := Z.C; -- [, line 61
-- substring, line 61
if Z.C - 1 <= Z.Lb or else (Character'Pos (Z.P (Z.C)) /= 161 and then Character'Pos (Z.P (Z.C)) /= 169) then
Result := False;
return;
-- substring, line 61
end if;
Find_Among_Backward (Z, A_1, Among_String, null, A);
if A = 0 then
Result := False;
return;
end if;
Z.Bra := Z.C; -- ], line 61
-- call R1, line 61
R_R1 (Z, Result);
if not Result then
Result := False;
return;
end if;
-- among, line 61
case A is
when 1 =>
-- (, line 62
-- <-, line 62
Slice_From (Z, "a");
when 2 =>
-- (, line 63
-- <-, line 63
Slice_From (Z, "e");
when others =>
null;
end case;
Result := True;
end R_V_ending;
procedure R_Double (Z : in out Context_Type; Result : out Boolean) is
C : Result_Index;
A : Integer;
v_1 : Char_Index;
begin
-- test, line 68
v_1 := Z.L - Z.C;
-- among, line 68
if Z.C - 1 <= Z.Lb or else Check_Among (Z, Z.C - 1, 3, 16#65d7cdc#) then
Result := False;
return;
-- among, line 68
end if;
Find_Among_Backward (Z, A_2, Among_String, null, A);
if A = 0 then
Result := False;
return;
end if;
Z.C := Z.L - v_1;
Result := True;
end R_Double;
procedure R_Undouble (Z : in out Context_Type; Result : out Boolean) is
C : Result_Index;
A : Integer;
begin
-- (, line 72
-- next, line 73
C := Skip_Utf8_Backward (Z);
if C < 0 then
Result := False;
return;
end if;
Z.C := C;
Z.Ket := Z.C; -- [, line 73
C := Skip_Utf8_Backward (Z, 1); -- hop, line 73
if C < 0 then
Result := False;
return;
end if;
Z.C := C;
Z.Bra := Z.C; -- ], line 73
-- delete, line 73
Slice_Del (Z);
Result := True;
end R_Undouble;
procedure R_Instrum (Z : in out Context_Type; Result : out Boolean) is
C : Result_Index;
A : Integer;
begin
-- (, line 76
Z.Ket := Z.C; -- [, line 77
-- substring, line 77
if Z.C - 1 <= Z.Lb or else Character'Pos (Z.P (Z.C)) /= 108 then
Result := False;
return;
-- substring, line 77
end if;
Find_Among_Backward (Z, A_3, Among_String, null, A);
if A = 0 then
Result := False;
return;
end if;
Z.Bra := Z.C; -- ], line 77
-- call R1, line 77
R_R1 (Z, Result);
if not Result then
Result := False;
return;
end if;
-- (, line 78
-- call double, line 78
R_Double (Z, Result);
if not Result then
Result := False;
return;
end if;
-- delete, line 81
Slice_Del (Z);
-- call undouble, line 82
R_Undouble (Z, Result);
if not Result then
Result := False;
return;
end if;
Result := True;
end R_Instrum;
procedure R_Case (Z : in out Context_Type; Result : out Boolean) is
C : Result_Index;
A : Integer;
begin
-- (, line 86
Z.Ket := Z.C; -- [, line 87
-- substring, line 87
Find_Among_Backward (Z, A_4, Among_String, null, A);
if A = 0 then
Result := False;
return;
end if;
Z.Bra := Z.C; -- ], line 87
-- call R1, line 87
R_R1 (Z, Result);
if not Result then
Result := False;
return;
end if;
-- delete, line 111
Slice_Del (Z);
-- call v_ending, line 112
R_V_ending (Z, Result);
if not Result then
Result := False;
return;
end if;
Result := True;
end R_Case;
procedure R_Case_special (Z : in out Context_Type; Result : out Boolean) is
C : Result_Index;
A : Integer;
begin
-- (, line 115
Z.Ket := Z.C; -- [, line 116
-- substring, line 116
if Z.C - 2 <= Z.Lb or else (Character'Pos (Z.P (Z.C)) /= 110 and then Character'Pos (Z.P (Z.C)) /= 116) then
Result := False;
return;
-- substring, line 116
end if;
Find_Among_Backward (Z, A_5, Among_String, null, A);
if A = 0 then
Result := False;
return;
end if;
Z.Bra := Z.C; -- ], line 116
-- call R1, line 116
R_R1 (Z, Result);
if not Result then
Result := False;
return;
end if;
-- among, line 116
case A is
when 1 =>
-- (, line 117
-- <-, line 117
Slice_From (Z, "e");
when 2 =>
-- (, line 118
-- <-, line 118
Slice_From (Z, "a");
when others =>
null;
end case;
Result := True;
end R_Case_special;
procedure R_Case_other (Z : in out Context_Type; Result : out Boolean) is
C : Result_Index;
A : Integer;
begin
-- (, line 123
Z.Ket := Z.C; -- [, line 124
-- substring, line 124
if Z.C - 3 <= Z.Lb or else Character'Pos (Z.P (Z.C)) /= 108 then
Result := False;
return;
-- substring, line 124
end if;
Find_Among_Backward (Z, A_6, Among_String, null, A);
if A = 0 then
Result := False;
return;
end if;
Z.Bra := Z.C; -- ], line 124
-- call R1, line 124
R_R1 (Z, Result);
if not Result then
Result := False;
return;
end if;
-- among, line 124
case A is
when 1 =>
-- (, line 125
-- delete, line 125
Slice_Del (Z);
when 2 =>
-- (, line 127
-- <-, line 127
Slice_From (Z, "a");
when 3 =>
-- (, line 128
-- <-, line 128
Slice_From (Z, "e");
when others =>
null;
end case;
Result := True;
end R_Case_other;
procedure R_Factive (Z : in out Context_Type; Result : out Boolean) is
C : Result_Index;
A : Integer;
begin
-- (, line 132
Z.Ket := Z.C; -- [, line 133
-- substring, line 133
if Z.C - 1 <= Z.Lb or else (Character'Pos (Z.P (Z.C)) /= 161 and then Character'Pos (Z.P (Z.C)) /= 169) then
Result := False;
return;
-- substring, line 133
end if;
Find_Among_Backward (Z, A_7, Among_String, null, A);
if A = 0 then
Result := False;
return;
end if;
Z.Bra := Z.C; -- ], line 133
-- call R1, line 133
R_R1 (Z, Result);
if not Result then
Result := False;
return;
end if;
-- (, line 134
-- call double, line 134
R_Double (Z, Result);
if not Result then
Result := False;
return;
end if;
-- delete, line 137
Slice_Del (Z);
-- call undouble, line 138
R_Undouble (Z, Result);
if not Result then
Result := False;
return;
end if;
Result := True;
end R_Factive;
procedure R_Plural (Z : in out Context_Type; Result : out Boolean) is
C : Result_Index;
A : Integer;
begin
-- (, line 141
Z.Ket := Z.C; -- [, line 142
-- substring, line 142
if Z.C <= Z.Lb or else Character'Pos (Z.P (Z.C)) /= 107 then
Result := False;
return;
-- substring, line 142
end if;
Find_Among_Backward (Z, A_8, Among_String, null, A);
if A = 0 then
Result := False;
return;
end if;
Z.Bra := Z.C; -- ], line 142
-- call R1, line 142
R_R1 (Z, Result);
if not Result then
Result := False;
return;
end if;
-- among, line 142
case A is
when 1 =>
-- (, line 143
-- <-, line 143
Slice_From (Z, "a");
when 2 =>
-- (, line 144
-- <-, line 144
Slice_From (Z, "e");
when 3 =>
-- (, line 145
-- delete, line 145
Slice_Del (Z);
when others =>
null;
end case;
Result := True;
end R_Plural;
procedure R_Owned (Z : in out Context_Type; Result : out Boolean) is
C : Result_Index;
A : Integer;
begin
-- (, line 153
Z.Ket := Z.C; -- [, line 154
-- substring, line 154
if Z.C - 1 <= Z.Lb or else (Character'Pos (Z.P (Z.C)) /= 105 and then Character'Pos (Z.P (Z.C)) /= 169) then
Result := False;
return;
-- substring, line 154
end if;
Find_Among_Backward (Z, A_9, Among_String, null, A);
if A = 0 then
Result := False;
return;
end if;
Z.Bra := Z.C; -- ], line 154
-- call R1, line 154
R_R1 (Z, Result);
if not Result then
Result := False;
return;
end if;
-- among, line 154
case A is
when 1 =>
-- (, line 155
-- delete, line 155
Slice_Del (Z);
when 2 =>
-- (, line 156
-- <-, line 156
Slice_From (Z, "e");
when 3 =>
-- (, line 157
-- <-, line 157
Slice_From (Z, "a");
when others =>
null;
end case;
Result := True;
end R_Owned;
procedure R_Sing_owner (Z : in out Context_Type; Result : out Boolean) is
C : Result_Index;
A : Integer;
begin
-- (, line 167
Z.Ket := Z.C; -- [, line 168
-- substring, line 168
Find_Among_Backward (Z, A_10, Among_String, null, A);
if A = 0 then
Result := False;
return;
end if;
Z.Bra := Z.C; -- ], line 168
-- call R1, line 168
R_R1 (Z, Result);
if not Result then
Result := False;
return;
end if;
-- among, line 168
case A is
when 1 =>
-- (, line 169
-- delete, line 169
Slice_Del (Z);
when 2 =>
-- (, line 170
-- <-, line 170
Slice_From (Z, "a");
when 3 =>
-- (, line 171
-- <-, line 171
Slice_From (Z, "e");
when others =>
null;
end case;
Result := True;
end R_Sing_owner;
procedure R_Plur_owner (Z : in out Context_Type; Result : out Boolean) is
C : Result_Index;
A : Integer;
begin
-- (, line 192
Z.Ket := Z.C; -- [, line 193
-- substring, line 193
if Z.C <= Z.Lb or else Check_Among (Z, Z.C - 1, 3, 16#2a10#) then
Result := False;
return;
-- substring, line 193
end if;
Find_Among_Backward (Z, A_11, Among_String, null, A);
if A = 0 then
Result := False;
return;
end if;
Z.Bra := Z.C; -- ], line 193
-- call R1, line 193
R_R1 (Z, Result);
if not Result then
Result := False;
return;
end if;
-- among, line 193
case A is
when 1 =>
-- (, line 194
-- delete, line 194
Slice_Del (Z);
when 2 =>
-- (, line 195
-- <-, line 195
Slice_From (Z, "a");
when 3 =>
-- (, line 196
-- <-, line 196
Slice_From (Z, "e");
when others =>
null;
end case;
Result := True;
end R_Plur_owner;
procedure Stem (Z : in out Context_Type; Result : out Boolean) is
C : Result_Index;
A : Integer;
v_1 : Char_Index;
v_2 : Char_Index;
v_3 : Char_Index;
v_4 : Char_Index;
v_5 : Char_Index;
v_6 : Char_Index;
v_7 : Char_Index;
v_8 : Char_Index;
v_9 : Char_Index;
v_10 : Char_Index;
begin
-- (, line 228
-- do, line 229
v_1 := Z.C;
-- call mark_regions, line 229
R_Mark_regions (Z, Result);
Z.C := v_1;
Z.Lb := Z.C; Z.C := Z.L; -- backwards, line 230
-- (, line 230
-- do, line 231
v_2 := Z.L - Z.C;
-- call instrum, line 231
R_Instrum (Z, Result);
Z.C := Z.L - v_2;
-- do, line 232
v_3 := Z.L - Z.C;
-- call case, line 232
R_Case (Z, Result);
Z.C := Z.L - v_3;
-- do, line 233
v_4 := Z.L - Z.C;
-- call case_special, line 233
R_Case_special (Z, Result);
Z.C := Z.L - v_4;
-- do, line 234
v_5 := Z.L - Z.C;
-- call case_other, line 234
R_Case_other (Z, Result);
Z.C := Z.L - v_5;
-- do, line 235
v_6 := Z.L - Z.C;
-- call factive, line 235
R_Factive (Z, Result);
Z.C := Z.L - v_6;
-- do, line 236
v_7 := Z.L - Z.C;
-- call owned, line 236
R_Owned (Z, Result);
Z.C := Z.L - v_7;
-- do, line 237
v_8 := Z.L - Z.C;
-- call sing_owner, line 237
R_Sing_owner (Z, Result);
Z.C := Z.L - v_8;
-- do, line 238
v_9 := Z.L - Z.C;
-- call plur_owner, line 238
R_Plur_owner (Z, Result);
Z.C := Z.L - v_9;
-- do, line 239
v_10 := Z.L - Z.C;
-- call plural, line 239
R_Plural (Z, Result);
Z.C := Z.L - v_10;
Z.C := Z.Lb;
Result := True;
end Stem;
end Stemmer.Hungarian;
|
type IO_Port is mod 2**8; -- One byte
Device_Port : type IO_Port;
for Device_Port'Address use 16#FFFF_F000#;
|
------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- C S T A N D --
-- --
-- B o d y --
-- --
-- Copyright (C) 1992-2020, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
-- for more details. You should have received a copy of the GNU General --
-- Public License distributed with GNAT; see file COPYING3. If not, go to --
-- http://www.gnu.org/licenses for a complete copy of the license. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
with Atree; use Atree;
with Csets; use Csets;
with Debug; use Debug;
with Einfo; use Einfo;
with Elists; use Elists;
with Layout; use Layout;
with Namet; use Namet;
with Nlists; use Nlists;
with Nmake; use Nmake;
with Opt; use Opt;
with Output; use Output;
with Set_Targ; use Set_Targ;
with Targparm; use Targparm;
with Tbuild; use Tbuild;
with Ttypes; use Ttypes;
with Sem_Mech; use Sem_Mech;
with Sem_Util; use Sem_Util;
with Sinfo; use Sinfo;
with Snames; use Snames;
with Stand; use Stand;
with Uintp; use Uintp;
with Urealp; use Urealp;
package body CStand is
Stloc : Source_Ptr renames Standard_Location;
Staloc : Source_Ptr renames Standard_ASCII_Location;
-- Standard abbreviations used throughout this package
Back_End_Float_Types : Elist_Id := No_Elist;
-- List used for any floating point supported by the back end. This needs
-- to be at the library level, because the call back procedures retrieving
-- this information are at that level.
-----------------------
-- Local Subprograms --
-----------------------
procedure Build_Float_Type
(E : Entity_Id;
Digs : Int;
Rep : Float_Rep_Kind;
Siz : Int;
Align : Int);
-- Procedure to build standard predefined float base type. The first
-- parameter is the entity for the type. The second parameter is the
-- digits value. The third parameter indicates the representation to
-- be used for the type. The fourth parameter is the size in bits.
-- The fifth parameter is the alignment in storage units. Each type
-- is added to the list of predefined floating point types.
--
-- Note that both RM_Size and Esize are set to the specified size, i.e.
-- we do not set the RM_Size to the precision passed by the back end.
-- This is consistent with the semantics of 'Size specified in the RM
-- because we cannot pack components of the type tighter than this size.
procedure Build_Signed_Integer_Type (E : Entity_Id; Siz : Nat);
-- Procedure to build standard predefined signed integer subtype. The
-- first parameter is the entity for the subtype. The second parameter
-- is the size in bits. The corresponding base type is not built by
-- this routine but instead must be built by the caller where needed.
procedure Build_Unsigned_Integer_Type (Uns : Entity_Id; Siz : Nat);
-- Procedure to build standard predefined unsigned integer subtype. These
-- subtypes are not user visible, but they are used internally. The first
-- parameter is the entity for the subtype. The second parameter is the
-- size in bits.
procedure Copy_Float_Type (To : Entity_Id; From : Entity_Id);
-- Build a floating point type, copying representation details from From.
-- This is used to create predefined floating point types based on
-- available types in the back end.
procedure Create_Operators;
-- Make entries for each of the predefined operators in Standard
procedure Create_Unconstrained_Base_Type
(E : Entity_Id;
K : Entity_Kind);
-- The predefined signed integer types are constrained subtypes which
-- must have a corresponding unconstrained base type. This type is almost
-- useless. The only place it has semantics is Subtypes_Statically_Match.
-- Consequently, we arrange for it to be identical apart from the setting
-- of the constrained bit. This routine takes an entity E for the Type,
-- copies it to estabish the base type, then resets the Ekind of the
-- original entity to K (the Ekind for the subtype). The Etype field of
-- E is set by the call (to point to the created base type entity), and
-- also the Is_Constrained flag of E is set.
--
-- To understand the exact requirement for this, see RM 3.5.4(11) which
-- makes it clear that Integer, for example, is constrained, with the
-- constraint bounds matching the bounds of the (unconstrained) base
-- type. The point is that Integer and Integer'Base have identical
-- bounds, but do not statically match, since a subtype with constraints
-- never matches a subtype with no constraints.
function Find_Back_End_Float_Type (Name : String) return Entity_Id;
-- Return the first float type in Back_End_Float_Types with the given name.
-- Names of entities in back end types, are either type names of C
-- predefined types (all lower case), or mode names (upper case).
-- These are not generally valid identifier names.
function Identifier_For (S : Standard_Entity_Type) return Node_Id;
-- Returns an identifier node with the same name as the defining identifier
-- corresponding to the given Standard_Entity_Type value.
procedure Make_Component
(Rec : Entity_Id;
Typ : Entity_Id;
Nam : String);
-- Build a record component with the given type and name, and append to
-- the list of components of Rec.
function Make_Formal (Typ : Entity_Id; Nam : String) return Entity_Id;
-- Construct entity for subprogram formal with given name and type
function Make_Integer (V : Uint) return Node_Id;
-- Builds integer literal with given value
function New_Operator (Op : Name_Id; Typ : Entity_Id) return Entity_Id;
-- Build entity for standard operator with given name and type
function New_Standard_Entity
(New_Node_Kind : Node_Kind := N_Defining_Identifier) return Entity_Id;
-- Builds a new entity for Standard
function New_Standard_Entity (Nam : String) return Entity_Id;
-- Builds a new entity for Standard with Nkind = N_Defining_Identifier,
-- and Chars of this defining identifier set to the given string Nam.
procedure Print_Standard;
-- Print representation of package Standard if switch set
procedure Register_Float_Type
(Name : String;
Digs : Positive;
Float_Rep : Float_Rep_Kind;
Precision : Positive;
Size : Positive;
Alignment : Natural);
-- Registers a single back end floating-point type (from FPT_Mode_Table in
-- Set_Targ). This will create a predefined floating-point base type for
-- one of the floating point types reported by the back end, and add it
-- to the list of predefined float types. Name is the name of the type
-- as a normal format (non-null-terminated) string. Digs is the number of
-- digits, which is always non-zero, since non-floating-point types were
-- filtered out earlier. Float_Rep indicates the kind of floating-point
-- type, and Precision, Size and Alignment are the precision, size and
-- alignment in bits.
procedure Set_Integer_Bounds
(Id : Entity_Id;
Typ : Entity_Id;
Lb : Uint;
Hb : Uint);
-- Procedure to set bounds for integer type or subtype. Id is the entity
-- whose bounds and type are to be set. The Typ parameter is the Etype
-- value for the entity (which will be the same as Id for all predefined
-- integer base types. The third and fourth parameters are the bounds.
----------------------
-- Build_Float_Type --
----------------------
procedure Build_Float_Type
(E : Entity_Id;
Digs : Int;
Rep : Float_Rep_Kind;
Siz : Int;
Align : Int)
is
begin
Set_Type_Definition (Parent (E),
Make_Floating_Point_Definition (Stloc,
Digits_Expression => Make_Integer (UI_From_Int (Digs))));
Set_Ekind (E, E_Floating_Point_Type);
Set_Etype (E, E);
Init_Digits_Value (E, Digs);
Set_Float_Rep (E, Rep);
Init_Size (E, Siz);
Set_Elem_Alignment (E, Align);
Set_Float_Bounds (E);
Set_Is_Frozen (E);
Set_Is_Public (E);
Set_Size_Known_At_Compile_Time (E);
end Build_Float_Type;
------------------------------
-- Find_Back_End_Float_Type --
------------------------------
function Find_Back_End_Float_Type (Name : String) return Entity_Id is
N : Elmt_Id;
begin
N := First_Elmt (Back_End_Float_Types);
while Present (N) and then Get_Name_String (Chars (Node (N))) /= Name
loop
Next_Elmt (N);
end loop;
return Node (N);
end Find_Back_End_Float_Type;
-------------------------------
-- Build_Signed_Integer_Type --
-------------------------------
procedure Build_Signed_Integer_Type (E : Entity_Id; Siz : Nat) is
U2Siz1 : constant Uint := 2 ** (Siz - 1);
Lbound : constant Uint := -U2Siz1;
Ubound : constant Uint := U2Siz1 - 1;
begin
Set_Type_Definition (Parent (E),
Make_Signed_Integer_Type_Definition (Stloc,
Low_Bound => Make_Integer (Lbound),
High_Bound => Make_Integer (Ubound)));
Set_Ekind (E, E_Signed_Integer_Type);
Set_Etype (E, E);
Init_Size (E, Siz);
Set_Elem_Alignment (E);
Set_Integer_Bounds (E, E, Lbound, Ubound);
Set_Is_Frozen (E);
Set_Is_Public (E);
Set_Is_Known_Valid (E);
Set_Size_Known_At_Compile_Time (E);
end Build_Signed_Integer_Type;
---------------------------------
-- Build_Unsigned_Integer_Type --
---------------------------------
procedure Build_Unsigned_Integer_Type
(Uns : Entity_Id;
Siz : Nat)
is
Decl : constant Node_Id := New_Node (N_Full_Type_Declaration, Stloc);
R_Node : constant Node_Id := New_Node (N_Range, Stloc);
begin
Set_Defining_Identifier (Decl, Uns);
Set_Ekind (Uns, E_Modular_Integer_Type);
Set_Scope (Uns, Standard_Standard);
Set_Etype (Uns, Uns);
Init_Size (Uns, Siz);
Set_Elem_Alignment (Uns);
Set_Modulus (Uns, Uint_2 ** Siz);
Set_Is_Unsigned_Type (Uns);
Set_Size_Known_At_Compile_Time (Uns);
Set_Is_Known_Valid (Uns, True);
Set_Low_Bound (R_Node, Make_Integer (Uint_0));
Set_High_Bound (R_Node, Make_Integer (Modulus (Uns) - 1));
Set_Etype (Low_Bound (R_Node), Uns);
Set_Etype (High_Bound (R_Node), Uns);
Set_Scalar_Range (Uns, R_Node);
end Build_Unsigned_Integer_Type;
---------------------
-- Copy_Float_Type --
---------------------
procedure Copy_Float_Type (To : Entity_Id; From : Entity_Id) is
begin
Build_Float_Type
(To, UI_To_Int (Digits_Value (From)), Float_Rep (From),
UI_To_Int (Esize (From)), UI_To_Int (Alignment (From)));
end Copy_Float_Type;
----------------------
-- Create_Operators --
----------------------
-- Each operator has an abbreviated signature. The formals have the names
-- LEFT and RIGHT. Their types are not actually used for resolution.
procedure Create_Operators is
Op_Node : Entity_Id;
-- The following tables define the binary and unary operators and their
-- corresponding result type.
Binary_Ops : constant array (S_Binary_Ops) of Name_Id :=
-- There is one entry here for each binary operator, except for the
-- case of concatenation, where there are three entries, one for a
-- String result, one for Wide_String, and one for Wide_Wide_String.
(Name_Op_Add,
Name_Op_And,
Name_Op_Concat,
Name_Op_Concat,
Name_Op_Concat,
Name_Op_Divide,
Name_Op_Eq,
Name_Op_Expon,
Name_Op_Ge,
Name_Op_Gt,
Name_Op_Le,
Name_Op_Lt,
Name_Op_Mod,
Name_Op_Multiply,
Name_Op_Ne,
Name_Op_Or,
Name_Op_Rem,
Name_Op_Subtract,
Name_Op_Xor);
Bin_Op_Types : constant array (S_Binary_Ops) of Entity_Id :=
-- This table has the corresponding result types. The entries are
-- ordered so they correspond to the Binary_Ops array above.
(Universal_Integer, -- Add
Standard_Boolean, -- And
Standard_String, -- Concat (String)
Standard_Wide_String, -- Concat (Wide_String)
Standard_Wide_Wide_String, -- Concat (Wide_Wide_String)
Universal_Integer, -- Divide
Standard_Boolean, -- Eq
Universal_Integer, -- Expon
Standard_Boolean, -- Ge
Standard_Boolean, -- Gt
Standard_Boolean, -- Le
Standard_Boolean, -- Lt
Universal_Integer, -- Mod
Universal_Integer, -- Multiply
Standard_Boolean, -- Ne
Standard_Boolean, -- Or
Universal_Integer, -- Rem
Universal_Integer, -- Subtract
Standard_Boolean); -- Xor
Unary_Ops : constant array (S_Unary_Ops) of Name_Id :=
-- There is one entry here for each unary operator
(Name_Op_Abs,
Name_Op_Subtract,
Name_Op_Not,
Name_Op_Add);
Unary_Op_Types : constant array (S_Unary_Ops) of Entity_Id :=
-- This table has the corresponding result types. The entries are
-- ordered so they correspond to the Unary_Ops array above.
(Universal_Integer, -- Abs
Universal_Integer, -- Subtract
Standard_Boolean, -- Not
Universal_Integer); -- Add
begin
for J in S_Binary_Ops loop
Op_Node := New_Operator (Binary_Ops (J), Bin_Op_Types (J));
SE (J) := Op_Node;
Append_Entity (Make_Formal (Any_Type, "LEFT"), Op_Node);
Append_Entity (Make_Formal (Any_Type, "RIGHT"), Op_Node);
end loop;
for J in S_Unary_Ops loop
Op_Node := New_Operator (Unary_Ops (J), Unary_Op_Types (J));
SE (J) := Op_Node;
Append_Entity (Make_Formal (Any_Type, "RIGHT"), Op_Node);
end loop;
-- For concatenation, we create a separate operator for each
-- array type. This simplifies the resolution of the component-
-- component concatenation operation. In Standard, we set the types
-- of the formals for string, wide [wide]_string, concatenations.
Set_Etype (First_Entity (Standard_Op_Concat), Standard_String);
Set_Etype (Last_Entity (Standard_Op_Concat), Standard_String);
Set_Etype (First_Entity (Standard_Op_Concatw), Standard_Wide_String);
Set_Etype (Last_Entity (Standard_Op_Concatw), Standard_Wide_String);
Set_Etype (First_Entity (Standard_Op_Concatww),
Standard_Wide_Wide_String);
Set_Etype (Last_Entity (Standard_Op_Concatww),
Standard_Wide_Wide_String);
end Create_Operators;
---------------------
-- Create_Standard --
---------------------
-- The tree for the package Standard is prefixed to all compilations.
-- Several entities required by semantic analysis are denoted by global
-- variables that are initialized to point to the corresponding occurrences
-- in Standard. The visible entities of Standard are created here. Special
-- entities maybe created here as well or may be created from the semantics
-- module. By not adding them to the Decls list of Standard they will not
-- be visible to Ada programs.
procedure Create_Standard is
Decl_S : constant List_Id := New_List;
-- List of declarations in Standard
Decl_A : constant List_Id := New_List;
-- List of declarations in ASCII
Decl : Node_Id;
Pspec : Node_Id;
Tdef_Node : Node_Id;
Ident_Node : Node_Id;
Ccode : Char_Code;
E_Id : Entity_Id;
R_Node : Node_Id;
B_Node : Node_Id;
procedure Build_Exception (S : Standard_Entity_Type);
-- Procedure to declare given entity as an exception
procedure Create_Back_End_Float_Types;
-- Initialize the Back_End_Float_Types list by having the back end
-- enumerate all available types and building type entities for them.
procedure Create_Float_Types;
-- Creates entities for all predefined floating point types, and
-- adds these to the Predefined_Float_Types list in package Standard.
procedure Make_Dummy_Index (E : Entity_Id);
-- Called to provide a dummy index field value for Any_Array/Any_String
procedure Pack_String_Type (String_Type : Entity_Id);
-- Generate proper tree for pragma Pack that applies to given type, and
-- mark type as having the pragma.
---------------------
-- Build_Exception --
---------------------
procedure Build_Exception (S : Standard_Entity_Type) is
begin
Set_Ekind (Standard_Entity (S), E_Exception);
Set_Etype (Standard_Entity (S), Standard_Exception_Type);
Set_Is_Public (Standard_Entity (S), True);
Decl :=
Make_Exception_Declaration (Stloc,
Defining_Identifier => Standard_Entity (S));
Append (Decl, Decl_S);
end Build_Exception;
---------------------------------
-- Create_Back_End_Float_Types --
---------------------------------
procedure Create_Back_End_Float_Types is
begin
for J in 1 .. Num_FPT_Modes loop
declare
E : FPT_Mode_Entry renames FPT_Mode_Table (J);
begin
Register_Float_Type
(E.NAME.all, E.DIGS, E.FLOAT_REP, E.PRECISION, E.SIZE,
E.ALIGNMENT);
end;
end loop;
end Create_Back_End_Float_Types;
------------------------
-- Create_Float_Types --
------------------------
procedure Create_Float_Types is
begin
-- Create type definition nodes for predefined float types
Copy_Float_Type
(Standard_Short_Float,
Find_Back_End_Float_Type (C_Type_For (S_Short_Float)));
Set_Is_Implementation_Defined (Standard_Short_Float);
Copy_Float_Type (Standard_Float, Standard_Short_Float);
Copy_Float_Type
(Standard_Long_Float,
Find_Back_End_Float_Type (C_Type_For (S_Long_Float)));
Copy_Float_Type
(Standard_Long_Long_Float,
Find_Back_End_Float_Type (C_Type_For (S_Long_Long_Float)));
Set_Is_Implementation_Defined (Standard_Long_Long_Float);
Predefined_Float_Types := New_Elmt_List;
Append_Elmt (Standard_Short_Float, Predefined_Float_Types);
Append_Elmt (Standard_Float, Predefined_Float_Types);
Append_Elmt (Standard_Long_Float, Predefined_Float_Types);
Append_Elmt (Standard_Long_Long_Float, Predefined_Float_Types);
-- Any other back end types are appended at the end of the list of
-- predefined float types, and will only be selected if the none of
-- the types in Standard is suitable, or if a specific named type is
-- requested through a pragma Import.
while not Is_Empty_Elmt_List (Back_End_Float_Types) loop
declare
E : constant Elmt_Id := First_Elmt (Back_End_Float_Types);
begin
Append_Elmt (Node (E), To => Predefined_Float_Types);
Remove_Elmt (Back_End_Float_Types, E);
end;
end loop;
end Create_Float_Types;
----------------------
-- Make_Dummy_Index --
----------------------
procedure Make_Dummy_Index (E : Entity_Id) is
Index : constant Node_Id :=
Make_Range (Sloc (E),
Low_Bound => Make_Integer (Uint_0),
High_Bound => Make_Integer (Uint_2 ** Standard_Integer_Size));
-- Make sure Index is a list as required, so Next_Index is Empty
Dummy : constant List_Id := New_List (Index);
begin
Set_Etype (Index, Standard_Integer);
Set_First_Index (E, Index);
end Make_Dummy_Index;
----------------------
-- Pack_String_Type --
----------------------
procedure Pack_String_Type (String_Type : Entity_Id) is
Prag : constant Node_Id :=
Make_Pragma (Stloc,
Chars => Name_Pack,
Pragma_Argument_Associations =>
New_List (
Make_Pragma_Argument_Association (Stloc,
Expression => New_Occurrence_Of (String_Type, Stloc))));
begin
Append (Prag, Decl_S);
Record_Rep_Item (String_Type, Prag);
Set_Has_Pragma_Pack (String_Type, True);
end Pack_String_Type;
-- Start of processing for Create_Standard
begin
-- First step is to create defining identifiers for each entity
for S in Standard_Entity_Type loop
declare
S_Name : constant String := Standard_Entity_Type'Image (S);
-- Name of entity (note we skip S_ at the start)
Ident_Node : Node_Id;
-- Defining identifier node
begin
Ident_Node := New_Standard_Entity (S_Name (3 .. S_Name'Length));
Standard_Entity (S) := Ident_Node;
end;
end loop;
-- Create package declaration node for package Standard
Standard_Package_Node := New_Node (N_Package_Declaration, Stloc);
Pspec := New_Node (N_Package_Specification, Stloc);
Set_Specification (Standard_Package_Node, Pspec);
Set_Defining_Unit_Name (Pspec, Standard_Standard);
Set_Visible_Declarations (Pspec, Decl_S);
Set_Ekind (Standard_Standard, E_Package);
Set_Is_Pure (Standard_Standard);
Set_Is_Compilation_Unit (Standard_Standard);
-- Create type/subtype declaration nodes for standard types
for S in S_Types loop
-- Subtype declaration case
if S = S_Natural or else S = S_Positive then
Decl := New_Node (N_Subtype_Declaration, Stloc);
Set_Subtype_Indication (Decl,
New_Occurrence_Of (Standard_Integer, Stloc));
-- Full type declaration case
else
Decl := New_Node (N_Full_Type_Declaration, Stloc);
end if;
Set_Is_Frozen (Standard_Entity (S));
Set_Is_Public (Standard_Entity (S));
Set_Defining_Identifier (Decl, Standard_Entity (S));
Append (Decl, Decl_S);
end loop;
Create_Back_End_Float_Types;
-- Create type definition node for type Boolean. The Size is set to
-- 1 as required by Ada 95 and current ARG interpretations for Ada/83.
-- Note: Object_Size of Boolean is 8. This means that we do NOT in
-- general know that Boolean variables have valid values, so we do
-- not set the Is_Known_Valid flag.
Tdef_Node := New_Node (N_Enumeration_Type_Definition, Stloc);
Set_Literals (Tdef_Node, New_List);
Append (Standard_False, Literals (Tdef_Node));
Append (Standard_True, Literals (Tdef_Node));
Set_Type_Definition (Parent (Standard_Boolean), Tdef_Node);
Set_Ekind (Standard_Boolean, E_Enumeration_Type);
Set_First_Literal (Standard_Boolean, Standard_False);
Set_Etype (Standard_Boolean, Standard_Boolean);
Init_Esize (Standard_Boolean, Standard_Character_Size);
Init_RM_Size (Standard_Boolean, 1);
Set_Elem_Alignment (Standard_Boolean);
Set_Is_Unsigned_Type (Standard_Boolean);
Set_Size_Known_At_Compile_Time (Standard_Boolean);
Set_Has_Pragma_Ordered (Standard_Boolean);
Set_Ekind (Standard_True, E_Enumeration_Literal);
Set_Etype (Standard_True, Standard_Boolean);
Set_Enumeration_Pos (Standard_True, Uint_1);
Set_Enumeration_Rep (Standard_True, Uint_1);
Set_Is_Known_Valid (Standard_True, True);
Set_Ekind (Standard_False, E_Enumeration_Literal);
Set_Etype (Standard_False, Standard_Boolean);
Set_Enumeration_Pos (Standard_False, Uint_0);
Set_Enumeration_Rep (Standard_False, Uint_0);
Set_Is_Known_Valid (Standard_False, True);
-- For the bounds of Boolean, we create a range node corresponding to
-- range False .. True
-- where the occurrences of the literals must point to the
-- corresponding definition.
R_Node := New_Node (N_Range, Stloc);
B_Node := New_Node (N_Identifier, Stloc);
Set_Chars (B_Node, Chars (Standard_False));
Set_Entity (B_Node, Standard_False);
Set_Etype (B_Node, Standard_Boolean);
Set_Is_Static_Expression (B_Node);
Set_Low_Bound (R_Node, B_Node);
B_Node := New_Node (N_Identifier, Stloc);
Set_Chars (B_Node, Chars (Standard_True));
Set_Entity (B_Node, Standard_True);
Set_Etype (B_Node, Standard_Boolean);
Set_Is_Static_Expression (B_Node);
Set_High_Bound (R_Node, B_Node);
Set_Scalar_Range (Standard_Boolean, R_Node);
Set_Etype (R_Node, Standard_Boolean);
Set_Parent (R_Node, Standard_Boolean);
-- Record entity identifiers for boolean literals in the
-- Boolean_Literals array, for easy reference during expansion.
Boolean_Literals := (False => Standard_False, True => Standard_True);
-- Create type definition nodes for predefined integer types
Build_Signed_Integer_Type
(Standard_Short_Short_Integer, Standard_Short_Short_Integer_Size);
Set_Is_Implementation_Defined (Standard_Short_Short_Integer);
Build_Signed_Integer_Type
(Standard_Short_Integer, Standard_Short_Integer_Size);
Set_Is_Implementation_Defined (Standard_Short_Integer);
Build_Signed_Integer_Type
(Standard_Integer, Standard_Integer_Size);
Build_Signed_Integer_Type
(Standard_Long_Integer, Standard_Long_Integer_Size);
Build_Signed_Integer_Type
(Standard_Long_Long_Integer, Standard_Long_Long_Integer_Size);
Set_Is_Implementation_Defined (Standard_Long_Long_Integer);
Create_Unconstrained_Base_Type
(Standard_Short_Short_Integer, E_Signed_Integer_Subtype);
Create_Unconstrained_Base_Type
(Standard_Short_Integer, E_Signed_Integer_Subtype);
Create_Unconstrained_Base_Type
(Standard_Integer, E_Signed_Integer_Subtype);
Create_Unconstrained_Base_Type
(Standard_Long_Integer, E_Signed_Integer_Subtype);
Create_Unconstrained_Base_Type
(Standard_Long_Long_Integer, E_Signed_Integer_Subtype);
Create_Float_Types;
-- Create type definition node for type Character. Note that we do not
-- set the Literals field, since type Character is handled with special
-- routine that do not need a literal list.
Tdef_Node := New_Node (N_Enumeration_Type_Definition, Stloc);
Set_Type_Definition (Parent (Standard_Character), Tdef_Node);
Set_Ekind (Standard_Character, E_Enumeration_Type);
Set_Etype (Standard_Character, Standard_Character);
Init_Esize (Standard_Character, Standard_Character_Size);
Init_RM_Size (Standard_Character, 8);
Set_Elem_Alignment (Standard_Character);
Set_Has_Pragma_Ordered (Standard_Character);
Set_Is_Unsigned_Type (Standard_Character);
Set_Is_Character_Type (Standard_Character);
Set_Is_Known_Valid (Standard_Character);
Set_Size_Known_At_Compile_Time (Standard_Character);
-- Create the bounds for type Character
R_Node := New_Node (N_Range, Stloc);
-- Low bound for type Character (Standard.Nul)
B_Node := New_Node (N_Character_Literal, Stloc);
Set_Is_Static_Expression (B_Node);
Set_Chars (B_Node, No_Name);
Set_Char_Literal_Value (B_Node, Uint_0);
Set_Entity (B_Node, Empty);
Set_Etype (B_Node, Standard_Character);
Set_Low_Bound (R_Node, B_Node);
-- High bound for type Character
B_Node := New_Node (N_Character_Literal, Stloc);
Set_Is_Static_Expression (B_Node);
Set_Chars (B_Node, No_Name);
Set_Char_Literal_Value (B_Node, UI_From_Int (16#FF#));
Set_Entity (B_Node, Empty);
Set_Etype (B_Node, Standard_Character);
Set_High_Bound (R_Node, B_Node);
Set_Scalar_Range (Standard_Character, R_Node);
Set_Etype (R_Node, Standard_Character);
Set_Parent (R_Node, Standard_Character);
-- Create type definition for type Wide_Character. Note that we do not
-- set the Literals field, since type Wide_Character is handled with
-- special routines that do not need a literal list.
Tdef_Node := New_Node (N_Enumeration_Type_Definition, Stloc);
Set_Type_Definition (Parent (Standard_Wide_Character), Tdef_Node);
Set_Ekind (Standard_Wide_Character, E_Enumeration_Type);
Set_Etype (Standard_Wide_Character, Standard_Wide_Character);
Init_Size (Standard_Wide_Character, Standard_Wide_Character_Size);
Set_Elem_Alignment (Standard_Wide_Character);
Set_Has_Pragma_Ordered (Standard_Wide_Character);
Set_Is_Unsigned_Type (Standard_Wide_Character);
Set_Is_Character_Type (Standard_Wide_Character);
Set_Is_Known_Valid (Standard_Wide_Character);
Set_Size_Known_At_Compile_Time (Standard_Wide_Character);
-- Create the bounds for type Wide_Character
R_Node := New_Node (N_Range, Stloc);
-- Low bound for type Wide_Character
B_Node := New_Node (N_Character_Literal, Stloc);
Set_Is_Static_Expression (B_Node);
Set_Chars (B_Node, No_Name); -- ???
Set_Char_Literal_Value (B_Node, Uint_0);
Set_Entity (B_Node, Empty);
Set_Etype (B_Node, Standard_Wide_Character);
Set_Low_Bound (R_Node, B_Node);
-- High bound for type Wide_Character
B_Node := New_Node (N_Character_Literal, Stloc);
Set_Is_Static_Expression (B_Node);
Set_Chars (B_Node, No_Name); -- ???
Set_Char_Literal_Value (B_Node, UI_From_Int (16#FFFF#));
Set_Entity (B_Node, Empty);
Set_Etype (B_Node, Standard_Wide_Character);
Set_High_Bound (R_Node, B_Node);
Set_Scalar_Range (Standard_Wide_Character, R_Node);
Set_Etype (R_Node, Standard_Wide_Character);
Set_Parent (R_Node, Standard_Wide_Character);
-- Create type definition for type Wide_Wide_Character. Note that we
-- do not set the Literals field, since type Wide_Wide_Character is
-- handled with special routines that do not need a literal list.
Tdef_Node := New_Node (N_Enumeration_Type_Definition, Stloc);
Set_Type_Definition (Parent (Standard_Wide_Wide_Character), Tdef_Node);
Set_Ekind (Standard_Wide_Wide_Character, E_Enumeration_Type);
Set_Etype (Standard_Wide_Wide_Character,
Standard_Wide_Wide_Character);
Init_Size (Standard_Wide_Wide_Character,
Standard_Wide_Wide_Character_Size);
Set_Elem_Alignment (Standard_Wide_Wide_Character);
Set_Has_Pragma_Ordered (Standard_Wide_Wide_Character);
Set_Is_Unsigned_Type (Standard_Wide_Wide_Character);
Set_Is_Character_Type (Standard_Wide_Wide_Character);
Set_Is_Known_Valid (Standard_Wide_Wide_Character);
Set_Size_Known_At_Compile_Time (Standard_Wide_Wide_Character);
Set_Is_Ada_2005_Only (Standard_Wide_Wide_Character);
-- Create the bounds for type Wide_Wide_Character
R_Node := New_Node (N_Range, Stloc);
-- Low bound for type Wide_Wide_Character
B_Node := New_Node (N_Character_Literal, Stloc);
Set_Is_Static_Expression (B_Node);
Set_Chars (B_Node, No_Name); -- ???
Set_Char_Literal_Value (B_Node, Uint_0);
Set_Entity (B_Node, Empty);
Set_Etype (B_Node, Standard_Wide_Wide_Character);
Set_Low_Bound (R_Node, B_Node);
-- High bound for type Wide_Wide_Character
B_Node := New_Node (N_Character_Literal, Stloc);
Set_Is_Static_Expression (B_Node);
Set_Chars (B_Node, No_Name); -- ???
Set_Char_Literal_Value (B_Node, UI_From_Int (16#7FFF_FFFF#));
Set_Entity (B_Node, Empty);
Set_Etype (B_Node, Standard_Wide_Wide_Character);
Set_High_Bound (R_Node, B_Node);
Set_Scalar_Range (Standard_Wide_Wide_Character, R_Node);
Set_Etype (R_Node, Standard_Wide_Wide_Character);
Set_Parent (R_Node, Standard_Wide_Wide_Character);
-- Create type definition node for type String
Tdef_Node := New_Node (N_Unconstrained_Array_Definition, Stloc);
declare
CompDef_Node : Node_Id;
begin
CompDef_Node := New_Node (N_Component_Definition, Stloc);
Set_Aliased_Present (CompDef_Node, False);
Set_Access_Definition (CompDef_Node, Empty);
Set_Subtype_Indication (CompDef_Node, Identifier_For (S_Character));
Set_Component_Definition (Tdef_Node, CompDef_Node);
end;
Set_Subtype_Marks (Tdef_Node, New_List);
Append (Identifier_For (S_Positive), Subtype_Marks (Tdef_Node));
Set_Type_Definition (Parent (Standard_String), Tdef_Node);
Set_Ekind (Standard_String, E_Array_Type);
Set_Etype (Standard_String, Standard_String);
Set_Component_Type (Standard_String, Standard_Character);
Set_Component_Size (Standard_String, Uint_8);
Init_Size_Align (Standard_String);
Set_Alignment (Standard_String, Uint_1);
Pack_String_Type (Standard_String);
-- On targets where a storage unit is larger than a byte (such as AAMP),
-- pragma Pack has a real effect on the representation of type String,
-- and the type must be marked as having a nonstandard representation.
if System_Storage_Unit > Uint_8 then
Set_Has_Non_Standard_Rep (Standard_String);
Set_Has_Pragma_Pack (Standard_String);
end if;
-- Set index type of String
E_Id :=
First (Subtype_Marks (Type_Definition (Parent (Standard_String))));
Set_First_Index (Standard_String, E_Id);
Set_Entity (E_Id, Standard_Positive);
Set_Etype (E_Id, Standard_Positive);
-- Create type definition node for type Wide_String
Tdef_Node := New_Node (N_Unconstrained_Array_Definition, Stloc);
declare
CompDef_Node : Node_Id;
begin
CompDef_Node := New_Node (N_Component_Definition, Stloc);
Set_Aliased_Present (CompDef_Node, False);
Set_Access_Definition (CompDef_Node, Empty);
Set_Subtype_Indication (CompDef_Node,
Identifier_For (S_Wide_Character));
Set_Component_Definition (Tdef_Node, CompDef_Node);
end;
Set_Subtype_Marks (Tdef_Node, New_List);
Append (Identifier_For (S_Positive), Subtype_Marks (Tdef_Node));
Set_Type_Definition (Parent (Standard_Wide_String), Tdef_Node);
Set_Ekind (Standard_Wide_String, E_Array_Type);
Set_Etype (Standard_Wide_String, Standard_Wide_String);
Set_Component_Type (Standard_Wide_String, Standard_Wide_Character);
Set_Component_Size (Standard_Wide_String, Uint_16);
Init_Size_Align (Standard_Wide_String);
Pack_String_Type (Standard_Wide_String);
-- Set index type of Wide_String
E_Id :=
First
(Subtype_Marks (Type_Definition (Parent (Standard_Wide_String))));
Set_First_Index (Standard_Wide_String, E_Id);
Set_Entity (E_Id, Standard_Positive);
Set_Etype (E_Id, Standard_Positive);
-- Create type definition node for type Wide_Wide_String
Tdef_Node := New_Node (N_Unconstrained_Array_Definition, Stloc);
declare
CompDef_Node : Node_Id;
begin
CompDef_Node := New_Node (N_Component_Definition, Stloc);
Set_Aliased_Present (CompDef_Node, False);
Set_Access_Definition (CompDef_Node, Empty);
Set_Subtype_Indication (CompDef_Node,
Identifier_For (S_Wide_Wide_Character));
Set_Component_Definition (Tdef_Node, CompDef_Node);
end;
Set_Subtype_Marks (Tdef_Node, New_List);
Append (Identifier_For (S_Positive), Subtype_Marks (Tdef_Node));
Set_Type_Definition (Parent (Standard_Wide_Wide_String), Tdef_Node);
Set_Ekind (Standard_Wide_Wide_String, E_Array_Type);
Set_Etype (Standard_Wide_Wide_String,
Standard_Wide_Wide_String);
Set_Component_Type (Standard_Wide_Wide_String,
Standard_Wide_Wide_Character);
Set_Component_Size (Standard_Wide_Wide_String, Uint_32);
Init_Size_Align (Standard_Wide_Wide_String);
Set_Is_Ada_2005_Only (Standard_Wide_Wide_String);
Pack_String_Type (Standard_Wide_Wide_String);
-- Set index type of Wide_Wide_String
E_Id :=
First
(Subtype_Marks
(Type_Definition (Parent (Standard_Wide_Wide_String))));
Set_First_Index (Standard_Wide_Wide_String, E_Id);
Set_Entity (E_Id, Standard_Positive);
Set_Etype (E_Id, Standard_Positive);
-- Setup entity for Natural
Set_Ekind (Standard_Natural, E_Signed_Integer_Subtype);
Set_Etype (Standard_Natural, Base_Type (Standard_Integer));
Init_Esize (Standard_Natural, Standard_Integer_Size);
Init_RM_Size (Standard_Natural, Standard_Integer_Size - 1);
Set_Elem_Alignment (Standard_Natural);
Set_Size_Known_At_Compile_Time
(Standard_Natural);
Set_Integer_Bounds (Standard_Natural,
Typ => Base_Type (Standard_Integer),
Lb => Uint_0,
Hb => Intval (High_Bound (Scalar_Range (Standard_Integer))));
Set_Is_Constrained (Standard_Natural);
-- Setup entity for Positive
Set_Ekind (Standard_Positive, E_Signed_Integer_Subtype);
Set_Etype (Standard_Positive, Base_Type (Standard_Integer));
Init_Esize (Standard_Positive, Standard_Integer_Size);
Init_RM_Size (Standard_Positive, Standard_Integer_Size - 1);
Set_Elem_Alignment (Standard_Positive);
Set_Size_Known_At_Compile_Time (Standard_Positive);
Set_Integer_Bounds (Standard_Positive,
Typ => Base_Type (Standard_Integer),
Lb => Uint_1,
Hb => Intval (High_Bound (Scalar_Range (Standard_Integer))));
Set_Is_Constrained (Standard_Positive);
-- Create declaration for package ASCII
Decl := New_Node (N_Package_Declaration, Stloc);
Append (Decl, Decl_S);
Pspec := New_Node (N_Package_Specification, Stloc);
Set_Specification (Decl, Pspec);
Set_Defining_Unit_Name (Pspec, Standard_Entity (S_ASCII));
Set_Ekind (Standard_Entity (S_ASCII), E_Package);
Set_Visible_Declarations (Pspec, Decl_A);
-- Create control character definitions in package ASCII. Note that
-- the character literal entries created here correspond to literal
-- values that are impossible in the source, but can be represented
-- internally with no difficulties.
Ccode := 16#00#;
for S in S_ASCII_Names loop
Decl := New_Node (N_Object_Declaration, Staloc);
Set_Constant_Present (Decl, True);
declare
A_Char : constant Entity_Id := Standard_Entity (S);
Expr_Decl : Node_Id;
begin
Set_Sloc (A_Char, Staloc);
Set_Ekind (A_Char, E_Constant);
Set_Never_Set_In_Source (A_Char, True);
Set_Is_True_Constant (A_Char, True);
Set_Etype (A_Char, Standard_Character);
Set_Scope (A_Char, Standard_Entity (S_ASCII));
Set_Is_Immediately_Visible (A_Char, False);
Set_Is_Public (A_Char, True);
Set_Is_Known_Valid (A_Char, True);
Append_Entity (A_Char, Standard_Entity (S_ASCII));
Set_Defining_Identifier (Decl, A_Char);
Set_Object_Definition (Decl, Identifier_For (S_Character));
Expr_Decl := New_Node (N_Character_Literal, Staloc);
Set_Expression (Decl, Expr_Decl);
Set_Is_Static_Expression (Expr_Decl);
Set_Chars (Expr_Decl, No_Name);
Set_Etype (Expr_Decl, Standard_Character);
Set_Char_Literal_Value (Expr_Decl, UI_From_Int (Int (Ccode)));
end;
Append (Decl, Decl_A);
-- Increment character code, dealing with non-contiguities
Ccode := Ccode + 1;
if Ccode = 16#20# then
Ccode := 16#21#;
elsif Ccode = 16#27# then
Ccode := 16#3A#;
elsif Ccode = 16#3C# then
Ccode := 16#3F#;
elsif Ccode = 16#41# then
Ccode := 16#5B#;
end if;
end loop;
-- Create semantic phase entities
Standard_Void_Type := New_Standard_Entity ("_void_type");
Set_Ekind (Standard_Void_Type, E_Void);
Set_Etype (Standard_Void_Type, Standard_Void_Type);
Set_Scope (Standard_Void_Type, Standard_Standard);
-- The type field of packages is set to void
Set_Etype (Standard_Standard, Standard_Void_Type);
Set_Etype (Standard_ASCII, Standard_Void_Type);
-- Standard_A_String is actually used in generated code, so it has a
-- type name that is reasonable, but does not overlap any Ada name.
Standard_A_String := New_Standard_Entity ("access_string");
Set_Ekind (Standard_A_String, E_Access_Type);
Set_Scope (Standard_A_String, Standard_Standard);
Set_Etype (Standard_A_String, Standard_A_String);
if Debug_Flag_6 then
Init_Size (Standard_A_String, System_Address_Size);
else
Init_Size (Standard_A_String, System_Address_Size * 2);
end if;
Init_Alignment (Standard_A_String);
Set_Directly_Designated_Type
(Standard_A_String, Standard_String);
Standard_A_Char := New_Standard_Entity ("access_character");
Set_Ekind (Standard_A_Char, E_Access_Type);
Set_Scope (Standard_A_Char, Standard_Standard);
Set_Etype (Standard_A_Char, Standard_A_String);
Init_Size (Standard_A_Char, System_Address_Size);
Set_Elem_Alignment (Standard_A_Char);
Set_Directly_Designated_Type (Standard_A_Char, Standard_Character);
-- Standard_Debug_Renaming_Type is used for the special objects created
-- to encode the names occurring in renaming declarations for use by the
-- debugger (see exp_dbug.adb). The type is a zero-sized subtype of
-- Standard.Integer.
Standard_Debug_Renaming_Type := New_Standard_Entity ("_renaming_type");
Set_Ekind (Standard_Debug_Renaming_Type, E_Signed_Integer_Subtype);
Set_Scope (Standard_Debug_Renaming_Type, Standard_Standard);
Set_Etype (Standard_Debug_Renaming_Type, Base_Type (Standard_Integer));
Init_Esize (Standard_Debug_Renaming_Type, 0);
Init_RM_Size (Standard_Debug_Renaming_Type, 0);
Set_Size_Known_At_Compile_Time (Standard_Debug_Renaming_Type);
Set_Integer_Bounds (Standard_Debug_Renaming_Type,
Typ => Base_Type (Standard_Debug_Renaming_Type),
Lb => Uint_1,
Hb => Uint_0);
Set_Is_Constrained (Standard_Debug_Renaming_Type);
Set_Has_Size_Clause (Standard_Debug_Renaming_Type);
-- Note on type names. The type names for the following special types
-- are constructed so that they will look reasonable should they ever
-- appear in error messages etc, although in practice the use of the
-- special insertion character } for types results in special handling
-- of these type names in any case. The blanks in these names would
-- trouble in Gigi, but that's OK here, since none of these types
-- should ever get through to Gigi. Attributes of these types are
-- filled out to minimize problems with cascaded errors (for example,
-- Any_Integer is given reasonable and consistent type and size values)
Any_Type := New_Standard_Entity ("any type");
Decl := New_Node (N_Full_Type_Declaration, Stloc);
Set_Defining_Identifier (Decl, Any_Type);
Set_Scope (Any_Type, Standard_Standard);
Build_Signed_Integer_Type (Any_Type, Standard_Integer_Size);
Any_Id := New_Standard_Entity ("any id");
Set_Ekind (Any_Id, E_Variable);
Set_Scope (Any_Id, Standard_Standard);
Set_Etype (Any_Id, Any_Type);
Init_Esize (Any_Id);
Init_Alignment (Any_Id);
Any_Access := New_Standard_Entity ("an access type");
Set_Ekind (Any_Access, E_Access_Type);
Set_Scope (Any_Access, Standard_Standard);
Set_Etype (Any_Access, Any_Access);
Init_Size (Any_Access, System_Address_Size);
Set_Elem_Alignment (Any_Access);
Set_Directly_Designated_Type
(Any_Access, Any_Type);
Any_Character := New_Standard_Entity ("a character type");
Set_Ekind (Any_Character, E_Enumeration_Type);
Set_Scope (Any_Character, Standard_Standard);
Set_Etype (Any_Character, Any_Character);
Set_Is_Unsigned_Type (Any_Character);
Set_Is_Character_Type (Any_Character);
Init_Esize (Any_Character, Standard_Character_Size);
Init_RM_Size (Any_Character, 8);
Set_Elem_Alignment (Any_Character);
Set_Scalar_Range (Any_Character, Scalar_Range (Standard_Character));
Any_Array := New_Standard_Entity ("an array type");
Set_Ekind (Any_Array, E_Array_Type);
Set_Scope (Any_Array, Standard_Standard);
Set_Etype (Any_Array, Any_Array);
Set_Component_Type (Any_Array, Any_Character);
Init_Size_Align (Any_Array);
Make_Dummy_Index (Any_Array);
Any_Boolean := New_Standard_Entity ("a boolean type");
Set_Ekind (Any_Boolean, E_Enumeration_Type);
Set_Scope (Any_Boolean, Standard_Standard);
Set_Etype (Any_Boolean, Standard_Boolean);
Init_Esize (Any_Boolean, Standard_Character_Size);
Init_RM_Size (Any_Boolean, 1);
Set_Elem_Alignment (Any_Boolean);
Set_Is_Unsigned_Type (Any_Boolean);
Set_Scalar_Range (Any_Boolean, Scalar_Range (Standard_Boolean));
Any_Composite := New_Standard_Entity ("a composite type");
Set_Ekind (Any_Composite, E_Array_Type);
Set_Scope (Any_Composite, Standard_Standard);
Set_Etype (Any_Composite, Any_Composite);
Set_Component_Size (Any_Composite, Uint_0);
Set_Component_Type (Any_Composite, Standard_Integer);
Init_Size_Align (Any_Composite);
Any_Discrete := New_Standard_Entity ("a discrete type");
Set_Ekind (Any_Discrete, E_Signed_Integer_Type);
Set_Scope (Any_Discrete, Standard_Standard);
Set_Etype (Any_Discrete, Any_Discrete);
Init_Size (Any_Discrete, Standard_Integer_Size);
Set_Elem_Alignment (Any_Discrete);
Any_Fixed := New_Standard_Entity ("a fixed-point type");
Set_Ekind (Any_Fixed, E_Ordinary_Fixed_Point_Type);
Set_Scope (Any_Fixed, Standard_Standard);
Set_Etype (Any_Fixed, Any_Fixed);
Init_Size (Any_Fixed, Standard_Integer_Size);
Set_Elem_Alignment (Any_Fixed);
Any_Integer := New_Standard_Entity ("an integer type");
Set_Ekind (Any_Integer, E_Signed_Integer_Type);
Set_Scope (Any_Integer, Standard_Standard);
Set_Etype (Any_Integer, Standard_Long_Long_Integer);
Init_Size (Any_Integer, Standard_Long_Long_Integer_Size);
Set_Elem_Alignment (Any_Integer);
Set_Integer_Bounds
(Any_Integer,
Typ => Base_Type (Standard_Integer),
Lb => Uint_0,
Hb => Intval (High_Bound (Scalar_Range (Standard_Integer))));
Any_Modular := New_Standard_Entity ("a modular type");
Set_Ekind (Any_Modular, E_Modular_Integer_Type);
Set_Scope (Any_Modular, Standard_Standard);
Set_Etype (Any_Modular, Standard_Long_Long_Integer);
Init_Size (Any_Modular, Standard_Long_Long_Integer_Size);
Set_Elem_Alignment (Any_Modular);
Set_Is_Unsigned_Type (Any_Modular);
Any_Numeric := New_Standard_Entity ("a numeric type");
Set_Ekind (Any_Numeric, E_Signed_Integer_Type);
Set_Scope (Any_Numeric, Standard_Standard);
Set_Etype (Any_Numeric, Standard_Long_Long_Integer);
Init_Size (Any_Numeric, Standard_Long_Long_Integer_Size);
Set_Elem_Alignment (Any_Numeric);
Any_Real := New_Standard_Entity ("a real type");
Set_Ekind (Any_Real, E_Floating_Point_Type);
Set_Scope (Any_Real, Standard_Standard);
Set_Etype (Any_Real, Standard_Long_Long_Float);
Init_Size (Any_Real,
UI_To_Int (Esize (Standard_Long_Long_Float)));
Set_Elem_Alignment (Any_Real);
Any_Scalar := New_Standard_Entity ("a scalar type");
Set_Ekind (Any_Scalar, E_Signed_Integer_Type);
Set_Scope (Any_Scalar, Standard_Standard);
Set_Etype (Any_Scalar, Any_Scalar);
Init_Size (Any_Scalar, Standard_Integer_Size);
Set_Elem_Alignment (Any_Scalar);
Any_String := New_Standard_Entity ("a string type");
Set_Ekind (Any_String, E_Array_Type);
Set_Scope (Any_String, Standard_Standard);
Set_Etype (Any_String, Any_String);
Set_Component_Type (Any_String, Any_Character);
Init_Size_Align (Any_String);
Make_Dummy_Index (Any_String);
Raise_Type := New_Standard_Entity ("raise type");
Decl := New_Node (N_Full_Type_Declaration, Stloc);
Set_Defining_Identifier (Decl, Raise_Type);
Set_Scope (Raise_Type, Standard_Standard);
Build_Signed_Integer_Type (Raise_Type, Standard_Integer_Size);
Standard_Integer_8 := New_Standard_Entity ("integer_8");
Decl := New_Node (N_Full_Type_Declaration, Stloc);
Set_Defining_Identifier (Decl, Standard_Integer_8);
Set_Scope (Standard_Integer_8, Standard_Standard);
Build_Signed_Integer_Type (Standard_Integer_8, 8);
Standard_Integer_16 := New_Standard_Entity ("integer_16");
Decl := New_Node (N_Full_Type_Declaration, Stloc);
Set_Defining_Identifier (Decl, Standard_Integer_16);
Set_Scope (Standard_Integer_16, Standard_Standard);
Build_Signed_Integer_Type (Standard_Integer_16, 16);
Standard_Integer_32 := New_Standard_Entity ("integer_32");
Decl := New_Node (N_Full_Type_Declaration, Stloc);
Set_Defining_Identifier (Decl, Standard_Integer_32);
Set_Scope (Standard_Integer_32, Standard_Standard);
Build_Signed_Integer_Type (Standard_Integer_32, 32);
Standard_Integer_64 := New_Standard_Entity ("integer_64");
Decl := New_Node (N_Full_Type_Declaration, Stloc);
Set_Defining_Identifier (Decl, Standard_Integer_64);
Set_Scope (Standard_Integer_64, Standard_Standard);
Build_Signed_Integer_Type (Standard_Integer_64, 64);
-- Standard_*_Unsigned subtypes are not user visible, but they are
-- used internally. They are unsigned types with the same length as
-- the correspondingly named signed integer types.
Standard_Short_Short_Unsigned
:= New_Standard_Entity ("short_short_unsigned");
Build_Unsigned_Integer_Type
(Standard_Short_Short_Unsigned, Standard_Short_Short_Integer_Size);
Standard_Short_Unsigned := New_Standard_Entity ("short_unsigned");
Build_Unsigned_Integer_Type
(Standard_Short_Unsigned, Standard_Short_Integer_Size);
Standard_Unsigned := New_Standard_Entity ("unsigned");
Build_Unsigned_Integer_Type
(Standard_Unsigned, Standard_Integer_Size);
Standard_Long_Unsigned := New_Standard_Entity ("long_unsigned");
Build_Unsigned_Integer_Type
(Standard_Long_Unsigned, Standard_Long_Integer_Size);
Standard_Long_Long_Unsigned
:= New_Standard_Entity ("long_long_unsigned");
Build_Unsigned_Integer_Type
(Standard_Long_Long_Unsigned, Standard_Long_Long_Integer_Size);
-- Standard_Unsigned_64 is not user visible, but is used internally. It
-- is an unsigned type mod 2**64 with 64 bits size.
Standard_Unsigned_64 := New_Standard_Entity ("unsigned_64");
Build_Unsigned_Integer_Type (Standard_Unsigned_64, 64);
-- Standard_Address is not user visible, but is used internally. It is
-- an unsigned type mod 2**System_Address_Size with System.Address size.
Standard_Address := New_Standard_Entity ("standard_address");
Build_Unsigned_Integer_Type (Standard_Address, System_Address_Size);
-- Note: universal integer and universal real are constructed as fully
-- formed signed numeric types, with parameters corresponding to the
-- longest runtime types (Long_Long_Integer and Long_Long_Float). This
-- allows Gigi to properly process references to universal types that
-- are not folded at compile time.
Universal_Integer := New_Standard_Entity ("universal_integer");
Decl := New_Node (N_Full_Type_Declaration, Stloc);
Set_Defining_Identifier (Decl, Universal_Integer);
Set_Scope (Universal_Integer, Standard_Standard);
Build_Signed_Integer_Type
(Universal_Integer, Standard_Long_Long_Integer_Size);
Universal_Real := New_Standard_Entity ("universal_real");
Decl := New_Node (N_Full_Type_Declaration, Stloc);
Set_Defining_Identifier (Decl, Universal_Real);
Set_Scope (Universal_Real, Standard_Standard);
Copy_Float_Type (Universal_Real, Standard_Long_Long_Float);
-- Note: universal fixed, unlike universal integer and universal real,
-- is never used at runtime, so it does not need to have bounds set.
Universal_Fixed := New_Standard_Entity ("universal_fixed");
Decl := New_Node (N_Full_Type_Declaration, Stloc);
Set_Defining_Identifier (Decl, Universal_Fixed);
Set_Ekind (Universal_Fixed, E_Ordinary_Fixed_Point_Type);
Set_Etype (Universal_Fixed, Universal_Fixed);
Set_Scope (Universal_Fixed, Standard_Standard);
Init_Size (Universal_Fixed, Standard_Long_Long_Integer_Size);
Set_Elem_Alignment (Universal_Fixed);
Set_Size_Known_At_Compile_Time
(Universal_Fixed);
-- Create type declaration for Duration, using a 64-bit size. The
-- delta and size values depend on the mode set in system.ads.
Build_Duration : declare
Dlo : Uint;
Dhi : Uint;
Delta_Val : Ureal;
begin
-- In 32 bit mode, the size is 32 bits, and the delta and
-- small values are set to 20 milliseconds (20.0*(10.0**(-3)).
if Duration_32_Bits_On_Target then
Dlo := Intval (Type_Low_Bound (Standard_Integer_32));
Dhi := Intval (Type_High_Bound (Standard_Integer_32));
Delta_Val := UR_From_Components (UI_From_Int (20), Uint_3, 10);
-- In 64-bit mode, the size is 64-bits and the delta and
-- small values are set to nanoseconds (1.0*(10.0**(-9)).
else
Dlo := Intval (Type_Low_Bound (Standard_Integer_64));
Dhi := Intval (Type_High_Bound (Standard_Integer_64));
Delta_Val := UR_From_Components (Uint_1, Uint_9, 10);
end if;
Tdef_Node := Make_Ordinary_Fixed_Point_Definition (Stloc,
Delta_Expression => Make_Real_Literal (Stloc, Delta_Val),
Real_Range_Specification =>
Make_Real_Range_Specification (Stloc,
Low_Bound => Make_Real_Literal (Stloc,
Realval => Dlo * Delta_Val),
High_Bound => Make_Real_Literal (Stloc,
Realval => Dhi * Delta_Val)));
Set_Type_Definition (Parent (Standard_Duration), Tdef_Node);
Set_Ekind (Standard_Duration, E_Ordinary_Fixed_Point_Type);
Set_Etype (Standard_Duration, Standard_Duration);
if Duration_32_Bits_On_Target then
Init_Size (Standard_Duration, 32);
else
Init_Size (Standard_Duration, 64);
end if;
Set_Elem_Alignment (Standard_Duration);
Set_Delta_Value (Standard_Duration, Delta_Val);
Set_Small_Value (Standard_Duration, Delta_Val);
Set_Scalar_Range (Standard_Duration,
Real_Range_Specification
(Type_Definition (Parent (Standard_Duration))));
-- Normally it does not matter that nodes in package Standard are
-- not marked as analyzed. The Scalar_Range of the fixed-point type
-- Standard_Duration is an exception, because of the special test
-- made in Freeze.Freeze_Fixed_Point_Type.
Set_Analyzed (Scalar_Range (Standard_Duration));
Set_Etype (Type_High_Bound (Standard_Duration), Standard_Duration);
Set_Etype (Type_Low_Bound (Standard_Duration), Standard_Duration);
Set_Is_Static_Expression (Type_High_Bound (Standard_Duration));
Set_Is_Static_Expression (Type_Low_Bound (Standard_Duration));
Set_Corresponding_Integer_Value
(Type_High_Bound (Standard_Duration), Dhi);
Set_Corresponding_Integer_Value
(Type_Low_Bound (Standard_Duration), Dlo);
Set_Size_Known_At_Compile_Time (Standard_Duration);
end Build_Duration;
-- Build standard exception type. Note that the type name here is
-- actually used in the generated code, so it must be set correctly.
-- The type Standard_Exception_Type must be consistent with the type
-- System.Standard_Library.Exception_Data, as the latter is what is
-- known by the run-time. Components of the record are documented in
-- the declaration in System.Standard_Library.
Standard_Exception_Type := New_Standard_Entity ("exception");
Set_Ekind (Standard_Exception_Type, E_Record_Type);
Set_Etype (Standard_Exception_Type, Standard_Exception_Type);
Set_Scope (Standard_Exception_Type, Standard_Standard);
Set_Stored_Constraint
(Standard_Exception_Type, No_Elist);
Init_Size_Align (Standard_Exception_Type);
Set_Size_Known_At_Compile_Time
(Standard_Exception_Type, True);
Make_Component
(Standard_Exception_Type, Standard_Boolean, "Not_Handled_By_Others");
Make_Component
(Standard_Exception_Type, Standard_Character, "Lang");
Make_Component
(Standard_Exception_Type, Standard_Natural, "Name_Length");
Make_Component
(Standard_Exception_Type, Standard_A_Char, "Full_Name");
Make_Component
(Standard_Exception_Type, Standard_A_Char, "HTable_Ptr");
Make_Component
(Standard_Exception_Type, Standard_A_Char, "Foreign_Data");
Make_Component
(Standard_Exception_Type, Standard_A_Char, "Raise_Hook");
-- Build tree for record declaration, for use by the back-end
declare
Comp_List : List_Id;
Comp : Entity_Id;
begin
Comp := First_Entity (Standard_Exception_Type);
Comp_List := New_List;
while Present (Comp) loop
Append (
Make_Component_Declaration (Stloc,
Defining_Identifier => Comp,
Component_Definition =>
Make_Component_Definition (Stloc,
Aliased_Present => False,
Subtype_Indication => New_Occurrence_Of (Etype (Comp),
Stloc))),
Comp_List);
Next_Entity (Comp);
end loop;
Decl := Make_Full_Type_Declaration (Stloc,
Defining_Identifier => Standard_Exception_Type,
Type_Definition =>
Make_Record_Definition (Stloc,
End_Label => Empty,
Component_List =>
Make_Component_List (Stloc,
Component_Items => Comp_List)));
end;
Append (Decl, Decl_S);
Layout_Type (Standard_Exception_Type);
-- Create declarations of standard exceptions
Build_Exception (S_Constraint_Error);
Build_Exception (S_Program_Error);
Build_Exception (S_Storage_Error);
Build_Exception (S_Tasking_Error);
-- Numeric_Error is a normal exception in Ada 83, but in Ada 95
-- it is a renaming of Constraint_Error. This test is too early since
-- it doesn't handle pragma Ada_83. But it's not worth the trouble of
-- fixing this.
if Ada_Version = Ada_83 then
Build_Exception (S_Numeric_Error);
else
Decl := New_Node (N_Exception_Renaming_Declaration, Stloc);
E_Id := Standard_Entity (S_Numeric_Error);
Set_Ekind (E_Id, E_Exception);
Set_Etype (E_Id, Standard_Exception_Type);
Set_Is_Public (E_Id);
Set_Renamed_Entity (E_Id, Standard_Entity (S_Constraint_Error));
Set_Defining_Identifier (Decl, E_Id);
Append (Decl, Decl_S);
Ident_Node := New_Node (N_Identifier, Stloc);
Set_Chars (Ident_Node, Chars (Standard_Entity (S_Constraint_Error)));
Set_Entity (Ident_Node, Standard_Entity (S_Constraint_Error));
Set_Name (Decl, Ident_Node);
end if;
-- Abort_Signal is an entity that does not get made visible
Abort_Signal := New_Standard_Entity;
Set_Chars (Abort_Signal, Name_uAbort_Signal);
Set_Ekind (Abort_Signal, E_Exception);
Set_Etype (Abort_Signal, Standard_Exception_Type);
Set_Scope (Abort_Signal, Standard_Standard);
Set_Is_Public (Abort_Signal, True);
Decl :=
Make_Exception_Declaration (Stloc,
Defining_Identifier => Abort_Signal);
-- Create defining identifiers for shift operator entities. Note
-- that these entities are used only for marking shift operators
-- generated internally, and hence need no structure, just a name
-- and a unique identity.
Standard_Op_Rotate_Left := New_Standard_Entity;
Set_Chars (Standard_Op_Rotate_Left, Name_Rotate_Left);
Set_Ekind (Standard_Op_Rotate_Left, E_Operator);
Standard_Op_Rotate_Right := New_Standard_Entity;
Set_Chars (Standard_Op_Rotate_Right, Name_Rotate_Right);
Set_Ekind (Standard_Op_Rotate_Right, E_Operator);
Standard_Op_Shift_Left := New_Standard_Entity;
Set_Chars (Standard_Op_Shift_Left, Name_Shift_Left);
Set_Ekind (Standard_Op_Shift_Left, E_Operator);
Standard_Op_Shift_Right := New_Standard_Entity;
Set_Chars (Standard_Op_Shift_Right, Name_Shift_Right);
Set_Ekind (Standard_Op_Shift_Right, E_Operator);
Standard_Op_Shift_Right_Arithmetic := New_Standard_Entity;
Set_Chars (Standard_Op_Shift_Right_Arithmetic,
Name_Shift_Right_Arithmetic);
Set_Ekind (Standard_Op_Shift_Right_Arithmetic,
E_Operator);
-- Create standard operator declarations
Create_Operators;
-- Initialize visibility table with entities in Standard
for E in Standard_Entity_Type loop
if Ekind (Standard_Entity (E)) /= E_Operator then
Set_Name_Entity_Id
(Chars (Standard_Entity (E)), Standard_Entity (E));
Set_Homonym (Standard_Entity (E), Empty);
end if;
if E not in S_ASCII_Names then
Set_Scope (Standard_Entity (E), Standard_Standard);
Set_Is_Immediately_Visible (Standard_Entity (E));
end if;
end loop;
-- The predefined package Standard itself does not have a scope;
-- it is the only entity in the system not to have one, and this
-- is what identifies the package to Gigi.
Set_Scope (Standard_Standard, Empty);
-- Set global variables indicating last Id values and version
Last_Standard_Node_Id := Last_Node_Id;
Last_Standard_List_Id := Last_List_Id;
-- The Error node has an Etype of Any_Type to help error recovery
Set_Etype (Error, Any_Type);
-- Print representation of standard if switch set
if Opt.Print_Standard then
Print_Standard;
end if;
end Create_Standard;
------------------------------------
-- Create_Unconstrained_Base_Type --
------------------------------------
procedure Create_Unconstrained_Base_Type
(E : Entity_Id;
K : Entity_Kind)
is
New_Ent : constant Entity_Id := New_Copy (E);
begin
Set_Ekind (E, K);
Set_Is_Constrained (E, True);
Set_Is_First_Subtype (E, True);
Set_Etype (E, New_Ent);
Append_Entity (New_Ent, Standard_Standard);
Set_Is_Constrained (New_Ent, False);
Set_Etype (New_Ent, New_Ent);
Set_Is_Known_Valid (New_Ent, True);
if K = E_Signed_Integer_Subtype then
Set_Etype (Low_Bound (Scalar_Range (E)), New_Ent);
Set_Etype (High_Bound (Scalar_Range (E)), New_Ent);
end if;
end Create_Unconstrained_Base_Type;
--------------------
-- Identifier_For --
--------------------
function Identifier_For (S : Standard_Entity_Type) return Node_Id is
Ident_Node : constant Node_Id := New_Node (N_Identifier, Stloc);
begin
Set_Chars (Ident_Node, Chars (Standard_Entity (S)));
Set_Entity (Ident_Node, Standard_Entity (S));
return Ident_Node;
end Identifier_For;
--------------------
-- Make_Component --
--------------------
procedure Make_Component
(Rec : Entity_Id;
Typ : Entity_Id;
Nam : String)
is
Id : constant Entity_Id := New_Standard_Entity (Nam);
begin
Set_Ekind (Id, E_Component);
Set_Etype (Id, Typ);
Set_Scope (Id, Rec);
Init_Component_Location (Id);
Set_Original_Record_Component (Id, Id);
Append_Entity (Id, Rec);
end Make_Component;
-----------------
-- Make_Formal --
-----------------
function Make_Formal (Typ : Entity_Id; Nam : String) return Entity_Id is
Formal : constant Entity_Id := New_Standard_Entity (Nam);
begin
Set_Ekind (Formal, E_In_Parameter);
Set_Mechanism (Formal, Default_Mechanism);
Set_Scope (Formal, Standard_Standard);
Set_Etype (Formal, Typ);
return Formal;
end Make_Formal;
------------------
-- Make_Integer --
------------------
function Make_Integer (V : Uint) return Node_Id is
N : constant Node_Id := Make_Integer_Literal (Stloc, V);
begin
Set_Is_Static_Expression (N);
return N;
end Make_Integer;
------------------
-- New_Operator --
------------------
function New_Operator (Op : Name_Id; Typ : Entity_Id) return Entity_Id is
Ident_Node : constant Entity_Id := Make_Defining_Identifier (Stloc, Op);
begin
Set_Is_Pure (Ident_Node, True);
Set_Ekind (Ident_Node, E_Operator);
Set_Etype (Ident_Node, Typ);
Set_Scope (Ident_Node, Standard_Standard);
Set_Homonym (Ident_Node, Get_Name_Entity_Id (Op));
Set_Convention (Ident_Node, Convention_Intrinsic);
Set_Is_Immediately_Visible (Ident_Node, True);
Set_Is_Intrinsic_Subprogram (Ident_Node, True);
Set_Name_Entity_Id (Op, Ident_Node);
Append_Entity (Ident_Node, Standard_Standard);
return Ident_Node;
end New_Operator;
-------------------------
-- New_Standard_Entity --
-------------------------
function New_Standard_Entity
(New_Node_Kind : Node_Kind := N_Defining_Identifier) return Entity_Id
is
E : constant Entity_Id := New_Entity (New_Node_Kind, Stloc);
begin
-- All standard entities are Pure and Public
Set_Is_Pure (E);
Set_Is_Public (E);
-- All standard entity names are analyzed manually, and are thus
-- frozen as soon as they are created.
Set_Is_Frozen (E);
-- Set debug information required for all standard types
Set_Needs_Debug_Info (E);
-- All standard entities are built with fully qualified names, so
-- set the flag to prevent an abortive attempt at requalification.
Set_Has_Qualified_Name (E);
-- Return newly created entity to be completed by caller
return E;
end New_Standard_Entity;
function New_Standard_Entity (Nam : String) return Entity_Id is
Ent : constant Entity_Id := New_Standard_Entity;
begin
for J in 1 .. Nam'Length loop
Name_Buffer (J) := Fold_Lower (Nam (Nam'First + (J - 1)));
end loop;
Name_Len := Nam'Length;
Set_Chars (Ent, Name_Find);
return Ent;
end New_Standard_Entity;
--------------------
-- Print_Standard --
--------------------
procedure Print_Standard is
procedure P (Item : String) renames Output.Write_Line;
-- Short-hand, since we do a lot of line writes here
procedure P_Int_Range (Size : Pos);
-- Prints the range of an integer based on its Size
procedure P_Float_Range (Id : Entity_Id);
-- Prints the bounds range for the given float type entity
procedure P_Float_Type (Id : Entity_Id);
-- Prints the type declaration of the given float type entity
procedure P_Mixed_Name (Id : Name_Id);
-- Prints Id in mixed case
-------------------
-- P_Float_Range --
-------------------
procedure P_Float_Range (Id : Entity_Id) is
begin
Write_Str (" range ");
UR_Write (Realval (Type_Low_Bound (Id)));
Write_Str (" .. ");
UR_Write (Realval (Type_High_Bound (Id)));
Write_Str (";");
Write_Eol;
end P_Float_Range;
------------------
-- P_Float_Type --
------------------
procedure P_Float_Type (Id : Entity_Id) is
begin
Write_Str (" type ");
P_Mixed_Name (Chars (Id));
Write_Str (" is digits ");
Write_Int (UI_To_Int (Digits_Value (Id)));
Write_Eol;
P_Float_Range (Id);
Write_Str (" for ");
P_Mixed_Name (Chars (Id));
Write_Str ("'Size use ");
Write_Int (UI_To_Int (RM_Size (Id)));
Write_Line (";");
Write_Eol;
end P_Float_Type;
-----------------
-- P_Int_Range --
-----------------
procedure P_Int_Range (Size : Pos) is
begin
Write_Str (" is range -(2 **");
Write_Int (Size - 1);
Write_Str (")");
Write_Str (" .. +(2 **");
Write_Int (Size - 1);
Write_Str (" - 1);");
Write_Eol;
end P_Int_Range;
------------------
-- P_Mixed_Name --
------------------
procedure P_Mixed_Name (Id : Name_Id) is
begin
Get_Name_String (Id);
for J in 1 .. Name_Len loop
if J = 1 or else Name_Buffer (J - 1) = '_' then
Name_Buffer (J) := Fold_Upper (Name_Buffer (J));
end if;
end loop;
Write_Str (Name_Buffer (1 .. Name_Len));
end P_Mixed_Name;
-- Start of processing for Print_Standard
begin
P ("-- Representation of package Standard");
Write_Eol;
P ("-- This is not accurate Ada, since new base types cannot be ");
P ("-- created, but the listing shows the target dependent");
P ("-- characteristics of the Standard types for this compiler");
Write_Eol;
P ("package Standard is");
P ("pragma Pure (Standard);");
Write_Eol;
P (" type Boolean is (False, True);");
P (" for Boolean'Size use 1;");
P (" for Boolean use (False => 0, True => 1);");
Write_Eol;
-- Integer types
Write_Str (" type Integer");
P_Int_Range (Standard_Integer_Size);
Write_Str (" for Integer'Size use ");
Write_Int (Standard_Integer_Size);
P (";");
Write_Eol;
P (" subtype Natural is Integer range 0 .. Integer'Last;");
P (" subtype Positive is Integer range 1 .. Integer'Last;");
Write_Eol;
Write_Str (" type Short_Short_Integer");
P_Int_Range (Standard_Short_Short_Integer_Size);
Write_Str (" for Short_Short_Integer'Size use ");
Write_Int (Standard_Short_Short_Integer_Size);
P (";");
Write_Eol;
Write_Str (" type Short_Integer");
P_Int_Range (Standard_Short_Integer_Size);
Write_Str (" for Short_Integer'Size use ");
Write_Int (Standard_Short_Integer_Size);
P (";");
Write_Eol;
Write_Str (" type Long_Integer");
P_Int_Range (Standard_Long_Integer_Size);
Write_Str (" for Long_Integer'Size use ");
Write_Int (Standard_Long_Integer_Size);
P (";");
Write_Eol;
Write_Str (" type Long_Long_Integer");
P_Int_Range (Standard_Long_Long_Integer_Size);
Write_Str (" for Long_Long_Integer'Size use ");
Write_Int (Standard_Long_Long_Integer_Size);
P (";");
Write_Eol;
-- Floating point types
P_Float_Type (Standard_Short_Float);
P_Float_Type (Standard_Float);
P_Float_Type (Standard_Long_Float);
P_Float_Type (Standard_Long_Long_Float);
P (" type Character is (...)");
Write_Str (" for Character'Size use ");
Write_Int (Standard_Character_Size);
P (";");
P (" -- See RM A.1(35) for details of this type");
Write_Eol;
P (" type Wide_Character is (...)");
Write_Str (" for Wide_Character'Size use ");
Write_Int (Standard_Wide_Character_Size);
P (";");
P (" -- See RM A.1(36) for details of this type");
Write_Eol;
P (" type Wide_Wide_Character is (...)");
Write_Str (" for Wide_Wide_Character'Size use ");
Write_Int (Standard_Wide_Wide_Character_Size);
P (";");
P (" -- See RM A.1(36) for details of this type");
P (" type String is array (Positive range <>) of Character;");
P (" pragma Pack (String);");
Write_Eol;
P (" type Wide_String is array (Positive range <>)" &
" of Wide_Character;");
P (" pragma Pack (Wide_String);");
Write_Eol;
P (" type Wide_Wide_String is array (Positive range <>)" &
" of Wide_Wide_Character;");
P (" pragma Pack (Wide_Wide_String);");
Write_Eol;
-- We only have one representation each for 32-bit and 64-bit sizes,
-- so select the right one based on Duration_32_Bits_On_Target.
if Duration_32_Bits_On_Target then
P (" type Duration is delta 0.020");
P (" range -((2 ** 31) * 0.020) ..");
P (" +((2 ** 31 - 1) * 0.020);");
P (" for Duration'Small use 0.020;");
else
P (" type Duration is delta 0.000000001");
P (" range -((2 ** 63) * 0.000000001) ..");
P (" +((2 ** 63 - 1) * 0.000000001);");
P (" for Duration'Small use 0.000000001;");
end if;
Write_Eol;
P (" Constraint_Error : exception;");
P (" Program_Error : exception;");
P (" Storage_Error : exception;");
P (" Tasking_Error : exception;");
P (" Numeric_Error : exception renames Constraint_Error;");
Write_Eol;
P ("end Standard;");
end Print_Standard;
-------------------------
-- Register_Float_Type --
-------------------------
procedure Register_Float_Type
(Name : String;
Digs : Positive;
Float_Rep : Float_Rep_Kind;
Precision : Positive;
Size : Positive;
Alignment : Natural)
is
pragma Unreferenced (Precision);
-- See Build_Float_Type for the rationale
Ent : constant Entity_Id := New_Standard_Entity (Name);
begin
Set_Defining_Identifier (New_Node (N_Full_Type_Declaration, Stloc), Ent);
Set_Scope (Ent, Standard_Standard);
Build_Float_Type
(Ent, Pos (Digs), Float_Rep, Int (Size), Int (Alignment / 8));
if No (Back_End_Float_Types) then
Back_End_Float_Types := New_Elmt_List;
end if;
Append_Elmt (Ent, Back_End_Float_Types);
end Register_Float_Type;
----------------------
-- Set_Float_Bounds --
----------------------
procedure Set_Float_Bounds (Id : Entity_Id) is
L : Node_Id;
H : Node_Id;
-- Low and high bounds of literal value
R : Node_Id;
-- Range specification
Radix : constant Uint := Machine_Radix_Value (Id);
Mantissa : constant Uint := Machine_Mantissa_Value (Id);
Emax : constant Uint := Machine_Emax_Value (Id);
Significand : constant Uint := Radix ** Mantissa - 1;
Exponent : constant Uint := Emax - Mantissa;
begin
H := Make_Float_Literal (Stloc, Radix, Significand, Exponent);
L := Make_Float_Literal (Stloc, Radix, -Significand, Exponent);
Set_Etype (L, Id);
Set_Is_Static_Expression (L);
Set_Etype (H, Id);
Set_Is_Static_Expression (H);
R := New_Node (N_Range, Stloc);
Set_Low_Bound (R, L);
Set_High_Bound (R, H);
Set_Includes_Infinities (R, True);
Set_Scalar_Range (Id, R);
Set_Etype (R, Id);
Set_Parent (R, Id);
end Set_Float_Bounds;
------------------------
-- Set_Integer_Bounds --
------------------------
procedure Set_Integer_Bounds
(Id : Entity_Id;
Typ : Entity_Id;
Lb : Uint;
Hb : Uint)
is
L : Node_Id;
H : Node_Id;
-- Low and high bounds of literal value
R : Node_Id;
-- Range specification
begin
L := Make_Integer (Lb);
H := Make_Integer (Hb);
Set_Etype (L, Typ);
Set_Etype (H, Typ);
R := New_Node (N_Range, Stloc);
Set_Low_Bound (R, L);
Set_High_Bound (R, H);
Set_Scalar_Range (Id, R);
Set_Etype (R, Typ);
Set_Parent (R, Id);
Set_Is_Unsigned_Type (Id, Lb >= 0);
end Set_Integer_Bounds;
end CStand;
|
with Ada.Strings.Unbounded;
package body Test_Unit is
task type Boring_Task_Type is
entry Drop_Off_Work (Work_In : in Range_Type);
end Boring_Task_Type;
task body Boring_Task_Type is
Work : Range_Type := 5;
Result : Integer := 0;
Factor : constant Positive := 2;
begin
loop
accept Drop_Off_Work (Work_In : in Range_Type) do
Work := Work_In;
end Drop_Off_Work;
Result := Integer (Work) * Factor;
end loop;
end Boring_Task_Type;
Boring_Task : Boring_Task_Type;
procedure You_Do_It (Using : in Range_Type) is begin
if Using = 5 then
raise Dont_Like_5;
else
Boring_Task.Drop_Off_Work (Using);
end if;
end You_Do_It;
procedure Do_It (This : in Range_Type) is begin
You_Do_It (Using => This);
exception
when X : Dont_Like_5 =>
null;
end Do_It;
package body Parent_Class is
procedure Method_1 (This : in out Object) is begin
This.Component_1 := This.Component_1 * 2;
end Method_1;
end Parent_Class;
package body Child_Class is
procedure Method_1 (This : in out Object) is begin
This.Component_1 := This.Component_1 * 3;
This.Component_2 := This.Component_2 * 5;
end Method_1;
end Child_Class;
end Test_Unit;
|
package body gel.Mouse
is
--------------
--- Attributes
--
-- Nil.
---------------
--- Operations
--
procedure emit_button_press_Event (Self : in out Item'Class; Button : in mouse.button_Id;
Modifiers : in keyboard.modifier_Set;
Site : in mouse.Site)
is
begin
self.emit (button_press_Event' (Button, Modifiers, Site));
end emit_button_press_Event;
procedure emit_button_release_Event (Self : in out Item'Class; Button : in mouse.button_Id;
Modifiers : in keyboard.modifier_Set;
Site : in mouse.Site)
is
begin
self.emit (button_release_Event' (Button, Modifiers, Site));
end emit_button_release_Event;
procedure emit_motion_Event (Self : in out Item'Class; Site : in mouse.Site)
is
begin
self.emit (motion_Event' (site => Site));
end emit_motion_Event;
end gel.Mouse;
|
Ada.Numerics.e -- Euler's number
Ada.Numerics.pi -- pi
sqrt(x) -- square root
log(x, base) -- logarithm to any specified base
exp(x) -- exponential
abs(x) -- absolute value
S'floor(x) -- Produces the floor of an instance of subtype S
S'ceiling(x) -- Produces the ceiling of an instance of subtype S
x**y -- x raised to the y power
|
with System.Machine_Code;
with AVR.USART;
with AVR.TWI;
with AVR.TIMERS.CLOCK;
-- =============================================================================
-- Package body AVR.INTERRUPTS
-- =============================================================================
package body AVR.INTERRUPTS is
procedure Enable is
begin
System.Machine_Code.Asm ("sei", Volatile => True);
end Enable;
procedure Disable is
begin
System.Machine_Code.Asm ("cli", Volatile => True);
end Disable;
procedure Handle_Interrupt_USART0_RX is
begin
AVR.USART.Handle_ISR_RXC (AVR.USART.USART0);
end Handle_Interrupt_USART0_RX;
#if MCU="ATMEGA2560" then
procedure Handle_Interrupt_USART1_RX is
begin
AVR.USART.Handle_ISR_RXC (AVR.USART.USART1);
end Handle_Interrupt_USART1_RX;
procedure Handle_Interrupt_USART2_RX is
begin
AVR.USART.Handle_ISR_RXC (AVR.USART.USART2);
end Handle_Interrupt_USART2_RX;
procedure Handle_Interrupt_USART3_RX is
begin
AVR.USART.Handle_ISR_RXC (AVR.USART.USART3);
end Handle_Interrupt_USART3_RX;
#end if;
procedure Handle_Interrupt_TWI is
begin
AVR.TWI.Handle_Interrupts;
end Handle_Interrupt_TWI;
procedure Handle_Interrupt_TIMER4_OVF is
begin
AVR.TIMERS.CLOCK.Schedule_Update_Clock;
end Handle_Interrupt_TIMER4_OVF;
end AVR.INTERRUPTS;
|
------------------------------------------------------------------------------
-- --
-- GNAT RUN-TIME COMPONENTS --
-- --
-- A D A . T A G S --
-- --
-- B o d y --
-- --
-- Copyright (C) 1992-2006, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 2, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
-- for more details. You should have received a copy of the GNU General --
-- Public License distributed with GNAT; see file COPYING. If not, write --
-- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
-- Boston, MA 02110-1301, USA. --
-- --
-- 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. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
with Ada.Exceptions;
with System.HTable;
with System.Storage_Elements; use System.Storage_Elements;
with System.WCh_Con; use System.WCh_Con;
with System.WCh_StW; use System.WCh_StW;
pragma Elaborate_All (System.HTable);
package body Ada.Tags is
-- Structure of the GNAT Primary Dispatch Table
-- +----------------------+
-- | table of |
-- : predefined primitive :
-- | ops pointers |
-- +----------------------+
-- | Signature |
-- +----------------------+
-- | Tagged_Kind |
-- +----------------------+
-- | Offset_To_Top |
-- +----------------------+
-- | Typeinfo_Ptr/TSD_Ptr ---> Type Specific Data
-- Tag ---> +----------------------+ +-------------------+
-- | table of | | inheritance depth |
-- : primitive ops : +-------------------+
-- | pointers | | access level |
-- +----------------------+ +-------------------+
-- | expanded name |
-- +-------------------+
-- | external tag |
-- +-------------------+
-- | hash table link |
-- +-------------------+
-- | remotely callable |
-- +-------------------+
-- | rec ctrler offset |
-- +-------------------+
-- | num prim ops |
-- +-------------------+
-- | Ifaces_Table_Ptr --> Interface Data
-- +-------------------+ +------------+
-- Select Specific Data <---- SSD_Ptr | | table |
-- +--------------------+ +-------------------+ : of :
-- | table of primitive | | table of | | interfaces |
-- : operation : : ancestor : +------------+
-- | kinds | | tags |
-- +--------------------+ +-------------------+
-- | table of |
-- : entry :
-- | indices |
-- +--------------------+
-- Structure of the GNAT Secondary Dispatch Table
-- +-----------------------+
-- | table of |
-- : predefined primitive :
-- | ops pointers |
-- +-----------------------+
-- | Signature |
-- +-----------------------+
-- | Tagged_Kind |
-- +-----------------------+
-- | Offset_To_Top |
-- +-----------------------+
-- | OSD_Ptr |---> Object Specific Data
-- Tag ---> +-----------------------+ +---------------+
-- | table of | | num prim ops |
-- : primitive op : +---------------+
-- | thunk pointers | | table of |
-- +-----------------------+ + primitive |
-- | op offsets |
-- +---------------+
----------------------------------
-- GNAT Dispatch Table Prologue --
----------------------------------
-- GNAT's Dispatch Table prologue contains several fields which are hidden
-- in order to preserve compatibility with C++. These fields are accessed
-- by address calculations performed in the following manner:
-- Field : Field_Type :=
-- (To_Address (Tag) - Sum_Of_Preceding_Field_Sizes).all;
-- The bracketed subtraction shifts the pointer (Tag) from the table of
-- primitive operations (or thunks) to the field in question. Since the
-- result of the subtraction is an address, dereferencing it will obtain
-- the actual value of the field.
-- Guidelines for addition of new hidden fields
-- Define a Field_Type and Field_Type_Ptr (access to Field_Type) in
-- A-Tags.ads for the newly introduced field.
-- Defined the size of the new field as a constant Field_Name_Size
-- Introduce an Unchecked_Conversion from System.Address to
-- Field_Type_Ptr in A-Tags.ads.
-- Define the specifications of Get_<Field_Name> and Set_<Field_Name>
-- in a-tags.ads.
-- Update the GNAT Dispatch Table structure in a-tags.adb
-- Provide bodies to the Get_<Field_Name> and Set_<Field_Name> routines.
-- The profile of a Get_<Field_Name> routine should resemble:
-- function Get_<Field_Name> (T : Tag; ...) return Field_Type is
-- Field : constant System.Address :=
-- To_Address (T) - <Sum_Of_Previous_Field_Sizes>;
-- begin
-- pragma Assert (Check_Signature (T, <Applicable_DT>));
-- <Additional_Assertions>
-- return To_Field_Type_Ptr (Field).all;
-- end Get_<Field_Name>;
-- The profile of a Set_<Field_Name> routine should resemble:
-- procedure Set_<Field_Name> (T : Tag; ..., Value : Field_Type) is
-- Field : constant System.Address :=
-- To_Address (T) - <Sum_Of_Previous_Field_Sizes>;
-- begin
-- pragma Assert (Check_Signature (T, <Applicable_DT>));
-- <Additional_Assertions>
-- To_Field_Type_Ptr (Field).all := Value;
-- end Set_<Field_Name>;
-- NOTE: For each field in the prologue which precedes the newly added
-- one, find and update its respective Sum_Of_Previous_Field_Sizes by
-- subtractind Field_Name_Size from it. Falure to do so will clobber the
-- previous prologue field.
K_Typeinfo : constant SSE.Storage_Count := DT_Typeinfo_Ptr_Size;
K_Offset_To_Top : constant SSE.Storage_Count :=
K_Typeinfo + DT_Offset_To_Top_Size;
K_Tagged_Kind : constant SSE.Storage_Count :=
K_Offset_To_Top + DT_Tagged_Kind_Size;
K_Signature : constant SSE.Storage_Count :=
K_Tagged_Kind + DT_Signature_Size;
subtype Cstring is String (Positive);
type Cstring_Ptr is access all Cstring;
-- We suppress index checks because the declared size in the record below
-- is a dummy size of one (see below).
type Tag_Table is array (Natural range <>) of Tag;
pragma Suppress_Initialization (Tag_Table);
pragma Suppress (Index_Check, On => Tag_Table);
-- Declarations for the table of interfaces
type Interface_Data_Element is record
Iface_Tag : Tag;
Static_Offset_To_Top : Boolean;
Offset_To_Top_Value : System.Storage_Elements.Storage_Offset;
Offset_To_Top_Func : System.Address;
end record;
-- If some ancestor of the tagged type has discriminants the field
-- Static_Offset_To_Top is False and the field Offset_To_Top_Func
-- is used to store the address of the function generated by the
-- expander which provides this value; otherwise Static_Offset_To_Top
-- is True and such value is stored in the Offset_To_Top_Value field.
type Interfaces_Array is
array (Natural range <>) of Interface_Data_Element;
type Interface_Data (Nb_Ifaces : Positive) is record
Table : Interfaces_Array (1 .. Nb_Ifaces);
end record;
-- Object specific data types
type Object_Specific_Data_Array is array (Positive range <>) of Positive;
type Object_Specific_Data (Nb_Prim : Positive) is record
Num_Prim_Ops : Natural;
-- Number of primitive operations of the dispatch table. This field is
-- used by the run-time check routines that are activated when the
-- run-time is compiled with assertions enabled.
OSD_Table : Object_Specific_Data_Array (1 .. Nb_Prim);
-- Table used in secondary DT to reference their counterpart in the
-- select specific data (in the TSD of the primary DT). This construct
-- is used in the handling of dispatching triggers in select statements.
-- Nb_Prim is the number of non-predefined primitive operations.
end record;
-- Select specific data types
type Select_Specific_Data_Element is record
Index : Positive;
Kind : Prim_Op_Kind;
end record;
type Select_Specific_Data_Array is
array (Positive range <>) of Select_Specific_Data_Element;
type Select_Specific_Data (Nb_Prim : Positive) is record
SSD_Table : Select_Specific_Data_Array (1 .. Nb_Prim);
-- NOTE: Nb_Prim is the number of non-predefined primitive operations
end record;
-- Type specific data types
type Type_Specific_Data is record
Idepth : Natural;
-- Inheritance Depth Level: Used to implement the membership test
-- associated with single inheritance of tagged types in constant-time.
-- In addition it also indicates the size of the first table stored in
-- the Tags_Table component (see comment below).
Access_Level : Natural;
-- Accessibility level required to give support to Ada 2005 nested type
-- extensions. This feature allows safe nested type extensions by
-- shifting the accessibility checks to certain operations, rather than
-- being enforced at the type declaration. In particular, by performing
-- run-time accessibility checks on class-wide allocators, class-wide
-- function return, and class-wide stream I/O, the danger of objects
-- outliving their type declaration can be eliminated (Ada 2005: AI-344)
Expanded_Name : Cstring_Ptr;
External_Tag : Cstring_Ptr;
HT_Link : Tag;
-- Components used to give support to the Ada.Tags subprograms described
-- in ARM 3.9
Remotely_Callable : Boolean;
-- Used to check ARM E.4 (18)
RC_Offset : SSE.Storage_Offset;
-- Controller Offset: Used to give support to tagged controlled objects
-- (see Get_Deep_Controller at s-finimp)
Ifaces_Table_Ptr : System.Address;
-- Pointer to the table of interface tags. It is used to implement the
-- membership test associated with interfaces and also for backward
-- abstract interface type conversions (Ada 2005:AI-251)
Num_Prim_Ops : Natural;
-- Number of primitive operations of the dispatch table. This field is
-- used for additional run-time checks when the run-time is compiled
-- with assertions enabled.
SSD_Ptr : System.Address;
-- Pointer to a table of records used in dispatching selects. This
-- field has a meaningful value for all tagged types that implement
-- a limited, protected, synchronized or task interfaces and have
-- non-predefined primitive operations.
Tags_Table : Tag_Table (0 .. 1);
-- The size of the Tags_Table array actually depends on the tagged type
-- to which it applies. The compiler ensures that has enough space to
-- store all the entries of the two tables phisically stored there: the
-- "table of ancestor tags" and the "table of interface tags". For this
-- purpose we are using the same mechanism as for the Prims_Ptr array in
-- the Dispatch_Table record. See comments below on Prims_Ptr for
-- further details.
end record;
type Dispatch_Table is record
-- According to the C++ ABI the components Offset_To_Top and
-- Typeinfo_Ptr are stored just "before" the dispatch table (that is,
-- the Prims_Ptr table), and they are referenced with negative offsets
-- referring to the base of the dispatch table. The _Tag (or the
-- VTable_Ptr in C++ terminology) must point to the base of the virtual
-- table, just after these components, to point to the Prims_Ptr table.
-- For this purpose the expander generates a Prims_Ptr table that has
-- enough space for these additional components, and generates code that
-- displaces the _Tag to point after these components.
-- Signature : Signature_Kind;
-- Tagged_Kind : Tagged_Kind;
-- Offset_To_Top : Natural;
-- Typeinfo_Ptr : System.Address;
Prims_Ptr : Address_Array (1 .. 1);
-- The size of the Prims_Ptr array actually depends on the tagged type
-- to which it applies. For each tagged type, the expander computes the
-- actual array size, allocates the Dispatch_Table record accordingly,
-- and generates code that displaces the base of the record after the
-- Typeinfo_Ptr component. For this reason the first two components have
-- been commented in the previous declaration. The access to these
-- components is done by means of local functions.
--
-- To avoid the use of discriminants to define the actual size of the
-- dispatch table, we used to declare the tag as a pointer to a record
-- that contains an arbitrary array of addresses, using Positive as its
-- index. This ensures that there are never range checks when accessing
-- the dispatch table, but it prevents GDB from displaying tagged types
-- properly. A better approach is to declare this record type as holding
-- small number of addresses, and to explicitly suppress checks on it.
--
-- Note that in both cases, this type is never allocated, and serves
-- only to declare the corresponding access type.
end record;
type Signature_Type is
(Must_Be_Primary_DT,
Must_Be_Secondary_DT,
Must_Be_Primary_Or_Secondary_DT,
Must_Be_Interface,
Must_Be_Primary_Or_Interface);
-- Type of signature accepted by primitives in this package that are called
-- during the elaboration of tagged types. This type is used by the routine
-- Check_Signature that is called only when the run-time is compiled with
-- assertions enabled.
---------------------------------------------
-- Unchecked Conversions for String Fields --
---------------------------------------------
function To_Address is
new Unchecked_Conversion (Cstring_Ptr, System.Address);
function To_Cstring_Ptr is
new Unchecked_Conversion (System.Address, Cstring_Ptr);
------------------------------------------------
-- Unchecked Conversions for other components --
------------------------------------------------
type Acc_Size
is access function (A : System.Address) return Long_Long_Integer;
function To_Acc_Size is new Unchecked_Conversion (System.Address, Acc_Size);
-- The profile of the implicitly defined _size primitive
type Offset_To_Top_Function_Ptr is
access function (This : System.Address)
return System.Storage_Elements.Storage_Offset;
-- Type definition used to call the function that is generated by the
-- expander in case of tagged types with discriminants that have secondary
-- dispatch tables. This function provides the Offset_To_Top value in this
-- specific case.
function To_Offset_To_Top_Function_Ptr is
new Unchecked_Conversion (System.Address, Offset_To_Top_Function_Ptr);
type Storage_Offset_Ptr is access System.Storage_Elements.Storage_Offset;
function To_Storage_Offset_Ptr is
new Unchecked_Conversion (System.Address, Storage_Offset_Ptr);
-----------------------
-- Local Subprograms --
-----------------------
function Check_Signature (T : Tag; Kind : Signature_Type) return Boolean;
-- Check that the signature of T is valid and corresponds with the subset
-- specified by the signature Kind.
function Check_Size
(Old_T : Tag;
New_T : Tag;
Entry_Count : Natural) return Boolean;
-- Verify that Old_T and New_T have at least Entry_Count entries
function Get_Num_Prim_Ops (T : Tag) return Natural;
-- Retrieve the number of primitive operations in the dispatch table of T
function Is_Primary_DT (T : Tag) return Boolean;
pragma Inline_Always (Is_Primary_DT);
-- Given a tag returns True if it has the signature of a primary dispatch
-- table. This is Inline_Always since it is called from other Inline_
-- Always subprograms where we want no out of line code to be generated.
function Length (Str : Cstring_Ptr) return Natural;
-- Length of string represented by the given pointer (treating the string
-- as a C-style string, which is Nul terminated).
function Typeinfo_Ptr (T : Tag) return System.Address;
-- Returns the current value of the typeinfo_ptr component available in
-- the prologue of the dispatch table.
pragma Unreferenced (Typeinfo_Ptr);
-- These functions will be used for full compatibility with the C++ ABI
-------------------------
-- External_Tag_HTable --
-------------------------
type HTable_Headers is range 1 .. 64;
-- The following internal package defines the routines used for the
-- instantiation of a new System.HTable.Static_HTable (see below). See
-- spec in g-htable.ads for details of usage.
package HTable_Subprograms is
procedure Set_HT_Link (T : Tag; Next : Tag);
function Get_HT_Link (T : Tag) return Tag;
function Hash (F : System.Address) return HTable_Headers;
function Equal (A, B : System.Address) return Boolean;
end HTable_Subprograms;
package External_Tag_HTable is new System.HTable.Static_HTable (
Header_Num => HTable_Headers,
Element => Dispatch_Table,
Elmt_Ptr => Tag,
Null_Ptr => null,
Set_Next => HTable_Subprograms.Set_HT_Link,
Next => HTable_Subprograms.Get_HT_Link,
Key => System.Address,
Get_Key => Get_External_Tag,
Hash => HTable_Subprograms.Hash,
Equal => HTable_Subprograms.Equal);
------------------------
-- HTable_Subprograms --
------------------------
-- Bodies of routines for hash table instantiation
package body HTable_Subprograms is
-----------
-- Equal --
-----------
function Equal (A, B : System.Address) return Boolean is
Str1 : constant Cstring_Ptr := To_Cstring_Ptr (A);
Str2 : constant Cstring_Ptr := To_Cstring_Ptr (B);
J : Integer := 1;
begin
loop
if Str1 (J) /= Str2 (J) then
return False;
elsif Str1 (J) = ASCII.NUL then
return True;
else
J := J + 1;
end if;
end loop;
end Equal;
-----------------
-- Get_HT_Link --
-----------------
function Get_HT_Link (T : Tag) return Tag is
begin
return TSD (T).HT_Link;
end Get_HT_Link;
----------
-- Hash --
----------
function Hash (F : System.Address) return HTable_Headers is
function H is new System.HTable.Hash (HTable_Headers);
Str : constant Cstring_Ptr := To_Cstring_Ptr (F);
Res : constant HTable_Headers := H (Str (1 .. Length (Str)));
begin
return Res;
end Hash;
-----------------
-- Set_HT_Link --
-----------------
procedure Set_HT_Link (T : Tag; Next : Tag) is
begin
TSD (T).HT_Link := Next;
end Set_HT_Link;
end HTable_Subprograms;
---------------------
-- Check_Signature --
---------------------
function Check_Signature (T : Tag; Kind : Signature_Type) return Boolean is
Signature : constant Storage_Offset_Ptr :=
To_Storage_Offset_Ptr (To_Address (T) - K_Signature);
Sig_Values : constant Signature_Values :=
To_Signature_Values (Signature.all);
Signature_Id : Signature_Kind;
begin
if Sig_Values (1) /= Valid_Signature then
Signature_Id := Unknown;
elsif Sig_Values (2) in Primary_DT .. Abstract_Interface then
Signature_Id := Sig_Values (2);
else
Signature_Id := Unknown;
end if;
case Signature_Id is
when Primary_DT =>
if Kind = Must_Be_Secondary_DT
or else Kind = Must_Be_Interface
then
return False;
end if;
when Secondary_DT =>
if Kind = Must_Be_Primary_DT
or else Kind = Must_Be_Interface
then
return False;
end if;
when Abstract_Interface =>
if Kind = Must_Be_Primary_DT
or else Kind = Must_Be_Secondary_DT
or else Kind = Must_Be_Primary_Or_Secondary_DT
then
return False;
end if;
when others =>
return False;
end case;
return True;
end Check_Signature;
----------------
-- Check_Size --
----------------
function Check_Size
(Old_T : Tag;
New_T : Tag;
Entry_Count : Natural) return Boolean
is
Max_Entries_Old : constant Natural := Get_Num_Prim_Ops (Old_T);
Max_Entries_New : constant Natural := Get_Num_Prim_Ops (New_T);
begin
return Entry_Count <= Max_Entries_Old
and then Entry_Count <= Max_Entries_New;
end Check_Size;
-------------------
-- CW_Membership --
-------------------
-- Canonical implementation of Classwide Membership corresponding to:
-- Obj in Typ'Class
-- Each dispatch table contains a reference to a table of ancestors (stored
-- in the first part of the Tags_Table) and a count of the level of
-- inheritance "Idepth".
-- Obj is in Typ'Class if Typ'Tag is in the table of ancestors that are
-- contained in the dispatch table referenced by Obj'Tag . Knowing the
-- level of inheritance of both types, this can be computed in constant
-- time by the formula:
-- Obj'tag.TSD.Ancestor_Tags (Obj'tag.TSD.Idepth - Typ'tag.TSD.Idepth)
-- = Typ'tag
function CW_Membership (Obj_Tag : Tag; Typ_Tag : Tag) return Boolean is
Pos : Integer;
begin
pragma Assert (Check_Signature (Obj_Tag, Must_Be_Primary_DT));
pragma Assert (Check_Signature (Typ_Tag, Must_Be_Primary_DT));
Pos := TSD (Obj_Tag).Idepth - TSD (Typ_Tag).Idepth;
return Pos >= 0 and then TSD (Obj_Tag).Tags_Table (Pos) = Typ_Tag;
end CW_Membership;
--------------
-- Displace --
--------------
function Displace
(This : System.Address;
T : Tag) return System.Address
is
Curr_DT : constant Tag := To_Tag_Ptr (This).all;
Iface_Table : Interface_Data_Ptr;
Obj_Base : System.Address;
Obj_DT : Tag;
Obj_TSD : Type_Specific_Data_Ptr;
begin
pragma Assert
(Check_Signature (Curr_DT, Must_Be_Primary_Or_Secondary_DT));
pragma Assert
(Check_Signature (T, Must_Be_Interface));
Obj_Base := This - Offset_To_Top (This);
Obj_DT := To_Tag_Ptr (Obj_Base).all;
pragma Assert
(Check_Signature (Obj_DT, Must_Be_Primary_DT));
Obj_TSD := TSD (Obj_DT);
Iface_Table := To_Interface_Data_Ptr (Obj_TSD.Ifaces_Table_Ptr);
if Iface_Table /= null then
for Id in 1 .. Iface_Table.Nb_Ifaces loop
if Iface_Table.Table (Id).Iface_Tag = T then
-- Case of Static value of Offset_To_Top
if Iface_Table.Table (Id).Static_Offset_To_Top then
Obj_Base :=
Obj_Base + Iface_Table.Table (Id).Offset_To_Top_Value;
-- Otherwise we call the function generated by the expander
-- to provide us with this value
else
Obj_Base :=
Obj_Base +
To_Offset_To_Top_Function_Ptr
(Iface_Table.Table (Id).Offset_To_Top_Func).all
(Obj_Base);
end if;
Obj_DT := To_Tag_Ptr (Obj_Base).all;
pragma Assert
(Check_Signature (Obj_DT, Must_Be_Secondary_DT));
return Obj_Base;
end if;
end loop;
end if;
-- If the object does not implement the interface we must raise CE
raise Constraint_Error;
end Displace;
-------------------
-- IW_Membership --
-------------------
-- Canonical implementation of Classwide Membership corresponding to:
-- Obj in Iface'Class
-- Each dispatch table contains a table with the tags of all the
-- implemented interfaces.
-- Obj is in Iface'Class if Iface'Tag is found in the table of interfaces
-- that are contained in the dispatch table referenced by Obj'Tag.
function IW_Membership (This : System.Address; T : Tag) return Boolean is
Curr_DT : constant Tag := To_Tag_Ptr (This).all;
Iface_Table : Interface_Data_Ptr;
Last_Id : Natural;
Obj_Base : System.Address;
Obj_DT : Tag;
Obj_TSD : Type_Specific_Data_Ptr;
begin
pragma Assert
(Check_Signature (Curr_DT, Must_Be_Primary_Or_Secondary_DT));
pragma Assert
(Check_Signature (T, Must_Be_Primary_Or_Interface));
Obj_Base := This - Offset_To_Top (This);
Obj_DT := To_Tag_Ptr (Obj_Base).all;
pragma Assert
(Check_Signature (Obj_DT, Must_Be_Primary_DT));
Obj_TSD := TSD (Obj_DT);
Last_Id := Obj_TSD.Idepth;
-- Look for the tag in the table of interfaces
Iface_Table := To_Interface_Data_Ptr (Obj_TSD.Ifaces_Table_Ptr);
if Iface_Table /= null then
for Id in 1 .. Iface_Table.Nb_Ifaces loop
if Iface_Table.Table (Id).Iface_Tag = T then
return True;
end if;
end loop;
end if;
-- Look for the tag in the ancestor tags table. This is required for:
-- Iface_CW in Typ'Class
for Id in 0 .. Last_Id loop
if Obj_TSD.Tags_Table (Id) = T then
return True;
end if;
end loop;
return False;
end IW_Membership;
--------------------
-- Descendant_Tag --
--------------------
function Descendant_Tag (External : String; Ancestor : Tag) return Tag is
Int_Tag : Tag;
begin
pragma Assert (Check_Signature (Ancestor, Must_Be_Primary_DT));
Int_Tag := Internal_Tag (External);
pragma Assert (Check_Signature (Int_Tag, Must_Be_Primary_DT));
if not Is_Descendant_At_Same_Level (Int_Tag, Ancestor) then
raise Tag_Error;
end if;
return Int_Tag;
end Descendant_Tag;
-------------------
-- Expanded_Name --
-------------------
function Expanded_Name (T : Tag) return String is
Result : Cstring_Ptr;
begin
if T = No_Tag then
raise Tag_Error;
end if;
pragma Assert (Check_Signature (T, Must_Be_Primary_Or_Interface));
Result := TSD (T).Expanded_Name;
return Result (1 .. Length (Result));
end Expanded_Name;
------------------
-- External_Tag --
------------------
function External_Tag (T : Tag) return String is
Result : Cstring_Ptr;
begin
if T = No_Tag then
raise Tag_Error;
end if;
pragma Assert (Check_Signature (T, Must_Be_Primary_Or_Interface));
Result := TSD (T).External_Tag;
return Result (1 .. Length (Result));
end External_Tag;
----------------------
-- Get_Access_Level --
----------------------
function Get_Access_Level (T : Tag) return Natural is
begin
pragma Assert (Check_Signature (T, Must_Be_Primary_DT));
return TSD (T).Access_Level;
end Get_Access_Level;
---------------------
-- Get_Entry_Index --
---------------------
function Get_Entry_Index (T : Tag; Position : Positive) return Positive is
begin
pragma Assert (Check_Signature (T, Must_Be_Primary_DT));
pragma Assert (Position <= Get_Num_Prim_Ops (T));
return SSD (T).SSD_Table (Position).Index;
end Get_Entry_Index;
----------------------
-- Get_External_Tag --
----------------------
function Get_External_Tag (T : Tag) return System.Address is
begin
pragma Assert (Check_Signature (T, Must_Be_Primary_DT));
return To_Address (TSD (T).External_Tag);
end Get_External_Tag;
----------------------
-- Get_Num_Prim_Ops --
----------------------
function Get_Num_Prim_Ops (T : Tag) return Natural is
begin
pragma Assert (Check_Signature (T, Must_Be_Primary_Or_Secondary_DT));
if Is_Primary_DT (T) then
return TSD (T).Num_Prim_Ops;
else
return OSD (T).Num_Prim_Ops;
end if;
end Get_Num_Prim_Ops;
--------------------------------
-- Get_Predef_Prim_Op_Address --
--------------------------------
function Get_Predefined_Prim_Op_Address
(T : Tag;
Position : Positive) return System.Address
is
Prim_Ops_DT : constant Tag := To_Tag (To_Address (T) - DT_Prologue_Size);
begin
pragma Assert (Check_Signature (T, Must_Be_Primary_Or_Secondary_DT));
pragma Assert (Position <= Default_Prim_Op_Count);
return Prim_Ops_DT.Prims_Ptr (Position);
end Get_Predefined_Prim_Op_Address;
-------------------------
-- Get_Prim_Op_Address --
-------------------------
function Get_Prim_Op_Address
(T : Tag;
Position : Positive) return System.Address
is
begin
pragma Assert (Check_Signature (T, Must_Be_Primary_Or_Secondary_DT));
pragma Assert (Position <= Get_Num_Prim_Ops (T));
return T.Prims_Ptr (Position);
end Get_Prim_Op_Address;
----------------------
-- Get_Prim_Op_Kind --
----------------------
function Get_Prim_Op_Kind
(T : Tag;
Position : Positive) return Prim_Op_Kind
is
begin
pragma Assert (Check_Signature (T, Must_Be_Primary_DT));
pragma Assert (Position <= Get_Num_Prim_Ops (T));
return SSD (T).SSD_Table (Position).Kind;
end Get_Prim_Op_Kind;
----------------------
-- Get_Offset_Index --
----------------------
function Get_Offset_Index
(T : Tag;
Position : Positive) return Positive
is
begin
pragma Assert (Check_Signature (T, Must_Be_Secondary_DT));
pragma Assert (Position <= Get_Num_Prim_Ops (T));
return OSD (T).OSD_Table (Position);
end Get_Offset_Index;
-------------------
-- Get_RC_Offset --
-------------------
function Get_RC_Offset (T : Tag) return SSE.Storage_Offset is
begin
pragma Assert (Check_Signature (T, Must_Be_Primary_DT));
return TSD (T).RC_Offset;
end Get_RC_Offset;
---------------------------
-- Get_Remotely_Callable --
---------------------------
function Get_Remotely_Callable (T : Tag) return Boolean is
begin
pragma Assert (Check_Signature (T, Must_Be_Primary_DT));
return TSD (T).Remotely_Callable;
end Get_Remotely_Callable;
---------------------
-- Get_Tagged_Kind --
---------------------
function Get_Tagged_Kind (T : Tag) return Tagged_Kind is
Tagged_Kind_Ptr : constant System.Address :=
To_Address (T) - K_Tagged_Kind;
begin
pragma Assert (Check_Signature (T, Must_Be_Primary_Or_Secondary_DT));
return To_Tagged_Kind_Ptr (Tagged_Kind_Ptr).all;
end Get_Tagged_Kind;
----------------
-- Inherit_DT --
----------------
procedure Inherit_DT (Old_T : Tag; New_T : Tag; Entry_Count : Natural) is
Old_T_Prim_Ops : Tag;
New_T_Prim_Ops : Tag;
Size : Positive;
begin
pragma Assert (Check_Signature (Old_T, Must_Be_Primary_Or_Secondary_DT));
pragma Assert (Check_Signature (New_T, Must_Be_Primary_Or_Secondary_DT));
pragma Assert (Check_Size (Old_T, New_T, Entry_Count));
if Old_T /= null then
New_T.Prims_Ptr (1 .. Entry_Count) :=
Old_T.Prims_Ptr (1 .. Entry_Count);
Old_T_Prim_Ops := To_Tag (To_Address (Old_T) - DT_Prologue_Size);
New_T_Prim_Ops := To_Tag (To_Address (New_T) - DT_Prologue_Size);
Size := Default_Prim_Op_Count;
New_T_Prim_Ops.Prims_Ptr (1 .. Size) :=
Old_T_Prim_Ops.Prims_Ptr (1 .. Size);
end if;
end Inherit_DT;
-----------------
-- Inherit_TSD --
-----------------
procedure Inherit_TSD (Old_Tag : Tag; New_Tag : Tag) is
New_TSD_Ptr : Type_Specific_Data_Ptr;
New_Iface_Table_Ptr : Interface_Data_Ptr;
Old_TSD_Ptr : Type_Specific_Data_Ptr;
Old_Iface_Table_Ptr : Interface_Data_Ptr;
begin
pragma Assert (Check_Signature (New_Tag, Must_Be_Primary_Or_Interface));
New_TSD_Ptr := TSD (New_Tag);
if Old_Tag /= null then
pragma Assert
(Check_Signature (Old_Tag, Must_Be_Primary_Or_Interface));
Old_TSD_Ptr := TSD (Old_Tag);
New_TSD_Ptr.Idepth := Old_TSD_Ptr.Idepth + 1;
-- Copy the "table of ancestor tags" plus the "table of interfaces"
-- of the parent.
New_TSD_Ptr.Tags_Table (1 .. New_TSD_Ptr.Idepth) :=
Old_TSD_Ptr.Tags_Table (0 .. Old_TSD_Ptr.Idepth);
-- Copy the table of interfaces of the parent
if not System."=" (Old_TSD_Ptr.Ifaces_Table_Ptr,
System.Null_Address)
then
Old_Iface_Table_Ptr :=
To_Interface_Data_Ptr (Old_TSD_Ptr.Ifaces_Table_Ptr);
New_Iface_Table_Ptr :=
To_Interface_Data_Ptr (New_TSD_Ptr.Ifaces_Table_Ptr);
New_Iface_Table_Ptr.Table (1 .. Old_Iface_Table_Ptr.Nb_Ifaces) :=
Old_Iface_Table_Ptr.Table (1 .. Old_Iface_Table_Ptr.Nb_Ifaces);
end if;
else
New_TSD_Ptr.Idepth := 0;
end if;
New_TSD_Ptr.Tags_Table (0) := New_Tag;
end Inherit_TSD;
------------------
-- Internal_Tag --
------------------
function Internal_Tag (External : String) return Tag is
Ext_Copy : aliased String (External'First .. External'Last + 1);
Res : Tag;
begin
-- Make a copy of the string representing the external tag with
-- a null at the end.
Ext_Copy (External'Range) := External;
Ext_Copy (Ext_Copy'Last) := ASCII.NUL;
Res := External_Tag_HTable.Get (Ext_Copy'Address);
if Res = null then
declare
Msg1 : constant String := "unknown tagged type: ";
Msg2 : String (1 .. Msg1'Length + External'Length);
begin
Msg2 (1 .. Msg1'Length) := Msg1;
Msg2 (Msg1'Length + 1 .. Msg1'Length + External'Length) :=
External;
Ada.Exceptions.Raise_Exception (Tag_Error'Identity, Msg2);
end;
end if;
return Res;
end Internal_Tag;
---------------------------------
-- Is_Descendant_At_Same_Level --
---------------------------------
function Is_Descendant_At_Same_Level
(Descendant : Tag;
Ancestor : Tag) return Boolean
is
begin
return CW_Membership (Descendant, Ancestor)
and then TSD (Descendant).Access_Level = TSD (Ancestor).Access_Level;
end Is_Descendant_At_Same_Level;
-------------------
-- Is_Primary_DT --
-------------------
function Is_Primary_DT (T : Tag) return Boolean is
Signature : constant Storage_Offset_Ptr :=
To_Storage_Offset_Ptr (To_Address (T) - K_Signature);
Sig_Values : constant Signature_Values :=
To_Signature_Values (Signature.all);
begin
return Sig_Values (2) = Primary_DT;
end Is_Primary_DT;
------------
-- Length --
------------
function Length (Str : Cstring_Ptr) return Natural is
Len : Integer := 1;
begin
while Str (Len) /= ASCII.Nul loop
Len := Len + 1;
end loop;
return Len - 1;
end Length;
-------------------
-- Offset_To_Top --
-------------------
function Offset_To_Top
(This : System.Address) return System.Storage_Elements.Storage_Offset
is
Curr_DT : constant Tag := To_Tag_Ptr (This).all;
Offset_To_Top : Storage_Offset_Ptr;
begin
Offset_To_Top := To_Storage_Offset_Ptr
(To_Address (Curr_DT) - K_Offset_To_Top);
if Offset_To_Top.all = SSE.Storage_Offset'Last then
Offset_To_Top := To_Storage_Offset_Ptr (This + Tag_Size);
end if;
return Offset_To_Top.all;
end Offset_To_Top;
---------
-- OSD --
---------
function OSD (T : Tag) return Object_Specific_Data_Ptr is
OSD_Ptr : constant Addr_Ptr :=
To_Addr_Ptr (To_Address (T) - K_Typeinfo);
begin
pragma Assert (Check_Signature (T, Must_Be_Secondary_DT));
return To_Object_Specific_Data_Ptr (OSD_Ptr.all);
end OSD;
-----------------
-- Parent_Size --
-----------------
function Parent_Size
(Obj : System.Address;
T : Tag) return SSE.Storage_Count
is
Parent_Tag : Tag;
-- The tag of the parent type through the dispatch table
Prim_Ops_DT : Tag;
-- The table of primitive operations of the parent
F : Acc_Size;
-- Access to the _size primitive of the parent. We assume that it is
-- always in the first slot of the dispatch table.
begin
pragma Assert (Check_Signature (T, Must_Be_Primary_DT));
Parent_Tag := TSD (T).Tags_Table (1);
Prim_Ops_DT := To_Tag (To_Address (Parent_Tag) - DT_Prologue_Size);
F := To_Acc_Size (Prim_Ops_DT.Prims_Ptr (1));
-- Here we compute the size of the _parent field of the object
return SSE.Storage_Count (F.all (Obj));
end Parent_Size;
----------------
-- Parent_Tag --
----------------
function Parent_Tag (T : Tag) return Tag is
begin
if T = No_Tag then
raise Tag_Error;
end if;
pragma Assert (Check_Signature (T, Must_Be_Primary_DT));
-- The Parent_Tag of a root-level tagged type is defined to be No_Tag.
-- The first entry in the Ancestors_Tags array will be null for such
-- a type, but it's better to be explicit about returning No_Tag in
-- this case.
if TSD (T).Idepth = 0 then
return No_Tag;
else
return TSD (T).Tags_Table (1);
end if;
end Parent_Tag;
----------------------------
-- Register_Interface_Tag --
----------------------------
procedure Register_Interface_Tag
(T : Tag;
Interface_T : Tag;
Position : Positive)
is
New_T_TSD : Type_Specific_Data_Ptr;
Iface_Table : Interface_Data_Ptr;
begin
pragma Assert (Check_Signature (T, Must_Be_Primary_DT));
pragma Assert (Check_Signature (Interface_T, Must_Be_Interface));
New_T_TSD := TSD (T);
Iface_Table := To_Interface_Data_Ptr (New_T_TSD.Ifaces_Table_Ptr);
pragma Assert (Position <= Iface_Table.Nb_Ifaces);
Iface_Table.Table (Position).Iface_Tag := Interface_T;
end Register_Interface_Tag;
------------------
-- Register_Tag --
------------------
procedure Register_Tag (T : Tag) is
begin
External_Tag_HTable.Set (T);
end Register_Tag;
----------------------
-- Set_Access_Level --
----------------------
procedure Set_Access_Level (T : Tag; Value : Natural) is
begin
pragma Assert (Check_Signature (T, Must_Be_Primary_DT));
TSD (T).Access_Level := Value;
end Set_Access_Level;
---------------------
-- Set_Entry_Index --
---------------------
procedure Set_Entry_Index
(T : Tag;
Position : Positive;
Value : Positive)
is
begin
pragma Assert (Check_Signature (T, Must_Be_Primary_DT));
pragma Assert (Position <= Get_Num_Prim_Ops (T));
SSD (T).SSD_Table (Position).Index := Value;
end Set_Entry_Index;
-----------------------
-- Set_Expanded_Name --
-----------------------
procedure Set_Expanded_Name (T : Tag; Value : System.Address) is
begin
pragma Assert
(Check_Signature (T, Must_Be_Primary_Or_Interface));
TSD (T).Expanded_Name := To_Cstring_Ptr (Value);
end Set_Expanded_Name;
----------------------
-- Set_External_Tag --
----------------------
procedure Set_External_Tag (T : Tag; Value : System.Address) is
begin
pragma Assert (Check_Signature (T, Must_Be_Primary_Or_Interface));
TSD (T).External_Tag := To_Cstring_Ptr (Value);
end Set_External_Tag;
-------------------------
-- Set_Interface_Table --
-------------------------
procedure Set_Interface_Table (T : Tag; Value : System.Address) is
begin
pragma Assert (Check_Signature (T, Must_Be_Primary_DT));
TSD (T).Ifaces_Table_Ptr := Value;
end Set_Interface_Table;
----------------------
-- Set_Num_Prim_Ops --
----------------------
procedure Set_Num_Prim_Ops (T : Tag; Value : Natural) is
begin
pragma Assert (Check_Signature (T, Must_Be_Primary_Or_Secondary_DT));
if Is_Primary_DT (T) then
TSD (T).Num_Prim_Ops := Value;
else
OSD (T).Num_Prim_Ops := Value;
end if;
end Set_Num_Prim_Ops;
----------------------
-- Set_Offset_Index --
----------------------
procedure Set_Offset_Index
(T : Tag;
Position : Positive;
Value : Positive)
is
begin
pragma Assert (Check_Signature (T, Must_Be_Secondary_DT));
pragma Assert (Position <= Get_Num_Prim_Ops (T));
OSD (T).OSD_Table (Position) := Value;
end Set_Offset_Index;
-----------------------
-- Set_Offset_To_Top --
-----------------------
procedure Set_Offset_To_Top
(This : System.Address;
Interface_T : Tag;
Is_Static : Boolean;
Offset_Value : System.Storage_Elements.Storage_Offset;
Offset_Func : System.Address)
is
Prim_DT : Tag;
Sec_Base : System.Address;
Sec_DT : Tag;
Offset_To_Top : Storage_Offset_Ptr;
Iface_Table : Interface_Data_Ptr;
Obj_TSD : Type_Specific_Data_Ptr;
begin
if System."=" (This, System.Null_Address) then
pragma Assert
(Check_Signature (Interface_T, Must_Be_Primary_DT));
pragma Assert (Offset_Value = 0);
Offset_To_Top :=
To_Storage_Offset_Ptr (To_Address (Interface_T) - K_Offset_To_Top);
Offset_To_Top.all := Offset_Value;
return;
end if;
-- "This" points to the primary DT and we must save Offset_Value in the
-- Offset_To_Top field of the corresponding secondary dispatch table.
Prim_DT := To_Tag_Ptr (This).all;
pragma Assert
(Check_Signature (Prim_DT, Must_Be_Primary_DT));
Sec_Base := This + Offset_Value;
Sec_DT := To_Tag_Ptr (Sec_Base).all;
Offset_To_Top :=
To_Storage_Offset_Ptr (To_Address (Sec_DT) - K_Offset_To_Top);
pragma Assert
(Check_Signature (Sec_DT, Must_Be_Secondary_DT));
if Is_Static then
Offset_To_Top.all := Offset_Value;
else
Offset_To_Top.all := SSE.Storage_Offset'Last;
end if;
-- Save Offset_Value in the table of interfaces of the primary DT. This
-- data will be used by the subprogram "Displace" to give support to
-- backward abstract interface type conversions.
Obj_TSD := TSD (Prim_DT);
Iface_Table := To_Interface_Data_Ptr (Obj_TSD.Ifaces_Table_Ptr);
-- Register the offset in the table of interfaces
if Iface_Table /= null then
for Id in 1 .. Iface_Table.Nb_Ifaces loop
if Iface_Table.Table (Id).Iface_Tag = Interface_T then
Iface_Table.Table (Id).Static_Offset_To_Top := Is_Static;
if Is_Static then
Iface_Table.Table (Id).Offset_To_Top_Value := Offset_Value;
else
Iface_Table.Table (Id).Offset_To_Top_Func := Offset_Func;
end if;
return;
end if;
end loop;
end if;
-- If we arrive here there is some error in the run-time data structure
raise Program_Error;
end Set_Offset_To_Top;
-------------
-- Set_OSD --
-------------
procedure Set_OSD (T : Tag; Value : System.Address) is
OSD_Ptr : constant Addr_Ptr :=
To_Addr_Ptr (To_Address (T) - K_Typeinfo);
begin
pragma Assert (Check_Signature (T, Must_Be_Secondary_DT));
OSD_Ptr.all := Value;
end Set_OSD;
------------------------------------
-- Set_Predefined_Prim_Op_Address --
------------------------------------
procedure Set_Predefined_Prim_Op_Address
(T : Tag;
Position : Positive;
Value : System.Address)
is
Prim_Ops_DT : constant Tag := To_Tag (To_Address (T) - DT_Prologue_Size);
begin
pragma Assert (Check_Signature (T, Must_Be_Primary_Or_Secondary_DT));
pragma Assert (Position >= 1 and then Position <= Default_Prim_Op_Count);
Prim_Ops_DT.Prims_Ptr (Position) := Value;
end Set_Predefined_Prim_Op_Address;
-------------------------
-- Set_Prim_Op_Address --
-------------------------
procedure Set_Prim_Op_Address
(T : Tag;
Position : Positive;
Value : System.Address)
is
begin
pragma Assert (Check_Signature (T, Must_Be_Primary_Or_Secondary_DT));
pragma Assert (Position <= Get_Num_Prim_Ops (T));
T.Prims_Ptr (Position) := Value;
end Set_Prim_Op_Address;
----------------------
-- Set_Prim_Op_Kind --
----------------------
procedure Set_Prim_Op_Kind
(T : Tag;
Position : Positive;
Value : Prim_Op_Kind)
is
begin
pragma Assert (Check_Signature (T, Must_Be_Primary_DT));
pragma Assert (Position <= Get_Num_Prim_Ops (T));
SSD (T).SSD_Table (Position).Kind := Value;
end Set_Prim_Op_Kind;
-------------------
-- Set_RC_Offset --
-------------------
procedure Set_RC_Offset (T : Tag; Value : SSE.Storage_Offset) is
begin
pragma Assert (Check_Signature (T, Must_Be_Primary_DT));
TSD (T).RC_Offset := Value;
end Set_RC_Offset;
---------------------------
-- Set_Remotely_Callable --
---------------------------
procedure Set_Remotely_Callable (T : Tag; Value : Boolean) is
begin
pragma Assert (Check_Signature (T, Must_Be_Primary_DT));
TSD (T).Remotely_Callable := Value;
end Set_Remotely_Callable;
-------------------
-- Set_Signature --
-------------------
procedure Set_Signature (T : Tag; Value : Signature_Kind) is
Signature : constant System.Address := To_Address (T) - K_Signature;
Sig_Ptr : constant Signature_Values_Ptr :=
To_Signature_Values_Ptr (Signature);
begin
Sig_Ptr.all (1) := Valid_Signature;
Sig_Ptr.all (2) := Value;
end Set_Signature;
-------------
-- Set_SSD --
-------------
procedure Set_SSD (T : Tag; Value : System.Address) is
begin
pragma Assert (Check_Signature (T, Must_Be_Primary_DT));
TSD (T).SSD_Ptr := Value;
end Set_SSD;
---------------------
-- Set_Tagged_Kind --
---------------------
procedure Set_Tagged_Kind (T : Tag; Value : Tagged_Kind) is
Tagged_Kind_Ptr : constant System.Address :=
To_Address (T) - K_Tagged_Kind;
begin
pragma Assert (Check_Signature (T, Must_Be_Primary_Or_Secondary_DT));
To_Tagged_Kind_Ptr (Tagged_Kind_Ptr).all := Value;
end Set_Tagged_Kind;
-------------
-- Set_TSD --
-------------
procedure Set_TSD (T : Tag; Value : System.Address) is
TSD_Ptr : Addr_Ptr;
begin
pragma Assert (Check_Signature (T, Must_Be_Primary_Or_Interface));
TSD_Ptr := To_Addr_Ptr (To_Address (T) - K_Typeinfo);
TSD_Ptr.all := Value;
end Set_TSD;
---------
-- SSD --
---------
function SSD (T : Tag) return Select_Specific_Data_Ptr is
begin
pragma Assert (Check_Signature (T, Must_Be_Primary_DT));
return To_Select_Specific_Data_Ptr (TSD (T).SSD_Ptr);
end SSD;
------------------
-- Typeinfo_Ptr --
------------------
function Typeinfo_Ptr (T : Tag) return System.Address is
TSD_Ptr : constant Addr_Ptr :=
To_Addr_Ptr (To_Address (T) - K_Typeinfo);
begin
return TSD_Ptr.all;
end Typeinfo_Ptr;
---------
-- TSD --
---------
function TSD (T : Tag) return Type_Specific_Data_Ptr is
TSD_Ptr : constant Addr_Ptr :=
To_Addr_Ptr (To_Address (T) - K_Typeinfo);
begin
pragma Assert (Check_Signature (T, Must_Be_Primary_Or_Interface));
return To_Type_Specific_Data_Ptr (TSD_Ptr.all);
end TSD;
------------------------
-- Wide_Expanded_Name --
------------------------
WC_Encoding : Character;
pragma Import (C, WC_Encoding, "__gl_wc_encoding");
-- Encoding method for source, as exported by binder
function Wide_Expanded_Name (T : Tag) return Wide_String is
begin
return String_To_Wide_String
(Expanded_Name (T), Get_WC_Encoding_Method (WC_Encoding));
end Wide_Expanded_Name;
-----------------------------
-- Wide_Wide_Expanded_Name --
-----------------------------
function Wide_Wide_Expanded_Name (T : Tag) return Wide_Wide_String is
begin
return String_To_Wide_Wide_String
(Expanded_Name (T), Get_WC_Encoding_Method (WC_Encoding));
end Wide_Wide_Expanded_Name;
end Ada.Tags;
|
with Ada.Integer_Text_IO; Use Ada.Integer_Text_IO;
with Ada.Text_IO; Use Ada.Text_IO;
with inventory_list; Use inventory_list;
with player; Use player;
with save_load_game; Use save_load_game;
with stats; Use stats;
Procedure player_test is
response : Integer := -1;
response2 : Integer := -1;
response3 : character;
dungeon: Integer := 1;
bob : player_type;
--usedItem : inventoryItem;
begin
clearCharacter(bob);
insert(1, bob.backpack);
insert(2, bob.backpack);
insert(3, bob.backpack);
insert(4, bob.backpack);
insert(5, bob.backpack);
insert(6, bob.backpack);
insert(7, bob.backpack);
insert(8, bob.backpack);
insert(9, bob.backpack);
insert(10, bob.backpack);
insert(11, bob.backpack);
insert(12, bob.backpack);
insert(13, bob.backpack);
insert(14, bob.backpack);
insert(15, bob.backpack);
insert(16, bob.backpack);
insert(17, bob.backpack);
insert(18, bob.backpack);
insert(19, bob.backpack);
insert(20, bob.backpack);
insert(21, bob.backpack);
insert(22, bob.backpack);
insert(23, bob.backpack);
insert(24, bob.backpack);
insert(25, bob.backpack);
insert(26, bob.backpack);
insert(27, bob.backpack);
insert(28, bob.backpack);
insert(29, bob.backpack);
insert(30, bob.backpack);
loop
exit when response = 0;
put(ASCII.ESC & "[2J");
put("***Player*** ");
new_line;
put("Attack: ");
put(bob.stats.attack);
new_line;
put("Defense: ");
put(bob.stats.defense);
new_line;
put("Magic: ");
put(bob.stats.Magic);
put("/");
put(bob.stats.MaxMag, 0);
new_line;
put("Agility: ");
put(bob.stats.agility);
new_line;
put("Level: ");
put(bob.stats.level);
new_line;
put("HP: ");
put(bob.stats.HP);
put("/");
put(bob.stats.MaxHP, 0);
new_line;
put("XP: ");
put(bob.stats.xp);
new_line(2);
put("*Equipment* ");
new_line;
put("Weapon: ");
put(bob.Weapon.name);
new_line;
put("Helmet: ");
put(bob.helmet.name);
new_line;
put("Chest Armor: ");
put(bob.chestArmor.name);
new_line;
put("Gauntlets: ");
put(bob.gauntlets.name);
new_line;
put("Leg Armor: ");
put(bob.legArmor.name);
new_line;
put("Boots: ");
put(bob.boots.name);
new_line(2);
put("*Inventory*");
new_line;
DisplayList(bob.backpack);
new_line;
put("Use/Equip item: 1 Unequip item: 2");
new_line;
put("Hurt Player: 3 Decrement Magic: 4");
new_line;
put("Add XP: 5 Clear Character: 6");
new_line;
put("Save Game: 7 Load Game: 8");
new_line;
put("Quit: 0");
new_line;
get(response);
if response = 1 then
put("Type in the item ID that you are using/equipping: ");
get(response2);
equipOrUse(response2, bob);
response2 := -1;
elsif response = 2 then
put("Type in the item type that you are unequipping. ");
new_line;
put("1: Weapon, 2: Helmet, 3: Chest Armor ");
new_line;
put("4: Gauntlets 5: Leg Armor 6: Boots ");
new_line;
get(response2);
unequip(response2, bob);
response2 := -1;
elsif response = 3 then
put("Type in the amount of damage you want to inflict: ");
get(response2);
calculateDamage(bob.stats, bob.stats, response2, true);
response2 := -1;
elsif response = 4 then
put("Type in the amount of magic you want to use: ");
get(response2);
decMagic(response2, bob);
response2 := -1;
elsif response = 5 then
put("Type in the earned XP: ");
get(response2);
addXP(response2, bob.stats);
response2 := -1;
elsif response = 6 then
put("New Character? (Y/N): ");
get(response3);
if response3 = 'Y' OR response3 = 'y' then
clearCharacter(bob);
end if;
response3 := '0';
elsif response = 7 then
put("Dungeon 1, 2, or 3? ");
get(dungeon);
loop
put("Save File 1, 2, or 3? ");
get(response2);
exit when response2 = 1 OR response2 = 2 OR response2 = 3;
end loop;
saveGame(bob, dungeon, response2);
response2 := -1;
elsif response = 8 then
loop
put("Save File 1, 2, or 3? ");
get(response2);
exit when response2 = 1 OR response2 = 2 OR response2 = 3;
end loop;
loadGame(bob, dungeon, response2);
response2 := -1;
end if;
end loop;
end player_test;
|
with Text_IO; use Text_IO;
procedure Tritest is
Passed : Boolean := True;
type Triangle is (Equilateral, Isosceles, Scalene, Not_A_Triangle);
function Tritype(Len1, Len2, Len3 : in Integer) return Triangle
is separate;
procedure Compare(A, B, C: in Integer; Right_Answer : in Triangle)
is separate;
begin
Compare( 3, 4, 5, Scalene);
Compare( 6, 3, 4, Scalene);
Compare( 4, 3, 6, Scalene);
Compare( 3, 3, 3, Equilateral);
Compare( 3, 3, 4, Isosceles);
Compare( 3, 4, 3, Isosceles);
Compare( 4, 3, 3, Isosceles);
Compare( 7, 7, 4, Isosceles);
Compare( 7, 4, 7, Isosceles);
Compare( 4, 7, 7, Isosceles);
Compare( 1, 1, 1, Equilateral);
Compare( 0, 4, 4, Not_A_Triangle);
Compare( 4, 0, 4, Not_A_Triangle);
Compare( 4, 4, 0, Not_A_Triangle);
Compare( 0, 4, 3, Not_A_Triangle);
Compare( 3, 0, 4, Not_A_Triangle);
Compare( 4, 3, 0, Not_A_Triangle);
Compare(-1, 4, 4, Not_A_Triangle);
Compare( 4, -1, 4, Not_A_Triangle);
Compare( 4, 4, -1, Not_A_Triangle);
Compare(-1, 4, 3, Not_A_Triangle);
Compare( 3, -1, 4, Not_A_Triangle);
Compare( 4, 3, -1, Not_A_Triangle);
Compare( 2, 4, 6, Not_A_Triangle);
Compare( 1, 3, 2, Not_A_Triangle);
Compare( 3, 1, 2, Not_A_Triangle);
Compare( 1, 2, 4, Not_A_Triangle);
Compare( 1, 4, 2, Not_A_Triangle);
Compare( 4, 1, 2, Not_A_Triangle);
Compare( 0, 0, 0, Not_A_Triangle);
Compare( 0, 0, 4, Not_A_Triangle);
Compare( 0, 4, 0, Not_A_Triangle);
Compare( 4, 0, 0, Not_A_Triangle);
Compare( 3, 3, 7, Not_A_Triangle);
Compare( 3, 7, 3, Not_A_Triangle);
Compare( 6, 3, 3, Not_A_Triangle);
Compare(-3, -4, -5, Not_A_Triangle);
if Passed then
Put_Line("Congratulations, you completed the assignment!");
end if;
end Tritest;
separate (Tritest)
procedure Compare(A, B, C: in Integer; Right_Answer : in Triangle) is
package Int_IO is new Integer_IO(Integer); use Int_IO;
package Tri_IO is new Enumeration_IO(Triangle); use Tri_IO;
My_Answer : Triangle := Tritype(A, B, C);
begin
if My_Answer /= Right_Answer then
Put("Sides:");
Put(A, Width => 3);
Put(B, Width => 3);
Put(C, Width => 3);
Put(" My answer: ");
Put(My_Answer, Width => 14);
Put(" Right answer: ");
Put(Right_Answer);
New_Line;
Passed := False;
end if;
end Compare;
|
--------------------------------------------------------------------------------
-- --
-- Copyright (C) 2004, RISC OS Ada Library (RASCAL) developers. --
-- --
-- This library is free software; you can redistribute it and/or --
-- modify it under the terms of the GNU Lesser General Public --
-- License as published by the Free Software Foundation; either --
-- version 2.1 of the License, or (at your option) any later version. --
-- --
-- This library is distributed in the hope that it will be useful, --
-- but WITHOUT ANY WARRANTY; without even the implied warranty of --
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU --
-- Lesser General Public License for more details. --
-- --
-- You should have received a copy of the GNU Lesser General Public --
-- License along with this library; if not, write to the Free Software --
-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA --
-- --
--------------------------------------------------------------------------------
-- $Author$
-- $Date$
-- $Revision$
with Kernel; use Kernel;
with Interfaces.C; use Interfaces.C;
with System.Storage_Elements; use System.Storage_Elements;
with Ada.Strings.Fixed; use Ada.Strings.Fixed;
with Reporter;
with RASCAL.Memory; use RASCAL.Memory;
with RASCAL.Utility; use RASCAL.Utility;
with RASCAL.OS; use RASCAL.OS;
with RASCAL.FileName;
package body RASCAL.FileExternal is
OS_File : constant := 16#08#;
OS_FSControl : constant := 16#29#;
OS_GBPB : constant := 16#0C#;
OS_Find : constant := 16#0D#;
OS_Args : constant := 16#09#;
--
procedure Close_AllInPath (path : in String)is
buffer : String(1..1024);
register : aliased Kernel.swi_regs;
carry : aliased int;
handle : int := 255;
index : integer := 0;
str : unbounded_string;
Error : oserror_access;
begin
while handle >= 0 loop
Register.r(0) := 7;
Register.r(1) := handle;
Register.r(2) := int(To_Integer(buffer'Address));
Register.r(5) := 1024;
Error := Kernel.swi_c (OS_Args,register'Access,register'Access,carry'access);
if carry /= 0 then
str := U(Memory.MemoryToString(buffer'Address));
index := Ada.Strings.Fixed.
index(S(str),path);
if index > 0 then
register.r(0) := 0;
register.r(1) := handle;
Error := Kernel.SWI (OS_Find,register'Access,register'Access);
end if;
end if;
handle := handle - 1;
end loop ;
end Close_AllInPath;
--
function Get_UnUsedFileName (Path : in String) return String is
dummynr : Positive := 1;
dummypath : Unbounded_String;
begin
dummypath := U(Path & "." & intstr(dummynr));
while Exists(S(dummypath)) loop
dummynr := dummynr + 1;
dummypath := U(Path & "." & intstr(dummynr));
end loop;
return intstr(dummynr);
end Get_UnUsedFileName;
--
function Exists (Filename : in string) return boolean is
Filename_0 : string := Filename & ASCII.NUL;
Error : OSError_Access;
Register : aliased Kernel.SWI_Regs;
begin
Register.R(0) := 23;
Register.R(1) := int(To_Integer(Filename_0'Address));
Error := Kernel.swi(OS_File,Register'Access,Register'Access);
if Error /= null then
return false;
end if;
if Register.R(0) = 0 then
return false;
else
return true;
end if;
end Exists;
--
function Is_Valid (Path : in String;
FileSize : in Natural) return Boolean is
Register : aliased Kernel.swi_regs;
Error : oserror_access;
FileName_0 : String := Path & ASCII.NUL;
begin
Register.R(0) := 11;
Register.R(1) := Adr_To_Int(FileName_0'Address);
Register.R(2) := 16#fff#;
--Register.R(3) := 0;
Register.R(4) := 0;
Register.R(5) := Int(FileSize);
Error := Kernel.SWI (OS_File,Register'access,Register'access);
if Error /= null then
pragma Debug(Reporter.Report("FileExternal.Is_Valid: " & To_Ada(Error.ErrMess)));
return false;
end if;
Delete_File (Path);
return true;
end Is_Valid;
--
procedure Delete_File (Filename : in string) is
Filename_0 : string := Filename & ASCII.NUL;
Register : aliased Kernel.swi_regs;
Error : oserror_access;
begin
Register.R(0) := 6;
Register.R(1) := Adr_To_Int(Filename_0'address);
Error := Kernel.SWI (OS_File,Register'access,Register'access);
if Error /= null then
pragma Debug(Reporter.Report("FileExternal.Delete_File: " & To_Ada(Error.ErrMess)));
OS.Raise_Error(Error);
end if;
end Delete_File;
--
procedure Rename (Source : in string;
Target : in string) is
Source_0 : string := Source & ASCII.NUL;
Target_0 : string := Target & ASCII.NUL;
Register : aliased Kernel.SWI_Regs;
Error : OSError_Access;
begin
Register.R(0) := 25;
Register.R(1) := Adr_To_Int(Source_0'address);
Register.R(2) := Adr_To_Int(Target_0'address);
Error := Kernel.SWI (OS_FSControl,Register'Access,Register'Access);
if Error /= null then
pragma Debug(Reporter.Report("FileExternal.Rename: " & To_Ada(Error.ErrMess)));
OS.Raise_Error(Error);
end if;
end Rename;
--
procedure Copy (Source : in string; Target : in string;
Flags : in System.Unsigned_Types.Unsigned := 0) is
Source_0 : string := Source & ASCII.NUL;
Target_0 : string := Target & ASCII.NUL;
Register : aliased Kernel.SWI_Regs;
Error : OSError_Access;
begin
Register.R(0) := 26;
Register.R(1) := Adr_To_Int(Source_0'address);
Register.R(2) := Adr_To_Int(Target_0'address);
Register.R(3) := int(Unsigned_to_Int(Flags));
Error := Kernel.SWI (OS_FSControl,Register'Access,Register'Access);
if Error /= null then
pragma Debug(Reporter.Report("FileExternal.Copy: " & To_Ada(Error.ErrMess)));
OS.Raise_Error(Error);
end if;
end Copy;
--
procedure Move (Source : in string; Target : in string;
Flags : in System.Unsigned_Types.Unsigned := Copy_Option_Delete) is
begin
Copy (Source,Target,Flags);
end Move;
--
procedure Wipe (Path : in string) is
Path_0 : string := Path & ASCII.NUL;
Register : aliased Kernel.swi_regs;
Error : oserror_access;
begin
Register.R(0) := int(27);
Register.R(1) := Adr_To_Int(Path_0'address);
Register.R(2) := 0;
Register.R(3) := int(1+2);
Register.R(4) := int(0);
Register.R(5) := int(0);
Register.R(6) := int(0);
Register.R(7) := int(0);
Register.R(8) := int(0);
Error := Kernel.swi (OS_FSControl,Register'Access,Register'Access);
if Error /= null then
pragma Debug(Reporter.Report("FileExternal.Wipe: " & To_Ada(Error.ErrMess)));
OS.Raise_Error(Error);
end if;
end Wipe;
--
procedure Create_File (Filename : in string;
Length : in integer := 0;
Filetype : in integer := 16#FFD#) is
Filename_0 : string := Filename & ASCII.NUL;
Register : aliased Kernel.swi_regs;
Error : oserror_access;
begin
Register.R(0) := 11;
Register.R(1) := Adr_To_Int(Filename_0'address);
Register.R(2) := int(Filetype);
Register.R(4) := 0;
Register.R(5) := int(Length);
Error := Kernel.SWI (OS_File,Register'Access,Register'Access);
if Error /= null then
pragma Debug(Reporter.Report("FileExternal.Create_File: " & To_Ada(Error.ErrMess)));
OS.Raise_Error(Error);
end if;
end Create_File;
--
procedure Create_Directory (Dirname : in string) is
Dirname_0 : string := Dirname & ASCII.NUL;
Register : aliased Kernel.swi_regs;
Error : oserror_access;
begin
Register.R(0) := 8;
Register.R(1) := Adr_To_Int(Dirname_0'address);
Register.R(4) := 0;
Error := Kernel.SWI (OS_File,Register'Access,Register'Access);
if Error /= null then
pragma Debug(Reporter.Report("FileExternal.Create_Directory: " & To_Ada(Error.ErrMess)));
OS.Raise_Error(Error);
end if;
end Create_Directory;
--
function Get_FileNames (Path : in string) return string is
names : unbounded_string := U("");
Index : Integer := 0;
BufferSize: constant Positive := 4096;
Buffer : String(1..BufferSize);
Name : Unbounded_String;
ObjectsRead,Offset : Natural;
begin
loop
exit when Index = -1;
Read_Dir(Path,Index,ObjectsRead,Buffer'address,BufferSize);
Offset := 0;
loop
exit when ObjectsRead < 1;
Name := U(MemoryToString (Buffer'Address,Offset,ASCII.NUL));
Offset := Offset+Length(Name)+1;
ObjectsRead := ObjectsRead - 1;
if Length(name) > 0 then
if Length(names) > 0 then
names := names & ",";
end if;
names := names & name;
end if;
end loop;
end loop;
return S(names);
end Get_FileNames;
--
procedure Read_Dir (Path : in String;
Index : in out Integer;
ObjectsRead: out Natural;
Buffer : in Address;
BufferSize : in Positive := 8192;
Match : in string := "*") is
Path_0 : string := Path & ASCII.NUL;
Match_0 : string := Match & ASCII.NUL;
Register : aliased Kernel.swi_regs;
Error : oserror_access;
Nr : integer;
begin
loop
Register.R(0) := 9;
Register.R(1) := Adr_To_Int(Path_0'Address);
Register.R(2) := Adr_To_Int(Buffer);
Register.R(3) := int(BufferSize/10);
Register.R(4) := int(Index);
Register.R(5) := int(BufferSize);
if Match = "*" then
Register.R(6) := 0;
else
Register.R(6) := Adr_To_Int (Match_0'Address);
end if;
Error := Kernel.SWI (OS_GBPB,Register'Access,Register'Access);
if Error /= null then
pragma Debug(Reporter.Report("FileExternal.Read_Dir: " & To_Ada(Error.ErrMess)));
OS.Raise_Error(Error);
end if;
Index := integer(Register.R(4));
Nr := integer(Register.R(3));
exit when (Index = -1 or Nr > 0);
end loop;
ObjectsRead := Nr;
end Read_Dir;
--
function Nr_Of_Files (Path : in string) return integer is
Nr : integer := 0;
Index : integer := 0;
ObjectsRead : Natural;
Buffer : String (1..2048);
begin
loop
Read_Dir (Path,Index,ObjectsRead,Buffer'Address,2048,"*");
Nr := Nr + ObjectsRead;
exit when Index <0;
end loop;
return Nr;
end Nr_Of_Files;
--
function Get_DirectoryList (Path : in String) return Directory_Pointer is
Files : Natural := Nr_Of_Files(Path);
Directory : Directory_Pointer := new Directory_Type(1..Files);
Index : Integer := 0;
i : integer := 1;
BufferSize: constant Positive := 4096;
Buffer : String(1..BufferSize);
Name : Unbounded_String;
ObjectsRead,Offset : Natural;
begin
loop
exit when Index = -1;
Read_Dir(Path,Index,ObjectsRead,Buffer'address,BufferSize);
Offset := 0;
loop
exit when ObjectsRead < 1;
Name := U(MemoryToString (Buffer'Address,Offset,ASCII.NUL));
Offset := Offset+Length(Name)+1;
ObjectsRead := ObjectsRead - 1;
Directory.all (i) := Name;
i := i + 1;
end loop;
end loop;
return Directory;
end Get_DirectoryList;
--
procedure Get_DirectoryEntry (Directory : in string;
Index : in out integer;
Itemname : out Unbounded_String;
Loadadr : out integer;
Execadr : out integer;
Length : out integer;
Attributes : out integer;
Itemtype : out integer;
Match : in String := "*") is
Directory_0 : string := Directory & ASCII.NUL;
Match_0 : string := Match & ASCII.NUL;
Buffer : array (0..127) of integer;
Register : aliased Kernel.swi_regs;
Error : oserror_access;
begin
Register.R(0) := 11;
Register.R(1) := Adr_To_Int(Directory_0'address);
Register.R(2) := Adr_To_Int(Buffer'address);
Register.R(3) := 1;
Register.R(4) := int(Index);
Register.R(5) := 512;
if Match = "*" then
Register.R(6) := 0;
else
Register.R(6) := Adr_To_Int (Match_0'Address);
end if;
Error := Kernel.SWI (OS_GBPB,Register'access,Register'access);
if Error /= null then
pragma Debug(Reporter.Report("FileExternal.Get_Directory_Entry: " & To_Ada(Error.ErrMess)));
OS.Raise_Error(Error);
end if;
Index := integer(Register.R(4));
Itemname := U(Memory.MemoryToString(Buffer'Address,29));
Loadadr := Buffer(0);
Execadr := Buffer(1);
Length := Buffer(2);
Attributes := Buffer(3);
Itemtype := Buffer(4);
if Register.R(3) = 0 then
Index := -2;
end if;
end Get_DirectoryEntry;
--
procedure Get_DirectoryEntries (Path : in String;
Index : in out Integer;
ObjectsRead: out Natural;
Buffer : in Address;
BufferSize : in Positive := 8192;
Match : in string := "*") is
Path_0 : string := Path & ASCII.NUL;
Match_0 : string := Match & ASCII.NUL;
Register : aliased Kernel.swi_regs;
Error : oserror_access;
Nr : integer;
begin
loop
Register.R(0) := 11;
Register.R(1) := Adr_To_Int(Path_0'Address);
Register.R(2) := Adr_To_Int(Buffer);
Register.R(3) := int(BufferSize/10);
Register.R(4) := int(Index);
Register.R(5) := int(BufferSize);
if Match = "*" then
Register.R(6) := 0;
else
Register.R(6) := Adr_To_Int (Match_0'Address);
end if;
Error := Kernel.SWI (OS_GBPB,Register'Access,Register'Access);
if Error /= null then
pragma Debug(Reporter.Report("FileExternal.Get_DirectoryEntries: " & To_Ada(Error.ErrMess)));
OS.Raise_Error(Error);
end if;
Index := integer(Register.R(4));
Nr := integer(Register.R(3));
exit when (Index = -1 or Nr > 0);
end loop;
ObjectsRead := Nr;
end Get_DirectoryEntries;
--
procedure Get_FileInformation (Filepath : in string;
Loadadr : out integer;
Execadr : out integer;
Length : out integer;
Attributes : out integer;
Itemtype : out File_Object_Type) is
Error : oserror_access;
Register : aliased Kernel.swi_regs;
Filename_0 : string := Filepath & ASCII.NUL;
begin
Register.R(0) := 13;
Register.R(1) := Adr_To_Int(Filename_0'Address);
Error := Kernel.SWI (OS_File,Register'Access,Register'Access);
if Error /= null then
pragma Debug(Reporter.Report("FileExternal.Get_File_Information: " & To_Ada(Error.ErrMess)));
OS.Raise_Error(Error);
end if;
Loadadr := Integer(Register.R(2));
Execadr := Integer(Register.R(3));
Length := Integer(Register.R(4));
Attributes := Integer(Register.R(5));
Itemtype := File_Object_Type'Val(Integer(Register.R(0)));
end Get_FileInformation;
--
procedure Set_FileType (Filename : in string;
Filetype : in integer) is
Filename_0 : string := Filename & ASCII.NUL;
Register : aliased Kernel.swi_regs;
Error : oserror_access;
begin
Register.R(0) := 18;
Register.R(1) := Adr_To_Int(Filename_0'Address);
Register.R(2) := int(Filetype);
Error := Kernel.SWI (OS_File,Register'Access,Register'Access);
if Error /= null then
pragma Debug(Reporter.Report("FileExternal.Set_FileType: " & To_Ada(Error.ErrMess)));
OS.Raise_Error(Error);
end if;
exception
when others => null; pragma Debug(Reporter.Report("Error in FileExternal.Set_FileType"));
end Set_FileType;
--
function Get_Size (Filename : in string) return integer is
Filename_0 : string := Filename & ASCII.NUL;
Register : aliased Kernel.swi_regs;
Error : oserror_access;
begin
Register.R(0) := 17;
Register.R(1) := Adr_To_Int(Filename_0'address);
Error := Kernel.swi (OS_File,Register'Access,Register'Access);
if Error /= null then
pragma Debug(Reporter.Report("FileExternal.Get_Size: " & To_Ada(Error.ErrMess)));
OS.Raise_Error(Error);
end if;
return integer(Register.R(4));
end Get_Size;
--
procedure Get_DirectoryStamp (Directory : in string;
Loadadr : out integer;
Execadr : out integer) is
Directory_0 : string := Directory & ASCII.NUL;
Register : aliased Kernel.swi_regs;
Error : oserror_access;
begin
Register.R(0) := 21;
Register.R(1) := Adr_To_Int(Directory_0'address);
Error := Kernel.SWI (OS_File,Register'access,Register'access);
if Error /= null then
pragma Debug(Reporter.Report("FileExternal.Get_DirectoryStamp: " & To_Ada(Error.ErrMess)));
OS.Raise_Error(Error);
end if;
Loadadr := integer(Register.R(2));
Execadr := integer(Register.R(3));
end Get_DirectoryStamp;
--
function Get_ObjectType (Filename : in string) return File_Object_Type is
Filename_0 : string := Filename & ASCII.NUL;
Register : aliased Kernel.swi_regs;
Error : oserror_access;
begin
Register.R(0) := 23;
Register.R(1) := Adr_To_Int(Filename_0'address);
Error := Kernel.SWI(OS_File,Register'access,Register'access);
if Error /= null then
pragma Debug(Reporter.Report("FileExternal.Get_ObjectType: " & To_Ada(Error.ErrMess)));
OS.Raise_Error(Error);
end if;
return File_Object_Type'Val(Integer(Register.R(0)));
end Get_ObjectType;
--
function Get_FileType (Filename : in string) return integer is
Filename_0 : string := Filename & ASCII.NUL;
Register : aliased Kernel.swi_regs;
Error : oserror_access;
begin
Register.R(0) := 23;
Register.R(1) := Adr_To_Int(Filename_0'address);
Error := Kernel.swi(OS_File,Register'access,Register'access);
if Error /= null then
pragma Debug(Reporter.Report("FileExternal.Get_Filetype: " & To_Ada(Error.ErrMess)));
OS.Raise_Error(Error);
end if;
if Register.R(0) = 0 then
return -1;
else
return integer(Register.R(6));
end if;
end Get_FileType;
--
function Filetype_To_Hex (Loadadr : in integer) return string is
Result : string(1..3);
Masked : System.Unsigned_Types.Unsigned;
Nibble : System.Unsigned_Types.Unsigned;
Load : System.Unsigned_Types.Unsigned;
begin
if Loadadr = -1 then
return "";
end if;
Load := Int_To_Unsigned (Loadadr);
if (Load and 16#FFF00000#) = 16#FFF00000# then
Masked := System.Unsigned_Types.Shift_Right((Load and 16#000FFF00#),8);
for i in 1..3 loop
Nibble := (System.Unsigned_Types.Shift_Right(Masked,(3-i)*4)) and 16#F#;
case Nibble is
when 0 => Result(i) := '0';
when 1 => Result(i) := '1';
when 2 => Result(i) := '2';
when 3 => Result(i) := '3';
when 4 => Result(i) := '4';
when 5 => Result(i) := '5';
when 6 => Result(i) := '6';
when 7 => Result(i) := '7';
when 8 => Result(i) := '8';
when 9 => Result(i) := '9';
when 10 => Result(i) := 'A';
when 11 => Result(i) := 'B';
when 12 => Result(i) := 'C';
when 13 => Result(i) := 'D';
when 14 => Result(i) := 'E';
when 15 => Result(i) := 'F';
when others => Result(i) := 'x';
end case;
end loop;
return Result;
else
return "xxx";
end if;
end Filetype_To_Hex;
--
function Filetype_To_Number (FileType : in String) return Integer is
FileType_0 : string := FileType & ASCII.NUL;
Register : aliased Kernel.swi_regs;
Error : oserror_access;
begin
Register.R(0) := 31;
Register.R(1) := Adr_To_Int(FileType_0'address);
Error := Kernel.SWI(OS_FSControl,Register'access,Register'access);
if Error /= null then
return -1;
end if;
return Integer(Register.R(2));
end Filetype_To_Number;
--
function Get_Attributes (Path : in string) return integer is
Path_0 : String := Path & ASCII.NUL;
Register : aliased Kernel.swi_regs;
Error : oserror_access;
begin
Register.R(0) := 17;
Register.R(1) := Adr_To_Int(Path_0'Address);
Error := Kernel.SWI (OS_File,Register'Access,Register'Access);
if Error = null then
return integer(Register.r(5));
else
OS.Raise_Error(Error);
pragma Debug(Reporter.Report("FileExternal.Get_Attributes: " & To_Ada(Error.ErrMess)));
return 0;
end if;
end Get_Attributes;
--
procedure Set_Attributes (Path : in string; Attributes : in integer) is
Path_0 : String := Path & ASCII.NUL;
Register : aliased Kernel.swi_regs;
Error : oserror_access;
begin
Register.R(0) := 4;
Register.R(1) := Adr_To_Int(Path_0'Address);
Register.R(5) := Int(Attributes);
Error := Kernel.SWI (OS_File,Register'Access,Register'Access);
if Error /= null then
OS.Raise_Error(Error);
pragma Debug(Reporter.Report("FileExternal.Set_Attributes: " & To_Ada(Error.ErrMess)));
end if;
end Set_Attributes;
--
function Get_Stamp (Path : in String) return UTC_Pointer is
Register : aliased Kernel.swi_regs;
Error : oserror_access;
Path_0 : String := Path & ASCII.NUL;
Stamp : UTC_Pointer := new UTC_Time_Type;
Result,Word : System.Unsigned_Types.Unsigned;
begin
Register.R(0) := 17;
Register.R(1) := Adr_To_Int(Path_0'Address);
Error := Kernel.SWI (OS_File,Register'Access,Register'Access);
if Error /= null then
OS.Raise_Error(Error);
pragma Debug(Reporter.Report("FileExternal.Get_Stamp: " & To_Ada(Error.ErrMess)));
return null;
end if;
Result := Int_To_Unsigned(integer(Register.R(2)));
Stamp.all.Word := Int_To_Unsigned(integer(Register.R(3)));
Word := "and"(Result,16#ff#);
Stamp.all.Last_Byte := Byte(Word);
return Stamp;
end Get_Stamp;
--
end RASCAL.FileExternal;
|
-- Time-stamp: <02 oct 2012 09:38 queinnec@enseeiht.fr>
with LR.Tasks;
-- Simulateur temporel, avec possibilité de suspendre l'écoulement du temps,
-- de varier la vitesse du temps, et d'interrompre un sommeil.
package LR.Simu is
-- Initialise le simulateur de temps pour `Nbproc' processus.
procedure Init(Nbproc: Positive);
-- Suspend l'exécution du processus appelant, qui s'identifie par `Id', pour la durée spécifiée.
procedure Sleep(Id: LR.Tasks.Proc_Id; Duree: Positive);
-- Interrompt le sommeil du processus `Id'. Sans effet si le processus ne dort pas.
procedure Wakeup(Id: LR.Tasks.Proc_Id);
-- Renvoie la situation courante d'écoulement du temps.
function Get_Running return Boolean;
-- Décide de l'écoulement du temps.
procedure Set_Running(B: Boolean);
-- Inverse la situation courante d'écoulement du temps.
procedure Swap_Running;
-- Positionne la vitesse d'écoulement du temps.
procedure Set_Timespeed(Ts: Integer);
-- Obtention de la vitesse d'écoulement du temps.
function Get_Timespeed return Integer;
-- Suspend l'écoulement du temps en sauvegardant la situation courante (running ou pas).
-- Doit éventuellement être suivi par un appel à Resume_Time.
procedure Suspend_Time;
-- Restaure la situation de l'écoulement du temps avant le précédent `Suspend_Time'
procedure Resume_Time;
end LR.Simu;
|
with Ada.Interrupts; use Ada.Interrupts;
with Ada.Real_Time; use Ada.Real_Time;
with STM32_SVD.Interrupts; use STM32_SVD.Interrupts;
generic
Timer : STM32GD.Timer.Timer_Type := Timer_7;
IRQ : Interrupt_ID := TIM7;
package STM32GD.Timer.Peripheral is
procedure Init;
procedure Stop;
procedure After (Time : Time_Span; Callback : Timer_Callback_Type);
procedure Every (Interval : Time_Span; Callback : Timer_Callback_Type);
private
protected IRQ_Handler is
procedure Handler;
pragma Attach_Handler (Handler, IRQ);
end IRQ_Handler;
end STM32GD.Timer.Peripheral;
|
with System;
package HAL.Bitmap is
type Orientation_Mode is
(Default,
Portrait,
Landscape);
subtype Actual_Orientation is Orientation_Mode range Portrait .. Landscape;
type Bitmap_Color_Mode is
(ARGB_8888,
RGB_888,
RGB_565,
ARGB_1555,
ARGB_4444,
L_8,
AL_44,
AL_88,
L_4,
A_8,
A_4) with Size => 4;
function Bits_Per_Pixel (Mode : Bitmap_Color_Mode) return Positive is
(case Mode is
when ARGB_8888 => 32,
when RGB_888 => 24,
when RGB_565 | ARGB_1555 | ARGB_4444 | AL_88 => 16,
when L_8 | AL_44 | A_8 => 8,
when L_4 | A_4 => 4);
type Bitmap_Buffer is tagged record
Addr : System.Address;
Width : Natural;
Height : Natural;
-- Width and Height of the buffer. Note that it's the user-visible width
-- (see below for the meaning of the Swapped value).
Color_Mode : Bitmap_Color_Mode;
-- The buffer color mode. Note that not all color modes are supported by
-- the hardware acceleration (if any), so you need to check your actual
-- hardware to optimize buffer transfers.
Swapped : Boolean := False;
-- If Swap is set, then operations on this buffer will consider:
-- Width0 = Height
-- Height0 = Width
-- Y0 = Buffer.Width - X - 1
-- X0 = Y
--
-- As an example, the Bitmap buffer that corresponds to a 240x320
-- swapped display (to display images in landscape mode) with have
-- the following values:
-- Width => 320
-- Height => 240
-- Swapped => True
-- So Put_Pixel (Buffer, 30, 10, Color) will place the pixel at
-- Y0 = 320 - 30 - 1 = 289
-- X0 = 10
end record;
type Bitmap_Color is record
Alpha : Byte;
Red : Byte;
Green : Byte;
Blue : Byte;
end record with Size => 32;
for Bitmap_Color use record
Blue at 0 range 0 .. 7;
Green at 1 range 0 .. 7;
Red at 2 range 0 .. 7;
Alpha at 3 range 0 .. 7;
end record;
Black : constant Bitmap_Color := (255, 0, 0, 0);
Blue : constant Bitmap_Color := (255, 0, 0, 255);
Light_Blue : constant Bitmap_Color := (255, 173, 216, 230);
Brown : constant Bitmap_Color := (255, 165, 42, 42);
Cyan : constant Bitmap_Color := (255, 0, 255, 255);
Gray : constant Bitmap_Color := (255, 190, 190, 190);
Light_Gray : constant Bitmap_Color := (255, 211, 211, 211);
Green : constant Bitmap_Color := (255, 0, 255, 0);
Light_Green : constant Bitmap_Color := (255, 144, 238, 144);
Magenta : constant Bitmap_Color := (255, 255, 0, 255);
Red : constant Bitmap_Color := (255, 255, 0, 0);
Orange : constant Bitmap_Color := (255, 255, 69, 0);
Violet : constant Bitmap_Color := (255, 238, 130, 238);
Yellow : constant Bitmap_Color := (255, 255, 255, 0);
White : constant Bitmap_Color := (255, 255, 255, 255);
Transparent : constant Bitmap_Color := (0, 0, 0, 0);
procedure Set_Pixel
(Buffer : Bitmap_Buffer;
X : Natural;
Y : Natural;
Value : Bitmap_Color);
procedure Set_Pixel
(Buffer : Bitmap_Buffer;
X : Natural;
Y : Natural;
Value : Word);
procedure Set_Pixel_Blend
(Buffer : Bitmap_Buffer;
X : Natural;
Y : Natural;
Value : Bitmap_Color);
function Get_Pixel
(Buffer : Bitmap_Buffer;
X : Natural;
Y : Natural)
return Bitmap_Color;
function Get_Pixel
(Buffer : Bitmap_Buffer;
X : Natural;
Y : Natural)
return Word;
procedure Fill
(Buffer : Bitmap_Buffer;
Color : Bitmap_Color);
-- Fill the specified buffer with 'Color'
procedure Fill
(Buffer : Bitmap_Buffer;
Color : Word);
-- Same as above, using the destination buffer native color representation
procedure Fill_Rect
(Buffer : Bitmap_Buffer;
Color : Bitmap_Color;
X : Integer;
Y : Integer;
Width : Integer;
Height : Integer);
-- Fill the specified area of the buffer with 'Color'
procedure Fill_Rect
(Buffer : Bitmap_Buffer;
Color : Word;
X : Integer;
Y : Integer;
Width : Integer;
Height : Integer);
-- Same as above, using the destination buffer native color representation
procedure Copy_Rect
(Src_Buffer : Bitmap_Buffer'Class;
X_Src : Natural;
Y_Src : Natural;
Dst_Buffer : Bitmap_Buffer;
X_Dst : Natural;
Y_Dst : Natural;
Bg_Buffer : Bitmap_Buffer'Class;
X_Bg : Natural;
Y_Bg : Natural;
Width : Natural;
Height : Natural);
procedure Copy_Rect
(Src_Buffer : Bitmap_Buffer;
X_Src : Natural;
Y_Src : Natural;
Dst_Buffer : Bitmap_Buffer'Class;
X_Dst : Natural;
Y_Dst : Natural;
Width : Natural;
Height : Natural);
procedure Copy_Rect_Blend
(Src_Buffer : Bitmap_Buffer;
X_Src : Natural;
Y_Src : Natural;
Dst_Buffer : Bitmap_Buffer'Class;
X_Dst : Natural;
Y_Dst : Natural;
Width : Natural;
Height : Natural);
procedure Draw_Vertical_Line
(Buffer : Bitmap_Buffer;
Color : Word;
X : Integer;
Y : Integer;
Height : Integer);
procedure Draw_Vertical_Line
(Buffer : Bitmap_Buffer;
Color : Bitmap_Color;
X : Integer;
Y : Integer;
Height : Integer);
procedure Draw_Horizontal_Line
(Buffer : Bitmap_Buffer;
Color : Word;
X : Integer;
Y : Integer;
Width : Integer);
procedure Draw_Horizontal_Line
(Buffer : Bitmap_Buffer;
Color : Bitmap_Color;
X : Integer;
Y : Integer;
Width : Integer);
procedure Draw_Rect
(Buffer : Bitmap_Buffer;
Color : Bitmap_Color;
X : Integer;
Y : Integer;
Width : Integer;
Height : Integer);
-- Draws a rectangle
function Buffer_Size (Buffer : Bitmap_Buffer) return Natural;
function Bitmap_Color_To_Word
(Mode : Bitmap_Color_Mode; Col : Bitmap_Color)
return Word;
-- Translates the DMA2D Color into native buffer color
function Word_To_Bitmap_Color
(Mode : Bitmap_Color_Mode; Col : Word)
return Bitmap_Color;
-- Translates the native buffer color into DMA2D Color
procedure Wait_Transfer (Buffer : Bitmap_Buffer);
-- Makes sure the DMA2D transfers are done
end HAL.Bitmap;
|
package Pack1 is
package Nested is
type Rec_Typ is record
null;
end record;
end Nested;
end Pack1;
|
-----------------------------------------------------------------------
-- helios-commands -- Helios commands
-- Copyright (C) 2017, 2018, 2019 Stephane Carrez
-- Written by Stephane Carrez (Stephane.Carrez@gmail.com)
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-----------------------------------------------------------------------
with Ada.IO_Exceptions;
with Ada.Command_Line;
with Util.Log.Loggers;
with Helios.Commands.Drivers;
with Helios.Commands.Info;
with Helios.Commands.Check;
with Helios.Commands.Agent;
with Helios.Commands.Register;
package body Helios.Commands is
Log : constant Util.Log.Loggers.Logger := Util.Log.Loggers.Create ("Helios.Commands");
procedure Load_Server_Config (Context : in out Context_Type);
Help_Command : aliased Helios.Commands.Drivers.Help_Command_Type;
Info_Command : aliased Helios.Commands.Info.Command_Type;
Check_Command : aliased Helios.Commands.Check.Command_Type;
Agent_Command : aliased Helios.Commands.Agent.Command_Type;
Register_Command : aliased Helios.Commands.Register.Command_Type;
Driver : Drivers.Driver_Type;
-- ------------------------------
-- Initialize the commands.
-- ------------------------------
procedure Initialize is
begin
Driver.Set_Description ("helios - monitoring agent");
Driver.Set_Usage ("[-v] [-d] [-c config] <command> [<args>]" & ASCII.LF &
"where:" & ASCII.LF &
" -v Verbose execution mode" & ASCII.LF &
" -d Debug execution mode" & ASCII.LF &
" -c config Use the configuration file");
Driver.Add_Command ("help", "print some help", Help_Command'Access);
Driver.Add_Command ("info", "report information", Info_Command'Access);
Driver.Add_Command ("check", "check the agent status", Check_Command'Access);
Driver.Add_Command ("agent", "agent start and stop", Agent_Command'Access);
Driver.Add_Command ("register", "agent registration", Register_Command'Access);
end Initialize;
-- ------------------------------
-- Print the command usage.
-- ------------------------------
procedure Usage (Args : in Argument_List'Class;
Name : in String := "") is
Context : Context_Type;
begin
Driver.Usage (Args, Context, Name);
end Usage;
-- ------------------------------
-- Execute the command with its arguments.
-- ------------------------------
procedure Execute (Name : in String;
Args : in Argument_List'Class;
Context : in out Context_Type) is
begin
Driver.Execute (Name, Args, Context);
end Execute;
-- ------------------------------
-- Load the configuration to use REST API to our server.
-- ------------------------------
procedure Load_Server_Config (Context : in out Context_Type) is
Path : constant String := Context.Config.Get ("hyperion", "hyperion-client.cfg");
begin
Context.Server.Load_Properties (Path);
exception
when Ada.IO_Exceptions.Name_Error =>
Log.Error ("Configuration key file '{0}' does not exist.", Path);
Log.Error ("Use the '-c config' option to specify a configuration file.");
Ada.Command_Line.Set_Exit_Status (Ada.Command_Line.Failure);
raise Error;
end Load_Server_Config;
-- ------------------------------
-- Save the server connection configuration.
-- ------------------------------
procedure Save_Server_Configuration (Context : in out Context_Type) is
Path : constant String := Context.Config.Get ("hyperion", "hyperion-client.cfg");
begin
Context.Server.Save_Properties (Path);
exception
when Ada.IO_Exceptions.Name_Error =>
Log.Error ("Cannot save server configuration");
Ada.Command_Line.Set_Exit_Status (Ada.Command_Line.Failure);
raise Error;
end Save_Server_Configuration;
-- ------------------------------
-- Load the configuration context from the configuration file.
-- ------------------------------
procedure Load (Context : in out Context_Type) is
Path : constant String := Ada.Strings.Unbounded.To_String (Context.Config_Path);
begin
Context.Config.Load_Properties (Path);
Load_Server_Config (Context);
exception
when Ada.IO_Exceptions.Name_Error =>
Log.Error ("Configuration file '{0}' does not exist.", Path);
Log.Error ("Use the '-c config' option to specify a configuration file.");
Ada.Command_Line.Set_Exit_Status (Ada.Command_Line.Failure);
raise Error;
end Load;
-- ------------------------------
-- Set the path of the configuration file to load.
-- ------------------------------
procedure Set_Configuration (Context : in out Context_Type;
Path : in String) is
begin
Context.Config_Path := Ada.Strings.Unbounded.To_Unbounded_String (Path);
end Set_Configuration;
end Helios.Commands;
|
------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Localization, Internationalization, Globalization for Ada --
-- --
-- Tools Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2010-2011, Vadim Godunko <vgodunko@gmail.com> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
with Ada.Characters.Conversions;
with Ada.Characters.Handling;
with GNAT.Regpat;
with Asis.Declarations;
with Asis.Definitions;
with Asis.Elements;
with Asis.Expressions;
with Asis.Iterator;
with Asis.Statements;
with Asis.Text;
package body Scanner_Extractor is
type State_Information is record
States : Boolean := False;
end record;
procedure Process_Constant_Declaration
(Element : Asis.Element;
State : in out State_Information);
procedure Process_Integer_Number_Declaration (Element : Asis.Element);
procedure Process_Case_Statement (Element : Asis.Element);
procedure Pre_Operation
(Element : Asis.Element;
Control : in out Asis.Traverse_Control;
State : in out State_Information);
procedure Post_Operation
(Element : Asis.Element;
Control : in out Asis.Traverse_Control;
State : in out State_Information) is null;
procedure Iterate is new Asis.Iterator.Traverse_Element (State_Information);
function To_Upper (Item : Wide_String) return Wide_String;
-------------
-- Extract --
-------------
procedure Extract (Element : Asis.Element) is
Control : Asis.Traverse_Control := Asis.Continue;
State : State_Information;
begin
Iterate (Element, Control, State);
end Extract;
-------------------
-- Pre_Operation --
-------------------
procedure Pre_Operation
(Element : Asis.Element;
Control : in out Asis.Traverse_Control;
State : in out State_Information) is
begin
case Asis.Elements.Element_Kind (Element) is
when Asis.A_Declaration =>
case Asis.Elements.Declaration_Kind (Element) is
when Asis.A_Constant_Declaration =>
Process_Constant_Declaration (Element, State);
when Asis.An_Integer_Number_Declaration =>
Process_Integer_Number_Declaration (Element);
when others =>
null;
end case;
when Asis.A_Statement =>
case Asis.Elements.Statement_Kind (Element) is
when Asis.A_Case_Statement =>
Process_Case_Statement (Element);
when others =>
null;
end case;
when others =>
null;
end case;
end Pre_Operation;
----------------------------
-- Process_Case_Statement --
----------------------------
procedure Process_Case_Statement (Element : Asis.Element) is
use type Asis.Expression_Kinds;
procedure Process_Choice
(Choice : Asis.Element;
Line : Positive;
File : Ada.Strings.Wide_Unbounded.Unbounded_Wide_String;
Text : Unbounded_Wide_String_Vectors.Vector);
--------------------
-- Process_Choice --
--------------------
procedure Process_Choice
(Choice : Asis.Element;
Line : Positive;
File : Ada.Strings.Wide_Unbounded.Unbounded_Wide_String;
Text : Unbounded_Wide_String_Vectors.Vector)
is
use type Ada.Strings.Wide_Unbounded.Unbounded_Wide_String;
Number : Natural;
begin
case Asis.Elements.Expression_Kind (Choice) is
when Asis.An_Integer_Literal =>
Number :=
Integer'Wide_Value (Asis.Expressions.Value_Image (Choice));
when Asis.A_Function_Call =>
declare
Parameters_1 : constant Asis.Element_List :=
Asis.Expressions.Function_Call_Parameters (Choice);
Parameters_2 : constant Asis.Element_List :=
Asis.Expressions.Function_Call_Parameters
(Asis.Expressions.Actual_Parameter (Parameters_1 (1)));
Parameter_2 : constant Wide_String :=
To_Upper
(Asis.Expressions.Name_Image
(Asis.Expressions.Actual_Parameter (Parameters_2 (2))));
begin
Number := YY_End_Of_Buffer;
for J in 1 .. Natural (State_Constants.Length) loop
if State_Constants.Element (J).Name = Parameter_2 then
Number :=
Number + State_Constants.Element (J).Value + 1;
end if;
end loop;
end;
when others =>
null;
end case;
-- Skip jam state
if Number /= YY_End_Of_Buffer - 1 then
if Natural (Choices.Length) < Number then
Choices.Set_Length (Ada.Containers.Count_Type (Number));
end if;
Choices.Replace_Element
(Number, (False, Number, Line, File, Text));
end if;
end Process_Choice;
Expression : constant Asis.Element :=
Asis.Statements.Case_Expression (Element);
Paths : constant Asis.Element_List :=
Asis.Statements.Statement_Paths (Element);
begin
if Asis.Elements.Expression_Kind (Expression) = Asis.An_Identifier
and then To_Upper (Asis.Expressions.Name_Image (Expression)) = "YY_ACT"
then
for J in Paths'Range loop
declare
Choices : constant Asis.Element_List :=
Asis.Statements.Case_Statement_Alternative_Choices
(Paths (J));
Lines : constant Asis.Text.Line_List :=
Asis.Text.Lines (Paths (J));
Pattern : GNAT.Regpat.Pattern_Matcher :=
GNAT.Regpat.Compile ("--# line (\d+) ""(.*?)""");
Matched : Boolean := False;
Empty : Boolean := True;
Matches : GNAT.Regpat.Match_Array (0 .. 2);
Text : Unbounded_Wide_String_Vectors.Vector;
Line : Positive;
File : Ada.Strings.Wide_Unbounded.Unbounded_Wide_String;
begin
for J in Lines'Range loop
declare
Line_Image : constant Wide_String :=
Asis.Text.Line_Image (Lines (J));
begin
if not Matched then
GNAT.Regpat.Match
(Pattern,
Ada.Characters.Conversions.To_String (Line_Image),
Matches);
if Matches (0).First /= 0 then
Matched := True;
Line :=
Positive'Wide_Value
(Line_Image
(Matches (1).First .. Matches (1).Last));
File :=
Ada.Strings.Wide_Unbounded.To_Unbounded_Wide_String
(Line_Image
(Matches (2).First .. Matches (2).Last));
end if;
else
if Empty then
Empty := Line_Image'Length = 0;
end if;
if not Empty then
Text.Append
(Ada.Strings.Wide_Unbounded.To_Unbounded_Wide_String
(Line_Image));
end if;
end if;
end;
end loop;
if not Text.Is_Empty then
for J in Choices'Range loop
Process_Choice (Choices (J), Line, File, Text);
end loop;
end if;
end;
end loop;
end if;
end Process_Case_Statement;
----------------------------------
-- Process_Constant_Declaration --
----------------------------------
procedure Process_Constant_Declaration
(Element : Asis.Element;
State : in out State_Information)
is
Names : Asis.Element_List := Asis.Declarations.Names (Element);
procedure Process_Array
(Declaration : Asis.Element;
Expression : Asis.Element;
Values : out Integer_Vectors.Vector);
procedure Process_Plane
(Expression : Asis.Element;
Values : out Integer_Vectors.Vector);
-------------------
-- Process_Array --
-------------------
procedure Process_Array
(Declaration : Asis.Element;
Expression : Asis.Element;
Values : out Integer_Vectors.Vector)
is
Bounds : constant Asis.Element_List :=
Asis.Definitions.Discrete_Subtype_Definitions (Declaration);
Upper : constant Natural :=
Natural'Wide_Value
(Asis.Expressions.Value_Image
(Asis.Definitions.Upper_Bound (Bounds (1))));
Components : constant Asis.Element_List :=
Asis.Expressions.Array_Component_Associations (Expression);
begin
Values.Set_Length (Ada.Containers.Count_Type (Upper + 1));
for J in Components'Range loop
Values.Replace_Element
(J - 1,
Natural'Wide_Value
(Asis.Expressions.Value_Image
(Asis.Expressions.Component_Expression (Components (J)))));
end loop;
end Process_Array;
-------------------
-- Process_Plane --
-------------------
procedure Process_Plane
(Expression : Asis.Element;
Values : out Integer_Vectors.Vector)
is
Components : constant Asis.Element_List :=
Asis.Expressions.Array_Component_Associations (Expression);
begin
Values.Set_Length (256);
for J in Components'Range loop
Values.Replace_Element
(J - 1,
Natural'Wide_Value
(Asis.Expressions.Value_Image
(Asis.Expressions.Component_Expression (Components (J)))));
end loop;
end Process_Plane;
begin
for J in Names'Range loop
declare
Image : constant Wide_String :=
To_Upper (Asis.Declarations.Defining_Name_Image (Names (J)));
Declaration : constant Asis.Element :=
Asis.Declarations.Object_Declaration_View (Element);
Expression : constant Asis.Element :=
Asis.Declarations.Initialization_Expression (Element);
begin
if Image = "INITIAL" then
State.States := True;
State_Constants.Append
((Ada.Strings.Wide_Unbounded.To_Unbounded_Wide_String (Image),
Integer'Wide_Value
(Asis.Expressions.Value_Image (Expression))));
elsif Image = "YY_ACCEPT" then
State.States := False;
Process_Array (Declaration, Expression, YY_Accept);
elsif Image = "YY_META" then
Process_Array (Declaration, Expression, YY_Meta);
elsif Image = "YY_BASE" then
Process_Array (Declaration, Expression, YY_Base);
elsif Image = "YY_DEF" then
Process_Array (Declaration, Expression, YY_Def);
elsif Image = "YY_NXT" then
Process_Array (Declaration, Expression, YY_Nxt);
elsif Image = "YY_CHK" then
Process_Array (Declaration, Expression, YY_Chk);
elsif Image = "YY_EC_BASE" then
declare
Components : constant Asis.Element_List :=
Asis.Expressions.Array_Component_Associations (Expression);
begin
for J in Components'Range loop
declare
Choices : constant Asis.Element_List :=
Asis.Expressions.Array_Component_Choices
(Components (J));
Image : constant Wide_String :=
Asis.Expressions.Name_Image
(Asis.Expressions.Prefix
(Asis.Expressions.Component_Expression
(Components (J))));
Ref : Natural :=
Natural'Wide_Value (Image (7 .. Image'Last));
begin
for J in Choices'Range loop
case Asis.Elements.Expression_Kind (Choices (J)) is
when Asis.An_Integer_Literal =>
YY_EC_Base.Append
((Natural'Wide_Value
(Asis.Expressions.Value_Image
(Choices (J))),
Ref));
when others =>
null;
end case;
case Asis.Elements.Definition_Kind (Choices (J)) is
when Asis.An_Others_Choice =>
YY_EC_Base_Others := Ref;
when others =>
null;
end case;
end loop;
end;
end loop;
end;
elsif Image'Length > 6 and then Image (1 .. 6) = "YY_EC_" then
declare
Data : Plane_Information;
begin
Data.Number := Natural'Wide_Value (Image (7 .. Image'Last));
Process_Plane (Expression, Data.Values);
YY_EC_Planes.Append (Data);
end;
elsif State.States then
State_Constants.Append
((Ada.Strings.Wide_Unbounded.To_Unbounded_Wide_String (Image),
Integer'Wide_Value
(Asis.Expressions.Value_Image (Expression))));
end if;
end;
end loop;
end Process_Constant_Declaration;
----------------------------------------
-- Process_Integer_Number_Declaration --
----------------------------------------
procedure Process_Integer_Number_Declaration (Element : Asis.Element) is
Names : Asis.Element_List := Asis.Declarations.Names (Element);
begin
for J in Names'Range loop
declare
Image : constant Wide_String :=
To_Upper (Asis.Declarations.Defining_Name_Image (Names (J)));
Expression : constant Asis.Element :=
Asis.Declarations.Initialization_Expression (Element);
begin
if Image = "YY_END_OF_BUFFER" then
YY_End_Of_Buffer :=
Integer'Wide_Value
(Asis.Expressions.Value_Image (Expression));
elsif Image = "YY_JAMSTATE" then
YY_Jam_State :=
Integer'Wide_Value
(Asis.Expressions.Value_Image (Expression));
elsif Image = "YY_JAMBASE" then
YY_Jam_Base :=
Integer'Wide_Value
(Asis.Expressions.Value_Image (Expression));
elsif Image = "YY_FIRST_TEMPLATE" then
YY_First_Template :=
Integer'Wide_Value
(Asis.Expressions.Value_Image (Expression));
end if;
end;
end loop;
end Process_Integer_Number_Declaration;
--------------
-- To_Upper --
--------------
function To_Upper (Item : Wide_String) return Wide_String is
begin
return
Ada.Characters.Conversions.To_Wide_String
(Ada.Characters.Handling.To_Upper
(Ada.Characters.Conversions.To_String (Item)));
end To_Upper;
end Scanner_Extractor;
|
pragma License (Unrestricted);
-- implementation unit
package System.UTF_Conversions.From_16_To_8 is
pragma Pure;
pragma Suppress (All_Checks); -- for instantiation
procedure Convert is
new Convert_Procedure (
Wide_Character,
Wide_String,
Character,
String,
From_UTF_16,
To_UTF_8);
function Convert is
new Convert_Function (
Wide_Character,
Wide_String,
Character,
String,
Expanding_From_16_To_8,
Convert);
end System.UTF_Conversions.From_16_To_8;
|
-- -----------------------------------------------------------------------------
-- smk, the smart make (http://lionel.draghi.free.fr/smk/)
-- © 2018, 2019 Lionel Draghi <lionel.draghi@free.fr>
-- SPDX-License-Identifier: APSL-2.0
-- -----------------------------------------------------------------------------
-- 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.Directories;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
package body Smk.Settings is
-- --------------------------------------------------------------------------
-- Most of the variable here are "write once, read more".
-- To avoid the cost of Unbounded strings manipulation,
-- they are implemented as access to String
Smkfl_Name : access String := null;
Runfl_Name : access String := null;
Current_Section : access String := null;
Current_Target : access String := null;
Cmd_Line : Unbounded_String := Null_Unbounded_String;
WD : constant access String
:= new String'(Ada.Directories.Current_Directory);
Ignored : constant Filter_List := (new String'("/sys/*"),
new String'("/proc/*"),
new String'("/dev/*"),
new String'("/tmp/*"),
new String'("/etc/ld.so.cache"));
System_Dir : constant Filter_List := (new String'("/usr/*"),
new String'("/lib/*"),
new String'("/etc/*"),
new String'("/opt/*"));
-- --------------------------------------------------------------------------
function Is_File_In (File, Dir : String) return Boolean is
Compared_Length : constant Natural := (if Dir (Dir'Last) = '*'
then Dir'Length - 1
else Dir'Length);
-- return True if File is in Dir, supposing that both are full name.
-- e.g. (Dir => /usr/*, File => /usr/lib/locale) return True
-- e.g. (Dir => /usr/*, File => locale) return False
begin
return (File'Length >= Compared_Length and then
File (File'First .. File'First - 1 + Compared_Length)
= Dir (Dir'First .. Dir'First - 1 + Compared_Length));
end Is_File_In;
-- --------------------------------------------------------------------------
function In_Ignore_List (File_Name : in String) return Boolean is
begin
for D of Ignored loop
if Is_File_In (File => File_Name, Dir => D.all) then
return True;
end if;
end loop;
if File_Name = Settings.Smkfile_Name
or else File_Name = Settings.Runfile_Name
then
return True;
end if;
return False;
end In_Ignore_List;
-- --------------------------------------------------------------------------
function Is_System (File_Name : in String) return Boolean is
(for some D of System_Dir =>
Is_File_In (File => File_Name, Dir => D.all));
-- --------------------------------------------------------------------------
function System_Files return Filter_List is (System_Dir);
function Ignore_List return Filter_List is (Ignored);
-- --------------------------------------------------------------------------
function Initial_Directory return String is (WD.all);
-- --------------------------------------------------------------------------
procedure Set_Smkfile_Name (Name : in String) is
begin
Smkfl_Name := new String'(Name);
Runfl_Name := new String'(To_Runfile_Name (Name));
end Set_Smkfile_Name;
function Smkfile_Name return String is
(if Smkfl_Name = null then "" else Smkfl_Name.all);
function Is_Smkfile_Name_Set return Boolean is
(Smkfl_Name /= null);
function Run_Dir_Name return String is
(Ada.Directories.Containing_Directory (Smkfile_Name));
function Strace_Outfile_Name return String is
(if Is_Smkfile_Name_Set then
Strace_Outfile_Prefix & Ada.Directories.Simple_Name (Smkfile_Name) &
Strace_Outfile_Suffix
else "");
-- --------------------------------------------------------------------------
procedure Set_Runfile_Name (Name : in String) is
begin
Runfl_Name := new String'(Name);
end Set_Runfile_Name;
function Runfile_Name return String is
(if Runfl_Name = null then "" else Runfl_Name.all);
function To_Runfile_Name (Smkfile_Name : in String) return String is
(Smk_File_Prefix & Ada.Directories.Simple_Name (Smkfile_Name));
-- --------------------------------------------------------------------------
procedure Set_Section_Name (Name : in String) is
begin
Current_Section := new String'(Name);
end Set_Section_Name;
function Section_Name return String is
(if Current_Section = null then "" else Current_Section.all);
-- --------------------------------------------------------------------------
procedure Add_To_Command_Line (Text : in String) is
begin
if Cmd_Line = "" then
Cmd_Line := To_Unbounded_String (Text);
else
Cmd_Line := Cmd_Line & " " & Text;
end if;
end Add_To_Command_Line;
function Command_Line return String is (To_String (Cmd_Line));
-- --------------------------------------------------------------------------
procedure Set_Target_Name (Target : in String) is
begin
Current_Target := new String'(Target);
end Set_Target_Name;
function Target_Name return String is
(if Current_Target = null then "" else Current_Target.all);
end Smk.Settings;
|
------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Web Framework --
-- --
-- Tools Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2015-2018, Vadim Godunko <vgodunko@gmail.com> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
with Asis.Extensions.Flat_Kinds;
with League.Strings;
with Properties.Common;
with Properties.Declarations.Component_Declaration;
with Properties.Declarations.Constant_Declarations;
with Properties.Declarations.Defining_Expanded_Name;
with Properties.Declarations.Defining_Names;
with Properties.Declarations.Element_Iterator_Specification;
with Properties.Declarations.Function_Declarations;
with Properties.Declarations.Function_Renaming_Declaration;
with Properties.Declarations.Generic_Declaration;
with Properties.Declarations.Incomplete_Type;
with Properties.Declarations.Loop_Parameter_Specification;
with Properties.Declarations.Ordinary_Type;
with Properties.Declarations.Package_Declaration;
with Properties.Declarations.Package_Instantiation;
with Properties.Declarations.Private_Type;
with Properties.Declarations.Procedure_Body_Declarations;
with Properties.Declarations.Procedure_Declaration;
with Properties.Declarations.Subprogram_Instantiation;
with Properties.Definitions.Access_To_Object;
with Properties.Definitions.Component_Definition;
with Properties.Definitions.Constrained_Array_Type;
with Properties.Definitions.Derived_Type;
with Properties.Definitions.Discriminant_Constraint;
with Properties.Definitions.Enumeration_Type;
with Properties.Definitions.Float_Point;
with Properties.Definitions.Index_Constraint;
with Properties.Definitions.Modular;
with Properties.Definitions.Others_Choice;
with Properties.Definitions.Range_Attribute;
with Properties.Definitions.Record_Type;
with Properties.Definitions.Signed;
with Properties.Definitions.Simple_Expression_Range;
with Properties.Definitions.Subtype_Indication;
with Properties.Definitions.Tagged_Record_Type;
with Properties.Definitions.Unconstrained_Array_Type;
with Properties.Definitions.Variant_Part;
with Properties.Definitions.Variant;
with Properties.Expressions.Allocation;
with Properties.Expressions.Allocation_From_Subtype;
with Properties.Expressions.Array_Component_Association;
with Properties.Expressions.Attribute_Reference;
with Properties.Expressions.Case_Expression;
with Properties.Expressions.Enumeration_Literal;
with Properties.Expressions.Explicit_Dereference;
with Properties.Expressions.Extension_Aggregate;
with Properties.Expressions.Function_Calls;
with Properties.Expressions.Identifiers;
with Properties.Expressions.If_Expression;
with Properties.Expressions.Indexed_Component;
with Properties.Expressions.Integer_Literal;
with Properties.Expressions.Membership_Test;
with Properties.Expressions.Null_Literal;
with Properties.Expressions.Parameter_Association;
with Properties.Expressions.Parenthesized;
with Properties.Expressions.Pos_Array_Aggregate;
with Properties.Expressions.Record_Aggregate;
with Properties.Expressions.Record_Component_Association;
with Properties.Expressions.Selected_Components;
with Properties.Expressions.Short_Circuit;
with Properties.Expressions.Slice;
with Properties.Expressions.String_Literal;
with Properties.Expressions.Type_Conversion;
with Properties.Statements.Assignment_Statement;
with Properties.Statements.Block_Statement;
with Properties.Statements.Case_Statement;
with Properties.Statements.Exit_Statement;
with Properties.Statements.Extended_Return;
with Properties.Statements.For_Loop_Statement;
with Properties.Statements.If_Statement;
with Properties.Statements.Loop_Statement;
with Properties.Statements.Procedure_Call_Statement;
with Properties.Statements.Raise_Statement;
with Properties.Statements.Return_Statement;
with Properties.Statements.While_Loop_Statement;
procedure Engines.Registry_All_Actions
(Self : in out Engines.Contexts.Context)
is
type Text_Callback is access function
(Engine : access Engines.Contexts.Context;
Element : Asis.Element;
Name : Engines.Text_Property) return League.Strings.Universal_String;
type Action_Item is record
Name : Engines.Text_Property;
Kind : Asis.Extensions.Flat_Kinds.Flat_Element_Kinds;
Action : Text_Callback;
end record;
type Boolean_Callback is access function
(Engine : access Engines.Contexts.Context;
Element : Asis.Element;
Name : Engines.Boolean_Property) return Boolean;
type Boolean_Action_Item is record
Name : Engines.Boolean_Property;
Kind : Asis.Extensions.Flat_Kinds.Flat_Element_Kinds;
Action : Boolean_Callback;
end record;
type Integer_Callback is access function
(Engine : access Engines.Contexts.Context;
Element : Asis.Element;
Name : Engines.Integer_Property) return Integer;
type Integer_Action_Item is record
Name : Engines.Integer_Property;
Kind : Asis.Extensions.Flat_Kinds.Flat_Element_Kinds;
Action : Integer_Callback;
end record;
type Action_Array is array (Positive range <>) of Action_Item;
type Action_Range is record
Name : Engines.Text_Property;
From, To : Asis.Extensions.Flat_Kinds.Flat_Element_Kinds;
Action : Text_Callback;
end record;
type Range_Array is array (Positive range <>) of Action_Range;
package F renames Asis.Extensions.Flat_Kinds;
package N renames Engines;
package P renames Properties;
Action_List : constant Action_Array :=
-- Address
((Name => N.Address,
Kind => F.An_Identifier,
Action => P.Expressions.Identifiers.Address'Access),
(Name => N.Address,
Kind => F.A_Selected_Component,
Action => P.Expressions.Selected_Components.Code'Access),
(Name => N.Address,
Kind => F.A_Type_Conversion,
Action => P.Expressions.Type_Conversion.Code'Access),
(Name => N.Address,
Kind => F.An_Explicit_Dereference,
Action => P.Expressions.Explicit_Dereference.Address'Access),
(Name => N.Address,
Kind => F.An_Indexed_Component,
Action => P.Expressions.Indexed_Component.Address'Access),
-- Associations
(Name => N.Associations,
Kind => F.A_Record_Component_Association,
Action =>
P.Expressions.Record_Component_Association.Associations'Access),
-- Code
(Name => N.Code,
Kind => F.A_Use_Package_Clause,
Action => P.Common.Empty'Access),
(Name => N.Code,
Kind => F.A_Constant_Declaration,
Action => P.Declarations.Constant_Declarations.Code'Access),
(Name => N.Code,
Kind => F.A_Return_Constant_Specification,
Action => P.Declarations.Constant_Declarations.Code'Access),
(Name => N.Code,
Kind => F.A_Return_Variable_Specification,
Action => P.Declarations.Constant_Declarations.Code'Access),
(Name => N.Code,
Kind => F.A_Deferred_Constant_Declaration,
Action => P.Common.Empty'Access),
(Name => N.Code,
Kind => F.A_Function_Declaration,
Action => P.Common.Empty'Access), -- Ignore
(Name => N.Code,
Kind => F.An_Ordinary_Type_Declaration,
Action => P.Declarations.Ordinary_Type.Code'Access),
(Name => N.Code,
Kind => F.A_Package_Declaration,
Action => P.Declarations.Package_Declaration.Code'Access),
(Name => N.Code,
Kind => F.A_Package_Body_Declaration,
Action => P.Common.Empty'Access),
(Name => N.Code,
Kind => F.A_Generic_Package_Declaration,
Action => P.Declarations.Generic_Declaration.Code'Access),
(Name => N.Code,
Kind => F.A_Generic_Package_Renaming_Declaration,
Action => P.Declarations.Generic_Declaration.Code'Access),
(Name => N.Code,
Kind => F.A_Generic_Function_Renaming_Declaration,
Action => P.Common.Empty'Access), -- Ignore
(Name => N.Code,
Kind => F.A_Generic_Function_Declaration,
Action => P.Common.Empty'Access), -- Ignore
(Name => N.Code,
Kind => F.A_Generic_Procedure_Declaration,
Action => P.Common.Empty'Access), -- Ignore
(Name => N.Code,
Kind => F.A_Package_Renaming_Declaration, -- FIXME
Action => P.Common.Empty'Access), -- Ignore
(Name => N.Code,
Kind => F.An_Object_Renaming_Declaration,
Action => P.Common.Empty'Access), -- Ignore
(Name => N.Code,
Kind => F.An_Integer_Number_Declaration,
Action => P.Common.Empty'Access), -- Ignore
(Name => N.Code,
Kind => F.A_Real_Number_Declaration,
Action => P.Common.Empty'Access), -- Ignore
(Name => N.Code,
Kind => F.A_Private_Extension_Declaration,
Action => P.Common.Empty'Access),
(Name => N.Code,
Kind => F.A_Tagged_Incomplete_Type_Declaration,
Action => P.Common.Empty'Access),
(Name => N.Code,
Kind => F.A_Private_Type_Declaration,
Action => P.Common.Empty'Access),
(Name => N.Code,
Kind => F.An_Incomplete_Type_Declaration,
Action => P.Common.Empty'Access),
(Name => N.Code,
Kind => F.A_Procedure_Body_Declaration,
Action => P.Declarations.Procedure_Body_Declarations.Code'Access),
(Name => N.Code,
Kind => F.A_Function_Body_Declaration,
Action => P.Declarations.Procedure_Body_Declarations.Code'Access),
(Name => N.Code,
Kind => F.A_Procedure_Declaration,
Action => P.Common.Empty'Access), -- Ignore
(Name => N.Code,
Kind => F.A_Null_Procedure_Declaration,
Action => P.Common.Empty'Access), -- Ignore
(Name => N.Code,
Kind => F.A_Loop_Parameter_Specification,
Action =>
P.Declarations.Loop_Parameter_Specification.Code'Access),
(Name => N.Code,
Kind => F.An_Element_Iterator_Specification,
Action =>
P.Declarations.Element_Iterator_Specification.Code'Access),
(Name => N.Code,
Kind => F.A_Subtype_Declaration,
Action => P.Common.Empty'Access),
(Name => N.Code,
Kind => F.A_Variable_Declaration,
Action => P.Declarations.Constant_Declarations.Code'Access),
(Name => N.Code,
Kind => F.A_Function_Renaming_Declaration,
Action => P.Common.Empty'Access),
(Name => N.Code,
Kind => F.A_Procedure_Renaming_Declaration,
Action => P.Common.Empty'Access),
(Name => N.Code,
Kind => F.A_Defining_Identifier,
Action => P.Declarations.Defining_Names.Code'Access),
(Name => N.Code,
Kind => F.A_Defining_Enumeration_Literal,
Action => P.Declarations.Defining_Names.Code'Access),
(Name => N.Code,
Kind => F.A_Defining_Expanded_Name,
Action => P.Declarations.Defining_Expanded_Name.Code'Access),
(Name => N.Code,
Kind => F.A_Package_Instantiation,
Action => P.Declarations.Package_Instantiation.Code'Access),
(Name => N.Code,
Kind => F.A_Procedure_Instantiation,
Action => P.Declarations.Subprogram_Instantiation.Code'Access),
(Name => N.Code,
Kind => F.A_Function_Instantiation,
Action => P.Declarations.Subprogram_Instantiation.Code'Access),
(Name => N.Code,
Kind => F.An_Enumeration_Type_Definition,
Action => P.Definitions.Enumeration_Type.Code'Access),
(Name => N.Code,
Kind => F.A_Signed_Integer_Type_Definition,
Action => P.Common.Empty'Access), -- Ignore
(Name => N.Code,
Kind => F.A_Subtype_Indication,
Action => P.Definitions.Subtype_Indication.Code'Access),
(Name => N.Code,
Kind => F.A_Constrained_Array_Definition,
Action => P.Definitions.Constrained_Array_Type.Code'Access),
(Name => N.Code,
Kind => F.An_Unconstrained_Array_Definition,
Action => P.Definitions.Unconstrained_Array_Type.Code'Access),
(Name => N.Code,
Kind => F.A_Component_Definition,
Action => P.Definitions.Component_Definition.Initialize'Access),
(Name => N.Code,
Kind => F.A_Derived_Type_Definition,
Action => P.Definitions.Derived_Type.Code'Access),
(Name => N.Code,
Kind => F.A_Derived_Record_Extension_Definition,
Action => P.Definitions.Tagged_Record_Type.Code'Access),
(Name => N.Code,
Kind => F.A_Tagged_Record_Type_Definition,
Action => P.Definitions.Tagged_Record_Type.Code'Access),
(Name => N.Code,
Kind => F.A_Limited_Interface,
Action => P.Definitions.Tagged_Record_Type.Code'Access),
(Name => N.Code,
Kind => F.A_Record_Type_Definition,
Action => P.Definitions.Record_Type.Code'Access),
(Name => N.Code,
Kind => F.A_Discriminant_Constraint,
Action => P.Definitions.Discriminant_Constraint.Code'Access),
(Name => N.Code,
Kind => F.An_Index_Constraint,
Action => P.Definitions.Index_Constraint.Code'Access),
(Name => N.Code,
Kind => F.An_Others_Choice,
Action => P.Definitions.Others_Choice.Code'Access),
(Name => N.Code,
Kind => F.An_Access_To_Variable,
Action => P.Common.Empty'Access), -- Ignore
(Name => N.Code,
Kind => F.An_Access_To_Constant,
Action => P.Common.Empty'Access), -- Ignore
(Name => N.Code,
Kind => F.A_Pool_Specific_Access_To_Variable,
Action => P.Common.Empty'Access), -- Ignore
(Name => N.Code,
Kind => F.An_Access_To_Procedure,
Action => P.Common.Empty'Access), -- Ignore
(Name => N.Code,
Kind => F.An_Access_To_Function,
Action => P.Common.Empty'Access), -- Ignore
(Name => N.Code,
Kind => F.A_Box_Expression,
Action => P.Common.Empty'Access), -- return "" for <>
(Name => N.Code,
Kind => F.An_Allocation_From_Qualified_Expression,
Action => P.Expressions.Allocation.Code'Access),
(Name => N.Code,
Kind => F.An_Allocation_From_Subtype,
Action => P.Expressions.Allocation_From_Subtype.Code'Access),
(Name => N.Code,
Kind => F.An_Enumeration_Literal,
Action => P.Expressions.Enumeration_Literal.Code'Access),
(Name => N.Code,
Kind => F.An_Explicit_Dereference,
Action => P.Expressions.Explicit_Dereference.Code'Access),
(Name => N.Code,
Kind => F.A_Function_Call,
Action => P.Expressions.Function_Calls.Code'Access),
(Name => N.Code,
Kind => F.An_Identifier,
Action => P.Expressions.Identifiers.Code'Access),
(Name => N.Code,
Kind => F.An_Indexed_Component,
Action => P.Expressions.Indexed_Component.Code'Access),
(Name => N.Code,
Kind => F.A_Slice,
Action => P.Expressions.Slice.Code'Access),
(Name => N.Code,
Kind => F.An_Integer_Literal,
Action => P.Expressions.Integer_Literal.Code'Access),
(Name => N.Code,
Kind => F.A_Real_Literal,
Action => P.Expressions.Integer_Literal.Code'Access),
(Name => N.Code,
Kind => F.A_Named_Array_Aggregate,
Action => P.Expressions.Pos_Array_Aggregate.Code'Access),
(Name => N.Code,
Kind => F.A_Positional_Array_Aggregate,
Action => P.Expressions.Pos_Array_Aggregate.Code'Access),
(Name => N.Code,
Kind => F.An_In_Membership_Test,
Action => P.Expressions.Membership_Test.Code'Access),
(Name => N.Code,
Kind => F.A_Not_In_Membership_Test,
Action => P.Expressions.Membership_Test.Code'Access),
(Name => N.Code,
Kind => F.An_Or_Else_Short_Circuit,
Action => P.Expressions.Short_Circuit.Code'Access),
(Name => N.Code,
Kind => F.A_Record_Aggregate,
Action => P.Expressions.Record_Aggregate.Code'Access),
(Name => N.Code,
Kind => F.An_Extension_Aggregate,
Action => P.Expressions.Extension_Aggregate.Code'Access),
(Name => N.Code,
Kind => F.An_Array_Component_Association,
Action => P.Expressions.Array_Component_Association.Code'Access),
(Name => N.Code,
Kind => F.A_Record_Component_Association,
Action => P.Expressions.Record_Component_Association.Code'Access),
(Name => N.Code,
Kind => F.A_Null_Literal,
Action => P.Expressions.Null_Literal.Code'Access),
(Name => N.Code,
Kind => F.A_Selected_Component,
Action => P.Expressions.Selected_Components.Code'Access),
(Name => N.Code,
Kind => F.A_String_Literal,
Action => P.Expressions.String_Literal.Code'Access),
(Name => N.Code,
Kind => F.A_Type_Conversion,
Action => P.Expressions.Type_Conversion.Code'Access),
(Name => N.Code,
Kind => F.A_Qualified_Expression,
Action => P.Expressions.Type_Conversion.Code'Access),
(Name => N.Code,
Kind => F.A_Parenthesized_Expression,
Action => P.Expressions.Parenthesized.Code'Access),
(Name => N.Code,
Kind => F.An_If_Expression,
Action => P.Expressions.If_Expression.Code'Access),
(Name => N.Code,
Kind => F.A_Case_Expression,
Action => P.Expressions.Case_Expression.Code'Access),
(Name => N.Code,
Kind => F.An_Assignment_Statement,
Action => P.Statements.Assignment_Statement.Code'Access),
(Name => N.Code,
Kind => F.A_Block_Statement,
Action => P.Statements.Block_Statement.Code'Access),
(Name => N.Code,
Kind => F.A_Case_Statement,
Action => P.Statements.Case_Statement.Code'Access),
(Name => N.Code,
Kind => F.A_For_Loop_Statement,
Action => P.Statements.For_Loop_Statement.Code'Access),
(Name => N.Code,
Kind => F.A_Loop_Statement,
Action => P.Statements.Loop_Statement.Code'Access),
(Name => N.Code,
Kind => F.An_If_Statement,
Action => P.Statements.If_Statement.Code'Access),
(Name => N.Code,
Kind => F.A_Null_Statement,
Action => P.Common.Empty'Access),
(Name => N.Code,
Kind => F.A_Use_Type_Clause,
Action => P.Common.Empty'Access), -- Ignore
(Name => N.Code,
Kind => F.A_Use_All_Type_Clause,
Action => P.Common.Empty'Access), -- Ignore
(Name => N.Code,
Kind => F.A_Procedure_Call_Statement,
Action => P.Statements.Procedure_Call_Statement.Code'Access),
(Name => N.Code,
Kind => F.A_Return_Statement,
Action => P.Statements.Return_Statement.Code'Access),
(Name => N.Code,
Kind => F.An_Extended_Return_Statement,
Action => P.Statements.Extended_Return.Code'Access),
(Name => N.Code,
Kind => F.An_Exit_Statement,
Action => P.Statements.Exit_Statement.Code'Access),
(Name => N.Code,
Kind => F.A_While_Loop_Statement,
Action => P.Statements.While_Loop_Statement.Code'Access),
(Name => N.Code,
Kind => F.A_Raise_Statement,
Action => P.Statements.Raise_Statement.Code'Access),
(Name => N.Code,
Kind => F.A_With_Clause,
Action => P.Common.Empty'Access),
(Name => N.Condition,
Kind => F.An_Element_Iterator_Specification,
Action =>
P.Declarations.Element_Iterator_Specification.Condition'Access),
(Name => N.Condition,
Kind => F.A_Loop_Parameter_Specification,
Action =>
P.Declarations.Loop_Parameter_Specification.Condition'Access),
-- Assign
(Name => N.Assign,
Kind => F.A_Component_Declaration,
Action => P.Declarations.Component_Declaration.Assign'Access),
(Name => N.Assign,
Kind => F.A_Discriminant_Specification,
Action => P.Declarations.Component_Declaration.Assign'Access),
(Name => N.Assign,
Kind => F.A_Variant_Part,
Action => P.Definitions.Variant_Part.Assign'Access),
(Name => N.Assign,
Kind => F.A_Variant,
Action => P.Definitions.Variant.Assign'Access),
(Name => N.Assign,
Kind => F.A_Null_Component,
Action => P.Common.Empty'Access),
-- Bounds
(Name => N.Bounds,
Kind => F.A_Constant_Declaration,
Action => P.Declarations.Constant_Declarations.Bounds'Access),
(Name => N.Bounds,
Kind => F.A_Variable_Declaration,
Action => P.Declarations.Constant_Declarations.Bounds'Access),
(Name => N.Bounds,
Kind => F.A_Component_Declaration,
Action => P.Declarations.Constant_Declarations.Bounds'Access),
(Name => N.Bounds,
Kind => F.A_Component_Definition,
Action => P.Definitions.Component_Definition.Bounds'Access),
(Name => N.Bounds,
Kind => F.A_Subtype_Indication,
Action => P.Definitions.Subtype_Indication.Bounds'Access),
(Name => N.Bounds,
Kind => F.An_Index_Constraint,
Action => P.Definitions.Index_Constraint.Bounds'Access),
(Name => N.Bounds,
Kind => F.An_Identifier,
Action => P.Expressions.Identifiers.Bounds'Access),
(Name => N.Bounds,
Kind => F.A_Selected_Component,
Action => P.Expressions.Selected_Components.Bounds'Access),
(Name => N.Bounds,
Kind => F.An_Ordinary_Type_Declaration,
Action => P.Declarations.Ordinary_Type.Initialize'Access),
(Name => N.Bounds,
Kind => F.A_Constrained_Array_Definition,
Action => P.Definitions.Constrained_Array_Type.Bounds'Access),
(Name => N.Bounds,
Kind => F.An_Unconstrained_Array_Definition,
Action => P.Common.Empty'Access),
(Name => N.Bounds,
Kind => F.A_Return_Statement,
Action => P.Statements.Return_Statement.Bounds'Access),
(Name => N.Bounds,
Kind => F.A_Derived_Type_Definition,
Action => P.Definitions.Derived_Type.Bounds'Access),
(Name => N.Bounds,
Kind => F.A_Parameter_Association,
Action => P.Expressions.Parameter_Association.Bounds'Access),
(Name => N.Bounds,
Kind => F.A_Subtype_Declaration,
Action => P.Declarations.Ordinary_Type.Initialize'Access),
(Name => N.Bounds,
Kind => F.A_Record_Component_Association,
Action => P.Expressions.Record_Component_Association.Bounds'Access),
(Name => N.Bounds,
Kind => F.A_Qualified_Expression,
Action => P.Expressions.Type_Conversion.Bounds'Access),
(Name => N.Bounds,
Kind => F.An_Assignment_Statement,
Action => P.Statements.Assignment_Statement.Bounds'Access),
-- Initialize
(Name => N.Initialize,
Kind => F.A_Constant_Declaration,
Action => P.Declarations.Constant_Declarations.Initialize'Access),
(Name => N.Initialize,
Kind => F.A_Return_Constant_Specification,
Action => P.Declarations.Constant_Declarations.Initialize'Access),
(Name => N.Initialize,
Kind => F.A_Return_Variable_Specification,
Action => P.Declarations.Constant_Declarations.Initialize'Access),
(Name => N.Initialize,
Kind => F.A_Discriminant_Specification,
Action => P.Declarations.Constant_Declarations.Initialize'Access),
(Name => N.Initialize,
Kind => F.A_Component_Declaration,
Action => P.Declarations.Constant_Declarations.Initialize'Access),
(Name => N.Initialize,
Kind => F.A_Variable_Declaration,
Action => P.Declarations.Constant_Declarations.Initialize'Access),
(Name => N.Initialize,
Kind => F.An_Ordinary_Type_Declaration,
Action => P.Declarations.Ordinary_Type.Initialize'Access),
(Name => N.Initialize,
Kind => F.A_Subtype_Declaration,
Action => P.Declarations.Ordinary_Type.Initialize'Access),
(Name => N.Initialize,
Kind => F.A_Private_Extension_Declaration,
Action => P.Declarations.Private_Type.Initialize'Access),
(Name => N.Initialize,
Kind => F.A_Derived_Record_Extension_Definition,
Action => P.Definitions.Tagged_Record_Type.Initialize'Access),
(Name => N.Initialize,
Kind => F.A_Tagged_Record_Type_Definition,
Action => P.Definitions.Tagged_Record_Type.Initialize'Access),
(Name => N.Initialize,
Kind => F.A_Private_Type_Declaration,
Action => P.Declarations.Private_Type.Initialize'Access),
(Name => N.Initialize,
Kind => F.A_Loop_Parameter_Specification,
Action =>
P.Declarations.Loop_Parameter_Specification.Initialize'Access),
(Name => N.Initialize,
Kind => F.An_Element_Iterator_Specification,
Action =>
P.Declarations.Element_Iterator_Specification.Initialize'Access),
(Name => N.Initialize,
Kind => F.A_Component_Definition,
Action => P.Definitions.Component_Definition.Initialize'Access),
(Name => N.Initialize,
Kind => F.An_Access_To_Variable,
Action => P.Definitions.Access_To_Object.Initialize'Access),
(Name => N.Initialize,
Kind => F.An_Access_To_Constant,
Action => P.Definitions.Access_To_Object.Initialize'Access),
(Name => N.Initialize,
Kind => F.An_Anonymous_Access_To_Variable,
Action => P.Definitions.Access_To_Object.Initialize'Access),
(Name => N.Initialize,
Kind => F.An_Anonymous_Access_To_Constant,
Action => P.Definitions.Access_To_Object.Initialize'Access),
(Name => N.Initialize,
Kind => F.A_Constrained_Array_Definition,
Action => P.Definitions.Constrained_Array_Type.Initialize'Access),
(Name => N.Initialize,
Kind => F.A_Subtype_Indication,
Action => P.Definitions.Subtype_Indication.Initialize'Access),
(Name => N.Initialize,
Kind => F.An_Identifier,
Action => P.Expressions.Identifiers.Initialize'Access),
(Name => N.Initialize,
Kind => F.A_Selected_Component,
Action => P.Expressions.Selected_Components.Initialize'Access),
(Name => N.Initialize,
Kind => F.A_Derived_Type_Definition,
Action => P.Definitions.Derived_Type.Initialize'Access),
(Name => N.Initialize,
Kind => F.A_Record_Type_Definition,
Action => P.Definitions.Record_Type.Initialize'Access),
(Name => N.Initialize,
Kind => F.An_Enumeration_Type_Definition,
Action => P.Definitions.Enumeration_Type.Initialize'Access),
(Name => N.Initialize,
Kind => F.A_Signed_Integer_Type_Definition,
Action => P.Definitions.Enumeration_Type.Initialize'Access),
(Name => N.Initialize,
Kind => F.A_Modular_Type_Definition,
Action => P.Definitions.Enumeration_Type.Initialize'Access),
(Name => N.Initialize,
Kind => F.A_Floating_Point_Definition,
Action => P.Definitions.Enumeration_Type.Initialize'Access),
(Name => N.Lower,
Kind => F.A_Discrete_Simple_Expression_Range_As_Subtype_Definition,
Action => P.Definitions.Simple_Expression_Range.Lower'Access),
(Name => N.Upper,
Kind => F.A_Discrete_Simple_Expression_Range_As_Subtype_Definition,
Action => P.Definitions.Simple_Expression_Range.Upper'Access),
(Name => N.Lower,
Kind => F.A_Discrete_Simple_Expression_Range,
Action => P.Definitions.Simple_Expression_Range.Lower'Access),
(Name => N.Upper,
Kind => F.A_Discrete_Simple_Expression_Range,
Action => P.Definitions.Simple_Expression_Range.Upper'Access),
(Name => N.Lower,
Kind => F.A_Simple_Expression_Range,
Action => P.Definitions.Simple_Expression_Range.Lower'Access),
(Name => N.Upper,
Kind => F.A_Simple_Expression_Range,
Action => P.Definitions.Simple_Expression_Range.Upper'Access),
(Name => N.Upper,
Kind => F.A_Discrete_Subtype_Indication_As_Subtype_Definition,
Action => P.Definitions.Subtype_Indication.Bounds'Access),
(Name => N.Lower,
Kind => F.A_Discrete_Subtype_Indication_As_Subtype_Definition,
Action => P.Definitions.Subtype_Indication.Bounds'Access),
(Name => N.Upper,
Kind => F.A_Discrete_Range_Attribute_Reference_As_Subtype_Definition,
Action => P.Definitions.Range_Attribute.Upper'Access),
(Name => N.Lower,
Kind => F.A_Discrete_Range_Attribute_Reference_As_Subtype_Definition,
Action => P.Definitions.Range_Attribute.Lower'Access),
(Name => N.Upper,
Kind => F.A_Discrete_Range_Attribute_Reference,
Action => P.Definitions.Range_Attribute.Upper'Access),
(Name => N.Lower,
Kind => F.A_Discrete_Range_Attribute_Reference,
Action => P.Definitions.Range_Attribute.Lower'Access),
(Name => N.Upper,
Kind => F.An_Identifier,
Action => P.Expressions.Identifiers.Bounds'Access),
(Name => N.Lower,
Kind => F.An_Identifier,
Action => P.Expressions.Identifiers.Bounds'Access),
(Name => N.Upper,
Kind => F.An_Ordinary_Type_Declaration,
Action => P.Declarations.Ordinary_Type.Initialize'Access),
(Name => N.Lower,
Kind => F.An_Ordinary_Type_Declaration,
Action => P.Declarations.Ordinary_Type.Initialize'Access),
(Name => N.Lower,
Kind => F.An_Enumeration_Type_Definition,
Action => P.Definitions.Enumeration_Type.Lower'Access),
(Name => N.Upper,
Kind => F.An_Enumeration_Type_Definition,
Action => P.Definitions.Enumeration_Type.Upper'Access),
(Name => N.Lower,
Kind => F.A_Subtype_Declaration,
Action => P.Declarations.Ordinary_Type.Initialize'Access),
(Name => N.Upper,
Kind => F.A_Subtype_Declaration,
Action => P.Declarations.Ordinary_Type.Initialize'Access),
(Name => N.Lower,
Kind => F.A_Subtype_Indication,
Action => P.Definitions.Subtype_Indication.Bounds'Access),
(Name => N.Upper,
Kind => F.A_Subtype_Indication,
Action => P.Definitions.Subtype_Indication.Bounds'Access),
-- Intrinsic_Name
(Name => N.Intrinsic_Name,
Kind => F.A_Function_Declaration,
Action => P.Declarations.Function_Declarations.Intrinsic_Name'Access),
(Name => N.Intrinsic_Name,
Kind => F.A_Function_Renaming_Declaration,
Action => P.Declarations.Function_Renaming_Declaration
.Intrinsic_Name'Access),
(Name => N.Intrinsic_Name,
Kind => F.A_Procedure_Declaration,
Action => P.Declarations.Procedure_Declaration.Intrinsic_Name'Access),
(Name => N.Intrinsic_Name,
Kind => F.An_Identifier,
Action => P.Expressions.Identifiers.Intrinsic_Name'Access),
(Name => N.Intrinsic_Name,
Kind => F.A_Selected_Component,
Action => P.Expressions.Selected_Components
.Intrinsic_Name'Access),
-- Method_Name
(Name => N.Method_Name,
Kind => F.A_Defining_Identifier,
Action => P.Declarations.Defining_Names.Method_Name'Access),
(Name => N.Method_Name,
Kind => F.An_Identifier,
Action => P.Expressions.Identifiers.Code'Access),
(Name => N.Method_Name,
Kind => F.A_Selected_Component,
Action => P.Expressions.Selected_Components.Method_Name'Access),
-- Size
(Name => N.Size,
Kind => F.A_Subtype_Indication,
Action => P.Definitions.Subtype_Indication.Code'Access),
(Name => N.Size,
Kind => F.A_Subtype_Declaration,
Action => P.Declarations.Ordinary_Type.Initialize'Access),
(Name => N.Size,
Kind => F.An_Identifier,
Action => P.Expressions.Identifiers.Bounds'Access),
(Name => N.Size,
Kind => F.A_Selected_Component,
Action => P.Expressions.Selected_Components.Size'Access),
(Name => N.Size,
Kind => F.An_Ordinary_Type_Declaration,
Action => P.Declarations.Ordinary_Type.Initialize'Access),
(Name => N.Size,
Kind => F.A_Component_Declaration,
Action => P.Declarations.Constant_Declarations.Bounds'Access),
(Name => N.Size,
Kind => F.A_Component_Definition,
Action => P.Definitions.Component_Definition.Size'Access),
(Name => N.Size,
Kind => F.A_Derived_Type_Definition,
Action => P.Definitions.Derived_Type.Bounds'Access),
(Name => N.Size,
Kind => F.A_Floating_Point_Definition,
Action => P.Definitions.Float_Point.Size'Access),
(Name => N.Size,
Kind => F.A_Record_Type_Definition,
Action => P.Definitions.Record_Type.Size'Access),
(Name => N.Size,
Kind => F.A_Constrained_Array_Definition,
Action => P.Definitions.Constrained_Array_Type.Size'Access),
(Name => N.Size,
Kind => F.A_Modular_Type_Definition,
Action => P.Definitions.Modular.Size'Access),
(Name => N.Size,
Kind => F.A_Signed_Integer_Type_Definition,
Action => P.Definitions.Modular.Size'Access),
(Name => N.Size,
Kind => F.A_Private_Type_Declaration,
Action => P.Declarations.Private_Type.Initialize'Access),
-- Tag_Name
(Name => N.Tag_Name,
Kind => F.A_Subtype_Indication,
Action => P.Definitions.Subtype_Indication.Code'Access),
(Name => N.Tag_Name,
Kind => F.A_Selected_Component,
Action => P.Expressions.Selected_Components.Code'Access),
(Name => N.Tag_Name,
Kind => F.An_Identifier,
Action => P.Expressions.Identifiers.Initialize'Access),
(Name => N.Tag_Name,
Kind => F.An_Ordinary_Type_Declaration,
Action => P.Declarations.Ordinary_Type.Initialize'Access),
(Name => N.Tag_Name,
Kind => F.A_Private_Extension_Declaration,
Action => P.Declarations.Private_Type.Initialize'Access),
(Name => N.Tag_Name,
Kind => F.A_Private_Type_Declaration,
Action => P.Declarations.Private_Type.Initialize'Access),
(Name => N.Tag_Name,
Kind => F.A_Subtype_Declaration,
Action => P.Declarations.Ordinary_Type.Initialize'Access),
(Name => N.Tag_Name,
Kind => F.A_Derived_Record_Extension_Definition,
Action => P.Definitions.Tagged_Record_Type.Tag_Name'Access),
(Name => N.Tag_Name,
Kind => F.A_Tagged_Record_Type_Definition,
Action => P.Definitions.Tagged_Record_Type.Tag_Name'Access),
(Name => N.Tag_Name,
Kind => F.A_Limited_Interface,
Action => P.Definitions.Tagged_Record_Type.Tag_Name'Access),
(Name => N.Typed_Array_Item_Type,
Kind => F.An_Ordinary_Type_Declaration,
Action => P.Declarations.Ordinary_Type.Initialize'Access),
(Name => N.Typed_Array_Item_Type,
Kind => F.A_Derived_Type_Definition,
Action => P.Definitions.Derived_Type.Bounds'Access),
(Name => N.Typed_Array_Item_Type,
Kind => F.A_Subtype_Indication,
Action => P.Definitions.Subtype_Indication.Code'Access),
(Name => N.Typed_Array_Item_Type,
Kind => F.A_Floating_Point_Definition,
Action => P.Definitions.Float_Point.Typed_Array_Item_Type'Access),
(Name => N.Typed_Array_Item_Type,
Kind => F.A_Modular_Type_Definition,
Action => P.Definitions.Modular.Typed_Array_Item_Type'Access),
(Name => N.Typed_Array_Item_Type,
Kind => F.A_Signed_Integer_Type_Definition,
Action => P.Definitions.Signed.Typed_Array_Item_Type'Access),
(Name => N.Typed_Array_Item_Type,
Kind => F.A_Constrained_Array_Definition,
Action => P.Common.Empty'Access),
(Name => N.Typed_Array_Item_Type,
Kind => F.A_Record_Type_Definition,
Action => P.Common.Empty'Access),
(Name => N.Typed_Array_Item_Type,
Kind => F.An_Identifier,
Action => P.Expressions.Identifiers.Bounds'Access),
(Name => N.Typed_Array_Item_Type,
Kind => F.A_Private_Type_Declaration,
Action => P.Declarations.Private_Type.Initialize'Access),
(Name => N.Typed_Array_Item_Type,
Kind => F.A_Selected_Component,
Action => P.Expressions.Selected_Components
.Typed_Array_Item_Type'Access),
(Name => N.Typed_Array_Initialize,
Kind => F.A_Positional_Array_Aggregate,
Action => P.Expressions.Pos_Array_Aggregate
.Typed_Array_Initialize'Access),
(Name => N.Typed_Array_Initialize,
Kind => F.A_Record_Aggregate,
Action => P.Expressions.Record_Aggregate.Typed_Array_Initialize'Access)
);
Range_List : constant Range_Array :=
((N.Code,
F.An_And_Operator, F.A_Not_Operator,
P.Expressions.Identifiers.Code'Access),
(N.Code,
F.A_Defining_And_Operator, F.A_Defining_Not_Operator,
Action => P.Declarations.Defining_Names.Code'Access),
(N.Code,
F.An_Access_Attribute, F.An_Implementation_Defined_Attribute,
P.Expressions.Attribute_Reference.Code'Access),
(N.Intrinsic_Name,
F.An_Access_Attribute, F.An_Unknown_Attribute,
P.Expressions.Attribute_Reference.Intrinsic_Name'Access),
(N.Intrinsic_Name,
F.An_And_Operator, F.A_Not_Operator,
P.Expressions.Identifiers.Intrinsic_Name'Access),
(N.Method_Name,
F.A_Defining_And_Operator, F.A_Defining_Not_Operator,
Action => P.Declarations.Defining_Names.Method_Name'Access));
Integer_Actions : constant array (Positive range <>) of Integer_Action_Item
:=
((Name => N.Alignment,
Kind => F.A_Subtype_Indication,
Action => P.Definitions.Subtype_Indication.Alignment'Access),
(Name => N.Alignment,
Kind => F.An_Identifier,
Action => P.Expressions.Identifiers.Alignment'Access),
(Name => N.Alignment,
Kind => F.A_Selected_Component,
Action => P.Expressions.Selected_Components.Alignment'Access),
(Name => N.Alignment,
Kind => F.An_Ordinary_Type_Declaration,
Action => P.Declarations.Ordinary_Type.Alignment'Access),
(Name => N.Alignment,
Kind => F.A_Component_Declaration,
Action => P.Declarations.Component_Declaration.Alignment'Access),
(Name => N.Alignment,
Kind => F.A_Component_Definition,
Action => P.Definitions.Component_Definition.Alignment'Access),
(Name => N.Alignment,
Kind => F.A_Derived_Type_Definition,
Action => P.Definitions.Derived_Type.Alignment'Access),
(Name => N.Alignment,
Kind => F.A_Record_Type_Definition,
Action => P.Definitions.Record_Type.Alignment'Access),
(Name => N.Alignment,
Kind => F.A_Floating_Point_Definition,
Action => P.Definitions.Float_Point.Alignment'Access),
(Name => N.Alignment,
Kind => F.A_Modular_Type_Definition,
Action => P.Definitions.Modular.Alignment'Access),
(Name => N.Alignment,
Kind => F.A_Signed_Integer_Type_Definition,
Action => P.Definitions.Modular.Alignment'Access),
(Name => N.Alignment,
Kind => F.A_Private_Type_Declaration,
Action => P.Declarations.Private_Type.Alignment'Access),
(Name => N.Alignment,
Kind => F.A_Constrained_Array_Definition,
Action => P.Definitions.Constrained_Array_Type.Alignment'Access));
Boolean_Actions : constant array (Positive range <>) of Boolean_Action_Item
:=
((Name => N.Export,
Kind => F.A_Function_Body_Declaration,
Action => P.Declarations.Procedure_Body_Declarations.Export'Access),
(Name => N.Export,
Kind => F.A_Function_Declaration,
Action => P.Declarations.Function_Declarations.Export'Access),
(Name => N.Export,
Kind => F.A_Procedure_Body_Declaration,
Action => P.Declarations.Procedure_Body_Declarations.Export'Access),
(Name => N.Export,
Kind => F.A_Procedure_Declaration,
Action => P.Declarations.Function_Declarations.Export'Access),
(Kind => F.A_Parameter_Specification,
Name => N.Has_Simple_Output,
Action => P.Declarations.Constant_Declarations
.Has_Simple_Output'Access),
(Name => N.Has_Simple_Output,
Kind => F.A_Procedure_Body_Declaration,
Action => P.Declarations.Procedure_Body_Declarations
.Has_Simple_Output'Access),
(Name => N.Has_Simple_Output,
Kind => F.A_Function_Body_Declaration,
Action => P.Declarations.Procedure_Body_Declarations
.Has_Simple_Output'Access),
(Kind => F.A_Function_Declaration,
Name => N.Is_Dispatching,
Action => P.Declarations.Function_Declarations.Is_Dispatching'Access),
(Kind => F.A_Procedure_Declaration,
Name => N.Is_Dispatching,
Action => P.Declarations.Function_Declarations.Is_Dispatching'Access),
(Kind => F.A_Null_Procedure_Declaration,
Name => N.Is_Dispatching,
Action => P.Declarations.Function_Declarations.Is_Dispatching'Access),
(Kind => F.A_Function_Body_Declaration,
Name => N.Is_Dispatching,
Action =>
P.Declarations.Procedure_Body_Declarations.Is_Dispatching'Access),
(Kind => F.A_Procedure_Body_Declaration,
Name => N.Is_Dispatching,
Action =>
P.Declarations.Procedure_Body_Declarations.Is_Dispatching'Access),
(Kind => F.A_Selected_Component,
Name => N.Is_Dispatching,
Action => P.Expressions.Selected_Components.Is_Dispatching'Access),
(Kind => F.An_Identifier,
Name => N.Is_Dispatching,
Action => P.Expressions.Identifiers.Is_Dispatching'Access),
(Kind => F.A_Function_Renaming_Declaration,
Name => N.Is_Dispatching,
Action => P.Declarations.Function_Renaming_Declaration
.Is_Dispatching'Access),
(Kind => F.A_Procedure_Renaming_Declaration,
Name => N.Is_Dispatching,
Action => P.Declarations.Function_Renaming_Declaration
.Is_Dispatching'Access),
(Name => N.Is_Dispatching,
Kind => F.A_Procedure_Instantiation,
Action =>
P.Declarations.Subprogram_Instantiation.Is_Dispatching'Access),
(Name => N.Is_Dispatching,
Kind => F.A_Function_Instantiation,
Action =>
P.Declarations.Subprogram_Instantiation.Is_Dispatching'Access),
(Name => N.Is_Dispatching,
Kind => F.A_Generic_Procedure_Declaration,
Action => P.Common.False'Access),
(Name => N.Is_Dispatching,
Kind => F.A_Generic_Function_Declaration,
Action => P.Common.False'Access),
(Kind => F.An_Object_Renaming_Declaration,
Name => N.Is_Simple_Ref,
Action => P.Declarations.Constant_Declarations.Is_Simple_Ref'Access),
(Kind => F.A_Constant_Declaration,
Name => N.Is_Simple_Ref,
Action => P.Declarations.Constant_Declarations.Is_Simple_Ref'Access),
(Kind => F.A_Return_Constant_Specification,
Name => N.Is_Simple_Ref,
Action => P.Declarations.Constant_Declarations.Is_Simple_Ref'Access),
(Kind => F.A_Return_Variable_Specification,
Name => N.Is_Simple_Ref,
Action => P.Declarations.Constant_Declarations.Is_Simple_Ref'Access),
(Kind => F.A_Deferred_Constant_Declaration,
Name => N.Is_Simple_Ref,
Action => P.Declarations.Constant_Declarations.Is_Simple_Ref'Access),
(Kind => F.A_Component_Declaration,
Name => N.Is_Simple_Ref, -- The same as constant
Action => P.Declarations.Constant_Declarations.Is_Simple_Ref'Access),
(Kind => F.A_Discriminant_Specification,
Name => N.Is_Simple_Ref, -- The same as constant
Action => P.Declarations.Constant_Declarations.Is_Simple_Ref'Access),
(Kind => F.A_Variable_Declaration,
Name => N.Is_Simple_Ref,
Action => P.Declarations.Constant_Declarations.Is_Simple_Ref'Access),
(Kind => F.A_Parameter_Specification,
Name => N.Is_Simple_Ref,
Action => P.Declarations.Constant_Declarations.Is_Simple_Ref'Access),
(Kind => F.An_Ordinary_Type_Declaration,
Name => N.Is_Simple_Ref,
Action => P.Common.False'Access),
(Kind => F.A_Private_Type_Declaration,
Name => N.Is_Simple_Ref,
Action => P.Common.False'Access),
(Kind => F.A_Private_Extension_Declaration,
Name => N.Is_Simple_Ref,
Action => P.Common.False'Access),
(Kind => F.A_Subtype_Declaration,
Name => N.Is_Simple_Ref,
Action => P.Common.False'Access),
(Kind => F.A_Procedure_Declaration,
Name => N.Is_Simple_Ref,
Action => P.Common.False'Access),
(Kind => F.A_Function_Declaration,
Name => N.Is_Simple_Ref,
Action => P.Common.False'Access),
(Kind => F.A_Function_Renaming_Declaration,
Name => N.Is_Simple_Ref,
Action => P.Common.False'Access),
(Kind => F.A_Procedure_Renaming_Declaration,
Name => N.Is_Simple_Ref,
Action => P.Common.False'Access),
(Kind => F.A_Null_Procedure_Declaration,
Name => N.Is_Simple_Ref,
Action => P.Common.False'Access),
(Kind => F.A_Procedure_Instantiation,
Name => N.Is_Simple_Ref,
Action => P.Common.False'Access),
(Kind => F.A_Function_Instantiation,
Name => N.Is_Simple_Ref,
Action => P.Common.False'Access),
(Kind => F.An_Element_Iterator_Specification,
Name => N.Is_Simple_Ref,
Action => P.Common.False'Access),
(Kind => F.A_Loop_Parameter_Specification,
Name => N.Is_Simple_Ref,
Action => P.Common.False'Access),
(Kind => F.An_Integer_Number_Declaration,
Name => N.Is_Simple_Ref,
Action => P.Common.False'Access),
(Kind => F.A_Real_Number_Declaration,
Name => N.Is_Simple_Ref,
Action => P.Common.False'Access),
(Kind => F.An_Indexed_Component,
Name => N.Is_Simple_Ref,
Action => P.Expressions.Indexed_Component.Is_Simple_Ref'Access),
(Kind => F.A_Component_Definition,
Name => N.Is_Simple_Ref,
Action => P.Definitions.Component_Definition.Is_Simple_Ref'Access),
(Kind => F.A_Subtype_Indication,
Name => N.Is_Simple_Type,
Action => P.Definitions.Subtype_Indication.Is_Simple_Type'Access),
(Kind => F.A_Selected_Component,
Name => N.Is_Simple_Type,
Action => P.Expressions.Selected_Components.Is_Dispatching'Access),
(Kind => F.An_Identifier,
Name => N.Is_Simple_Type,
Action => P.Expressions.Identifiers.Is_Dispatching'Access),
(Kind => F.An_Ordinary_Type_Declaration,
Name => N.Is_Simple_Type,
Action => P.Declarations.Ordinary_Type.Is_Simple_Type'Access),
(Kind => F.A_Subtype_Declaration,
Name => N.Is_Simple_Type,
Action => P.Declarations.Ordinary_Type.Is_Simple_Type'Access),
(Kind => F.A_Private_Type_Declaration,
Name => N.Is_Simple_Type,
Action => P.Declarations.Private_Type.Is_Simple_Type'Access),
(Kind => F.A_Tagged_Incomplete_Type_Declaration,
Name => N.Is_Simple_Type,
Action => P.Common.False'Access),
(Kind => F.An_Incomplete_Type_Declaration,
Name => N.Is_Simple_Type,
Action => P.Declarations.Incomplete_Type.Is_Simple_Type'Access),
(Kind => F.An_Enumeration_Type_Definition,
Name => N.Is_Simple_Type,
Action => P.Definitions.Enumeration_Type.Is_Simple_Type'Access),
(Kind => F.A_Signed_Integer_Type_Definition,
Name => N.Is_Simple_Type,
Action => P.Definitions.Enumeration_Type.Is_Simple_Type'Access),
(Kind => F.A_Modular_Type_Definition,
Name => N.Is_Simple_Type,
Action => P.Definitions.Enumeration_Type.Is_Simple_Type'Access),
(Kind => F.A_Floating_Point_Definition,
Name => N.Is_Simple_Type,
Action => P.Definitions.Enumeration_Type.Is_Simple_Type'Access),
(Kind => F.A_Universal_Real_Definition,
Name => N.Is_Simple_Type,
Action => P.Common.True'Access),
(Kind => F.An_Access_To_Variable,
Name => N.Is_Simple_Type,
Action => P.Definitions.Enumeration_Type.Is_Simple_Type'Access),
(Kind => F.An_Access_To_Constant,
Name => N.Is_Simple_Type,
Action => P.Definitions.Enumeration_Type.Is_Simple_Type'Access),
(Kind => F.A_Record_Type_Definition,
Name => N.Is_Simple_Type,
Action => P.Definitions.Constrained_Array_Type.Is_Simple_Type'Access),
(Kind => F.A_Private_Extension_Declaration,
Name => N.Is_Simple_Type,
Action => P.Definitions.Constrained_Array_Type.Is_Simple_Type'Access),
(Kind => F.A_Derived_Type_Definition,
Name => N.Is_Simple_Type,
Action => P.Definitions.Derived_Type.Is_Simple_Type'Access),
(Kind => F.A_Derived_Record_Extension_Definition,
Name => N.Is_Simple_Type,
Action => P.Definitions.Tagged_Record_Type.Is_Simple_Type'Access),
(Kind => F.A_Tagged_Record_Type_Definition,
Name => N.Is_Simple_Type,
Action => P.Definitions.Tagged_Record_Type.Is_Simple_Type'Access),
(Kind => F.A_Limited_Interface,
Name => N.Is_Simple_Type,
Action => P.Definitions.Constrained_Array_Type.Is_Simple_Type'Access),
(Kind => F.A_Constrained_Array_Definition,
Name => N.Is_Simple_Type,
Action => P.Definitions.Constrained_Array_Type.Is_Simple_Type'Access),
(Kind => F.An_Unconstrained_Array_Definition,
Name => N.Is_Simple_Type,
Action => P.Definitions.Constrained_Array_Type.Is_Simple_Type'Access),
(Kind => F.A_Class_Attribute,
Name => N.Is_Simple_Type,
Action => P.Common.False'Access),
(Kind => F.A_Base_Attribute,
Name => N.Is_Simple_Type,
Action => P.Common.True'Access),
(Kind => F.An_Anonymous_Access_To_Constant,
Name => N.Is_Simple_Type,
Action => P.Common.True'Access),
(Kind => F.An_Anonymous_Access_To_Variable,
Name => N.Is_Simple_Type,
Action => P.Common.True'Access),
(Kind => F.A_Constrained_Array_Definition,
Name => N.Is_Array_Of_Simple,
Action => P.Definitions.Constrained_Array_Type
.Is_Array_Of_Simple'Access),
(Kind => F.An_Unconstrained_Array_Definition,
Name => N.Is_Array_Of_Simple,
Action => P.Definitions.Constrained_Array_Type
.Is_Array_Of_Simple'Access));
begin
for X of Action_List loop
Self.Text.Register_Calculator (X.Kind, X.Name, X.Action);
end loop;
for X of Range_List loop
for J in X.From .. X.To loop
Self.Text.Register_Calculator (J, X.Name, X.Action);
end loop;
end loop;
-- Call_Convention
Self.Call_Convention.Register_Calculator
(Name => N.Call_Convention,
Kind => F.A_Function_Call,
Action => P.Expressions.Function_Calls.Call_Convention'Access);
Self.Call_Convention.Register_Calculator
(Name => N.Call_Convention,
Kind => F.An_Identifier,
Action => P.Expressions.Identifiers.Call_Convention'Access);
Self.Call_Convention.Register_Calculator
(Name => N.Call_Convention,
Kind => F.A_Function_Declaration,
Action => P.Declarations.Function_Declarations.Call_Convention'Access);
Self.Call_Convention.Register_Calculator
(Name => N.Call_Convention,
Kind => F.A_Function_Renaming_Declaration,
Action => P.Declarations.Function_Renaming_Declaration
.Call_Convention'Access);
Self.Call_Convention.Register_Calculator
(Name => N.Call_Convention,
Kind => F.A_Procedure_Renaming_Declaration,
Action => P.Declarations.Function_Renaming_Declaration
.Call_Convention'Access);
Self.Call_Convention.Register_Calculator
(Name => N.Call_Convention,
Kind => F.A_Procedure_Declaration,
Action => P.Declarations.Procedure_Declaration.Call_Convention'Access);
Self.Call_Convention.Register_Calculator
(Name => N.Call_Convention,
Kind => F.A_Null_Procedure_Declaration,
Action => P.Declarations.Procedure_Declaration.Call_Convention'Access);
Self.Call_Convention.Register_Calculator
(Name => N.Call_Convention,
Kind => F.A_Selected_Component,
Action => P.Expressions.Selected_Components.Call_Convention'Access);
Self.Call_Convention.Register_Calculator
(Name => N.Call_Convention,
Kind => F.A_Procedure_Instantiation,
Action =>
P.Declarations.Subprogram_Instantiation.Call_Convention'Access);
Self.Call_Convention.Register_Calculator
(Name => N.Call_Convention,
Kind => F.A_Function_Instantiation,
Action =>
P.Declarations.Subprogram_Instantiation.Call_Convention'Access);
for X in F.An_And_Operator .. F.A_Not_Operator loop
Self.Call_Convention.Register_Calculator
(Kind => X,
Name => N.Call_Convention,
Action => P.Expressions.Identifiers.Call_Convention'Access);
end loop;
for X in F.An_Access_Attribute .. F.An_Unknown_Attribute loop
Self.Call_Convention.Register_Calculator
(Kind => X,
Name => N.Call_Convention,
Action => P.Expressions.Attribute_Reference.Call_Convention'Access);
end loop;
for X in F.Flat_Declaration_Kinds loop
Self.Boolean.Register_Calculator
(Kind => X,
Name => N.Inside_Package,
Action => P.Declarations.Inside_Package'Access);
end loop;
for X in F.An_And_Operator .. F.A_Not_Operator loop
Self.Boolean.Register_Calculator
(Kind => X,
Name => N.Is_Dispatching,
Action => P.Expressions.Identifiers.Is_Dispatching'Access);
end loop;
for X of Integer_Actions loop
Self.Integer.Register_Calculator
(Kind => X.Kind,
Name => X.Name,
Action => X.Action);
end loop;
for X of Boolean_Actions loop
Self.Boolean.Register_Calculator
(Kind => X.Kind,
Name => X.Name,
Action => X.Action);
end loop;
end Engines.Registry_All_Actions;
|
-- { dg-do compile }
procedure access2 is
Arr : array (1..10) of aliased Float;
type Acc is access all Float;
procedure Set (X : integer) is
Buffer: String (1..8);
for Buffer'address use Arr (4)'address;
begin
Arr (X) := 31.1415;
end;
function Get (C : Integer) return Acc is
begin
return Arr (C)'access;
end;
begin
null;
end;
|
with AUnit;
with AUnit.Simple_Test_Cases;
package kv.avm.Comm_Tests is
type Comm_Test_Case is abstract new AUnit.Simple_Test_Cases.Test_Case with
record
null;
end record;
procedure Set_Up (T : in out Comm_Test_Case);
procedure Tear_Down (T : in out Comm_Test_Case);
type Test_01 is new Comm_Test_Case with null record;
function Name(T : Test_01) return AUnit.Message_String;
procedure Run_Test(T : in out Test_01);
type Test_02 is new Comm_Test_Case with null record;
function Name(T : Test_02) return AUnit.Message_String;
procedure Run_Test(T : in out Test_02);
type Test_03 is new Comm_Test_Case with null record;
function Name(T : Test_03) return AUnit.Message_String;
procedure Run_Test(T : in out Test_03);
type Test_04 is new Comm_Test_Case with null record;
function Name(T : Test_04) return AUnit.Message_String;
procedure Run_Test(T : in out Test_04);
type Test_05 is new Comm_Test_Case with null record;
function Name(T : Test_05) return AUnit.Message_String;
procedure Run_Test(T : in out Test_05);
type Test_06 is new Comm_Test_Case with null record;
function Name(T : Test_06) return AUnit.Message_String;
procedure Run_Test(T : in out Test_06);
type Test_07 is new Comm_Test_Case with null record;
function Name(T : Test_07) return AUnit.Message_String;
procedure Run_Test(T : in out Test_07);
type Test_08 is new Comm_Test_Case with null record;
function Name(T : Test_08) return AUnit.Message_String;
procedure Run_Test(T : in out Test_08);
type Test_09 is new Comm_Test_Case with null record;
function Name(T : Test_09) return AUnit.Message_String;
procedure Run_Test(T : in out Test_09);
end kv.avm.Comm_Tests;
|
with Interfaces; use Interfaces;
with MIDI; use MIDI;
package MIDI_Synthesizer is
Samplerate : constant Float := 44100.0;
type Freq_Table is array (0 .. 127) of Float;
type Generator is record
PhaseIncrement : Float := 0.0;
PhaseAccumulator : Float := 0.0;
end record;
type ADSR_State is (Idle, Attack, Decay, Sustain, Release);
type ADSR is record
Attack : Float := 50.0 / Samplerate;
Decay : Float := 50.0 / Samplerate;
Sustain : Float := 0.9;
Release : Float := 1.2 / Samplerate;
Level : Float := 0.0;
State : ADSR_State := Idle;
end record;
type Synthesizer is new I_Event_Listener with record
MIDI_Parser : access Parser'Class;
MIDI_Notes : Freq_Table;
Generator0 : Generator;
ADSR0 : ADSR;
end record;
function Create_Synthesizer return access Synthesizer;
function Next_Sample (Self : in out Synthesizer) return Float;
procedure Parse_MIDI_Byte
(Self : in out Synthesizer;
Received : Unsigned_8);
overriding procedure Note_On
(Self : in out Synthesizer;
Channel : Unsigned_8;
Note : Unsigned_8;
Velocity : Unsigned_8);
overriding procedure Note_Off
(Self : in out Synthesizer;
Channel : Unsigned_8;
Note : Unsigned_8;
Velocity : Unsigned_8);
overriding procedure Control_Change
(Self : in out Synthesizer;
Channel : Unsigned_8;
Controller_Number : Unsigned_8;
Controller_Value : Unsigned_8);
end MIDI_Synthesizer;
|
-- Copyright 2019 Michael Casadevall <michael@casadevall.pro>
--
-- Permission is hereby granted, free of charge, to any person obtaining a copy
-- of this software and associated documentation files (the "Software"), to
-- deal in the Software without restriction, including without limitation the
-- rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
-- sell copies of the Software, and to permit persons to whom the Software is
-- furnished to do so, subject to the following conditions:
--
-- The above copyright notice and this permission notice shall be included in
-- all copies or substantial portions of the Software.
--
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
-- THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-- FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
-- DEALINGS IN THE SOFTWARE.
with Interfaces; use Interfaces;
package body DNSCatcher.DNS.Processor.RData.OPT_Parser is
-- EDNS is a pretty harry beast and incorporates a lot of stuff in ways
-- different from all other packets. As such parsing is quite a bit more
-- complicated than it is for other packet types.
procedure From_Parsed_RR
(This : in out Parsed_OPT_RData;
DNS_Header : DNS_Packet_Header;
Parsed_RR : Parsed_DNS_Resource_Record)
is
Top_Half_TTL : Interfaces.Unsigned_16;
Bottom_Half_TTL : Interfaces.Unsigned_16;
Full_RCode : Interfaces.Unsigned_16 := 0;
begin
-- RClass is the UDP requester size
This.Requester_UDP_Size := Parsed_RR.RClass;
--!pp off
-- TTL is subdivided into the following parts
-- 0..7 - Extended RCode
-- 8..16 - EDNS Version (must be zero)
--
-- The remainder is a 16-bit flags register set by
-- IANA. At the time of writing, only a single flag,
-- DO, is specified. The registry is available here:
-- https://www.iana.org/assignments/dns-parameters/dns-parameters.xhtml#dns-parameters-13
--
-- EDNS Flags:
-- 17 - DO
-- 18..32 - Must be zero
--
-- The horseshit however continues. Despite being a 32-bit int, it's
-- essentially two 16-bit ones, so we need to split this into a high
-- and low half and then compare it. My brain is already hurting ...
--!pp on
-- To get the full RCode, we need to take the 4-bit "normal" RCode, then
-- tack on the EDNS ones at the top for 12 bits total
-- Since we're network byte order, load the high half first from the
-- bottom bits
Top_Half_TTL :=
Interfaces.Unsigned_16
(Shift_Right (Interfaces.Unsigned_32 (Parsed_RR.TTL), 16));
Bottom_Half_TTL := Interfaces.Unsigned_16 (Parsed_RR.TTL and 16#ffff#);
-- 0..7 MSB is our RCode
Full_RCode := Top_Half_TTL and 16#ff00#;
Full_RCode := Shift_Right (Full_RCode, 4);
Full_RCode :=
Full_RCode or Interfaces.Unsigned_16 (DNS_Header.Response_Code);
This.Extended_RCode := RCodes'Enum_Val (Full_RCode);
-- Grab the EDNS version. It should be zero
This.EDNS_Version :=
Interfaces.C.Extensions.Unsigned_8 (Top_Half_TTL and 16#ff#);
-- Easiest way to fish out these bits is doing ANDs
This.DNSSEC_OK := (Bottom_Half_TTL and 16#8000#) /= 0;
This.Z_Section := Unsigned_15 (Bottom_Half_TTL and 16#7FF#);
-- Mask off top bits
end From_Parsed_RR;
function RData_To_String
(This : in Parsed_OPT_RData)
return String
is
begin
return "RCode: " & This.Extended_RCode'Image & " Version: " &
This.EDNS_Version'Image & " DO: " & This.DNSSEC_OK'Image & " Z: " &
This.Z_Section'Image;
end RData_To_String;
function Print_Packet
(This : in Parsed_OPT_RData)
return String
is
begin
return "OPT " & RData_To_String (This);
end Print_Packet;
-- Obliberate ourselves
procedure Delete (This : in out Parsed_OPT_RData) is
begin
null;
end Delete;
end DNSCatcher.DNS.Processor.RData.OPT_Parser;
|
-- reference:
-- http://www.opensource.apple.com/
-- source/boot/boot-132/i386/libsaio/hfs_compare.c
-- http://www.opensource.apple.com/
-- source/xnu/xnu-1504.15.3/bsd/vfs/vfs_utfconv.c
with Ada.Unchecked_Conversion;
with System.Address_To_Constant_Access_Conversions;
with System.Address_To_Named_Access_Conversions;
with System.Formatting;
with System.Once;
with System.Standard_Allocators;
with System.Storage_Elements;
with System.UTF_Conversions;
with C.hfs_casetables;
with C.vfs_utfconvdata;
package body System.Native_Directories.File_Names is
use type Formatting.Digit;
use type Storage_Elements.Integer_Address;
use type Storage_Elements.Storage_Offset;
use type UTF_Conversions.From_Status_Type;
use type UTF_Conversions.UCS_4;
use type C.signed_int;
use type C.size_t;
use type C.unsigned_char; -- implies u_int8_t
use type C.unsigned_short; -- implies u_int16_t
use type C.unsigned_short_ptr;
use type C.unsigned_int;
Flag : aliased Once.Flag := 0;
package unsigned_short_ptr_Conv is
new Address_To_Named_Access_Conversions (
C.unsigned_short,
C.unsigned_short_ptr);
package compressed_block_const_ptr_Conv is
new Address_To_Constant_Access_Conversions (
C.hfs_casetables.compressed_block,
C.hfs_casetables.compressed_block_const_ptr);
-- equivalent to UncompressStructure (hfs_compare.c)
function UncompressStructure (
bp : not null C.hfs_casetables.compressed_block_const_ptr;
count : C.signed_int;
size : C.signed_int)
return C.unsigned_short_ptr;
function UncompressStructure (
bp : not null C.hfs_casetables.compressed_block_const_ptr;
count : C.signed_int;
size : C.signed_int)
return C.unsigned_short_ptr
is
m_bp : not null C.hfs_casetables.compressed_block_const_ptr := bp;
l_out : constant C.unsigned_short_ptr :=
unsigned_short_ptr_Conv.To_Pointer (
Standard_Allocators.Allocate (
Storage_Elements.Storage_Offset (size)));
op : C.unsigned_short_ptr := l_out;
data : C.unsigned_short;
begin
for i in 0 .. count - 1 loop
data := m_bp.data;
for j in 0 .. m_bp.count - 1 loop
op.all := data;
op := unsigned_short_ptr_Conv.To_Pointer (
unsigned_short_ptr_Conv.To_Address (op)
+ Storage_Elements.Storage_Offset'(
C.unsigned_short'Size / Standard'Storage_Unit));
if m_bp.f_type = C.hfs_casetables.kTypeAscending then
data := data + 1;
elsif m_bp.f_type = C.hfs_casetables.kTypeAscending256 then
data := data + 256;
end if;
end loop;
m_bp := compressed_block_const_ptr_Conv.To_Pointer (
compressed_block_const_ptr_Conv.To_Address (m_bp)
+ Storage_Elements.Storage_Offset'(
C.hfs_casetables.compressed_block'Size
/ Standard'Storage_Unit));
end loop;
return l_out;
end UncompressStructure;
-- equivalent to InitCompareTables (hfs_compare.c)
procedure InitCompareTables;
procedure InitCompareTables is
begin
-- C.hfs_casetables.gCompareTable := UncompressStructure (
-- C.hfs_casetables.gCompareTableCompressed (0)'Access,
-- C.hfs_casetables.kCompareTableNBlocks,
-- C.hfs_casetables.kCompareTableDataSize);
C.hfs_casetables.gLowerCaseTable := UncompressStructure (
C.hfs_casetables.gLowerCaseTableCompressed (0)'Access,
C.hfs_casetables.kLowerCaseTableNBlocks,
C.hfs_casetables.kLowerCaseTableDataSize);
end InitCompareTables;
-- a part of FastUnicodeCompare (hfs_compare.c)
function To_Lower (Item : UTF_Conversions.UCS_4)
return UTF_Conversions.UCS_4;
function To_Lower (Item : UTF_Conversions.UCS_4)
return UTF_Conversions.UCS_4 is
begin
if Item > 16#ffff# then
return Item; -- out of gCompareTable
else
declare
subtype Fixed_unsigned_short_array is
C.unsigned_short_array (C.size_t);
type unsigned_short_array_const_ptr is
access constant Fixed_unsigned_short_array
with Convention => C;
function To_unsigned_short_array_const_ptr is
new Ada.Unchecked_Conversion (
C.unsigned_short_ptr,
unsigned_short_array_const_ptr);
Table : constant unsigned_short_array_const_ptr :=
To_unsigned_short_array_const_ptr (
C.hfs_casetables.gLowerCaseTable);
cn : constant C.unsigned_short := C.unsigned_short (Item);
temp : constant C.unsigned_short := Table (C.size_t (cn / 256));
begin
if temp /= 0 then
return UTF_Conversions.UCS_4 (
Table (C.size_t (temp + cn rem 256)));
else
return Item;
end if;
end;
end if;
end To_Lower;
-- equivalent to get_combining_class (vfs_utfconv.c)
function get_combining_class (character : C.vfs_utfconvdata.u_int16_t)
return C.vfs_utfconvdata.u_int8_t;
function get_combining_class (character : C.vfs_utfconvdata.u_int16_t)
return C.vfs_utfconvdata.u_int8_t
is
bitmap : C.vfs_utfconvdata.u_int8_t_array
renames C.vfs_utfconvdata.CFUniCharCombiningPropertyBitmap;
value : constant C.vfs_utfconvdata.u_int8_t :=
bitmap (C.size_t (C.Shift_Right (character, 8)));
begin
if value /= 0 then
return bitmap (
C.size_t (value) * 256 + C.size_t (character and 16#00FF#));
end if;
return 0;
end get_combining_class;
-- equivalent to unicode_decomposeable (vfs_utfconv.c)
function unicode_decomposeable (character : C.vfs_utfconvdata.u_int16_t)
return Boolean;
function unicode_decomposeable (character : C.vfs_utfconvdata.u_int16_t)
return Boolean
is
bitmap : C.vfs_utfconvdata.u_int8_t_array
renames C.vfs_utfconvdata.CFUniCharDecomposableBitmap;
Offset : C.size_t;
value : C.vfs_utfconvdata.u_int8_t;
begin
if character < 16#00C0# then
return False;
end if;
value := bitmap (C.size_t (C.Shift_Right (character, 8) and 16#FF#));
if value = 16#FF# then
return True;
elsif value /= 0 then
Offset := (C.size_t (value) - 1) * 32 + 256;
return (bitmap (Offset + C.size_t ((character and 16#FF#) / 8))
and C.Shift_Left (1, Natural (character rem 8))) /= 0;
end if;
return False;
end unicode_decomposeable;
RECURSIVE_DECOMPOSITION : constant := 2 ** 15;
function EXTRACT_COUNT (value : C.vfs_utfconvdata.u_int16_t)
return C.size_t;
function EXTRACT_COUNT (value : C.vfs_utfconvdata.u_int16_t)
return C.size_t is
begin
return C.size_t (C.Shift_Right (value, 12) and 16#0007#);
end EXTRACT_COUNT;
type unicode_mappings16 is record
key : C.vfs_utfconvdata.u_int16_t;
value : C.vfs_utfconvdata.u_int16_t;
end record;
pragma Suppress_Initialization (unicode_mappings16);
-- equivalent to getmappedvalue16 (vfs_utfconv.c)
function getmappedvalue16 (
-- theTable : Address; -- CFUniCharDecompositionTable
-- numElem : C.size_t; -- CFUniCharDecompositionTable'Length / 2
character : C.vfs_utfconvdata.u_int16_t)
return C.vfs_utfconvdata.u_int16_t;
function getmappedvalue16 (
-- theTable : Address;
-- numElem : C.size_t;
character : C.vfs_utfconvdata.u_int16_t)
return C.vfs_utfconvdata.u_int16_t
is
type unicode_mappings16_array is
array (C.size_t range
0 ..
C.vfs_utfconvdata.CFUniCharDecompositionTable'Length / 2 - 1) of
unicode_mappings16;
pragma Suppress_Initialization (unicode_mappings16_array);
table : unicode_mappings16_array;
for table'Address use
C.vfs_utfconvdata.CFUniCharDecompositionTable'Address;
numElem : constant :=
C.vfs_utfconvdata.CFUniCharDecompositionTable'Length / 2;
p, q, divider : C.size_t;
begin
if character < table (0).key
or else character > table (numElem - 1).key
then
return 0;
end if;
p := 0;
q := numElem - 1;
while p <= q loop
divider := p + (q - p) / 2; -- divide by 2
if character < table (divider).key then
q := divider - 1;
elsif character > table (divider).key then
p := divider + 1;
else
return table (divider).value;
end if;
end loop;
return 0;
end getmappedvalue16;
Expanding : constant := 4; -- max decomposed length of one code point
subtype decompose_buffer is
C.vfs_utfconvdata.u_int16_t_array (0 .. Expanding - 1);
type u_int16_t_ptr is access constant C.vfs_utfconvdata.u_int16_t;
package u_int16_t_ptr_Conv is
new Address_To_Constant_Access_Conversions (
C.vfs_utfconvdata.u_int16_t,
u_int16_t_ptr);
-- equivalent to unicode_recursive_decompose (vfs_utfconv.c)
procedure unicode_recursive_decompose (
character : C.vfs_utfconvdata.u_int16_t;
convertedChars : out decompose_buffer;
usedLength : out C.size_t);
procedure unicode_recursive_decompose (
character : C.vfs_utfconvdata.u_int16_t;
convertedChars : out decompose_buffer;
usedLength : out C.size_t)
is
value : C.vfs_utfconvdata.u_int16_t;
length : C.size_t;
firstChar : C.vfs_utfconvdata.u_int16_t;
theChar : aliased C.vfs_utfconvdata.u_int16_t;
bmpMappings : u_int16_t_ptr;
begin
value := getmappedvalue16 (
-- C.vfs_utfconvdata.CFUniCharDecompositionTable'Address,
-- C.vfs_utfconvdata.CFUniCharDecompositionTable'Length / 2,
character);
length := EXTRACT_COUNT (value);
firstChar := value and 16#0FFF#;
theChar := firstChar;
if length = 1 then
bmpMappings := theChar'Unchecked_Access;
else
bmpMappings := u_int16_t_ptr_Conv.To_Pointer (
C.vfs_utfconvdata.CFUniCharMultipleDecompositionTable'Address
+ Storage_Elements.Storage_Offset (firstChar)
* (
C.vfs_utfconvdata.u_int16_t'Size
/ Standard'Storage_Unit));
end if;
usedLength := 0;
if (value and RECURSIVE_DECOMPOSITION) /= 0 then
unicode_recursive_decompose (
bmpMappings.all,
convertedChars,
usedLength);
length := length - 1; -- Decrement for the first char
if usedLength = 0 then
return;
end if;
bmpMappings := u_int16_t_ptr_Conv.To_Pointer (
u_int16_t_ptr_Conv.To_Address (bmpMappings)
+ Storage_Elements.Storage_Offset'(
C.vfs_utfconvdata.u_int16_t'Size / Standard'Storage_Unit));
end if;
for I in 0 .. length - 1 loop
convertedChars (usedLength + I) := bmpMappings.all;
bmpMappings := u_int16_t_ptr_Conv.To_Pointer (
u_int16_t_ptr_Conv.To_Address (bmpMappings)
+ Storage_Elements.Storage_Offset'(
C.vfs_utfconvdata.u_int16_t'Size / Standard'Storage_Unit));
end loop;
usedLength := usedLength + length;
end unicode_recursive_decompose;
HANGUL_SBASE : constant := 16#AC00#;
HANGUL_LBASE : constant := 16#1100#;
HANGUL_VBASE : constant := 16#1161#;
HANGUL_TBASE : constant := 16#11A7#;
HANGUL_SCOUNT : constant := 11172;
-- HANGUL_LCOUNT : constant := 19;
HANGUL_VCOUNT : constant := 21;
HANGUL_TCOUNT : constant := 28;
HANGUL_NCOUNT : constant := HANGUL_VCOUNT * HANGUL_TCOUNT;
-- equivalent to unicode_decompose (vfs_utfconv.c)
procedure unicode_decompose (
character : C.vfs_utfconvdata.u_int16_t;
convertedChars : out decompose_buffer;
length : out C.size_t);
procedure unicode_decompose (
character : C.vfs_utfconvdata.u_int16_t;
convertedChars : out decompose_buffer;
length : out C.size_t) is
begin
if character >= HANGUL_SBASE
and then character <= HANGUL_SBASE + HANGUL_SCOUNT
then
declare
sindex : constant C.vfs_utfconvdata.u_int16_t :=
character - HANGUL_SBASE;
begin
if sindex rem HANGUL_TCOUNT /= 0 then
length := 3;
else
length := 2;
end if;
convertedChars (0) :=
sindex / HANGUL_NCOUNT + HANGUL_LBASE;
convertedChars (1) :=
(sindex rem HANGUL_NCOUNT) / HANGUL_TCOUNT + HANGUL_VBASE;
if length > 2 then
convertedChars (2) :=
(sindex rem HANGUL_TCOUNT) + HANGUL_TBASE;
end if;
end;
else
unicode_recursive_decompose (character, convertedChars, length);
end if;
end unicode_decompose;
type Stack_Type is array (Positive range <>) of UTF_Conversions.UCS_4;
pragma Suppress_Initialization (Stack_Type);
-- a part of utf8_decodestr (vfs_utfconv.c)
procedure Push (
S : String;
Index : in out Positive;
Stack : in out Stack_Type;
Top : in out Natural);
procedure Push (
S : String;
Index : in out Positive;
Stack : in out Stack_Type;
Top : in out Natural)
is
Last : Natural;
Code : UTF_Conversions.UCS_4;
From_Status : UTF_Conversions.From_Status_Type;
begin
UTF_Conversions.From_UTF_8 (
S (Index .. S'Last),
Last,
Code,
From_Status);
if From_Status /= UTF_Conversions.Success then
-- an illegal sequence is replaced to %XX at HFS
declare
Illegal : Character;
D : Character;
begin
Illegal := S (Index);
Stack (3) := Wide_Wide_Character'Pos ('%');
Formatting.Image (
Character'Pos (Illegal) / 16,
D,
Set => Formatting.Upper_Case);
Stack (2) := Character'Pos (D);
Formatting.Image (
Character'Pos (Illegal) rem 16,
D,
Set => Formatting.Upper_Case);
Stack (1) := Character'Pos (D);
Top := 3;
end;
Index := Index + 1;
else
Top := 0;
-- push trailing composable characters
while Last < S'Last loop
declare
Trailing_Last : Natural;
Trailing_Code : UTF_Conversions.UCS_4;
Trailing_From_Status : UTF_Conversions.From_Status_Type;
begin
UTF_Conversions.From_UTF_8 (
S (Last + 1 .. S'Last),
Trailing_Last,
Trailing_Code,
Trailing_From_Status);
if Trailing_From_Status = UTF_Conversions.Success
and then Trailing_Code < 16#FFFF#
and then get_combining_class (
C.vfs_utfconvdata.u_int16_t (Trailing_Code)) /= 0
then
Top := Top + 1;
Stack (Top) := Trailing_Code;
Last := Trailing_Last;
else
exit;
end if;
end;
end loop;
-- reverse trailing composable characters
for I in 0 .. Top / 2 - 1 loop
declare
Temp : constant UTF_Conversions.UCS_4 :=
Stack (Stack'First + I);
begin
Stack (Stack'First + I) := Stack (Top - I);
Stack (Top - I) := Temp;
end;
end loop;
-- push taken code
if Code < 16#FFFF#
and then unicode_decomposeable (C.vfs_utfconvdata.u_int16_t (Code))
then
declare
sequence : decompose_buffer;
count : C.size_t;
ucs_ch : C.vfs_utfconvdata.u_int16_t;
begin
unicode_decompose (
C.vfs_utfconvdata.u_int16_t (Code),
sequence,
count);
-- push decomposed sequence
for i in reverse 0 .. count - 1 loop
ucs_ch := sequence (i);
Top := Top + 1;
Stack (Top) := UTF_Conversions.UCS_4 (ucs_ch);
end loop;
end;
else
Top := Top + 1;
Stack (Top) := Code;
end if;
-- sort combining characters in Stack (1 .. Top - 1)
-- equivalent to priortysort (vfs_utfconv.c) except reverse order
for I in reverse 1 .. Top - 2 loop
declare
Item : constant UTF_Conversions.UCS_4 := Stack (I);
Item_Class : constant C.vfs_utfconvdata.u_int8_t :=
get_combining_class (
C.vfs_utfconvdata.u_int16_t (Stack (I)));
begin
for J in I + 1 .. Top - 1 loop
exit when get_combining_class (
C.vfs_utfconvdata.u_int16_t (Stack (J))) <= Item_Class;
Stack (J - 1) := Stack (J);
Stack (J) := Item;
end loop;
end;
end loop;
Index := Last + 1;
end if;
end Push;
function HFS_Compare (
Left, Right : String;
Case_Sensitive : Boolean)
return Integer;
function HFS_Compare (
Left, Right : String;
Case_Sensitive : Boolean)
return Integer
is
L_Stack : Stack_Type (1 .. Left'Length + Expanding - 1);
R_Stack : Stack_Type (1 .. Right'Length + Expanding - 1);
L_Top : Natural := 0;
R_Top : Natural := 0;
L_Index : Positive := Left'First;
R_Index : Positive := Right'First;
begin
loop
if L_Top = 0 then
if L_Index > Left'Last then
if R_Index > Right'Last and then R_Top = 0 then
return 0;
else
return -1; -- Left'Length < Right'Length
end if;
end if;
Push (Left, L_Index, L_Stack, L_Top);
end if;
if R_Top = 0 then
if R_Index > Right'Last then
return 1; -- Left'Length > Right'Length
end if;
Push (Right, R_Index, R_Stack, R_Top);
end if;
declare
L_Code : UTF_Conversions.UCS_4 := L_Stack (L_Top);
R_Code : UTF_Conversions.UCS_4 := R_Stack (R_Top);
begin
if not Case_Sensitive then
L_Code := To_Lower (L_Code);
R_Code := To_Lower (R_Code);
end if;
if L_Code /= R_Code then
if L_Code < R_Code then
return -1;
else
return 1;
end if;
end if;
end;
L_Top := L_Top - 1;
R_Top := R_Top - 1;
end loop;
end HFS_Compare;
-- implementation
function Equal_File_Names (
FS : Ada.Directories.Volumes.File_System;
Left, Right : String)
return Boolean is
begin
if Ada.Directories.Volumes.Is_HFS (FS) then
Once.Initialize (Flag'Access, InitCompareTables'Access);
return HFS_Compare (Left, Right,
Case_Sensitive => Ada.Directories.Volumes.Case_Sensitive (FS)) = 0;
else
return Left = Right;
end if;
end Equal_File_Names;
function Less_File_Names (
FS : Ada.Directories.Volumes.File_System;
Left, Right : String)
return Boolean is
begin
if Ada.Directories.Volumes.Is_HFS (FS) then
Once.Initialize (Flag'Access, InitCompareTables'Access);
return HFS_Compare (Left, Right,
Case_Sensitive => Ada.Directories.Volumes.Case_Sensitive (FS)) < 0;
else
return Left < Right;
end if;
end Less_File_Names;
end System.Native_Directories.File_Names;
|
-- MIT License
-- Copyright (c) 2021 Stephen Merrony
-- Permission is hereby granted, free of charge, to any person obtaining a copy
-- of this software and associated documentation files (the "Software"), to deal
-- in the Software without restriction, including without limitation the rights
-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-- copies of the Software, and to permit persons to whom the Software is
-- furnished to do so, subject to the following conditions:
-- The above copyright notice and this permission notice shall be included in all
-- copies or substantial portions of the Software.
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-- SOFTWARE.
with Ada.Streams.Stream_IO; use Ada.Streams.Stream_IO;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
with DG_Types; use DG_Types;
package body Debug_Logs is
protected body Loggers is
procedure Init is
begin
for L in Logs'Range loop
First_Line(L) := 1;
Last_Line(L) := 1;
end loop;
end Init;
procedure Debug_Logs_Dump (Directory : in String) is
Write_Path : Unbounded_String;
Write_File : File_Type;
This_Line : Positive;
begin
for L in Logs'Range loop
if Last_Line(L) /= 1 then -- ignore unused or empty logs
Write_Path := Directory & "/" & Log_Filenames(L);
Create (Write_File, Out_File, To_String (Write_Path));
This_Line := First_Line(L);
loop
String'Write (Stream(Write_File), To_String(Log_Array(L, This_Line) & Dasher_NL));
This_Line := This_Line + 1;
if This_Line = Num_Lines then
This_Line := 1;
end if;
exit when This_Line = Last_Line(L) + 1;
end loop;
-- String'Write (Stream(Write_File), To_String(Log_Array(L, This_Line) & Dasher_NL));
String'Write (Stream(Write_File), ">>> Debug Log Ends <<<");
Close (Write_File);
end if;
end loop;
end Debug_Logs_Dump;
-- Debug_Print doesn't print anything! It stores the log message
-- in array-backed circular arrays written out when debugLogsDump() is invoked.
-- This proc can be called very often, KISS...
procedure Debug_Print (Log : in Logs; Msg : in String) is
begin
Last_Line(Log) := Last_Line(Log) + 1;
if Last_Line(Log) >= Num_Lines then
Last_Line(Log) := 1; -- wrap-around
end if;
-- has the tail hit the head of the circular buffer?
if Last_Line(Log) = First_Line(Log) then
First_Line(Log) := First_Line(Log) + 1; -- advance the head pointer
if First_Line(Log) = Num_Lines then
First_Line(Log) := 1; -- wrap-around
end if;
end if;
Log_Array(Log, Last_Line(Log)) := To_Unbounded_String(Msg);
end Debug_Print;
end Loggers;
end Debug_Logs; |
------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Ada Modeling Framework --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2012, Vadim Godunko <vgodunko@gmail.com> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
-- This file is generated, don't edit it.
------------------------------------------------------------------------------
with AMF.Utp.Coding_Rules;
with AMF.Utp.Data_Partitions;
with AMF.Utp.Data_Pools;
with AMF.Utp.Data_Selectors;
with AMF.Utp.Default_Applications;
with AMF.Utp.Defaults;
with AMF.Utp.Determ_Alts;
with AMF.Utp.Finish_Actions;
with AMF.Utp.Get_Timezone_Actions;
with AMF.Utp.Literal_Anies;
with AMF.Utp.Literal_Any_Or_Nulls;
with AMF.Utp.Log_Actions;
with AMF.Utp.Managed_Elements;
with AMF.Utp.Read_Timer_Actions;
with AMF.Utp.SUTs;
with AMF.Utp.Set_Timezone_Actions;
with AMF.Utp.Start_Timer_Actions;
with AMF.Utp.Stop_Timer_Actions;
with AMF.Utp.Test_Cases;
with AMF.Utp.Test_Components;
with AMF.Utp.Test_Contexts;
with AMF.Utp.Test_Log_Applications;
with AMF.Utp.Test_Logs;
with AMF.Utp.Test_Objectives;
with AMF.Utp.Test_Suites;
with AMF.Utp.Time_Out_Actions;
with AMF.Utp.Time_Out_Messages;
with AMF.Utp.Time_Outs;
with AMF.Utp.Timer_Running_Actions;
with AMF.Utp.Validation_Actions;
package AMF.Factories.Utp_Factories is
pragma Preelaborate;
type Utp_Factory is limited interface
and AMF.Factories.Factory;
type Utp_Factory_Access is access all Utp_Factory'Class;
for Utp_Factory_Access'Storage_Size use 0;
not overriding function Create_Coding_Rule
(Self : not null access Utp_Factory)
return AMF.Utp.Coding_Rules.Utp_Coding_Rule_Access is abstract;
not overriding function Create_Data_Partition
(Self : not null access Utp_Factory)
return AMF.Utp.Data_Partitions.Utp_Data_Partition_Access is abstract;
not overriding function Create_Data_Pool
(Self : not null access Utp_Factory)
return AMF.Utp.Data_Pools.Utp_Data_Pool_Access is abstract;
not overriding function Create_Data_Selector
(Self : not null access Utp_Factory)
return AMF.Utp.Data_Selectors.Utp_Data_Selector_Access is abstract;
not overriding function Create_Default
(Self : not null access Utp_Factory)
return AMF.Utp.Defaults.Utp_Default_Access is abstract;
not overriding function Create_Default_Application
(Self : not null access Utp_Factory)
return AMF.Utp.Default_Applications.Utp_Default_Application_Access is abstract;
not overriding function Create_Determ_Alt
(Self : not null access Utp_Factory)
return AMF.Utp.Determ_Alts.Utp_Determ_Alt_Access is abstract;
not overriding function Create_Finish_Action
(Self : not null access Utp_Factory)
return AMF.Utp.Finish_Actions.Utp_Finish_Action_Access is abstract;
not overriding function Create_Get_Timezone_Action
(Self : not null access Utp_Factory)
return AMF.Utp.Get_Timezone_Actions.Utp_Get_Timezone_Action_Access is abstract;
not overriding function Create_Literal_Any
(Self : not null access Utp_Factory)
return AMF.Utp.Literal_Anies.Utp_Literal_Any_Access is abstract;
not overriding function Create_Literal_Any_Or_Null
(Self : not null access Utp_Factory)
return AMF.Utp.Literal_Any_Or_Nulls.Utp_Literal_Any_Or_Null_Access is abstract;
not overriding function Create_Log_Action
(Self : not null access Utp_Factory)
return AMF.Utp.Log_Actions.Utp_Log_Action_Access is abstract;
not overriding function Create_Managed_Element
(Self : not null access Utp_Factory)
return AMF.Utp.Managed_Elements.Utp_Managed_Element_Access is abstract;
not overriding function Create_Read_Timer_Action
(Self : not null access Utp_Factory)
return AMF.Utp.Read_Timer_Actions.Utp_Read_Timer_Action_Access is abstract;
not overriding function Create_SUT
(Self : not null access Utp_Factory)
return AMF.Utp.SUTs.Utp_SUT_Access is abstract;
not overriding function Create_Set_Timezone_Action
(Self : not null access Utp_Factory)
return AMF.Utp.Set_Timezone_Actions.Utp_Set_Timezone_Action_Access is abstract;
not overriding function Create_Start_Timer_Action
(Self : not null access Utp_Factory)
return AMF.Utp.Start_Timer_Actions.Utp_Start_Timer_Action_Access is abstract;
not overriding function Create_Stop_Timer_Action
(Self : not null access Utp_Factory)
return AMF.Utp.Stop_Timer_Actions.Utp_Stop_Timer_Action_Access is abstract;
not overriding function Create_Test_Case
(Self : not null access Utp_Factory)
return AMF.Utp.Test_Cases.Utp_Test_Case_Access is abstract;
not overriding function Create_Test_Component
(Self : not null access Utp_Factory)
return AMF.Utp.Test_Components.Utp_Test_Component_Access is abstract;
not overriding function Create_Test_Context
(Self : not null access Utp_Factory)
return AMF.Utp.Test_Contexts.Utp_Test_Context_Access is abstract;
not overriding function Create_Test_Log
(Self : not null access Utp_Factory)
return AMF.Utp.Test_Logs.Utp_Test_Log_Access is abstract;
not overriding function Create_Test_Log_Application
(Self : not null access Utp_Factory)
return AMF.Utp.Test_Log_Applications.Utp_Test_Log_Application_Access is abstract;
not overriding function Create_Test_Objective
(Self : not null access Utp_Factory)
return AMF.Utp.Test_Objectives.Utp_Test_Objective_Access is abstract;
not overriding function Create_Test_Suite
(Self : not null access Utp_Factory)
return AMF.Utp.Test_Suites.Utp_Test_Suite_Access is abstract;
not overriding function Create_Time_Out
(Self : not null access Utp_Factory)
return AMF.Utp.Time_Outs.Utp_Time_Out_Access is abstract;
not overriding function Create_Time_Out_Action
(Self : not null access Utp_Factory)
return AMF.Utp.Time_Out_Actions.Utp_Time_Out_Action_Access is abstract;
not overriding function Create_Time_Out_Message
(Self : not null access Utp_Factory)
return AMF.Utp.Time_Out_Messages.Utp_Time_Out_Message_Access is abstract;
not overriding function Create_Timer_Running_Action
(Self : not null access Utp_Factory)
return AMF.Utp.Timer_Running_Actions.Utp_Timer_Running_Action_Access is abstract;
not overriding function Create_Validation_Action
(Self : not null access Utp_Factory)
return AMF.Utp.Validation_Actions.Utp_Validation_Action_Access is abstract;
end AMF.Factories.Utp_Factories;
|
with Ada.Text_IO; use Ada.Text_IO;
-- Permuter deux caractères lus au clavier
procedure Permuter_Caracteres is
C1, C2: Character; -- Entier lu au clavier dont on veut connaître le signe
Temp: Character; -- Charactere utilisé pour la permutation
begin
-- Demander les deux caractères C1 et C2
Get (C1);
Skip_Line;
Get (C2);
Skip_Line;
-- Afficher C1
Put_Line ("C1 = '" & C1 & "'");
-- Afficher C2
Put_Line ("C2 = '" & C2 & "'");
-- Permuter C1 et C2
Temp := C1;
C1 := C2;
C2 := Temp;
-- Afficher C1
Put_Line ("C1 = '" & C1 & "'");
-- Afficher C2
Put_Line ("C2 = '" & C2 & "'");
end Permuter_Caracteres;
|
-- SPDX-License-Identifier: Apache-2.0
--
-- Copyright (c) 2016 onox <denkpadje@gmail.com>
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
with GL.Objects.Buffers;
with GL.Types.Indirect;
with Orka.Types;
package Orka.Rendering.Buffers is
pragma Preelaborate;
subtype Storage_Bits is GL.Objects.Buffers.Storage_Bits;
use GL.Types;
use all type Orka.Types.Element_Type;
-----------------------------------------------------------------------------
type Bindable_Buffer is interface;
type Indexed_Buffer_Target is (Atomic_Counter, Shader_Storage, Uniform);
-- Buffer targets that can be read/written in shaders
type Buffer_Target is
(Index, Dispatch_Indirect, Draw_Indirect, Parameter, Pixel_Pack, Pixel_Unpack, Query);
procedure Bind
(Object : Bindable_Buffer;
Target : Indexed_Buffer_Target;
Index : Natural) is abstract;
-- Bind the buffer object to the binding point at the given index of
-- the target
procedure Bind
(Object : Bindable_Buffer;
Target : Buffer_Target) is abstract;
-- Bind the buffer object to the target
function Length (Object : Bindable_Buffer) return Natural is abstract;
-----------------------------------------------------------------------------
type Buffer (Kind : Types.Element_Type) is new Bindable_Buffer with private;
function Create_Buffer
(Flags : Storage_Bits;
Kind : Types.Element_Type;
Length : Natural) return Buffer;
-----------------------------------------------------------------------------
function Create_Buffer
(Flags : Storage_Bits;
Data : Half_Array) return Buffer;
function Create_Buffer
(Flags : Storage_Bits;
Data : Single_Array) return Buffer;
function Create_Buffer
(Flags : Storage_Bits;
Data : Double_Array) return Buffer;
function Create_Buffer
(Flags : Storage_Bits;
Data : Int_Array) return Buffer;
function Create_Buffer
(Flags : Storage_Bits;
Data : UInt_Array) return Buffer;
function Create_Buffer
(Flags : Storage_Bits;
Data : Orka.Types.Singles.Vector4_Array) return Buffer;
function Create_Buffer
(Flags : Storage_Bits;
Data : Orka.Types.Singles.Matrix4_Array) return Buffer;
function Create_Buffer
(Flags : Storage_Bits;
Data : Orka.Types.Doubles.Vector4_Array) return Buffer;
function Create_Buffer
(Flags : Storage_Bits;
Data : Orka.Types.Doubles.Matrix4_Array) return Buffer;
function Create_Buffer
(Flags : Storage_Bits;
Data : Indirect.Arrays_Indirect_Command_Array) return Buffer;
function Create_Buffer
(Flags : Storage_Bits;
Data : Indirect.Elements_Indirect_Command_Array) return Buffer;
function Create_Buffer
(Flags : Storage_Bits;
Data : Indirect.Dispatch_Indirect_Command_Array) return Buffer;
-----------------------------------------------------------------------------
overriding
function Length (Object : Buffer) return Natural
with Inline;
overriding
procedure Bind (Object : Buffer; Target : Indexed_Buffer_Target; Index : Natural);
-- Bind the buffer object to the binding point at the given index of
-- the target
overriding
procedure Bind (Object : Buffer; Target : Buffer_Target);
-- Bind the buffer object to the target
-----------------------------------------------------------------------------
procedure Set_Data
(Object : Buffer;
Data : Half_Array;
Offset : Natural := 0)
with Pre => Object.Kind = Half_Type and Offset + Data'Length <= Object.Length;
procedure Set_Data
(Object : Buffer;
Data : Single_Array;
Offset : Natural := 0)
with Pre => Object.Kind = Single_Type and Offset + Data'Length <= Object.Length;
procedure Set_Data
(Object : Buffer;
Data : Double_Array;
Offset : Natural := 0)
with Pre => Object.Kind = Double_Type and Offset + Data'Length <= Object.Length;
procedure Set_Data
(Object : Buffer;
Data : Int_Array;
Offset : Natural := 0)
with Pre => Object.Kind = Int_Type and Offset + Data'Length <= Object.Length;
procedure Set_Data
(Object : Buffer;
Data : UInt_Array;
Offset : Natural := 0)
with Pre => Object.Kind = UInt_Type and Offset + Data'Length <= Object.Length;
procedure Set_Data
(Object : Buffer;
Data : Orka.Types.Singles.Vector4_Array;
Offset : Natural := 0)
with Pre => Object.Kind = Single_Vector_Type and Offset + Data'Length <= Object.Length;
procedure Set_Data
(Object : Buffer;
Data : Orka.Types.Singles.Matrix4_Array;
Offset : Natural := 0)
with Pre => Object.Kind = Single_Matrix_Type and Offset + Data'Length <= Object.Length;
procedure Set_Data
(Object : Buffer;
Data : Orka.Types.Doubles.Vector4_Array;
Offset : Natural := 0)
with Pre => Object.Kind = Double_Vector_Type and Offset + Data'Length <= Object.Length;
procedure Set_Data
(Object : Buffer;
Data : Orka.Types.Doubles.Matrix4_Array;
Offset : Natural := 0)
with Pre => Object.Kind = Double_Matrix_Type and Offset + Data'Length <= Object.Length;
procedure Set_Data
(Object : Buffer;
Data : Indirect.Arrays_Indirect_Command_Array;
Offset : Natural := 0)
with Pre => Object.Kind = Arrays_Command_Type and Offset + Data'Length <= Object.Length;
procedure Set_Data
(Object : Buffer;
Data : Indirect.Elements_Indirect_Command_Array;
Offset : Natural := 0)
with Pre => Object.Kind = Elements_Command_Type and Offset + Data'Length <= Object.Length;
procedure Set_Data
(Object : Buffer;
Data : Indirect.Dispatch_Indirect_Command_Array;
Offset : Natural := 0)
with Pre => Object.Kind = Dispatch_Command_Type and Offset + Data'Length <= Object.Length;
-----------------------------------------------------------------------------
procedure Get_Data
(Object : Buffer;
Data : in out Half_Array;
Offset : Natural := 0)
with Pre => Object.Kind = Half_Type and Offset + Data'Length <= Object.Length;
procedure Get_Data
(Object : Buffer;
Data : in out Single_Array;
Offset : Natural := 0)
with Pre => Object.Kind = Single_Type and Offset + Data'Length <= Object.Length;
procedure Get_Data
(Object : Buffer;
Data : in out Double_Array;
Offset : Natural := 0)
with Pre => Object.Kind = Double_Type and Offset + Data'Length <= Object.Length;
procedure Get_Data
(Object : Buffer;
Data : in out Int_Array;
Offset : Natural := 0)
with Pre => Object.Kind = Int_Type and Offset + Data'Length <= Object.Length;
procedure Get_Data
(Object : Buffer;
Data : in out UInt_Array;
Offset : Natural := 0)
with Pre => Object.Kind = UInt_Type and Offset + Data'Length <= Object.Length;
-----------------------------------------------------------------------------
procedure Get_Data
(Object : Buffer;
Data : in out Orka.Types.Singles.Vector4_Array;
Offset : Natural := 0)
with Pre => Object.Kind = Single_Vector_Type and Offset + Data'Length <= Object.Length;
procedure Get_Data
(Object : Buffer;
Data : in out Orka.Types.Singles.Matrix4_Array;
Offset : Natural := 0)
with Pre => Object.Kind = Single_Matrix_Type and Offset + Data'Length <= Object.Length;
procedure Get_Data
(Object : Buffer;
Data : in out Orka.Types.Doubles.Vector4_Array;
Offset : Natural := 0)
with Pre => Object.Kind = Double_Vector_Type and Offset + Data'Length <= Object.Length;
procedure Get_Data
(Object : Buffer;
Data : in out Orka.Types.Doubles.Matrix4_Array;
Offset : Natural := 0)
with Pre => Object.Kind = Double_Matrix_Type and Offset + Data'Length <= Object.Length;
-----------------------------------------------------------------------------
procedure Clear_Data
(Object : Buffer;
Data : Int_Array)
with Pre => Object.Kind = Int_Type
and Data'Length in 1 .. 4
and Object.Length mod Data'Length = 0;
procedure Clear_Data
(Object : Buffer;
Data : UInt_Array)
with Pre => Object.Kind = UInt_Type
and Data'Length in 1 .. 4
and Object.Length mod Data'Length = 0;
procedure Clear_Data
(Object : Buffer;
Data : Single_Array)
with Pre => Object.Kind = Single_Type
and Data'Length in 1 .. 4
and Object.Length mod Data'Length = 0;
procedure Clear_Data
(Object : Buffer;
Data : Orka.Types.Singles.Vector4)
with Pre => Object.Kind = Single_Vector_Type
or else (Object.Kind = Single_Type and Object.Length mod 4 = 0);
-----------------------------------------------------------------------------
procedure Copy_Data
(Object : Buffer;
Target : Buffer)
with Pre => Object.Kind = Target.Kind and then Object.Length = Target.Length;
private
type Buffer (Kind : Types.Element_Type) is new Bindable_Buffer with record
Buffer : GL.Objects.Buffers.Buffer;
Length : Natural;
end record;
end Orka.Rendering.Buffers;
|
-- SPDX-License-Identifier: Apache-2.0
--
-- Copyright (c) 2021 onox <denkpadje@gmail.com>
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
with System;
with Ada.Unchecked_Conversion;
with Event_Device.Input_Dev;
package body Event_Device is
subtype Unused_Type is Boolean range False .. False;
type Internal_Key_Features is record
Button_South : Boolean := False;
Button_East : Boolean := False;
Button_North : Boolean := False;
Button_West : Boolean := False;
Button_Trigger_Left_1 : Boolean := False;
Button_Trigger_Right_1 : Boolean := False;
Button_Trigger_Left_2 : Boolean := False;
Button_Trigger_Right_2 : Boolean := False;
Button_Select : Boolean := False;
Button_Start : Boolean := False;
Button_Mode : Boolean := False;
Button_Thumb_Left : Boolean := False;
Button_Thumb_Right : Boolean := False;
Unused : Unused_Type := False;
end record;
for Internal_Key_Features use record
Button_South at 0 range 304 .. 304;
Button_East at 0 range 305 .. 305;
Button_North at 0 range 307 .. 307;
Button_West at 0 range 308 .. 308;
Button_Trigger_Left_1 at 0 range 310 .. 310;
Button_Trigger_Right_1 at 0 range 311 .. 311;
Button_Trigger_Left_2 at 0 range 312 .. 312;
Button_Trigger_Right_2 at 0 range 313 .. 313;
Button_Select at 0 range 314 .. 314;
Button_Start at 0 range 315 .. 315;
Button_Mode at 0 range 316 .. 316;
Button_Thumb_Left at 0 range 317 .. 317;
Button_Thumb_Right at 0 range 318 .. 318;
Unused at 0 range 319 .. 319;
end record;
for Internal_Key_Features'Size use 320;
type Internal_Relative_Axis_Features is record
X : Boolean := False;
Y : Boolean := False;
Z : Boolean := False;
Rx : Boolean := False;
Ry : Boolean := False;
Rz : Boolean := False;
Horizontal_Wheel : Boolean := False;
Diagonal : Boolean := False;
Wheel : Boolean := False;
Misc : Boolean := False;
Wheel_High_Res : Boolean := False;
Horizontal_Wheel_High_Res : Boolean := False;
end record;
for Internal_Relative_Axis_Features use record
X at 0 range 0 .. 0;
Y at 0 range 1 .. 1;
Z at 0 range 2 .. 2;
Rx at 0 range 3 .. 3;
Ry at 0 range 4 .. 4;
Rz at 0 range 5 .. 5;
Horizontal_Wheel at 0 range 6 .. 6;
Diagonal at 0 range 7 .. 7;
Wheel at 0 range 8 .. 8;
Misc at 0 range 9 .. 9;
Wheel_High_Res at 0 range 11 .. 11;
Horizontal_Wheel_High_Res at 0 range 12 .. 12;
end record;
for Internal_Relative_Axis_Features'Size use Relative_Axis_Info_Kind'Size;
type Internal_Absolute_Axis_Features is record
X : Boolean := False;
Y : Boolean := False;
Z : Boolean := False;
Rx : Boolean := False;
Ry : Boolean := False;
Rz : Boolean := False;
Throttle : Boolean := False;
Rudder : Boolean := False;
Wheel : Boolean := False;
Gas : Boolean := False;
Brake : Boolean := False;
Hat_0X : Boolean := False;
Hat_0Y : Boolean := False;
Hat_1X : Boolean := False;
Hat_1Y : Boolean := False;
Hat_2X : Boolean := False;
Hat_2Y : Boolean := False;
Hat_3X : Boolean := False;
Hat_3Y : Boolean := False;
Pressure : Boolean := False;
Distance : Boolean := False;
Tilt_X : Boolean := False;
Tilt_Y : Boolean := False;
Tool_Width : Boolean := False;
Volume : Boolean := False;
Misc : Boolean := False;
MT_Slot : Boolean := False;
MT_Touch_Major : Boolean := False;
MT_Touch_Minor : Boolean := False;
MT_Width_Major : Boolean := False;
MT_Width_Minor : Boolean := False;
MT_Orientation : Boolean := False;
MT_Position_X : Boolean := False;
MT_Position_Y : Boolean := False;
MT_Tool_Type : Boolean := False;
MT_Blob_ID : Boolean := False;
MT_Tracking_ID : Boolean := False;
MT_Pressure : Boolean := False;
MT_Distance : Boolean := False;
MT_Tool_X : Boolean := False;
MT_Tool_Y : Boolean := False;
end record;
for Internal_Absolute_Axis_Features use record
X at 0 range 0 .. 0;
Y at 0 range 1 .. 1;
Z at 0 range 2 .. 2;
Rx at 0 range 3 .. 3;
Ry at 0 range 4 .. 4;
Rz at 0 range 5 .. 5;
Throttle at 0 range 6 .. 6;
Rudder at 0 range 7 .. 7;
Wheel at 0 range 8 .. 8;
Gas at 0 range 9 .. 9;
Brake at 0 range 10 .. 10;
Hat_0X at 0 range 16 .. 16;
Hat_0Y at 0 range 17 .. 17;
Hat_1X at 0 range 18 .. 18;
Hat_1Y at 0 range 19 .. 19;
Hat_2X at 0 range 20 .. 20;
Hat_2Y at 0 range 21 .. 21;
Hat_3X at 0 range 22 .. 22;
Hat_3Y at 0 range 23 .. 23;
Pressure at 0 range 24 .. 24;
Distance at 0 range 25 .. 25;
Tilt_X at 0 range 26 .. 26;
Tilt_Y at 0 range 27 .. 27;
Tool_Width at 0 range 28 .. 28;
Volume at 0 range 32 .. 32;
Misc at 0 range 40 .. 40;
MT_Slot at 0 range 47 .. 47;
MT_Touch_Major at 0 range 48 .. 48;
MT_Touch_Minor at 0 range 49 .. 49;
MT_Width_Major at 0 range 50 .. 50;
MT_Width_Minor at 0 range 51 .. 51;
MT_Orientation at 0 range 52 .. 52;
MT_Position_X at 0 range 53 .. 53;
MT_Position_Y at 0 range 54 .. 54;
MT_Tool_Type at 0 range 55 .. 55;
MT_Blob_ID at 0 range 56 .. 56;
MT_Tracking_ID at 0 range 57 .. 57;
MT_Pressure at 0 range 58 .. 58;
MT_Distance at 0 range 59 .. 59;
MT_Tool_X at 0 range 60 .. 60;
MT_Tool_Y at 0 range 61 .. 61;
end record;
for Internal_Absolute_Axis_Features'Size use Absolute_Axis_Info_Kind'Size;
type Internal_Force_Feedback_Features is record
Rumble : Boolean := False;
Periodic : Boolean := False;
Constant_V : Boolean := False;
Spring : Boolean := False;
Friction : Boolean := False;
Damper : Boolean := False;
Inertia : Boolean := False;
Ramp : Boolean := False;
Square : Boolean := False;
Triangle : Boolean := False;
Sine : Boolean := False;
Saw_Up : Boolean := False;
Saw_Down : Boolean := False;
Custom : Boolean := False;
Gain : Boolean := False;
Auto_Center : Boolean := False;
Unused : Unused_Type := False;
end record;
for Internal_Force_Feedback_Features use record
Rumble at 0 range 80 .. 80;
Periodic at 0 range 81 .. 81;
Constant_V at 0 range 82 .. 82;
Spring at 0 range 83 .. 83;
Friction at 0 range 84 .. 84;
Damper at 0 range 85 .. 85;
Inertia at 0 range 86 .. 86;
Ramp at 0 range 87 .. 87;
Square at 0 range 88 .. 88;
Triangle at 0 range 89 .. 89;
Sine at 0 range 90 .. 90;
Saw_Up at 0 range 91 .. 91;
Saw_Down at 0 range 92 .. 92;
Custom at 0 range 93 .. 93;
Gain at 0 range 96 .. 96;
Auto_Center at 0 range 97 .. 97;
Unused at 0 range 98 .. 127;
end record;
for Internal_Force_Feedback_Features'Size use 128;
function Hex_Image (Value : Unsigned_8) return String is
Hex : constant array (Unsigned_8 range 0 .. 15) of Character := "0123456789abcdef";
begin
return Hex (Value / 16) & Hex (Value mod 16);
end Hex_Image;
function Hex_Image (Value : Unsigned_16; Bit_Order : System.Bit_Order) return String is
Low : constant Unsigned_8 := Unsigned_8 (16#FF# and Value);
High : constant Unsigned_8 := Unsigned_8 (16#FF# and (Value / 256));
use type System.Bit_Order;
begin
if System.Default_Bit_Order = Bit_Order then
return Hex_Image (Low) & Hex_Image (High);
else
return Hex_Image (High) & Hex_Image (Low);
end if;
end Hex_Image;
function Hex_Image (Value : Unsigned_16) return String is
(Hex_Image (Value, System.High_Order_First));
function GUID (ID : Device_ID) return String is
(Hex_Image (ID.Bus, System.Low_Order_First) & "0000" &
Hex_Image (ID.Vendor, System.Low_Order_First) & "0000" &
Hex_Image (ID.Product, System.Low_Order_First) & "0000" &
Hex_Image (ID.Version, System.Low_Order_First) & "0000");
----------------------------------------------------------------------------
use all type Event_Device.Input_Dev.Access_Mode;
use type Event_Device.Input_Dev.Unsigned_14;
function ID (Object : Input_Device) return Device_ID is
Result : aliased Device_ID;
Error_Code : constant Integer := Event_Device.Input_Dev.IO_Control
(Object.FD, (Read, 'E', 16#02#, Result'Size / System.Storage_Unit), Result'Address);
begin
return (if Error_Code /= -1 then Result else (others => 0));
end ID;
function Location (Object : Input_Device) return String is
Result : aliased String (1 .. 128) := (others => ' ');
Length : constant Integer := Event_Device.Input_Dev.IO_Control
(Object.FD, (Read, 'E', 16#07#, Result'Length), Result'Address);
begin
return (if Length > 0 then Result (1 .. Length - 1) else "");
end Location;
function Unique_ID (Object : Input_Device) return String is
Result : aliased String (1 .. 128) := (others => ' ');
Length : constant Integer := Event_Device.Input_Dev.IO_Control
(Object.FD, (Read, 'E', 16#08#, Result'Length), Result'Address);
begin
return (if Length > 0 then Result (1 .. Length - 1) else "");
end Unique_ID;
----------------------------------------------------------------------------
function Properties (Object : Input_Device) return Device_Properties is
Result : aliased Device_Properties;
Error_Code : constant Integer := Event_Device.Input_Dev.IO_Control
(Object.FD, (Read, 'E', 16#09#, Result'Size / System.Storage_Unit), Result'Address);
begin
pragma Assert (Error_Code /= -1);
return Result;
end Properties;
function Events (Object : Input_Device) return Device_Events is
Result : aliased Device_Events;
Error_Code : constant Integer := Event_Device.Input_Dev.IO_Control
(Object.FD, (Read, 'E', 16#20#, Result'Size / System.Storage_Unit), Result'Address);
begin
pragma Assert (Error_Code /= -1);
return Result;
end Events;
function Convert is new Ada.Unchecked_Conversion
(Source => Event_Kind, Target => Interfaces.C.unsigned_short);
function Features (Object : Input_Device) return Synchronization_Features is
Result : aliased Synchronization_Features;
Error_Code : constant Integer := Event_Device.Input_Dev.IO_Control
(Object.FD, (Read, 'E', 16#20# + Unsigned_8 (Convert (Synchronization)),
Result'Size / System.Storage_Unit),
Result'Address);
begin
pragma Assert (Error_Code /= -1);
return Result;
end Features;
function Features (Object : Input_Device) return Key_Features is
Result : aliased Internal_Key_Features;
Error_Code : constant Integer := Event_Device.Input_Dev.IO_Control
(Object.FD, (Read, 'E', 16#20# + Unsigned_8 (Convert (Key)),
Result'Size / System.Storage_Unit),
Result'Address);
begin
pragma Assert (Error_Code /= -1);
return
(Button_South => Result.Button_South,
Button_East => Result.Button_East,
Button_North => Result.Button_North,
Button_West => Result.Button_West,
Button_Trigger_Left_1 => Result.Button_Trigger_Left_1,
Button_Trigger_Right_1 => Result.Button_Trigger_Right_1,
Button_Trigger_Left_2 => Result.Button_Trigger_Left_2,
Button_Trigger_Right_2 => Result.Button_Trigger_Right_2,
Button_Select => Result.Button_Select,
Button_Start => Result.Button_Start,
Button_Mode => Result.Button_Mode,
Button_Thumb_Left => Result.Button_Thumb_Left,
Button_Thumb_Right => Result.Button_Thumb_Right);
end Features;
function Features (Object : Input_Device) return Relative_Axis_Features is
Result : aliased Internal_Relative_Axis_Features;
Error_Code : constant Integer := Event_Device.Input_Dev.IO_Control
(Object.FD,
(Read, 'E', 16#20# + Unsigned_8 (Convert (Relative)), Result'Size / System.Storage_Unit),
Result'Address);
begin
pragma Assert (Error_Code /= -1);
return
(X => Result.X,
Y => Result.Y,
Z => Result.Z,
Rx => Result.Rx,
Ry => Result.Ry,
Rz => Result.Rz,
Horizontal_Wheel => Result.Horizontal_Wheel,
Diagonal => Result.Diagonal,
Wheel => Result.Wheel,
Misc => Result.Misc,
Wheel_High_Res => Result.Wheel_High_Res,
Horizontal_Wheel_High_Res => Result.Horizontal_Wheel_High_Res);
end Features;
function Features (Object : Input_Device) return Absolute_Axis_Features is
Result : aliased Internal_Absolute_Axis_Features;
Error_Code : constant Integer := Event_Device.Input_Dev.IO_Control
(Object.FD,
(Read, 'E', 16#20# + Unsigned_8 (Convert (Absolute)), Result'Size / System.Storage_Unit),
Result'Address);
begin
pragma Assert (Error_Code /= -1);
return
(X => Result.X,
Y => Result.Y,
Z => Result.Z,
Rx => Result.Rx,
Ry => Result.Ry,
Rz => Result.Rz,
Throttle => Result.Throttle,
Rudder => Result.Rudder,
Wheel => Result.Wheel,
Gas => Result.Gas,
Brake => Result.Brake,
Hat_0X => Result.Hat_0X,
Hat_0Y => Result.Hat_0Y,
Hat_1X => Result.Hat_1X,
Hat_1Y => Result.Hat_1Y,
Hat_2X => Result.Hat_2X,
Hat_2Y => Result.Hat_2Y,
Hat_3X => Result.Hat_3X,
Hat_3Y => Result.Hat_3Y,
Pressure => Result.Pressure,
Distance => Result.Distance,
Tilt_X => Result.Tilt_X,
Tilt_Y => Result.Tilt_Y,
Tool_Width => Result.Tool_Width,
Volume => Result.Volume,
Misc => Result.Misc,
MT_Slot => Result.MT_Slot,
MT_Touch_Major => Result.MT_Touch_Major,
MT_Touch_Minor => Result.MT_Touch_Minor,
MT_Width_Major => Result.MT_Width_Major,
MT_Width_Minor => Result.MT_Width_Minor,
MT_Orientation => Result.MT_Orientation,
MT_Position_X => Result.MT_Position_X,
MT_Position_Y => Result.MT_Position_Y,
MT_Tool_Type => Result.MT_Tool_Type,
MT_Blob_ID => Result.MT_Blob_ID,
MT_Tracking_ID => Result.MT_Tracking_ID,
MT_Pressure => Result.MT_Pressure,
MT_Distance => Result.MT_Distance,
MT_Tool_X => Result.MT_Tool_X,
MT_Tool_Y => Result.MT_Tool_Y);
end Features;
function Features (Object : Input_Device) return Switch_Features is
Result : aliased Switch_Features;
Error_Code : constant Integer := Event_Device.Input_Dev.IO_Control
(Object.FD,
(Read, 'E', 16#20# + Unsigned_8 (Convert (Switch)), Result'Size / System.Storage_Unit),
Result'Address);
begin
pragma Assert (Error_Code /= -1);
return Result;
end Features;
function Features (Object : Input_Device) return Miscellaneous_Features is
Result : aliased Miscellaneous_Features;
Error_Code : constant Integer := Event_Device.Input_Dev.IO_Control
(Object.FD,
(Read, 'E', 16#20# + Unsigned_8 (Convert (Miscellaneous)),
Result'Size / System.Storage_Unit),
Result'Address);
begin
pragma Assert (Error_Code /= -1);
return Result;
end Features;
function Features (Object : Input_Device) return LED_Features is
Result : aliased LED_Features;
Error_Code : constant Integer := Event_Device.Input_Dev.IO_Control
(Object.FD,
(Read, 'E', 16#20# + Unsigned_8 (Convert (LED)), Result'Size / System.Storage_Unit),
Result'Address);
begin
pragma Assert (Error_Code /= -1);
return Result;
end Features;
function Features (Object : Input_Device) return Repeat_Features is
Result : aliased Repeat_Features;
Error_Code : constant Integer := Event_Device.Input_Dev.IO_Control
(Object.FD,
(Read, 'E', 16#20# + Unsigned_8 (Convert (Repeat)), Result'Size / System.Storage_Unit),
Result'Address);
begin
pragma Assert (Error_Code /= -1);
return Result;
end Features;
function Features (Object : Input_Device) return Sound_Features is
Result : aliased Sound_Features;
Error_Code : constant Integer := Event_Device.Input_Dev.IO_Control
(Object.FD,
(Read, 'E', 16#20# + Unsigned_8 (Convert (Sound)), Result'Size / System.Storage_Unit),
Result'Address);
begin
pragma Assert (Error_Code /= -1);
return Result;
end Features;
function Features (Object : Input_Device) return Force_Feedback_Features is
Result : aliased Internal_Force_Feedback_Features;
Error_Code : constant Integer := Event_Device.Input_Dev.IO_Control
(Object.FD,
(Read, 'E', 16#20# + Unsigned_8 (Convert (Force_Feedback)),
Result'Size / System.Storage_Unit),
Result'Address);
begin
pragma Assert (Error_Code /= -1);
return
(Rumble => Result.Rumble,
Periodic => Result.Periodic,
Constant_V => Result.Constant_V,
Spring => Result.Spring,
Friction => Result.Friction,
Damper => Result.Damper,
Inertia => Result.Inertia,
Ramp => Result.Ramp,
Square => Result.Square,
Triangle => Result.Triangle,
Sine => Result.Sine,
Saw_Up => Result.Saw_Up,
Saw_Down => Result.Saw_Down,
Custom => Result.Custom,
Gain => Result.Gain,
Auto_Center => Result.Auto_Center);
end Features;
----------------------------------------------------------------------------
function Axis (Object : Input_Device; Axis : Absolute_Axis_Kind) return Axis_Info is
Result : aliased Axis_Info;
function Convert is new Ada.Unchecked_Conversion
(Source => Absolute_Axis_Info_Kind, Target => Unsigned_64);
Error_Code : constant Integer := Event_Device.Input_Dev.IO_Control
(Object.FD,
(Read, 'E', 16#40# + Unsigned_8 (Convert (Absolute_Axis_Info_Kind (Axis))),
Result'Size / System.Storage_Unit),
Result'Address);
begin
pragma Assert (Error_Code /= -1);
return Result;
end Axis;
function Key_Statuses (Object : Input_Device) return Key_Features is
Result : aliased Internal_Key_Features;
Error_Code : constant Integer := Event_Device.Input_Dev.IO_Control
(Object.FD, (Read, 'E', 16#18#,
Result'Size / System.Storage_Unit),
Result'Address);
begin
pragma Assert (Error_Code /= -1);
return
(Button_South => Result.Button_South,
Button_East => Result.Button_East,
Button_North => Result.Button_North,
Button_West => Result.Button_West,
Button_Trigger_Left_1 => Result.Button_Trigger_Left_1,
Button_Trigger_Right_1 => Result.Button_Trigger_Right_1,
Button_Trigger_Left_2 => Result.Button_Trigger_Left_2,
Button_Trigger_Right_2 => Result.Button_Trigger_Right_2,
Button_Select => Result.Button_Select,
Button_Start => Result.Button_Start,
Button_Mode => Result.Button_Mode,
Button_Thumb_Left => Result.Button_Thumb_Left,
Button_Thumb_Right => Result.Button_Thumb_Right);
end Key_Statuses;
function LED_Statuses (Object : Input_Device) return LED_Features is
Result : aliased LED_Features;
Error_Code : constant Integer := Event_Device.Input_Dev.IO_Control
(Object.FD,
(Read, 'E', 16#19#, Result'Size / System.Storage_Unit),
Result'Address);
begin
pragma Assert (Error_Code /= -1);
return Result;
end LED_Statuses;
function Sound_Statuses (Object : Input_Device) return Sound_Features is
Result : aliased Sound_Features;
Error_Code : constant Integer := Event_Device.Input_Dev.IO_Control
(Object.FD,
(Read, 'E', 16#1A#, Result'Size / System.Storage_Unit),
Result'Address);
begin
pragma Assert (Error_Code /= -1);
return Result;
end Sound_Statuses;
function Switch_Statuses (Object : Input_Device) return Switch_Features is
Result : aliased Switch_Features;
Error_Code : constant Integer := Event_Device.Input_Dev.IO_Control
(Object.FD,
(Read, 'E', 16#1B#, Result'Size / System.Storage_Unit),
Result'Address);
begin
pragma Assert (Error_Code /= -1);
return Result;
end Switch_Statuses;
function Force_Feedback_Effects (Object : Input_Device) return Natural is
Result : aliased Integer;
Error_Code : constant Integer := Event_Device.Input_Dev.IO_Control
(Object.FD, (Read, 'E', 16#84#, Result'Size / System.Storage_Unit), Result'Address);
begin
pragma Assert (Error_Code /= -1);
return Result;
end Force_Feedback_Effects;
procedure Set_Force_Feedback_Gain
(Object : Input_Device;
Value : Force_Feedback_Gain)
is
FF_Gain_Code : constant := 16#60#;
Event : constant Input_Dev.Input_Event :=
(Time => (0, 0),
Event => Force_Feedback,
Code => FF_Gain_Code,
Value => Interfaces.C.int (16#FF_FF.00# * Value));
Result : constant Input_Dev.Result := Input_Dev.Write (Object.FD, Event);
begin
-- Ignore any possible errors. If the device has been disconnected
-- then playing a force-feedback effect will fail, which can be
-- detected by the boolean returned by Play_Force_Feedback_Effect.
null;
end Set_Force_Feedback_Gain;
procedure Set_Force_Feedback_Auto_Center
(Object : Input_Device;
Value : Force_Feedback_Auto_Center)
is
FF_Auto_Center_Code : constant := 16#61#;
Event : constant Input_Dev.Input_Event :=
(Time => (0, 0),
Event => Force_Feedback,
Code => FF_Auto_Center_Code,
Value => Interfaces.C.int (16#FF_FF.00# * Value));
Result : constant Input_Dev.Result := Input_Dev.Write (Object.FD, Event);
begin
-- Ignore any possible errors. If the device has been disconnected
-- then playing a force-feedback effect will fail, which can be
-- detected by the boolean returned by Play_Force_Feedback_Effect.
null;
end Set_Force_Feedback_Auto_Center;
function Play_Force_Feedback_Effect
(Object : Input_Device;
Identifier : Uploaded_Force_Feedback_Effect_ID;
Count : Natural := 1) return Boolean
is
Event : constant Input_Dev.Input_Event :=
(Time => (0, 0),
Event => Force_Feedback,
Code => Interfaces.C.unsigned_short (Identifier),
Value => Interfaces.C.int (Count));
Result : constant Input_Dev.Result := Input_Dev.Write (Object.FD, Event);
begin
return Result.Is_Success;
end Play_Force_Feedback_Effect;
function Name (Object : Input_Device) return String is
Result : aliased String (1 .. 128) := (others => ' ');
Length : constant Integer := Event_Device.Input_Dev.IO_Control
(Object.FD, (Read, 'E', 16#06#, Result'Length), Result'Address);
begin
return (if Length > 0 then Result (1 .. Length - 1) else "");
end Name;
function Is_Open (Object : Input_Device) return Boolean is
(Object.Open);
function Open
(Object : in out Input_Device;
File_Name : String;
Blocking : Boolean := True) return Boolean
is
Result : constant Input_Dev.Result := Input_Dev.Open (File_Name, Blocking => Blocking);
begin
if Result.Is_Success then
Object.FD := Result.FD;
end if;
Object.Open := Result.Is_Success;
return Object.Open;
end Open;
procedure Close (Object : in out Input_Device) is
Result : constant Input_Dev.Result := Input_Dev.Close (Object.FD);
begin
Object.FD := -1;
Object.Open := not Result.Is_Success;
end Close;
overriding procedure Finalize (Object : in out Input_Device) is
begin
if Object.Is_Open then
Object.Close;
end if;
end Finalize;
function Read
(Object : Input_Device;
Value : out State) return Read_Result
is
use Event_Device.Input_Dev;
use type Interfaces.C.unsigned_short;
use type Interfaces.C.int;
function Convert is new Ada.Unchecked_Conversion
(Source => Interfaces.C.unsigned_short, Target => Synchronization_Kind);
function Convert is new Ada.Unchecked_Conversion
(Source => Interfaces.C.unsigned_short, Target => Key_Info_Kind);
function Convert is new Ada.Unchecked_Conversion
(Source => Interfaces.C.unsigned_short, Target => Relative_Axis_Info_Kind);
function Convert is new Ada.Unchecked_Conversion
(Source => Unsigned_64, Target => Absolute_Axis_Info_Kind);
-- Convert to Absolute_Axis_Info_Kind first before converting to
-- Absolute_Axis_Kind, because the former has a representation clause
Event : Input_Event;
Result : Input_Dev.Result;
Has_Dropped : Boolean := False;
begin
loop
Result := Input_Dev.Read (Object.FD, Event);
if not Result.Is_Success then
if Result.Error = Would_Block then
return Would_Block;
else
Value := (others => <>);
return Error;
end if;
end if;
case Event.Event is
when Key =>
declare
Code : constant Key_Kind := Key_Kind (Key_Info_Kind'(Convert (Event.Code)));
begin
Value.Keys (Code) := (if Event.Value /= 0 then Pressed else Released);
end;
when Relative =>
if not Has_Dropped then
declare
Code : constant Relative_Axis_Kind :=
Relative_Axis_Kind (Relative_Axis_Info_Kind'(Convert (Event.Code)));
begin
Value.Relative (Code) := Integer (Event.Value);
end;
end if;
when Absolute =>
if not Has_Dropped then
declare
Code : constant Absolute_Axis_Kind :=
Absolute_Axis_Kind (Convert (Unsigned_64 (Event.Code)));
begin
Value.Absolute (Code) := Integer (Event.Value);
end;
end if;
when Synchronization =>
declare
Code : constant Synchronization_Kind := Convert (Event.Code);
begin
case Code is
when Report =>
Value.Time := Duration (Event.Time.Seconds)
+ Duration (Event.Time.Microseconds) / 1.0e6;
exit;
when Dropped =>
Has_Dropped := True;
when others =>
null;
end case;
end;
when others =>
null;
end case;
end loop;
return OK;
end Read;
end Event_Device;
|
-- This file provides definitions for the high resolution timers on the
-- STM32F3 (ARM Cortex M4F) microcontrollers from ST Microelectronics.
pragma Restrictions (No_Elaboration_Code);
with System; use System;
with STM32_SVD.HRTIM; use STM32_SVD.HRTIM, STM32_SVD;
package STM32.HRTimers is
type HRTimer_Channel is limited private;
type HRTimer_Master is limited private;
----------------------------------------------------------------------------
-- HRTimer Master functions -----------------------------------------------
----------------------------------------------------------------------------
procedure Enable (This : HRTimer_Master)
with Post => Enabled (This);
procedure Disable (This : HRTimer_Master)
with Post => (if This'Address = HRTIM_Master_Base then
-- Test if HRTimer A to F has no outputs enabled.
(if not (HRTIM_Common_Periph.OENR.TA1OEN or
HRTIM_Common_Periph.OENR.TA2OEN) and
not (HRTIM_Common_Periph.OENR.TB1OEN or
HRTIM_Common_Periph.OENR.TB2OEN) and
not (HRTIM_Common_Periph.OENR.TC1OEN or
HRTIM_Common_Periph.OENR.TC2OEN) and
not (HRTIM_Common_Periph.OENR.TD1OEN or
HRTIM_Common_Periph.OENR.TD2OEN) and
not (HRTIM_Common_Periph.OENR.TE1OEN or
HRTIM_Common_Periph.OENR.TE2OEN)
then
not Enabled (This)
else
Enabled (This)));
function Enabled (This : HRTimer_Master) return Boolean;
type HRTimer is
(HRTimer_M, -- Master
HRTimer_A,
HRTimer_B,
HRTimer_C,
HRTimer_D,
HRTimer_E)
with Size => 6;
for HRTimer use
(HRTimer_M => 2#000001#,
HRTimer_A => 2#000010#,
HRTimer_B => 2#000100#,
HRTimer_C => 2#001000#,
HRTimer_D => 2#010000#,
HRTimer_E => 2#100000#);
type HRTimer_List is array (Positive range <>) of HRTimer;
procedure Enable (Counters : HRTimer_List);
-- Start all chosen timer counters at the same time.
procedure Disable (Counters : HRTimer_List);
-- Stop all chosen timer counters at the same time if they don't have
-- outputs enabled.
procedure Set_Preload_Enable
(This : in out HRTimer_Master;
Enable : Boolean);
-- Enables the registers preload mechanism and defines whether the write
-- accesses to the memory mapped registers are done into HRTIM active or
-- preload registers.
type HRTimer_Prescaler is
(Mul_32, -- fHRCK = 32 * fHRTIM
Mul_16, -- fHRCK = 16 * fHRTIM
Mul_8, -- fHRCK = 8 * fHRTIM
Mul_4, -- fHRCK = 4 * fHRTIM
Mul_2, -- fHRCK = 2 * fHRTIM
Mul_1, -- fHRCK = fHRTIM
Div_2, -- fHRCK = fHRTIM / 2
Div_4) -- fHRCK = fHRTIM / 4
with Size => 3;
-- The fHRCK input clock to the prescaler is equal to 32 x fHRTIM, so when
-- the prescaler is Div_32, fHRCK = fHRTIM. With fHRTIM = 144 MHz,
-- fHRCK = 4.608 GHz with resolution 217 ps. See RM0364 rev 4 Chapter 21.3.3
-- "Clocks".
type HRTimer_Prescaler_Array is array (HRTimer_Prescaler) of UInt16;
HRTimer_Prescaler_Value : HRTimer_Prescaler_Array := (1, 2, 4, 8, 16, 32, 64, 128);
procedure Configure_Prescaler
(This : in out HRTimer_Master;
Prescaler : HRTimer_Prescaler)
with Pre => not Enabled (This),
Post => Current_Prescaler (This) = HRTimer_Prescaler_Value (Prescaler);
-- The actual prescaler value is (2 ** Prescaler). The counter clock
-- equivalent frequency (fCOUNTER) is equal to fHRCK / 2 ** CKPSC[2:0].
-- It is mandatory to have the same prescaling factors for all timers
-- sharing resources (for instance master timer and Timer A must have
-- identical CKPSC[2:0] values if master timer is controlling HRTIM_CHA1 or
-- HRTIM_CHA2 outputs).
function Current_Prescaler (This : HRTimer_Master) return UInt16;
type Synchronization_Input_Source is
(Disabled,
Internal_Event,
External_Event);
for Synchronization_Input_Source use
(Disabled => 2#00#,
Internal_Event => 2#10#,
External_Event => 2#11#);
-- When disabled, the HRTIM is not synchronized and runs in standalone mode,
-- when internal event, it is synchronized with the on-chip timer, when
-- external event (input pin), a positive pulse on HRTIM_SCIN input triggers
-- the HRTIM.
procedure Configure_Synchronization_Input
(This : in out HRTimer_Master;
Source : Synchronization_Input_Source;
Reset : Boolean;
Start : Boolean)
with Pre => not Enabled (This);
-- Define if the synchronization input source reset and start the master
-- timer.
type Synchronization_Output_Source is
(Master_Timer_Start,
Master_Timer_Compare_1_Event,
Timer_A_StartReset,
Timer_A_Compare_1_Event);
-- Define the source and event to be sent on the synchronization outputs
-- SYNCOUT[2:1]
type Synchronization_Output_Event is
(Disabled,
Positive_Pulse_HRTIM_SCOUT,
Negative_Pulse_HRTIM_SCOUT);
-- Define the routing and conditioning of the synchronization output event.
for Synchronization_Output_Event use
(Disabled => 2#00#,
Positive_Pulse_HRTIM_SCOUT => 2#10#,
Negative_Pulse_HRTIM_SCOUT => 2#11#);
procedure Configure_Synchronization_Output
(This : in out HRTimer_Master;
Source : Synchronization_Output_Source;
Event : Synchronization_Output_Event)
with Pre => not Enabled (This);
type DAC_Synchronization_Trigger is
(No_Trigger,
DACtrigOut1,
DACtrigOut2,
DACtrigOut3);
procedure Configure_DAC_Synchronization_Trigger
(This : in out HRTimer_Master;
Trigger : DAC_Synchronization_Trigger);
-- A DAC synchronization event can be enabled and generated when the master
-- timer update occurs. These bits are defining on which output the DAC
-- synchronization is sent (refer to Section 21.3.19 in RM0364: DAC triggers
-- for connections details).
type Burst_DMA_Update_Mode is
(Independent,
DMA_Burst_Complete,
Master_RollOver);
procedure Configure_Timer_Update
(This : in out HRTimer_Master;
Repetition : Boolean;
Burst_DMA : Burst_DMA_Update_Mode)
with Pre => HRTIM_Master_Periph.MCR.BRSTDMA = 2#00# or
HRTIM_Master_Periph.MCR.BRSTDMA = 2#01#;
-- Defines whether an update occurs when the master timer repetition period
-- is completed (either due to roll-over or reset events) and if it starts
-- Interrupt and/or DMA requests.
-- MREPU can be set only if BRSTDMA[1:0] = 00 or 01.
--
-- Define how the update occurs relatively to a burst DMA transaction:
-- update done independently from the DMA burst transfer completion;
-- update done when the DMA burst transfer is completed; update done on
-- master timer roll-over following a DMA burst transfer completion (this
-- mode only works in continuous mode).
procedure Set_HalfPeriod_Mode
(This : in out HRTimer_Master;
Mode : Boolean);
-- Enables the half duty-cycle mode: the HRTIM_MCMP1xR active register is
-- automatically updated with HRTIM_MPERxR/2 value when HRTIM_MPERxR
-- register is written.
procedure Set_Period (This : in out HRTimer_Master; Value : UInt16)
with Post => Current_Period (This) = Value;
function Current_Period (This : HRTimer_Master) return UInt16;
procedure Configure
(This : in out HRTimer_Master;
Prescaler : HRTimer_Prescaler;
Period : UInt16)
with Pre => not Enabled (This),
Post => Current_Prescaler (This) = HRTimer_Prescaler_Value (Prescaler) and
Current_Period (This) = Period;
type Counter_Operating_Mode is
(SingleShot_NonRetriggerable,
SingleShot_Retriggerable,
Continuous);
procedure Set_Counter_Operating_Mode
(This : in out HRTimer_Master;
Mode : Counter_Operating_Mode);
-- The timer operates in single-shot mode and stops when it reaches the
-- MPER value or operates in continuous (free-running) mode and rolls over
-- to zero when it reaches the MPER value. In single-shot mode it may be
-- not re-triggerable - a counter reset can be done only if the counter is
-- stoped (period elapsed), or re-triggerable - a counter reset is done
-- whatever the counter state (running or stopped).
-- See RM0364 rev. 4 Section 21.3.4 pg. 636 Table 83 Timer operating modes.
procedure Set_Counter (This : in out HRTimer_Master; Value : UInt16)
with Post => Current_Counter (This) = Value;
function Current_Counter (This : HRTimer_Master) return UInt16;
procedure Set_Repetition_Counter
(This : in out HRTimer_Master;
Value : UInt8)
with Post => Current_Repetition_Counter (This) = Value;
-- The repetition period value for the master counter. It holds either
-- the content of the preload register or the content of the active
-- register if preload is disabled.
function Current_Repetition_Counter (This : HRTimer_Master) return UInt8;
procedure Configure_Repetition_Counter
(This : in out HRTimer_Master;
Counter : UInt8;
Interrupt : Boolean;
DMA_Request : Boolean);
-- Defines the repetition period and whether the master timer starts
-- Interrupt and/or DMA requests at the end of repetition.
procedure Configure
(This : in out HRTimer_Master;
Prescaler : HRTimer_Prescaler;
Period : UInt16;
Repetitions : UInt8)
with Pre => not Enabled (This),
Post => Current_Prescaler (This) = HRTimer_Prescaler_Value (Prescaler) and
Current_Period (This) = Period and
Current_Repetition_Counter (This) = Repetitions;
type HRTimer_Compare_Number is
(Compare_1,
Compare_2,
Compare_3,
Compare_4);
procedure Set_Compare_Value
(This : in out HRTimer_Master;
Compare : HRTimer_Compare_Number;
Value : in out UInt16)
with Post => Read_Compare_Value (This, Compare) = Value;
-- Set the value for Compare registers 1 to 4.
function Read_Compare_Value
(This : HRTimer_Master;
Compare : HRTimer_Compare_Number) return UInt16;
-- Read the value for Compare registers 1 to 4.
type HRTimer_Master_Interrupt is
(Compare_1_Interrupt,
Compare_2_Interrupt,
Compare_3_Interrupt,
Compare_4_Interrupt,
Repetition_Interrupt,
Sync_Input_Interrupt,
Update_Interrupt);
procedure Enable_Interrupt
(This : in out HRTimer_Master;
Source : HRTimer_Master_Interrupt)
with Post => Interrupt_Enabled (This, Source);
type HRTimer_Master_Interrupt_List is
array (Positive range <>) of HRTimer_Master_Interrupt;
procedure Enable_Interrupt
(This : in out HRTimer_Master;
Sources : HRTimer_Master_Interrupt_List)
with
Post => (for all Source of Sources => Interrupt_Enabled (This, Source));
procedure Disable_Interrupt
(This : in out HRTimer_Master;
Source : HRTimer_Master_Interrupt)
with Post => not Interrupt_Enabled (This, Source);
function Interrupt_Enabled
(This : HRTimer_Master;
Source : HRTimer_Master_Interrupt) return Boolean;
function Interrupt_Status
(This : HRTimer_Master;
Source : HRTimer_Master_Interrupt) return Boolean;
procedure Clear_Pending_Interrupt
(This : in out HRTimer_Master;
Source : HRTimer_Master_Interrupt);
type HRTimer_Master_DMA_Request is
(Compare_1_DMA,
Compare_2_DMA,
Compare_3_DMA,
Compare_4_DMA,
Repetition_DMA,
Sync_Input_DMA,
Update_DMA);
procedure Enable_DMA_Source
(This : in out HRTimer_Master;
Source : HRTimer_Master_DMA_Request)
with Post => DMA_Source_Enabled (This, Source);
procedure Disable_DMA_Source
(This : in out HRTimer_Master;
Source : HRTimer_Master_DMA_Request)
with Post => not DMA_Source_Enabled (This, Source);
function DMA_Source_Enabled
(This : HRTimer_Master;
Source : HRTimer_Master_DMA_Request) return Boolean;
----------------------------------------------------------------------------
-- HRTimer A to E functions -----------------------------------------------
----------------------------------------------------------------------------
procedure Enable (This : HRTimer_Channel)
with Post => Enabled (This);
procedure Disable (This : HRTimer_Channel)
with Post => (if This'Address = HRTIM_TIMA_Base then
-- Test if HRTimer A has no outputs enabled.
(if not (HRTIM_Common_Periph.OENR.TA1OEN or
HRTIM_Common_Periph.OENR.TA2OEN)
then
not Enabled (This)
else
Enabled (This))
elsif This'Address = HRTIM_TIMB_Base then
-- Test if HRTimer B has no outputs enabled.
(if not (HRTIM_Common_Periph.OENR.TB1OEN or
HRTIM_Common_Periph.OENR.TB2OEN)
then
not Enabled (This)
else
Enabled (This))
elsif This'Address = HRTIM_TIMC_Base then
-- Test if HRTimer C has no outputs enabled.
(if not (HRTIM_Common_Periph.OENR.TC1OEN or
HRTIM_Common_Periph.OENR.TC2OEN)
then
not Enabled (This)
else
Enabled (This))
elsif This'Address = HRTIM_TIMD_Base then
-- Test if HRTimer D has no outputs enabled.
(if not (HRTIM_Common_Periph.OENR.TD1OEN or
HRTIM_Common_Periph.OENR.TD2OEN)
then
not Enabled (This)
else
Enabled (This))
elsif This'Address = HRTIM_TIME_Base then
-- Test if HRTimer E has no outputs enabled.
(if not (HRTIM_Common_Periph.OENR.TE1OEN or
HRTIM_Common_Periph.OENR.TE2OEN)
then
not Enabled (This)
else
Enabled (This)));
function Enabled (This : HRTimer_Channel) return Boolean;
procedure Set_Register_Preload
(This : in out HRTimer_Channel;
Enable : Boolean);
-- Enables the registers preload mechanism and defines whether the write
-- accesses to the memory mapped registers are done into HRTIM active or
-- preload registers.
procedure Configure_Prescaler
(This : in out HRTimer_Channel;
Prescaler : HRTimer_Prescaler)
with Pre => not Enabled (This),
Post => Current_Prescaler (This) = HRTimer_Prescaler_Value (Prescaler);
-- The actual prescaler value is (2 ** Prescaler). For clock prescaling ratios
-- below 32 (CKPSC[2:0] < 5), the least significant bits of the counter and
-- capture registers are not significant. The least significant bits cannot
-- be written (counter register only) and return 0 when read.
-- See RM0364 rev 4 Section 21.3.3 pg 632 Timer clock and prescaler.
-- It is mandatory to have the same prescaling factors for all timers
-- sharing resources (for instance master timer and Timer A must have
-- identical CKPSC[2:0] values if master timer is controlling HRTIM_CHA1 or
-- HRTIM_CHA2 outputs).
function Current_Prescaler (This : HRTimer_Channel) return UInt16;
procedure Set_PushPull_Mode (This : in out HRTimer_Channel; Mode : Boolean)
with Pre => not Enabled (This);
-- It applies the signals generated by the crossbar to output 1 and output 2
-- alternatively, on the period basis, maintaining the other output to its
-- inactive state. The redirection rate (push-pull frequency) is defined by
-- the timer’s period event. The push-pull period is twice the timer
-- counting period. The push-pull mode is available when the timer operates
-- in continuous mode and in single-shot mode. It also needs to be enabled
-- when the delayed idle protection is required.
procedure Configure_Synchronization_Input
(This : in out HRTimer_Channel;
Reset : Boolean;
Start : Boolean);
procedure Configure_DAC_Synchronization_Trigger
(This : in out HRTimer_Channel;
Trigger : DAC_Synchronization_Trigger);
-- A DAC synchronization event can be enabled and generated when the master
-- timer update occurs. These bits are defining on which output the DAC
-- synchronization is sent (refer to RM0364 rev 4 Section 21.3.19: DAC
-- triggers for connections details).
type Comparator_AutoDelayed_Mode is (CMP2, CMP4);
type CMP2_AutoDelayed_Mode is
(Always_Active,
Active_After_Capture_1,
Active_After_Capture_1_Compare_1,
Active_After_Capture_1_Compare_3);
type CMP4_AutoDelayed_Mode is
(Always_Active,
Active_After_Capture_2,
Active_After_Capture_2_Compare_1,
Active_After_Capture_2_Compare_3);
type CMP_AutoDelayed_Mode_Descriptor
(Selector : Comparator_AutoDelayed_Mode := CMP2) is
record
case Selector is
when CMP2 =>
AutoDelay_1 : CMP2_AutoDelayed_Mode;
when CMP4 =>
AutoDelay_2 : CMP4_AutoDelayed_Mode;
end case;
end record with Size => 3;
for CMP_AutoDelayed_Mode_Descriptor use record
Selector at 0 range 2 .. 2;
AutoDelay_1 at 0 range 0 .. 1;
AutoDelay_2 at 0 range 0 .. 1;
end record;
procedure Configure_Comparator_AutoDelayed_Mode
(This : in out HRTimer_Channel;
Mode : CMP_AutoDelayed_Mode_Descriptor)
with Pre => not Enabled (This);
type HRTimer_Update_Event is
(Repetition_Counter_Reset,
Counter_Reset,
TimerA_Update,
TimerB_Update,
TimerC_Update,
TimerD_Update,
TimerE_Update,
Master_Update);
procedure Set_Timer_Update
(This : in out HRTimer_Channel;
Event : HRTimer_Update_Event;
Enable : Boolean)
with Pre => (if This'Address = HRTIM_TIMA_Base then Event /= TimerA_Update
elsif This'Address = HRTIM_TIMB_Base then Event /= TimerB_Update
elsif This'Address = HRTIM_TIMC_Base then Event /= TimerC_Update
elsif This'Address = HRTIM_TIMD_Base then Event /= TimerD_Update
elsif This'Address = HRTIM_TIME_Base then Event /= TimerE_Update);
-- Register update is triggered when the current counter rolls-over and
-- HRTIM_REPx = 0, or the current counter reset or rolls-over to 0 after
-- reaching the period value in continuous mode, or by any other timer
-- update.
type Update_Gating_Mode is
(Independent,
DMA_Burst_Complete,
DMA_Burst_Complete_Update_Event,
Rising_Edge_Input_1, -- TIM16_OC
Rising_Edge_Input_2, -- TIM17_OC
Rising_Edge_Input_3, -- TIM6_TRGO
Rising_Edge_Input_1_Update,
Rising_Edge_Input_2_Update,
Rising_Edge_Input_3_Update);
procedure Set_Update_Gating_Mode
(This : in out HRTimer_Channel;
Mode : Update_Gating_Mode);
-- Define how the update occurs relatively to the burst DMA transaction
-- and the external update request on update enable inputs 1 to 3 (see
-- RM0364 rev 4 section 21.3.10 pg 674 Table 91: Update enable inputs and
-- sources). The update events, can be: MSTU, TEU, TDU, TCU, TBU, TAU,
-- TxRSTU, TxREPU.
procedure Set_HalfPeriod_Mode
(This : in out HRTimer_Channel;
Mode : Boolean);
-- Enables the half duty-cycle mode: the HRTIM_CMP1xR active register is
-- automatically updated with HRTIM_PERxR/2 value when HRTIM_PERxR register
-- is written.
procedure Set_Period (This : in out HRTimer_Channel; Value : UInt16)
with Post => Current_Period (This) = Value;
function Current_Period (This : HRTimer_Channel) return UInt16;
procedure Configure
(This : in out HRTimer_Channel;
Prescaler : HRTimer_Prescaler;
Period : UInt16)
with Pre => not Enabled (This),
Post => Current_Prescaler (This) = HRTimer_Prescaler_Value (Prescaler) and
Current_Period (This) = Period;
procedure Compute_Prescaler_And_Period
(This : HRTimer_Channel;
Requested_Frequency : UInt32;
Prescaler : out HRTimer_Prescaler;
Period : out UInt32)
with Pre => Requested_Frequency > 0;
-- Computes the minimum prescaler and thus the maximum resolution for the
-- given timer, based on the system clocks and the requested frequency.
-- Computes the period required for the requested frequency.
Invalid_Request : exception;
-- Raised when the requested frequency is too high or too low for the given
-- timer and system clocks.
procedure Set_Counter_Operating_Mode
(This : in out HRTimer_Channel;
Mode : Counter_Operating_Mode);
-- The timer operates in single-shot mode and stops when it reaches the
-- MPER value or operates in continuous (free-running) mode and rolls over
-- to zero when it reaches the MPER value. In single-shot mode it may be
-- not re-triggerable - a counter reset can be done only if the counter is
-- stoped (period elapsed), or re-triggerable - a counter reset is done
-- whatever the counter state (running or stopped).
-- See RM0364 rev. 4 Chapter 21.3.4 pg. 636 Section Counter operating mode.
procedure Set_Counter (This : in out HRTimer_Channel; Value : UInt16)
with Post => Current_Counter (This) = Value;
function Current_Counter (This : HRTimer_Channel) return UInt16;
procedure Set_Repetition_Counter
(This : in out HRTimer_Channel; Value : UInt8)
with Post => Current_Repetition_Counter (This) = Value;
-- The repetition counter is initialized with the content of the HRTIM_REPxR
-- register when the timer is enabled (TXCEN bit set). Once the timer has
-- been enabled, any time the counter is cleared, either due to a reset
-- event or due to a counter roll-over, the repetition counter is decreased.
-- When it reaches zero, a REP interrupt or a DMA request is issued if
-- enabled (REPIE and REPDE bits in the HRTIM_DIER register).
function Current_Repetition_Counter (This : HRTimer_Channel) return UInt8;
procedure Configure_Repetition_Counter
(This : in out HRTimer_Channel;
Repetitions : UInt8;
Interrupt : Boolean;
DMA_Request : Boolean)
with Post => Current_Repetition_Counter (This) = Repetitions;
-- The repetition counter is initialized with the content of the HRTIM_REPxR
-- register when the timer is enabled (TXCEN bit set). Once the timer has
-- been enabled, any time the counter is cleared, either due to a reset
-- event or due to a counter roll-over, the repetition counter is decreased.
-- When it reaches zero, a REP interrupt or a DMA request is issued if
-- enabled (REPIE and REPDE bits in the HRTIM_DIER register).
procedure Configure
(This : in out HRTimer_Channel;
Prescaler : HRTimer_Prescaler;
Period : UInt16;
Repetitions : UInt8)
with Pre => not Enabled (This),
Post => Current_Prescaler (This) = HRTimer_Prescaler_Value (Prescaler) and
Current_Period (This) = Period and
Current_Repetition_Counter (This) = Repetitions;
type Counter_Reset_Event is
(Timer_Update,
Timer_Compare_2,
Timer_Compare_4,
Master_Timer_Period,
Master_Compare_1,
Master_Compare_2,
Master_Compare_3,
Master_Compare_4,
External_Event_1,
External_Event_2,
External_Event_3,
External_Event_4,
External_Event_5,
External_Event_6,
External_Event_7,
External_Event_8,
External_Event_9,
External_Event_10,
Option_20,
Option_21,
Option_22,
Option_23,
Option_24,
Option_25,
Option_26,
Option_27,
Option_28,
Option_29,
Option_30,
Option_31)
with Size => 32;
-- The HRTimer A to F are reset upon these events.
-- Option HRTimer_A HRTimer_B HRTimer_C
-- 20 Timer_B_CMP_1 Timer_A_CMP_1 Timer_A_CMP_1
-- 21 Timer_B_CMP_2 Timer_A_CMP_2 Timer_A_CMP_2
-- 22 Timer_B_CMP_4 Timer_A_CMP_4 Timer_A_CMP_4
-- 23 Timer_C_CMP_1 Timer_C_CMP_1 Timer_B_CMP_1
-- 24 Timer_C_CMP_2 Timer_C_CMP_2 Timer_B_CMP_2
-- 25 Timer_C_CMP_4 Timer_C_CMP_4 Timer_B_CMP_4
-- 26 Timer_D_CMP_1 Timer_D_CMP_1 Timer_D_CMP_1
-- 27 Timer_D_CMP_2 Timer_D_CMP_2 Timer_D_CMP_2
-- 28 Timer_D_CMP_4 Timer_D_CMP_4 Timer_D_CMP_4
-- 29 Timer_E_CMP_1 Timer_E_CMP_1 Timer_E_CMP_1
-- 30 Timer_E_CMP_2 Timer_E_CMP_2 Timer_E_CMP_2
-- 31 Timer_E_CMP_4 Timer_E_CMP_4 Timer_E_CMP_4
--
-- Option HRTimer_D HRTimer_E
-- 20 Timer_A_CMP_1 Timer_A_CMP_1
-- 21 Timer_A_CMP_2 Timer_A_CMP_2
-- 22 Timer_A_CMP_4 Timer_A_CMP_4
-- 23 Timer_B_CMP_1 Timer_B_CMP_1
-- 24 Timer_B_CMP_2 Timer_B_CMP_2
-- 25 Timer_B_CMP_4 Timer_B_CMP_4
-- 26 Timer_C_CMP_1 Timer_C_CMP_1
-- 27 Timer_C_CMP_2 Timer_C_CMP_2
-- 28 Timer_C_CMP_4 Timer_C_CMP_4
-- 29 Timer_E_CMP_1 Timer_D_CMP_1
-- 30 Timer_E_CMP_2 Timer_D_CMP_2
-- 31 Timer_E_CMP_4 Timer_D_CMP_4
procedure Set_Counter_Reset_Event
(This : in out HRTimer_Channel;
Event : Counter_Reset_Event;
Enable : Boolean);
type HRTimer_Capture_Compare_State is (Disable, Enable);
procedure Set_Compare_Value
(This : in out HRTimer_Channel;
Compare : HRTimer_Compare_Number;
Value : UInt16)
with Post => Current_Compare_Value (This, Compare) = Value;
-- Set the value for Compare registers 1 to 4.
function Current_Compare_Value
(This : HRTimer_Channel;
Compare : HRTimer_Compare_Number) return UInt16;
-- Read the value for Compare registers 1 to 4.
type HRTimer_Capture_Number is
(Capture_1,
Capture_2);
function Current_Capture_Value
(This : HRTimer_Channel;
Number : HRTimer_Capture_Number) return UInt16;
-- Read the counter value when the capture event occurred.
type HRTimer_Capture_Event is
(Software,
Timer_Update,
External_Event_1,
External_Event_2,
External_Event_3,
External_Event_4,
External_Event_5,
External_Event_6,
External_Event_7,
External_Event_8,
External_Event_9,
External_Event_10,
Timer_A_Output_1_Set,
Timer_A_Output_1_Reset,
Timer_A_Compare_1,
Timer_A_Compare_2,
Timer_B_Output_1_Set,
Timer_B_Output_1_Reset,
Timer_B_Compare_1,
Timer_B_Compare_2,
Timer_C_Output_1_Set,
Timer_C_Output_1_Reset,
Timer_C_Compare_1,
Timer_C_Compare_2,
Timer_D_Output_1_Set,
Timer_D_Output_1_Reset,
Timer_D_Compare_1,
Timer_D_Compare_2,
Timer_E_Output_1_Set,
Timer_E_Output_1_Reset,
Timer_E_Compare_1,
Timer_E_Compare_2);
-- Events that trigger the counter.
procedure Set_Capture_Event
(This : in out HRTimer_Channel;
Capture : HRTimer_Capture_Number;
Event : HRTimer_Capture_Event;
Enable : Boolean)
with Pre => (if This'Address = HRTIM_TIMA_Base then
Event not in Timer_A_Output_1_Set |
Timer_A_Output_1_Reset |
Timer_A_Compare_1 |
Timer_A_Compare_2
elsif This'Address = HRTIM_TIMB_Base then
Event not in Timer_B_Output_1_Set |
Timer_B_Output_1_Reset |
Timer_B_Compare_1 |
Timer_B_Compare_2
elsif This'Address = HRTIM_TIMC_Base then
Event not in Timer_C_Output_1_Set |
Timer_C_Output_1_Reset |
Timer_C_Compare_1 |
Timer_C_Compare_2
elsif This'Address = HRTIM_TIMD_Base then
Event not in Timer_D_Output_1_Set |
Timer_D_Output_1_Reset |
Timer_D_Compare_1 |
Timer_D_Compare_2
elsif This'Address = HRTIM_TIME_Base then
Event not in Timer_E_Output_1_Set |
Timer_E_Output_1_Reset |
Timer_E_Compare_1 |
Timer_E_Compare_2);
-- Enable/disable the event that trigger the counter.
type HRTimer_Channel_Interrupt is
(Compare_1_Interrupt,
Compare_2_Interrupt,
Compare_3_Interrupt,
Compare_4_Interrupt,
Repetition_Interrupt,
Update_Interrupt,
Capture_1_Interrupt,
Capture_2_Interrupt,
Output_1_Set_Interrupt,
Output_1_Reset_Interrupt,
Output_2_Set_Interrupt,
Output_2_Reset_Interrupt,
Reset_RollOver_Interrupt,
Delayed_Protection_Interrupt);
procedure Enable_Interrupt
(This : in out HRTimer_Channel;
Source : HRTimer_Channel_Interrupt)
with Post => Interrupt_Enabled (This, Source);
type HRTimer_Channel_Interrupt_List is
array (Positive range <>) of HRTimer_Channel_Interrupt;
procedure Enable_Interrupt
(This : in out HRTimer_Channel;
Sources : HRTimer_Channel_Interrupt_List)
with
Post => (for all Source of Sources => Interrupt_Enabled (This, Source));
procedure Disable_Interrupt
(This : in out HRTimer_Channel;
Source : HRTimer_Channel_Interrupt)
with Post => not Interrupt_Enabled (This, Source);
function Interrupt_Enabled
(This : HRTimer_Channel;
Source : HRTimer_Channel_Interrupt) return Boolean;
function Interrupt_Status
(This : HRTimer_Channel;
Source : HRTimer_Channel_Interrupt) return Boolean;
procedure Clear_Pending_Interrupt
(This : in out HRTimer_Channel;
Source : HRTimer_Channel_Interrupt);
type HRTimer_Channel_DMA_Request is
(Compare_1_DMA,
Compare_2_DMA,
Compare_3_DMA,
Compare_4_DMA,
Repetition_DMA,
Update_DMA,
Capture_1_DMA,
Capture_2_DMA,
Output_1_Set_DMA,
Output_1_Reset_DMA,
Output_2_Set_DMA,
Output_2_Reset_DMA,
Reset_RollOver_DMA,
Delayed_Protection_DMA);
procedure Enable_DMA_Source
(This : in out HRTimer_Channel;
Source : HRTimer_Channel_DMA_Request)
with Post => DMA_Source_Enabled (This, Source);
procedure Disable_DMA_Source
(This : in out HRTimer_Channel;
Source : HRTimer_Channel_DMA_Request)
with Post => not DMA_Source_Enabled (This, Source);
function DMA_Source_Enabled
(This : HRTimer_Channel;
Source : HRTimer_Channel_DMA_Request) return Boolean;
procedure Set_Deadtime (This : in out HRTimer_Channel; Enable : Boolean)
with Pre =>
(if This'Address = HRTIM_TIMA_Base then
not Enabled (This) or No_Outputs_Enabled (This)
elsif This'Address = HRTIM_TIMB_Base then
not Enabled (This) or No_Outputs_Enabled (This)
elsif This'Address = HRTIM_TIMC_Base then
not Enabled (This) or No_Outputs_Enabled (This)
elsif This'Address = HRTIM_TIMD_Base then
not Enabled (This) or No_Outputs_Enabled (This)
elsif This'Address = HRTIM_TIME_Base then
not Enabled (This) or No_Outputs_Enabled (This)),
Post => Enabled_Deadtime (This) = Enable;
-- Enable or disable the deadtime. This parameter cannot be changed once
-- the timer is operating (TxEN bit set) or if its outputs are enabled
-- and set/reset by another timer. See RM0364 rev. 4 Chapter 21.5.37 pg.761.
function Enabled_Deadtime (This : HRTimer_Channel) return Boolean;
-- Return True if the timer deadtime is enabled.
type HRTimer_Deadtime_Sign is (Positive_Sign, Negative_Sign);
procedure Configure_Deadtime
(This : in out HRTimer_Channel;
Prescaler : UInt3;
Rising_Value : UInt9;
Rising_Sign : HRTimer_Deadtime_Sign := Positive_Sign;
Falling_Value : UInt9;
Falling_Sign : HRTimer_Deadtime_Sign := Positive_Sign);
-- Two deadtimes values can be defined in relationship with the rising edge
-- and the falling edge of the Output 1 reference waveform. The sign
-- determines whether the deadtime is positive or negative (overlaping
-- signals). See RM0364 rev. 4 Chapter 21.3.4 Section Deadtime pg. 649.
-- The deadtime cannot be used simultaneously with the push-pull mode.
procedure Configure_Deadtime
(This : in out HRTimer_Channel;
Rising_Value : Float;
Rising_Sign : HRTimer_Deadtime_Sign := Positive_Sign;
Falling_Value : Float;
Falling_Sign : HRTimer_Deadtime_Sign := Positive_Sign);
-- Two deadtimes values can be defined in relationship with the rising edge
-- and the falling edge of the Output 1 reference waveform.
-- The sign determines whether the deadtime is positive or negative
-- (overlaping signals). See pg. 649 in RM0364 rev. 4.
-- The deadtime cannot be used simultaneously with the push-pull mode.
type Deadtime_Lock is record
Rising_Value : Boolean;
Rising_Sign : Boolean;
Falling_Value : Boolean;
Falling_Sign : Boolean;
end record;
procedure Enable_Deadtime_Lock
(This : in out HRTimer_Channel;
Lock : Deadtime_Lock)
with Post => (if Lock.Rising_Value then Read_Deadtime_Lock (This).Rising_Value) and
(if Lock.Rising_Sign then Read_Deadtime_Lock (This).Rising_Sign) and
(if Lock.Falling_Value then Read_Deadtime_Lock (This).Falling_Value) and
(if Lock.Falling_Sign then Read_Deadtime_Lock (This).Falling_Sign);
-- Prevents the deadtime value and sign to be modified.
function Read_Deadtime_Lock (This : HRTimer_Channel) return Deadtime_Lock;
type Output_Event is
(Software_Trigger,
Timer_A_Resynchronization,
Timer_Period,
Timer_Compare_1,
Timer_Compare_2,
Timer_Compare_3,
Timer_Compare_4,
Master_Period,
Master_Compare_1,
Master_Compare_2,
Master_Compare_3,
Master_Compare_4,
Timer_Event_1,
Timer_Event_2,
Timer_Event_3,
Timer_Event_4,
Timer_Event_5,
Timer_Event_6,
Timer_Event_7,
Timer_Event_8,
Timer_Event_9,
External_Event_1,
External_Event_2,
External_Event_3,
External_Event_4,
External_Event_5,
External_Event_6,
External_Event_7,
External_Event_8,
External_Event_9,
External_Event_10,
Register_Update);
-- These events determine the set/reset crossbar of the outputs, so the
-- output waveform is established.
type HRTimer_Channel_Output is (Output_1, Output_2);
procedure Configure_Channel_Output_Event
(This : in out HRTimer_Channel;
Output : HRTimer_Channel_Output;
Set_Event : Output_Event;
Reset_Event : Output_Event)
with Pre => Set_Event /= Reset_Event;
-- The output waveform is determined by this set/reset crossbar.
-- When set and reset requests from two different sources are simultaneous,
-- the reset action has the highest priority. If the interval between set
-- and reset requests is below 2 fHRTIM period, the behavior depends on the
-- time interval and on the alignment with the fHRTIM clock. See chapter
-- 21.3.6 at pg. 654 in the RM0364 rev 4 for set/reset events priorities
-- and narrow pulses management.
type External_Event_Number is
(Event_1,
Event_2,
Event_3,
Event_4,
Event_5,
Event_6,
Event_7,
Event_8,
Event_9,
Event_10);
type External_Event_Latch is (Ignore, Latch);
-- Event is ignored if it happens during a blank, or passed through during
-- a window, or latched and delayed till the end of the blanking or
-- windowing period.
type External_Event_Blanking_Filter is
(No_Filtering,
Blanking_from_Counter_to_Compare_1,
Blanking_from_Counter_to_Compare_2,
Blanking_from_Counter_to_Compare_3,
Blanking_from_Counter_to_Compare_4,
Blanking_from_TIMFLTR1,
Blanking_from_TIMFLTR2,
Blanking_from_TIMFLTR3,
Blanking_from_TIMFLTR4,
Blanking_from_TIMFLTR5,
Blanking_from_TIMFLTR6,
Blanking_from_TIMFLTR7,
Blanking_from_TIMFLTR8,
Windowing_from_Counter_to_Compare_2,
Windowing_from_Counter_to_Compare_3,
Windowing_from_TIMWIN);
procedure Configure_External_Event
(This : in out HRTimer_Channel;
Event_Number : External_Event_Number;
Event_Latch : External_Event_Latch;
Event_Filter : External_Event_Blanking_Filter)
with Pre => not Enabled (This);
-- The HRTIM timer can handle events not generated within the timer,
-- referred to as “external event”. These external events come from
-- multiple sources, either on-chip or off-chip: built-in comparators,
-- digital input pins (typically connected to off-chip comparators and
-- zero-crossing detectors), on-chip events for other peripheral (ADC’s
-- analog watchdogs and general purpose timer trigger outputs).
-- See chapter 21.3.7 at pg. 657 in RM0364 rev. 4.
procedure Set_Chopper_Mode
(This : in out HRTimer_Channel;
Output1 : Boolean;
Output2 : Boolean)
with Post => Enabled_Chopper_Mode (This, Output_1) = Output1 and
Enabled_Chopper_Mode (This, Output_2) = Output2;
-- Enable/disable chopper mode for HRTimer channel outputs.
function Enabled_Chopper_Mode
(This : HRTimer_Channel;
Output : HRTimer_Channel_Output) return Boolean;
type Chopper_Carrier_Frequency is
(fHRTIM_Over_16, -- 9 MHz with fHRTIM = 144 MHz
fHRTIM_Over_32,
fHRTIM_Over_48,
fHRTIM_Over_64,
fHRTIM_Over_80,
fHRTIM_Over_96,
fHRTIM_Over_112,
fHRTIM_Over_128,
fHRTIM_Over_144,
fHRTIM_Over_160,
fHRTIM_Over_176,
fHRTIM_Over_192,
fHRTIM_Over_208,
fHRTIM_Over_224,
fHRTIM_Over_240,
fHRTIM_Over_256);
-- Chopper carrier frequency FCHPFRQ = fHRTIM / (16 x (CARFRQ[3:0]+1)).
-- This bitfield cannot be modified when one of the CHPx bits is set.
type Chopper_Duty_Cycle is
(Zero_Over_Eight, -- Only 1st pulse is present
One_Over_Eight,
Two_Over_Eight,
Three_Over_Eight,
Four_Over_Eight,
Five_Over_Eight,
Six_Over_Eight,
Seven_Over_Eight);
-- Duty cycle of the carrier signal. This bitfield cannot be modified
-- when one of the CHPx bits is set.
type Chopper_Start_PulseWidth is
(tHRTIM_x_16, -- 111 ns (1/9 MHz) for tHRTIM = 1/144 MHz
tHRTIM_x_32,
tHRTIM_x_48,
tHRTIM_x_64,
tHRTIM_x_80,
tHRTIM_x_96,
tHRTIM_x_112,
tHRTIM_x_128,
tHRTIM_x_144,
tHRTIM_x_160,
tHRTIM_x_176,
tHRTIM_x_192,
tHRTIM_x_208,
tHRTIM_x_224,
tHRTIM_x_240,
tHRTIM_x_256);
-- Initial pulsewidth following a rising edge on output signal, defined by
-- t1STPW = tHRTIM x 16 x (STRPW[3:0]+1).
-- This bitfield cannot be modified when one of the CHPx bits is set.
procedure Configure_Chopper_Mode
(This : in out HRTimer_Channel;
Output1 : Boolean;
Output2 : Boolean;
Carrier_Frequency : Chopper_Carrier_Frequency;
Duty_Cycle : Chopper_Duty_Cycle;
Start_PulseWidth : Chopper_Start_PulseWidth)
with Pre => not Enabled (This) and
(not Enabled_Chopper_Mode (This, Output_1) or
not Enabled_Chopper_Mode (This, Output_2));
-- A high-frequency carrier can be added on top of the timing unit output
-- signals to drive isolation transformers. This is done in the output
-- stage before the polarity insertion to enable chopper on outputs 1 and 2.
-- See chapter 21.3.14 at pg. 690 in RM0364 rev. 4.
type Burst_Mode_Idle_Output is
(No_Action,
Inactive,
Active);
procedure Set_Burst_Mode_Idle_Output
(This : in out HRTimer_Channel;
Output : HRTimer_Channel_Output;
Mode : Burst_Mode_Idle_Output)
with Pre => not Enabled (This) or
(Enabled (This) and No_Outputs_Enabled (This));
-- The output is in idle state when requested by the burst mode controller.
procedure Set_Deadtime_Burst_Mode_Idle
(This : in out HRTimer_Channel;
Output : HRTimer_Channel_Output;
Enable : Boolean)
with Pre => not Enabled (This);
-- Delay the idle mode entry by forcing a deadtime insertion before
-- switching the outputs to their idle state. The deadtime value is set
-- by DTRx[8:0]. This setting only applies when entering the idle state
-- during a burst mode operation.
type HRTimer_State is (Disable, Enable);
type Channel_Output_Polarity is (High, Low);
procedure Set_Channel_Output_Polarity
(This : in out HRTimer_Channel;
Output : HRTimer_Channel_Output;
Polarity : Channel_Output_Polarity)
with Pre => not Enabled (This),
Post => Current_Channel_Output_Polarity (This, Output) = Polarity;
function Current_Channel_Output_Polarity
(This : HRTimer_Channel;
Output : HRTimer_Channel_Output) return Channel_Output_Polarity;
procedure Configure_Channel_Output
(This : in out HRTimer_Channel;
Mode : Counter_Operating_Mode;
State : HRTimer_State;
Output : HRTimer_Channel_Output;
Polarity : Channel_Output_Polarity;
Idle_State : Boolean);
-- Configure parameters for one channel output. If the output set/reset
-- events are already programmed, then the output state may be enabled,
-- otherwise it must be disabled, the set/reset events are programmed and
-- then the output is enabled. If any compare channel is used for set/reset
-- event, it must be programmed too.
procedure Configure_Channel_Output
(This : in out HRTimer_Channel;
Mode : Counter_Operating_Mode;
State : HRTimer_State;
Compare : HRTimer_Compare_Number;
Pulse : UInt16;
Output : HRTimer_Channel_Output;
Polarity : Channel_Output_Polarity;
Idle_State : Boolean);
-- Configure all parameters for one channel output with set/reset events
-- already programmed (set on timer period and reset on compare value).
-- The output state may be enabled or disabled.
procedure Configure_Channel_Output
(This : in out HRTimer_Channel;
Mode : Counter_Operating_Mode;
State : HRTimer_State;
Polarity : Channel_Output_Polarity;
Idle_State : Boolean;
Complementary_Polarity : Channel_Output_Polarity;
Complementary_Idle_State : Boolean);
-- Configure parameters for channel outputs. If the outputs set/reset
-- events are already programmed, then the output state may be enabled,
-- otherwise it must be disabled, the set/reset events are programmed and
-- then the output is enabled. If any compare channel is used for set/reset
-- event, it must be programmed too.
procedure Configure_Channel_Output
(This : in out HRTimer_Channel;
Mode : Counter_Operating_Mode;
State : HRTimer_State;
Compare : HRTimer_Compare_Number;
Pulse : UInt16;
Polarity : Channel_Output_Polarity;
Idle_State : Boolean;
Complementary_Polarity : Channel_Output_Polarity;
Complementary_Idle_State : Boolean);
-- Configure all parameters for channel outputs with set/reset events
-- already programmed (set on timer period and reset on compare value for
-- Output_1 and vice-versa for Output_2), so the outputs are in opposite
-- phases. The outputs state may be enabled or disabled.
type Delayed_Idle_Protection_Enum is
(Option_1,
Option_2,
Option_3,
Option_4,
Option_5,
Option_6,
Option_7,
Option_8)
with Size => 3;
-- Define the source and outputs on which the delayed protection schemes
-- are applied.
-- Option HRTimer_A HRTimer_D
-- HRTimer_B HRTimer_E
-- HRTimer_D
--
-- 1 Output_1_External_Event_6 Output_1_External_Event_8
-- 2 Output_2_External_Event_6 Output_2_External_Event_8
-- 3 Output_12_External_Event_6 Output_12External_Event_8
-- 4 Balanced_Idle_External_Event_6 Balanced_Idle_External_Event_8
-- 5 Output_1_External_Event_7 Output_1_External_Event_9
-- 6 Output_2_External_Event_7 Output_2_External_Event_9
-- 7 Output_12_External_Event_7 Output_12External_Event_9
-- 8 Balanced_Idle_External_Event_7 Balanced_Idle_External_Event_9
type Delayed_Idle_Protection is record
Enabled : Boolean;
Value : Delayed_Idle_Protection_Enum;
end record with Size => 4;
for Delayed_Idle_Protection use record
Enabled at 0 range 3 .. 3;
Value at 0 range 0 .. 2;
end record;
procedure Set_Delayed_Idle_Protection
(This : in out HRTimer_Channel;
Option : Delayed_Idle_Protection)
with Pre => not Enabled (This) and
(if Option.Enabled then
Current_Delayed_Idle_Protection (This).Enabled);
function Current_Delayed_Idle_Protection
(This : in out HRTimer_Channel) return Delayed_Idle_Protection;
type HRTimer_Fault_Source is
(Fault_1,
Fault_2,
Fault_3,
Fault_4,
Fault_5);
procedure Set_Fault_Source
(This : in out HRTimer_Channel;
Source : HRTimer_Fault_Source;
Enable : Boolean)
with Pre => not Enabled_Fault_Source_Lock (This),
Post => Enabled_Fault_Source (This, Source) = Enable;
-- Fault protection circuitry to disable the outputs in case of an
-- abnormal operation. See chapter 21.3.15 pg. 691 in RM0364 ver. 4.
function Enabled_Fault_Source
(This : HRTimer_Channel; Source : HRTimer_Fault_Source) return Boolean;
procedure Enable_Fault_Source_Lock
(This : in out HRTimer_Channel)
with Post => Enabled_Fault_Source_Lock (This);
-- Prevents the fault value and sign to be modified.
function Enabled_Fault_Source_Lock (This : HRTimer_Channel) return Boolean;
----------------------------------------------------------------------------
-- HRTimer Common functions -----------------------------------------------
----------------------------------------------------------------------------
type HRTimer_Register_Update is (Enable, Disable, Imediate);
procedure Set_Register_Update
(Counter : HRTimer;
Update : HRTimer_Register_Update);
-- The updates are enabled or temporarily disabled to allow the software to
-- write multiple registers that have to be simultaneously taken into
-- account. Also forces an immediate transfer from the preload to the
-- active register in the timer and any pending update request is canceled.
procedure Enable_Software_Reset (Counter : HRTimer);
-- Forces a timer reset.
procedure Set_Register_Update
(Counters : HRTimer_List;
Update : HRTimer_Register_Update);
-- Updates some/all timers simultaneously.
-- The updates are enabled or temporarily disabled to allow the software to
-- write multiple registers that have to be simultaneously taken into
-- account. Also forces an immediate transfer from the preload to the
-- active register in the timer and any pending update request is canceled.
procedure Enable_Software_Reset (Counters : HRTimer_List);
-- Forces a timer reset for some/all timers simultaneously.
type HRTimer_Common_Interrupt is
(Fault_1_Interrupt,
Fault_2_Interrupt,
Fault_3_Interrupt,
Fault_4_Interrupt,
Fault_5_Interrupt,
System_Fault_Interrupt,
DLL_Ready_Interrupt,
Burst_Mode_Period_Interrupt);
procedure Enable_Interrupt (Source : HRTimer_Common_Interrupt)
with Post => Interrupt_Enabled (Source);
type HRTimer_Common_Interrupt_List is
array (Positive range <>) of HRTimer_Common_Interrupt;
procedure Enable_Interrupt (Sources : HRTimer_Common_Interrupt_List)
with Post => (for all Source of Sources => Interrupt_Enabled (Source));
procedure Disable_Interrupt (Source : HRTimer_Common_Interrupt)
with Post => not Interrupt_Enabled (Source);
function Interrupt_Enabled
(Source : HRTimer_Common_Interrupt) return Boolean;
function Interrupt_Status
(Source : HRTimer_Common_Interrupt) return Boolean;
procedure Clear_Pending_Interrupt (Source : HRTimer_Common_Interrupt);
procedure Set_Channel_Output
(This : HRTimer_Channel;
Output : HRTimer_Channel_Output;
Enable : Boolean)
with Post => (if Output = Output_1 then
(if Enable then Output_Status (This)(1) = Enabled
else Output_Status (This)(1) = Idle or
Output_Status (This)(1) = Fault)
elsif Output = Output_2 then
(if Enable then Output_Status (This)(2) = Enabled
else Output_Status (This)(2) = Idle or
Output_Status (This)(2) = Fault));
-- Enable/disable the output 1 or 2 for any HRTimer A to E.
procedure Set_Channel_Outputs
(This : HRTimer_Channel;
Enable : Boolean)
with Inline,
Post => Enable = not No_Outputs_Enabled (This);
-- Enable/disable the outputs 1 and 2 for any HRTimer A to E.
procedure Set_Channel_Outputs
(Channels : HRTimer_List;
Enable : Boolean)
with Inline;
-- Enable/disable the outputs 1 and 2 for several HRTimer from A to E.
type HRTimer_Channel_Output_Status is (Idle, Fault, Enabled);
type Output_Status_List is
array (Positive range 1 .. 2) of HRTimer_Channel_Output_Status;
function Output_Status (This : HRTimer_Channel) return Output_Status_List;
function Channel_Output_Enabled
(This : HRTimer_Channel;
Output : HRTimer_Channel_Output) return Boolean;
function No_Outputs_Enabled (This : HRTimer_Channel) return Boolean;
-- Indicates whether the outputs are disabled for all timer.
type Burst_Mode_Operating_Mode is (SingleShot, Continuous);
type Burst_Mode_HRTimer_Mode is (Running, Stopped);
-- When running, the HRTimer counter clock is maintained and the timer
-- operates normally. When stopped, the HRTimer counter clock is stopped
-- and the counter is reset.
type Burst_Mode_Clock_Source is
(Master_Timer_Counter, -- Reset/roll-over
Timer_A_Counter,
Timer_B_Counter,
Timer_C_Counter,
Timer_D_Counter,
Timer_E_Counter,
Event_1,
Event_2,
Event_3,
Event_4,
Prescaler_fHRTIM_Clock);
type Burst_Mode_Prescaler is
(No_Division,
fHRTIM_Over_2,
fHRTIM_Over_4,
fHRTIM_Over_8,
fHRTIM_Over_16,
fHRTIM_Over_32,
fHRTIM_Over_64,
fHRTIM_Over_128,
fHRTIM_Over_256,
fHRTIM_Over_512,
fHRTIM_Over_1024,
fHRTIM_Over_2048,
fHRTIM_Over_4096,
fHRTIM_Over_8192,
fHRTIM_Over_16384,
fHRTIM_Over_32768);
procedure Enable_Burst_Mode
with Pre => HRTIM_Common_Periph.BMPER.BMPER /= 16#0000#,
Post => Burst_Mode_Enabled;
-- Starts the burst mode controller, which becomes ready to receive the
-- start trigger.
-- The BMPER[15:0] must not be null when the burst mode is enabled.
procedure Disable_Burst_Mode
with Post => not Burst_Mode_Enabled;
-- Causes a burst mode early termination.
function Burst_Mode_Enabled return Boolean;
function Burst_Mode_Status return Boolean;
-- Indicates that a burst operation is on-going.
procedure Configure_Burst_Mode
(Operating_Mode : Burst_Mode_Operating_Mode;
Clock_Source : Burst_Mode_Clock_Source;
Prescaler : Burst_Mode_Prescaler;
Preload_Enable : Boolean);
procedure Configure_HRTimer_Burst_Mode
(Counter : HRTimer;
Mode : Burst_Mode_HRTimer_Mode);
-- To simplify the bit-field access to the Burst Mode Trigger register,
-- we remap it as 32-bit registers. This way we program several bits
-- "oring" them in a 32-bit value, instead of accessing bit-by-bit.
type Burst_Mode_Trigger_Event is
(Software_Start,
Master_Reset,
Master_Repetition,
Master_Compare_1,
Master_Compare_2,
Master_Compare_3,
Master_Compare_4,
HRTimer_A_Reset,
HRTimer_A_Repetition,
HRTimer_A_Compare_1,
HRTimer_A_Compare_2,
HRTimer_B_Reset,
HRTimer_B_Repetition,
HRTimer_B_Compare_1,
HRTimer_B_Compare_2,
HRTimer_C_Reset,
HRTimer_C_Repetition,
HRTimer_C_Compare_1,
HRTimer_C_Compare_2,
HRTimer_D_Reset,
HRTimer_D_Repetition,
HRTimer_D_Compare_1,
HRTimer_D_Compare_2,
HRTimer_E_Reset,
HRTimer_E_Repetition,
HRTimer_E_Compare_1,
HRTimer_E_Compare_2,
HRTimer_A_Period_After_EEvent_7,
HRTimer_D_Period_After_EEvent_8,
External_Event_7,
External_Event_8,
OnChip_Event_Rising_Edge);
type Burst_Mode_Trigger_List is
array (Natural range <>) of Burst_Mode_Trigger_Event;
procedure Configure_Burst_Mode_Trigger
(Triggers : Burst_Mode_Trigger_List;
Enable : Boolean);
-- Enable/disable one or several burst mode triggers.
procedure Set_Burst_Mode_Compare (Value : UInt16)
with Pre => (if (HRTIM_Common_Periph.BMCR.BMCLK = 2#1010# and
HRTIM_Common_Periph.BMCR.BMPRSC = 2#0000#)
then HRTIM_Common_Periph.BMCMPR.BMCMP /= 16#0000#);
-- Defines the number of periods during which the selected timers are in
-- idle state. This register holds either the content of the preload
-- register or the content of the active register if the preload is
-- disabled.
-- BMCMP[15:0] cannot be set to 0x0000 when using the fHRTIM clock without
-- a prescaler as the burst mode clock source, (BMCLK[3:0] = 1010 and
-- BMPRESC[3:0] = 0000).
procedure Set_Burst_Mode_Period (Value : UInt16);
-- Defines the burst mode repetition periode (corresponding to the sum of
-- the idle and run periods). This register holds either the content of the
-- preload register or the content of the active register if preload is
-- disabled.
type External_Event_Source is
(EExSrc1,
EExSrc2,
EExSrc3,
EExSrc4);
type External_Event_Polarity is (Active_High, Active_Low);
type External_Event_Sensitivity is
(Active_Level, -- defined by polarity bit
Rising_Edge,
Falling_Edge,
Both_Edges);
type External_Event_Fast_Mode is (fHRTIM_Latency, Low_Latency);
-- External Event is re-synchronized by the HRTIM logic before acting
-- on outputs, which adds a fHRTIM clock-related latency, or acts
-- asynchronously on outputs (low latency).
type External_Event_Frequency_Filter is
(No_Filter, -- FLT acts assynchronously
fHRTIM_N2,
fHRTIM_N4,
fHRTIM_N8,
fFLTS_Over_2_N6,
fFLTS_Over_2_N8,
fFLTS_Over_4_N6,
fFLTS_Over_4_N8,
fFLTS_Over_8_N6,
fFLTS_Over_8_N8,
fFLTS_Over_16_N5,
fFLTS_Over_16_N6,
fFLTS_Over_16_N8,
fFLTS_Over_32_N5,
fFLTS_Over_32_N6,
fFLTS_Over_32_N8);
procedure Configure_External_Event
(Event : External_Event_Number;
Source : External_Event_Source;
Polarity : External_Event_Polarity;
Sensitivity : External_Event_Sensitivity;
Fast_Mode : External_Event_Fast_Mode;
Filter : External_Event_Frequency_Filter);
-- For events 1 to 5, filter has no effect; for events 6 to 10, fast mode
-- has no effect.
type External_Event_Sampling_Clock is
(fHRTIM,
fHRTIM_Over_2,
fHRTIM_Over_4,
fHRTIM_Over_8);
procedure Set_External_Event_Clock
(Clock : External_Event_Sampling_Clock);
-- Set the division ratio between the timer clock frequency (fHRTIM) and
-- the external event sampling clock (fEEVS) used by the digital filters.
-- To simplify the bit-field access to the ADC Trigger Source registers,
-- we remap them as 32-bit registers. This way we program several bits
-- "oring" them in a 32-bit value, instead of accessing bit-by-bit.
type ADC_Trigger_Output is
(ADC_Trigger_1,
ADC_Trigger_2,
ADC_Trigger_3,
ADC_Trigger_4);
type ADC_Trigger_Source is
(Master_Compare_1,
Master_Compare_2,
Master_Compare_3,
Master_Compare_4,
Master_Period,
Option_6,
Option_7,
Option_8,
Option_9,
Option_10,
HRTimer_A_Compare_2,
HRTimer_A_Compare_3,
HRTimer_A_Compare_4,
HRTimer_A_Period,
Option_15,
Option_16,
Option_17,
Option_18,
Option_19,
Option_20,
Option_21,
Option_22,
Option_23,
Option_24,
Option_25,
Option_26,
Option_27,
Option_28,
Option_29,
Option_30,
Option_31,
Option_32);
-- These bits select the trigger source for the ADC Trigger output.
-- Option ADC13 ADC24
-- 6 External_Event_1 External_Event_6
-- 7 External_Event_2 External_Event_7
-- 8 External_Event_3 External_Event_8
-- 9 External_Event_4 External_Event_9
-- 10 External_Event_5 External_Event_10
-- 15 HRTimer_A_Reset HRTimer_B_Compare_2
-- 16 HRTimer_B_Compare_2 HRTimer_B_Compare_3
-- 17 HRTimer_B_Compare_3 HRTimer_B_Compare_4
-- 18 HRTimer_B_Compare_4 HRTimer_B_Period
-- 19 HRTimer_B_Period HRTimer_C_Compare_2
-- 20 HRTimer_B_Reset HRTimer_C_Compare_3
-- 21 HRTimer_C_Compare_2 HRTimer_C_Compare_4
-- 22 HRTimer_C_Compare_3 HRTimer_C_Period
-- 23 HRTimer_C_Compare_4 HRTimer_C_Reset
-- 24 HRTimer_C_Period HRTimer_D_Compare_2
-- 25 HRTimer_D_Compare_2 HRTimer_D_Compare_3
-- 26 HRTimer_D_Compare_3 HRTimer_D_Compare_4
-- 27 HRTimer_D_Compare_4 HRTimer_D_Period
-- 28 HRTimer_D_Period HRTimer_D_Reset
-- 29 HRTimer_E_Compare_2 HRTimer_E_Compare_2
-- 30 HRTimer_E_Compare_3 HRTimer_E_Compare_3
-- 31 HRTimer_E_Compare_4 HRTimer_E_Compare_4
-- 32 HRTimer_E_Period HRTimer_E_Reset
procedure Configure_ADC_Trigger
(Output : ADC_Trigger_Output;
Source : ADC_Trigger_Source);
type ADC_Trigger_Update_Source is
(Master_Timer,
Timer_A,
Timer_B,
Timer_C,
Timer_D,
Timer_E);
procedure Configure_ADC_Trigger_Update
(Output : ADC_Trigger_Output;
Source : ADC_Trigger_Update_Source);
type DLL_Calibration is
(tHRTIMx2E20, -- 7.3 ms
tHRTIMx2E17, -- 910 ux
tHRTIMx2E14, -- 114 us
tHRTIMx2E11 -- 14 us
);
procedure Configure_DLL_Calibration
(Calibration_Start : Boolean;
Periodic_Calibration : Boolean;
Calibration_Rate : DLL_Calibration);
-- PLL calibration must be done before starting HRTIM master and timing
-- units. See RM0364 rev 4 Chapter 21.3.22 pg. 709 for the sequence of
-- initialization.
procedure Set_Fault_Input
(Input : HRTimer_Fault_Source;
Enable : Boolean);
function Enabled_Fault_Input
(Input : HRTimer_Fault_Source) return Boolean;
type Fault_Input_Polarity is (Active_Low, Active_High);
type Fault_Input_Source is (HRTIM_FLTx_Input, FLTx_Int_Signal);
type Fault_Input_Filter is
(No_Filter, -- FLT acts assynchronously
fHRTIM_N2,
fHRTIM_N4,
fHRTIM_N8,
fFLTS_Over_2_N6,
fFLTS_Over_2_N8,
fFLTS_Over_4_N6,
fFLTS_Over_4_N8,
fFLTS_Over_8_N6,
fFLTS_Over_8_N8,
fFLTS_Over_16_N5,
fFLTS_Over_16_N6,
fFLTS_Over_16_N8,
fFLTS_Over_32_N5,
fFLTS_Over_32_N6,
fFLTS_Over_32_N8);
procedure Configure_Fault_Input
(Input : HRTimer_Fault_Source;
Enable : Boolean;
Polarity : Fault_Input_Polarity;
Source : Fault_Input_Source;
Filter : Fault_Input_Filter)
with Pre => not Enabled_Fault_Input_Lock (Input);
type Fault_Input_Sampling_Clock is
(fHRTIM,
fHRTIM_Over_2,
fHRTIM_Over_4,
fHRTIM_Over_8);
procedure Configure_Fault_Input_Clock (Clock : Fault_Input_Sampling_Clock);
-- Set the division ratio between the timer clock frequency (fHRTIM) and
-- the fault signal sampling clock (fFLTS) used by the digital filters.
-- To simplify the bit-field access to the Burst DMA Timer Update registers,
-- we remap them as 32-bit registers. This way we program several bits
-- "oring" them in a 32-bit value, instead of accessing bit-by-bit.
procedure Enable_Fault_Input_Lock (Input : HRTimer_Fault_Source)
with Post => Enabled_Fault_Input_Lock (Input);
-- Prevents the fault enable, polarity, source and filter to be modified.
function Enabled_Fault_Input_Lock
(Input : HRTimer_Fault_Source) return Boolean;
type Burst_DMA_Master_Update is
(MCR_Register,
MICR_Register,
MDIER_Register,
MCNTR_Register,
MPER_Register,
MREP_Register,
MCMP1R_Register,
MCMP2R_Register,
MCMP3R_Register,
MCMP4R_Register);
type Burst_DMA_Master_Update_List is
array (Natural range <>) of Burst_DMA_Master_Update;
procedure Set_Burst_DMA_Timer_Update
(Counter : HRTimer_Master;
Registers : Burst_DMA_Master_Update_List;
Enable : Boolean);
-- Defines which master timer register is part of the list of registers
-- to be updated by the Burst DMA.
type Burst_DMA_Timer_Channel_Update is
(HRTIM_TIMxCR_Register,
HRTIM_TIMxICR_Register,
HRTIM_TIMxDIER_Register,
HRTIM_CNTxR_Register,
HRTIM_PERxR_Register,
HRTIM_REPxR_Register,
HRTIM_CMP1xR_Register,
HRTIM_CMP2xR_Register,
HRTIM_CMP3xR_Register,
HRTIM_CMP4xR_Register,
HRTIM_DTxR_Register,
HRTIM_SET1xR_Register,
HRTIM_RST1xR_Register,
HRTIM_SET2xR_Register,
HRTIM_RST2xR_Register,
HRTIM_EEFxR1_Register,
HRTIM_EEFxR2_Register,
HRTIM_RSTxR_Register,
HRTIM_CHPxR_Register,
HRTIM_OUTxR_Register,
HRTIM_FLTxR_Register);
type Burst_DMA_Timer_Channel_Update_List is
array (Natural range <>) of Burst_DMA_Timer_Channel_Update;
procedure Set_Burst_DMA_Timer_Update
(Counter : HRTimer_Channel;
Registers : Burst_DMA_Timer_Channel_Update_List;
Enable : Boolean);
-- Defines which timer X register is part of the list of registers
-- to be updated by the Burst DMA.
procedure Set_Burst_DMA_Data (Data : UInt32);
-- Writting this value triggers the copy of the data value into the
-- registers enabled in BDTxUPR and BDMUPR register bits and the increment
-- of the register pointer to the next location to be filled.
private
-- High Resolution Timer: Master
type HRTimer_Master is new STM32_SVD.HRTIM.HRTIM_Master_Peripheral;
-- Timerx Control Register
type TIMxCR_Register is record
-- HRTIM Timer x Clock prescaler
CKPSCx : TIMACR_CKPSCx_Field := 16#0#;
-- Continuous mode
CONT : Boolean := False;
-- Re-triggerable mode
RETRIG : Boolean := False;
-- Half mode enable
HALF : Boolean := False;
-- Push-Pull mode enable
PSHPLL : Boolean := False;
-- unspecified
Reserved_7_9 : HAL.UInt3 := 16#0#;
-- Synchronization Resets Timer x
SYNCRSTx : Boolean := False;
-- Synchronization Starts Timer x
SYNCSTRTx : Boolean := False;
-- Delayed CMP2 mode
DELCMP : TIMACR_DELCMP_Field :=
(As_Array => False, Val => 16#0#);
-- unspecified
Reserved_16_16 : HAL.Bit := 16#0#;
-- Timer x Repetition update
TxREPU : Boolean := False;
-- Timerx reset update
TxRSTU : Boolean := False;
-- TAU
TAU : Boolean := False;
-- TBU
TBU : Boolean := False;
-- TCU
TCU : Boolean := False;
-- TDU
TDU : Boolean := False;
-- TEU
TEU : Boolean := False;
-- Master Timer update
MSTU : Boolean := False;
-- AC Synchronization
DACSYNC : TIMACR_DACSYNC_Field := 16#0#;
-- Preload enable
PREEN : Boolean := False;
-- Update Gating
UPDGAT : TIMACR_UPDGAT_Field := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for TIMxCR_Register use record
CKPSCx at 0 range 0 .. 2;
CONT at 0 range 3 .. 3;
RETRIG at 0 range 4 .. 4;
HALF at 0 range 5 .. 5;
PSHPLL at 0 range 6 .. 6;
Reserved_7_9 at 0 range 7 .. 9;
SYNCRSTx at 0 range 10 .. 10;
SYNCSTRTx at 0 range 11 .. 11;
DELCMP at 0 range 12 .. 15;
Reserved_16_16 at 0 range 16 .. 16;
TxREPU at 0 range 17 .. 17;
TxRSTU at 0 range 18 .. 18;
TAU at 0 range 19 .. 19;
TBU at 0 range 20 .. 20;
TCU at 0 range 21 .. 21;
TDU at 0 range 22 .. 22;
TEU at 0 range 23 .. 23;
MSTU at 0 range 24 .. 24;
DACSYNC at 0 range 25 .. 26;
PREEN at 0 range 27 .. 27;
UPDGAT at 0 range 28 .. 31;
end record;
-- High Resolution Timer: TIMx
type HRTimer_Channel is record
-- Timerx Control Register
TIMxCR : aliased TIMxCR_Register;
-- Timerx Interrupt Status Register
TIMxISR : aliased TIMAISR_Register;
-- Timerx Interrupt Clear Register
TIMxICR : aliased TIMAICR_Register;
-- TIMxDIER5
TIMxDIER : aliased TIMADIER_Register;
-- Timerx Counter Register
CNTxR : aliased CNTAR_Register;
-- Timerx Period Register
PERxR : aliased PERAR_Register;
-- Timerx Repetition Register
REPxR : aliased REPAR_Register;
-- Timerx Compare 1 Register
CMP1xR : aliased CMP1AR_Register;
-- Timerx Compare 1 Compound Register
CMP1CxR : aliased CMP1CAR_Register;
-- Timerx Compare 2 Register
CMP2xR : aliased CMP2AR_Register;
-- Timerx Compare 3 Register
CMP3xR : aliased CMP3AR_Register;
-- Timerx Compare 4 Register
CMP4xR : aliased CMP4AR_Register;
-- Timerx Capture 1 Register
CPT1xR : aliased CPT1AR_Register;
-- Timerx Capture 2 Register
CPT2xR : aliased CPT2AR_Register;
-- Timerx Deadtime Register
DTxR : aliased DTAR_Register;
-- Timerx Output1 Set Register
SETx1R : HAL.UInt32;
-- Timerx Output1 Reset Register
RSTx1R : HAL.UInt32;
-- Timerx Output2 Set Register
SETx2R : HAL.UInt32;
-- Timerx Output2 Reset Register
RSTx2R : HAL.UInt32;
-- Timerx External Event Filtering Register 1
EEFxR1 : aliased EEFAR1_Register;
-- Timerx External Event Filtering Register 2
EEFxR2 : aliased EEFAR2_Register;
-- TimerA Reset Register
RSTxR : HAL.UInt32;
-- Timerx Chopper Register
CHPxR : aliased CHPAR_Register;
-- Timerx Capture 2 Control Register
CPT1xCR : HAL.UInt32;
-- CPT2xCR
CPT2xCR : HAL.UInt32;
-- Timerx Output Register
OUTxR : aliased OUTAR_Register;
-- Timerx Fault Register
FLTxR : aliased FLTAR_Register;
end record
with Volatile;
for HRTimer_Channel use record
TIMxCR at 16#0# range 0 .. 31;
TIMxISR at 16#4# range 0 .. 31;
TIMxICR at 16#8# range 0 .. 31;
TIMxDIER at 16#C# range 0 .. 31;
CNTxR at 16#10# range 0 .. 31;
PERxR at 16#14# range 0 .. 31;
REPxR at 16#18# range 0 .. 31;
CMP1xR at 16#1C# range 0 .. 31;
CMP1CxR at 16#20# range 0 .. 31;
CMP2xR at 16#24# range 0 .. 31;
CMP3xR at 16#28# range 0 .. 31;
CMP4xR at 16#2C# range 0 .. 31;
CPT1xR at 16#30# range 0 .. 31;
CPT2xR at 16#34# range 0 .. 31;
DTxR at 16#38# range 0 .. 31;
SETx1R at 16#3C# range 0 .. 31;
RSTx1R at 16#40# range 0 .. 31;
SETx2R at 16#44# range 0 .. 31;
RSTx2R at 16#48# range 0 .. 31;
EEFxR1 at 16#4C# range 0 .. 31;
EEFxR2 at 16#50# range 0 .. 31;
RSTxR at 16#54# range 0 .. 31;
CHPxR at 16#58# range 0 .. 31;
CPT1xCR at 16#5C# range 0 .. 31;
CPT2xCR at 16#60# range 0 .. 31;
OUTxR at 16#64# range 0 .. 31;
FLTxR at 16#68# range 0 .. 31;
end record;
-- High Resolution Timer: Common functions
type HRTimer_Common_Peripheral is record
-- Control Register 1
CR1 : aliased CR1_Register;
-- Control Register 2
CR2 : aliased CR2_Register;
-- Interrupt Status Register
ISR : aliased ISR_Register;
-- Interrupt Clear Register
ICR : aliased ICR_Register;
-- Interrupt Enable Register
IER : aliased IER_Register;
-- Output Enable Register
OENR : aliased OENR_Register;
-- DISR
ODISR : aliased ODISR_Register;
-- Output Disable Status Register
ODSR : aliased ODSR_Register;
-- Burst Mode Control Register
BMCR : aliased BMCR_Register;
-- BMTRGR
BMTRGR : aliased HAL.UInt32;
-- BMCMPR
BMCMPR : aliased BMCMPR_Register;
-- Burst Mode Period Register
BMPER : aliased BMPER_Register;
-- Timer External Event Control Register 1
EECR1 : aliased EECR1_Register;
-- Timer External Event Control Register 2
EECR2 : aliased EECR2_Register;
-- Timer External Event Control Register 3
EECR3 : aliased EECR3_Register;
-- ADC Trigger 1 Register
ADC1R : aliased HAL.UInt32;
-- ADC Trigger 2 Register
ADC2R : aliased HAL.UInt32;
-- ADC Trigger 3 Register
ADC3R : aliased HAL.UInt32;
-- ADC Trigger 4 Register
ADC4R : aliased HAL.UInt32;
-- DLL Control Register
DLLCR : aliased DLLCR_Register;
-- HRTIM Fault Input Register 1
FLTINR1 : aliased FLTINR1_Register;
-- HRTIM Fault Input Register 2
FLTINR2 : aliased FLTINR2_Register;
-- BDMUPR
BDMUPR : aliased HAL.UInt32;
-- Burst DMA Timerx update Register
BDTAUPR : aliased HAL.UInt32;
-- Burst DMA Timerx update Register
BDTBUPR : aliased HAL.UInt32;
-- Burst DMA Timerx update Register
BDTCUPR : aliased HAL.UInt32;
-- Burst DMA Timerx update Register
BDTDUPR : aliased HAL.UInt32;
-- Burst DMA Timerx update Register
BDTEUPR : aliased HAL.UInt32;
-- Burst DMA Data Register
BDMADR : aliased HAL.UInt32;
end record
with Volatile;
for HRTimer_Common_Peripheral use record
CR1 at 16#00# range 0 .. 31;
CR2 at 16#04# range 0 .. 31;
ISR at 16#08# range 0 .. 31;
ICR at 16#0C# range 0 .. 31;
IER at 16#10# range 0 .. 31;
OENR at 16#14# range 0 .. 31;
ODISR at 16#18# range 0 .. 31;
ODSR at 16#1C# range 0 .. 31;
BMCR at 16#20# range 0 .. 31;
BMTRGR at 16#24# range 0 .. 31;
BMCMPR at 16#28# range 0 .. 31;
BMPER at 16#2C# range 0 .. 31;
EECR1 at 16#30# range 0 .. 31;
EECR2 at 16#34# range 0 .. 31;
EECR3 at 16#38# range 0 .. 31;
ADC1R at 16#3C# range 0 .. 31;
ADC2R at 16#40# range 0 .. 31;
ADC3R at 16#44# range 0 .. 31;
ADC4R at 16#48# range 0 .. 31;
DLLCR at 16#4C# range 0 .. 31;
FLTINR1 at 16#50# range 0 .. 31;
FLTINR2 at 16#54# range 0 .. 31;
BDMUPR at 16#58# range 0 .. 31;
BDTAUPR at 16#5C# range 0 .. 31;
BDTBUPR at 16#60# range 0 .. 31;
BDTCUPR at 16#64# range 0 .. 31;
BDTDUPR at 16#68# range 0 .. 31;
BDTEUPR at 16#6C# range 0 .. 31;
BDMADR at 16#70# range 0 .. 31;
end record;
-- High Resolution Timer: Common functions
HRTimer_Common_Periph : aliased HRTimer_Common_Peripheral
with Import, Address => HRTIM_Common_Base;
end STM32.HRTimers;
|
-- The Village of Vampire by YT, このソースコードはNYSLです
-- renderer ver.3
with Ada.Calendar;
with Ada.Streams;
with Web.Producers;
with Tabula.Villages.Lists;
with Vampire.Forms;
package Vampire.R3 is
function Read (
Template_Source : in String;
Template_Cache : in String := "")
return Web.Producers.Template;
private
function Day_Name (
Day : Natural;
Today : Natural;
State : Tabula.Villages.Village_State)
return String;
procedure Raise_Unknown_Tag (
Tag : in String;
File : in String := Ada.Debug.File;
Line : in Integer := Ada.Debug.Line);
pragma No_Return (Raise_Unknown_Tag);
-- ログインパネル
procedure Handle_User_Panel (
Output : not null access Ada.Streams.Root_Stream_Type'Class;
Template : in Web.Producers.Template;
Form : in Forms.Root_Form_Type'Class;
User_Id : in String;
User_Password : in String);
-- 村リスト
procedure Handle_Village_List (
Output : not null access Ada.Streams.Root_Stream_Type'Class;
Template : in Web.Producers.Template;
Form : in Forms.Root_Form_Type'Class;
Current_Directory : in String;
HTML_Directory : in String;
Summaries : in Tabula.Villages.Lists.Summary_Maps.Map;
Log : in Boolean;
Limits : in Natural;
User_Id : in String;
User_Password : in String);
-- 発言
procedure Handle_Speech (
Output : not null access Ada.Streams.Root_Stream_Type'Class;
Template : in Web.Producers.Template;
Tag : in String := "";
Form : in Forms.Root_Form_Type'Class;
Current_Directory : in String;
Image_Directory : in String;
Face_Width : in Integer;
Face_Height : in Integer;
Subject : in Tabula.Villages.Person_Type'Class;
Text : in String;
Time : in Ada.Calendar.Time; -- 時刻嘘表示用
Filter : in String);
end Vampire.R3;
|
package body STM32.FMAC is
----------------
-- Reset_FMAC --
----------------
procedure Reset_FMAC (This : in out FMAC_Accelerator) is
begin
This.CR.RESET := True;
end Reset_FMAC;
-----------------------------
-- Set_FMAC_Buffer_Address --
-----------------------------
procedure Set_FMAC_Buffer_Address
(This : in out FMAC_Accelerator;
Buffer : FMAC_Buffer;
Base_Address : UInt8)
is
begin
case Buffer is
when X1 =>
This.X1BUFCFG.X1_BASE := Base_Address;
when X2 =>
This.X2BUFCFG.X2_BASE := Base_Address;
when Y =>
This.YBUFCFG.Y_BASE := Base_Address;
end case;
end Set_FMAC_Buffer_Address;
--------------------------
-- Set_FMAC_Buffer_Size --
--------------------------
procedure Set_FMAC_Buffer_Size
(This : in out FMAC_Accelerator;
Buffer : FMAC_Buffer;
Size : UInt8)
is
begin
case Buffer is
when X1 =>
This.X1BUFCFG.X1_BUF_SIZE := Size;
when X2 =>
This.X2BUFCFG.X2_BUF_SIZE := Size;
when Y =>
This.YBUFCFG.Y_BUF_SIZE := Size;
end case;
end Set_FMAC_Buffer_Size;
-------------------------------
-- Set_FMAC_Buffer_Watermark --
-------------------------------
procedure Set_FMAC_Buffer_Watermark
(This : in out FMAC_Accelerator;
Buffer : FMAC_Buffer;
Watermark : FMAC_Watermark := Threshold_1)
is
begin
case Buffer is
when X1 =>
This.X1BUFCFG.FULL_WM := Watermark'Enum_Rep;
when X2 =>
null;
when Y =>
This.YBUFCFG.EMPTY_WM := Watermark'Enum_Rep;
end case;
end Set_FMAC_Buffer_Watermark;
---------------------------
-- Configure_FMAC_Buffer --
---------------------------
procedure Configure_FMAC_Buffer
(This : in out FMAC_Accelerator;
Buffer : FMAC_Buffer;
Base_Address : UInt8;
Size : UInt8;
Watermark : FMAC_Watermark := Threshold_1)
is
begin
case Buffer is
when X1 =>
This.X1BUFCFG.X1_BASE := Base_Address;
This.X1BUFCFG.X1_BUF_SIZE := Size;
This.X1BUFCFG.FULL_WM := Watermark'Enum_Rep;
when X2 =>
This.X2BUFCFG.X2_BASE := Base_Address;
This.X2BUFCFG.X2_BUF_SIZE := Size;
when Y =>
This.YBUFCFG.Y_BASE := Base_Address;
This.YBUFCFG.Y_BUF_SIZE := Size;
This.YBUFCFG.EMPTY_WM := Watermark'Enum_Rep;
end case;
end Configure_FMAC_Buffer;
---------------------
-- Initialize_FMAC --
---------------------
procedure Initialize_FMAC
(This : in out FMAC_Accelerator;
Config : FMAC_Buffer_Configuration)
is
begin
-- Configure X2 buffer for coefficients
This.X2BUFCFG.X2_BASE := Config.Coeff_Base_Address;
This.X2BUFCFG.X2_BUF_SIZE := Config.Coeff_Buffer_Size;
-- Configure X1 buffer for input values
This.X1BUFCFG.X1_BASE := Config.Input_Base_Address;
This.X1BUFCFG.X1_BUF_SIZE := Config.Input_Buffer_Size;
This.X1BUFCFG.FULL_WM := Config.Input_Buffer_Threshold'Enum_Rep;
-- Configure Y buffer for output values
This.YBUFCFG.Y_BASE := Config.Output_Base_Address;
This.YBUFCFG.Y_BUF_SIZE := Config.Output_Buffer_Size;
This.YBUFCFG.EMPTY_WM := Config.Output_Buffer_Threshold'Enum_Rep;
This.CR.CLIPEN := Config.Clipping;
end Initialize_FMAC;
--------------------
-- Set_FMAC_Start --
--------------------
procedure Set_FMAC_Start
(This : in out FMAC_Accelerator;
Start : Boolean)
is
begin
This.PARAM.START := Start;
end Set_FMAC_Start;
------------------
-- FMAC_Started --
------------------
function FMAC_Started (This : FMAC_Accelerator) return Boolean is
begin
return This.PARAM.START;
end FMAC_Started;
-------------------------------
-- Configure_FMAC_Parameters --
-------------------------------
procedure Configure_FMAC_Parameters
(This : in out FMAC_Accelerator;
Operation : FMAC_Function;
Input_P : UInt8;
Input_Q : UInt8 := 0;
Input_R : UInt8 := 0)
is
begin
This.PARAM.P := Input_P;
case Operation is
when Load_X2_Buffer =>
This.PARAM.Q := Input_Q;
when FIR_Filter_Convolution =>
This.PARAM.R := Input_R;
when IIR_Filter_Direct_Form_1 =>
This.PARAM.Q := Input_Q;
This.PARAM.R := Input_R;
when others => null;
end case;
This.PARAM.FUNC := Operation'Enum_Rep;
end Configure_FMAC_Parameters;
---------------------
-- Write_FMAC_Data --
---------------------
procedure Write_FMAC_Data
(This : in out FMAC_Accelerator;
Data : UInt16)
is
begin
This.WDATA.WDATA := Data;
end Write_FMAC_Data;
--------------------
-- Read_FMAC_Data --
--------------------
function Read_FMAC_Data
(This : FMAC_Accelerator) return UInt16
is
begin
return This.RDATA.RDATA;
end Read_FMAC_Data;
-----------------------
-- Write_FMAC_Buffer --
-----------------------
procedure Write_FMAC_Buffer
(This : in out FMAC_Accelerator;
Vector : Block_Q1_15)
is
begin
for N in Vector'Range loop
This.WDATA.WDATA := Q1_15_To_UInt16 (Vector (N));
end loop;
end Write_FMAC_Buffer;
----------------------
-- Preload_Buffers --
----------------------
procedure Preload_Buffers
(This : in out FMAC_Accelerator;
Filter : FMAC_Filter_Function;
Input_Vector : Block_Q1_15;
Coeff_Vector_B : Block_Q1_15;
Coeff_Vector_A : Block_Q1_15;
Output_Vector : Block_Q1_15)
is
begin
-- Make shure there is no DMA nor interrupt enabled since no flow
-- control is required.
if This.CR.RIEN then
This.CR.RIEN := False;
end if;
if This.CR.WIEN then
This.CR.WIEN := False;
end if;
if This.CR.DMAREN then
This.CR.DMAREN := False;
end if;
if This.CR.DMAWEN then
This.CR.DMAWEN := False;
end if;
-- Preload X1 buffer
if Input_Vector'Length /= 0 then
This.PARAM.P := Input_Vector'Size;
This.PARAM.FUNC := Load_X1_Buffer'Enum_Rep;
This.PARAM.START := True;
for N in Input_Vector'Range loop
This.WDATA.WDATA := Q1_15_To_UInt16 (Input_Vector (N));
end loop;
-- Test if START bit is reset
pragma Assert (This.PARAM.START = True, "Preload X1 not done");
end if;
-- Preload X2 buffer
This.PARAM.P := Coeff_Vector_B'Length;
if Filter = IIR_Filter_Direct_Form_1 then
This.PARAM.Q := Coeff_Vector_A'Length;
end if;
This.PARAM.FUNC := Load_X2_Buffer'Enum_Rep;
This.PARAM.START := True;
for N in Coeff_Vector_B'Range loop
This.WDATA.WDATA := Q1_15_To_UInt16 (Coeff_Vector_B (N));
end loop;
if Filter = IIR_Filter_Direct_Form_1 then
for M in Coeff_Vector_A'Range loop
This.WDATA.WDATA := Q1_15_To_UInt16 (Coeff_Vector_A (M));
end loop;
end if;
-- Test if START bit is reset
pragma Assert (This.PARAM.START = True, "Preload X2 not done");
-- Preload Y buffer
if Output_Vector'Length /= 0 then
This.PARAM.P := Output_Vector'Size;
This.PARAM.FUNC := Load_Y_Buffer'Enum_Rep;
This.PARAM.START := True;
for N in Output_Vector'Range loop
This.WDATA.WDATA := Q1_15_To_UInt16 (Output_Vector (N));
end loop;
-- Test if START bit is reset
pragma Assert (This.PARAM.START = True, "Preload Y not done");
end if;
end Preload_Buffers;
-----------------------
-- Set_FMAC_Clipping --
-----------------------
procedure Set_FMAC_Clipping
(This : in out FMAC_Accelerator;
Enable : Boolean)
is
begin
This.CR.CLIPEN := Enable;
end Set_FMAC_Clipping;
------------
-- Status --
------------
function Status
(This : FMAC_Accelerator;
Flag : FMAC_Status) return Boolean
is
begin
case Flag is
when Y_Buffer_Empty =>
return This.SR.YEMPTY;
when X1_Buffer_Full =>
return This.SR.X1FULL;
when Overflow_Error =>
return This.SR.OVFL;
when Underflow_Error =>
return This.SR.UNFL;
when Saturation_Error =>
return This.SR.SAT;
end case;
end Status;
-------------------
-- Set_Interrupt --
-------------------
procedure Set_Interrupt
(This : in out FMAC_Accelerator;
Interrupt : FMAC_Interrupt;
Enable : Boolean)
is
begin
case Interrupt is
when Read_Interrupt =>
This.CR.RIEN := Enable;
when Write_Interrupt =>
This.CR.WIEN := Enable;
when Overflow_Error =>
This.CR.OVFLIEN := Enable;
when Underflow_Error =>
This.CR.UNFLIEN := Enable;
when Saturation_Error =>
This.CR.SATIEN := Enable;
end case;
end Set_Interrupt;
-----------------------
-- Interrupt_Enabled --
-----------------------
function Interrupt_Enabled
(This : FMAC_Accelerator;
Interrupt : FMAC_Interrupt) return Boolean
is
begin
case Interrupt is
when Read_Interrupt =>
return This.CR.RIEN;
when Write_Interrupt =>
return This.CR.WIEN;
when Overflow_Error =>
return This.CR.OVFLIEN;
when Underflow_Error =>
return This.CR.UNFLIEN;
when Saturation_Error =>
return This.CR.SATIEN;
end case;
end Interrupt_Enabled;
-------------
-- Set_DMA --
-------------
procedure Set_DMA
(This : in out FMAC_Accelerator;
DMA : FMAC_DMA;
Enable : Boolean)
is
begin
case DMA is
when Read_DMA =>
This.CR.DMAREN := Enable;
when Write_DMA =>
This.CR.DMAWEN := Enable;
end case;
end Set_DMA;
-----------------
-- DMA_Enabled --
-----------------
function DMA_Enabled
(This : FMAC_Accelerator;
DMA : FMAC_DMA)
return Boolean
is
begin
case DMA is
when Read_DMA =>
return This.CR.DMAREN;
when Write_DMA =>
return This.CR.DMAWEN;
end case;
end DMA_Enabled;
end STM32.FMAC;
|
with Ada.Characters.Wide_Wide_Latin_1;
with Ada.Wide_Wide_Text_IO;
with League.Strings;
with Ada_Pretty;
procedure Ada_Output_Test is
function "+" (Text : Wide_Wide_String)
return League.Strings.Universal_String
renames League.Strings.To_Universal_String;
procedure Print_API;
procedure Print_Core_Spec_And_Body;
F : aliased Ada_Pretty.Factory;
Convention : constant Ada_Pretty.Node_Access := F.New_Aspect
(F.New_Name (+"Convention"),
F.New_Name (+"C"));
Import : constant Ada_Pretty.Node_Access := F.New_Aspect
(F.New_Name (+"Import"),
F.New_Name (+"True"));
LF : constant Wide_Wide_Character := Ada.Characters.Wide_Wide_Latin_1.LF;
---------------
-- Print_API --
---------------
procedure Print_API is
Name : constant Ada_Pretty.Node_Access :=
F.New_Selected_Name (+"Qt_Ada.API.Strings");
Clause : constant Ada_Pretty.Node_Access := F.New_With
(F.New_Selected_Name (+"System.Storage_Elements"));
Preelaborate : constant Ada_Pretty.Node_Access := F.New_Pragma
(F.New_Name (+"Preelaborate"));
QString : constant Ada_Pretty.Node_Access :=
F.New_Name (+"QString");
QString_Type : constant Ada_Pretty.Node_Access := F.New_Type
(Name => QString,
Definition => F.New_Record,
Aspects => Convention);
QString_Access : constant Ada_Pretty.Node_Access := F.New_Type
(Name => F.New_Name (+"QString_Access"),
Definition => F.New_Access (Ada_Pretty.Access_All, QString),
Aspects => Convention);
Link_Name : constant Ada_Pretty.Node_Access := F.New_Aspect
(F.New_Name (+"Link_Name"),
F.New_String_Literal (+"__qtada__QString__storage_size"));
Aspect_List : constant Ada_Pretty.Node_Access :=
F.New_List
(F.New_List (Import, Convention),
Link_Name);
QString_Storage_Size : constant Ada_Pretty.Node_Access :=
F.New_Variable
(Name => F.New_Name (+"QString_Storage_Size"),
Type_Definition => F.New_Selected_Name
(+"System.Storage_Elements.Storage_Offset"),
Is_Constant => True,
Aspects => Aspect_List);
Public : constant Ada_Pretty.Node_Access := F.New_List
((Preelaborate, QString_Type, QString_Access, QString_Storage_Size));
Root : constant Ada_Pretty.Node_Access :=
F.New_Package (Name, Public);
Unit : constant Ada_Pretty.Node_Access :=
F.New_Compilation_Unit (Root, Clause);
begin
Ada.Wide_Wide_Text_IO.Put_Line
(F.To_Text (Unit).Join (LF).To_Wide_Wide_String);
end Print_API;
------------------------------
-- Print_Core_Spec_And_Body --
------------------------------
procedure Print_Core_Spec_And_Body is
Name : constant Ada_Pretty.Node_Access :=
F.New_Selected_Name (+"Qt5.Qt_Core.Strings");
With_1 : constant Ada_Pretty.Node_Access := F.New_With
(F.New_Selected_Name (+"Ada.Finalization"), Is_Private => True);
With_2 : constant Ada_Pretty.Node_Access := F.New_With
(F.New_Selected_Name (+"System.Storage_Elements"), Is_Private => True);
With_3 : constant Ada_Pretty.Node_Access := F.New_With
(F.New_Selected_Name (+"Qt_Ada.API.Strings"), Is_Private => True);
Clause : constant Ada_Pretty.Node_Access :=
F.New_List ((With_1, With_2, With_3));
Q_String : constant Ada_Pretty.Node_Access :=
F.New_Name (+"Q_String");
Q_String_Type : constant Ada_Pretty.Node_Access := F.New_Type
(Name => Q_String,
Definition => F.New_Private_Record (Is_Tagged => True));
QString_View : constant Ada_Pretty.Node_Access := F.New_Variable
(Name => F.New_Name (+"QString_View"),
Type_Definition => F.New_Selected_Name
(+"Qt_Ada.API.Strings.QString_Access"));
Is_Wrapper : constant Ada_Pretty.Node_Access := F.New_Variable
(Name => F.New_Name (+"Is_Wrapper"),
Type_Definition => F.New_Name (+"Boolean"));
Storage : constant Ada_Pretty.Node_Access := F.New_Variable
(Name => F.New_Name (+"Storage"),
Type_Definition => F.New_Apply
(F.New_Selected_Name (+"System.Storage_Elements.Storage_Array"),
F.New_List
(F.New_Literal (1),
F.New_Infix
(+"..",
F.New_Selected_Name
(+"Qt_Ada.API.Strings.QString_Storage_Size")))));
Q_String_Type_Full : constant Ada_Pretty.Node_Access := F.New_Type
(Name => Q_String,
Definition => F.New_Record
(Parent => F.New_Selected_Name (+"Ada.Finalization.Controlled"),
Components => F.New_List ((QString_View, Is_Wrapper, Storage))));
Self_Q_String : constant Ada_Pretty.Node_Access := F.New_Parameter
(Name => F.New_Name (+"Self"),
Is_In => True,
Is_Out => True,
Type_Definition => Q_String);
Initialize : constant Ada_Pretty.Node_Access :=
F.New_Subprogram_Specification
(Is_Overriding => Ada_Pretty.True,
Name => F.New_Name (+"Initialize"),
Parameters => Self_Q_String);
Adjust : constant Ada_Pretty.Node_Access :=
F.New_Subprogram_Specification
(Is_Overriding => Ada_Pretty.True,
Name => F.New_Name (+"Adjust"),
Parameters => Self_Q_String);
Finalize : constant Ada_Pretty.Node_Access :=
F.New_Subprogram_Specification
(Is_Overriding => Ada_Pretty.True,
Name => F.New_Name (+"Finalize"),
Parameters => Self_Q_String);
Private_Part : constant Ada_Pretty.Node_Access :=
F.New_List ((Q_String_Type_Full,
F.New_Subprogram_Declaration (Initialize),
F.New_Subprogram_Declaration (Adjust),
F.New_Subprogram_Declaration (Finalize)));
Spec_Root : constant Ada_Pretty.Node_Access :=
F.New_Package (Name, Q_String_Type, Private_Part);
Spec_Unit : constant Ada_Pretty.Node_Access :=
F.New_Compilation_Unit (Spec_Root, Clause);
QString_Access : constant Ada_Pretty.Node_Access :=
F.New_Selected_Name (+"Qt_Ada.API.Strings.QString_Access");
Self_QString_Access : constant Ada_Pretty.Node_Access :=
F.New_Parameter
(Name => F.New_Name (+"Self"),
Is_In => True,
Is_Out => True,
Type_Definition => QString_Access);
Address : constant Ada_Pretty.Node_Access :=
F.New_Selected_Name (+"System.Address");
Storage_Param : constant Ada_Pretty.Node_Access :=
F.New_Parameter
(Name => F.New_Name (+"Storage"),
Type_Definition => Address);
QString_initialize : constant Ada_Pretty.Node_Access :=
F.New_Subprogram_Declaration
(F.New_Subprogram_Specification
(Name => F.New_Name (+"QString_initialize"),
Parameters =>
F.New_List (Self_QString_Access, Storage_Param)),
Aspects => F.New_List
((Import,
Convention,
F.New_Aspect
(F.New_Name (+"Link_Name"),
F.New_String_Literal (+"QString___initialize")))));
QString_finalize : constant Ada_Pretty.Node_Access :=
F.New_Subprogram_Declaration
(F.New_Subprogram_Specification
(Name => F.New_Name (+"QString_finalize"),
Parameters => Self_QString_Access),
Aspects => F.New_List
((Import,
Convention,
F.New_Aspect
(F.New_Name (+"Link_Name"),
F.New_String_Literal (+"QString__finalize")))));
QString_adjust : constant Ada_Pretty.Node_Access :=
F.New_Subprogram_Declaration
(F.New_Subprogram_Specification
(Name => F.New_Name (+"QString_adjust"),
Parameters =>
F.New_List (Self_QString_Access, Storage_Param)),
Aspects => F.New_List
((Import,
Convention,
F.New_Aspect
(F.New_Name (+"Link_Name"),
F.New_String_Literal (+"QString__adjust")))));
Self_QString_View : constant Ada_Pretty.Node_Access :=
F.New_Selected_Name (+"Self.QString_View");
Adjust_Stmt_1 : constant Ada_Pretty.Node_Access :=
F.New_Statement
(F.New_Apply
(F.New_Name (+"QString_adjust"),
F.New_List
(Self_QString_View,
F.New_Selected_Name (+"Self.Storage'Address"))));
Adjust_Stmt_2 : constant Ada_Pretty.Node_Access :=
F.New_Assignment
(F.New_Selected_Name (+"Self.Is_Wrapper"),
F.New_Name (+"False"));
Adjust_Body : constant Ada_Pretty.Node_Access :=
F.New_Subprogram_Body
(Adjust,
Statements =>
F.New_List (Adjust_Stmt_1, Adjust_Stmt_2));
Finalize_Stmt : constant Ada_Pretty.Node_Access :=
F.New_If
(Condition => F.New_Selected_Name (+"Self.Is_Wrapper"),
Then_Path => F.New_Assignment
(Self_QString_View, F.New_Name (+"null")),
Elsif_List => F.New_Elsif
(Condition => F.New_List
(Self_QString_View,
F.New_Infix (+"/=", F.New_Name (+"null"))),
List => F.New_Statement
(F.New_Apply
(F.New_Name (+"QString_finalize"),
Self_QString_View))));
Finalize_Body : constant Ada_Pretty.Node_Access :=
F.New_Subprogram_Body
(Finalize,
Declarations => F.New_Use
(F.New_Selected_Name (+"Qt_Ada.API.Strings.QString_Access"),
Use_Type => True),
Statements => Finalize_Stmt);
Initialize_Stmt_1 : constant Ada_Pretty.Node_Access :=
F.New_Statement
(F.New_Apply
(F.New_Name (+"QString_initialize"),
F.New_List
(Self_QString_View,
F.New_Selected_Name (+"Self.Storage'Address"))));
Initialize_Body : constant Ada_Pretty.Node_Access :=
F.New_Subprogram_Body
(Initialize,
Statements =>
F.New_List (Initialize_Stmt_1, Adjust_Stmt_2));
Body_Root : constant Ada_Pretty.Node_Access :=
F.New_Package_Body
(Name,
F.New_List
((QString_initialize,
QString_finalize,
QString_adjust,
Adjust_Body,
Finalize_Body,
Initialize_Body)));
Body_Unit : constant Ada_Pretty.Node_Access :=
F.New_Compilation_Unit (Body_Root);
begin
Ada.Wide_Wide_Text_IO.Put_Line
(F.To_Text (Spec_Unit).Join (LF).To_Wide_Wide_String);
Ada.Wide_Wide_Text_IO.Put_Line
(F.To_Text (Body_Unit).Join (LF).To_Wide_Wide_String);
end Print_Core_Spec_And_Body;
begin
Print_API;
Print_Core_Spec_And_Body;
end Ada_Output_Test;
|
------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- E X P _ C H 4 --
-- --
-- B o d y --
-- --
-- Copyright (C) 1992-2006, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 2, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
-- for more details. You should have received a copy of the GNU General --
-- Public License distributed with GNAT; see file COPYING. If not, write --
-- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
-- Boston, MA 02110-1301, USA. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
with Atree; use Atree;
with Checks; use Checks;
with Einfo; use Einfo;
with Elists; use Elists;
with Errout; use Errout;
with Exp_Aggr; use Exp_Aggr;
with Exp_Ch3; use Exp_Ch3;
with Exp_Ch7; use Exp_Ch7;
with Exp_Ch9; use Exp_Ch9;
with Exp_Fixd; use Exp_Fixd;
with Exp_Pakd; use Exp_Pakd;
with Exp_Tss; use Exp_Tss;
with Exp_Util; use Exp_Util;
with Exp_VFpt; use Exp_VFpt;
with Freeze; use Freeze;
with Hostparm; use Hostparm;
with Inline; use Inline;
with Nlists; use Nlists;
with Nmake; use Nmake;
with Opt; use Opt;
with Rtsfind; use Rtsfind;
with Sem; use Sem;
with Sem_Cat; use Sem_Cat;
with Sem_Ch3; use Sem_Ch3;
with Sem_Ch13; use Sem_Ch13;
with Sem_Eval; use Sem_Eval;
with Sem_Res; use Sem_Res;
with Sem_Type; use Sem_Type;
with Sem_Util; use Sem_Util;
with Sem_Warn; use Sem_Warn;
with Sinfo; use Sinfo;
with Snames; use Snames;
with Stand; use Stand;
with Targparm; use Targparm;
with Tbuild; use Tbuild;
with Ttypes; use Ttypes;
with Uintp; use Uintp;
with Urealp; use Urealp;
with Validsw; use Validsw;
package body Exp_Ch4 is
-----------------------
-- Local Subprograms --
-----------------------
procedure Binary_Op_Validity_Checks (N : Node_Id);
pragma Inline (Binary_Op_Validity_Checks);
-- Performs validity checks for a binary operator
procedure Build_Boolean_Array_Proc_Call
(N : Node_Id;
Op1 : Node_Id;
Op2 : Node_Id);
-- If an boolean array assignment can be done in place, build call to
-- corresponding library procedure.
procedure Expand_Allocator_Expression (N : Node_Id);
-- Subsidiary to Expand_N_Allocator, for the case when the expression
-- is a qualified expression or an aggregate.
procedure Expand_Array_Comparison (N : Node_Id);
-- This routine handles expansion of the comparison operators (N_Op_Lt,
-- N_Op_Le, N_Op_Gt, N_Op_Ge) when operating on an array type. The basic
-- code for these operators is similar, differing only in the details of
-- the actual comparison call that is made. Special processing (call a
-- run-time routine)
function Expand_Array_Equality
(Nod : Node_Id;
Lhs : Node_Id;
Rhs : Node_Id;
Bodies : List_Id;
Typ : Entity_Id) return Node_Id;
-- Expand an array equality into a call to a function implementing this
-- equality, and a call to it. Loc is the location for the generated
-- nodes. Lhs and Rhs are the array expressions to be compared.
-- Bodies is a list on which to attach bodies of local functions that
-- are created in the process. It is the responsibility of the
-- caller to insert those bodies at the right place. Nod provides
-- the Sloc value for the generated code. Normally the types used
-- for the generated equality routine are taken from Lhs and Rhs.
-- However, in some situations of generated code, the Etype fields
-- of Lhs and Rhs are not set yet. In such cases, Typ supplies the
-- type to be used for the formal parameters.
procedure Expand_Boolean_Operator (N : Node_Id);
-- Common expansion processing for Boolean operators (And, Or, Xor)
-- for the case of array type arguments.
function Expand_Composite_Equality
(Nod : Node_Id;
Typ : Entity_Id;
Lhs : Node_Id;
Rhs : Node_Id;
Bodies : List_Id) return Node_Id;
-- Local recursive function used to expand equality for nested
-- composite types. Used by Expand_Record/Array_Equality, Bodies
-- is a list on which to attach bodies of local functions that are
-- created in the process. This is the responsability of the caller
-- to insert those bodies at the right place. Nod provides the Sloc
-- value for generated code. Lhs and Rhs are the left and right sides
-- for the comparison, and Typ is the type of the arrays to compare.
procedure Expand_Concatenate_Other (Cnode : Node_Id; Opnds : List_Id);
-- This routine handles expansion of concatenation operations, where
-- N is the N_Op_Concat node being expanded and Operands is the list
-- of operands (at least two are present). The caller has dealt with
-- converting any singleton operands into singleton aggregates.
procedure Expand_Concatenate_String (Cnode : Node_Id; Opnds : List_Id);
-- Routine to expand concatenation of 2-5 operands (in the list Operands)
-- and replace node Cnode with the result of the contatenation. If there
-- are two operands, they can be string or character. If there are more
-- than two operands, then are always of type string (i.e. the caller has
-- already converted character operands to strings in this case).
procedure Fixup_Universal_Fixed_Operation (N : Node_Id);
-- N is either an N_Op_Divide or N_Op_Multiply node whose result is
-- universal fixed. We do not have such a type at runtime, so the
-- purpose of this routine is to find the real type by looking up
-- the tree. We also determine if the operation must be rounded.
function Get_Allocator_Final_List
(N : Node_Id;
T : Entity_Id;
PtrT : Entity_Id) return Entity_Id;
-- If the designated type is controlled, build final_list expression
-- for created object. If context is an access parameter, create a
-- local access type to have a usable finalization list.
function Has_Inferable_Discriminants (N : Node_Id) return Boolean;
-- Ada 2005 (AI-216): A view of an Unchecked_Union object has inferable
-- discriminants if it has a constrained nominal type, unless the object
-- is a component of an enclosing Unchecked_Union object that is subject
-- to a per-object constraint and the enclosing object lacks inferable
-- discriminants.
--
-- An expression of an Unchecked_Union type has inferable discriminants
-- if it is either a name of an object with inferable discriminants or a
-- qualified expression whose subtype mark denotes a constrained subtype.
procedure Insert_Dereference_Action (N : Node_Id);
-- N is an expression whose type is an access. When the type of the
-- associated storage pool is derived from Checked_Pool, generate a
-- call to the 'Dereference' primitive operation.
function Make_Array_Comparison_Op
(Typ : Entity_Id;
Nod : Node_Id) return Node_Id;
-- Comparisons between arrays are expanded in line. This function
-- produces the body of the implementation of (a > b), where a and b
-- are one-dimensional arrays of some discrete type. The original
-- node is then expanded into the appropriate call to this function.
-- Nod provides the Sloc value for the generated code.
function Make_Boolean_Array_Op
(Typ : Entity_Id;
N : Node_Id) return Node_Id;
-- Boolean operations on boolean arrays are expanded in line. This
-- function produce the body for the node N, which is (a and b),
-- (a or b), or (a xor b). It is used only the normal case and not
-- the packed case. The type involved, Typ, is the Boolean array type,
-- and the logical operations in the body are simple boolean operations.
-- Note that Typ is always a constrained type (the caller has ensured
-- this by using Convert_To_Actual_Subtype if necessary).
procedure Rewrite_Comparison (N : Node_Id);
-- if N is the node for a comparison whose outcome can be determined at
-- compile time, then the node N can be rewritten with True or False. If
-- the outcome cannot be determined at compile time, the call has no
-- effect. If N is a type conversion, then this processing is applied to
-- its expression. If N is neither comparison nor a type conversion, the
-- call has no effect.
function Tagged_Membership (N : Node_Id) return Node_Id;
-- Construct the expression corresponding to the tagged membership test.
-- Deals with a second operand being (or not) a class-wide type.
function Safe_In_Place_Array_Op
(Lhs : Node_Id;
Op1 : Node_Id;
Op2 : Node_Id) return Boolean;
-- In the context of an assignment, where the right-hand side is a
-- boolean operation on arrays, check whether operation can be performed
-- in place.
procedure Unary_Op_Validity_Checks (N : Node_Id);
pragma Inline (Unary_Op_Validity_Checks);
-- Performs validity checks for a unary operator
-------------------------------
-- Binary_Op_Validity_Checks --
-------------------------------
procedure Binary_Op_Validity_Checks (N : Node_Id) is
begin
if Validity_Checks_On and Validity_Check_Operands then
Ensure_Valid (Left_Opnd (N));
Ensure_Valid (Right_Opnd (N));
end if;
end Binary_Op_Validity_Checks;
------------------------------------
-- Build_Boolean_Array_Proc_Call --
------------------------------------
procedure Build_Boolean_Array_Proc_Call
(N : Node_Id;
Op1 : Node_Id;
Op2 : Node_Id)
is
Loc : constant Source_Ptr := Sloc (N);
Kind : constant Node_Kind := Nkind (Expression (N));
Target : constant Node_Id :=
Make_Attribute_Reference (Loc,
Prefix => Name (N),
Attribute_Name => Name_Address);
Arg1 : constant Node_Id := Op1;
Arg2 : Node_Id := Op2;
Call_Node : Node_Id;
Proc_Name : Entity_Id;
begin
if Kind = N_Op_Not then
if Nkind (Op1) in N_Binary_Op then
-- Use negated version of the binary operators
if Nkind (Op1) = N_Op_And then
Proc_Name := RTE (RE_Vector_Nand);
elsif Nkind (Op1) = N_Op_Or then
Proc_Name := RTE (RE_Vector_Nor);
else pragma Assert (Nkind (Op1) = N_Op_Xor);
Proc_Name := RTE (RE_Vector_Xor);
end if;
Call_Node :=
Make_Procedure_Call_Statement (Loc,
Name => New_Occurrence_Of (Proc_Name, Loc),
Parameter_Associations => New_List (
Target,
Make_Attribute_Reference (Loc,
Prefix => Left_Opnd (Op1),
Attribute_Name => Name_Address),
Make_Attribute_Reference (Loc,
Prefix => Right_Opnd (Op1),
Attribute_Name => Name_Address),
Make_Attribute_Reference (Loc,
Prefix => Left_Opnd (Op1),
Attribute_Name => Name_Length)));
else
Proc_Name := RTE (RE_Vector_Not);
Call_Node :=
Make_Procedure_Call_Statement (Loc,
Name => New_Occurrence_Of (Proc_Name, Loc),
Parameter_Associations => New_List (
Target,
Make_Attribute_Reference (Loc,
Prefix => Op1,
Attribute_Name => Name_Address),
Make_Attribute_Reference (Loc,
Prefix => Op1,
Attribute_Name => Name_Length)));
end if;
else
-- We use the following equivalences:
-- (not X) or (not Y) = not (X and Y) = Nand (X, Y)
-- (not X) and (not Y) = not (X or Y) = Nor (X, Y)
-- (not X) xor (not Y) = X xor Y
-- X xor (not Y) = not (X xor Y) = Nxor (X, Y)
if Nkind (Op1) = N_Op_Not then
if Kind = N_Op_And then
Proc_Name := RTE (RE_Vector_Nor);
elsif Kind = N_Op_Or then
Proc_Name := RTE (RE_Vector_Nand);
else
Proc_Name := RTE (RE_Vector_Xor);
end if;
else
if Kind = N_Op_And then
Proc_Name := RTE (RE_Vector_And);
elsif Kind = N_Op_Or then
Proc_Name := RTE (RE_Vector_Or);
elsif Nkind (Op2) = N_Op_Not then
Proc_Name := RTE (RE_Vector_Nxor);
Arg2 := Right_Opnd (Op2);
else
Proc_Name := RTE (RE_Vector_Xor);
end if;
end if;
Call_Node :=
Make_Procedure_Call_Statement (Loc,
Name => New_Occurrence_Of (Proc_Name, Loc),
Parameter_Associations => New_List (
Target,
Make_Attribute_Reference (Loc,
Prefix => Arg1,
Attribute_Name => Name_Address),
Make_Attribute_Reference (Loc,
Prefix => Arg2,
Attribute_Name => Name_Address),
Make_Attribute_Reference (Loc,
Prefix => Op1,
Attribute_Name => Name_Length)));
end if;
Rewrite (N, Call_Node);
Analyze (N);
exception
when RE_Not_Available =>
return;
end Build_Boolean_Array_Proc_Call;
---------------------------------
-- Expand_Allocator_Expression --
---------------------------------
procedure Expand_Allocator_Expression (N : Node_Id) is
Loc : constant Source_Ptr := Sloc (N);
Exp : constant Node_Id := Expression (Expression (N));
Indic : constant Node_Id := Subtype_Mark (Expression (N));
PtrT : constant Entity_Id := Etype (N);
DesigT : constant Entity_Id := Designated_Type (PtrT);
T : constant Entity_Id := Entity (Indic);
Flist : Node_Id;
Node : Node_Id;
Temp : Entity_Id;
TagT : Entity_Id := Empty;
-- Type used as source for tag assignment
TagR : Node_Id := Empty;
-- Target reference for tag assignment
Aggr_In_Place : constant Boolean := Is_Delayed_Aggregate (Exp);
Tag_Assign : Node_Id;
Tmp_Node : Node_Id;
begin
if Is_Tagged_Type (T) or else Controlled_Type (T) then
-- Actions inserted before:
-- Temp : constant ptr_T := new T'(Expression);
-- <no CW> Temp._tag := T'tag;
-- <CTRL> Adjust (Finalizable (Temp.all));
-- <CTRL> Attach_To_Final_List (Finalizable (Temp.all));
-- We analyze by hand the new internal allocator to avoid
-- any recursion and inappropriate call to Initialize
if not Aggr_In_Place then
Remove_Side_Effects (Exp);
end if;
Temp :=
Make_Defining_Identifier (Loc, New_Internal_Name ('P'));
-- For a class wide allocation generate the following code:
-- type Equiv_Record is record ... end record;
-- implicit subtype CW is <Class_Wide_Subytpe>;
-- temp : PtrT := new CW'(CW!(expr));
if Is_Class_Wide_Type (T) then
Expand_Subtype_From_Expr (Empty, T, Indic, Exp);
Set_Expression (Expression (N),
Unchecked_Convert_To (Entity (Indic), Exp));
Analyze_And_Resolve (Expression (N), Entity (Indic));
end if;
if Aggr_In_Place then
Tmp_Node :=
Make_Object_Declaration (Loc,
Defining_Identifier => Temp,
Object_Definition => New_Reference_To (PtrT, Loc),
Expression =>
Make_Allocator (Loc,
New_Reference_To (Etype (Exp), Loc)));
Set_Comes_From_Source
(Expression (Tmp_Node), Comes_From_Source (N));
Set_No_Initialization (Expression (Tmp_Node));
Insert_Action (N, Tmp_Node);
if Controlled_Type (T)
and then Ekind (PtrT) = E_Anonymous_Access_Type
then
-- Create local finalization list for access parameter
Flist := Get_Allocator_Final_List (N, Base_Type (T), PtrT);
end if;
Convert_Aggr_In_Allocator (Tmp_Node, Exp);
else
Node := Relocate_Node (N);
Set_Analyzed (Node);
Insert_Action (N,
Make_Object_Declaration (Loc,
Defining_Identifier => Temp,
Constant_Present => True,
Object_Definition => New_Reference_To (PtrT, Loc),
Expression => Node));
end if;
-- Ada 2005 (AI-344): For an allocator with a class-wide designated
-- type, generate an accessibility check to verify that the level of
-- the type of the created object is not deeper than the level of the
-- access type. If the type of the qualified expression is class-
-- wide, then always generate the check. Otherwise, only generate the
-- check if the level of the qualified expression type is statically
-- deeper than the access type. Although the static accessibility
-- will generally have been performed as a legality check, it won't
-- have been done in cases where the allocator appears in generic
-- body, so a run-time check is needed in general.
if Ada_Version >= Ada_05
and then Is_Class_Wide_Type (DesigT)
and then not Scope_Suppress (Accessibility_Check)
and then
(Is_Class_Wide_Type (Etype (Exp))
or else
Type_Access_Level (Etype (Exp)) > Type_Access_Level (PtrT))
then
Insert_Action (N,
Make_Raise_Program_Error (Loc,
Condition =>
Make_Op_Gt (Loc,
Left_Opnd =>
Make_Function_Call (Loc,
Name =>
New_Reference_To (RTE (RE_Get_Access_Level), Loc),
Parameter_Associations =>
New_List (Make_Attribute_Reference (Loc,
Prefix =>
New_Reference_To (Temp, Loc),
Attribute_Name =>
Name_Tag))),
Right_Opnd =>
Make_Integer_Literal (Loc, Type_Access_Level (PtrT))),
Reason => PE_Accessibility_Check_Failed));
end if;
if Java_VM then
-- Suppress the tag assignment when Java_VM because JVM tags are
-- represented implicitly in objects.
null;
elsif Is_Tagged_Type (T) and then not Is_Class_Wide_Type (T) then
TagT := T;
TagR := New_Reference_To (Temp, Loc);
elsif Is_Private_Type (T)
and then Is_Tagged_Type (Underlying_Type (T))
then
TagT := Underlying_Type (T);
TagR :=
Unchecked_Convert_To (Underlying_Type (T),
Make_Explicit_Dereference (Loc,
Prefix => New_Reference_To (Temp, Loc)));
end if;
if Present (TagT) then
Tag_Assign :=
Make_Assignment_Statement (Loc,
Name =>
Make_Selected_Component (Loc,
Prefix => TagR,
Selector_Name =>
New_Reference_To (First_Tag_Component (TagT), Loc)),
Expression =>
Unchecked_Convert_To (RTE (RE_Tag),
New_Reference_To
(Elists.Node (First_Elmt (Access_Disp_Table (TagT))),
Loc)));
-- The previous assignment has to be done in any case
Set_Assignment_OK (Name (Tag_Assign));
Insert_Action (N, Tag_Assign);
end if;
if Controlled_Type (DesigT)
and then Controlled_Type (T)
then
declare
Attach : Node_Id;
Apool : constant Entity_Id :=
Associated_Storage_Pool (PtrT);
begin
-- If it is an allocation on the secondary stack
-- (i.e. a value returned from a function), the object
-- is attached on the caller side as soon as the call
-- is completed (see Expand_Ctrl_Function_Call)
if Is_RTE (Apool, RE_SS_Pool) then
declare
F : constant Entity_Id :=
Make_Defining_Identifier (Loc,
New_Internal_Name ('F'));
begin
Insert_Action (N,
Make_Object_Declaration (Loc,
Defining_Identifier => F,
Object_Definition => New_Reference_To (RTE
(RE_Finalizable_Ptr), Loc)));
Flist := New_Reference_To (F, Loc);
Attach := Make_Integer_Literal (Loc, 1);
end;
-- Normal case, not a secondary stack allocation
else
if Controlled_Type (T)
and then Ekind (PtrT) = E_Anonymous_Access_Type
then
-- Create local finalization list for access parameter
Flist :=
Get_Allocator_Final_List (N, Base_Type (T), PtrT);
else
Flist := Find_Final_List (PtrT);
end if;
Attach := Make_Integer_Literal (Loc, 2);
end if;
if not Aggr_In_Place then
Insert_Actions (N,
Make_Adjust_Call (
Ref =>
-- An unchecked conversion is needed in the
-- classwide case because the designated type
-- can be an ancestor of the subtype mark of
-- the allocator.
Unchecked_Convert_To (T,
Make_Explicit_Dereference (Loc,
Prefix => New_Reference_To (Temp, Loc))),
Typ => T,
Flist_Ref => Flist,
With_Attach => Attach,
Allocator => True));
end if;
end;
end if;
Rewrite (N, New_Reference_To (Temp, Loc));
Analyze_And_Resolve (N, PtrT);
elsif Aggr_In_Place then
Temp :=
Make_Defining_Identifier (Loc, New_Internal_Name ('P'));
Tmp_Node :=
Make_Object_Declaration (Loc,
Defining_Identifier => Temp,
Object_Definition => New_Reference_To (PtrT, Loc),
Expression => Make_Allocator (Loc,
New_Reference_To (Etype (Exp), Loc)));
Set_Comes_From_Source
(Expression (Tmp_Node), Comes_From_Source (N));
Set_No_Initialization (Expression (Tmp_Node));
Insert_Action (N, Tmp_Node);
Convert_Aggr_In_Allocator (Tmp_Node, Exp);
Rewrite (N, New_Reference_To (Temp, Loc));
Analyze_And_Resolve (N, PtrT);
elsif Is_Access_Type (DesigT)
and then Nkind (Exp) = N_Allocator
and then Nkind (Expression (Exp)) /= N_Qualified_Expression
then
-- Apply constraint to designated subtype indication
Apply_Constraint_Check (Expression (Exp),
Designated_Type (DesigT),
No_Sliding => True);
if Nkind (Expression (Exp)) = N_Raise_Constraint_Error then
-- Propagate constraint_error to enclosing allocator
Rewrite (Exp, New_Copy (Expression (Exp)));
end if;
else
-- First check against the type of the qualified expression
--
-- NOTE: The commented call should be correct, but for
-- some reason causes the compiler to bomb (sigsegv) on
-- ACVC test c34007g, so for now we just perform the old
-- (incorrect) test against the designated subtype with
-- no sliding in the else part of the if statement below.
-- ???
--
-- Apply_Constraint_Check (Exp, T, No_Sliding => True);
-- A check is also needed in cases where the designated
-- subtype is constrained and differs from the subtype
-- given in the qualified expression. Note that the check
-- on the qualified expression does not allow sliding,
-- but this check does (a relaxation from Ada 83).
if Is_Constrained (DesigT)
and then not Subtypes_Statically_Match
(T, DesigT)
then
Apply_Constraint_Check
(Exp, DesigT, No_Sliding => False);
-- The nonsliding check should really be performed
-- (unconditionally) against the subtype of the
-- qualified expression, but that causes a problem
-- with c34007g (see above), so for now we retain this.
else
Apply_Constraint_Check
(Exp, DesigT, No_Sliding => True);
end if;
-- For an access to unconstrained packed array, GIGI needs
-- to see an expression with a constrained subtype in order
-- to compute the proper size for the allocator.
if Is_Array_Type (T)
and then not Is_Constrained (T)
and then Is_Packed (T)
then
declare
ConstrT : constant Entity_Id :=
Make_Defining_Identifier (Loc,
Chars => New_Internal_Name ('A'));
Internal_Exp : constant Node_Id := Relocate_Node (Exp);
begin
Insert_Action (Exp,
Make_Subtype_Declaration (Loc,
Defining_Identifier => ConstrT,
Subtype_Indication =>
Make_Subtype_From_Expr (Exp, T)));
Freeze_Itype (ConstrT, Exp);
Rewrite (Exp, OK_Convert_To (ConstrT, Internal_Exp));
end;
end if;
end if;
exception
when RE_Not_Available =>
return;
end Expand_Allocator_Expression;
-----------------------------
-- Expand_Array_Comparison --
-----------------------------
-- Expansion is only required in the case of array types. For the
-- unpacked case, an appropriate runtime routine is called. For
-- packed cases, and also in some other cases where a runtime
-- routine cannot be called, the form of the expansion is:
-- [body for greater_nn; boolean_expression]
-- The body is built by Make_Array_Comparison_Op, and the form of the
-- Boolean expression depends on the operator involved.
procedure Expand_Array_Comparison (N : Node_Id) is
Loc : constant Source_Ptr := Sloc (N);
Op1 : Node_Id := Left_Opnd (N);
Op2 : Node_Id := Right_Opnd (N);
Typ1 : constant Entity_Id := Base_Type (Etype (Op1));
Ctyp : constant Entity_Id := Component_Type (Typ1);
Expr : Node_Id;
Func_Body : Node_Id;
Func_Name : Entity_Id;
Comp : RE_Id;
Byte_Addressable : constant Boolean := System_Storage_Unit = Byte'Size;
-- True for byte addressable target
function Length_Less_Than_4 (Opnd : Node_Id) return Boolean;
-- Returns True if the length of the given operand is known to be
-- less than 4. Returns False if this length is known to be four
-- or greater or is not known at compile time.
------------------------
-- Length_Less_Than_4 --
------------------------
function Length_Less_Than_4 (Opnd : Node_Id) return Boolean is
Otyp : constant Entity_Id := Etype (Opnd);
begin
if Ekind (Otyp) = E_String_Literal_Subtype then
return String_Literal_Length (Otyp) < 4;
else
declare
Ityp : constant Entity_Id := Etype (First_Index (Otyp));
Lo : constant Node_Id := Type_Low_Bound (Ityp);
Hi : constant Node_Id := Type_High_Bound (Ityp);
Lov : Uint;
Hiv : Uint;
begin
if Compile_Time_Known_Value (Lo) then
Lov := Expr_Value (Lo);
else
return False;
end if;
if Compile_Time_Known_Value (Hi) then
Hiv := Expr_Value (Hi);
else
return False;
end if;
return Hiv < Lov + 3;
end;
end if;
end Length_Less_Than_4;
-- Start of processing for Expand_Array_Comparison
begin
-- Deal first with unpacked case, where we can call a runtime routine
-- except that we avoid this for targets for which are not addressable
-- by bytes, and for the JVM, since the JVM does not support direct
-- addressing of array components.
if not Is_Bit_Packed_Array (Typ1)
and then Byte_Addressable
and then not Java_VM
then
-- The call we generate is:
-- Compare_Array_xn[_Unaligned]
-- (left'address, right'address, left'length, right'length) <op> 0
-- x = U for unsigned, S for signed
-- n = 8,16,32,64 for component size
-- Add _Unaligned if length < 4 and component size is 8.
-- <op> is the standard comparison operator
if Component_Size (Typ1) = 8 then
if Length_Less_Than_4 (Op1)
or else
Length_Less_Than_4 (Op2)
then
if Is_Unsigned_Type (Ctyp) then
Comp := RE_Compare_Array_U8_Unaligned;
else
Comp := RE_Compare_Array_S8_Unaligned;
end if;
else
if Is_Unsigned_Type (Ctyp) then
Comp := RE_Compare_Array_U8;
else
Comp := RE_Compare_Array_S8;
end if;
end if;
elsif Component_Size (Typ1) = 16 then
if Is_Unsigned_Type (Ctyp) then
Comp := RE_Compare_Array_U16;
else
Comp := RE_Compare_Array_S16;
end if;
elsif Component_Size (Typ1) = 32 then
if Is_Unsigned_Type (Ctyp) then
Comp := RE_Compare_Array_U32;
else
Comp := RE_Compare_Array_S32;
end if;
else pragma Assert (Component_Size (Typ1) = 64);
if Is_Unsigned_Type (Ctyp) then
Comp := RE_Compare_Array_U64;
else
Comp := RE_Compare_Array_S64;
end if;
end if;
Remove_Side_Effects (Op1, Name_Req => True);
Remove_Side_Effects (Op2, Name_Req => True);
Rewrite (Op1,
Make_Function_Call (Sloc (Op1),
Name => New_Occurrence_Of (RTE (Comp), Loc),
Parameter_Associations => New_List (
Make_Attribute_Reference (Loc,
Prefix => Relocate_Node (Op1),
Attribute_Name => Name_Address),
Make_Attribute_Reference (Loc,
Prefix => Relocate_Node (Op2),
Attribute_Name => Name_Address),
Make_Attribute_Reference (Loc,
Prefix => Relocate_Node (Op1),
Attribute_Name => Name_Length),
Make_Attribute_Reference (Loc,
Prefix => Relocate_Node (Op2),
Attribute_Name => Name_Length))));
Rewrite (Op2,
Make_Integer_Literal (Sloc (Op2),
Intval => Uint_0));
Analyze_And_Resolve (Op1, Standard_Integer);
Analyze_And_Resolve (Op2, Standard_Integer);
return;
end if;
-- Cases where we cannot make runtime call
-- For (a <= b) we convert to not (a > b)
if Chars (N) = Name_Op_Le then
Rewrite (N,
Make_Op_Not (Loc,
Right_Opnd =>
Make_Op_Gt (Loc,
Left_Opnd => Op1,
Right_Opnd => Op2)));
Analyze_And_Resolve (N, Standard_Boolean);
return;
-- For < the Boolean expression is
-- greater__nn (op2, op1)
elsif Chars (N) = Name_Op_Lt then
Func_Body := Make_Array_Comparison_Op (Typ1, N);
-- Switch operands
Op1 := Right_Opnd (N);
Op2 := Left_Opnd (N);
-- For (a >= b) we convert to not (a < b)
elsif Chars (N) = Name_Op_Ge then
Rewrite (N,
Make_Op_Not (Loc,
Right_Opnd =>
Make_Op_Lt (Loc,
Left_Opnd => Op1,
Right_Opnd => Op2)));
Analyze_And_Resolve (N, Standard_Boolean);
return;
-- For > the Boolean expression is
-- greater__nn (op1, op2)
else
pragma Assert (Chars (N) = Name_Op_Gt);
Func_Body := Make_Array_Comparison_Op (Typ1, N);
end if;
Func_Name := Defining_Unit_Name (Specification (Func_Body));
Expr :=
Make_Function_Call (Loc,
Name => New_Reference_To (Func_Name, Loc),
Parameter_Associations => New_List (Op1, Op2));
Insert_Action (N, Func_Body);
Rewrite (N, Expr);
Analyze_And_Resolve (N, Standard_Boolean);
exception
when RE_Not_Available =>
return;
end Expand_Array_Comparison;
---------------------------
-- Expand_Array_Equality --
---------------------------
-- Expand an equality function for multi-dimensional arrays. Here is
-- an example of such a function for Nb_Dimension = 2
-- function Enn (A : atyp; B : btyp) return boolean is
-- begin
-- if (A'length (1) = 0 or else A'length (2) = 0)
-- and then
-- (B'length (1) = 0 or else B'length (2) = 0)
-- then
-- return True; -- RM 4.5.2(22)
-- end if;
-- if A'length (1) /= B'length (1)
-- or else
-- A'length (2) /= B'length (2)
-- then
-- return False; -- RM 4.5.2(23)
-- end if;
-- declare
-- A1 : Index_T1 := A'first (1);
-- B1 : Index_T1 := B'first (1);
-- begin
-- loop
-- declare
-- A2 : Index_T2 := A'first (2);
-- B2 : Index_T2 := B'first (2);
-- begin
-- loop
-- if A (A1, A2) /= B (B1, B2) then
-- return False;
-- end if;
-- exit when A2 = A'last (2);
-- A2 := Index_T2'succ (A2);
-- B2 := Index_T2'succ (B2);
-- end loop;
-- end;
-- exit when A1 = A'last (1);
-- A1 := Index_T1'succ (A1);
-- B1 := Index_T1'succ (B1);
-- end loop;
-- end;
-- return true;
-- end Enn;
-- Note on the formal types used (atyp and btyp). If either of the
-- arrays is of a private type, we use the underlying type, and
-- do an unchecked conversion of the actual. If either of the arrays
-- has a bound depending on a discriminant, then we use the base type
-- since otherwise we have an escaped discriminant in the function.
-- If both arrays are constrained and have the same bounds, we can
-- generate a loop with an explicit iteration scheme using a 'Range
-- attribute over the first array.
function Expand_Array_Equality
(Nod : Node_Id;
Lhs : Node_Id;
Rhs : Node_Id;
Bodies : List_Id;
Typ : Entity_Id) return Node_Id
is
Loc : constant Source_Ptr := Sloc (Nod);
Decls : constant List_Id := New_List;
Index_List1 : constant List_Id := New_List;
Index_List2 : constant List_Id := New_List;
Actuals : List_Id;
Formals : List_Id;
Func_Name : Entity_Id;
Func_Body : Node_Id;
A : constant Entity_Id := Make_Defining_Identifier (Loc, Name_uA);
B : constant Entity_Id := Make_Defining_Identifier (Loc, Name_uB);
Ltyp : Entity_Id;
Rtyp : Entity_Id;
-- The parameter types to be used for the formals
function Arr_Attr
(Arr : Entity_Id;
Nam : Name_Id;
Num : Int) return Node_Id;
-- This builds the attribute reference Arr'Nam (Expr)
function Component_Equality (Typ : Entity_Id) return Node_Id;
-- Create one statement to compare corresponding components,
-- designated by a full set of indices.
function Get_Arg_Type (N : Node_Id) return Entity_Id;
-- Given one of the arguments, computes the appropriate type to
-- be used for that argument in the corresponding function formal
function Handle_One_Dimension
(N : Int;
Index : Node_Id) return Node_Id;
-- This procedure returns the following code
--
-- declare
-- Bn : Index_T := B'First (N);
-- begin
-- loop
-- xxx
-- exit when An = A'Last (N);
-- An := Index_T'Succ (An)
-- Bn := Index_T'Succ (Bn)
-- end loop;
-- end;
--
-- If both indices are constrained and identical, the procedure
-- returns a simpler loop:
--
-- for An in A'Range (N) loop
-- xxx
-- end loop
--
-- N is the dimension for which we are generating a loop. Index is the
-- N'th index node, whose Etype is Index_Type_n in the above code.
-- The xxx statement is either the loop or declare for the next
-- dimension or if this is the last dimension the comparison
-- of corresponding components of the arrays.
--
-- The actual way the code works is to return the comparison
-- of corresponding components for the N+1 call. That's neater!
function Test_Empty_Arrays return Node_Id;
-- This function constructs the test for both arrays being empty
-- (A'length (1) = 0 or else A'length (2) = 0 or else ...)
-- and then
-- (B'length (1) = 0 or else B'length (2) = 0 or else ...)
function Test_Lengths_Correspond return Node_Id;
-- This function constructs the test for arrays having different
-- lengths in at least one index position, in which case resull
-- A'length (1) /= B'length (1)
-- or else
-- A'length (2) /= B'length (2)
-- or else
-- ...
--------------
-- Arr_Attr --
--------------
function Arr_Attr
(Arr : Entity_Id;
Nam : Name_Id;
Num : Int) return Node_Id
is
begin
return
Make_Attribute_Reference (Loc,
Attribute_Name => Nam,
Prefix => New_Reference_To (Arr, Loc),
Expressions => New_List (Make_Integer_Literal (Loc, Num)));
end Arr_Attr;
------------------------
-- Component_Equality --
------------------------
function Component_Equality (Typ : Entity_Id) return Node_Id is
Test : Node_Id;
L, R : Node_Id;
begin
-- if a(i1...) /= b(j1...) then return false; end if;
L :=
Make_Indexed_Component (Loc,
Prefix => Make_Identifier (Loc, Chars (A)),
Expressions => Index_List1);
R :=
Make_Indexed_Component (Loc,
Prefix => Make_Identifier (Loc, Chars (B)),
Expressions => Index_List2);
Test := Expand_Composite_Equality
(Nod, Component_Type (Typ), L, R, Decls);
-- If some (sub)component is an unchecked_union, the whole operation
-- will raise program error.
if Nkind (Test) = N_Raise_Program_Error then
-- This node is going to be inserted at a location where a
-- statement is expected: clear its Etype so analysis will
-- set it to the expected Standard_Void_Type.
Set_Etype (Test, Empty);
return Test;
else
return
Make_Implicit_If_Statement (Nod,
Condition => Make_Op_Not (Loc, Right_Opnd => Test),
Then_Statements => New_List (
Make_Return_Statement (Loc,
Expression => New_Occurrence_Of (Standard_False, Loc))));
end if;
end Component_Equality;
------------------
-- Get_Arg_Type --
------------------
function Get_Arg_Type (N : Node_Id) return Entity_Id is
T : Entity_Id;
X : Node_Id;
begin
T := Etype (N);
if No (T) then
return Typ;
else
T := Underlying_Type (T);
X := First_Index (T);
while Present (X) loop
if Denotes_Discriminant (Type_Low_Bound (Etype (X)))
or else
Denotes_Discriminant (Type_High_Bound (Etype (X)))
then
T := Base_Type (T);
exit;
end if;
Next_Index (X);
end loop;
return T;
end if;
end Get_Arg_Type;
--------------------------
-- Handle_One_Dimension --
---------------------------
function Handle_One_Dimension
(N : Int;
Index : Node_Id) return Node_Id
is
Need_Separate_Indexes : constant Boolean :=
Ltyp /= Rtyp
or else not Is_Constrained (Ltyp);
-- If the index types are identical, and we are working with
-- constrained types, then we can use the same index for both of
-- the arrays.
An : constant Entity_Id := Make_Defining_Identifier (Loc,
Chars => New_Internal_Name ('A'));
Bn : Entity_Id;
Index_T : Entity_Id;
Stm_List : List_Id;
Loop_Stm : Node_Id;
begin
if N > Number_Dimensions (Ltyp) then
return Component_Equality (Ltyp);
end if;
-- Case where we generate a loop
Index_T := Base_Type (Etype (Index));
if Need_Separate_Indexes then
Bn :=
Make_Defining_Identifier (Loc,
Chars => New_Internal_Name ('B'));
else
Bn := An;
end if;
Append (New_Reference_To (An, Loc), Index_List1);
Append (New_Reference_To (Bn, Loc), Index_List2);
Stm_List := New_List (
Handle_One_Dimension (N + 1, Next_Index (Index)));
if Need_Separate_Indexes then
-- Generate guard for loop, followed by increments of indices
Append_To (Stm_List,
Make_Exit_Statement (Loc,
Condition =>
Make_Op_Eq (Loc,
Left_Opnd => New_Reference_To (An, Loc),
Right_Opnd => Arr_Attr (A, Name_Last, N))));
Append_To (Stm_List,
Make_Assignment_Statement (Loc,
Name => New_Reference_To (An, Loc),
Expression =>
Make_Attribute_Reference (Loc,
Prefix => New_Reference_To (Index_T, Loc),
Attribute_Name => Name_Succ,
Expressions => New_List (New_Reference_To (An, Loc)))));
Append_To (Stm_List,
Make_Assignment_Statement (Loc,
Name => New_Reference_To (Bn, Loc),
Expression =>
Make_Attribute_Reference (Loc,
Prefix => New_Reference_To (Index_T, Loc),
Attribute_Name => Name_Succ,
Expressions => New_List (New_Reference_To (Bn, Loc)))));
end if;
-- If separate indexes, we need a declare block for An and Bn, and a
-- loop without an iteration scheme.
if Need_Separate_Indexes then
Loop_Stm :=
Make_Implicit_Loop_Statement (Nod, Statements => Stm_List);
return
Make_Block_Statement (Loc,
Declarations => New_List (
Make_Object_Declaration (Loc,
Defining_Identifier => An,
Object_Definition => New_Reference_To (Index_T, Loc),
Expression => Arr_Attr (A, Name_First, N)),
Make_Object_Declaration (Loc,
Defining_Identifier => Bn,
Object_Definition => New_Reference_To (Index_T, Loc),
Expression => Arr_Attr (B, Name_First, N))),
Handled_Statement_Sequence =>
Make_Handled_Sequence_Of_Statements (Loc,
Statements => New_List (Loop_Stm)));
-- If no separate indexes, return loop statement with explicit
-- iteration scheme on its own
else
Loop_Stm :=
Make_Implicit_Loop_Statement (Nod,
Statements => Stm_List,
Iteration_Scheme =>
Make_Iteration_Scheme (Loc,
Loop_Parameter_Specification =>
Make_Loop_Parameter_Specification (Loc,
Defining_Identifier => An,
Discrete_Subtype_Definition =>
Arr_Attr (A, Name_Range, N))));
return Loop_Stm;
end if;
end Handle_One_Dimension;
-----------------------
-- Test_Empty_Arrays --
-----------------------
function Test_Empty_Arrays return Node_Id is
Alist : Node_Id;
Blist : Node_Id;
Atest : Node_Id;
Btest : Node_Id;
begin
Alist := Empty;
Blist := Empty;
for J in 1 .. Number_Dimensions (Ltyp) loop
Atest :=
Make_Op_Eq (Loc,
Left_Opnd => Arr_Attr (A, Name_Length, J),
Right_Opnd => Make_Integer_Literal (Loc, 0));
Btest :=
Make_Op_Eq (Loc,
Left_Opnd => Arr_Attr (B, Name_Length, J),
Right_Opnd => Make_Integer_Literal (Loc, 0));
if No (Alist) then
Alist := Atest;
Blist := Btest;
else
Alist :=
Make_Or_Else (Loc,
Left_Opnd => Relocate_Node (Alist),
Right_Opnd => Atest);
Blist :=
Make_Or_Else (Loc,
Left_Opnd => Relocate_Node (Blist),
Right_Opnd => Btest);
end if;
end loop;
return
Make_And_Then (Loc,
Left_Opnd => Alist,
Right_Opnd => Blist);
end Test_Empty_Arrays;
-----------------------------
-- Test_Lengths_Correspond --
-----------------------------
function Test_Lengths_Correspond return Node_Id is
Result : Node_Id;
Rtest : Node_Id;
begin
Result := Empty;
for J in 1 .. Number_Dimensions (Ltyp) loop
Rtest :=
Make_Op_Ne (Loc,
Left_Opnd => Arr_Attr (A, Name_Length, J),
Right_Opnd => Arr_Attr (B, Name_Length, J));
if No (Result) then
Result := Rtest;
else
Result :=
Make_Or_Else (Loc,
Left_Opnd => Relocate_Node (Result),
Right_Opnd => Rtest);
end if;
end loop;
return Result;
end Test_Lengths_Correspond;
-- Start of processing for Expand_Array_Equality
begin
Ltyp := Get_Arg_Type (Lhs);
Rtyp := Get_Arg_Type (Rhs);
-- For now, if the argument types are not the same, go to the
-- base type, since the code assumes that the formals have the
-- same type. This is fixable in future ???
if Ltyp /= Rtyp then
Ltyp := Base_Type (Ltyp);
Rtyp := Base_Type (Rtyp);
pragma Assert (Ltyp = Rtyp);
end if;
-- Build list of formals for function
Formals := New_List (
Make_Parameter_Specification (Loc,
Defining_Identifier => A,
Parameter_Type => New_Reference_To (Ltyp, Loc)),
Make_Parameter_Specification (Loc,
Defining_Identifier => B,
Parameter_Type => New_Reference_To (Rtyp, Loc)));
Func_Name := Make_Defining_Identifier (Loc, New_Internal_Name ('E'));
-- Build statement sequence for function
Func_Body :=
Make_Subprogram_Body (Loc,
Specification =>
Make_Function_Specification (Loc,
Defining_Unit_Name => Func_Name,
Parameter_Specifications => Formals,
Result_Definition => New_Reference_To (Standard_Boolean, Loc)),
Declarations => Decls,
Handled_Statement_Sequence =>
Make_Handled_Sequence_Of_Statements (Loc,
Statements => New_List (
Make_Implicit_If_Statement (Nod,
Condition => Test_Empty_Arrays,
Then_Statements => New_List (
Make_Return_Statement (Loc,
Expression =>
New_Occurrence_Of (Standard_True, Loc)))),
Make_Implicit_If_Statement (Nod,
Condition => Test_Lengths_Correspond,
Then_Statements => New_List (
Make_Return_Statement (Loc,
Expression =>
New_Occurrence_Of (Standard_False, Loc)))),
Handle_One_Dimension (1, First_Index (Ltyp)),
Make_Return_Statement (Loc,
Expression => New_Occurrence_Of (Standard_True, Loc)))));
Set_Has_Completion (Func_Name, True);
Set_Is_Inlined (Func_Name);
-- If the array type is distinct from the type of the arguments,
-- it is the full view of a private type. Apply an unchecked
-- conversion to insure that analysis of the call succeeds.
declare
L, R : Node_Id;
begin
L := Lhs;
R := Rhs;
if No (Etype (Lhs))
or else Base_Type (Etype (Lhs)) /= Base_Type (Ltyp)
then
L := OK_Convert_To (Ltyp, Lhs);
end if;
if No (Etype (Rhs))
or else Base_Type (Etype (Rhs)) /= Base_Type (Rtyp)
then
R := OK_Convert_To (Rtyp, Rhs);
end if;
Actuals := New_List (L, R);
end;
Append_To (Bodies, Func_Body);
return
Make_Function_Call (Loc,
Name => New_Reference_To (Func_Name, Loc),
Parameter_Associations => Actuals);
end Expand_Array_Equality;
-----------------------------
-- Expand_Boolean_Operator --
-----------------------------
-- Note that we first get the actual subtypes of the operands,
-- since we always want to deal with types that have bounds.
procedure Expand_Boolean_Operator (N : Node_Id) is
Typ : constant Entity_Id := Etype (N);
begin
-- Special case of bit packed array where both operands are known
-- to be properly aligned. In this case we use an efficient run time
-- routine to carry out the operation (see System.Bit_Ops).
if Is_Bit_Packed_Array (Typ)
and then not Is_Possibly_Unaligned_Object (Left_Opnd (N))
and then not Is_Possibly_Unaligned_Object (Right_Opnd (N))
then
Expand_Packed_Boolean_Operator (N);
return;
end if;
-- For the normal non-packed case, the general expansion is to build
-- function for carrying out the comparison (use Make_Boolean_Array_Op)
-- and then inserting it into the tree. The original operator node is
-- then rewritten as a call to this function. We also use this in the
-- packed case if either operand is a possibly unaligned object.
declare
Loc : constant Source_Ptr := Sloc (N);
L : constant Node_Id := Relocate_Node (Left_Opnd (N));
R : constant Node_Id := Relocate_Node (Right_Opnd (N));
Func_Body : Node_Id;
Func_Name : Entity_Id;
begin
Convert_To_Actual_Subtype (L);
Convert_To_Actual_Subtype (R);
Ensure_Defined (Etype (L), N);
Ensure_Defined (Etype (R), N);
Apply_Length_Check (R, Etype (L));
if Nkind (Parent (N)) = N_Assignment_Statement
and then Safe_In_Place_Array_Op (Name (Parent (N)), L, R)
then
Build_Boolean_Array_Proc_Call (Parent (N), L, R);
elsif Nkind (Parent (N)) = N_Op_Not
and then Nkind (N) = N_Op_And
and then
Safe_In_Place_Array_Op (Name (Parent (Parent (N))), L, R)
then
return;
else
Func_Body := Make_Boolean_Array_Op (Etype (L), N);
Func_Name := Defining_Unit_Name (Specification (Func_Body));
Insert_Action (N, Func_Body);
-- Now rewrite the expression with a call
Rewrite (N,
Make_Function_Call (Loc,
Name => New_Reference_To (Func_Name, Loc),
Parameter_Associations =>
New_List (
L,
Make_Type_Conversion
(Loc, New_Reference_To (Etype (L), Loc), R))));
Analyze_And_Resolve (N, Typ);
end if;
end;
end Expand_Boolean_Operator;
-------------------------------
-- Expand_Composite_Equality --
-------------------------------
-- This function is only called for comparing internal fields of composite
-- types when these fields are themselves composites. This is a special
-- case because it is not possible to respect normal Ada visibility rules.
function Expand_Composite_Equality
(Nod : Node_Id;
Typ : Entity_Id;
Lhs : Node_Id;
Rhs : Node_Id;
Bodies : List_Id) return Node_Id
is
Loc : constant Source_Ptr := Sloc (Nod);
Full_Type : Entity_Id;
Prim : Elmt_Id;
Eq_Op : Entity_Id;
begin
if Is_Private_Type (Typ) then
Full_Type := Underlying_Type (Typ);
else
Full_Type := Typ;
end if;
-- Defense against malformed private types with no completion
-- the error will be diagnosed later by check_completion
if No (Full_Type) then
return New_Reference_To (Standard_False, Loc);
end if;
Full_Type := Base_Type (Full_Type);
if Is_Array_Type (Full_Type) then
-- If the operand is an elementary type other than a floating-point
-- type, then we can simply use the built-in block bitwise equality,
-- since the predefined equality operators always apply and bitwise
-- equality is fine for all these cases.
if Is_Elementary_Type (Component_Type (Full_Type))
and then not Is_Floating_Point_Type (Component_Type (Full_Type))
then
return Make_Op_Eq (Loc, Left_Opnd => Lhs, Right_Opnd => Rhs);
-- For composite component types, and floating-point types, use
-- the expansion. This deals with tagged component types (where
-- we use the applicable equality routine) and floating-point,
-- (where we need to worry about negative zeroes), and also the
-- case of any composite type recursively containing such fields.
else
return Expand_Array_Equality (Nod, Lhs, Rhs, Bodies, Full_Type);
end if;
elsif Is_Tagged_Type (Full_Type) then
-- Call the primitive operation "=" of this type
if Is_Class_Wide_Type (Full_Type) then
Full_Type := Root_Type (Full_Type);
end if;
-- If this is derived from an untagged private type completed
-- with a tagged type, it does not have a full view, so we
-- use the primitive operations of the private type.
-- This check should no longer be necessary when these
-- types receive their full views ???
if Is_Private_Type (Typ)
and then not Is_Tagged_Type (Typ)
and then not Is_Controlled (Typ)
and then Is_Derived_Type (Typ)
and then No (Full_View (Typ))
then
Prim := First_Elmt (Collect_Primitive_Operations (Typ));
else
Prim := First_Elmt (Primitive_Operations (Full_Type));
end if;
loop
Eq_Op := Node (Prim);
exit when Chars (Eq_Op) = Name_Op_Eq
and then Etype (First_Formal (Eq_Op)) =
Etype (Next_Formal (First_Formal (Eq_Op)))
and then Base_Type (Etype (Eq_Op)) = Standard_Boolean;
Next_Elmt (Prim);
pragma Assert (Present (Prim));
end loop;
Eq_Op := Node (Prim);
return
Make_Function_Call (Loc,
Name => New_Reference_To (Eq_Op, Loc),
Parameter_Associations =>
New_List
(Unchecked_Convert_To (Etype (First_Formal (Eq_Op)), Lhs),
Unchecked_Convert_To (Etype (First_Formal (Eq_Op)), Rhs)));
elsif Is_Record_Type (Full_Type) then
Eq_Op := TSS (Full_Type, TSS_Composite_Equality);
if Present (Eq_Op) then
if Etype (First_Formal (Eq_Op)) /= Full_Type then
-- Inherited equality from parent type. Convert the actuals
-- to match signature of operation.
declare
T : constant Entity_Id := Etype (First_Formal (Eq_Op));
begin
return
Make_Function_Call (Loc,
Name => New_Reference_To (Eq_Op, Loc),
Parameter_Associations =>
New_List (OK_Convert_To (T, Lhs),
OK_Convert_To (T, Rhs)));
end;
else
-- Comparison between Unchecked_Union components
if Is_Unchecked_Union (Full_Type) then
declare
Lhs_Type : Node_Id := Full_Type;
Rhs_Type : Node_Id := Full_Type;
Lhs_Discr_Val : Node_Id;
Rhs_Discr_Val : Node_Id;
begin
-- Lhs subtype
if Nkind (Lhs) = N_Selected_Component then
Lhs_Type := Etype (Entity (Selector_Name (Lhs)));
end if;
-- Rhs subtype
if Nkind (Rhs) = N_Selected_Component then
Rhs_Type := Etype (Entity (Selector_Name (Rhs)));
end if;
-- Lhs of the composite equality
if Is_Constrained (Lhs_Type) then
-- Since the enclosing record can never be an
-- Unchecked_Union (this code is executed for records
-- that do not have variants), we may reference its
-- discriminant(s).
if Nkind (Lhs) = N_Selected_Component
and then Has_Per_Object_Constraint (
Entity (Selector_Name (Lhs)))
then
Lhs_Discr_Val :=
Make_Selected_Component (Loc,
Prefix => Prefix (Lhs),
Selector_Name =>
New_Copy (
Get_Discriminant_Value (
First_Discriminant (Lhs_Type),
Lhs_Type,
Stored_Constraint (Lhs_Type))));
else
Lhs_Discr_Val := New_Copy (
Get_Discriminant_Value (
First_Discriminant (Lhs_Type),
Lhs_Type,
Stored_Constraint (Lhs_Type)));
end if;
else
-- It is not possible to infer the discriminant since
-- the subtype is not constrained.
return
Make_Raise_Program_Error (Loc,
Reason => PE_Unchecked_Union_Restriction);
end if;
-- Rhs of the composite equality
if Is_Constrained (Rhs_Type) then
if Nkind (Rhs) = N_Selected_Component
and then Has_Per_Object_Constraint (
Entity (Selector_Name (Rhs)))
then
Rhs_Discr_Val :=
Make_Selected_Component (Loc,
Prefix => Prefix (Rhs),
Selector_Name =>
New_Copy (
Get_Discriminant_Value (
First_Discriminant (Rhs_Type),
Rhs_Type,
Stored_Constraint (Rhs_Type))));
else
Rhs_Discr_Val := New_Copy (
Get_Discriminant_Value (
First_Discriminant (Rhs_Type),
Rhs_Type,
Stored_Constraint (Rhs_Type)));
end if;
else
return
Make_Raise_Program_Error (Loc,
Reason => PE_Unchecked_Union_Restriction);
end if;
-- Call the TSS equality function with the inferred
-- discriminant values.
return
Make_Function_Call (Loc,
Name => New_Reference_To (Eq_Op, Loc),
Parameter_Associations => New_List (
Lhs,
Rhs,
Lhs_Discr_Val,
Rhs_Discr_Val));
end;
end if;
-- Shouldn't this be an else, we can't fall through
-- the above IF, right???
return
Make_Function_Call (Loc,
Name => New_Reference_To (Eq_Op, Loc),
Parameter_Associations => New_List (Lhs, Rhs));
end if;
else
return Expand_Record_Equality (Nod, Full_Type, Lhs, Rhs, Bodies);
end if;
else
-- It can be a simple record or the full view of a scalar private
return Make_Op_Eq (Loc, Left_Opnd => Lhs, Right_Opnd => Rhs);
end if;
end Expand_Composite_Equality;
------------------------------
-- Expand_Concatenate_Other --
------------------------------
-- Let n be the number of array operands to be concatenated, Base_Typ
-- their base type, Ind_Typ their index type, and Arr_Typ the original
-- array type to which the concatenantion operator applies, then the
-- following subprogram is constructed:
-- [function Cnn (S1 : Base_Typ; ...; Sn : Base_Typ) return Base_Typ is
-- L : Ind_Typ;
-- begin
-- if S1'Length /= 0 then
-- L := XXX; --> XXX = S1'First if Arr_Typ is unconstrained
-- XXX = Arr_Typ'First otherwise
-- elsif S2'Length /= 0 then
-- L := YYY; --> YYY = S2'First if Arr_Typ is unconstrained
-- YYY = Arr_Typ'First otherwise
-- ...
-- elsif Sn-1'Length /= 0 then
-- L := ZZZ; --> ZZZ = Sn-1'First if Arr_Typ is unconstrained
-- ZZZ = Arr_Typ'First otherwise
-- else
-- return Sn;
-- end if;
-- declare
-- P : Ind_Typ;
-- H : Ind_Typ :=
-- Ind_Typ'Val ((((S1'Length - 1) + S2'Length) + ... + Sn'Length)
-- + Ind_Typ'Pos (L));
-- R : Base_Typ (L .. H);
-- begin
-- if S1'Length /= 0 then
-- P := S1'First;
-- loop
-- R (L) := S1 (P);
-- L := Ind_Typ'Succ (L);
-- exit when P = S1'Last;
-- P := Ind_Typ'Succ (P);
-- end loop;
-- end if;
--
-- if S2'Length /= 0 then
-- L := Ind_Typ'Succ (L);
-- loop
-- R (L) := S2 (P);
-- L := Ind_Typ'Succ (L);
-- exit when P = S2'Last;
-- P := Ind_Typ'Succ (P);
-- end loop;
-- end if;
-- ...
-- if Sn'Length /= 0 then
-- P := Sn'First;
-- loop
-- R (L) := Sn (P);
-- L := Ind_Typ'Succ (L);
-- exit when P = Sn'Last;
-- P := Ind_Typ'Succ (P);
-- end loop;
-- end if;
-- return R;
-- end;
-- end Cnn;]
procedure Expand_Concatenate_Other (Cnode : Node_Id; Opnds : List_Id) is
Loc : constant Source_Ptr := Sloc (Cnode);
Nb_Opnds : constant Nat := List_Length (Opnds);
Arr_Typ : constant Entity_Id := Etype (Entity (Cnode));
Base_Typ : constant Entity_Id := Base_Type (Etype (Cnode));
Ind_Typ : constant Entity_Id := Etype (First_Index (Base_Typ));
Func_Id : Node_Id;
Func_Spec : Node_Id;
Param_Specs : List_Id;
Func_Body : Node_Id;
Func_Decls : List_Id;
Func_Stmts : List_Id;
L_Decl : Node_Id;
If_Stmt : Node_Id;
Elsif_List : List_Id;
Declare_Block : Node_Id;
Declare_Decls : List_Id;
Declare_Stmts : List_Id;
H_Decl : Node_Id;
H_Init : Node_Id;
P_Decl : Node_Id;
R_Decl : Node_Id;
R_Constr : Node_Id;
R_Range : Node_Id;
Params : List_Id;
Operand : Node_Id;
function Copy_Into_R_S (I : Nat; Last : Boolean) return List_Id;
-- Builds the sequence of statement:
-- P := Si'First;
-- loop
-- R (L) := Si (P);
-- L := Ind_Typ'Succ (L);
-- exit when P = Si'Last;
-- P := Ind_Typ'Succ (P);
-- end loop;
--
-- where i is the input parameter I given.
-- If the flag Last is true, the exit statement is emitted before
-- incrementing the lower bound, to prevent the creation out of
-- bound values.
function Init_L (I : Nat) return Node_Id;
-- Builds the statement:
-- L := Arr_Typ'First; If Arr_Typ is constrained
-- L := Si'First; otherwise (where I is the input param given)
function H return Node_Id;
-- Builds reference to identifier H
function Ind_Val (E : Node_Id) return Node_Id;
-- Builds expression Ind_Typ'Val (E);
function L return Node_Id;
-- Builds reference to identifier L
function L_Pos return Node_Id;
-- Builds expression Integer_Type'(Ind_Typ'Pos (L)). We qualify the
-- expression to avoid universal_integer computations whenever possible,
-- in the expression for the upper bound H.
function L_Succ return Node_Id;
-- Builds expression Ind_Typ'Succ (L)
function One return Node_Id;
-- Builds integer literal one
function P return Node_Id;
-- Builds reference to identifier P
function P_Succ return Node_Id;
-- Builds expression Ind_Typ'Succ (P)
function R return Node_Id;
-- Builds reference to identifier R
function S (I : Nat) return Node_Id;
-- Builds reference to identifier Si, where I is the value given
function S_First (I : Nat) return Node_Id;
-- Builds expression Si'First, where I is the value given
function S_Last (I : Nat) return Node_Id;
-- Builds expression Si'Last, where I is the value given
function S_Length (I : Nat) return Node_Id;
-- Builds expression Si'Length, where I is the value given
function S_Length_Test (I : Nat) return Node_Id;
-- Builds expression Si'Length /= 0, where I is the value given
-------------------
-- Copy_Into_R_S --
-------------------
function Copy_Into_R_S (I : Nat; Last : Boolean) return List_Id is
Stmts : constant List_Id := New_List;
P_Start : Node_Id;
Loop_Stmt : Node_Id;
R_Copy : Node_Id;
Exit_Stmt : Node_Id;
L_Inc : Node_Id;
P_Inc : Node_Id;
begin
-- First construct the initializations
P_Start := Make_Assignment_Statement (Loc,
Name => P,
Expression => S_First (I));
Append_To (Stmts, P_Start);
-- Then build the loop
R_Copy := Make_Assignment_Statement (Loc,
Name => Make_Indexed_Component (Loc,
Prefix => R,
Expressions => New_List (L)),
Expression => Make_Indexed_Component (Loc,
Prefix => S (I),
Expressions => New_List (P)));
L_Inc := Make_Assignment_Statement (Loc,
Name => L,
Expression => L_Succ);
Exit_Stmt := Make_Exit_Statement (Loc,
Condition => Make_Op_Eq (Loc, P, S_Last (I)));
P_Inc := Make_Assignment_Statement (Loc,
Name => P,
Expression => P_Succ);
if Last then
Loop_Stmt :=
Make_Implicit_Loop_Statement (Cnode,
Statements => New_List (R_Copy, Exit_Stmt, L_Inc, P_Inc));
else
Loop_Stmt :=
Make_Implicit_Loop_Statement (Cnode,
Statements => New_List (R_Copy, L_Inc, Exit_Stmt, P_Inc));
end if;
Append_To (Stmts, Loop_Stmt);
return Stmts;
end Copy_Into_R_S;
-------
-- H --
-------
function H return Node_Id is
begin
return Make_Identifier (Loc, Name_uH);
end H;
-------------
-- Ind_Val --
-------------
function Ind_Val (E : Node_Id) return Node_Id is
begin
return
Make_Attribute_Reference (Loc,
Prefix => New_Reference_To (Ind_Typ, Loc),
Attribute_Name => Name_Val,
Expressions => New_List (E));
end Ind_Val;
------------
-- Init_L --
------------
function Init_L (I : Nat) return Node_Id is
E : Node_Id;
begin
if Is_Constrained (Arr_Typ) then
E := Make_Attribute_Reference (Loc,
Prefix => New_Reference_To (Arr_Typ, Loc),
Attribute_Name => Name_First);
else
E := S_First (I);
end if;
return Make_Assignment_Statement (Loc, Name => L, Expression => E);
end Init_L;
-------
-- L --
-------
function L return Node_Id is
begin
return Make_Identifier (Loc, Name_uL);
end L;
-----------
-- L_Pos --
-----------
function L_Pos return Node_Id is
Target_Type : Entity_Id;
begin
-- If the index type is an enumeration type, the computation
-- can be done in standard integer. Otherwise, choose a large
-- enough integer type.
if Is_Enumeration_Type (Ind_Typ)
or else Root_Type (Ind_Typ) = Standard_Integer
or else Root_Type (Ind_Typ) = Standard_Short_Integer
or else Root_Type (Ind_Typ) = Standard_Short_Short_Integer
then
Target_Type := Standard_Integer;
else
Target_Type := Root_Type (Ind_Typ);
end if;
return
Make_Qualified_Expression (Loc,
Subtype_Mark => New_Reference_To (Target_Type, Loc),
Expression =>
Make_Attribute_Reference (Loc,
Prefix => New_Reference_To (Ind_Typ, Loc),
Attribute_Name => Name_Pos,
Expressions => New_List (L)));
end L_Pos;
------------
-- L_Succ --
------------
function L_Succ return Node_Id is
begin
return
Make_Attribute_Reference (Loc,
Prefix => New_Reference_To (Ind_Typ, Loc),
Attribute_Name => Name_Succ,
Expressions => New_List (L));
end L_Succ;
---------
-- One --
---------
function One return Node_Id is
begin
return Make_Integer_Literal (Loc, 1);
end One;
-------
-- P --
-------
function P return Node_Id is
begin
return Make_Identifier (Loc, Name_uP);
end P;
------------
-- P_Succ --
------------
function P_Succ return Node_Id is
begin
return
Make_Attribute_Reference (Loc,
Prefix => New_Reference_To (Ind_Typ, Loc),
Attribute_Name => Name_Succ,
Expressions => New_List (P));
end P_Succ;
-------
-- R --
-------
function R return Node_Id is
begin
return Make_Identifier (Loc, Name_uR);
end R;
-------
-- S --
-------
function S (I : Nat) return Node_Id is
begin
return Make_Identifier (Loc, New_External_Name ('S', I));
end S;
-------------
-- S_First --
-------------
function S_First (I : Nat) return Node_Id is
begin
return Make_Attribute_Reference (Loc,
Prefix => S (I),
Attribute_Name => Name_First);
end S_First;
------------
-- S_Last --
------------
function S_Last (I : Nat) return Node_Id is
begin
return Make_Attribute_Reference (Loc,
Prefix => S (I),
Attribute_Name => Name_Last);
end S_Last;
--------------
-- S_Length --
--------------
function S_Length (I : Nat) return Node_Id is
begin
return Make_Attribute_Reference (Loc,
Prefix => S (I),
Attribute_Name => Name_Length);
end S_Length;
-------------------
-- S_Length_Test --
-------------------
function S_Length_Test (I : Nat) return Node_Id is
begin
return
Make_Op_Ne (Loc,
Left_Opnd => S_Length (I),
Right_Opnd => Make_Integer_Literal (Loc, 0));
end S_Length_Test;
-- Start of processing for Expand_Concatenate_Other
begin
-- Construct the parameter specs and the overall function spec
Param_Specs := New_List;
for I in 1 .. Nb_Opnds loop
Append_To
(Param_Specs,
Make_Parameter_Specification (Loc,
Defining_Identifier =>
Make_Defining_Identifier (Loc, New_External_Name ('S', I)),
Parameter_Type => New_Reference_To (Base_Typ, Loc)));
end loop;
Func_Id := Make_Defining_Identifier (Loc, New_Internal_Name ('C'));
Func_Spec :=
Make_Function_Specification (Loc,
Defining_Unit_Name => Func_Id,
Parameter_Specifications => Param_Specs,
Result_Definition => New_Reference_To (Base_Typ, Loc));
-- Construct L's object declaration
L_Decl :=
Make_Object_Declaration (Loc,
Defining_Identifier => Make_Defining_Identifier (Loc, Name_uL),
Object_Definition => New_Reference_To (Ind_Typ, Loc));
Func_Decls := New_List (L_Decl);
-- Construct the if-then-elsif statements
Elsif_List := New_List;
for I in 2 .. Nb_Opnds - 1 loop
Append_To (Elsif_List, Make_Elsif_Part (Loc,
Condition => S_Length_Test (I),
Then_Statements => New_List (Init_L (I))));
end loop;
If_Stmt :=
Make_Implicit_If_Statement (Cnode,
Condition => S_Length_Test (1),
Then_Statements => New_List (Init_L (1)),
Elsif_Parts => Elsif_List,
Else_Statements => New_List (Make_Return_Statement (Loc,
Expression => S (Nb_Opnds))));
-- Construct the declaration for H
P_Decl :=
Make_Object_Declaration (Loc,
Defining_Identifier => Make_Defining_Identifier (Loc, Name_uP),
Object_Definition => New_Reference_To (Ind_Typ, Loc));
H_Init := Make_Op_Subtract (Loc, S_Length (1), One);
for I in 2 .. Nb_Opnds loop
H_Init := Make_Op_Add (Loc, H_Init, S_Length (I));
end loop;
H_Init := Ind_Val (Make_Op_Add (Loc, H_Init, L_Pos));
H_Decl :=
Make_Object_Declaration (Loc,
Defining_Identifier => Make_Defining_Identifier (Loc, Name_uH),
Object_Definition => New_Reference_To (Ind_Typ, Loc),
Expression => H_Init);
-- Construct the declaration for R
R_Range := Make_Range (Loc, Low_Bound => L, High_Bound => H);
R_Constr :=
Make_Index_Or_Discriminant_Constraint (Loc,
Constraints => New_List (R_Range));
R_Decl :=
Make_Object_Declaration (Loc,
Defining_Identifier => Make_Defining_Identifier (Loc, Name_uR),
Object_Definition =>
Make_Subtype_Indication (Loc,
Subtype_Mark => New_Reference_To (Base_Typ, Loc),
Constraint => R_Constr));
-- Construct the declarations for the declare block
Declare_Decls := New_List (P_Decl, H_Decl, R_Decl);
-- Construct list of statements for the declare block
Declare_Stmts := New_List;
for I in 1 .. Nb_Opnds loop
Append_To (Declare_Stmts,
Make_Implicit_If_Statement (Cnode,
Condition => S_Length_Test (I),
Then_Statements => Copy_Into_R_S (I, I = Nb_Opnds)));
end loop;
Append_To (Declare_Stmts, Make_Return_Statement (Loc, Expression => R));
-- Construct the declare block
Declare_Block := Make_Block_Statement (Loc,
Declarations => Declare_Decls,
Handled_Statement_Sequence =>
Make_Handled_Sequence_Of_Statements (Loc, Declare_Stmts));
-- Construct the list of function statements
Func_Stmts := New_List (If_Stmt, Declare_Block);
-- Construct the function body
Func_Body :=
Make_Subprogram_Body (Loc,
Specification => Func_Spec,
Declarations => Func_Decls,
Handled_Statement_Sequence =>
Make_Handled_Sequence_Of_Statements (Loc, Func_Stmts));
-- Insert the newly generated function in the code. This is analyzed
-- with all checks off, since we have completed all the checks.
-- Note that this does *not* fix the array concatenation bug when the
-- low bound is Integer'first sibce that bug comes from the pointer
-- dereferencing an unconstrained array. An there we need a constraint
-- check to make sure the length of the concatenated array is ok. ???
Insert_Action (Cnode, Func_Body, Suppress => All_Checks);
-- Construct list of arguments for the function call
Params := New_List;
Operand := First (Opnds);
for I in 1 .. Nb_Opnds loop
Append_To (Params, Relocate_Node (Operand));
Next (Operand);
end loop;
-- Insert the function call
Rewrite
(Cnode,
Make_Function_Call (Loc, New_Reference_To (Func_Id, Loc), Params));
Analyze_And_Resolve (Cnode, Base_Typ);
Set_Is_Inlined (Func_Id);
end Expand_Concatenate_Other;
-------------------------------
-- Expand_Concatenate_String --
-------------------------------
procedure Expand_Concatenate_String (Cnode : Node_Id; Opnds : List_Id) is
Loc : constant Source_Ptr := Sloc (Cnode);
Opnd1 : constant Node_Id := First (Opnds);
Opnd2 : constant Node_Id := Next (Opnd1);
Typ1 : constant Entity_Id := Base_Type (Etype (Opnd1));
Typ2 : constant Entity_Id := Base_Type (Etype (Opnd2));
R : RE_Id;
-- RE_Id value for function to be called
begin
-- In all cases, we build a call to a routine giving the list of
-- arguments as the parameter list to the routine.
case List_Length (Opnds) is
when 2 =>
if Typ1 = Standard_Character then
if Typ2 = Standard_Character then
R := RE_Str_Concat_CC;
else
pragma Assert (Typ2 = Standard_String);
R := RE_Str_Concat_CS;
end if;
elsif Typ1 = Standard_String then
if Typ2 = Standard_Character then
R := RE_Str_Concat_SC;
else
pragma Assert (Typ2 = Standard_String);
R := RE_Str_Concat;
end if;
-- If we have anything other than Standard_Character or
-- Standard_String, then we must have had a serious error
-- earlier, so we just abandon the attempt at expansion.
else
pragma Assert (Serious_Errors_Detected > 0);
return;
end if;
when 3 =>
R := RE_Str_Concat_3;
when 4 =>
R := RE_Str_Concat_4;
when 5 =>
R := RE_Str_Concat_5;
when others =>
R := RE_Null;
raise Program_Error;
end case;
-- Now generate the appropriate call
Rewrite (Cnode,
Make_Function_Call (Sloc (Cnode),
Name => New_Occurrence_Of (RTE (R), Loc),
Parameter_Associations => Opnds));
Analyze_And_Resolve (Cnode, Standard_String);
exception
when RE_Not_Available =>
return;
end Expand_Concatenate_String;
------------------------
-- Expand_N_Allocator --
------------------------
procedure Expand_N_Allocator (N : Node_Id) is
PtrT : constant Entity_Id := Etype (N);
Dtyp : constant Entity_Id := Designated_Type (PtrT);
Etyp : constant Entity_Id := Etype (Expression (N));
Loc : constant Source_Ptr := Sloc (N);
Desig : Entity_Id;
Temp : Entity_Id;
Node : Node_Id;
begin
-- RM E.2.3(22). We enforce that the expected type of an allocator
-- shall not be a remote access-to-class-wide-limited-private type
-- Why is this being done at expansion time, seems clearly wrong ???
Validate_Remote_Access_To_Class_Wide_Type (N);
-- Set the Storage Pool
Set_Storage_Pool (N, Associated_Storage_Pool (Root_Type (PtrT)));
if Present (Storage_Pool (N)) then
if Is_RTE (Storage_Pool (N), RE_SS_Pool) then
if not Java_VM then
Set_Procedure_To_Call (N, RTE (RE_SS_Allocate));
end if;
elsif Is_Class_Wide_Type (Etype (Storage_Pool (N))) then
Set_Procedure_To_Call (N, RTE (RE_Allocate_Any));
else
Set_Procedure_To_Call (N,
Find_Prim_Op (Etype (Storage_Pool (N)), Name_Allocate));
end if;
end if;
-- Under certain circumstances we can replace an allocator by an
-- access to statically allocated storage. The conditions, as noted
-- in AARM 3.10 (10c) are as follows:
-- Size and initial value is known at compile time
-- Access type is access-to-constant
-- The allocator is not part of a constraint on a record component,
-- because in that case the inserted actions are delayed until the
-- record declaration is fully analyzed, which is too late for the
-- analysis of the rewritten allocator.
if Is_Access_Constant (PtrT)
and then Nkind (Expression (N)) = N_Qualified_Expression
and then Compile_Time_Known_Value (Expression (Expression (N)))
and then Size_Known_At_Compile_Time (Etype (Expression
(Expression (N))))
and then not Is_Record_Type (Current_Scope)
then
-- Here we can do the optimization. For the allocator
-- new x'(y)
-- We insert an object declaration
-- Tnn : aliased x := y;
-- and replace the allocator by Tnn'Unrestricted_Access.
-- Tnn is marked as requiring static allocation.
Temp :=
Make_Defining_Identifier (Loc, New_Internal_Name ('T'));
Desig := Subtype_Mark (Expression (N));
-- If context is constrained, use constrained subtype directly,
-- so that the constant is not labelled as having a nomimally
-- unconstrained subtype.
if Entity (Desig) = Base_Type (Dtyp) then
Desig := New_Occurrence_Of (Dtyp, Loc);
end if;
Insert_Action (N,
Make_Object_Declaration (Loc,
Defining_Identifier => Temp,
Aliased_Present => True,
Constant_Present => Is_Access_Constant (PtrT),
Object_Definition => Desig,
Expression => Expression (Expression (N))));
Rewrite (N,
Make_Attribute_Reference (Loc,
Prefix => New_Occurrence_Of (Temp, Loc),
Attribute_Name => Name_Unrestricted_Access));
Analyze_And_Resolve (N, PtrT);
-- We set the variable as statically allocated, since we don't
-- want it going on the stack of the current procedure!
Set_Is_Statically_Allocated (Temp);
return;
end if;
-- Handle case of qualified expression (other than optimization above)
if Nkind (Expression (N)) = N_Qualified_Expression then
Expand_Allocator_Expression (N);
-- If the allocator is for a type which requires initialization, and
-- there is no initial value (i.e. operand is a subtype indication
-- rather than a qualifed expression), then we must generate a call
-- to the initialization routine. This is done using an expression
-- actions node:
--
-- [Pnnn : constant ptr_T := new (T); Init (Pnnn.all,...); Pnnn]
--
-- Here ptr_T is the pointer type for the allocator, and T is the
-- subtype of the allocator. A special case arises if the designated
-- type of the access type is a task or contains tasks. In this case
-- the call to Init (Temp.all ...) is replaced by code that ensures
-- that tasks get activated (see Exp_Ch9.Build_Task_Allocate_Block
-- for details). In addition, if the type T is a task T, then the
-- first argument to Init must be converted to the task record type.
else
declare
T : constant Entity_Id := Entity (Expression (N));
Init : Entity_Id;
Arg1 : Node_Id;
Args : List_Id;
Decls : List_Id;
Decl : Node_Id;
Discr : Elmt_Id;
Flist : Node_Id;
Temp_Decl : Node_Id;
Temp_Type : Entity_Id;
Attach_Level : Uint;
begin
if No_Initialization (N) then
null;
-- Case of no initialization procedure present
elsif not Has_Non_Null_Base_Init_Proc (T) then
-- Case of simple initialization required
if Needs_Simple_Initialization (T) then
Rewrite (Expression (N),
Make_Qualified_Expression (Loc,
Subtype_Mark => New_Occurrence_Of (T, Loc),
Expression => Get_Simple_Init_Val (T, Loc)));
Analyze_And_Resolve (Expression (Expression (N)), T);
Analyze_And_Resolve (Expression (N), T);
Set_Paren_Count (Expression (Expression (N)), 1);
Expand_N_Allocator (N);
-- No initialization required
else
null;
end if;
-- Case of initialization procedure present, must be called
else
Init := Base_Init_Proc (T);
Node := N;
Temp :=
Make_Defining_Identifier (Loc, New_Internal_Name ('P'));
-- Construct argument list for the initialization routine call
-- The CPP constructor needs the address directly
if Is_CPP_Class (T) then
Arg1 := New_Reference_To (Temp, Loc);
Temp_Type := T;
else
Arg1 :=
Make_Explicit_Dereference (Loc,
Prefix => New_Reference_To (Temp, Loc));
Set_Assignment_OK (Arg1);
Temp_Type := PtrT;
-- The initialization procedure expects a specific type.
-- if the context is access to class wide, indicate that
-- the object being allocated has the right specific type.
if Is_Class_Wide_Type (Dtyp) then
Arg1 := Unchecked_Convert_To (T, Arg1);
end if;
end if;
-- If designated type is a concurrent type or if it is a
-- private type whose definition is a concurrent type,
-- the first argument in the Init routine has to be
-- unchecked conversion to the corresponding record type.
-- If the designated type is a derived type, we also
-- convert the argument to its root type.
if Is_Concurrent_Type (T) then
Arg1 :=
Unchecked_Convert_To (Corresponding_Record_Type (T), Arg1);
elsif Is_Private_Type (T)
and then Present (Full_View (T))
and then Is_Concurrent_Type (Full_View (T))
then
Arg1 :=
Unchecked_Convert_To
(Corresponding_Record_Type (Full_View (T)), Arg1);
elsif Etype (First_Formal (Init)) /= Base_Type (T) then
declare
Ftyp : constant Entity_Id := Etype (First_Formal (Init));
begin
Arg1 := OK_Convert_To (Etype (Ftyp), Arg1);
Set_Etype (Arg1, Ftyp);
end;
end if;
Args := New_List (Arg1);
-- For the task case, pass the Master_Id of the access type
-- as the value of the _Master parameter, and _Chain as the
-- value of the _Chain parameter (_Chain will be defined as
-- part of the generated code for the allocator).
if Has_Task (T) then
if No (Master_Id (Base_Type (PtrT))) then
-- The designated type was an incomplete type, and
-- the access type did not get expanded. Salvage
-- it now.
Expand_N_Full_Type_Declaration
(Parent (Base_Type (PtrT)));
end if;
-- If the context of the allocator is a declaration or
-- an assignment, we can generate a meaningful image for
-- it, even though subsequent assignments might remove
-- the connection between task and entity. We build this
-- image when the left-hand side is a simple variable,
-- a simple indexed assignment or a simple selected
-- component.
if Nkind (Parent (N)) = N_Assignment_Statement then
declare
Nam : constant Node_Id := Name (Parent (N));
begin
if Is_Entity_Name (Nam) then
Decls :=
Build_Task_Image_Decls (
Loc,
New_Occurrence_Of
(Entity (Nam), Sloc (Nam)), T);
elsif (Nkind (Nam) = N_Indexed_Component
or else Nkind (Nam) = N_Selected_Component)
and then Is_Entity_Name (Prefix (Nam))
then
Decls :=
Build_Task_Image_Decls
(Loc, Nam, Etype (Prefix (Nam)));
else
Decls := Build_Task_Image_Decls (Loc, T, T);
end if;
end;
elsif Nkind (Parent (N)) = N_Object_Declaration then
Decls :=
Build_Task_Image_Decls (
Loc, Defining_Identifier (Parent (N)), T);
else
Decls := Build_Task_Image_Decls (Loc, T, T);
end if;
Append_To (Args,
New_Reference_To
(Master_Id (Base_Type (Root_Type (PtrT))), Loc));
Append_To (Args, Make_Identifier (Loc, Name_uChain));
Decl := Last (Decls);
Append_To (Args,
New_Occurrence_Of (Defining_Identifier (Decl), Loc));
-- Has_Task is false, Decls not used
else
Decls := No_List;
end if;
-- Add discriminants if discriminated type
if Has_Discriminants (T) then
Discr := First_Elmt (Discriminant_Constraint (T));
while Present (Discr) loop
Append (New_Copy_Tree (Elists.Node (Discr)), Args);
Next_Elmt (Discr);
end loop;
elsif Is_Private_Type (T)
and then Present (Full_View (T))
and then Has_Discriminants (Full_View (T))
then
Discr :=
First_Elmt (Discriminant_Constraint (Full_View (T)));
while Present (Discr) loop
Append (New_Copy_Tree (Elists.Node (Discr)), Args);
Next_Elmt (Discr);
end loop;
end if;
-- We set the allocator as analyzed so that when we analyze the
-- expression actions node, we do not get an unwanted recursive
-- expansion of the allocator expression.
Set_Analyzed (N, True);
Node := Relocate_Node (N);
-- Here is the transformation:
-- input: new T
-- output: Temp : constant ptr_T := new T;
-- Init (Temp.all, ...);
-- <CTRL> Attach_To_Final_List (Finalizable (Temp.all));
-- <CTRL> Initialize (Finalizable (Temp.all));
-- Here ptr_T is the pointer type for the allocator, and T
-- is the subtype of the allocator.
Temp_Decl :=
Make_Object_Declaration (Loc,
Defining_Identifier => Temp,
Constant_Present => True,
Object_Definition => New_Reference_To (Temp_Type, Loc),
Expression => Node);
Set_Assignment_OK (Temp_Decl);
if Is_CPP_Class (T) then
Set_Aliased_Present (Temp_Decl);
end if;
Insert_Action (N, Temp_Decl, Suppress => All_Checks);
-- If the designated type is task type or contains tasks,
-- Create block to activate created tasks, and insert
-- declaration for Task_Image variable ahead of call.
if Has_Task (T) then
declare
L : constant List_Id := New_List;
Blk : Node_Id;
begin
Build_Task_Allocate_Block (L, Node, Args);
Blk := Last (L);
Insert_List_Before (First (Declarations (Blk)), Decls);
Insert_Actions (N, L);
end;
else
Insert_Action (N,
Make_Procedure_Call_Statement (Loc,
Name => New_Reference_To (Init, Loc),
Parameter_Associations => Args));
end if;
if Controlled_Type (T) then
Flist := Get_Allocator_Final_List (N, Base_Type (T), PtrT);
if Ekind (PtrT) = E_Anonymous_Access_Type then
Attach_Level := Uint_1;
else
Attach_Level := Uint_2;
end if;
Insert_Actions (N,
Make_Init_Call (
Ref => New_Copy_Tree (Arg1),
Typ => T,
Flist_Ref => Flist,
With_Attach => Make_Integer_Literal (Loc,
Attach_Level)));
end if;
if Is_CPP_Class (T) then
Rewrite (N,
Make_Attribute_Reference (Loc,
Prefix => New_Reference_To (Temp, Loc),
Attribute_Name => Name_Unchecked_Access));
else
Rewrite (N, New_Reference_To (Temp, Loc));
end if;
Analyze_And_Resolve (N, PtrT);
end if;
end;
end if;
-- Ada 2005 (AI-251): If the allocated object is accessed through an
-- access to class-wide interface we force the displacement of the
-- pointer to the allocated object to reference the corresponding
-- secondary dispatch table.
if Is_Class_Wide_Type (Dtyp)
and then Is_Interface (Dtyp)
then
declare
Saved_Typ : constant Entity_Id := Etype (N);
begin
-- 1) Get access to the allocated object
Rewrite (N,
Make_Explicit_Dereference (Loc,
Relocate_Node (N)));
Set_Etype (N, Etyp);
Set_Analyzed (N);
-- 2) Add the conversion to displace the pointer to reference
-- the secondary dispatch table.
Rewrite (N, Convert_To (Dtyp, Relocate_Node (N)));
Analyze_And_Resolve (N, Dtyp);
-- 3) The 'access to the secondary dispatch table will be used as
-- the value returned by the allocator.
Rewrite (N,
Make_Attribute_Reference (Loc,
Prefix => Relocate_Node (N),
Attribute_Name => Name_Access));
Set_Etype (N, Saved_Typ);
Set_Analyzed (N);
end;
end if;
exception
when RE_Not_Available =>
return;
end Expand_N_Allocator;
-----------------------
-- Expand_N_And_Then --
-----------------------
-- Expand into conditional expression if Actions present, and also
-- deal with optimizing case of arguments being True or False.
procedure Expand_N_And_Then (N : Node_Id) is
Loc : constant Source_Ptr := Sloc (N);
Typ : constant Entity_Id := Etype (N);
Left : constant Node_Id := Left_Opnd (N);
Right : constant Node_Id := Right_Opnd (N);
Actlist : List_Id;
begin
-- Deal with non-standard booleans
if Is_Boolean_Type (Typ) then
Adjust_Condition (Left);
Adjust_Condition (Right);
Set_Etype (N, Standard_Boolean);
end if;
-- Check for cases of left argument is True or False
if Nkind (Left) = N_Identifier then
-- If left argument is True, change (True and then Right) to Right.
-- Any actions associated with Right will be executed unconditionally
-- and can thus be inserted into the tree unconditionally.
if Entity (Left) = Standard_True then
if Present (Actions (N)) then
Insert_Actions (N, Actions (N));
end if;
Rewrite (N, Right);
Adjust_Result_Type (N, Typ);
return;
-- If left argument is False, change (False and then Right) to
-- False. In this case we can forget the actions associated with
-- Right, since they will never be executed.
elsif Entity (Left) = Standard_False then
Kill_Dead_Code (Right);
Kill_Dead_Code (Actions (N));
Rewrite (N, New_Occurrence_Of (Standard_False, Loc));
Adjust_Result_Type (N, Typ);
return;
end if;
end if;
-- If Actions are present, we expand
-- left and then right
-- into
-- if left then right else false end
-- with the actions becoming the Then_Actions of the conditional
-- expression. This conditional expression is then further expanded
-- (and will eventually disappear)
if Present (Actions (N)) then
Actlist := Actions (N);
Rewrite (N,
Make_Conditional_Expression (Loc,
Expressions => New_List (
Left,
Right,
New_Occurrence_Of (Standard_False, Loc))));
Set_Then_Actions (N, Actlist);
Analyze_And_Resolve (N, Standard_Boolean);
Adjust_Result_Type (N, Typ);
return;
end if;
-- No actions present, check for cases of right argument True/False
if Nkind (Right) = N_Identifier then
-- Change (Left and then True) to Left. Note that we know there
-- are no actions associated with the True operand, since we
-- just checked for this case above.
if Entity (Right) = Standard_True then
Rewrite (N, Left);
-- Change (Left and then False) to False, making sure to preserve
-- any side effects associated with the Left operand.
elsif Entity (Right) = Standard_False then
Remove_Side_Effects (Left);
Rewrite
(N, New_Occurrence_Of (Standard_False, Loc));
end if;
end if;
Adjust_Result_Type (N, Typ);
end Expand_N_And_Then;
-------------------------------------
-- Expand_N_Conditional_Expression --
-------------------------------------
-- Expand into expression actions if then/else actions present
procedure Expand_N_Conditional_Expression (N : Node_Id) is
Loc : constant Source_Ptr := Sloc (N);
Cond : constant Node_Id := First (Expressions (N));
Thenx : constant Node_Id := Next (Cond);
Elsex : constant Node_Id := Next (Thenx);
Typ : constant Entity_Id := Etype (N);
Cnn : Entity_Id;
New_If : Node_Id;
begin
-- If either then or else actions are present, then given:
-- if cond then then-expr else else-expr end
-- we insert the following sequence of actions (using Insert_Actions):
-- Cnn : typ;
-- if cond then
-- <<then actions>>
-- Cnn := then-expr;
-- else
-- <<else actions>>
-- Cnn := else-expr
-- end if;
-- and replace the conditional expression by a reference to Cnn
if Present (Then_Actions (N)) or else Present (Else_Actions (N)) then
Cnn := Make_Defining_Identifier (Loc, New_Internal_Name ('C'));
New_If :=
Make_Implicit_If_Statement (N,
Condition => Relocate_Node (Cond),
Then_Statements => New_List (
Make_Assignment_Statement (Sloc (Thenx),
Name => New_Occurrence_Of (Cnn, Sloc (Thenx)),
Expression => Relocate_Node (Thenx))),
Else_Statements => New_List (
Make_Assignment_Statement (Sloc (Elsex),
Name => New_Occurrence_Of (Cnn, Sloc (Elsex)),
Expression => Relocate_Node (Elsex))));
Set_Assignment_OK (Name (First (Then_Statements (New_If))));
Set_Assignment_OK (Name (First (Else_Statements (New_If))));
if Present (Then_Actions (N)) then
Insert_List_Before
(First (Then_Statements (New_If)), Then_Actions (N));
end if;
if Present (Else_Actions (N)) then
Insert_List_Before
(First (Else_Statements (New_If)), Else_Actions (N));
end if;
Rewrite (N, New_Occurrence_Of (Cnn, Loc));
Insert_Action (N,
Make_Object_Declaration (Loc,
Defining_Identifier => Cnn,
Object_Definition => New_Occurrence_Of (Typ, Loc)));
Insert_Action (N, New_If);
Analyze_And_Resolve (N, Typ);
end if;
end Expand_N_Conditional_Expression;
-----------------------------------
-- Expand_N_Explicit_Dereference --
-----------------------------------
procedure Expand_N_Explicit_Dereference (N : Node_Id) is
begin
-- Insert explicit dereference call for the checked storage pool case
Insert_Dereference_Action (Prefix (N));
end Expand_N_Explicit_Dereference;
-----------------
-- Expand_N_In --
-----------------
procedure Expand_N_In (N : Node_Id) is
Loc : constant Source_Ptr := Sloc (N);
Rtyp : constant Entity_Id := Etype (N);
Lop : constant Node_Id := Left_Opnd (N);
Rop : constant Node_Id := Right_Opnd (N);
Static : constant Boolean := Is_OK_Static_Expression (N);
procedure Substitute_Valid_Check;
-- Replaces node N by Lop'Valid. This is done when we have an explicit
-- test for the left operand being in range of its subtype.
----------------------------
-- Substitute_Valid_Check --
----------------------------
procedure Substitute_Valid_Check is
begin
Rewrite (N,
Make_Attribute_Reference (Loc,
Prefix => Relocate_Node (Lop),
Attribute_Name => Name_Valid));
Analyze_And_Resolve (N, Rtyp);
Error_Msg_N ("?explicit membership test may be optimized away", N);
Error_Msg_N ("\?use ''Valid attribute instead", N);
return;
end Substitute_Valid_Check;
-- Start of processing for Expand_N_In
begin
-- Check case of explicit test for an expression in range of its
-- subtype. This is suspicious usage and we replace it with a 'Valid
-- test and give a warning.
if Is_Scalar_Type (Etype (Lop))
and then Nkind (Rop) in N_Has_Entity
and then Etype (Lop) = Entity (Rop)
and then Comes_From_Source (N)
then
Substitute_Valid_Check;
return;
end if;
-- Case of explicit range
if Nkind (Rop) = N_Range then
declare
Lo : constant Node_Id := Low_Bound (Rop);
Hi : constant Node_Id := High_Bound (Rop);
Lo_Orig : constant Node_Id := Original_Node (Lo);
Hi_Orig : constant Node_Id := Original_Node (Hi);
Lcheck : constant Compare_Result := Compile_Time_Compare (Lop, Lo);
Ucheck : constant Compare_Result := Compile_Time_Compare (Lop, Hi);
begin
-- If test is explicit x'first .. x'last, replace by valid check
if Is_Scalar_Type (Etype (Lop))
and then Nkind (Lo_Orig) = N_Attribute_Reference
and then Attribute_Name (Lo_Orig) = Name_First
and then Nkind (Prefix (Lo_Orig)) in N_Has_Entity
and then Entity (Prefix (Lo_Orig)) = Etype (Lop)
and then Nkind (Hi_Orig) = N_Attribute_Reference
and then Attribute_Name (Hi_Orig) = Name_Last
and then Nkind (Prefix (Hi_Orig)) in N_Has_Entity
and then Entity (Prefix (Hi_Orig)) = Etype (Lop)
and then Comes_From_Source (N)
then
Substitute_Valid_Check;
return;
end if;
-- If we have an explicit range, do a bit of optimization based
-- on range analysis (we may be able to kill one or both checks).
-- If either check is known to fail, replace result by False since
-- the other check does not matter. Preserve the static flag for
-- legality checks, because we are constant-folding beyond RM 4.9.
if Lcheck = LT or else Ucheck = GT then
Rewrite (N,
New_Reference_To (Standard_False, Loc));
Analyze_And_Resolve (N, Rtyp);
Set_Is_Static_Expression (N, Static);
return;
-- If both checks are known to succeed, replace result
-- by True, since we know we are in range.
elsif Lcheck in Compare_GE and then Ucheck in Compare_LE then
Rewrite (N,
New_Reference_To (Standard_True, Loc));
Analyze_And_Resolve (N, Rtyp);
Set_Is_Static_Expression (N, Static);
return;
-- If lower bound check succeeds and upper bound check is
-- not known to succeed or fail, then replace the range check
-- with a comparison against the upper bound.
elsif Lcheck in Compare_GE then
Rewrite (N,
Make_Op_Le (Loc,
Left_Opnd => Lop,
Right_Opnd => High_Bound (Rop)));
Analyze_And_Resolve (N, Rtyp);
return;
-- If upper bound check succeeds and lower bound check is
-- not known to succeed or fail, then replace the range check
-- with a comparison against the lower bound.
elsif Ucheck in Compare_LE then
Rewrite (N,
Make_Op_Ge (Loc,
Left_Opnd => Lop,
Right_Opnd => Low_Bound (Rop)));
Analyze_And_Resolve (N, Rtyp);
return;
end if;
end;
-- For all other cases of an explicit range, nothing to be done
return;
-- Here right operand is a subtype mark
else
declare
Typ : Entity_Id := Etype (Rop);
Is_Acc : constant Boolean := Is_Access_Type (Typ);
Obj : Node_Id := Lop;
Cond : Node_Id := Empty;
begin
Remove_Side_Effects (Obj);
-- For tagged type, do tagged membership operation
if Is_Tagged_Type (Typ) then
-- No expansion will be performed when Java_VM, as the
-- JVM back end will handle the membership tests directly
-- (tags are not explicitly represented in Java objects,
-- so the normal tagged membership expansion is not what
-- we want).
if not Java_VM then
Rewrite (N, Tagged_Membership (N));
Analyze_And_Resolve (N, Rtyp);
end if;
return;
-- If type is scalar type, rewrite as x in t'first .. t'last
-- This reason we do this is that the bounds may have the wrong
-- type if they come from the original type definition.
elsif Is_Scalar_Type (Typ) then
Rewrite (Rop,
Make_Range (Loc,
Low_Bound =>
Make_Attribute_Reference (Loc,
Attribute_Name => Name_First,
Prefix => New_Reference_To (Typ, Loc)),
High_Bound =>
Make_Attribute_Reference (Loc,
Attribute_Name => Name_Last,
Prefix => New_Reference_To (Typ, Loc))));
Analyze_And_Resolve (N, Rtyp);
return;
-- Ada 2005 (AI-216): Program_Error is raised when evaluating
-- a membership test if the subtype mark denotes a constrained
-- Unchecked_Union subtype and the expression lacks inferable
-- discriminants.
elsif Is_Unchecked_Union (Base_Type (Typ))
and then Is_Constrained (Typ)
and then not Has_Inferable_Discriminants (Lop)
then
Insert_Action (N,
Make_Raise_Program_Error (Loc,
Reason => PE_Unchecked_Union_Restriction));
-- Prevent Gigi from generating incorrect code by rewriting
-- the test as a standard False.
Rewrite (N,
New_Occurrence_Of (Standard_False, Loc));
return;
end if;
-- Here we have a non-scalar type
if Is_Acc then
Typ := Designated_Type (Typ);
end if;
if not Is_Constrained (Typ) then
Rewrite (N,
New_Reference_To (Standard_True, Loc));
Analyze_And_Resolve (N, Rtyp);
-- For the constrained array case, we have to check the
-- subscripts for an exact match if the lengths are
-- non-zero (the lengths must match in any case).
elsif Is_Array_Type (Typ) then
Check_Subscripts : declare
function Construct_Attribute_Reference
(E : Node_Id;
Nam : Name_Id;
Dim : Nat) return Node_Id;
-- Build attribute reference E'Nam(Dim)
-----------------------------------
-- Construct_Attribute_Reference --
-----------------------------------
function Construct_Attribute_Reference
(E : Node_Id;
Nam : Name_Id;
Dim : Nat) return Node_Id
is
begin
return
Make_Attribute_Reference (Loc,
Prefix => E,
Attribute_Name => Nam,
Expressions => New_List (
Make_Integer_Literal (Loc, Dim)));
end Construct_Attribute_Reference;
-- Start processing for Check_Subscripts
begin
for J in 1 .. Number_Dimensions (Typ) loop
Evolve_And_Then (Cond,
Make_Op_Eq (Loc,
Left_Opnd =>
Construct_Attribute_Reference
(Duplicate_Subexpr_No_Checks (Obj),
Name_First, J),
Right_Opnd =>
Construct_Attribute_Reference
(New_Occurrence_Of (Typ, Loc), Name_First, J)));
Evolve_And_Then (Cond,
Make_Op_Eq (Loc,
Left_Opnd =>
Construct_Attribute_Reference
(Duplicate_Subexpr_No_Checks (Obj),
Name_Last, J),
Right_Opnd =>
Construct_Attribute_Reference
(New_Occurrence_Of (Typ, Loc), Name_Last, J)));
end loop;
if Is_Acc then
Cond :=
Make_Or_Else (Loc,
Left_Opnd =>
Make_Op_Eq (Loc,
Left_Opnd => Obj,
Right_Opnd => Make_Null (Loc)),
Right_Opnd => Cond);
end if;
Rewrite (N, Cond);
Analyze_And_Resolve (N, Rtyp);
end Check_Subscripts;
-- These are the cases where constraint checks may be
-- required, e.g. records with possible discriminants
else
-- Expand the test into a series of discriminant comparisons.
-- The expression that is built is the negation of the one
-- that is used for checking discriminant constraints.
Obj := Relocate_Node (Left_Opnd (N));
if Has_Discriminants (Typ) then
Cond := Make_Op_Not (Loc,
Right_Opnd => Build_Discriminant_Checks (Obj, Typ));
if Is_Acc then
Cond := Make_Or_Else (Loc,
Left_Opnd =>
Make_Op_Eq (Loc,
Left_Opnd => Obj,
Right_Opnd => Make_Null (Loc)),
Right_Opnd => Cond);
end if;
else
Cond := New_Occurrence_Of (Standard_True, Loc);
end if;
Rewrite (N, Cond);
Analyze_And_Resolve (N, Rtyp);
end if;
end;
end if;
end Expand_N_In;
--------------------------------
-- Expand_N_Indexed_Component --
--------------------------------
procedure Expand_N_Indexed_Component (N : Node_Id) is
Loc : constant Source_Ptr := Sloc (N);
Typ : constant Entity_Id := Etype (N);
P : constant Node_Id := Prefix (N);
T : constant Entity_Id := Etype (P);
begin
-- A special optimization, if we have an indexed component that
-- is selecting from a slice, then we can eliminate the slice,
-- since, for example, x (i .. j)(k) is identical to x(k). The
-- only difference is the range check required by the slice. The
-- range check for the slice itself has already been generated.
-- The range check for the subscripting operation is ensured
-- by converting the subject to the subtype of the slice.
-- This optimization not only generates better code, avoiding
-- slice messing especially in the packed case, but more importantly
-- bypasses some problems in handling this peculiar case, for
-- example, the issue of dealing specially with object renamings.
if Nkind (P) = N_Slice then
Rewrite (N,
Make_Indexed_Component (Loc,
Prefix => Prefix (P),
Expressions => New_List (
Convert_To
(Etype (First_Index (Etype (P))),
First (Expressions (N))))));
Analyze_And_Resolve (N, Typ);
return;
end if;
-- If the prefix is an access type, then we unconditionally rewrite
-- if as an explicit deference. This simplifies processing for several
-- cases, including packed array cases and certain cases in which
-- checks must be generated. We used to try to do this only when it
-- was necessary, but it cleans up the code to do it all the time.
if Is_Access_Type (T) then
Insert_Explicit_Dereference (P);
Analyze_And_Resolve (P, Designated_Type (T));
end if;
-- Generate index and validity checks
Generate_Index_Checks (N);
if Validity_Checks_On and then Validity_Check_Subscripts then
Apply_Subscript_Validity_Checks (N);
end if;
-- All done for the non-packed case
if not Is_Packed (Etype (Prefix (N))) then
return;
end if;
-- For packed arrays that are not bit-packed (i.e. the case of an array
-- with one or more index types with a non-coniguous enumeration type),
-- we can always use the normal packed element get circuit.
if not Is_Bit_Packed_Array (Etype (Prefix (N))) then
Expand_Packed_Element_Reference (N);
return;
end if;
-- For a reference to a component of a bit packed array, we have to
-- convert it to a reference to the corresponding Packed_Array_Type.
-- We only want to do this for simple references, and not for:
-- Left side of assignment, or prefix of left side of assignment,
-- or prefix of the prefix, to handle packed arrays of packed arrays,
-- This case is handled in Exp_Ch5.Expand_N_Assignment_Statement
-- Renaming objects in renaming associations
-- This case is handled when a use of the renamed variable occurs
-- Actual parameters for a procedure call
-- This case is handled in Exp_Ch6.Expand_Actuals
-- The second expression in a 'Read attribute reference
-- The prefix of an address or size attribute reference
-- The following circuit detects these exceptions
declare
Child : Node_Id := N;
Parnt : Node_Id := Parent (N);
begin
loop
if Nkind (Parnt) = N_Unchecked_Expression then
null;
elsif Nkind (Parnt) = N_Object_Renaming_Declaration
or else Nkind (Parnt) = N_Procedure_Call_Statement
or else (Nkind (Parnt) = N_Parameter_Association
and then
Nkind (Parent (Parnt)) = N_Procedure_Call_Statement)
then
return;
elsif Nkind (Parnt) = N_Attribute_Reference
and then (Attribute_Name (Parnt) = Name_Address
or else
Attribute_Name (Parnt) = Name_Size)
and then Prefix (Parnt) = Child
then
return;
elsif Nkind (Parnt) = N_Assignment_Statement
and then Name (Parnt) = Child
then
return;
-- If the expression is an index of an indexed component,
-- it must be expanded regardless of context.
elsif Nkind (Parnt) = N_Indexed_Component
and then Child /= Prefix (Parnt)
then
Expand_Packed_Element_Reference (N);
return;
elsif Nkind (Parent (Parnt)) = N_Assignment_Statement
and then Name (Parent (Parnt)) = Parnt
then
return;
elsif Nkind (Parnt) = N_Attribute_Reference
and then Attribute_Name (Parnt) = Name_Read
and then Next (First (Expressions (Parnt))) = Child
then
return;
elsif (Nkind (Parnt) = N_Indexed_Component
or else Nkind (Parnt) = N_Selected_Component)
and then Prefix (Parnt) = Child
then
null;
else
Expand_Packed_Element_Reference (N);
return;
end if;
-- Keep looking up tree for unchecked expression, or if we are
-- the prefix of a possible assignment left side.
Child := Parnt;
Parnt := Parent (Child);
end loop;
end;
end Expand_N_Indexed_Component;
---------------------
-- Expand_N_Not_In --
---------------------
-- Replace a not in b by not (a in b) so that the expansions for (a in b)
-- can be done. This avoids needing to duplicate this expansion code.
procedure Expand_N_Not_In (N : Node_Id) is
Loc : constant Source_Ptr := Sloc (N);
Typ : constant Entity_Id := Etype (N);
Cfs : constant Boolean := Comes_From_Source (N);
begin
Rewrite (N,
Make_Op_Not (Loc,
Right_Opnd =>
Make_In (Loc,
Left_Opnd => Left_Opnd (N),
Right_Opnd => Right_Opnd (N))));
-- We want this tp appear as coming from source if original does (see
-- tranformations in Expand_N_In).
Set_Comes_From_Source (N, Cfs);
Set_Comes_From_Source (Right_Opnd (N), Cfs);
-- Now analyze tranformed node
Analyze_And_Resolve (N, Typ);
end Expand_N_Not_In;
-------------------
-- Expand_N_Null --
-------------------
-- The only replacement required is for the case of a null of type
-- that is an access to protected subprogram. We represent such
-- access values as a record, and so we must replace the occurrence
-- of null by the equivalent record (with a null address and a null
-- pointer in it), so that the backend creates the proper value.
procedure Expand_N_Null (N : Node_Id) is
Loc : constant Source_Ptr := Sloc (N);
Typ : constant Entity_Id := Etype (N);
Agg : Node_Id;
begin
if Ekind (Typ) = E_Access_Protected_Subprogram_Type then
Agg :=
Make_Aggregate (Loc,
Expressions => New_List (
New_Occurrence_Of (RTE (RE_Null_Address), Loc),
Make_Null (Loc)));
Rewrite (N, Agg);
Analyze_And_Resolve (N, Equivalent_Type (Typ));
-- For subsequent semantic analysis, the node must retain its
-- type. Gigi in any case replaces this type by the corresponding
-- record type before processing the node.
Set_Etype (N, Typ);
end if;
exception
when RE_Not_Available =>
return;
end Expand_N_Null;
---------------------
-- Expand_N_Op_Abs --
---------------------
procedure Expand_N_Op_Abs (N : Node_Id) is
Loc : constant Source_Ptr := Sloc (N);
Expr : constant Node_Id := Right_Opnd (N);
begin
Unary_Op_Validity_Checks (N);
-- Deal with software overflow checking
if not Backend_Overflow_Checks_On_Target
and then Is_Signed_Integer_Type (Etype (N))
and then Do_Overflow_Check (N)
then
-- The only case to worry about is when the argument is
-- equal to the largest negative number, so what we do is
-- to insert the check:
-- [constraint_error when Expr = typ'Base'First]
-- with the usual Duplicate_Subexpr use coding for expr
Insert_Action (N,
Make_Raise_Constraint_Error (Loc,
Condition =>
Make_Op_Eq (Loc,
Left_Opnd => Duplicate_Subexpr (Expr),
Right_Opnd =>
Make_Attribute_Reference (Loc,
Prefix =>
New_Occurrence_Of (Base_Type (Etype (Expr)), Loc),
Attribute_Name => Name_First)),
Reason => CE_Overflow_Check_Failed));
end if;
-- Vax floating-point types case
if Vax_Float (Etype (N)) then
Expand_Vax_Arith (N);
end if;
end Expand_N_Op_Abs;
---------------------
-- Expand_N_Op_Add --
---------------------
procedure Expand_N_Op_Add (N : Node_Id) is
Typ : constant Entity_Id := Etype (N);
begin
Binary_Op_Validity_Checks (N);
-- N + 0 = 0 + N = N for integer types
if Is_Integer_Type (Typ) then
if Compile_Time_Known_Value (Right_Opnd (N))
and then Expr_Value (Right_Opnd (N)) = Uint_0
then
Rewrite (N, Left_Opnd (N));
return;
elsif Compile_Time_Known_Value (Left_Opnd (N))
and then Expr_Value (Left_Opnd (N)) = Uint_0
then
Rewrite (N, Right_Opnd (N));
return;
end if;
end if;
-- Arithmetic overflow checks for signed integer/fixed point types
if Is_Signed_Integer_Type (Typ)
or else Is_Fixed_Point_Type (Typ)
then
Apply_Arithmetic_Overflow_Check (N);
return;
-- Vax floating-point types case
elsif Vax_Float (Typ) then
Expand_Vax_Arith (N);
end if;
end Expand_N_Op_Add;
---------------------
-- Expand_N_Op_And --
---------------------
procedure Expand_N_Op_And (N : Node_Id) is
Typ : constant Entity_Id := Etype (N);
begin
Binary_Op_Validity_Checks (N);
if Is_Array_Type (Etype (N)) then
Expand_Boolean_Operator (N);
elsif Is_Boolean_Type (Etype (N)) then
Adjust_Condition (Left_Opnd (N));
Adjust_Condition (Right_Opnd (N));
Set_Etype (N, Standard_Boolean);
Adjust_Result_Type (N, Typ);
end if;
end Expand_N_Op_And;
------------------------
-- Expand_N_Op_Concat --
------------------------
Max_Available_String_Operands : Int := -1;
-- This is initialized the first time this routine is called. It records
-- a value of 0,2,3,4,5 depending on what Str_Concat_n procedures are
-- available in the run-time:
--
-- 0 None available
-- 2 RE_Str_Concat available, RE_Str_Concat_3 not available
-- 3 RE_Str_Concat/Concat_2 available, RE_Str_Concat_4 not available
-- 4 RE_Str_Concat/Concat_2/3 available, RE_Str_Concat_5 not available
-- 5 All routines including RE_Str_Concat_5 available
Char_Concat_Available : Boolean;
-- Records if the routines RE_Str_Concat_CC/CS/SC are available. True if
-- all three are available, False if any one of these is unavailable.
procedure Expand_N_Op_Concat (N : Node_Id) is
Opnds : List_Id;
-- List of operands to be concatenated
Opnd : Node_Id;
-- Single operand for concatenation
Cnode : Node_Id;
-- Node which is to be replaced by the result of concatenating
-- the nodes in the list Opnds.
Atyp : Entity_Id;
-- Array type of concatenation result type
Ctyp : Entity_Id;
-- Component type of concatenation represented by Cnode
begin
-- Initialize global variables showing run-time status
if Max_Available_String_Operands < 1 then
if not RTE_Available (RE_Str_Concat) then
Max_Available_String_Operands := 0;
elsif not RTE_Available (RE_Str_Concat_3) then
Max_Available_String_Operands := 2;
elsif not RTE_Available (RE_Str_Concat_4) then
Max_Available_String_Operands := 3;
elsif not RTE_Available (RE_Str_Concat_5) then
Max_Available_String_Operands := 4;
else
Max_Available_String_Operands := 5;
end if;
Char_Concat_Available :=
RTE_Available (RE_Str_Concat_CC)
and then
RTE_Available (RE_Str_Concat_CS)
and then
RTE_Available (RE_Str_Concat_SC);
end if;
-- Ensure validity of both operands
Binary_Op_Validity_Checks (N);
-- If we are the left operand of a concatenation higher up the
-- tree, then do nothing for now, since we want to deal with a
-- series of concatenations as a unit.
if Nkind (Parent (N)) = N_Op_Concat
and then N = Left_Opnd (Parent (N))
then
return;
end if;
-- We get here with a concatenation whose left operand may be a
-- concatenation itself with a consistent type. We need to process
-- these concatenation operands from left to right, which means
-- from the deepest node in the tree to the highest node.
Cnode := N;
while Nkind (Left_Opnd (Cnode)) = N_Op_Concat loop
Cnode := Left_Opnd (Cnode);
end loop;
-- Now Opnd is the deepest Opnd, and its parents are the concatenation
-- nodes above, so now we process bottom up, doing the operations. We
-- gather a string that is as long as possible up to five operands
-- The outer loop runs more than once if there are more than five
-- concatenations of type Standard.String, the most we handle for
-- this case, or if more than one concatenation type is involved.
Outer : loop
Opnds := New_List (Left_Opnd (Cnode), Right_Opnd (Cnode));
Set_Parent (Opnds, N);
-- The inner loop gathers concatenation operands. We gather any
-- number of these in the non-string case, or if no concatenation
-- routines are available for string (since in that case we will
-- treat string like any other non-string case). Otherwise we only
-- gather as many operands as can be handled by the available
-- procedures in the run-time library (normally 5, but may be
-- less for the configurable run-time case).
Inner : while Cnode /= N
and then (Base_Type (Etype (Cnode)) /= Standard_String
or else
Max_Available_String_Operands = 0
or else
List_Length (Opnds) <
Max_Available_String_Operands)
and then Base_Type (Etype (Cnode)) =
Base_Type (Etype (Parent (Cnode)))
loop
Cnode := Parent (Cnode);
Append (Right_Opnd (Cnode), Opnds);
end loop Inner;
-- Here we process the collected operands. First we convert
-- singleton operands to singleton aggregates. This is skipped
-- however for the case of two operands of type String, since
-- we have special routines for these cases.
Atyp := Base_Type (Etype (Cnode));
Ctyp := Base_Type (Component_Type (Etype (Cnode)));
if (List_Length (Opnds) > 2 or else Atyp /= Standard_String)
or else not Char_Concat_Available
then
Opnd := First (Opnds);
loop
if Base_Type (Etype (Opnd)) = Ctyp then
Rewrite (Opnd,
Make_Aggregate (Sloc (Cnode),
Expressions => New_List (Relocate_Node (Opnd))));
Analyze_And_Resolve (Opnd, Atyp);
end if;
Next (Opnd);
exit when No (Opnd);
end loop;
end if;
-- Now call appropriate continuation routine
if Atyp = Standard_String
and then Max_Available_String_Operands > 0
then
Expand_Concatenate_String (Cnode, Opnds);
else
Expand_Concatenate_Other (Cnode, Opnds);
end if;
exit Outer when Cnode = N;
Cnode := Parent (Cnode);
end loop Outer;
end Expand_N_Op_Concat;
------------------------
-- Expand_N_Op_Divide --
------------------------
procedure Expand_N_Op_Divide (N : Node_Id) is
Loc : constant Source_Ptr := Sloc (N);
Lopnd : constant Node_Id := Left_Opnd (N);
Ropnd : constant Node_Id := Right_Opnd (N);
Ltyp : constant Entity_Id := Etype (Lopnd);
Rtyp : constant Entity_Id := Etype (Ropnd);
Typ : Entity_Id := Etype (N);
Rknow : constant Boolean := Is_Integer_Type (Typ)
and then
Compile_Time_Known_Value (Ropnd);
Rval : Uint;
begin
Binary_Op_Validity_Checks (N);
if Rknow then
Rval := Expr_Value (Ropnd);
end if;
-- N / 1 = N for integer types
if Rknow and then Rval = Uint_1 then
Rewrite (N, Lopnd);
return;
end if;
-- Convert x / 2 ** y to Shift_Right (x, y). Note that the fact that
-- Is_Power_Of_2_For_Shift is set means that we know that our left
-- operand is an unsigned integer, as required for this to work.
if Nkind (Ropnd) = N_Op_Expon
and then Is_Power_Of_2_For_Shift (Ropnd)
-- We cannot do this transformation in configurable run time mode if we
-- have 64-bit -- integers and long shifts are not available.
and then
(Esize (Ltyp) <= 32
or else Support_Long_Shifts_On_Target)
then
Rewrite (N,
Make_Op_Shift_Right (Loc,
Left_Opnd => Lopnd,
Right_Opnd =>
Convert_To (Standard_Natural, Right_Opnd (Ropnd))));
Analyze_And_Resolve (N, Typ);
return;
end if;
-- Do required fixup of universal fixed operation
if Typ = Universal_Fixed then
Fixup_Universal_Fixed_Operation (N);
Typ := Etype (N);
end if;
-- Divisions with fixed-point results
if Is_Fixed_Point_Type (Typ) then
-- No special processing if Treat_Fixed_As_Integer is set,
-- since from a semantic point of view such operations are
-- simply integer operations and will be treated that way.
if not Treat_Fixed_As_Integer (N) then
if Is_Integer_Type (Rtyp) then
Expand_Divide_Fixed_By_Integer_Giving_Fixed (N);
else
Expand_Divide_Fixed_By_Fixed_Giving_Fixed (N);
end if;
end if;
-- Other cases of division of fixed-point operands. Again we
-- exclude the case where Treat_Fixed_As_Integer is set.
elsif (Is_Fixed_Point_Type (Ltyp) or else
Is_Fixed_Point_Type (Rtyp))
and then not Treat_Fixed_As_Integer (N)
then
if Is_Integer_Type (Typ) then
Expand_Divide_Fixed_By_Fixed_Giving_Integer (N);
else
pragma Assert (Is_Floating_Point_Type (Typ));
Expand_Divide_Fixed_By_Fixed_Giving_Float (N);
end if;
-- Mixed-mode operations can appear in a non-static universal
-- context, in which case the integer argument must be converted
-- explicitly.
elsif Typ = Universal_Real
and then Is_Integer_Type (Rtyp)
then
Rewrite (Ropnd,
Convert_To (Universal_Real, Relocate_Node (Ropnd)));
Analyze_And_Resolve (Ropnd, Universal_Real);
elsif Typ = Universal_Real
and then Is_Integer_Type (Ltyp)
then
Rewrite (Lopnd,
Convert_To (Universal_Real, Relocate_Node (Lopnd)));
Analyze_And_Resolve (Lopnd, Universal_Real);
-- Non-fixed point cases, do integer zero divide and overflow checks
elsif Is_Integer_Type (Typ) then
Apply_Divide_Check (N);
-- Check for 64-bit division available, or long shifts if the divisor
-- is a small power of 2 (since such divides will be converted into
-- long shifts.
if Esize (Ltyp) > 32
and then not Support_64_Bit_Divides_On_Target
and then
(not Rknow
or else not Support_Long_Shifts_On_Target
or else (Rval /= Uint_2 and then
Rval /= Uint_4 and then
Rval /= Uint_8 and then
Rval /= Uint_16 and then
Rval /= Uint_32 and then
Rval /= Uint_64))
then
Error_Msg_CRT ("64-bit division", N);
end if;
-- Deal with Vax_Float
elsif Vax_Float (Typ) then
Expand_Vax_Arith (N);
return;
end if;
end Expand_N_Op_Divide;
--------------------
-- Expand_N_Op_Eq --
--------------------
procedure Expand_N_Op_Eq (N : Node_Id) is
Loc : constant Source_Ptr := Sloc (N);
Typ : constant Entity_Id := Etype (N);
Lhs : constant Node_Id := Left_Opnd (N);
Rhs : constant Node_Id := Right_Opnd (N);
Bodies : constant List_Id := New_List;
A_Typ : constant Entity_Id := Etype (Lhs);
Typl : Entity_Id := A_Typ;
Op_Name : Entity_Id;
Prim : Elmt_Id;
procedure Build_Equality_Call (Eq : Entity_Id);
-- If a constructed equality exists for the type or for its parent,
-- build and analyze call, adding conversions if the operation is
-- inherited.
function Has_Unconstrained_UU_Component (Typ : Node_Id) return Boolean;
-- Determines whether a type has a subcompoment of an unconstrained
-- Unchecked_Union subtype. Typ is a record type.
-------------------------
-- Build_Equality_Call --
-------------------------
procedure Build_Equality_Call (Eq : Entity_Id) is
Op_Type : constant Entity_Id := Etype (First_Formal (Eq));
L_Exp : Node_Id := Relocate_Node (Lhs);
R_Exp : Node_Id := Relocate_Node (Rhs);
begin
if Base_Type (Op_Type) /= Base_Type (A_Typ)
and then not Is_Class_Wide_Type (A_Typ)
then
L_Exp := OK_Convert_To (Op_Type, L_Exp);
R_Exp := OK_Convert_To (Op_Type, R_Exp);
end if;
-- If we have an Unchecked_Union, we need to add the inferred
-- discriminant values as actuals in the function call. At this
-- point, the expansion has determined that both operands have
-- inferable discriminants.
if Is_Unchecked_Union (Op_Type) then
declare
Lhs_Type : constant Node_Id := Etype (L_Exp);
Rhs_Type : constant Node_Id := Etype (R_Exp);
Lhs_Discr_Val : Node_Id;
Rhs_Discr_Val : Node_Id;
begin
-- Per-object constrained selected components require special
-- attention. If the enclosing scope of the component is an
-- Unchecked_Union, we cannot reference its discriminants
-- directly. This is why we use the two extra parameters of
-- the equality function of the enclosing Unchecked_Union.
-- type UU_Type (Discr : Integer := 0) is
-- . . .
-- end record;
-- pragma Unchecked_Union (UU_Type);
-- 1. Unchecked_Union enclosing record:
-- type Enclosing_UU_Type (Discr : Integer := 0) is record
-- . . .
-- Comp : UU_Type (Discr);
-- . . .
-- end Enclosing_UU_Type;
-- pragma Unchecked_Union (Enclosing_UU_Type);
-- Obj1 : Enclosing_UU_Type;
-- Obj2 : Enclosing_UU_Type (1);
-- [. . .] Obj1 = Obj2 [. . .]
-- Generated code:
-- if not (uu_typeEQ (obj1.comp, obj2.comp, a, b)) then
-- A and B are the formal parameters of the equality function
-- of Enclosing_UU_Type. The function always has two extra
-- formals to capture the inferred discriminant values.
-- 2. Non-Unchecked_Union enclosing record:
-- type
-- Enclosing_Non_UU_Type (Discr : Integer := 0)
-- is record
-- . . .
-- Comp : UU_Type (Discr);
-- . . .
-- end Enclosing_Non_UU_Type;
-- Obj1 : Enclosing_Non_UU_Type;
-- Obj2 : Enclosing_Non_UU_Type (1);
-- ... Obj1 = Obj2 ...
-- Generated code:
-- if not (uu_typeEQ (obj1.comp, obj2.comp,
-- obj1.discr, obj2.discr)) then
-- In this case we can directly reference the discriminants of
-- the enclosing record.
-- Lhs of equality
if Nkind (Lhs) = N_Selected_Component
and then Has_Per_Object_Constraint
(Entity (Selector_Name (Lhs)))
then
-- Enclosing record is an Unchecked_Union, use formal A
if Is_Unchecked_Union (Scope
(Entity (Selector_Name (Lhs))))
then
Lhs_Discr_Val :=
Make_Identifier (Loc,
Chars => Name_A);
-- Enclosing record is of a non-Unchecked_Union type, it is
-- possible to reference the discriminant.
else
Lhs_Discr_Val :=
Make_Selected_Component (Loc,
Prefix => Prefix (Lhs),
Selector_Name =>
New_Copy
(Get_Discriminant_Value
(First_Discriminant (Lhs_Type),
Lhs_Type,
Stored_Constraint (Lhs_Type))));
end if;
-- Comment needed here ???
else
-- Infer the discriminant value
Lhs_Discr_Val :=
New_Copy
(Get_Discriminant_Value
(First_Discriminant (Lhs_Type),
Lhs_Type,
Stored_Constraint (Lhs_Type)));
end if;
-- Rhs of equality
if Nkind (Rhs) = N_Selected_Component
and then Has_Per_Object_Constraint
(Entity (Selector_Name (Rhs)))
then
if Is_Unchecked_Union
(Scope (Entity (Selector_Name (Rhs))))
then
Rhs_Discr_Val :=
Make_Identifier (Loc,
Chars => Name_B);
else
Rhs_Discr_Val :=
Make_Selected_Component (Loc,
Prefix => Prefix (Rhs),
Selector_Name =>
New_Copy (Get_Discriminant_Value (
First_Discriminant (Rhs_Type),
Rhs_Type,
Stored_Constraint (Rhs_Type))));
end if;
else
Rhs_Discr_Val :=
New_Copy (Get_Discriminant_Value (
First_Discriminant (Rhs_Type),
Rhs_Type,
Stored_Constraint (Rhs_Type)));
end if;
Rewrite (N,
Make_Function_Call (Loc,
Name => New_Reference_To (Eq, Loc),
Parameter_Associations => New_List (
L_Exp,
R_Exp,
Lhs_Discr_Val,
Rhs_Discr_Val)));
end;
-- Normal case, not an unchecked union
else
Rewrite (N,
Make_Function_Call (Loc,
Name => New_Reference_To (Eq, Loc),
Parameter_Associations => New_List (L_Exp, R_Exp)));
end if;
Analyze_And_Resolve (N, Standard_Boolean, Suppress => All_Checks);
end Build_Equality_Call;
------------------------------------
-- Has_Unconstrained_UU_Component --
------------------------------------
function Has_Unconstrained_UU_Component
(Typ : Node_Id) return Boolean
is
Tdef : constant Node_Id :=
Type_Definition (Declaration_Node (Base_Type (Typ)));
Clist : Node_Id;
Vpart : Node_Id;
function Component_Is_Unconstrained_UU
(Comp : Node_Id) return Boolean;
-- Determines whether the subtype of the component is an
-- unconstrained Unchecked_Union.
function Variant_Is_Unconstrained_UU
(Variant : Node_Id) return Boolean;
-- Determines whether a component of the variant has an unconstrained
-- Unchecked_Union subtype.
-----------------------------------
-- Component_Is_Unconstrained_UU --
-----------------------------------
function Component_Is_Unconstrained_UU
(Comp : Node_Id) return Boolean
is
begin
if Nkind (Comp) /= N_Component_Declaration then
return False;
end if;
declare
Sindic : constant Node_Id :=
Subtype_Indication (Component_Definition (Comp));
begin
-- Unconstrained nominal type. In the case of a constraint
-- present, the node kind would have been N_Subtype_Indication.
if Nkind (Sindic) = N_Identifier then
return Is_Unchecked_Union (Base_Type (Etype (Sindic)));
end if;
return False;
end;
end Component_Is_Unconstrained_UU;
---------------------------------
-- Variant_Is_Unconstrained_UU --
---------------------------------
function Variant_Is_Unconstrained_UU
(Variant : Node_Id) return Boolean
is
Clist : constant Node_Id := Component_List (Variant);
begin
if Is_Empty_List (Component_Items (Clist)) then
return False;
end if;
-- We only need to test one component
declare
Comp : Node_Id := First (Component_Items (Clist));
begin
while Present (Comp) loop
if Component_Is_Unconstrained_UU (Comp) then
return True;
end if;
Next (Comp);
end loop;
end;
-- None of the components withing the variant were of
-- unconstrained Unchecked_Union type.
return False;
end Variant_Is_Unconstrained_UU;
-- Start of processing for Has_Unconstrained_UU_Component
begin
if Null_Present (Tdef) then
return False;
end if;
Clist := Component_List (Tdef);
Vpart := Variant_Part (Clist);
-- Inspect available components
if Present (Component_Items (Clist)) then
declare
Comp : Node_Id := First (Component_Items (Clist));
begin
while Present (Comp) loop
-- One component is sufficent
if Component_Is_Unconstrained_UU (Comp) then
return True;
end if;
Next (Comp);
end loop;
end;
end if;
-- Inspect available components withing variants
if Present (Vpart) then
declare
Variant : Node_Id := First (Variants (Vpart));
begin
while Present (Variant) loop
-- One component within a variant is sufficent
if Variant_Is_Unconstrained_UU (Variant) then
return True;
end if;
Next (Variant);
end loop;
end;
end if;
-- Neither the available components, nor the components inside the
-- variant parts were of an unconstrained Unchecked_Union subtype.
return False;
end Has_Unconstrained_UU_Component;
-- Start of processing for Expand_N_Op_Eq
begin
Binary_Op_Validity_Checks (N);
if Ekind (Typl) = E_Private_Type then
Typl := Underlying_Type (Typl);
elsif Ekind (Typl) = E_Private_Subtype then
Typl := Underlying_Type (Base_Type (Typl));
else
null;
end if;
-- It may happen in error situations that the underlying type is not
-- set. The error will be detected later, here we just defend the
-- expander code.
if No (Typl) then
return;
end if;
Typl := Base_Type (Typl);
-- Boolean types (requiring handling of non-standard case)
if Is_Boolean_Type (Typl) then
Adjust_Condition (Left_Opnd (N));
Adjust_Condition (Right_Opnd (N));
Set_Etype (N, Standard_Boolean);
Adjust_Result_Type (N, Typ);
-- Array types
elsif Is_Array_Type (Typl) then
-- If we are doing full validity checking, then expand out array
-- comparisons to make sure that we check the array elements.
if Validity_Check_Operands then
declare
Save_Force_Validity_Checks : constant Boolean :=
Force_Validity_Checks;
begin
Force_Validity_Checks := True;
Rewrite (N,
Expand_Array_Equality
(N,
Relocate_Node (Lhs),
Relocate_Node (Rhs),
Bodies,
Typl));
Insert_Actions (N, Bodies);
Analyze_And_Resolve (N, Standard_Boolean);
Force_Validity_Checks := Save_Force_Validity_Checks;
end;
-- Packed case where both operands are known aligned
elsif Is_Bit_Packed_Array (Typl)
and then not Is_Possibly_Unaligned_Object (Lhs)
and then not Is_Possibly_Unaligned_Object (Rhs)
then
Expand_Packed_Eq (N);
-- Where the component type is elementary we can use a block bit
-- comparison (if supported on the target) exception in the case
-- of floating-point (negative zero issues require element by
-- element comparison), and atomic types (where we must be sure
-- to load elements independently) and possibly unaligned arrays.
elsif Is_Elementary_Type (Component_Type (Typl))
and then not Is_Floating_Point_Type (Component_Type (Typl))
and then not Is_Atomic (Component_Type (Typl))
and then not Is_Possibly_Unaligned_Object (Lhs)
and then not Is_Possibly_Unaligned_Object (Rhs)
and then Support_Composite_Compare_On_Target
then
null;
-- For composite and floating-point cases, expand equality loop
-- to make sure of using proper comparisons for tagged types,
-- and correctly handling the floating-point case.
else
Rewrite (N,
Expand_Array_Equality
(N,
Relocate_Node (Lhs),
Relocate_Node (Rhs),
Bodies,
Typl));
Insert_Actions (N, Bodies, Suppress => All_Checks);
Analyze_And_Resolve (N, Standard_Boolean, Suppress => All_Checks);
end if;
-- Record Types
elsif Is_Record_Type (Typl) then
-- For tagged types, use the primitive "="
if Is_Tagged_Type (Typl) then
-- If this is derived from an untagged private type completed
-- with a tagged type, it does not have a full view, so we
-- use the primitive operations of the private type.
-- This check should no longer be necessary when these
-- types receive their full views ???
if Is_Private_Type (A_Typ)
and then not Is_Tagged_Type (A_Typ)
and then Is_Derived_Type (A_Typ)
and then No (Full_View (A_Typ))
then
-- Search for equality operation, checking that the
-- operands have the same type. Note that we must find
-- a matching entry, or something is very wrong!
Prim := First_Elmt (Collect_Primitive_Operations (A_Typ));
while Present (Prim) loop
exit when Chars (Node (Prim)) = Name_Op_Eq
and then Etype (First_Formal (Node (Prim))) =
Etype (Next_Formal (First_Formal (Node (Prim))))
and then
Base_Type (Etype (Node (Prim))) = Standard_Boolean;
Next_Elmt (Prim);
end loop;
pragma Assert (Present (Prim));
Op_Name := Node (Prim);
-- Find the type's predefined equality or an overriding
-- user-defined equality. The reason for not simply calling
-- Find_Prim_Op here is that there may be a user-defined
-- overloaded equality op that precedes the equality that
-- we want, so we have to explicitly search (e.g., there
-- could be an equality with two different parameter types).
else
if Is_Class_Wide_Type (Typl) then
Typl := Root_Type (Typl);
end if;
Prim := First_Elmt (Primitive_Operations (Typl));
while Present (Prim) loop
exit when Chars (Node (Prim)) = Name_Op_Eq
and then Etype (First_Formal (Node (Prim))) =
Etype (Next_Formal (First_Formal (Node (Prim))))
and then
Base_Type (Etype (Node (Prim))) = Standard_Boolean;
Next_Elmt (Prim);
end loop;
pragma Assert (Present (Prim));
Op_Name := Node (Prim);
end if;
Build_Equality_Call (Op_Name);
-- Ada 2005 (AI-216): Program_Error is raised when evaluating the
-- predefined equality operator for a type which has a subcomponent
-- of an Unchecked_Union type whose nominal subtype is unconstrained.
elsif Has_Unconstrained_UU_Component (Typl) then
Insert_Action (N,
Make_Raise_Program_Error (Loc,
Reason => PE_Unchecked_Union_Restriction));
-- Prevent Gigi from generating incorrect code by rewriting the
-- equality as a standard False.
Rewrite (N,
New_Occurrence_Of (Standard_False, Loc));
elsif Is_Unchecked_Union (Typl) then
-- If we can infer the discriminants of the operands, we make a
-- call to the TSS equality function.
if Has_Inferable_Discriminants (Lhs)
and then
Has_Inferable_Discriminants (Rhs)
then
Build_Equality_Call
(TSS (Root_Type (Typl), TSS_Composite_Equality));
else
-- Ada 2005 (AI-216): Program_Error is raised when evaluating
-- the predefined equality operator for an Unchecked_Union type
-- if either of the operands lack inferable discriminants.
Insert_Action (N,
Make_Raise_Program_Error (Loc,
Reason => PE_Unchecked_Union_Restriction));
-- Prevent Gigi from generating incorrect code by rewriting
-- the equality as a standard False.
Rewrite (N,
New_Occurrence_Of (Standard_False, Loc));
end if;
-- If a type support function is present (for complex cases), use it
elsif Present (TSS (Root_Type (Typl), TSS_Composite_Equality)) then
Build_Equality_Call
(TSS (Root_Type (Typl), TSS_Composite_Equality));
-- Otherwise expand the component by component equality. Note that
-- we never use block-bit coparisons for records, because of the
-- problems with gaps. The backend will often be able to recombine
-- the separate comparisons that we generate here.
else
Remove_Side_Effects (Lhs);
Remove_Side_Effects (Rhs);
Rewrite (N,
Expand_Record_Equality (N, Typl, Lhs, Rhs, Bodies));
Insert_Actions (N, Bodies, Suppress => All_Checks);
Analyze_And_Resolve (N, Standard_Boolean, Suppress => All_Checks);
end if;
end if;
-- Test if result is known at compile time
Rewrite_Comparison (N);
-- If we still have comparison for Vax_Float, process it
if Vax_Float (Typl) and then Nkind (N) in N_Op_Compare then
Expand_Vax_Comparison (N);
return;
end if;
end Expand_N_Op_Eq;
-----------------------
-- Expand_N_Op_Expon --
-----------------------
procedure Expand_N_Op_Expon (N : Node_Id) is
Loc : constant Source_Ptr := Sloc (N);
Typ : constant Entity_Id := Etype (N);
Rtyp : constant Entity_Id := Root_Type (Typ);
Base : constant Node_Id := Relocate_Node (Left_Opnd (N));
Bastyp : constant Node_Id := Etype (Base);
Exp : constant Node_Id := Relocate_Node (Right_Opnd (N));
Exptyp : constant Entity_Id := Etype (Exp);
Ovflo : constant Boolean := Do_Overflow_Check (N);
Expv : Uint;
Xnode : Node_Id;
Temp : Node_Id;
Rent : RE_Id;
Ent : Entity_Id;
Etyp : Entity_Id;
begin
Binary_Op_Validity_Checks (N);
-- If either operand is of a private type, then we have the use of
-- an intrinsic operator, and we get rid of the privateness, by using
-- root types of underlying types for the actual operation. Otherwise
-- the private types will cause trouble if we expand multiplications
-- or shifts etc. We also do this transformation if the result type
-- is different from the base type.
if Is_Private_Type (Etype (Base))
or else
Is_Private_Type (Typ)
or else
Is_Private_Type (Exptyp)
or else
Rtyp /= Root_Type (Bastyp)
then
declare
Bt : constant Entity_Id := Root_Type (Underlying_Type (Bastyp));
Et : constant Entity_Id := Root_Type (Underlying_Type (Exptyp));
begin
Rewrite (N,
Unchecked_Convert_To (Typ,
Make_Op_Expon (Loc,
Left_Opnd => Unchecked_Convert_To (Bt, Base),
Right_Opnd => Unchecked_Convert_To (Et, Exp))));
Analyze_And_Resolve (N, Typ);
return;
end;
end if;
-- Test for case of known right argument
if Compile_Time_Known_Value (Exp) then
Expv := Expr_Value (Exp);
-- We only fold small non-negative exponents. You might think we
-- could fold small negative exponents for the real case, but we
-- can't because we are required to raise Constraint_Error for
-- the case of 0.0 ** (negative) even if Machine_Overflows = False.
-- See ACVC test C4A012B.
if Expv >= 0 and then Expv <= 4 then
-- X ** 0 = 1 (or 1.0)
if Expv = 0 then
if Ekind (Typ) in Integer_Kind then
Xnode := Make_Integer_Literal (Loc, Intval => 1);
else
Xnode := Make_Real_Literal (Loc, Ureal_1);
end if;
-- X ** 1 = X
elsif Expv = 1 then
Xnode := Base;
-- X ** 2 = X * X
elsif Expv = 2 then
Xnode :=
Make_Op_Multiply (Loc,
Left_Opnd => Duplicate_Subexpr (Base),
Right_Opnd => Duplicate_Subexpr_No_Checks (Base));
-- X ** 3 = X * X * X
elsif Expv = 3 then
Xnode :=
Make_Op_Multiply (Loc,
Left_Opnd =>
Make_Op_Multiply (Loc,
Left_Opnd => Duplicate_Subexpr (Base),
Right_Opnd => Duplicate_Subexpr_No_Checks (Base)),
Right_Opnd => Duplicate_Subexpr_No_Checks (Base));
-- X ** 4 ->
-- En : constant base'type := base * base;
-- ...
-- En * En
else -- Expv = 4
Temp :=
Make_Defining_Identifier (Loc, New_Internal_Name ('E'));
Insert_Actions (N, New_List (
Make_Object_Declaration (Loc,
Defining_Identifier => Temp,
Constant_Present => True,
Object_Definition => New_Reference_To (Typ, Loc),
Expression =>
Make_Op_Multiply (Loc,
Left_Opnd => Duplicate_Subexpr (Base),
Right_Opnd => Duplicate_Subexpr_No_Checks (Base)))));
Xnode :=
Make_Op_Multiply (Loc,
Left_Opnd => New_Reference_To (Temp, Loc),
Right_Opnd => New_Reference_To (Temp, Loc));
end if;
Rewrite (N, Xnode);
Analyze_And_Resolve (N, Typ);
return;
end if;
end if;
-- Case of (2 ** expression) appearing as an argument of an integer
-- multiplication, or as the right argument of a division of a non-
-- negative integer. In such cases we leave the node untouched, setting
-- the flag Is_Natural_Power_Of_2_for_Shift set, then the expansion
-- of the higher level node converts it into a shift.
if Nkind (Base) = N_Integer_Literal
and then Intval (Base) = 2
and then Is_Integer_Type (Root_Type (Exptyp))
and then Esize (Root_Type (Exptyp)) <= Esize (Standard_Integer)
and then Is_Unsigned_Type (Exptyp)
and then not Ovflo
and then Nkind (Parent (N)) in N_Binary_Op
then
declare
P : constant Node_Id := Parent (N);
L : constant Node_Id := Left_Opnd (P);
R : constant Node_Id := Right_Opnd (P);
begin
if (Nkind (P) = N_Op_Multiply
and then
((Is_Integer_Type (Etype (L)) and then R = N)
or else
(Is_Integer_Type (Etype (R)) and then L = N))
and then not Do_Overflow_Check (P))
or else
(Nkind (P) = N_Op_Divide
and then Is_Integer_Type (Etype (L))
and then Is_Unsigned_Type (Etype (L))
and then R = N
and then not Do_Overflow_Check (P))
then
Set_Is_Power_Of_2_For_Shift (N);
return;
end if;
end;
end if;
-- Fall through if exponentiation must be done using a runtime routine
-- First deal with modular case
if Is_Modular_Integer_Type (Rtyp) then
-- Non-binary case, we call the special exponentiation routine for
-- the non-binary case, converting the argument to Long_Long_Integer
-- and passing the modulus value. Then the result is converted back
-- to the base type.
if Non_Binary_Modulus (Rtyp) then
Rewrite (N,
Convert_To (Typ,
Make_Function_Call (Loc,
Name => New_Reference_To (RTE (RE_Exp_Modular), Loc),
Parameter_Associations => New_List (
Convert_To (Standard_Integer, Base),
Make_Integer_Literal (Loc, Modulus (Rtyp)),
Exp))));
-- Binary case, in this case, we call one of two routines, either
-- the unsigned integer case, or the unsigned long long integer
-- case, with a final "and" operation to do the required mod.
else
if UI_To_Int (Esize (Rtyp)) <= Standard_Integer_Size then
Ent := RTE (RE_Exp_Unsigned);
else
Ent := RTE (RE_Exp_Long_Long_Unsigned);
end if;
Rewrite (N,
Convert_To (Typ,
Make_Op_And (Loc,
Left_Opnd =>
Make_Function_Call (Loc,
Name => New_Reference_To (Ent, Loc),
Parameter_Associations => New_List (
Convert_To (Etype (First_Formal (Ent)), Base),
Exp)),
Right_Opnd =>
Make_Integer_Literal (Loc, Modulus (Rtyp) - 1))));
end if;
-- Common exit point for modular type case
Analyze_And_Resolve (N, Typ);
return;
-- Signed integer cases, done using either Integer or Long_Long_Integer.
-- It is not worth having routines for Short_[Short_]Integer, since for
-- most machines it would not help, and it would generate more code that
-- might need certification when a certified run time is required.
-- In the integer cases, we have two routines, one for when overflow
-- checks are required, and one when they are not required, since there
-- is a real gain in omitting checks on many machines.
elsif Rtyp = Base_Type (Standard_Long_Long_Integer)
or else (Rtyp = Base_Type (Standard_Long_Integer)
and then
Esize (Standard_Long_Integer) > Esize (Standard_Integer))
or else (Rtyp = Universal_Integer)
then
Etyp := Standard_Long_Long_Integer;
if Ovflo then
Rent := RE_Exp_Long_Long_Integer;
else
Rent := RE_Exn_Long_Long_Integer;
end if;
elsif Is_Signed_Integer_Type (Rtyp) then
Etyp := Standard_Integer;
if Ovflo then
Rent := RE_Exp_Integer;
else
Rent := RE_Exn_Integer;
end if;
-- Floating-point cases, always done using Long_Long_Float. We do not
-- need separate routines for the overflow case here, since in the case
-- of floating-point, we generate infinities anyway as a rule (either
-- that or we automatically trap overflow), and if there is an infinity
-- generated and a range check is required, the check will fail anyway.
else
pragma Assert (Is_Floating_Point_Type (Rtyp));
Etyp := Standard_Long_Long_Float;
Rent := RE_Exn_Long_Long_Float;
end if;
-- Common processing for integer cases and floating-point cases.
-- If we are in the right type, we can call runtime routine directly
if Typ = Etyp
and then Rtyp /= Universal_Integer
and then Rtyp /= Universal_Real
then
Rewrite (N,
Make_Function_Call (Loc,
Name => New_Reference_To (RTE (Rent), Loc),
Parameter_Associations => New_List (Base, Exp)));
-- Otherwise we have to introduce conversions (conversions are also
-- required in the universal cases, since the runtime routine is
-- typed using one of the standard types.
else
Rewrite (N,
Convert_To (Typ,
Make_Function_Call (Loc,
Name => New_Reference_To (RTE (Rent), Loc),
Parameter_Associations => New_List (
Convert_To (Etyp, Base),
Exp))));
end if;
Analyze_And_Resolve (N, Typ);
return;
exception
when RE_Not_Available =>
return;
end Expand_N_Op_Expon;
--------------------
-- Expand_N_Op_Ge --
--------------------
procedure Expand_N_Op_Ge (N : Node_Id) is
Typ : constant Entity_Id := Etype (N);
Op1 : constant Node_Id := Left_Opnd (N);
Op2 : constant Node_Id := Right_Opnd (N);
Typ1 : constant Entity_Id := Base_Type (Etype (Op1));
begin
Binary_Op_Validity_Checks (N);
if Is_Array_Type (Typ1) then
Expand_Array_Comparison (N);
return;
end if;
if Is_Boolean_Type (Typ1) then
Adjust_Condition (Op1);
Adjust_Condition (Op2);
Set_Etype (N, Standard_Boolean);
Adjust_Result_Type (N, Typ);
end if;
Rewrite_Comparison (N);
-- If we still have comparison, and Vax_Float type, process it
if Vax_Float (Typ1) and then Nkind (N) in N_Op_Compare then
Expand_Vax_Comparison (N);
return;
end if;
end Expand_N_Op_Ge;
--------------------
-- Expand_N_Op_Gt --
--------------------
procedure Expand_N_Op_Gt (N : Node_Id) is
Typ : constant Entity_Id := Etype (N);
Op1 : constant Node_Id := Left_Opnd (N);
Op2 : constant Node_Id := Right_Opnd (N);
Typ1 : constant Entity_Id := Base_Type (Etype (Op1));
begin
Binary_Op_Validity_Checks (N);
if Is_Array_Type (Typ1) then
Expand_Array_Comparison (N);
return;
end if;
if Is_Boolean_Type (Typ1) then
Adjust_Condition (Op1);
Adjust_Condition (Op2);
Set_Etype (N, Standard_Boolean);
Adjust_Result_Type (N, Typ);
end if;
Rewrite_Comparison (N);
-- If we still have comparison, and Vax_Float type, process it
if Vax_Float (Typ1) and then Nkind (N) in N_Op_Compare then
Expand_Vax_Comparison (N);
return;
end if;
end Expand_N_Op_Gt;
--------------------
-- Expand_N_Op_Le --
--------------------
procedure Expand_N_Op_Le (N : Node_Id) is
Typ : constant Entity_Id := Etype (N);
Op1 : constant Node_Id := Left_Opnd (N);
Op2 : constant Node_Id := Right_Opnd (N);
Typ1 : constant Entity_Id := Base_Type (Etype (Op1));
begin
Binary_Op_Validity_Checks (N);
if Is_Array_Type (Typ1) then
Expand_Array_Comparison (N);
return;
end if;
if Is_Boolean_Type (Typ1) then
Adjust_Condition (Op1);
Adjust_Condition (Op2);
Set_Etype (N, Standard_Boolean);
Adjust_Result_Type (N, Typ);
end if;
Rewrite_Comparison (N);
-- If we still have comparison, and Vax_Float type, process it
if Vax_Float (Typ1) and then Nkind (N) in N_Op_Compare then
Expand_Vax_Comparison (N);
return;
end if;
end Expand_N_Op_Le;
--------------------
-- Expand_N_Op_Lt --
--------------------
procedure Expand_N_Op_Lt (N : Node_Id) is
Typ : constant Entity_Id := Etype (N);
Op1 : constant Node_Id := Left_Opnd (N);
Op2 : constant Node_Id := Right_Opnd (N);
Typ1 : constant Entity_Id := Base_Type (Etype (Op1));
begin
Binary_Op_Validity_Checks (N);
if Is_Array_Type (Typ1) then
Expand_Array_Comparison (N);
return;
end if;
if Is_Boolean_Type (Typ1) then
Adjust_Condition (Op1);
Adjust_Condition (Op2);
Set_Etype (N, Standard_Boolean);
Adjust_Result_Type (N, Typ);
end if;
Rewrite_Comparison (N);
-- If we still have comparison, and Vax_Float type, process it
if Vax_Float (Typ1) and then Nkind (N) in N_Op_Compare then
Expand_Vax_Comparison (N);
return;
end if;
end Expand_N_Op_Lt;
-----------------------
-- Expand_N_Op_Minus --
-----------------------
procedure Expand_N_Op_Minus (N : Node_Id) is
Loc : constant Source_Ptr := Sloc (N);
Typ : constant Entity_Id := Etype (N);
begin
Unary_Op_Validity_Checks (N);
if not Backend_Overflow_Checks_On_Target
and then Is_Signed_Integer_Type (Etype (N))
and then Do_Overflow_Check (N)
then
-- Software overflow checking expands -expr into (0 - expr)
Rewrite (N,
Make_Op_Subtract (Loc,
Left_Opnd => Make_Integer_Literal (Loc, 0),
Right_Opnd => Right_Opnd (N)));
Analyze_And_Resolve (N, Typ);
-- Vax floating-point types case
elsif Vax_Float (Etype (N)) then
Expand_Vax_Arith (N);
end if;
end Expand_N_Op_Minus;
---------------------
-- Expand_N_Op_Mod --
---------------------
procedure Expand_N_Op_Mod (N : Node_Id) is
Loc : constant Source_Ptr := Sloc (N);
Typ : constant Entity_Id := Etype (N);
Left : constant Node_Id := Left_Opnd (N);
Right : constant Node_Id := Right_Opnd (N);
DOC : constant Boolean := Do_Overflow_Check (N);
DDC : constant Boolean := Do_Division_Check (N);
LLB : Uint;
Llo : Uint;
Lhi : Uint;
LOK : Boolean;
Rlo : Uint;
Rhi : Uint;
ROK : Boolean;
begin
Binary_Op_Validity_Checks (N);
Determine_Range (Right, ROK, Rlo, Rhi);
Determine_Range (Left, LOK, Llo, Lhi);
-- Convert mod to rem if operands are known non-negative. We do this
-- since it is quite likely that this will improve the quality of code,
-- (the operation now corresponds to the hardware remainder), and it
-- does not seem likely that it could be harmful.
if LOK and then Llo >= 0
and then
ROK and then Rlo >= 0
then
Rewrite (N,
Make_Op_Rem (Sloc (N),
Left_Opnd => Left_Opnd (N),
Right_Opnd => Right_Opnd (N)));
-- Instead of reanalyzing the node we do the analysis manually.
-- This avoids anomalies when the replacement is done in an
-- instance and is epsilon more efficient.
Set_Entity (N, Standard_Entity (S_Op_Rem));
Set_Etype (N, Typ);
Set_Do_Overflow_Check (N, DOC);
Set_Do_Division_Check (N, DDC);
Expand_N_Op_Rem (N);
Set_Analyzed (N);
-- Otherwise, normal mod processing
else
if Is_Integer_Type (Etype (N)) then
Apply_Divide_Check (N);
end if;
-- Apply optimization x mod 1 = 0. We don't really need that with
-- gcc, but it is useful with other back ends (e.g. AAMP), and is
-- certainly harmless.
if Is_Integer_Type (Etype (N))
and then Compile_Time_Known_Value (Right)
and then Expr_Value (Right) = Uint_1
then
Rewrite (N, Make_Integer_Literal (Loc, 0));
Analyze_And_Resolve (N, Typ);
return;
end if;
-- Deal with annoying case of largest negative number remainder
-- minus one. Gigi does not handle this case correctly, because
-- it generates a divide instruction which may trap in this case.
-- In fact the check is quite easy, if the right operand is -1,
-- then the mod value is always 0, and we can just ignore the
-- left operand completely in this case.
-- The operand type may be private (e.g. in the expansion of an
-- an intrinsic operation) so we must use the underlying type to
-- get the bounds, and convert the literals explicitly.
LLB :=
Expr_Value
(Type_Low_Bound (Base_Type (Underlying_Type (Etype (Left)))));
if ((not ROK) or else (Rlo <= (-1) and then (-1) <= Rhi))
and then
((not LOK) or else (Llo = LLB))
then
Rewrite (N,
Make_Conditional_Expression (Loc,
Expressions => New_List (
Make_Op_Eq (Loc,
Left_Opnd => Duplicate_Subexpr (Right),
Right_Opnd =>
Unchecked_Convert_To (Typ,
Make_Integer_Literal (Loc, -1))),
Unchecked_Convert_To (Typ,
Make_Integer_Literal (Loc, Uint_0)),
Relocate_Node (N))));
Set_Analyzed (Next (Next (First (Expressions (N)))));
Analyze_And_Resolve (N, Typ);
end if;
end if;
end Expand_N_Op_Mod;
--------------------------
-- Expand_N_Op_Multiply --
--------------------------
procedure Expand_N_Op_Multiply (N : Node_Id) is
Loc : constant Source_Ptr := Sloc (N);
Lop : constant Node_Id := Left_Opnd (N);
Rop : constant Node_Id := Right_Opnd (N);
Lp2 : constant Boolean :=
Nkind (Lop) = N_Op_Expon
and then Is_Power_Of_2_For_Shift (Lop);
Rp2 : constant Boolean :=
Nkind (Rop) = N_Op_Expon
and then Is_Power_Of_2_For_Shift (Rop);
Ltyp : constant Entity_Id := Etype (Lop);
Rtyp : constant Entity_Id := Etype (Rop);
Typ : Entity_Id := Etype (N);
begin
Binary_Op_Validity_Checks (N);
-- Special optimizations for integer types
if Is_Integer_Type (Typ) then
-- N * 0 = 0 * N = 0 for integer types
if (Compile_Time_Known_Value (Rop)
and then Expr_Value (Rop) = Uint_0)
or else
(Compile_Time_Known_Value (Lop)
and then Expr_Value (Lop) = Uint_0)
then
Rewrite (N, Make_Integer_Literal (Loc, Uint_0));
Analyze_And_Resolve (N, Typ);
return;
end if;
-- N * 1 = 1 * N = N for integer types
-- This optimisation is not done if we are going to
-- rewrite the product 1 * 2 ** N to a shift.
if Compile_Time_Known_Value (Rop)
and then Expr_Value (Rop) = Uint_1
and then not Lp2
then
Rewrite (N, Lop);
return;
elsif Compile_Time_Known_Value (Lop)
and then Expr_Value (Lop) = Uint_1
and then not Rp2
then
Rewrite (N, Rop);
return;
end if;
end if;
-- Convert x * 2 ** y to Shift_Left (x, y). Note that the fact that
-- Is_Power_Of_2_For_Shift is set means that we know that our left
-- operand is an integer, as required for this to work.
if Rp2 then
if Lp2 then
-- Convert 2 ** A * 2 ** B into 2 ** (A + B)
Rewrite (N,
Make_Op_Expon (Loc,
Left_Opnd => Make_Integer_Literal (Loc, 2),
Right_Opnd =>
Make_Op_Add (Loc,
Left_Opnd => Right_Opnd (Lop),
Right_Opnd => Right_Opnd (Rop))));
Analyze_And_Resolve (N, Typ);
return;
else
Rewrite (N,
Make_Op_Shift_Left (Loc,
Left_Opnd => Lop,
Right_Opnd =>
Convert_To (Standard_Natural, Right_Opnd (Rop))));
Analyze_And_Resolve (N, Typ);
return;
end if;
-- Same processing for the operands the other way round
elsif Lp2 then
Rewrite (N,
Make_Op_Shift_Left (Loc,
Left_Opnd => Rop,
Right_Opnd =>
Convert_To (Standard_Natural, Right_Opnd (Lop))));
Analyze_And_Resolve (N, Typ);
return;
end if;
-- Do required fixup of universal fixed operation
if Typ = Universal_Fixed then
Fixup_Universal_Fixed_Operation (N);
Typ := Etype (N);
end if;
-- Multiplications with fixed-point results
if Is_Fixed_Point_Type (Typ) then
-- No special processing if Treat_Fixed_As_Integer is set,
-- since from a semantic point of view such operations are
-- simply integer operations and will be treated that way.
if not Treat_Fixed_As_Integer (N) then
-- Case of fixed * integer => fixed
if Is_Integer_Type (Rtyp) then
Expand_Multiply_Fixed_By_Integer_Giving_Fixed (N);
-- Case of integer * fixed => fixed
elsif Is_Integer_Type (Ltyp) then
Expand_Multiply_Integer_By_Fixed_Giving_Fixed (N);
-- Case of fixed * fixed => fixed
else
Expand_Multiply_Fixed_By_Fixed_Giving_Fixed (N);
end if;
end if;
-- Other cases of multiplication of fixed-point operands. Again
-- we exclude the cases where Treat_Fixed_As_Integer flag is set.
elsif (Is_Fixed_Point_Type (Ltyp) or else Is_Fixed_Point_Type (Rtyp))
and then not Treat_Fixed_As_Integer (N)
then
if Is_Integer_Type (Typ) then
Expand_Multiply_Fixed_By_Fixed_Giving_Integer (N);
else
pragma Assert (Is_Floating_Point_Type (Typ));
Expand_Multiply_Fixed_By_Fixed_Giving_Float (N);
end if;
-- Mixed-mode operations can appear in a non-static universal
-- context, in which case the integer argument must be converted
-- explicitly.
elsif Typ = Universal_Real
and then Is_Integer_Type (Rtyp)
then
Rewrite (Rop, Convert_To (Universal_Real, Relocate_Node (Rop)));
Analyze_And_Resolve (Rop, Universal_Real);
elsif Typ = Universal_Real
and then Is_Integer_Type (Ltyp)
then
Rewrite (Lop, Convert_To (Universal_Real, Relocate_Node (Lop)));
Analyze_And_Resolve (Lop, Universal_Real);
-- Non-fixed point cases, check software overflow checking required
elsif Is_Signed_Integer_Type (Etype (N)) then
Apply_Arithmetic_Overflow_Check (N);
-- Deal with VAX float case
elsif Vax_Float (Typ) then
Expand_Vax_Arith (N);
return;
end if;
end Expand_N_Op_Multiply;
--------------------
-- Expand_N_Op_Ne --
--------------------
procedure Expand_N_Op_Ne (N : Node_Id) is
Typ : constant Entity_Id := Etype (Left_Opnd (N));
begin
-- Case of elementary type with standard operator
if Is_Elementary_Type (Typ)
and then Sloc (Entity (N)) = Standard_Location
then
Binary_Op_Validity_Checks (N);
-- Boolean types (requiring handling of non-standard case)
if Is_Boolean_Type (Typ) then
Adjust_Condition (Left_Opnd (N));
Adjust_Condition (Right_Opnd (N));
Set_Etype (N, Standard_Boolean);
Adjust_Result_Type (N, Typ);
end if;
Rewrite_Comparison (N);
-- If we still have comparison for Vax_Float, process it
if Vax_Float (Typ) and then Nkind (N) in N_Op_Compare then
Expand_Vax_Comparison (N);
return;
end if;
-- For all cases other than elementary types, we rewrite node as the
-- negation of an equality operation, and reanalyze. The equality to be
-- used is defined in the same scope and has the same signature. This
-- signature must be set explicitly since in an instance it may not have
-- the same visibility as in the generic unit. This avoids duplicating
-- or factoring the complex code for record/array equality tests etc.
else
declare
Loc : constant Source_Ptr := Sloc (N);
Neg : Node_Id;
Ne : constant Entity_Id := Entity (N);
begin
Binary_Op_Validity_Checks (N);
Neg :=
Make_Op_Not (Loc,
Right_Opnd =>
Make_Op_Eq (Loc,
Left_Opnd => Left_Opnd (N),
Right_Opnd => Right_Opnd (N)));
Set_Paren_Count (Right_Opnd (Neg), 1);
if Scope (Ne) /= Standard_Standard then
Set_Entity (Right_Opnd (Neg), Corresponding_Equality (Ne));
end if;
-- For navigation purposes, the inequality is treated as an
-- implicit reference to the corresponding equality. Preserve the
-- Comes_From_ source flag so that the proper Xref entry is
-- generated.
Preserve_Comes_From_Source (Neg, N);
Preserve_Comes_From_Source (Right_Opnd (Neg), N);
Rewrite (N, Neg);
Analyze_And_Resolve (N, Standard_Boolean);
end;
end if;
end Expand_N_Op_Ne;
---------------------
-- Expand_N_Op_Not --
---------------------
-- If the argument is other than a Boolean array type, there is no
-- special expansion required.
-- For the packed case, we call the special routine in Exp_Pakd, except
-- that if the component size is greater than one, we use the standard
-- routine generating a gruesome loop (it is so peculiar to have packed
-- arrays with non-standard Boolean representations anyway, so it does
-- not matter that we do not handle this case efficiently).
-- For the unpacked case (and for the special packed case where we have
-- non standard Booleans, as discussed above), we generate and insert
-- into the tree the following function definition:
-- function Nnnn (A : arr) is
-- B : arr;
-- begin
-- for J in a'range loop
-- B (J) := not A (J);
-- end loop;
-- return B;
-- end Nnnn;
-- Here arr is the actual subtype of the parameter (and hence always
-- constrained). Then we replace the not with a call to this function.
procedure Expand_N_Op_Not (N : Node_Id) is
Loc : constant Source_Ptr := Sloc (N);
Typ : constant Entity_Id := Etype (N);
Opnd : Node_Id;
Arr : Entity_Id;
A : Entity_Id;
B : Entity_Id;
J : Entity_Id;
A_J : Node_Id;
B_J : Node_Id;
Func_Name : Entity_Id;
Loop_Statement : Node_Id;
begin
Unary_Op_Validity_Checks (N);
-- For boolean operand, deal with non-standard booleans
if Is_Boolean_Type (Typ) then
Adjust_Condition (Right_Opnd (N));
Set_Etype (N, Standard_Boolean);
Adjust_Result_Type (N, Typ);
return;
end if;
-- Only array types need any other processing
if not Is_Array_Type (Typ) then
return;
end if;
-- Case of array operand. If bit packed with a component size of 1,
-- handle it in Exp_Pakd if the operand is known to be aligned.
if Is_Bit_Packed_Array (Typ)
and then Component_Size (Typ) = 1
and then not Is_Possibly_Unaligned_Object (Right_Opnd (N))
then
Expand_Packed_Not (N);
return;
end if;
-- Case of array operand which is not bit-packed. If the context is
-- a safe assignment, call in-place operation, If context is a larger
-- boolean expression in the context of a safe assignment, expansion is
-- done by enclosing operation.
Opnd := Relocate_Node (Right_Opnd (N));
Convert_To_Actual_Subtype (Opnd);
Arr := Etype (Opnd);
Ensure_Defined (Arr, N);
if Nkind (Parent (N)) = N_Assignment_Statement then
if Safe_In_Place_Array_Op (Name (Parent (N)), N, Empty) then
Build_Boolean_Array_Proc_Call (Parent (N), Opnd, Empty);
return;
-- Special case the negation of a binary operation
elsif (Nkind (Opnd) = N_Op_And
or else Nkind (Opnd) = N_Op_Or
or else Nkind (Opnd) = N_Op_Xor)
and then Safe_In_Place_Array_Op
(Name (Parent (N)), Left_Opnd (Opnd), Right_Opnd (Opnd))
then
Build_Boolean_Array_Proc_Call (Parent (N), Opnd, Empty);
return;
end if;
elsif Nkind (Parent (N)) in N_Binary_Op
and then Nkind (Parent (Parent (N))) = N_Assignment_Statement
then
declare
Op1 : constant Node_Id := Left_Opnd (Parent (N));
Op2 : constant Node_Id := Right_Opnd (Parent (N));
Lhs : constant Node_Id := Name (Parent (Parent (N)));
begin
if Safe_In_Place_Array_Op (Lhs, Op1, Op2) then
if N = Op1
and then Nkind (Op2) = N_Op_Not
then
-- (not A) op (not B) can be reduced to a single call
return;
elsif N = Op2
and then Nkind (Parent (N)) = N_Op_Xor
then
-- A xor (not B) can also be special-cased
return;
end if;
end if;
end;
end if;
A := Make_Defining_Identifier (Loc, Name_uA);
B := Make_Defining_Identifier (Loc, Name_uB);
J := Make_Defining_Identifier (Loc, Name_uJ);
A_J :=
Make_Indexed_Component (Loc,
Prefix => New_Reference_To (A, Loc),
Expressions => New_List (New_Reference_To (J, Loc)));
B_J :=
Make_Indexed_Component (Loc,
Prefix => New_Reference_To (B, Loc),
Expressions => New_List (New_Reference_To (J, Loc)));
Loop_Statement :=
Make_Implicit_Loop_Statement (N,
Identifier => Empty,
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 => Make_Identifier (Loc, Chars (A)),
Attribute_Name => Name_Range))),
Statements => New_List (
Make_Assignment_Statement (Loc,
Name => B_J,
Expression => Make_Op_Not (Loc, A_J))));
Func_Name := Make_Defining_Identifier (Loc, New_Internal_Name ('N'));
Set_Is_Inlined (Func_Name);
Insert_Action (N,
Make_Subprogram_Body (Loc,
Specification =>
Make_Function_Specification (Loc,
Defining_Unit_Name => Func_Name,
Parameter_Specifications => New_List (
Make_Parameter_Specification (Loc,
Defining_Identifier => A,
Parameter_Type => New_Reference_To (Typ, Loc))),
Result_Definition => New_Reference_To (Typ, Loc)),
Declarations => New_List (
Make_Object_Declaration (Loc,
Defining_Identifier => B,
Object_Definition => New_Reference_To (Arr, Loc))),
Handled_Statement_Sequence =>
Make_Handled_Sequence_Of_Statements (Loc,
Statements => New_List (
Loop_Statement,
Make_Return_Statement (Loc,
Expression =>
Make_Identifier (Loc, Chars (B)))))));
Rewrite (N,
Make_Function_Call (Loc,
Name => New_Reference_To (Func_Name, Loc),
Parameter_Associations => New_List (Opnd)));
Analyze_And_Resolve (N, Typ);
end Expand_N_Op_Not;
--------------------
-- Expand_N_Op_Or --
--------------------
procedure Expand_N_Op_Or (N : Node_Id) is
Typ : constant Entity_Id := Etype (N);
begin
Binary_Op_Validity_Checks (N);
if Is_Array_Type (Etype (N)) then
Expand_Boolean_Operator (N);
elsif Is_Boolean_Type (Etype (N)) then
Adjust_Condition (Left_Opnd (N));
Adjust_Condition (Right_Opnd (N));
Set_Etype (N, Standard_Boolean);
Adjust_Result_Type (N, Typ);
end if;
end Expand_N_Op_Or;
----------------------
-- Expand_N_Op_Plus --
----------------------
procedure Expand_N_Op_Plus (N : Node_Id) is
begin
Unary_Op_Validity_Checks (N);
end Expand_N_Op_Plus;
---------------------
-- Expand_N_Op_Rem --
---------------------
procedure Expand_N_Op_Rem (N : Node_Id) is
Loc : constant Source_Ptr := Sloc (N);
Typ : constant Entity_Id := Etype (N);
Left : constant Node_Id := Left_Opnd (N);
Right : constant Node_Id := Right_Opnd (N);
LLB : Uint;
Llo : Uint;
Lhi : Uint;
LOK : Boolean;
Rlo : Uint;
Rhi : Uint;
ROK : Boolean;
begin
Binary_Op_Validity_Checks (N);
if Is_Integer_Type (Etype (N)) then
Apply_Divide_Check (N);
end if;
-- Apply optimization x rem 1 = 0. We don't really need that with
-- gcc, but it is useful with other back ends (e.g. AAMP), and is
-- certainly harmless.
if Is_Integer_Type (Etype (N))
and then Compile_Time_Known_Value (Right)
and then Expr_Value (Right) = Uint_1
then
Rewrite (N, Make_Integer_Literal (Loc, 0));
Analyze_And_Resolve (N, Typ);
return;
end if;
-- Deal with annoying case of largest negative number remainder
-- minus one. Gigi does not handle this case correctly, because
-- it generates a divide instruction which may trap in this case.
-- In fact the check is quite easy, if the right operand is -1,
-- then the remainder is always 0, and we can just ignore the
-- left operand completely in this case.
Determine_Range (Right, ROK, Rlo, Rhi);
Determine_Range (Left, LOK, Llo, Lhi);
-- The operand type may be private (e.g. in the expansion of an
-- an intrinsic operation) so we must use the underlying type to
-- get the bounds, and convert the literals explicitly.
LLB :=
Expr_Value
(Type_Low_Bound (Base_Type (Underlying_Type (Etype (Left)))));
-- Now perform the test, generating code only if needed
if ((not ROK) or else (Rlo <= (-1) and then (-1) <= Rhi))
and then
((not LOK) or else (Llo = LLB))
then
Rewrite (N,
Make_Conditional_Expression (Loc,
Expressions => New_List (
Make_Op_Eq (Loc,
Left_Opnd => Duplicate_Subexpr (Right),
Right_Opnd =>
Unchecked_Convert_To (Typ,
Make_Integer_Literal (Loc, -1))),
Unchecked_Convert_To (Typ,
Make_Integer_Literal (Loc, Uint_0)),
Relocate_Node (N))));
Set_Analyzed (Next (Next (First (Expressions (N)))));
Analyze_And_Resolve (N, Typ);
end if;
end Expand_N_Op_Rem;
-----------------------------
-- Expand_N_Op_Rotate_Left --
-----------------------------
procedure Expand_N_Op_Rotate_Left (N : Node_Id) is
begin
Binary_Op_Validity_Checks (N);
end Expand_N_Op_Rotate_Left;
------------------------------
-- Expand_N_Op_Rotate_Right --
------------------------------
procedure Expand_N_Op_Rotate_Right (N : Node_Id) is
begin
Binary_Op_Validity_Checks (N);
end Expand_N_Op_Rotate_Right;
----------------------------
-- Expand_N_Op_Shift_Left --
----------------------------
procedure Expand_N_Op_Shift_Left (N : Node_Id) is
begin
Binary_Op_Validity_Checks (N);
end Expand_N_Op_Shift_Left;
-----------------------------
-- Expand_N_Op_Shift_Right --
-----------------------------
procedure Expand_N_Op_Shift_Right (N : Node_Id) is
begin
Binary_Op_Validity_Checks (N);
end Expand_N_Op_Shift_Right;
----------------------------------------
-- Expand_N_Op_Shift_Right_Arithmetic --
----------------------------------------
procedure Expand_N_Op_Shift_Right_Arithmetic (N : Node_Id) is
begin
Binary_Op_Validity_Checks (N);
end Expand_N_Op_Shift_Right_Arithmetic;
--------------------------
-- Expand_N_Op_Subtract --
--------------------------
procedure Expand_N_Op_Subtract (N : Node_Id) is
Typ : constant Entity_Id := Etype (N);
begin
Binary_Op_Validity_Checks (N);
-- N - 0 = N for integer types
if Is_Integer_Type (Typ)
and then Compile_Time_Known_Value (Right_Opnd (N))
and then Expr_Value (Right_Opnd (N)) = 0
then
Rewrite (N, Left_Opnd (N));
return;
end if;
-- Arithemtic overflow checks for signed integer/fixed point types
if Is_Signed_Integer_Type (Typ)
or else Is_Fixed_Point_Type (Typ)
then
Apply_Arithmetic_Overflow_Check (N);
-- Vax floating-point types case
elsif Vax_Float (Typ) then
Expand_Vax_Arith (N);
end if;
end Expand_N_Op_Subtract;
---------------------
-- Expand_N_Op_Xor --
---------------------
procedure Expand_N_Op_Xor (N : Node_Id) is
Typ : constant Entity_Id := Etype (N);
begin
Binary_Op_Validity_Checks (N);
if Is_Array_Type (Etype (N)) then
Expand_Boolean_Operator (N);
elsif Is_Boolean_Type (Etype (N)) then
Adjust_Condition (Left_Opnd (N));
Adjust_Condition (Right_Opnd (N));
Set_Etype (N, Standard_Boolean);
Adjust_Result_Type (N, Typ);
end if;
end Expand_N_Op_Xor;
----------------------
-- Expand_N_Or_Else --
----------------------
-- Expand into conditional expression if Actions present, and also
-- deal with optimizing case of arguments being True or False.
procedure Expand_N_Or_Else (N : Node_Id) is
Loc : constant Source_Ptr := Sloc (N);
Typ : constant Entity_Id := Etype (N);
Left : constant Node_Id := Left_Opnd (N);
Right : constant Node_Id := Right_Opnd (N);
Actlist : List_Id;
begin
-- Deal with non-standard booleans
if Is_Boolean_Type (Typ) then
Adjust_Condition (Left);
Adjust_Condition (Right);
Set_Etype (N, Standard_Boolean);
end if;
-- Check for cases of left argument is True or False
if Nkind (Left) = N_Identifier then
-- If left argument is False, change (False or else Right) to Right.
-- Any actions associated with Right will be executed unconditionally
-- and can thus be inserted into the tree unconditionally.
if Entity (Left) = Standard_False then
if Present (Actions (N)) then
Insert_Actions (N, Actions (N));
end if;
Rewrite (N, Right);
Adjust_Result_Type (N, Typ);
return;
-- If left argument is True, change (True and then Right) to
-- True. In this case we can forget the actions associated with
-- Right, since they will never be executed.
elsif Entity (Left) = Standard_True then
Kill_Dead_Code (Right);
Kill_Dead_Code (Actions (N));
Rewrite (N, New_Occurrence_Of (Standard_True, Loc));
Adjust_Result_Type (N, Typ);
return;
end if;
end if;
-- If Actions are present, we expand
-- left or else right
-- into
-- if left then True else right end
-- with the actions becoming the Else_Actions of the conditional
-- expression. This conditional expression is then further expanded
-- (and will eventually disappear)
if Present (Actions (N)) then
Actlist := Actions (N);
Rewrite (N,
Make_Conditional_Expression (Loc,
Expressions => New_List (
Left,
New_Occurrence_Of (Standard_True, Loc),
Right)));
Set_Else_Actions (N, Actlist);
Analyze_And_Resolve (N, Standard_Boolean);
Adjust_Result_Type (N, Typ);
return;
end if;
-- No actions present, check for cases of right argument True/False
if Nkind (Right) = N_Identifier then
-- Change (Left or else False) to Left. Note that we know there
-- are no actions associated with the True operand, since we
-- just checked for this case above.
if Entity (Right) = Standard_False then
Rewrite (N, Left);
-- Change (Left or else True) to True, making sure to preserve
-- any side effects associated with the Left operand.
elsif Entity (Right) = Standard_True then
Remove_Side_Effects (Left);
Rewrite
(N, New_Occurrence_Of (Standard_True, Loc));
end if;
end if;
Adjust_Result_Type (N, Typ);
end Expand_N_Or_Else;
-----------------------------------
-- Expand_N_Qualified_Expression --
-----------------------------------
procedure Expand_N_Qualified_Expression (N : Node_Id) is
Operand : constant Node_Id := Expression (N);
Target_Type : constant Entity_Id := Entity (Subtype_Mark (N));
begin
-- Do validity check if validity checking operands
if Validity_Checks_On
and then Validity_Check_Operands
then
Ensure_Valid (Operand);
end if;
-- Apply possible constraint check
Apply_Constraint_Check (Operand, Target_Type, No_Sliding => True);
end Expand_N_Qualified_Expression;
---------------------------------
-- Expand_N_Selected_Component --
---------------------------------
-- If the selector is a discriminant of a concurrent object, rewrite the
-- prefix to denote the corresponding record type.
procedure Expand_N_Selected_Component (N : Node_Id) is
Loc : constant Source_Ptr := Sloc (N);
Par : constant Node_Id := Parent (N);
P : constant Node_Id := Prefix (N);
Ptyp : Entity_Id := Underlying_Type (Etype (P));
Disc : Entity_Id;
New_N : Node_Id;
Dcon : Elmt_Id;
function In_Left_Hand_Side (Comp : Node_Id) return Boolean;
-- Gigi needs a temporary for prefixes that depend on a discriminant,
-- unless the context of an assignment can provide size information.
-- Don't we have a general routine that does this???
-----------------------
-- In_Left_Hand_Side --
-----------------------
function In_Left_Hand_Side (Comp : Node_Id) return Boolean is
begin
return (Nkind (Parent (Comp)) = N_Assignment_Statement
and then Comp = Name (Parent (Comp)))
or else (Present (Parent (Comp))
and then Nkind (Parent (Comp)) in N_Subexpr
and then In_Left_Hand_Side (Parent (Comp)));
end In_Left_Hand_Side;
-- Start of processing for Expand_N_Selected_Component
begin
-- Insert explicit dereference if required
if Is_Access_Type (Ptyp) then
Insert_Explicit_Dereference (P);
Analyze_And_Resolve (P, Designated_Type (Ptyp));
if Ekind (Etype (P)) = E_Private_Subtype
and then Is_For_Access_Subtype (Etype (P))
then
Set_Etype (P, Base_Type (Etype (P)));
end if;
Ptyp := Etype (P);
end if;
-- Deal with discriminant check required
if Do_Discriminant_Check (N) then
-- Present the discrminant checking function to the backend,
-- so that it can inline the call to the function.
Add_Inlined_Body
(Discriminant_Checking_Func
(Original_Record_Component (Entity (Selector_Name (N)))));
-- Now reset the flag and generate the call
Set_Do_Discriminant_Check (N, False);
Generate_Discriminant_Check (N);
end if;
-- Gigi cannot handle unchecked conversions that are the prefix of a
-- selected component with discriminants. This must be checked during
-- expansion, because during analysis the type of the selector is not
-- known at the point the prefix is analyzed. If the conversion is the
-- target of an assignment, then we cannot force the evaluation.
if Nkind (Prefix (N)) = N_Unchecked_Type_Conversion
and then Has_Discriminants (Etype (N))
and then not In_Left_Hand_Side (N)
then
Force_Evaluation (Prefix (N));
end if;
-- Remaining processing applies only if selector is a discriminant
if Ekind (Entity (Selector_Name (N))) = E_Discriminant then
-- If the selector is a discriminant of a constrained record type,
-- we may be able to rewrite the expression with the actual value
-- of the discriminant, a useful optimization in some cases.
if Is_Record_Type (Ptyp)
and then Has_Discriminants (Ptyp)
and then Is_Constrained (Ptyp)
then
-- Do this optimization for discrete types only, and not for
-- access types (access discriminants get us into trouble!)
if not Is_Discrete_Type (Etype (N)) then
null;
-- Don't do this on the left hand of an assignment statement.
-- Normally one would think that references like this would
-- not occur, but they do in generated code, and mean that
-- we really do want to assign the discriminant!
elsif Nkind (Par) = N_Assignment_Statement
and then Name (Par) = N
then
null;
-- Don't do this optimization for the prefix of an attribute
-- or the operand of an object renaming declaration since these
-- are contexts where we do not want the value anyway.
elsif (Nkind (Par) = N_Attribute_Reference
and then Prefix (Par) = N)
or else Is_Renamed_Object (N)
then
null;
-- Don't do this optimization if we are within the code for a
-- discriminant check, since the whole point of such a check may
-- be to verify the condition on which the code below depends!
elsif Is_In_Discriminant_Check (N) then
null;
-- Green light to see if we can do the optimization. There is
-- still one condition that inhibits the optimization below
-- but now is the time to check the particular discriminant.
else
-- Loop through discriminants to find the matching
-- discriminant constraint to see if we can copy it.
Disc := First_Discriminant (Ptyp);
Dcon := First_Elmt (Discriminant_Constraint (Ptyp));
Discr_Loop : while Present (Dcon) loop
-- Check if this is the matching discriminant
if Disc = Entity (Selector_Name (N)) then
-- Here we have the matching discriminant. Check for
-- the case of a discriminant of a component that is
-- constrained by an outer discriminant, which cannot
-- be optimized away.
if
Denotes_Discriminant
(Node (Dcon), Check_Protected => True)
then
exit Discr_Loop;
-- In the context of a case statement, the expression
-- may have the base type of the discriminant, and we
-- need to preserve the constraint to avoid spurious
-- errors on missing cases.
elsif Nkind (Parent (N)) = N_Case_Statement
and then Etype (Node (Dcon)) /= Etype (Disc)
then
Rewrite (N,
Make_Qualified_Expression (Loc,
Subtype_Mark =>
New_Occurrence_Of (Etype (Disc), Loc),
Expression =>
New_Copy_Tree (Node (Dcon))));
Analyze_And_Resolve (N, Etype (Disc));
-- In case that comes out as a static expression,
-- reset it (a selected component is never static).
Set_Is_Static_Expression (N, False);
return;
-- Otherwise we can just copy the constraint, but the
-- result is certainly not static! In some cases the
-- discriminant constraint has been analyzed in the
-- context of the original subtype indication, but for
-- itypes the constraint might not have been analyzed
-- yet, and this must be done now.
else
Rewrite (N, New_Copy_Tree (Node (Dcon)));
Analyze_And_Resolve (N);
Set_Is_Static_Expression (N, False);
return;
end if;
end if;
Next_Elmt (Dcon);
Next_Discriminant (Disc);
end loop Discr_Loop;
-- Note: the above loop should always find a matching
-- discriminant, but if it does not, we just missed an
-- optimization due to some glitch (perhaps a previous
-- error), so ignore.
end if;
end if;
-- The only remaining processing is in the case of a discriminant of
-- a concurrent object, where we rewrite the prefix to denote the
-- corresponding record type. If the type is derived and has renamed
-- discriminants, use corresponding discriminant, which is the one
-- that appears in the corresponding record.
if not Is_Concurrent_Type (Ptyp) then
return;
end if;
Disc := Entity (Selector_Name (N));
if Is_Derived_Type (Ptyp)
and then Present (Corresponding_Discriminant (Disc))
then
Disc := Corresponding_Discriminant (Disc);
end if;
New_N :=
Make_Selected_Component (Loc,
Prefix =>
Unchecked_Convert_To (Corresponding_Record_Type (Ptyp),
New_Copy_Tree (P)),
Selector_Name => Make_Identifier (Loc, Chars (Disc)));
Rewrite (N, New_N);
Analyze (N);
end if;
end Expand_N_Selected_Component;
--------------------
-- Expand_N_Slice --
--------------------
procedure Expand_N_Slice (N : Node_Id) is
Loc : constant Source_Ptr := Sloc (N);
Typ : constant Entity_Id := Etype (N);
Pfx : constant Node_Id := Prefix (N);
Ptp : Entity_Id := Etype (Pfx);
function Is_Procedure_Actual (N : Node_Id) return Boolean;
-- Check whether the argument is an actual for a procedure call,
-- in which case the expansion of a bit-packed slice is deferred
-- until the call itself is expanded. The reason this is required
-- is that we might have an IN OUT or OUT parameter, and the copy out
-- is essential, and that copy out would be missed if we created a
-- temporary here in Expand_N_Slice. Note that we don't bother
-- to test specifically for an IN OUT or OUT mode parameter, since it
-- is a bit tricky to do, and it is harmless to defer expansion
-- in the IN case, since the call processing will still generate the
-- appropriate copy in operation, which will take care of the slice.
procedure Make_Temporary;
-- Create a named variable for the value of the slice, in
-- cases where the back-end cannot handle it properly, e.g.
-- when packed types or unaligned slices are involved.
-------------------------
-- Is_Procedure_Actual --
-------------------------
function Is_Procedure_Actual (N : Node_Id) return Boolean is
Par : Node_Id := Parent (N);
begin
loop
-- If our parent is a procedure call we can return
if Nkind (Par) = N_Procedure_Call_Statement then
return True;
-- If our parent is a type conversion, keep climbing the
-- tree, since a type conversion can be a procedure actual.
-- Also keep climbing if parameter association or a qualified
-- expression, since these are additional cases that do can
-- appear on procedure actuals.
elsif Nkind (Par) = N_Type_Conversion
or else Nkind (Par) = N_Parameter_Association
or else Nkind (Par) = N_Qualified_Expression
then
Par := Parent (Par);
-- Any other case is not what we are looking for
else
return False;
end if;
end loop;
end Is_Procedure_Actual;
--------------------
-- Make_Temporary --
--------------------
procedure Make_Temporary is
Decl : Node_Id;
Ent : constant Entity_Id :=
Make_Defining_Identifier (Loc, New_Internal_Name ('T'));
begin
Decl :=
Make_Object_Declaration (Loc,
Defining_Identifier => Ent,
Object_Definition => New_Occurrence_Of (Typ, Loc));
Set_No_Initialization (Decl);
Insert_Actions (N, New_List (
Decl,
Make_Assignment_Statement (Loc,
Name => New_Occurrence_Of (Ent, Loc),
Expression => Relocate_Node (N))));
Rewrite (N, New_Occurrence_Of (Ent, Loc));
Analyze_And_Resolve (N, Typ);
end Make_Temporary;
-- Start of processing for Expand_N_Slice
begin
-- Special handling for access types
if Is_Access_Type (Ptp) then
Ptp := Designated_Type (Ptp);
Rewrite (Pfx,
Make_Explicit_Dereference (Sloc (N),
Prefix => Relocate_Node (Pfx)));
Analyze_And_Resolve (Pfx, Ptp);
end if;
-- Range checks are potentially also needed for cases involving
-- a slice indexed by a subtype indication, but Do_Range_Check
-- can currently only be set for expressions ???
if not Index_Checks_Suppressed (Ptp)
and then (not Is_Entity_Name (Pfx)
or else not Index_Checks_Suppressed (Entity (Pfx)))
and then Nkind (Discrete_Range (N)) /= N_Subtype_Indication
then
Enable_Range_Check (Discrete_Range (N));
end if;
-- The remaining case to be handled is packed slices. We can leave
-- packed slices as they are in the following situations:
-- 1. Right or left side of an assignment (we can handle this
-- situation correctly in the assignment statement expansion).
-- 2. Prefix of indexed component (the slide is optimized away
-- in this case, see the start of Expand_N_Slice.
-- 3. Object renaming declaration, since we want the name of
-- the slice, not the value.
-- 4. Argument to procedure call, since copy-in/copy-out handling
-- may be required, and this is handled in the expansion of
-- call itself.
-- 5. Prefix of an address attribute (this is an error which
-- is caught elsewhere, and the expansion would intefere
-- with generating the error message).
if not Is_Packed (Typ) then
-- Apply transformation for actuals of a function call,
-- where Expand_Actuals is not used.
if Nkind (Parent (N)) = N_Function_Call
and then Is_Possibly_Unaligned_Slice (N)
then
Make_Temporary;
end if;
elsif Nkind (Parent (N)) = N_Assignment_Statement
or else (Nkind (Parent (Parent (N))) = N_Assignment_Statement
and then Parent (N) = Name (Parent (Parent (N))))
then
return;
elsif Nkind (Parent (N)) = N_Indexed_Component
or else Is_Renamed_Object (N)
or else Is_Procedure_Actual (N)
then
return;
elsif Nkind (Parent (N)) = N_Attribute_Reference
and then Attribute_Name (Parent (N)) = Name_Address
then
return;
else
Make_Temporary;
end if;
end Expand_N_Slice;
------------------------------
-- Expand_N_Type_Conversion --
------------------------------
procedure Expand_N_Type_Conversion (N : Node_Id) is
Loc : constant Source_Ptr := Sloc (N);
Operand : constant Node_Id := Expression (N);
Target_Type : constant Entity_Id := Etype (N);
Operand_Type : Entity_Id := Etype (Operand);
procedure Handle_Changed_Representation;
-- This is called in the case of record and array type conversions
-- to see if there is a change of representation to be handled.
-- Change of representation is actually handled at the assignment
-- statement level, and what this procedure does is rewrite node N
-- conversion as an assignment to temporary. If there is no change
-- of representation, then the conversion node is unchanged.
procedure Real_Range_Check;
-- Handles generation of range check for real target value
-----------------------------------
-- Handle_Changed_Representation --
-----------------------------------
procedure Handle_Changed_Representation is
Temp : Entity_Id;
Decl : Node_Id;
Odef : Node_Id;
Disc : Node_Id;
N_Ix : Node_Id;
Cons : List_Id;
begin
-- Nothing else to do if no change of representation
if Same_Representation (Operand_Type, Target_Type) then
return;
-- The real change of representation work is done by the assignment
-- statement processing. So if this type conversion is appearing as
-- the expression of an assignment statement, nothing needs to be
-- done to the conversion.
elsif Nkind (Parent (N)) = N_Assignment_Statement then
return;
-- Otherwise we need to generate a temporary variable, and do the
-- change of representation assignment into that temporary variable.
-- The conversion is then replaced by a reference to this variable.
else
Cons := No_List;
-- If type is unconstrained we have to add a constraint,
-- copied from the actual value of the left hand side.
if not Is_Constrained (Target_Type) then
if Has_Discriminants (Operand_Type) then
Disc := First_Discriminant (Operand_Type);
if Disc /= First_Stored_Discriminant (Operand_Type) then
Disc := First_Stored_Discriminant (Operand_Type);
end if;
Cons := New_List;
while Present (Disc) loop
Append_To (Cons,
Make_Selected_Component (Loc,
Prefix => Duplicate_Subexpr_Move_Checks (Operand),
Selector_Name =>
Make_Identifier (Loc, Chars (Disc))));
Next_Discriminant (Disc);
end loop;
elsif Is_Array_Type (Operand_Type) then
N_Ix := First_Index (Target_Type);
Cons := New_List;
for J in 1 .. Number_Dimensions (Operand_Type) loop
-- We convert the bounds explicitly. We use an unchecked
-- conversion because bounds checks are done elsewhere.
Append_To (Cons,
Make_Range (Loc,
Low_Bound =>
Unchecked_Convert_To (Etype (N_Ix),
Make_Attribute_Reference (Loc,
Prefix =>
Duplicate_Subexpr_No_Checks
(Operand, Name_Req => True),
Attribute_Name => Name_First,
Expressions => New_List (
Make_Integer_Literal (Loc, J)))),
High_Bound =>
Unchecked_Convert_To (Etype (N_Ix),
Make_Attribute_Reference (Loc,
Prefix =>
Duplicate_Subexpr_No_Checks
(Operand, Name_Req => True),
Attribute_Name => Name_Last,
Expressions => New_List (
Make_Integer_Literal (Loc, J))))));
Next_Index (N_Ix);
end loop;
end if;
end if;
Odef := New_Occurrence_Of (Target_Type, Loc);
if Present (Cons) then
Odef :=
Make_Subtype_Indication (Loc,
Subtype_Mark => Odef,
Constraint =>
Make_Index_Or_Discriminant_Constraint (Loc,
Constraints => Cons));
end if;
Temp := Make_Defining_Identifier (Loc, New_Internal_Name ('C'));
Decl :=
Make_Object_Declaration (Loc,
Defining_Identifier => Temp,
Object_Definition => Odef);
Set_No_Initialization (Decl, True);
-- Insert required actions. It is essential to suppress checks
-- since we have suppressed default initialization, which means
-- that the variable we create may have no discriminants.
Insert_Actions (N,
New_List (
Decl,
Make_Assignment_Statement (Loc,
Name => New_Occurrence_Of (Temp, Loc),
Expression => Relocate_Node (N))),
Suppress => All_Checks);
Rewrite (N, New_Occurrence_Of (Temp, Loc));
return;
end if;
end Handle_Changed_Representation;
----------------------
-- Real_Range_Check --
----------------------
-- Case of conversions to floating-point or fixed-point. If range
-- checks are enabled and the target type has a range constraint,
-- we convert:
-- typ (x)
-- to
-- Tnn : typ'Base := typ'Base (x);
-- [constraint_error when Tnn < typ'First or else Tnn > typ'Last]
-- Tnn
-- This is necessary when there is a conversion of integer to float
-- or to fixed-point to ensure that the correct checks are made. It
-- is not necessary for float to float where it is enough to simply
-- set the Do_Range_Check flag.
procedure Real_Range_Check is
Btyp : constant Entity_Id := Base_Type (Target_Type);
Lo : constant Node_Id := Type_Low_Bound (Target_Type);
Hi : constant Node_Id := Type_High_Bound (Target_Type);
Xtyp : constant Entity_Id := Etype (Operand);
Conv : Node_Id;
Tnn : Entity_Id;
begin
-- Nothing to do if conversion was rewritten
if Nkind (N) /= N_Type_Conversion then
return;
end if;
-- Nothing to do if range checks suppressed, or target has the
-- same range as the base type (or is the base type).
if Range_Checks_Suppressed (Target_Type)
or else (Lo = Type_Low_Bound (Btyp)
and then
Hi = Type_High_Bound (Btyp))
then
return;
end if;
-- Nothing to do if expression is an entity on which checks
-- have been suppressed.
if Is_Entity_Name (Operand)
and then Range_Checks_Suppressed (Entity (Operand))
then
return;
end if;
-- Nothing to do if bounds are all static and we can tell that
-- the expression is within the bounds of the target. Note that
-- if the operand is of an unconstrained floating-point type,
-- then we do not trust it to be in range (might be infinite)
declare
S_Lo : constant Node_Id := Type_Low_Bound (Xtyp);
S_Hi : constant Node_Id := Type_High_Bound (Xtyp);
begin
if (not Is_Floating_Point_Type (Xtyp)
or else Is_Constrained (Xtyp))
and then Compile_Time_Known_Value (S_Lo)
and then Compile_Time_Known_Value (S_Hi)
and then Compile_Time_Known_Value (Hi)
and then Compile_Time_Known_Value (Lo)
then
declare
D_Lov : constant Ureal := Expr_Value_R (Lo);
D_Hiv : constant Ureal := Expr_Value_R (Hi);
S_Lov : Ureal;
S_Hiv : Ureal;
begin
if Is_Real_Type (Xtyp) then
S_Lov := Expr_Value_R (S_Lo);
S_Hiv := Expr_Value_R (S_Hi);
else
S_Lov := UR_From_Uint (Expr_Value (S_Lo));
S_Hiv := UR_From_Uint (Expr_Value (S_Hi));
end if;
if D_Hiv > D_Lov
and then S_Lov >= D_Lov
and then S_Hiv <= D_Hiv
then
Set_Do_Range_Check (Operand, False);
return;
end if;
end;
end if;
end;
-- For float to float conversions, we are done
if Is_Floating_Point_Type (Xtyp)
and then
Is_Floating_Point_Type (Btyp)
then
return;
end if;
-- Otherwise rewrite the conversion as described above
Conv := Relocate_Node (N);
Rewrite
(Subtype_Mark (Conv), New_Occurrence_Of (Btyp, Loc));
Set_Etype (Conv, Btyp);
-- Enable overflow except for case of integer to float conversions,
-- where it is never required, since we can never have overflow in
-- this case.
if not Is_Integer_Type (Etype (Operand)) then
Enable_Overflow_Check (Conv);
end if;
Tnn :=
Make_Defining_Identifier (Loc,
Chars => New_Internal_Name ('T'));
Insert_Actions (N, New_List (
Make_Object_Declaration (Loc,
Defining_Identifier => Tnn,
Object_Definition => New_Occurrence_Of (Btyp, Loc),
Expression => Conv),
Make_Raise_Constraint_Error (Loc,
Condition =>
Make_Or_Else (Loc,
Left_Opnd =>
Make_Op_Lt (Loc,
Left_Opnd => New_Occurrence_Of (Tnn, Loc),
Right_Opnd =>
Make_Attribute_Reference (Loc,
Attribute_Name => Name_First,
Prefix =>
New_Occurrence_Of (Target_Type, Loc))),
Right_Opnd =>
Make_Op_Gt (Loc,
Left_Opnd => New_Occurrence_Of (Tnn, Loc),
Right_Opnd =>
Make_Attribute_Reference (Loc,
Attribute_Name => Name_Last,
Prefix =>
New_Occurrence_Of (Target_Type, Loc)))),
Reason => CE_Range_Check_Failed)));
Rewrite (N, New_Occurrence_Of (Tnn, Loc));
Analyze_And_Resolve (N, Btyp);
end Real_Range_Check;
-- Start of processing for Expand_N_Type_Conversion
begin
-- Nothing at all to do if conversion is to the identical type
-- so remove the conversion completely, it is useless.
if Operand_Type = Target_Type then
Rewrite (N, Relocate_Node (Operand));
return;
end if;
-- Nothing to do if this is the second argument of read. This
-- is a "backwards" conversion that will be handled by the
-- specialized code in attribute processing.
if Nkind (Parent (N)) = N_Attribute_Reference
and then Attribute_Name (Parent (N)) = Name_Read
and then Next (First (Expressions (Parent (N)))) = N
then
return;
end if;
-- Here if we may need to expand conversion
-- Do validity check if validity checking operands
if Validity_Checks_On
and then Validity_Check_Operands
then
Ensure_Valid (Operand);
end if;
-- Special case of converting from non-standard boolean type
if Is_Boolean_Type (Operand_Type)
and then (Nonzero_Is_True (Operand_Type))
then
Adjust_Condition (Operand);
Set_Etype (Operand, Standard_Boolean);
Operand_Type := Standard_Boolean;
end if;
-- Case of converting to an access type
if Is_Access_Type (Target_Type) then
-- Apply an accessibility check if the operand is an
-- access parameter. Note that other checks may still
-- need to be applied below (such as tagged type checks).
if Is_Entity_Name (Operand)
and then Ekind (Entity (Operand)) in Formal_Kind
and then Ekind (Etype (Operand)) = E_Anonymous_Access_Type
then
Apply_Accessibility_Check (Operand, Target_Type);
-- If the level of the operand type is statically deeper
-- then the level of the target type, then force Program_Error.
-- Note that this can only occur for cases where the attribute
-- is within the body of an instantiation (otherwise the
-- conversion will already have been rejected as illegal).
-- Note: warnings are issued by the analyzer for the instance
-- cases.
elsif In_Instance_Body
and then Type_Access_Level (Operand_Type) >
Type_Access_Level (Target_Type)
then
Rewrite (N,
Make_Raise_Program_Error (Sloc (N),
Reason => PE_Accessibility_Check_Failed));
Set_Etype (N, Target_Type);
-- When the operand is a selected access discriminant
-- the check needs to be made against the level of the
-- object denoted by the prefix of the selected name.
-- Force Program_Error for this case as well (this
-- accessibility violation can only happen if within
-- the body of an instantiation).
elsif In_Instance_Body
and then Ekind (Operand_Type) = E_Anonymous_Access_Type
and then Nkind (Operand) = N_Selected_Component
and then Object_Access_Level (Operand) >
Type_Access_Level (Target_Type)
then
Rewrite (N,
Make_Raise_Program_Error (Sloc (N),
Reason => PE_Accessibility_Check_Failed));
Set_Etype (N, Target_Type);
end if;
end if;
-- Case of conversions of tagged types and access to tagged types
-- When needed, that is to say when the expression is class-wide,
-- Add runtime a tag check for (strict) downward conversion by using
-- the membership test, generating:
-- [constraint_error when Operand not in Target_Type'Class]
-- or in the access type case
-- [constraint_error
-- when Operand /= null
-- and then Operand.all not in
-- Designated_Type (Target_Type)'Class]
if (Is_Access_Type (Target_Type)
and then Is_Tagged_Type (Designated_Type (Target_Type)))
or else Is_Tagged_Type (Target_Type)
then
-- Do not do any expansion in the access type case if the
-- parent is a renaming, since this is an error situation
-- which will be caught by Sem_Ch8, and the expansion can
-- intefere with this error check.
if Is_Access_Type (Target_Type)
and then Is_Renamed_Object (N)
then
return;
end if;
-- Oherwise, proceed with processing tagged conversion
declare
Actual_Operand_Type : Entity_Id;
Actual_Target_Type : Entity_Id;
Cond : Node_Id;
begin
if Is_Access_Type (Target_Type) then
Actual_Operand_Type := Designated_Type (Operand_Type);
Actual_Target_Type := Designated_Type (Target_Type);
else
Actual_Operand_Type := Operand_Type;
Actual_Target_Type := Target_Type;
end if;
if Is_Class_Wide_Type (Actual_Operand_Type)
and then Root_Type (Actual_Operand_Type) /= Actual_Target_Type
and then Is_Ancestor
(Root_Type (Actual_Operand_Type),
Actual_Target_Type)
and then not Tag_Checks_Suppressed (Actual_Target_Type)
then
-- The conversion is valid for any descendant of the
-- target type
Actual_Target_Type := Class_Wide_Type (Actual_Target_Type);
if Is_Access_Type (Target_Type) then
Cond :=
Make_And_Then (Loc,
Left_Opnd =>
Make_Op_Ne (Loc,
Left_Opnd => Duplicate_Subexpr_No_Checks (Operand),
Right_Opnd => Make_Null (Loc)),
Right_Opnd =>
Make_Not_In (Loc,
Left_Opnd =>
Make_Explicit_Dereference (Loc,
Prefix =>
Duplicate_Subexpr_No_Checks (Operand)),
Right_Opnd =>
New_Reference_To (Actual_Target_Type, Loc)));
else
Cond :=
Make_Not_In (Loc,
Left_Opnd => Duplicate_Subexpr_No_Checks (Operand),
Right_Opnd =>
New_Reference_To (Actual_Target_Type, Loc));
end if;
Insert_Action (N,
Make_Raise_Constraint_Error (Loc,
Condition => Cond,
Reason => CE_Tag_Check_Failed));
declare
Conv : Node_Id;
begin
Conv :=
Make_Unchecked_Type_Conversion (Loc,
Subtype_Mark => New_Occurrence_Of (Target_Type, Loc),
Expression => Relocate_Node (Expression (N)));
Rewrite (N, Conv);
Analyze_And_Resolve (N, Target_Type);
end;
end if;
end;
-- Case of other access type conversions
elsif Is_Access_Type (Target_Type) then
Apply_Constraint_Check (Operand, Target_Type);
-- Case of conversions from a fixed-point type
-- These conversions require special expansion and processing, found
-- in the Exp_Fixd package. We ignore cases where Conversion_OK is
-- set, since from a semantic point of view, these are simple integer
-- conversions, which do not need further processing.
elsif Is_Fixed_Point_Type (Operand_Type)
and then not Conversion_OK (N)
then
-- We should never see universal fixed at this case, since the
-- expansion of the constituent divide or multiply should have
-- eliminated the explicit mention of universal fixed.
pragma Assert (Operand_Type /= Universal_Fixed);
-- Check for special case of the conversion to universal real
-- that occurs as a result of the use of a round attribute.
-- In this case, the real type for the conversion is taken
-- from the target type of the Round attribute and the
-- result must be marked as rounded.
if Target_Type = Universal_Real
and then Nkind (Parent (N)) = N_Attribute_Reference
and then Attribute_Name (Parent (N)) = Name_Round
then
Set_Rounded_Result (N);
Set_Etype (N, Etype (Parent (N)));
end if;
-- Otherwise do correct fixed-conversion, but skip these if the
-- Conversion_OK flag is set, because from a semantic point of
-- view these are simple integer conversions needing no further
-- processing (the backend will simply treat them as integers)
if not Conversion_OK (N) then
if Is_Fixed_Point_Type (Etype (N)) then
Expand_Convert_Fixed_To_Fixed (N);
Real_Range_Check;
elsif Is_Integer_Type (Etype (N)) then
Expand_Convert_Fixed_To_Integer (N);
else
pragma Assert (Is_Floating_Point_Type (Etype (N)));
Expand_Convert_Fixed_To_Float (N);
Real_Range_Check;
end if;
end if;
-- Case of conversions to a fixed-point type
-- These conversions require special expansion and processing, found
-- in the Exp_Fixd package. Again, ignore cases where Conversion_OK
-- is set, since from a semantic point of view, these are simple
-- integer conversions, which do not need further processing.
elsif Is_Fixed_Point_Type (Target_Type)
and then not Conversion_OK (N)
then
if Is_Integer_Type (Operand_Type) then
Expand_Convert_Integer_To_Fixed (N);
Real_Range_Check;
else
pragma Assert (Is_Floating_Point_Type (Operand_Type));
Expand_Convert_Float_To_Fixed (N);
Real_Range_Check;
end if;
-- Case of float-to-integer conversions
-- We also handle float-to-fixed conversions with Conversion_OK set
-- since semantically the fixed-point target is treated as though it
-- were an integer in such cases.
elsif Is_Floating_Point_Type (Operand_Type)
and then
(Is_Integer_Type (Target_Type)
or else
(Is_Fixed_Point_Type (Target_Type) and then Conversion_OK (N)))
then
-- Special processing required if the conversion is the expression
-- of a Truncation attribute reference. In this case we replace:
-- ityp (ftyp'Truncation (x))
-- by
-- ityp (x)
-- with the Float_Truncate flag set. This is clearly more efficient
if Nkind (Operand) = N_Attribute_Reference
and then Attribute_Name (Operand) = Name_Truncation
then
Rewrite (Operand,
Relocate_Node (First (Expressions (Operand))));
Set_Float_Truncate (N, True);
end if;
-- One more check here, gcc is still not able to do conversions of
-- this type with proper overflow checking, and so gigi is doing an
-- approximation of what is required by doing floating-point compares
-- with the end-point. But that can lose precision in some cases, and
-- give a wrong result. Converting the operand to Universal_Real is
-- helpful, but still does not catch all cases with 64-bit integers
-- on targets with only 64-bit floats ???
if Do_Range_Check (Operand) then
Rewrite (Operand,
Make_Type_Conversion (Loc,
Subtype_Mark =>
New_Occurrence_Of (Universal_Real, Loc),
Expression =>
Relocate_Node (Operand)));
Set_Etype (Operand, Universal_Real);
Enable_Range_Check (Operand);
Set_Do_Range_Check (Expression (Operand), False);
end if;
-- Case of array conversions
-- Expansion of array conversions, add required length/range checks
-- but only do this if there is no change of representation. For
-- handling of this case, see Handle_Changed_Representation.
elsif Is_Array_Type (Target_Type) then
if Is_Constrained (Target_Type) then
Apply_Length_Check (Operand, Target_Type);
else
Apply_Range_Check (Operand, Target_Type);
end if;
Handle_Changed_Representation;
-- Case of conversions of discriminated types
-- Add required discriminant checks if target is constrained. Again
-- this change is skipped if we have a change of representation.
elsif Has_Discriminants (Target_Type)
and then Is_Constrained (Target_Type)
then
Apply_Discriminant_Check (Operand, Target_Type);
Handle_Changed_Representation;
-- Case of all other record conversions. The only processing required
-- is to check for a change of representation requiring the special
-- assignment processing.
elsif Is_Record_Type (Target_Type) then
-- Ada 2005 (AI-216): Program_Error is raised when converting from
-- a derived Unchecked_Union type to an unconstrained non-Unchecked_
-- Union type if the operand lacks inferable discriminants.
if Is_Derived_Type (Operand_Type)
and then Is_Unchecked_Union (Base_Type (Operand_Type))
and then not Is_Constrained (Target_Type)
and then not Is_Unchecked_Union (Base_Type (Target_Type))
and then not Has_Inferable_Discriminants (Operand)
then
-- To prevent Gigi from generating illegal code, we make a
-- Program_Error node, but we give it the target type of the
-- conversion.
declare
PE : constant Node_Id := Make_Raise_Program_Error (Loc,
Reason => PE_Unchecked_Union_Restriction);
begin
Set_Etype (PE, Target_Type);
Rewrite (N, PE);
end;
else
Handle_Changed_Representation;
end if;
-- Case of conversions of enumeration types
elsif Is_Enumeration_Type (Target_Type) then
-- Special processing is required if there is a change of
-- representation (from enumeration representation clauses)
if not Same_Representation (Target_Type, Operand_Type) then
-- Convert: x(y) to x'val (ytyp'val (y))
Rewrite (N,
Make_Attribute_Reference (Loc,
Prefix => New_Occurrence_Of (Target_Type, Loc),
Attribute_Name => Name_Val,
Expressions => New_List (
Make_Attribute_Reference (Loc,
Prefix => New_Occurrence_Of (Operand_Type, Loc),
Attribute_Name => Name_Pos,
Expressions => New_List (Operand)))));
Analyze_And_Resolve (N, Target_Type);
end if;
-- Case of conversions to floating-point
elsif Is_Floating_Point_Type (Target_Type) then
Real_Range_Check;
end if;
-- At this stage, either the conversion node has been transformed
-- into some other equivalent expression, or left as a conversion
-- that can be handled by Gigi. The conversions that Gigi can handle
-- are the following:
-- Conversions with no change of representation or type
-- Numeric conversions involving integer values, floating-point
-- values, and fixed-point values. Fixed-point values are allowed
-- only if Conversion_OK is set, i.e. if the fixed-point values
-- are to be treated as integers.
-- No other conversions should be passed to Gigi
-- Check: are these rules stated in sinfo??? if so, why restate here???
-- The only remaining step is to generate a range check if we still
-- have a type conversion at this stage and Do_Range_Check is set.
-- For now we do this only for conversions of discrete types.
if Nkind (N) = N_Type_Conversion
and then Is_Discrete_Type (Etype (N))
then
declare
Expr : constant Node_Id := Expression (N);
Ftyp : Entity_Id;
Ityp : Entity_Id;
begin
if Do_Range_Check (Expr)
and then Is_Discrete_Type (Etype (Expr))
then
Set_Do_Range_Check (Expr, False);
-- Before we do a range check, we have to deal with treating
-- a fixed-point operand as an integer. The way we do this
-- is simply to do an unchecked conversion to an appropriate
-- integer type large enough to hold the result.
-- This code is not active yet, because we are only dealing
-- with discrete types so far ???
if Nkind (Expr) in N_Has_Treat_Fixed_As_Integer
and then Treat_Fixed_As_Integer (Expr)
then
Ftyp := Base_Type (Etype (Expr));
if Esize (Ftyp) >= Esize (Standard_Integer) then
Ityp := Standard_Long_Long_Integer;
else
Ityp := Standard_Integer;
end if;
Rewrite (Expr, Unchecked_Convert_To (Ityp, Expr));
end if;
-- Reset overflow flag, since the range check will include
-- dealing with possible overflow, and generate the check
-- If Address is either source or target type, suppress
-- range check to avoid typing anomalies when it is a visible
-- integer type.
Set_Do_Overflow_Check (N, False);
if not Is_Descendent_Of_Address (Etype (Expr))
and then not Is_Descendent_Of_Address (Target_Type)
then
Generate_Range_Check
(Expr, Target_Type, CE_Range_Check_Failed);
end if;
end if;
end;
end if;
-- Final step, if the result is a type conversion involving Vax_Float
-- types, then it is subject for further special processing.
if Nkind (N) = N_Type_Conversion
and then (Vax_Float (Operand_Type) or else Vax_Float (Target_Type))
then
Expand_Vax_Conversion (N);
return;
end if;
end Expand_N_Type_Conversion;
-----------------------------------
-- Expand_N_Unchecked_Expression --
-----------------------------------
-- Remove the unchecked expression node from the tree. It's job was simply
-- to make sure that its constituent expression was handled with checks
-- off, and now that that is done, we can remove it from the tree, and
-- indeed must, since gigi does not expect to see these nodes.
procedure Expand_N_Unchecked_Expression (N : Node_Id) is
Exp : constant Node_Id := Expression (N);
begin
Set_Assignment_OK (Exp, Assignment_OK (N) or Assignment_OK (Exp));
Rewrite (N, Exp);
end Expand_N_Unchecked_Expression;
----------------------------------------
-- Expand_N_Unchecked_Type_Conversion --
----------------------------------------
-- If this cannot be handled by Gigi and we haven't already made
-- a temporary for it, do it now.
procedure Expand_N_Unchecked_Type_Conversion (N : Node_Id) is
Target_Type : constant Entity_Id := Etype (N);
Operand : constant Node_Id := Expression (N);
Operand_Type : constant Entity_Id := Etype (Operand);
begin
-- If we have a conversion of a compile time known value to a target
-- type and the value is in range of the target type, then we can simply
-- replace the construct by an integer literal of the correct type. We
-- only apply this to integer types being converted. Possibly it may
-- apply in other cases, but it is too much trouble to worry about.
-- Note that we do not do this transformation if the Kill_Range_Check
-- flag is set, since then the value may be outside the expected range.
-- This happens in the Normalize_Scalars case.
if Is_Integer_Type (Target_Type)
and then Is_Integer_Type (Operand_Type)
and then Compile_Time_Known_Value (Operand)
and then not Kill_Range_Check (N)
then
declare
Val : constant Uint := Expr_Value (Operand);
begin
if Compile_Time_Known_Value (Type_Low_Bound (Target_Type))
and then
Compile_Time_Known_Value (Type_High_Bound (Target_Type))
and then
Val >= Expr_Value (Type_Low_Bound (Target_Type))
and then
Val <= Expr_Value (Type_High_Bound (Target_Type))
then
Rewrite (N, Make_Integer_Literal (Sloc (N), Val));
-- If Address is the target type, just set the type
-- to avoid a spurious type error on the literal when
-- Address is a visible integer type.
if Is_Descendent_Of_Address (Target_Type) then
Set_Etype (N, Target_Type);
else
Analyze_And_Resolve (N, Target_Type);
end if;
return;
end if;
end;
end if;
-- Nothing to do if conversion is safe
if Safe_Unchecked_Type_Conversion (N) then
return;
end if;
-- Otherwise force evaluation unless Assignment_OK flag is set (this
-- flag indicates ??? -- more comments needed here)
if Assignment_OK (N) then
null;
else
Force_Evaluation (N);
end if;
end Expand_N_Unchecked_Type_Conversion;
----------------------------
-- Expand_Record_Equality --
----------------------------
-- For non-variant records, Equality is expanded when needed into:
-- and then Lhs.Discr1 = Rhs.Discr1
-- and then ...
-- and then Lhs.Discrn = Rhs.Discrn
-- and then Lhs.Cmp1 = Rhs.Cmp1
-- and then ...
-- and then Lhs.Cmpn = Rhs.Cmpn
-- The expression is folded by the back-end for adjacent fields. This
-- function is called for tagged record in only one occasion: for imple-
-- menting predefined primitive equality (see Predefined_Primitives_Bodies)
-- otherwise the primitive "=" is used directly.
function Expand_Record_Equality
(Nod : Node_Id;
Typ : Entity_Id;
Lhs : Node_Id;
Rhs : Node_Id;
Bodies : List_Id) return Node_Id
is
Loc : constant Source_Ptr := Sloc (Nod);
Result : Node_Id;
C : Entity_Id;
First_Time : Boolean := True;
function Suitable_Element (C : Entity_Id) return Entity_Id;
-- Return the first field to compare beginning with C, skipping the
-- inherited components.
----------------------
-- Suitable_Element --
----------------------
function Suitable_Element (C : Entity_Id) return Entity_Id is
begin
if No (C) then
return Empty;
elsif Ekind (C) /= E_Discriminant
and then Ekind (C) /= E_Component
then
return Suitable_Element (Next_Entity (C));
elsif Is_Tagged_Type (Typ)
and then C /= Original_Record_Component (C)
then
return Suitable_Element (Next_Entity (C));
elsif Chars (C) = Name_uController
or else Chars (C) = Name_uTag
then
return Suitable_Element (Next_Entity (C));
else
return C;
end if;
end Suitable_Element;
-- Start of processing for Expand_Record_Equality
begin
-- Generates the following code: (assuming that Typ has one Discr and
-- component C2 is also a record)
-- True
-- and then Lhs.Discr1 = Rhs.Discr1
-- and then Lhs.C1 = Rhs.C1
-- and then Lhs.C2.C1=Rhs.C2.C1 and then ... Lhs.C2.Cn=Rhs.C2.Cn
-- and then ...
-- and then Lhs.Cmpn = Rhs.Cmpn
Result := New_Reference_To (Standard_True, Loc);
C := Suitable_Element (First_Entity (Typ));
while Present (C) loop
declare
New_Lhs : Node_Id;
New_Rhs : Node_Id;
Check : Node_Id;
begin
if First_Time then
First_Time := False;
New_Lhs := Lhs;
New_Rhs := Rhs;
else
New_Lhs := New_Copy_Tree (Lhs);
New_Rhs := New_Copy_Tree (Rhs);
end if;
Check :=
Expand_Composite_Equality (Nod, Etype (C),
Lhs =>
Make_Selected_Component (Loc,
Prefix => New_Lhs,
Selector_Name => New_Reference_To (C, Loc)),
Rhs =>
Make_Selected_Component (Loc,
Prefix => New_Rhs,
Selector_Name => New_Reference_To (C, Loc)),
Bodies => Bodies);
-- If some (sub)component is an unchecked_union, the whole
-- operation will raise program error.
if Nkind (Check) = N_Raise_Program_Error then
Result := Check;
Set_Etype (Result, Standard_Boolean);
exit;
else
Result :=
Make_And_Then (Loc,
Left_Opnd => Result,
Right_Opnd => Check);
end if;
end;
C := Suitable_Element (Next_Entity (C));
end loop;
return Result;
end Expand_Record_Equality;
-------------------------------------
-- Fixup_Universal_Fixed_Operation --
-------------------------------------
procedure Fixup_Universal_Fixed_Operation (N : Node_Id) is
Conv : constant Node_Id := Parent (N);
begin
-- We must have a type conversion immediately above us
pragma Assert (Nkind (Conv) = N_Type_Conversion);
-- Normally the type conversion gives our target type. The exception
-- occurs in the case of the Round attribute, where the conversion
-- will be to universal real, and our real type comes from the Round
-- attribute (as well as an indication that we must round the result)
if Nkind (Parent (Conv)) = N_Attribute_Reference
and then Attribute_Name (Parent (Conv)) = Name_Round
then
Set_Etype (N, Etype (Parent (Conv)));
Set_Rounded_Result (N);
-- Normal case where type comes from conversion above us
else
Set_Etype (N, Etype (Conv));
end if;
end Fixup_Universal_Fixed_Operation;
------------------------------
-- Get_Allocator_Final_List --
------------------------------
function Get_Allocator_Final_List
(N : Node_Id;
T : Entity_Id;
PtrT : Entity_Id) return Entity_Id
is
Loc : constant Source_Ptr := Sloc (N);
Owner : Entity_Id := PtrT;
-- The entity whose finalisation list must be used to attach the
-- allocated object.
begin
if Ekind (PtrT) = E_Anonymous_Access_Type then
if Nkind (Associated_Node_For_Itype (PtrT))
in N_Subprogram_Specification
then
-- If the context is an access parameter, we need to create
-- a non-anonymous access type in order to have a usable
-- final list, because there is otherwise no pool to which
-- the allocated object can belong. We create both the type
-- and the finalization chain here, because freezing an
-- internal type does not create such a chain. The Final_Chain
-- that is thus created is shared by the access parameter.
Owner := Make_Defining_Identifier (Loc, New_Internal_Name ('J'));
Insert_Action (N,
Make_Full_Type_Declaration (Loc,
Defining_Identifier => Owner,
Type_Definition =>
Make_Access_To_Object_Definition (Loc,
Subtype_Indication =>
New_Occurrence_Of (T, Loc))));
Build_Final_List (N, Owner);
Set_Associated_Final_Chain (PtrT, Associated_Final_Chain (Owner));
else
-- Case of an access discriminant, or (Ada 2005) of
-- an anonymous access component: find the final list
-- associated with the scope of the type.
Owner := Scope (PtrT);
end if;
end if;
return Find_Final_List (Owner);
end Get_Allocator_Final_List;
---------------------------------
-- Has_Inferable_Discriminants --
---------------------------------
function Has_Inferable_Discriminants (N : Node_Id) return Boolean is
function Prefix_Is_Formal_Parameter (N : Node_Id) return Boolean;
-- Determines whether the left-most prefix of a selected component is a
-- formal parameter in a subprogram. Assumes N is a selected component.
--------------------------------
-- Prefix_Is_Formal_Parameter --
--------------------------------
function Prefix_Is_Formal_Parameter (N : Node_Id) return Boolean is
Sel_Comp : Node_Id := N;
begin
-- Move to the left-most prefix by climbing up the tree
while Present (Parent (Sel_Comp))
and then Nkind (Parent (Sel_Comp)) = N_Selected_Component
loop
Sel_Comp := Parent (Sel_Comp);
end loop;
return Ekind (Entity (Prefix (Sel_Comp))) in Formal_Kind;
end Prefix_Is_Formal_Parameter;
-- Start of processing for Has_Inferable_Discriminants
begin
-- For identifiers and indexed components, it is sufficent to have a
-- constrained Unchecked_Union nominal subtype.
if Nkind (N) = N_Identifier
or else
Nkind (N) = N_Indexed_Component
then
return Is_Unchecked_Union (Base_Type (Etype (N)))
and then
Is_Constrained (Etype (N));
-- For selected components, the subtype of the selector must be a
-- constrained Unchecked_Union. If the component is subject to a
-- per-object constraint, then the enclosing object must have inferable
-- discriminants.
elsif Nkind (N) = N_Selected_Component then
if Has_Per_Object_Constraint (Entity (Selector_Name (N))) then
-- A small hack. If we have a per-object constrained selected
-- component of a formal parameter, return True since we do not
-- know the actual parameter association yet.
if Prefix_Is_Formal_Parameter (N) then
return True;
end if;
-- Otherwise, check the enclosing object and the selector
return Has_Inferable_Discriminants (Prefix (N))
and then
Has_Inferable_Discriminants (Selector_Name (N));
end if;
-- The call to Has_Inferable_Discriminants will determine whether
-- the selector has a constrained Unchecked_Union nominal type.
return Has_Inferable_Discriminants (Selector_Name (N));
-- A qualified expression has inferable discriminants if its subtype
-- mark is a constrained Unchecked_Union subtype.
elsif Nkind (N) = N_Qualified_Expression then
return Is_Unchecked_Union (Subtype_Mark (N))
and then
Is_Constrained (Subtype_Mark (N));
end if;
return False;
end Has_Inferable_Discriminants;
-------------------------------
-- Insert_Dereference_Action --
-------------------------------
procedure Insert_Dereference_Action (N : Node_Id) is
Loc : constant Source_Ptr := Sloc (N);
Typ : constant Entity_Id := Etype (N);
Pool : constant Entity_Id := Associated_Storage_Pool (Typ);
Pnod : constant Node_Id := Parent (N);
function Is_Checked_Storage_Pool (P : Entity_Id) return Boolean;
-- Return true if type of P is derived from Checked_Pool;
-----------------------------
-- Is_Checked_Storage_Pool --
-----------------------------
function Is_Checked_Storage_Pool (P : Entity_Id) return Boolean is
T : Entity_Id;
begin
if No (P) then
return False;
end if;
T := Etype (P);
while T /= Etype (T) loop
if Is_RTE (T, RE_Checked_Pool) then
return True;
else
T := Etype (T);
end if;
end loop;
return False;
end Is_Checked_Storage_Pool;
-- Start of processing for Insert_Dereference_Action
begin
pragma Assert (Nkind (Pnod) = N_Explicit_Dereference);
if not (Is_Checked_Storage_Pool (Pool)
and then Comes_From_Source (Original_Node (Pnod)))
then
return;
end if;
Insert_Action (N,
Make_Procedure_Call_Statement (Loc,
Name => New_Reference_To (
Find_Prim_Op (Etype (Pool), Name_Dereference), Loc),
Parameter_Associations => New_List (
-- Pool
New_Reference_To (Pool, Loc),
-- Storage_Address. We use the attribute Pool_Address,
-- which uses the pointer itself to find the address of
-- the object, and which handles unconstrained arrays
-- properly by computing the address of the template.
-- i.e. the correct address of the corresponding allocation.
Make_Attribute_Reference (Loc,
Prefix => Duplicate_Subexpr_Move_Checks (N),
Attribute_Name => Name_Pool_Address),
-- Size_In_Storage_Elements
Make_Op_Divide (Loc,
Left_Opnd =>
Make_Attribute_Reference (Loc,
Prefix =>
Make_Explicit_Dereference (Loc,
Duplicate_Subexpr_Move_Checks (N)),
Attribute_Name => Name_Size),
Right_Opnd =>
Make_Integer_Literal (Loc, System_Storage_Unit)),
-- Alignment
Make_Attribute_Reference (Loc,
Prefix =>
Make_Explicit_Dereference (Loc,
Duplicate_Subexpr_Move_Checks (N)),
Attribute_Name => Name_Alignment))));
exception
when RE_Not_Available =>
return;
end Insert_Dereference_Action;
------------------------------
-- Make_Array_Comparison_Op --
------------------------------
-- This is a hand-coded expansion of the following generic function:
-- generic
-- type elem is (<>);
-- type index is (<>);
-- type a is array (index range <>) of elem;
--
-- function Gnnn (X : a; Y: a) return boolean is
-- J : index := Y'first;
--
-- begin
-- if X'length = 0 then
-- return false;
--
-- elsif Y'length = 0 then
-- return true;
--
-- else
-- for I in X'range loop
-- if X (I) = Y (J) then
-- if J = Y'last then
-- exit;
-- else
-- J := index'succ (J);
-- end if;
--
-- else
-- return X (I) > Y (J);
-- end if;
-- end loop;
--
-- return X'length > Y'length;
-- end if;
-- end Gnnn;
-- Note that since we are essentially doing this expansion by hand, we
-- do not need to generate an actual or formal generic part, just the
-- instantiated function itself.
function Make_Array_Comparison_Op
(Typ : Entity_Id;
Nod : Node_Id) return Node_Id
is
Loc : constant Source_Ptr := Sloc (Nod);
X : constant Entity_Id := Make_Defining_Identifier (Loc, Name_uX);
Y : constant Entity_Id := Make_Defining_Identifier (Loc, Name_uY);
I : constant Entity_Id := Make_Defining_Identifier (Loc, Name_uI);
J : constant Entity_Id := Make_Defining_Identifier (Loc, Name_uJ);
Index : constant Entity_Id := Base_Type (Etype (First_Index (Typ)));
Loop_Statement : Node_Id;
Loop_Body : Node_Id;
If_Stat : Node_Id;
Inner_If : Node_Id;
Final_Expr : Node_Id;
Func_Body : Node_Id;
Func_Name : Entity_Id;
Formals : List_Id;
Length1 : Node_Id;
Length2 : Node_Id;
begin
-- if J = Y'last then
-- exit;
-- else
-- J := index'succ (J);
-- end if;
Inner_If :=
Make_Implicit_If_Statement (Nod,
Condition =>
Make_Op_Eq (Loc,
Left_Opnd => New_Reference_To (J, Loc),
Right_Opnd =>
Make_Attribute_Reference (Loc,
Prefix => New_Reference_To (Y, Loc),
Attribute_Name => Name_Last)),
Then_Statements => New_List (
Make_Exit_Statement (Loc)),
Else_Statements =>
New_List (
Make_Assignment_Statement (Loc,
Name => New_Reference_To (J, Loc),
Expression =>
Make_Attribute_Reference (Loc,
Prefix => New_Reference_To (Index, Loc),
Attribute_Name => Name_Succ,
Expressions => New_List (New_Reference_To (J, Loc))))));
-- if X (I) = Y (J) then
-- if ... end if;
-- else
-- return X (I) > Y (J);
-- end if;
Loop_Body :=
Make_Implicit_If_Statement (Nod,
Condition =>
Make_Op_Eq (Loc,
Left_Opnd =>
Make_Indexed_Component (Loc,
Prefix => New_Reference_To (X, Loc),
Expressions => New_List (New_Reference_To (I, Loc))),
Right_Opnd =>
Make_Indexed_Component (Loc,
Prefix => New_Reference_To (Y, Loc),
Expressions => New_List (New_Reference_To (J, Loc)))),
Then_Statements => New_List (Inner_If),
Else_Statements => New_List (
Make_Return_Statement (Loc,
Expression =>
Make_Op_Gt (Loc,
Left_Opnd =>
Make_Indexed_Component (Loc,
Prefix => New_Reference_To (X, Loc),
Expressions => New_List (New_Reference_To (I, Loc))),
Right_Opnd =>
Make_Indexed_Component (Loc,
Prefix => New_Reference_To (Y, Loc),
Expressions => New_List (
New_Reference_To (J, Loc)))))));
-- for I in X'range loop
-- if ... end if;
-- end loop;
Loop_Statement :=
Make_Implicit_Loop_Statement (Nod,
Identifier => Empty,
Iteration_Scheme =>
Make_Iteration_Scheme (Loc,
Loop_Parameter_Specification =>
Make_Loop_Parameter_Specification (Loc,
Defining_Identifier => I,
Discrete_Subtype_Definition =>
Make_Attribute_Reference (Loc,
Prefix => New_Reference_To (X, Loc),
Attribute_Name => Name_Range))),
Statements => New_List (Loop_Body));
-- if X'length = 0 then
-- return false;
-- elsif Y'length = 0 then
-- return true;
-- else
-- for ... loop ... end loop;
-- return X'length > Y'length;
-- end if;
Length1 :=
Make_Attribute_Reference (Loc,
Prefix => New_Reference_To (X, Loc),
Attribute_Name => Name_Length);
Length2 :=
Make_Attribute_Reference (Loc,
Prefix => New_Reference_To (Y, Loc),
Attribute_Name => Name_Length);
Final_Expr :=
Make_Op_Gt (Loc,
Left_Opnd => Length1,
Right_Opnd => Length2);
If_Stat :=
Make_Implicit_If_Statement (Nod,
Condition =>
Make_Op_Eq (Loc,
Left_Opnd =>
Make_Attribute_Reference (Loc,
Prefix => New_Reference_To (X, Loc),
Attribute_Name => Name_Length),
Right_Opnd =>
Make_Integer_Literal (Loc, 0)),
Then_Statements =>
New_List (
Make_Return_Statement (Loc,
Expression => New_Reference_To (Standard_False, Loc))),
Elsif_Parts => New_List (
Make_Elsif_Part (Loc,
Condition =>
Make_Op_Eq (Loc,
Left_Opnd =>
Make_Attribute_Reference (Loc,
Prefix => New_Reference_To (Y, Loc),
Attribute_Name => Name_Length),
Right_Opnd =>
Make_Integer_Literal (Loc, 0)),
Then_Statements =>
New_List (
Make_Return_Statement (Loc,
Expression => New_Reference_To (Standard_True, Loc))))),
Else_Statements => New_List (
Loop_Statement,
Make_Return_Statement (Loc,
Expression => Final_Expr)));
-- (X : a; Y: a)
Formals := New_List (
Make_Parameter_Specification (Loc,
Defining_Identifier => X,
Parameter_Type => New_Reference_To (Typ, Loc)),
Make_Parameter_Specification (Loc,
Defining_Identifier => Y,
Parameter_Type => New_Reference_To (Typ, Loc)));
-- function Gnnn (...) return boolean is
-- J : index := Y'first;
-- begin
-- if ... end if;
-- end Gnnn;
Func_Name := Make_Defining_Identifier (Loc, New_Internal_Name ('G'));
Func_Body :=
Make_Subprogram_Body (Loc,
Specification =>
Make_Function_Specification (Loc,
Defining_Unit_Name => Func_Name,
Parameter_Specifications => Formals,
Result_Definition => New_Reference_To (Standard_Boolean, Loc)),
Declarations => New_List (
Make_Object_Declaration (Loc,
Defining_Identifier => J,
Object_Definition => New_Reference_To (Index, Loc),
Expression =>
Make_Attribute_Reference (Loc,
Prefix => New_Reference_To (Y, Loc),
Attribute_Name => Name_First))),
Handled_Statement_Sequence =>
Make_Handled_Sequence_Of_Statements (Loc,
Statements => New_List (If_Stat)));
return Func_Body;
end Make_Array_Comparison_Op;
---------------------------
-- Make_Boolean_Array_Op --
---------------------------
-- For logical operations on boolean arrays, expand in line the
-- following, replacing 'and' with 'or' or 'xor' where needed:
-- function Annn (A : typ; B: typ) return typ is
-- C : typ;
-- begin
-- for J in A'range loop
-- C (J) := A (J) op B (J);
-- end loop;
-- return C;
-- end Annn;
-- Here typ is the boolean array type
function Make_Boolean_Array_Op
(Typ : Entity_Id;
N : Node_Id) return Node_Id
is
Loc : constant Source_Ptr := Sloc (N);
A : constant Entity_Id := Make_Defining_Identifier (Loc, Name_uA);
B : constant Entity_Id := Make_Defining_Identifier (Loc, Name_uB);
C : constant Entity_Id := Make_Defining_Identifier (Loc, Name_uC);
J : constant Entity_Id := Make_Defining_Identifier (Loc, Name_uJ);
A_J : Node_Id;
B_J : Node_Id;
C_J : Node_Id;
Op : Node_Id;
Formals : List_Id;
Func_Name : Entity_Id;
Func_Body : Node_Id;
Loop_Statement : Node_Id;
begin
A_J :=
Make_Indexed_Component (Loc,
Prefix => New_Reference_To (A, Loc),
Expressions => New_List (New_Reference_To (J, Loc)));
B_J :=
Make_Indexed_Component (Loc,
Prefix => New_Reference_To (B, Loc),
Expressions => New_List (New_Reference_To (J, Loc)));
C_J :=
Make_Indexed_Component (Loc,
Prefix => New_Reference_To (C, Loc),
Expressions => New_List (New_Reference_To (J, Loc)));
if Nkind (N) = N_Op_And then
Op :=
Make_Op_And (Loc,
Left_Opnd => A_J,
Right_Opnd => B_J);
elsif Nkind (N) = N_Op_Or then
Op :=
Make_Op_Or (Loc,
Left_Opnd => A_J,
Right_Opnd => B_J);
else
Op :=
Make_Op_Xor (Loc,
Left_Opnd => A_J,
Right_Opnd => B_J);
end if;
Loop_Statement :=
Make_Implicit_Loop_Statement (N,
Identifier => Empty,
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_Reference_To (A, Loc),
Attribute_Name => Name_Range))),
Statements => New_List (
Make_Assignment_Statement (Loc,
Name => C_J,
Expression => Op)));
Formals := New_List (
Make_Parameter_Specification (Loc,
Defining_Identifier => A,
Parameter_Type => New_Reference_To (Typ, Loc)),
Make_Parameter_Specification (Loc,
Defining_Identifier => B,
Parameter_Type => New_Reference_To (Typ, Loc)));
Func_Name :=
Make_Defining_Identifier (Loc, New_Internal_Name ('A'));
Set_Is_Inlined (Func_Name);
Func_Body :=
Make_Subprogram_Body (Loc,
Specification =>
Make_Function_Specification (Loc,
Defining_Unit_Name => Func_Name,
Parameter_Specifications => Formals,
Result_Definition => New_Reference_To (Typ, Loc)),
Declarations => New_List (
Make_Object_Declaration (Loc,
Defining_Identifier => C,
Object_Definition => New_Reference_To (Typ, Loc))),
Handled_Statement_Sequence =>
Make_Handled_Sequence_Of_Statements (Loc,
Statements => New_List (
Loop_Statement,
Make_Return_Statement (Loc,
Expression => New_Reference_To (C, Loc)))));
return Func_Body;
end Make_Boolean_Array_Op;
------------------------
-- Rewrite_Comparison --
------------------------
procedure Rewrite_Comparison (N : Node_Id) is
begin
if Nkind (N) = N_Type_Conversion then
Rewrite_Comparison (Expression (N));
elsif Nkind (N) not in N_Op_Compare then
null;
else
declare
Typ : constant Entity_Id := Etype (N);
Op1 : constant Node_Id := Left_Opnd (N);
Op2 : constant Node_Id := Right_Opnd (N);
Res : constant Compare_Result := Compile_Time_Compare (Op1, Op2);
-- Res indicates if compare outcome can be compile time determined
True_Result : Boolean;
False_Result : Boolean;
begin
case N_Op_Compare (Nkind (N)) is
when N_Op_Eq =>
True_Result := Res = EQ;
False_Result := Res = LT or else Res = GT or else Res = NE;
when N_Op_Ge =>
True_Result := Res in Compare_GE;
False_Result := Res = LT;
if Res = LE
and then Constant_Condition_Warnings
and then Comes_From_Source (Original_Node (N))
and then Nkind (Original_Node (N)) = N_Op_Ge
and then not In_Instance
and then not Warnings_Off (Etype (Left_Opnd (N)))
and then Is_Integer_Type (Etype (Left_Opnd (N)))
then
Error_Msg_N
("can never be greater than, could replace by ""'=""?", N);
end if;
when N_Op_Gt =>
True_Result := Res = GT;
False_Result := Res in Compare_LE;
when N_Op_Lt =>
True_Result := Res = LT;
False_Result := Res in Compare_GE;
when N_Op_Le =>
True_Result := Res in Compare_LE;
False_Result := Res = GT;
if Res = GE
and then Constant_Condition_Warnings
and then Comes_From_Source (Original_Node (N))
and then Nkind (Original_Node (N)) = N_Op_Le
and then not In_Instance
and then not Warnings_Off (Etype (Left_Opnd (N)))
and then Is_Integer_Type (Etype (Left_Opnd (N)))
then
Error_Msg_N
("can never be less than, could replace by ""'=""?", N);
end if;
when N_Op_Ne =>
True_Result := Res = NE or else Res = GT or else Res = LT;
False_Result := Res = EQ;
end case;
if True_Result then
Rewrite (N,
Convert_To (Typ,
New_Occurrence_Of (Standard_True, Sloc (N))));
Analyze_And_Resolve (N, Typ);
Warn_On_Known_Condition (N);
elsif False_Result then
Rewrite (N,
Convert_To (Typ,
New_Occurrence_Of (Standard_False, Sloc (N))));
Analyze_And_Resolve (N, Typ);
Warn_On_Known_Condition (N);
end if;
end;
end if;
end Rewrite_Comparison;
----------------------------
-- Safe_In_Place_Array_Op --
----------------------------
function Safe_In_Place_Array_Op
(Lhs : Node_Id;
Op1 : Node_Id;
Op2 : Node_Id) return Boolean
is
Target : Entity_Id;
function Is_Safe_Operand (Op : Node_Id) return Boolean;
-- Operand is safe if it cannot overlap part of the target of the
-- operation. If the operand and the target are identical, the operand
-- is safe. The operand can be empty in the case of negation.
function Is_Unaliased (N : Node_Id) return Boolean;
-- Check that N is a stand-alone entity
------------------
-- Is_Unaliased --
------------------
function Is_Unaliased (N : Node_Id) return Boolean is
begin
return
Is_Entity_Name (N)
and then No (Address_Clause (Entity (N)))
and then No (Renamed_Object (Entity (N)));
end Is_Unaliased;
---------------------
-- Is_Safe_Operand --
---------------------
function Is_Safe_Operand (Op : Node_Id) return Boolean is
begin
if No (Op) then
return True;
elsif Is_Entity_Name (Op) then
return Is_Unaliased (Op);
elsif Nkind (Op) = N_Indexed_Component
or else Nkind (Op) = N_Selected_Component
then
return Is_Unaliased (Prefix (Op));
elsif Nkind (Op) = N_Slice then
return
Is_Unaliased (Prefix (Op))
and then Entity (Prefix (Op)) /= Target;
elsif Nkind (Op) = N_Op_Not then
return Is_Safe_Operand (Right_Opnd (Op));
else
return False;
end if;
end Is_Safe_Operand;
-- Start of processing for Is_Safe_In_Place_Array_Op
begin
-- We skip this processing if the component size is not the
-- same as a system storage unit (since at least for NOT
-- this would cause problems).
if Component_Size (Etype (Lhs)) /= System_Storage_Unit then
return False;
-- Cannot do in place stuff on Java_VM since cannot pass addresses
elsif Java_VM then
return False;
-- Cannot do in place stuff if non-standard Boolean representation
elsif Has_Non_Standard_Rep (Component_Type (Etype (Lhs))) then
return False;
elsif not Is_Unaliased (Lhs) then
return False;
else
Target := Entity (Lhs);
return
Is_Safe_Operand (Op1)
and then Is_Safe_Operand (Op2);
end if;
end Safe_In_Place_Array_Op;
-----------------------
-- Tagged_Membership --
-----------------------
-- There are two different cases to consider depending on whether
-- the right operand is a class-wide type or not. If not we just
-- compare the actual tag of the left expr to the target type tag:
--
-- Left_Expr.Tag = Right_Type'Tag;
--
-- If it is a class-wide type we use the RT function CW_Membership which
-- is usually implemented by looking in the ancestor tables contained in
-- the dispatch table pointed by Left_Expr.Tag for Typ'Tag
function Tagged_Membership (N : Node_Id) return Node_Id is
Left : constant Node_Id := Left_Opnd (N);
Right : constant Node_Id := Right_Opnd (N);
Loc : constant Source_Ptr := Sloc (N);
Left_Type : Entity_Id;
Right_Type : Entity_Id;
Obj_Tag : Node_Id;
begin
Left_Type := Etype (Left);
Right_Type := Etype (Right);
if Is_Class_Wide_Type (Left_Type) then
Left_Type := Root_Type (Left_Type);
end if;
Obj_Tag :=
Make_Selected_Component (Loc,
Prefix => Relocate_Node (Left),
Selector_Name =>
New_Reference_To (First_Tag_Component (Left_Type), Loc));
if Is_Class_Wide_Type (Right_Type) then
-- Ada 2005 (AI-251): Class-wide applied to interfaces
if Is_Interface (Etype (Class_Wide_Type (Right_Type)))
-- Give support to: "Iface_CW_Typ in Typ'Class"
or else Is_Interface (Left_Type)
then
-- Issue error if IW_Membership operation not available in a
-- configurable run time setting.
if not RTE_Available (RE_IW_Membership) then
Error_Msg_CRT ("abstract interface types", N);
return Empty;
end if;
return
Make_Function_Call (Loc,
Name => New_Occurrence_Of (RTE (RE_IW_Membership), Loc),
Parameter_Associations => New_List (
Make_Attribute_Reference (Loc,
Prefix => Obj_Tag,
Attribute_Name => Name_Address),
New_Reference_To (
Node (First_Elmt
(Access_Disp_Table (Root_Type (Right_Type)))),
Loc)));
-- Ada 95: Normal case
else
return
Make_Function_Call (Loc,
Name => New_Occurrence_Of (RTE (RE_CW_Membership), Loc),
Parameter_Associations => New_List (
Obj_Tag,
New_Reference_To (
Node (First_Elmt
(Access_Disp_Table (Root_Type (Right_Type)))),
Loc)));
end if;
else
return
Make_Op_Eq (Loc,
Left_Opnd => Obj_Tag,
Right_Opnd =>
New_Reference_To
(Node (First_Elmt (Access_Disp_Table (Right_Type))), Loc));
end if;
end Tagged_Membership;
------------------------------
-- Unary_Op_Validity_Checks --
------------------------------
procedure Unary_Op_Validity_Checks (N : Node_Id) is
begin
if Validity_Checks_On and Validity_Check_Operands then
Ensure_Valid (Right_Opnd (N));
end if;
end Unary_Op_Validity_Checks;
end Exp_Ch4;
|
package GESTE_Fonts.FreeSerif5pt7b is
Font : constant Bitmap_Font_Ref;
private
FreeSerif5pt7bBitmaps : aliased constant Font_Bitmap := (
16#00#, 16#00#, 16#00#, 16#00#, 16#04#, 16#02#, 16#01#, 16#00#, 16#80#,
16#00#, 16#00#, 16#10#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#03#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#05#, 16#02#, 16#83#, 16#E0#,
16#A0#, 16#F8#, 16#28#, 16#28#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#04#, 16#07#, 16#05#, 16#01#, 16#80#, 16#60#, 16#28#, 16#58#, 16#1C#,
16#04#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#02#, 16#02#, 16#E1#,
16#60#, 16#BC#, 16#75#, 16#14#, 16#89#, 16#80#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#03#, 16#01#, 16#40#, 16#D8#, 16#68#, 16#D8#, 16#64#,
16#1D#, 16#80#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#04#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#02#, 16#01#, 16#01#, 16#00#, 16#80#,
16#40#, 16#10#, 16#08#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#04#, 16#01#, 16#00#, 16#80#, 16#20#, 16#20#, 16#10#, 16#08#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#02#, 16#03#, 16#81#, 16#C0#, 16#40#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#40#, 16#F8#, 16#10#, 16#08#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#10#, 16#08#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#E0#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#10#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#02#, 16#02#, 16#01#, 16#00#, 16#80#, 16#80#, 16#40#,
16#20#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#0E#, 16#05#, 16#04#,
16#42#, 16#21#, 16#10#, 16#88#, 16#28#, 16#1C#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#02#, 16#01#, 16#00#, 16#80#, 16#40#, 16#20#,
16#10#, 16#1C#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#07#,
16#04#, 16#80#, 16#40#, 16#20#, 16#20#, 16#20#, 16#1C#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#07#, 16#00#, 16#80#, 16#80#, 16#60#,
16#10#, 16#08#, 16#38#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#01#, 16#03#, 16#81#, 16#41#, 16#20#, 16#F8#, 16#08#, 16#04#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#03#, 16#02#, 16#01#, 16#C0#,
16#20#, 16#10#, 16#08#, 16#38#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#02#, 16#06#, 16#02#, 16#03#, 16#C1#, 16#30#, 16#88#, 16#24#, 16#1C#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#07#, 16#04#, 16#80#,
16#40#, 16#40#, 16#20#, 16#10#, 16#08#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#07#, 16#02#, 16#81#, 16#40#, 16#40#, 16#50#, 16#28#,
16#1C#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#07#, 16#04#,
16#82#, 16#21#, 16#90#, 16#70#, 16#08#, 16#08#, 16#08#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#01#, 16#00#, 16#00#, 16#00#,
16#00#, 16#10#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#01#, 16#00#, 16#00#, 16#00#, 16#00#, 16#10#, 16#08#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#20#, 16#E0#,
16#80#, 16#38#, 16#02#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#01#, 16#F0#, 16#00#, 16#7C#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#01#, 16#00#,
16#60#, 16#0C#, 16#0C#, 16#18#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#07#, 16#02#, 16#80#, 16#40#, 16#20#, 16#20#, 16#00#, 16#08#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#01#, 16#C1#, 16#51#,
16#54#, 16#AA#, 16#55#, 16#3F#, 16#07#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#01#, 16#00#, 16#80#, 16#A0#, 16#90#, 16#7C#, 16#22#,
16#31#, 16#80#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#0F#, 16#82#,
16#61#, 16#20#, 16#E0#, 16#4C#, 16#22#, 16#3E#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#03#, 16#82#, 16#23#, 16#01#, 16#80#, 16#40#,
16#20#, 16#0F#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#0F#,
16#82#, 16#21#, 16#08#, 16#84#, 16#42#, 16#22#, 16#3E#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#0F#, 16#82#, 16#01#, 16#00#, 16#F0#,
16#40#, 16#22#, 16#3F#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#0F#, 16#82#, 16#01#, 16#20#, 16#F0#, 16#48#, 16#20#, 16#38#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#03#, 16#82#, 16#21#, 16#01#,
16#8C#, 16#C4#, 16#22#, 16#0F#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#0E#, 16#E2#, 16#21#, 16#10#, 16#F8#, 16#44#, 16#22#, 16#3B#,
16#80#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#0E#, 16#02#, 16#01#,
16#00#, 16#80#, 16#40#, 16#20#, 16#38#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#07#, 16#01#, 16#00#, 16#80#, 16#40#, 16#20#, 16#10#,
16#30#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#0E#, 16#E2#,
16#41#, 16#40#, 16#E0#, 16#58#, 16#22#, 16#3B#, 16#80#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#0E#, 16#02#, 16#01#, 16#00#, 16#80#, 16#40#,
16#22#, 16#3F#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#0C#,
16#3B#, 16#19#, 16#94#, 16#EA#, 16#59#, 16#2C#, 16#BC#, 16#E0#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#0C#, 16#63#, 16#21#, 16#D0#, 16#B8#,
16#4C#, 16#22#, 16#39#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#03#, 16#82#, 16#23#, 16#09#, 16#04#, 16#C2#, 16#22#, 16#0E#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#0F#, 16#82#, 16#41#, 16#20#,
16#90#, 16#78#, 16#20#, 16#38#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#03#, 16#82#, 16#23#, 16#09#, 16#04#, 16#C2#, 16#22#, 16#0E#,
16#01#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#0F#, 16#82#, 16#41#,
16#20#, 16#E0#, 16#50#, 16#26#, 16#39#, 16#80#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#06#, 16#02#, 16#C1#, 16#00#, 16#60#, 16#08#, 16#44#,
16#1C#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#0F#, 16#C4#,
16#A0#, 16#40#, 16#20#, 16#10#, 16#18#, 16#0E#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#0E#, 16#62#, 16#21#, 16#10#, 16#88#, 16#44#,
16#22#, 16#0E#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#0E#,
16#62#, 16#21#, 16#90#, 16#50#, 16#28#, 16#08#, 16#04#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#0F#, 16#DA#, 16#45#, 16#34#, 16#5A#,
16#36#, 16#19#, 16#08#, 16#80#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#0E#, 16#63#, 16#20#, 16#A0#, 16#20#, 16#28#, 16#22#, 16#33#, 16#80#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#0E#, 16#62#, 16#20#, 16#A0#,
16#20#, 16#10#, 16#08#, 16#0E#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#0F#, 16#C4#, 16#40#, 16#40#, 16#40#, 16#20#, 16#22#, 16#3F#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#06#, 16#02#, 16#01#,
16#00#, 16#80#, 16#40#, 16#20#, 16#10#, 16#08#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#08#, 16#04#, 16#02#, 16#00#, 16#80#, 16#40#, 16#20#,
16#08#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#0C#, 16#02#,
16#01#, 16#00#, 16#80#, 16#40#, 16#20#, 16#10#, 16#08#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#02#, 16#03#, 16#02#, 16#41#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#1F#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#02#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#01#, 16#80#, 16#20#, 16#70#, 16#48#, 16#3C#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#0C#, 16#02#, 16#01#, 16#C0#,
16#90#, 16#48#, 16#24#, 16#1C#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#01#, 16#C1#, 16#00#, 16#80#, 16#40#, 16#1C#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#01#, 16#00#, 16#81#,
16#C1#, 16#20#, 16#90#, 16#48#, 16#1C#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#01#, 16#C1#, 16#E0#, 16#80#, 16#40#,
16#1C#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#06#, 16#04#, 16#02#,
16#03#, 16#80#, 16#80#, 16#40#, 16#20#, 16#38#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#01#, 16#E1#, 16#20#, 16#50#,
16#30#, 16#1C#, 16#12#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#0C#,
16#02#, 16#01#, 16#C0#, 16#A0#, 16#50#, 16#28#, 16#36#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#04#, 16#00#, 16#01#, 16#01#, 16#80#,
16#40#, 16#20#, 16#38#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#02#, 16#00#, 16#00#, 16#80#, 16#C0#, 16#20#, 16#10#, 16#08#, 16#04#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#0C#, 16#02#, 16#01#, 16#60#,
16#C0#, 16#60#, 16#28#, 16#36#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#0C#, 16#02#, 16#01#, 16#00#, 16#80#, 16#40#, 16#20#, 16#30#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#03#,
16#D8#, 16#B4#, 16#52#, 16#29#, 16#37#, 16#C0#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#03#, 16#C0#, 16#A0#, 16#50#, 16#28#,
16#36#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#01#, 16#C1#, 16#30#, 16#88#, 16#68#, 16#1C#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#03#, 16#C0#, 16#90#, 16#48#,
16#24#, 16#1C#, 16#08#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#01#, 16#81#, 16#20#, 16#90#, 16#48#, 16#1C#, 16#02#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#01#, 16#80#, 16#80#,
16#40#, 16#20#, 16#38#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#01#, 16#01#, 16#00#, 16#60#, 16#50#, 16#38#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#02#, 16#03#, 16#80#,
16#80#, 16#40#, 16#20#, 16#10#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#03#, 16#40#, 16#A0#, 16#50#, 16#28#, 16#1E#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#03#,
16#60#, 16#A0#, 16#50#, 16#30#, 16#08#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#03#, 16#C9#, 16#28#, 16#54#, 16#34#,
16#0A#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#03#, 16#40#, 16#C0#, 16#20#, 16#68#, 16#36#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#03#, 16#60#, 16#A0#, 16#50#,
16#10#, 16#08#, 16#08#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#03#, 16#C1#, 16#40#, 16#40#, 16#20#, 16#3C#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#06#, 16#02#, 16#01#, 16#00#, 16#80#, 16#80#,
16#40#, 16#10#, 16#08#, 16#04#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#04#, 16#02#, 16#01#, 16#00#, 16#80#, 16#40#, 16#20#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#02#, 16#01#, 16#00#, 16#80#,
16#40#, 16#20#, 16#10#, 16#08#, 16#04#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#D0#, 16#B0#, 16#00#, 16#00#,
16#00#, 16#00#);
Font_D : aliased constant Bitmap_Font :=
(
Bytes_Per_Glyph => 14,
Glyph_Width => 9,
Glyph_Height => 12,
Data => FreeSerif5pt7bBitmaps'Access);
Font : constant Bitmap_Font_Ref := Font_D'Access;
end GESTE_Fonts.FreeSerif5pt7b;
|
-- This package has been generated automatically by GNATtest.
-- You are allowed to add your code to the bodies of test routines.
-- Such changes will be kept during further regeneration of this file.
-- All code placed outside of test routine bodies will be lost. The
-- code intended to set up and tear down the test environment should be
-- placed into Tk.Widget.Test_Data.
with AUnit.Assertions; use AUnit.Assertions;
with System.Assertions;
-- begin read only
-- id:2.2/00/
--
-- This section can be used to add with clauses if necessary.
--
-- end read only
with Ada.Environment_Variables; use Ada.Environment_Variables;
with System.Address_Image;
with Tk.Button; use Tk.Button;
with Tk.Grid; use Tk.Grid;
with Tk.Labelframe; use Tk.Labelframe;
with Tk.Menu; use Tk.Menu;
with Tk.TopLevel; use Tk.TopLevel;
with Tk.TtkButton; use Tk.TtkButton;
with Tk.TtkEntry; use Tk.TtkEntry;
with Tk.TtkLabel; use Tk.TtkLabel;
-- begin read only
-- end read only
package body Tk.Widget.Test_Data.Tests is
-- begin read only
-- id:2.2/01/
--
-- This section can be used to add global variables and other elements.
--
-- end read only
-- begin read only
-- end read only
-- begin read only
function Wrap_Test_Widgets_Array_Image_8ee9dc_a68b37
(Widgets: Widgets_Array) return String is
begin
begin
pragma Assert(Widgets'Length > 0);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"req_sloc(tk-widget.ads:0):Test_Widgets_Array_Image test requirement violated");
end;
declare
Test_Widgets_Array_Image_8ee9dc_a68b37_Result: constant String :=
GNATtest_Generated.GNATtest_Standard.Tk.Widget.Widgets_Array_Image
(Widgets);
begin
begin
pragma Assert
(Test_Widgets_Array_Image_8ee9dc_a68b37_Result'Length > 0);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"ens_sloc(tk-widget.ads:0:):Test_Widgets_Array_Image test commitment violated");
end;
return Test_Widgets_Array_Image_8ee9dc_a68b37_Result;
end;
end Wrap_Test_Widgets_Array_Image_8ee9dc_a68b37;
-- end read only
-- begin read only
procedure Test_Widgets_Array_Image_test_widgets_array_image
(Gnattest_T: in out Test);
procedure Test_Widgets_Array_Image_8ee9dc_a68b37
(Gnattest_T: in out Test) renames
Test_Widgets_Array_Image_test_widgets_array_image;
-- id:2.2/8ee9dccd40bd054f/Widgets_Array_Image/1/0/test_widgets_array_image/
procedure Test_Widgets_Array_Image_test_widgets_array_image
(Gnattest_T: in out Test) is
function Widgets_Array_Image
(Widgets: Widgets_Array) return String renames
Wrap_Test_Widgets_Array_Image_8ee9dc_a68b37;
-- end read only
pragma Unreferenced(Gnattest_T);
Button1: Tk_Button;
Button2: Tk_Button;
Widgets: Widgets_Array(1 .. 2);
begin
if Value("DISPLAY", "")'Length = 0 then
Assert(True, "No display, can't test");
return;
end if;
Create(Button1, ".mybutton1", Button_Options'(others => <>));
Create(Button2, ".mybutton2", Button_Options'(others => <>));
Widgets := (Button1, Button2);
Assert
(Widgets_Array_Image(Widgets) = ".mybutton1 .mybutton2",
"Invalid image for Widgets_Array");
Destroy(Button1);
Destroy(Button2);
-- begin read only
end Test_Widgets_Array_Image_test_widgets_array_image;
-- end read only
-- begin read only
function Wrap_Test_Pixel_Data_Value_1cddc7_342332
(Value: String) return Pixel_Data is
begin
begin
pragma Assert(True);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"req_sloc(tk-widget.ads:0):Test_Pixel_Data_Value test requirement violated");
end;
declare
Test_Pixel_Data_Value_1cddc7_342332_Result: constant Pixel_Data :=
GNATtest_Generated.GNATtest_Standard.Tk.Widget.Pixel_Data_Value
(Value);
begin
begin
pragma Assert(True);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"ens_sloc(tk-widget.ads:0:):Test_Pixel_Data_Value test commitment violated");
end;
return Test_Pixel_Data_Value_1cddc7_342332_Result;
end;
end Wrap_Test_Pixel_Data_Value_1cddc7_342332;
-- end read only
-- begin read only
procedure Test_Pixel_Data_Value_test_pixel_data_value
(Gnattest_T: in out Test);
procedure Test_Pixel_Data_Value_1cddc7_342332
(Gnattest_T: in out Test) renames
Test_Pixel_Data_Value_test_pixel_data_value;
-- id:2.2/1cddc72f48314db2/Pixel_Data_Value/1/0/test_pixel_data_value/
procedure Test_Pixel_Data_Value_test_pixel_data_value
(Gnattest_T: in out Test) is
function Pixel_Data_Value(Value: String) return Pixel_Data renames
Wrap_Test_Pixel_Data_Value_1cddc7_342332;
-- end read only
pragma Unreferenced(Gnattest_T);
My_Pixel: Pixel_Data;
begin
My_Pixel := Pixel_Data_Value("2c");
Assert
(My_Pixel.Value = 2.0 and My_Pixel.Value_Unit = C,
"Invalid value for pixel data from string conversion.");
My_Pixel := Pixel_Data_Value("");
Assert
(My_Pixel.Value = -1.0 and My_Pixel.Value_Unit = PIXEL,
"Failed to convert empty string with Pixel_Data");
-- begin read only
end Test_Pixel_Data_Value_test_pixel_data_value;
-- end read only
-- begin read only
function Wrap_Test_Get_Widget_331ad1_ff97b7
(Path_Name: Tk_Path_String;
Interpreter: Tcl_Interpreter := Get_Interpreter) return Tk_Widget is
begin
begin
pragma Assert
(Path_Name'Length > 0 and Interpreter /= Null_Interpreter);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"req_sloc(tk-widget.ads:0):Test_Get_Widget test requirement violated");
end;
declare
Test_Get_Widget_331ad1_ff97b7_Result: constant Tk_Widget :=
GNATtest_Generated.GNATtest_Standard.Tk.Widget.Get_Widget
(Path_Name, Interpreter);
begin
begin
pragma Assert(True);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"ens_sloc(tk-widget.ads:0:):Test_Get_Widget test commitment violated");
end;
return Test_Get_Widget_331ad1_ff97b7_Result;
end;
end Wrap_Test_Get_Widget_331ad1_ff97b7;
-- end read only
-- begin read only
procedure Test_Get_Widget_test_get_widget(Gnattest_T: in out Test);
procedure Test_Get_Widget_331ad1_ff97b7(Gnattest_T: in out Test) renames
Test_Get_Widget_test_get_widget;
-- id:2.2/331ad1a0fc5269a6/Get_Widget/1/0/test_get_widget/
procedure Test_Get_Widget_test_get_widget(Gnattest_T: in out Test) is
function Get_Widget
(Path_Name: Tk_Path_String;
Interpreter: Tcl_Interpreter := Get_Interpreter)
return Tk_Widget renames
Wrap_Test_Get_Widget_331ad1_ff97b7;
-- end read only
pragma Unreferenced(Gnattest_T);
Button: Tk_Button;
begin
if Value("DISPLAY", "")'Length = 0 then
Assert(True, "No display, can't test");
return;
end if;
Create(Button, ".mybutton", Button_Options'(others => <>));
Create(Button, ".mybutton2", Button_Options'(others => <>));
Button := Get_Widget(".mybutton");
Assert
(Tk_Path_Name(Button) = ".mybutton",
"Failed to get the proper widget with Get_Widget.");
Destroy(Button);
Button := Get_Widget(".mybutton2");
Destroy(Button);
Assert(Button = Null_Widget, "Failed to get non existing Tk widget.");
-- begin read only
end Test_Get_Widget_test_get_widget;
-- end read only
-- begin read only
function Wrap_Test_Tk_Path_Name_5c8bcc_22ac87
(Widgt: Tk_Widget) return Tk_Path_String is
begin
begin
pragma Assert(Widgt /= Null_Widget);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"req_sloc(tk-widget.ads:0):Test_Tk_PathName test requirement violated");
end;
declare
Test_Tk_Path_Name_5c8bcc_22ac87_Result: constant Tk_Path_String :=
GNATtest_Generated.GNATtest_Standard.Tk.Widget.Tk_Path_Name(Widgt);
begin
begin
pragma Assert(Test_Tk_Path_Name_5c8bcc_22ac87_Result'Length > 0);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"ens_sloc(tk-widget.ads:0:):Test_Tk_PathName test commitment violated");
end;
return Test_Tk_Path_Name_5c8bcc_22ac87_Result;
end;
end Wrap_Test_Tk_Path_Name_5c8bcc_22ac87;
-- end read only
-- begin read only
procedure Test_Tk_Path_Name_test_tk_pathname(Gnattest_T: in out Test);
procedure Test_Tk_Path_Name_5c8bcc_22ac87(Gnattest_T: in out Test) renames
Test_Tk_Path_Name_test_tk_pathname;
-- id:2.2/5c8bcc67c7e58aca/Tk_Path_Name/1/0/test_tk_pathname/
procedure Test_Tk_Path_Name_test_tk_pathname(Gnattest_T: in out Test) is
function Tk_Path_Name(Widgt: Tk_Widget) return Tk_Path_String renames
Wrap_Test_Tk_Path_Name_5c8bcc_22ac87;
-- end read only
pragma Unreferenced(Gnattest_T);
Button: Tk_Button;
begin
if Value("DISPLAY", "")'Length = 0 then
Assert(True, "No display, can't test");
return;
end if;
Create(Button, ".mybutton", Button_Options'(others => <>));
Assert
(Tk_Path_Name(Button) = ".mybutton",
"Failed to get Tk pathname for the selected widget.");
Destroy(Button);
-- begin read only
end Test_Tk_Path_Name_test_tk_pathname;
-- end read only
-- begin read only
function Wrap_Test_Tk_Interp_37dfaa_4dad3f
(Widgt: Tk_Widget) return Tcl_Interpreter is
begin
begin
pragma Assert(Widgt /= Null_Widget);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"req_sloc(tk-widget.ads:0):Test_Tk_Interp test requirement violated");
end;
declare
Test_Tk_Interp_37dfaa_4dad3f_Result: constant Tcl_Interpreter :=
GNATtest_Generated.GNATtest_Standard.Tk.Widget.Tk_Interp(Widgt);
begin
begin
pragma Assert
(Test_Tk_Interp_37dfaa_4dad3f_Result /= Null_Interpreter);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"ens_sloc(tk-widget.ads:0:):Test_Tk_Interp test commitment violated");
end;
return Test_Tk_Interp_37dfaa_4dad3f_Result;
end;
end Wrap_Test_Tk_Interp_37dfaa_4dad3f;
-- end read only
-- begin read only
procedure Test_Tk_Interp_test_tk_interp(Gnattest_T: in out Test);
procedure Test_Tk_Interp_37dfaa_4dad3f(Gnattest_T: in out Test) renames
Test_Tk_Interp_test_tk_interp;
-- id:2.2/37dfaac7975d5a6d/Tk_Interp/1/0/test_tk_interp/
procedure Test_Tk_Interp_test_tk_interp(Gnattest_T: in out Test) is
function Tk_Interp(Widgt: Tk_Widget) return Tcl_Interpreter renames
Wrap_Test_Tk_Interp_37dfaa_4dad3f;
-- end read only
pragma Unreferenced(Gnattest_T);
Button: Tk_Button;
begin
if Value("DISPLAY", "")'Length = 0 then
Assert(True, "No display, can't test");
return;
end if;
Create(Button, ".mybutton2", Button_Options'(others => <>));
Assert
(Tk_Interp(Button) /= Null_Interpreter,
"Failed to get Tk interpreter for the selected widget.");
Destroy(Button);
-- begin read only
end Test_Tk_Interp_test_tk_interp;
-- end read only
-- begin read only
function Wrap_Test_Tk_Window_Id_08bdcd_2020b9
(Widgt: Tk_Widget) return Tk_Window is
begin
begin
pragma Assert(Widgt /= Null_Widget);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"req_sloc(tk-widget.ads:0):Test_Tk_Window_Id test requirement violated");
end;
declare
Test_Tk_Window_Id_08bdcd_2020b9_Result: constant Tk_Window :=
GNATtest_Generated.GNATtest_Standard.Tk.Widget.Tk_Window_Id(Widgt);
begin
begin
pragma Assert(True);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"ens_sloc(tk-widget.ads:0:):Test_Tk_Window_Id test commitment violated");
end;
return Test_Tk_Window_Id_08bdcd_2020b9_Result;
end;
end Wrap_Test_Tk_Window_Id_08bdcd_2020b9;
-- end read only
-- begin read only
procedure Test_Tk_Window_Id_test_tk_window_id(Gnattest_T: in out Test);
procedure Test_Tk_Window_Id_08bdcd_2020b9(Gnattest_T: in out Test) renames
Test_Tk_Window_Id_test_tk_window_id;
-- id:2.2/08bdcd5144a32481/Tk_Window_Id/1/0/test_tk_window_id/
procedure Test_Tk_Window_Id_test_tk_window_id(Gnattest_T: in out Test) is
function Tk_Window_Id(Widgt: Tk_Widget) return Tk_Window renames
Wrap_Test_Tk_Window_Id_08bdcd_2020b9;
-- end read only
pragma Unreferenced(Gnattest_T);
Button: Tk_Button;
begin
if Value("DISPLAY", "")'Length = 0 then
Assert(True, "No display, can't test");
return;
end if;
Create(Button, ".mybutton", Button_Options'(others => <>));
Add(Button);
Tcl_Eval("update");
Assert
(Tk_Window_Id(Button) /= Null_Window,
"Failed to get pointer to Tk_Window for the selected widget.");
Destroy(Button);
-- begin read only
end Test_Tk_Window_Id_test_tk_window_id;
-- end read only
-- begin read only
procedure Wrap_Test_Option_Image_df3576_53f0ec
(Name: String; Value: Tcl_String;
Options_String: in out Unbounded_String) is
begin
begin
pragma Assert(Name'Length > 0);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"req_sloc(tk-widget.ads:0):Test_Option_Image_Tcl_String test requirement violated");
end;
GNATtest_Generated.GNATtest_Standard.Tk.Widget.Option_Image
(Name, Value, Options_String);
begin
pragma Assert(True);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"ens_sloc(tk-widget.ads:0:):Test_Option_Image_Tcl_String test commitment violated");
end;
end Wrap_Test_Option_Image_df3576_53f0ec;
-- end read only
-- begin read only
procedure Test_1_Option_Image_test_option_image_tcl_string
(Gnattest_T: in out Test);
procedure Test_Option_Image_df3576_53f0ec(Gnattest_T: in out Test) renames
Test_1_Option_Image_test_option_image_tcl_string;
-- id:2.2/df35765d5c552ca5/Option_Image/1/0/test_option_image_tcl_string/
procedure Test_1_Option_Image_test_option_image_tcl_string
(Gnattest_T: in out Test) is
procedure Option_Image
(Name: String; Value: Tcl_String;
Options_String: in out Unbounded_String) renames
Wrap_Test_Option_Image_df3576_53f0ec;
-- end read only
pragma Unreferenced(Gnattest_T);
Options_String: Unbounded_String;
begin
Option_Image("myoption", To_Tcl_String("myvalue"), Options_String);
Assert
(To_String(Options_String) = " -myoption myvalue",
"Failed to get image for Tcl_String option");
-- begin read only
end Test_1_Option_Image_test_option_image_tcl_string;
-- end read only
-- begin read only
procedure Wrap_Test_Option_Image_63348c_5cc1ad
(Name: String; Value: Extended_Natural;
Options_String: in out Unbounded_String) is
begin
begin
pragma Assert(Name'Length > 0);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"req_sloc(tk-widget.ads:0):Test_Option_Image_Extended_Natural test requirement violated");
end;
GNATtest_Generated.GNATtest_Standard.Tk.Widget.Option_Image
(Name, Value, Options_String);
begin
pragma Assert(True);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"ens_sloc(tk-widget.ads:0:):Test_Option_Image_Extended_Natural test commitment violated");
end;
end Wrap_Test_Option_Image_63348c_5cc1ad;
-- end read only
-- begin read only
procedure Test_2_Option_Image_test_option_image_extended_natural
(Gnattest_T: in out Test);
procedure Test_Option_Image_63348c_5cc1ad(Gnattest_T: in out Test) renames
Test_2_Option_Image_test_option_image_extended_natural;
-- id:2.2/63348cfcb5ac0347/Option_Image/0/0/test_option_image_extended_natural/
procedure Test_2_Option_Image_test_option_image_extended_natural
(Gnattest_T: in out Test) is
procedure Option_Image
(Name: String; Value: Extended_Natural;
Options_String: in out Unbounded_String) renames
Wrap_Test_Option_Image_63348c_5cc1ad;
-- end read only
pragma Unreferenced(Gnattest_T);
Options_String: Unbounded_String;
begin
Option_Image("myoption", Extended_Natural(10), Options_String);
Assert
(To_String(Options_String) = " -myoption 10",
"Failed to get image for Extended_Natural option");
-- begin read only
end Test_2_Option_Image_test_option_image_extended_natural;
-- end read only
-- begin read only
procedure Wrap_Test_Option_Image_a5c722_ce612d
(Name: String; Value: Pixel_Data;
Options_String: in out Unbounded_String) is
begin
begin
pragma Assert(Name'Length > 0);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"req_sloc(tk-widget.ads:0):Test_Option_Image_Pixed_Data test requirement violated");
end;
GNATtest_Generated.GNATtest_Standard.Tk.Widget.Option_Image
(Name, Value, Options_String);
begin
pragma Assert(True);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"ens_sloc(tk-widget.ads:0:):Test_Option_Image_Pixed_Data test commitment violated");
end;
end Wrap_Test_Option_Image_a5c722_ce612d;
-- end read only
-- begin read only
procedure Test_3_Option_Image_test_option_image_pixed_data
(Gnattest_T: in out Test);
procedure Test_Option_Image_a5c722_ce612d(Gnattest_T: in out Test) renames
Test_3_Option_Image_test_option_image_pixed_data;
-- id:2.2/a5c722c1bd7d0d8c/Option_Image/0/0/test_option_image_pixed_data/
procedure Test_3_Option_Image_test_option_image_pixed_data
(Gnattest_T: in out Test) is
procedure Option_Image
(Name: String; Value: Pixel_Data;
Options_String: in out Unbounded_String) renames
Wrap_Test_Option_Image_a5c722_ce612d;
-- end read only
pragma Unreferenced(Gnattest_T);
Options_String: Unbounded_String;
begin
Option_Image
("myoption", Pixel_Data'(Value => 2.0, Value_Unit => C),
Options_String);
Assert
(To_String(Options_String) = " -myoption 2.00c",
"Failed to get image for Pixel_Data option");
-- begin read only
end Test_3_Option_Image_test_option_image_pixed_data;
-- end read only
-- begin read only
procedure Wrap_Test_Option_Image_5707c3_208fae
(Name: String; Value: Relief_Type;
Options_String: in out Unbounded_String) is
begin
begin
pragma Assert(Name'Length > 0);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"req_sloc(tk-widget.ads:0):Test_Option_Image_Relief_Type test requirement violated");
end;
GNATtest_Generated.GNATtest_Standard.Tk.Widget.Option_Image
(Name, Value, Options_String);
begin
pragma Assert(True);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"ens_sloc(tk-widget.ads:0:):Test_Option_Image_Relief_Type test commitment violated");
end;
end Wrap_Test_Option_Image_5707c3_208fae;
-- end read only
-- begin read only
procedure Test_4_Option_Image_test_option_image_relief_type
(Gnattest_T: in out Test);
procedure Test_Option_Image_5707c3_208fae(Gnattest_T: in out Test) renames
Test_4_Option_Image_test_option_image_relief_type;
-- id:2.2/5707c3a9dd1ecf93/Option_Image/0/0/test_option_image_relief_type/
procedure Test_4_Option_Image_test_option_image_relief_type
(Gnattest_T: in out Test) is
procedure Option_Image
(Name: String; Value: Relief_Type;
Options_String: in out Unbounded_String) renames
Wrap_Test_Option_Image_5707c3_208fae;
-- end read only
pragma Unreferenced(Gnattest_T);
Options_String: Unbounded_String;
begin
Option_Image("myoption", RAISED, Options_String);
Assert
(To_String(Options_String) = " -myoption raised",
"Failed to get image for Relief_Type option");
-- begin read only
end Test_4_Option_Image_test_option_image_relief_type;
-- end read only
-- begin read only
procedure Wrap_Test_Option_Image_a39172_0792dc
(Name: String; Value: State_Type;
Options_String: in out Unbounded_String) is
begin
begin
pragma Assert(Name'Length > 0);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"req_sloc(tk-widget.ads:0):Test_Option_Image_State_Type test requirement violated");
end;
GNATtest_Generated.GNATtest_Standard.Tk.Widget.Option_Image
(Name, Value, Options_String);
begin
pragma Assert(True);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"ens_sloc(tk-widget.ads:0:):Test_Option_Image_State_Type test commitment violated");
end;
end Wrap_Test_Option_Image_a39172_0792dc;
-- end read only
-- begin read only
procedure Test_5_Option_Image_test_option_image_state_type
(Gnattest_T: in out Test);
procedure Test_Option_Image_a39172_0792dc(Gnattest_T: in out Test) renames
Test_5_Option_Image_test_option_image_state_type;
-- id:2.2/a391724162d5b3c0/Option_Image/0/0/test_option_image_state_type/
procedure Test_5_Option_Image_test_option_image_state_type
(Gnattest_T: in out Test) is
procedure Option_Image
(Name: String; Value: State_Type;
Options_String: in out Unbounded_String) renames
Wrap_Test_Option_Image_a39172_0792dc;
-- end read only
pragma Unreferenced(Gnattest_T);
Options_String: Unbounded_String;
begin
Option_Image("myoption", ACTIVE, Options_String);
Assert
(To_String(Options_String) = " -myoption active",
"Failed to get image for State_Type option");
-- begin read only
end Test_5_Option_Image_test_option_image_state_type;
-- end read only
-- begin read only
procedure Wrap_Test_Option_Image_9aff01_51f5f4
(Name: String; Value: Directions_Type;
Options_String: in out Unbounded_String) is
begin
begin
pragma Assert(Name'Length > 0);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"req_sloc(tk-widget.ads:0):Test_Option_Image_Directions_Type test requirement violated");
end;
GNATtest_Generated.GNATtest_Standard.Tk.Widget.Option_Image
(Name, Value, Options_String);
begin
pragma Assert(True);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"ens_sloc(tk-widget.ads:0:):Test_Option_Image_Directions_Type test commitment violated");
end;
end Wrap_Test_Option_Image_9aff01_51f5f4;
-- end read only
-- begin read only
procedure Test_6_Option_Image_test_option_image_directions_type
(Gnattest_T: in out Test);
procedure Test_Option_Image_9aff01_51f5f4(Gnattest_T: in out Test) renames
Test_6_Option_Image_test_option_image_directions_type;
-- id:2.2/9aff013d5cf41ab0/Option_Image/0/0/test_option_image_directions_type/
procedure Test_6_Option_Image_test_option_image_directions_type
(Gnattest_T: in out Test) is
procedure Option_Image
(Name: String; Value: Directions_Type;
Options_String: in out Unbounded_String) renames
Wrap_Test_Option_Image_9aff01_51f5f4;
-- end read only
pragma Unreferenced(Gnattest_T);
Options_String: Unbounded_String;
begin
Option_Image("myoption", Directions_Type'(SE), Options_String);
Assert
(To_String(Options_String) = " -myoption se",
"Failed to get image for Directions_Type option");
-- begin read only
end Test_6_Option_Image_test_option_image_directions_type;
-- end read only
-- begin read only
procedure Wrap_Test_Option_Image_6245ae_247131
(Name: String; Value: Place_Type;
Options_String: in out Unbounded_String) is
begin
begin
pragma Assert(Name'Length > 0);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"req_sloc(tk-widget.ads:0):Test_Option_Image_Place_Type test requirement violated");
end;
GNATtest_Generated.GNATtest_Standard.Tk.Widget.Option_Image
(Name, Value, Options_String);
begin
pragma Assert(True);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"ens_sloc(tk-widget.ads:0:):Test_Option_Image_Place_Type test commitment violated");
end;
end Wrap_Test_Option_Image_6245ae_247131;
-- end read only
-- begin read only
procedure Test_7_Option_Image_test_option_image_place_type
(Gnattest_T: in out Test);
procedure Test_Option_Image_6245ae_247131(Gnattest_T: in out Test) renames
Test_7_Option_Image_test_option_image_place_type;
-- id:2.2/6245aed24fd272d7/Option_Image/0/0/test_option_image_place_type/
procedure Test_7_Option_Image_test_option_image_place_type
(Gnattest_T: in out Test) is
procedure Option_Image
(Name: String; Value: Place_Type;
Options_String: in out Unbounded_String) renames
Wrap_Test_Option_Image_6245ae_247131;
-- end read only
pragma Unreferenced(Gnattest_T);
Options_String: Unbounded_String;
begin
Option_Image("myoption", BOTTOM, Options_String);
Assert
(To_String(Options_String) = " -myoption bottom",
"Failed to get image for Place_Type option");
-- begin read only
end Test_7_Option_Image_test_option_image_place_type;
-- end read only
-- begin read only
procedure Wrap_Test_Option_Image_509411_31f5ae
(Name: String; Value: Justify_Type;
Options_String: in out Unbounded_String) is
begin
begin
pragma Assert(Name'Length > 0);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"req_sloc(tk-widget.ads:0):Test_Option_Image_Justify_Type test requirement violated");
end;
GNATtest_Generated.GNATtest_Standard.Tk.Widget.Option_Image
(Name, Value, Options_String);
begin
pragma Assert(True);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"ens_sloc(tk-widget.ads:0:):Test_Option_Image_Justify_Type test commitment violated");
end;
end Wrap_Test_Option_Image_509411_31f5ae;
-- end read only
-- begin read only
procedure Test_8_Option_Image_test_option_image_justify_type
(Gnattest_T: in out Test);
procedure Test_Option_Image_509411_31f5ae(Gnattest_T: in out Test) renames
Test_8_Option_Image_test_option_image_justify_type;
-- id:2.2/509411649995311a/Option_Image/0/0/test_option_image_justify_type/
procedure Test_8_Option_Image_test_option_image_justify_type
(Gnattest_T: in out Test) is
procedure Option_Image
(Name: String; Value: Justify_Type;
Options_String: in out Unbounded_String) renames
Wrap_Test_Option_Image_509411_31f5ae;
-- end read only
pragma Unreferenced(Gnattest_T);
Options_String: Unbounded_String;
begin
Option_Image("myoption", Justify_Type'(CENTER), Options_String);
Assert
(To_String(Options_String) = " -myoption center",
"Failed to get image for Justify_Type option");
-- begin read only
end Test_8_Option_Image_test_option_image_justify_type;
-- end read only
-- begin read only
procedure Wrap_Test_Option_Image_8ca0c0_f0d5d6
(Name: String; Value: Horizontal_Pad_Data;
Options_String: in out Unbounded_String) is
begin
begin
pragma Assert(Name'Length > 0);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"req_sloc(tk-widget.ads:0):Test_Option_Image_Pad_Data test requirement violated");
end;
GNATtest_Generated.GNATtest_Standard.Tk.Widget.Option_Image
(Name, Value, Options_String);
begin
pragma Assert(True);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"ens_sloc(tk-widget.ads:0:):Test_Option_Image_Pad_Data test commitment violated");
end;
end Wrap_Test_Option_Image_8ca0c0_f0d5d6;
-- end read only
-- begin read only
procedure Test_9_Option_Image_test_option_image_pad_data
(Gnattest_T: in out Test);
procedure Test_Option_Image_8ca0c0_f0d5d6(Gnattest_T: in out Test) renames
Test_9_Option_Image_test_option_image_pad_data;
-- id:2.2/8ca0c0c7370eb476/Option_Image/0/0/test_option_image_pad_data/
procedure Test_9_Option_Image_test_option_image_pad_data
(Gnattest_T: in out Test) is
procedure Option_Image
(Name: String; Value: Horizontal_Pad_Data;
Options_String: in out Unbounded_String) renames
Wrap_Test_Option_Image_8ca0c0_f0d5d6;
-- end read only
pragma Unreferenced(Gnattest_T);
Options_String: Unbounded_String;
begin
Option_Image
("myoption", Horizontal_Pad_Data'((2.0, PIXEL), (5.0, PIXEL)),
Options_String);
Assert
(To_String(Options_String) = " -myoption {2.00 5.00}",
"Failed to get image for Horizontal_Pad_Array option");
-- begin read only
end Test_9_Option_Image_test_option_image_pad_data;
-- end read only
-- begin read only
procedure Wrap_Test_Option_Image_e74cc8_5d77f2
(Name: String; Value: Vertical_Pad_Data;
Options_String: in out Unbounded_String) is
begin
begin
pragma Assert(Name'Length > 0);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"req_sloc(tk-widget.ads:0):Test_Option_Image_Vertical_Pad_Data test requirement violated");
end;
GNATtest_Generated.GNATtest_Standard.Tk.Widget.Option_Image
(Name, Value, Options_String);
begin
pragma Assert(True);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"ens_sloc(tk-widget.ads:0:):Test_Option_Image_Vertical_Pad_Data test commitment violated");
end;
end Wrap_Test_Option_Image_e74cc8_5d77f2;
-- end read only
-- begin read only
procedure Test_10_Option_Image_test_option_image_vertical_pad_data
(Gnattest_T: in out Test);
procedure Test_Option_Image_e74cc8_5d77f2(Gnattest_T: in out Test) renames
Test_10_Option_Image_test_option_image_vertical_pad_data;
-- id:2.2/e74cc8ad175b0572/Option_Image/0/0/test_option_image_vertical_pad_data/
procedure Test_10_Option_Image_test_option_image_vertical_pad_data
(Gnattest_T: in out Test) is
procedure Option_Image
(Name: String; Value: Vertical_Pad_Data;
Options_String: in out Unbounded_String) renames
Wrap_Test_Option_Image_e74cc8_5d77f2;
-- end read only
pragma Unreferenced(Gnattest_T);
Options_String: Unbounded_String;
begin
Option_Image
("myoption2", Vertical_Pad_Data'((20.0, PIXEL), (15.0, PIXEL)),
Options_String);
Assert
(To_String(Options_String) = " -myoption2 {20.00 15.00}",
"Failed to get image for Vertical_Pad_Array option");
-- begin read only
end Test_10_Option_Image_test_option_image_vertical_pad_data;
-- end read only
-- begin read only
procedure Wrap_Test_Option_Image_22581b_a1b982
(Name: String; Value: Tk_Widget;
Options_String: in out Unbounded_String) is
begin
begin
pragma Assert(Name'Length > 0);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"req_sloc(tk-widget.ads:0):Test_Option_Image_Tk_Widget test requirement violated");
end;
GNATtest_Generated.GNATtest_Standard.Tk.Widget.Option_Image
(Name, Value, Options_String);
begin
pragma Assert(True);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"ens_sloc(tk-widget.ads:0:):Test_Option_Image_Tk_Widget test commitment violated");
end;
end Wrap_Test_Option_Image_22581b_a1b982;
-- end read only
-- begin read only
procedure Test_11_Option_Image_test_option_image_tk_widget
(Gnattest_T: in out Test);
procedure Test_Option_Image_22581b_a1b982(Gnattest_T: in out Test) renames
Test_11_Option_Image_test_option_image_tk_widget;
-- id:2.2/22581b562d182ab3/Option_Image/0/0/test_option_image_tk_widget/
procedure Test_11_Option_Image_test_option_image_tk_widget
(Gnattest_T: in out Test) is
procedure Option_Image
(Name: String; Value: Tk_Widget;
Options_String: in out Unbounded_String) renames
Wrap_Test_Option_Image_22581b_a1b982;
-- end read only
pragma Unreferenced(Gnattest_T);
Button: Tk_Button;
Options_String: Unbounded_String;
begin
if Value("DISPLAY", "")'Length = 0 then
Assert(True, "No display, can't test");
return;
end if;
Create(Button, ".mybutton", Button_Options'(others => <>));
Add(Button);
Tcl_Eval("update");
Option_Image("myoption", Button, Options_String);
Assert
(To_String(Options_String) = " -myoption .mybutton",
"Failed to get image for Tk_Widget option");
Destroy(Button);
-- begin read only
end Test_11_Option_Image_test_option_image_tk_widget;
-- end read only
-- begin read only
procedure Wrap_Test_Option_Image_08d32e_f8251b
(Name: String; Value: Extended_Boolean;
Options_String: in out Unbounded_String) is
begin
begin
pragma Assert(Name'Length > 0);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"req_sloc(tk-widget.ads:0):Test_Option_Image_Extended_Boolean test requirement violated");
end;
GNATtest_Generated.GNATtest_Standard.Tk.Widget.Option_Image
(Name, Value, Options_String);
begin
pragma Assert(True);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"ens_sloc(tk-widget.ads:0:):Test_Option_Image_Extended_Boolean test commitment violated");
end;
end Wrap_Test_Option_Image_08d32e_f8251b;
-- end read only
-- begin read only
procedure Test_12_Option_Image_test_option_image_extended_boolean
(Gnattest_T: in out Test);
procedure Test_Option_Image_08d32e_f8251b(Gnattest_T: in out Test) renames
Test_12_Option_Image_test_option_image_extended_boolean;
-- id:2.2/08d32e5f47f51d1d/Option_Image/0/0/test_option_image_extended_boolean/
procedure Test_12_Option_Image_test_option_image_extended_boolean
(Gnattest_T: in out Test) is
procedure Option_Image
(Name: String; Value: Extended_Boolean;
Options_String: in out Unbounded_String) renames
Wrap_Test_Option_Image_08d32e_f8251b;
-- end read only
pragma Unreferenced(Gnattest_T);
Options_String: Unbounded_String;
begin
Option_Image("myoption", Extended_Boolean'(TRUE), Options_String);
Assert
(To_String(Options_String) = " -myoption 1",
"Failed to get image for Extended_Boolean option");
-- begin read only
end Test_12_Option_Image_test_option_image_extended_boolean;
-- end read only
-- begin read only
procedure Wrap_Test_Option_Image_5269f4_fb7043
(Name: String; Value: Tk_Window;
Options_String: in out Unbounded_String) is
begin
begin
pragma Assert(Name'Length > 0);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"req_sloc(tk-widget.ads:0):Test_Option_Image_Tk_Window test requirement violated");
end;
GNATtest_Generated.GNATtest_Standard.Tk.Widget.Option_Image
(Name, Value, Options_String);
begin
pragma Assert(True);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"ens_sloc(tk-widget.ads:0:):Test_Option_Image_Tk_Window test commitment violated");
end;
end Wrap_Test_Option_Image_5269f4_fb7043;
-- end read only
-- begin read only
procedure Test_13_Option_Image_test_option_image_tk_window
(Gnattest_T: in out Test);
procedure Test_Option_Image_5269f4_fb7043(Gnattest_T: in out Test) renames
Test_13_Option_Image_test_option_image_tk_window;
-- id:2.2/5269f46f63b9ac48/Option_Image/0/0/test_option_image_tk_window/
procedure Test_13_Option_Image_test_option_image_tk_window
(Gnattest_T: in out Test) is
procedure Option_Image
(Name: String; Value: Tk_Window;
Options_String: in out Unbounded_String) renames
Wrap_Test_Option_Image_5269f4_fb7043;
-- end read only
pragma Unreferenced(Gnattest_T);
Button: Tk_Button;
Options_String: Unbounded_String;
begin
if Value("DISPLAY", "")'Length = 0 then
Assert(True, "No display, can't test");
return;
end if;
Create(Button, ".mybutton", Button_Options'(others => <>));
Add(Button);
Tcl_Eval("update");
Option_Image("myoption", Tk_Window_Id(Button), Options_String);
Tcl_Eval("winfo id .mybutton");
Assert
(To_String(Options_String) = " -myoption " & Tcl_Get_Result,
"Failed to get image for Tk_Widget option");
Destroy(Button);
-- begin read only
end Test_13_Option_Image_test_option_image_tk_window;
-- end read only
-- begin read only
procedure Wrap_Test_Option_Image_183a44_55069e
(Name: String; Value: Anchor_Directions;
Options_String: in out Unbounded_String) is
begin
begin
pragma Assert(Name'Length > 0);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"req_sloc(tk-widget.ads:0):Test_Option_Image_Anchor_Directions test requirement violated");
end;
GNATtest_Generated.GNATtest_Standard.Tk.Widget.Option_Image
(Name, Value, Options_String);
begin
pragma Assert(True);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"ens_sloc(tk-widget.ads:0:):Test_Option_Image_Anchor_Directions test commitment violated");
end;
end Wrap_Test_Option_Image_183a44_55069e;
-- end read only
-- begin read only
procedure Test_14_Option_Image_test_option_image_anchor_directions
(Gnattest_T: in out Test);
procedure Test_Option_Image_183a44_55069e(Gnattest_T: in out Test) renames
Test_14_Option_Image_test_option_image_anchor_directions;
-- id:2.2/183a44bf51805f78/Option_Image/0/0/test_option_image_anchor_directions/
procedure Test_14_Option_Image_test_option_image_anchor_directions
(Gnattest_T: in out Test) is
procedure Option_Image
(Name: String; Value: Anchor_Directions;
Options_String: in out Unbounded_String) renames
Wrap_Test_Option_Image_183a44_55069e;
-- end read only
pragma Unreferenced(Gnattest_T);
Options_String: Unbounded_String;
begin
Option_Image("myoption", WN, Options_String);
Assert
(To_String(Options_String) = " -myoption wn",
"Failed to get image for Anchor_Directions option");
-- begin read only
end Test_14_Option_Image_test_option_image_anchor_directions;
-- end read only
-- begin read only
procedure Wrap_Test_Option_Image_2254d6_97b6c7
(Name: String; Value: Positive_Float;
Options_String: in out Unbounded_String) is
begin
begin
pragma Assert(Name'Length > 0);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"req_sloc(tk-widget.ads:0):Test_Option_Image_Positive_Float test requirement violated");
end;
GNATtest_Generated.GNATtest_Standard.Tk.Widget.Option_Image
(Name, Value, Options_String);
begin
pragma Assert(True);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"ens_sloc(tk-widget.ads:0:):Test_Option_Image_Positive_Float test commitment violated");
end;
end Wrap_Test_Option_Image_2254d6_97b6c7;
-- end read only
-- begin read only
procedure Test_15_Option_Image_test_option_image_positive_float
(Gnattest_T: in out Test);
procedure Test_Option_Image_2254d6_97b6c7(Gnattest_T: in out Test) renames
Test_15_Option_Image_test_option_image_positive_float;
-- id:2.2/2254d657bca7a12e/Option_Image/0/0/test_option_image_positive_float/
procedure Test_15_Option_Image_test_option_image_positive_float
(Gnattest_T: in out Test) is
procedure Option_Image
(Name: String; Value: Positive_Float;
Options_String: in out Unbounded_String) renames
Wrap_Test_Option_Image_2254d6_97b6c7;
-- end read only
pragma Unreferenced(Gnattest_T);
Options_String: Unbounded_String;
begin
Option_Image("myoption", Positive_Float(10.0), Options_String);
Assert
(To_String(Options_String) = " -myoption 10.00",
"Failed to get image for Positive_Float option");
-- begin read only
end Test_15_Option_Image_test_option_image_positive_float;
-- end read only
-- begin read only
procedure Wrap_Test_Option_Image_e3c074_1ae135
(Name: String; Value: Point_Position;
Options_String: in out Unbounded_String) is
begin
begin
pragma Assert(Name'Length > 0);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"req_sloc(tk-widget.ads:0):Test_Option_Image_Point_Position test requirement violated");
end;
GNATtest_Generated.GNATtest_Standard.Tk.Widget.Option_Image
(Name, Value, Options_String);
begin
pragma Assert(True);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"ens_sloc(tk-widget.ads:0:):Test_Option_Image_Point_Position test commitment violated");
end;
end Wrap_Test_Option_Image_e3c074_1ae135;
-- end read only
-- begin read only
procedure Test_16_Option_Image_test_option_image_point_position
(Gnattest_T: in out Test);
procedure Test_Option_Image_e3c074_1ae135(Gnattest_T: in out Test) renames
Test_16_Option_Image_test_option_image_point_position;
-- id:2.2/e3c0749de0cd7904/Option_Image/0/0/test_option_image_point_position/
procedure Test_16_Option_Image_test_option_image_point_position
(Gnattest_T: in out Test) is
procedure Option_Image
(Name: String; Value: Point_Position;
Options_String: in out Unbounded_String) renames
Wrap_Test_Option_Image_e3c074_1ae135;
-- end read only
pragma Unreferenced(Gnattest_T);
Options_String: Unbounded_String;
begin
Option_Image("myoption", Point_Position'(5, 10), Options_String);
Assert
(To_String(Options_String) = " -myoption 5 10",
"Failed to get image for Point_Position option");
-- begin read only
end Test_16_Option_Image_test_option_image_point_position;
-- end read only
-- begin read only
procedure Wrap_Test_Option_Image_7332d0_b72ca9
(Name: String; Value: Boolean; Options_String: in out Unbounded_String) is
begin
begin
pragma Assert(Name'Length > 0);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"req_sloc(tk-widget.ads:0):Test_Option_Image_Boolean test requirement violated");
end;
GNATtest_Generated.GNATtest_Standard.Tk.Widget.Option_Image
(Name, Value, Options_String);
begin
pragma Assert(True);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"ens_sloc(tk-widget.ads:0:):Test_Option_Image_Boolean test commitment violated");
end;
end Wrap_Test_Option_Image_7332d0_b72ca9;
-- end read only
-- begin read only
procedure Test_17_Option_Image_test_option_image_boolean
(Gnattest_T: in out Test);
procedure Test_Option_Image_7332d0_b72ca9(Gnattest_T: in out Test) renames
Test_17_Option_Image_test_option_image_boolean;
-- id:2.2/7332d0be2739d19f/Option_Image/0/0/test_option_image_boolean/
procedure Test_17_Option_Image_test_option_image_boolean
(Gnattest_T: in out Test) is
procedure Option_Image
(Name: String; Value: Boolean;
Options_String: in out Unbounded_String) renames
Wrap_Test_Option_Image_7332d0_b72ca9;
-- end read only
pragma Unreferenced(Gnattest_T);
Options_String: Unbounded_String;
begin
Option_Image("myoption", Boolean'(True), Options_String);
Assert
(To_String(Options_String) = " -myoption",
"Failed to get image for Boolean option");
-- begin read only
end Test_17_Option_Image_test_option_image_boolean;
-- end read only
-- begin read only
procedure Wrap_Test_Option_Image_e5f273_81a16f
(Name: String; Value: Integer; Options_String: in out Unbounded_String;
Base: Positive := 10) is
begin
begin
pragma Assert(Name'Length > 0 and Base in 10 | 16);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"req_sloc(tk-widget.ads:0):Test_Option_Image_Integer test requirement violated");
end;
GNATtest_Generated.GNATtest_Standard.Tk.Widget.Option_Image
(Name, Value, Options_String, Base);
begin
pragma Assert(True);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"ens_sloc(tk-widget.ads:0:):Test_Option_Image_Integer test commitment violated");
end;
end Wrap_Test_Option_Image_e5f273_81a16f;
-- end read only
-- begin read only
procedure Test_18_Option_Image_test_option_image_integer
(Gnattest_T: in out Test);
procedure Test_Option_Image_e5f273_81a16f(Gnattest_T: in out Test) renames
Test_18_Option_Image_test_option_image_integer;
-- id:2.2/e5f273869df45ad5/Option_Image/0/0/test_option_image_integer/
procedure Test_18_Option_Image_test_option_image_integer
(Gnattest_T: in out Test) is
procedure Option_Image
(Name: String; Value: Integer; Options_String: in out Unbounded_String;
Base: Positive := 10) renames
Wrap_Test_Option_Image_e5f273_81a16f;
-- end read only
pragma Unreferenced(Gnattest_T);
Options_String: Unbounded_String;
begin
Option_Image("myoption", Integer(10), Options_String);
Assert
(To_String(Options_String) = " -myoption 10",
"Failed to get image for Integer option");
-- begin read only
end Test_18_Option_Image_test_option_image_integer;
-- end read only
-- begin read only
function Wrap_Test_Option_Value_7653ac_8290b8
(Widgt: Tk_Widget; Name: String) return Tcl_String is
begin
begin
pragma Assert(Widgt /= Null_Widget and Name'Length > 0);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"req_sloc(tk-widget.ads:0):Test_Option_Value_Tcl_String test requirement violated");
end;
declare
Test_Option_Value_7653ac_8290b8_Result: constant Tcl_String :=
GNATtest_Generated.GNATtest_Standard.Tk.Widget.Option_Value
(Widgt, Name);
begin
begin
pragma Assert(True);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"ens_sloc(tk-widget.ads:0:):Test_Option_Value_Tcl_String test commitment violated");
end;
return Test_Option_Value_7653ac_8290b8_Result;
end;
end Wrap_Test_Option_Value_7653ac_8290b8;
-- end read only
-- begin read only
procedure Test_1_Option_Value_test_option_value_tcl_string
(Gnattest_T: in out Test);
procedure Test_Option_Value_7653ac_8290b8(Gnattest_T: in out Test) renames
Test_1_Option_Value_test_option_value_tcl_string;
-- id:2.2/7653ac7cbd9fae0e/Option_Value/1/0/test_option_value_tcl_string/
procedure Test_1_Option_Value_test_option_value_tcl_string
(Gnattest_T: in out Test) is
function Option_Value
(Widgt: Tk_Widget; Name: String) return Tcl_String renames
Wrap_Test_Option_Value_7653ac_8290b8;
-- end read only
pragma Unreferenced(Gnattest_T);
Result: Tcl_String;
Button: Tk_Button;
begin
if Value("DISPLAY", "")'Length = 0 then
Assert(True, "No display, can't test");
return;
end if;
Create
(Button, ".mybutton",
Button_Options'(Text => To_Tcl_String("Test"), others => <>));
Add(Button);
Tcl_Eval("update");
Result := Option_Value(Button, "text");
Assert
(Result = To_Tcl_String("Test"),
"Failed to get value for Tcl_String widget option");
Destroy(Button);
-- begin read only
end Test_1_Option_Value_test_option_value_tcl_string;
-- end read only
-- begin read only
function Wrap_Test_Option_Value_233bf0_aec4d0
(Widgt: Tk_Widget; Name: String) return Directions_Type is
begin
begin
pragma Assert(Widgt /= Null_Widget and Name'Length > 0);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"req_sloc(tk-widget.ads:0):Test_Option_Value_Direction_Type test requirement violated");
end;
declare
Test_Option_Value_233bf0_aec4d0_Result: constant Directions_Type :=
GNATtest_Generated.GNATtest_Standard.Tk.Widget.Option_Value
(Widgt, Name);
begin
begin
pragma Assert(True);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"ens_sloc(tk-widget.ads:0:):Test_Option_Value_Direction_Type test commitment violated");
end;
return Test_Option_Value_233bf0_aec4d0_Result;
end;
end Wrap_Test_Option_Value_233bf0_aec4d0;
-- end read only
-- begin read only
procedure Test_2_Option_Value_test_option_value_direction_type
(Gnattest_T: in out Test);
procedure Test_Option_Value_233bf0_aec4d0(Gnattest_T: in out Test) renames
Test_2_Option_Value_test_option_value_direction_type;
-- id:2.2/233bf0449cc91e05/Option_Value/0/0/test_option_value_direction_type/
procedure Test_2_Option_Value_test_option_value_direction_type
(Gnattest_T: in out Test) is
function Option_Value
(Widgt: Tk_Widget; Name: String) return Directions_Type renames
Wrap_Test_Option_Value_233bf0_aec4d0;
-- end read only
pragma Unreferenced(Gnattest_T);
Button: Tk_Button;
Result: Directions_Type;
Label: Ttk_Label;
begin
if Value("DISPLAY", "")'Length = 0 then
Assert(True, "No display, can't test");
return;
end if;
Create(Button, ".mybutton", Button_Options'(Anchor => N, others => <>));
Add(Button);
Tcl_Eval("update");
Result := Option_Value(Button, "anchor");
Assert
(Result = N, "Failed to get value for Directions_Type widget option");
Destroy(Button);
Create(Label, ".mylabel", Ttk_Label_Options'(others => <>));
Result := Option_Value(Label, "anchor");
Assert
(Result = NONE,
"Failed to get empty value for Directions_Type widget option");
Destroy(Label);
-- begin read only
end Test_2_Option_Value_test_option_value_direction_type;
-- end read only
-- begin read only
function Wrap_Test_Option_Value_5928a5_91f6f6
(Widgt: Tk_Widget; Name: String) return Pixel_Data is
begin
begin
pragma Assert(Widgt /= Null_Widget and Name'Length > 0);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"req_sloc(tk-widget.ads:0):Test_Option_Value_Pixel_Data test requirement violated");
end;
declare
Test_Option_Value_5928a5_91f6f6_Result: constant Pixel_Data :=
GNATtest_Generated.GNATtest_Standard.Tk.Widget.Option_Value
(Widgt, Name);
begin
begin
pragma Assert(True);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"ens_sloc(tk-widget.ads:0:):Test_Option_Value_Pixel_Data test commitment violated");
end;
return Test_Option_Value_5928a5_91f6f6_Result;
end;
end Wrap_Test_Option_Value_5928a5_91f6f6;
-- end read only
-- begin read only
procedure Test_3_Option_Value_test_option_value_pixel_data
(Gnattest_T: in out Test);
procedure Test_Option_Value_5928a5_91f6f6(Gnattest_T: in out Test) renames
Test_3_Option_Value_test_option_value_pixel_data;
-- id:2.2/5928a584ab6c8004/Option_Value/0/0/test_option_value_pixel_data/
procedure Test_3_Option_Value_test_option_value_pixel_data
(Gnattest_T: in out Test) is
function Option_Value
(Widgt: Tk_Widget; Name: String) return Pixel_Data renames
Wrap_Test_Option_Value_5928a5_91f6f6;
-- end read only
pragma Unreferenced(Gnattest_T);
Button: Tk_Button;
Result: Pixel_Data;
begin
if Value("DISPLAY", "")'Length = 0 then
Assert(True, "No display, can't test");
return;
end if;
Create
(Button, ".mybutton",
Button_Options'(Border_Width => (2.0, PIXEL), others => <>));
Add(Button);
Tcl_Eval("update");
Result := Option_Value(Button, "borderwidth");
Assert
(Result = (2.0, PIXEL),
"Failed to get value for Pixel_Data widget option");
Destroy(Button);
-- begin read only
end Test_3_Option_Value_test_option_value_pixel_data;
-- end read only
-- begin read only
function Wrap_Test_Option_Value_28b181_505a65
(Widgt: Tk_Widget; Name: String) return Place_Type is
begin
begin
pragma Assert(Widgt /= Null_Widget and Name'Length > 0);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"req_sloc(tk-widget.ads:0):Test_Option_Value_Place_Type test requirement violated");
end;
declare
Test_Option_Value_28b181_505a65_Result: constant Place_Type :=
GNATtest_Generated.GNATtest_Standard.Tk.Widget.Option_Value
(Widgt, Name);
begin
begin
pragma Assert(True);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"ens_sloc(tk-widget.ads:0:):Test_Option_Value_Place_Type test commitment violated");
end;
return Test_Option_Value_28b181_505a65_Result;
end;
end Wrap_Test_Option_Value_28b181_505a65;
-- end read only
-- begin read only
procedure Test_4_Option_Value_test_option_value_place_type
(Gnattest_T: in out Test);
procedure Test_Option_Value_28b181_505a65(Gnattest_T: in out Test) renames
Test_4_Option_Value_test_option_value_place_type;
-- id:2.2/28b1817b22e294d8/Option_Value/0/0/test_option_value_place_type/
procedure Test_4_Option_Value_test_option_value_place_type
(Gnattest_T: in out Test) is
function Option_Value
(Widgt: Tk_Widget; Name: String) return Place_Type renames
Wrap_Test_Option_Value_28b181_505a65;
-- end read only
pragma Unreferenced(Gnattest_T);
Button: Tk_Button;
Result: Place_Type;
begin
if Value("DISPLAY", "")'Length = 0 then
Assert(True, "No display, can't test");
return;
end if;
Create
(Button, ".mybutton",
Button_Options'(Compound => BOTTOM, others => <>));
Add(Button);
Tcl_Eval("update");
Result := Option_Value(Button, "compound");
Assert
(Result = BOTTOM, "Failed to get value for Place_Type widget option");
Destroy(Button);
-- begin read only
end Test_4_Option_Value_test_option_value_place_type;
-- end read only
-- begin read only
function Wrap_Test_Option_Value_f5b002_a22b94
(Widgt: Tk_Widget; Name: String) return State_Type is
begin
begin
pragma Assert(Widgt /= Null_Widget and Name'Length > 0);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"req_sloc(tk-widget.ads:0):Test_Option_Value_State_Type test requirement violated");
end;
declare
Test_Option_Value_f5b002_a22b94_Result: constant State_Type :=
GNATtest_Generated.GNATtest_Standard.Tk.Widget.Option_Value
(Widgt, Name);
begin
begin
pragma Assert(True);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"ens_sloc(tk-widget.ads:0:):Test_Option_Value_State_Type test commitment violated");
end;
return Test_Option_Value_f5b002_a22b94_Result;
end;
end Wrap_Test_Option_Value_f5b002_a22b94;
-- end read only
-- begin read only
procedure Test_5_Option_Value_test_option_value_state_type
(Gnattest_T: in out Test);
procedure Test_Option_Value_f5b002_a22b94(Gnattest_T: in out Test) renames
Test_5_Option_Value_test_option_value_state_type;
-- id:2.2/f5b002d7d9b49b26/Option_Value/0/0/test_option_value_state_type/
procedure Test_5_Option_Value_test_option_value_state_type
(Gnattest_T: in out Test) is
function Option_Value
(Widgt: Tk_Widget; Name: String) return State_Type renames
Wrap_Test_Option_Value_f5b002_a22b94;
-- end read only
pragma Unreferenced(Gnattest_T);
Button: Tk_Button;
Result: State_Type;
begin
if Value("DISPLAY", "")'Length = 0 then
Assert(True, "No display, can't test");
return;
end if;
Create
(Button, ".mybutton",
Button_Options'(Default => ACTIVE, others => <>));
Add(Button);
Tcl_Eval("update");
Result := Option_Value(Button, "default");
Assert
(Result = ACTIVE, "Failed to get value for State_Type widget option");
Destroy(Button);
-- begin read only
end Test_5_Option_Value_test_option_value_state_type;
-- end read only
-- begin read only
function Wrap_Test_Option_Value_0d429d_011a37
(Widgt: Tk_Widget; Name: String) return Justify_Type is
begin
begin
pragma Assert(Widgt /= Null_Widget and Name'Length > 0);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"req_sloc(tk-widget.ads:0):Test_Option_Value_Justify_Type test requirement violated");
end;
declare
Test_Option_Value_0d429d_011a37_Result: constant Justify_Type :=
GNATtest_Generated.GNATtest_Standard.Tk.Widget.Option_Value
(Widgt, Name);
begin
begin
pragma Assert(True);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"ens_sloc(tk-widget.ads:0:):Test_Option_Value_Justify_Type test commitment violated");
end;
return Test_Option_Value_0d429d_011a37_Result;
end;
end Wrap_Test_Option_Value_0d429d_011a37;
-- end read only
-- begin read only
procedure Test_6_Option_Value_test_option_value_justify_type
(Gnattest_T: in out Test);
procedure Test_Option_Value_0d429d_011a37(Gnattest_T: in out Test) renames
Test_6_Option_Value_test_option_value_justify_type;
-- id:2.2/0d429d825d130717/Option_Value/0/0/test_option_value_justify_type/
procedure Test_6_Option_Value_test_option_value_justify_type
(Gnattest_T: in out Test) is
function Option_Value
(Widgt: Tk_Widget; Name: String) return Justify_Type renames
Wrap_Test_Option_Value_0d429d_011a37;
-- end read only
pragma Unreferenced(Gnattest_T);
Button: Tk_Button;
Result: Justify_Type;
Label: Ttk_Label;
begin
if Value("DISPLAY", "")'Length = 0 then
Assert(True, "No display, can't test");
return;
end if;
Create
(Button, ".mybutton",
Button_Options'(Justify => CENTER, others => <>));
Add(Button);
Tcl_Eval("update");
Result := Option_Value(Button, "justify");
Assert
(Result = CENTER,
"Failed to get value for Justify_Type widget option");
Destroy(Button);
Create(Label, ".mylabel", Ttk_Label_Options'(others => <>));
Result := Option_Value(Label, "anchor");
Assert
(Result = NONE,
"Failed to get empty value for Justify_Type widget option");
Destroy(Label);
-- begin read only
end Test_6_Option_Value_test_option_value_justify_type;
-- end read only
-- begin read only
function Wrap_Test_Option_Value_433a71_606e95
(Widgt: Tk_Widget; Name: String) return Relief_Type is
begin
begin
pragma Assert(Widgt /= Null_Widget and Name'Length > 0);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"req_sloc(tk-widget.ads:0):Test_Option_Value_Relief_Type test requirement violated");
end;
declare
Test_Option_Value_433a71_606e95_Result: constant Relief_Type :=
GNATtest_Generated.GNATtest_Standard.Tk.Widget.Option_Value
(Widgt, Name);
begin
begin
pragma Assert(True);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"ens_sloc(tk-widget.ads:0:):Test_Option_Value_Relief_Type test commitment violated");
end;
return Test_Option_Value_433a71_606e95_Result;
end;
end Wrap_Test_Option_Value_433a71_606e95;
-- end read only
-- begin read only
procedure Test_7_Option_Value_test_option_value_relief_type
(Gnattest_T: in out Test);
procedure Test_Option_Value_433a71_606e95(Gnattest_T: in out Test) renames
Test_7_Option_Value_test_option_value_relief_type;
-- id:2.2/433a71288d1580d9/Option_Value/0/0/test_option_value_relief_type/
procedure Test_7_Option_Value_test_option_value_relief_type
(Gnattest_T: in out Test) is
function Option_Value
(Widgt: Tk_Widget; Name: String) return Relief_Type renames
Wrap_Test_Option_Value_433a71_606e95;
-- end read only
pragma Unreferenced(Gnattest_T);
Button: Tk_Button;
Result: Relief_Type;
begin
if Value("DISPLAY", "")'Length = 0 then
Assert(True, "No display, can't test");
return;
end if;
Create
(Button, ".mybutton", Button_Options'(Relief => RAISED, others => <>));
Add(Button);
Tcl_Eval("update");
Assert
(Option_Value(Button, "relief") = RAISED,
"Failed to get value for Relief_Type widget option");
Assert
(Option_Value(Button, "overrelief") = Relief_Type'(NONE),
"Failed to get value for empty Relief_Type widget option");
Destroy(Button);
-- begin read only
end Test_7_Option_Value_test_option_value_relief_type;
-- end read only
-- begin read only
function Wrap_Test_Option_Value_c23604_f3a6bc
(Widgt: Tk_Widget; Name: String) return Extended_Natural is
begin
begin
pragma Assert(Widgt /= Null_Widget and Name'Length > 0);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"req_sloc(tk-widget.ads:0):Test_Option_Value_Extended_Natural test requirement violated");
end;
declare
Test_Option_Value_c23604_f3a6bc_Result: constant Extended_Natural :=
GNATtest_Generated.GNATtest_Standard.Tk.Widget.Option_Value
(Widgt, Name);
begin
begin
pragma Assert(True);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"ens_sloc(tk-widget.ads:0:):Test_Option_Value_Extended_Natural test commitment violated");
end;
return Test_Option_Value_c23604_f3a6bc_Result;
end;
end Wrap_Test_Option_Value_c23604_f3a6bc;
-- end read only
-- begin read only
procedure Test_8_Option_Value_test_option_value_extended_natural
(Gnattest_T: in out Test);
procedure Test_Option_Value_c23604_f3a6bc(Gnattest_T: in out Test) renames
Test_8_Option_Value_test_option_value_extended_natural;
-- id:2.2/c2360441dc017b3b/Option_Value/0/0/test_option_value_extended_natural/
procedure Test_8_Option_Value_test_option_value_extended_natural
(Gnattest_T: in out Test) is
function Option_Value
(Widgt: Tk_Widget; Name: String) return Extended_Natural renames
Wrap_Test_Option_Value_c23604_f3a6bc;
-- end read only
pragma Unreferenced(Gnattest_T);
Button: Tk_Button;
Result: Extended_Natural;
Label: Ttk_Label;
begin
if Value("DISPLAY", "")'Length = 0 then
Assert(True, "No display, can't test");
return;
end if;
Create
(Button, ".mybutton",
Button_Options'(Repeat_Delay => 10, others => <>));
Add(Button);
Tcl_Eval("update");
Result := Option_Value(Button, "repeatdelay");
Assert
(Result = 10,
"Failed to get value for Extended_Natural widget option");
Destroy(Button);
Create(Label, ".mylabel", Ttk_Label_Options'(others => <>));
Result := Option_Value(Label, "wraplength");
Assert
(Result = -1,
"Failed to get value for empty Extended_Natural widget option");
Destroy(Label);
-- begin read only
end Test_8_Option_Value_test_option_value_extended_natural;
-- end read only
-- begin read only
function Wrap_Test_Option_Value_4261cf_d0c79a
(Widgt: Tk_Widget; Name: String) return Extended_Boolean is
begin
begin
pragma Assert(Widgt /= Null_Widget and Name'Length > 0);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"req_sloc(tk-widget.ads:0):Test_Option_Value_Extended_Boolean test requirement violated");
end;
declare
Test_Option_Value_4261cf_d0c79a_Result: constant Extended_Boolean :=
GNATtest_Generated.GNATtest_Standard.Tk.Widget.Option_Value
(Widgt, Name);
begin
begin
pragma Assert(True);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"ens_sloc(tk-widget.ads:0:):Test_Option_Value_Extended_Boolean test commitment violated");
end;
return Test_Option_Value_4261cf_d0c79a_Result;
end;
end Wrap_Test_Option_Value_4261cf_d0c79a;
-- end read only
-- begin read only
procedure Test_9_Option_Value_test_option_value_extended_boolean
(Gnattest_T: in out Test);
procedure Test_Option_Value_4261cf_d0c79a(Gnattest_T: in out Test) renames
Test_9_Option_Value_test_option_value_extended_boolean;
-- id:2.2/4261cff0a1c9a280/Option_Value/0/0/test_option_value_extended_boolean/
procedure Test_9_Option_Value_test_option_value_extended_boolean
(Gnattest_T: in out Test) is
function Option_Value
(Widgt: Tk_Widget; Name: String) return Extended_Boolean renames
Wrap_Test_Option_Value_4261cf_d0c79a;
-- end read only
pragma Unreferenced(Gnattest_T);
Widget: Tk_Toplevel;
Result: Extended_Boolean;
begin
if Value("DISPLAY", "")'Length = 0 then
Assert(True, "No display, can't test");
return;
end if;
Create
(Widget, ".mydialog",
Toplevel_Create_Options'(Container => TRUE, others => <>));
Tcl_Eval("update");
Result := Option_Value(Widget, "container");
Assert
(Result = True,
"Failed to get value for Extended_Boolean widget option");
Destroy(Widget);
-- begin read only
end Test_9_Option_Value_test_option_value_extended_boolean;
-- end read only
-- begin read only
function Wrap_Test_Option_Value_6c79cd_4a4c5a
(Widgt: Tk_Widget; Name: String) return Tk_Widget is
begin
begin
pragma Assert(Widgt /= Null_Widget and Name'Length > 0);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"req_sloc(tk-widget.ads:0):Test_Option_Value_Tk_Widget test requirement violated");
end;
declare
Test_Option_Value_6c79cd_4a4c5a_Result: constant Tk_Widget :=
GNATtest_Generated.GNATtest_Standard.Tk.Widget.Option_Value
(Widgt, Name);
begin
begin
pragma Assert(True);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"ens_sloc(tk-widget.ads:0:):Test_Option_Value_Tk_Widget test commitment violated");
end;
return Test_Option_Value_6c79cd_4a4c5a_Result;
end;
end Wrap_Test_Option_Value_6c79cd_4a4c5a;
-- end read only
-- begin read only
procedure Test_10_Option_Value_test_option_value_tk_widget
(Gnattest_T: in out Test);
procedure Test_Option_Value_6c79cd_4a4c5a(Gnattest_T: in out Test) renames
Test_10_Option_Value_test_option_value_tk_widget;
-- id:2.2/6c79cde7e8b52cd2/Option_Value/0/0/test_option_value_tk_widget/
procedure Test_10_Option_Value_test_option_value_tk_widget
(Gnattest_T: in out Test) is
function Option_Value
(Widgt: Tk_Widget; Name: String) return Tk_Widget renames
Wrap_Test_Option_Value_6c79cd_4a4c5a;
-- end read only
pragma Unreferenced(Gnattest_T);
Widget: Tk_Toplevel;
Menu: Tk_Menu;
Result: Tk_Widget;
begin
if Value("DISPLAY", "")'Length = 0 then
Assert(True, "No display, can't test");
return;
end if;
Create(Menu, ".mymenu", Menu_Options'(others => <>));
Create
(Widget, ".mydialog",
Toplevel_Create_Options'(Menu => Menu, others => <>));
Tcl_Eval("update");
Result := Option_Value(Widget, "menu");
Assert(Result = Menu, "Failed to get value for Tk_Widget widget option");
Destroy(Widget);
Destroy(Menu);
-- begin read only
end Test_10_Option_Value_test_option_value_tk_widget;
-- end read only
-- begin read only
function Wrap_Test_Option_Value_eba58c_c374e8
(Widgt: Tk_Widget; Name: String) return Tk_Window is
begin
begin
pragma Assert(Widgt /= Null_Widget and Name'Length > 0);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"req_sloc(tk-widget.ads:0):Test_Option_Value_Tk_Window test requirement violated");
end;
declare
Test_Option_Value_eba58c_c374e8_Result: constant Tk_Window :=
GNATtest_Generated.GNATtest_Standard.Tk.Widget.Option_Value
(Widgt, Name);
begin
begin
pragma Assert(True);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"ens_sloc(tk-widget.ads:0:):Test_Option_Value_Tk_Window test commitment violated");
end;
return Test_Option_Value_eba58c_c374e8_Result;
end;
end Wrap_Test_Option_Value_eba58c_c374e8;
-- end read only
-- begin read only
procedure Test_11_Option_Value_test_option_value_tk_window
(Gnattest_T: in out Test);
procedure Test_Option_Value_eba58c_c374e8(Gnattest_T: in out Test) renames
Test_11_Option_Value_test_option_value_tk_window;
-- id:2.2/eba58cc5c22700dd/Option_Value/0/0/test_option_value_tk_window/
procedure Test_11_Option_Value_test_option_value_tk_window
(Gnattest_T: in out Test) is
function Option_Value
(Widgt: Tk_Widget; Name: String) return Tk_Window renames
Wrap_Test_Option_Value_eba58c_c374e8;
-- end read only
pragma Unreferenced(Gnattest_T);
TopWidget, ChildWidget: Tk_Toplevel;
Result: Tk_Window;
begin
if Value("DISPLAY", "")'Length = 0 then
Assert(True, "No display, can't test");
return;
end if;
Create
(TopWidget, ".mydialog",
Toplevel_Create_Options'(Container => TRUE, others => <>));
Tcl_Eval("update");
Create
(ChildWidget, ".mychild",
Toplevel_Create_Options'
(Use_Container => Tk_Window_Id(TopWidget), others => <>));
Result := Option_Value(ChildWidget, "use");
Assert
(Result = Tk_Window_Id(TopWidget),
"Failed to get value for Tk_Window widget option");
Destroy(TopWidget);
Create(TopWidget, ".mydialog", Toplevel_Create_Options'(others => <>));
Assert
(Option_Value(TopWidget, "use") = Null_Window,
"Failed to get empty value for Tk_Window widget option");
Destroy(TopWidget);
Destroy(ChildWidget);
-- begin read only
end Test_11_Option_Value_test_option_value_tk_window;
-- end read only
-- begin read only
function Wrap_Test_Option_Value_f2311c_69e413
(Widgt: Tk_Widget; Name: String) return Integer is
begin
begin
pragma Assert(Widgt /= Null_Widget and Name'Length > 0);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"req_sloc(tk-widget.ads:0):Test_Option_Value_Integer test requirement violated");
end;
declare
Test_Option_Value_f2311c_69e413_Result: constant Integer :=
GNATtest_Generated.GNATtest_Standard.Tk.Widget.Option_Value
(Widgt, Name);
begin
begin
pragma Assert(True);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"ens_sloc(tk-widget.ads:0:):Test_Option_Value_Integer test commitment violated");
end;
return Test_Option_Value_f2311c_69e413_Result;
end;
end Wrap_Test_Option_Value_f2311c_69e413;
-- end read only
-- begin read only
procedure Test_12_Option_Value_test_option_value_integer
(Gnattest_T: in out Test);
procedure Test_Option_Value_f2311c_69e413(Gnattest_T: in out Test) renames
Test_12_Option_Value_test_option_value_integer;
-- id:2.2/f2311c8d530f5ad5/Option_Value/0/0/test_option_value_integer/
procedure Test_12_Option_Value_test_option_value_integer
(Gnattest_T: in out Test) is
function Option_Value
(Widgt: Tk_Widget; Name: String) return Integer renames
Wrap_Test_Option_Value_f2311c_69e413;
-- end read only
pragma Unreferenced(Gnattest_T);
Widget: Ttk_Button;
Result: Integer;
begin
if Value("DISPLAY", "")'Length = 0 then
Assert(True, "No display, can't test");
return;
end if;
Create(Widget, ".button", Default_Ttk_Button_Options);
Result := Option_Value(Widget, "width");
Assert
(Result = 0, "Failed to get empty value for Integer widget option");
Configure(Widget, Ttk_Button_Options'(Width => -15, others => <>));
Result := Option_Value(Widget, "width");
Assert(Result = -15, "Failed to get value for Integer widget option");
Destroy(Widget);
-- begin read only
end Test_12_Option_Value_test_option_value_integer;
-- end read only
-- begin read only
function Wrap_Test_Option_Value_54a47c_6cc903
(Widgt: Tk_Widget; Name: String) return Anchor_Directions is
begin
begin
pragma Assert(Widgt /= Null_Widget and Name'Length > 0);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"req_sloc(tk-widget.ads:0):Test_Option_Value_Anchor_Directions test requirement violated");
end;
declare
Test_Option_Value_54a47c_6cc903_Result: constant Anchor_Directions :=
GNATtest_Generated.GNATtest_Standard.Tk.Widget.Option_Value
(Widgt, Name);
begin
begin
pragma Assert(True);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"ens_sloc(tk-widget.ads:0:):Test_Option_Value_Anchor_Directions test commitment violated");
end;
return Test_Option_Value_54a47c_6cc903_Result;
end;
end Wrap_Test_Option_Value_54a47c_6cc903;
-- end read only
-- begin read only
procedure Test_13_Option_Value_test_option_value_anchor_directions
(Gnattest_T: in out Test);
procedure Test_Option_Value_54a47c_6cc903(Gnattest_T: in out Test) renames
Test_13_Option_Value_test_option_value_anchor_directions;
-- id:2.2/54a47c075654f531/Option_Value/0/0/test_option_value_anchor_directions/
procedure Test_13_Option_Value_test_option_value_anchor_directions
(Gnattest_T: in out Test) is
function Option_Value
(Widgt: Tk_Widget; Name: String) return Anchor_Directions renames
Wrap_Test_Option_Value_54a47c_6cc903;
-- end read only
pragma Unreferenced(Gnattest_T);
Frame: Tk_Label_Frame;
begin
if Value("DISPLAY", "")'Length = 0 then
Assert(True, "No display, can't test");
return;
end if;
Create
(Frame, ".myframe",
Label_Frame_Create_Options'(Label_Anchor => N, others => <>));
Add(Frame);
Tcl_Eval("update");
Assert
(Option_Value(Frame, "labelanchor") = Anchor_Directions'(N),
"Failed to get value for Anchor_Directions widget option");
Destroy(Frame);
-- begin read only
end Test_13_Option_Value_test_option_value_anchor_directions;
-- end read only
-- begin read only
procedure Wrap_Test_Destroy_568000_03a39f(Widgt: in out Tk_Widget) is
begin
begin
pragma Assert(Widgt /= Null_Widget);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"req_sloc(tk-widget.ads:0):Test_Destroy test requirement violated");
end;
GNATtest_Generated.GNATtest_Standard.Tk.Widget.Destroy(Widgt);
begin
pragma Assert(Widgt = Null_Widget);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"ens_sloc(tk-widget.ads:0:):Test_Destroy test commitment violated");
end;
end Wrap_Test_Destroy_568000_03a39f;
-- end read only
-- begin read only
procedure Test_Destroy_test_destroy(Gnattest_T: in out Test);
procedure Test_Destroy_568000_03a39f(Gnattest_T: in out Test) renames
Test_Destroy_test_destroy;
-- id:2.2/568000e013c6ee78/Destroy/1/0/test_destroy/
procedure Test_Destroy_test_destroy(Gnattest_T: in out Test) is
procedure Destroy(Widgt: in out Tk_Widget) renames
Wrap_Test_Destroy_568000_03a39f;
-- end read only
pragma Unreferenced(Gnattest_T);
Button: Tk_Button;
begin
if Value("DISPLAY", "")'Length = 0 then
Assert(True, "No display, can't test");
return;
end if;
Create(Button, ".mybutton", Button_Options'(others => <>));
Destroy(Button);
Assert(Button = Null_Widget, "Failed to destroy Tk_Widget");
-- begin read only
end Test_Destroy_test_destroy;
-- end read only
-- begin read only
procedure Wrap_Test_Execute_Widget_Command_7643c6_2f4d36
(Widgt: Tk_Widget; Command_Name: String; Options: String := "") is
begin
begin
pragma Assert(Widgt /= Null_Widget and Command_Name'Length > 0);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"req_sloc(tk-widget.ads:0):Test_Execute_Widget_Command test requirement violated");
end;
GNATtest_Generated.GNATtest_Standard.Tk.Widget.Execute_Widget_Command
(Widgt, Command_Name, Options);
begin
pragma Assert(True);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"ens_sloc(tk-widget.ads:0:):Test_Execute_Widget_Command test commitment violated");
end;
end Wrap_Test_Execute_Widget_Command_7643c6_2f4d36;
-- end read only
-- begin read only
procedure Test_1_Execute_Widget_Command_test_execute_widget_command
(Gnattest_T: in out Test);
procedure Test_Execute_Widget_Command_7643c6_2f4d36
(Gnattest_T: in out Test) renames
Test_1_Execute_Widget_Command_test_execute_widget_command;
-- id:2.2/7643c6ae56a5b360/Execute_Widget_Command/1/0/test_execute_widget_command/
procedure Test_1_Execute_Widget_Command_test_execute_widget_command
(Gnattest_T: in out Test) is
procedure Execute_Widget_Command
(Widgt: Tk_Widget; Command_Name: String; Options: String := "") renames
Wrap_Test_Execute_Widget_Command_7643c6_2f4d36;
-- end read only
pragma Unreferenced(Gnattest_T);
Button: Tk_Button;
begin
if Value("DISPLAY", "")'Length = 0 then
Assert(True, "No display, can't test");
return;
end if;
Create
(Button, ".mybutton",
Button_Options'(Text => To_Tcl_String("Quit"), others => <>));
Execute_Widget_Command(Button, "cget", "-text");
Assert
(Tcl_Get_Result = "Quit",
"Failed to execute Tcl command on the selected Tk_Widget.");
Destroy(Button);
-- begin read only
end Test_1_Execute_Widget_Command_test_execute_widget_command;
-- end read only
-- begin read only
function Wrap_Test_Execute_Widget_Command_6ed39c_9808c7
(Widgt: Tk_Widget; Command_Name: String; Options: String := "")
return Tcl_String_Result is
begin
begin
pragma Assert(Widgt /= Null_Widget and Command_Name'Length > 0);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"req_sloc(tk-widget.ads:0):Test_Execute_Widget_Command2 test requirement violated");
end;
declare
Test_Execute_Widget_Command_6ed39c_9808c7_Result: constant Tcl_String_Result :=
GNATtest_Generated.GNATtest_Standard.Tk.Widget
.Execute_Widget_Command
(Widgt, Command_Name, Options);
begin
begin
pragma Assert(True);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"ens_sloc(tk-widget.ads:0:):Test_Execute_Widget_Command2 test commitment violated");
end;
return Test_Execute_Widget_Command_6ed39c_9808c7_Result;
end;
end Wrap_Test_Execute_Widget_Command_6ed39c_9808c7;
-- end read only
-- begin read only
procedure Test_2_Execute_Widget_Command_test_execute_widget_command2
(Gnattest_T: in out Test);
procedure Test_Execute_Widget_Command_6ed39c_9808c7
(Gnattest_T: in out Test) renames
Test_2_Execute_Widget_Command_test_execute_widget_command2;
-- id:2.2/6ed39c8302f3fc5b/Execute_Widget_Command/0/0/test_execute_widget_command2/
procedure Test_2_Execute_Widget_Command_test_execute_widget_command2
(Gnattest_T: in out Test) is
function Execute_Widget_Command
(Widgt: Tk_Widget; Command_Name: String; Options: String := "")
return Tcl_String_Result renames
Wrap_Test_Execute_Widget_Command_6ed39c_9808c7;
-- end read only
pragma Unreferenced(Gnattest_T);
Button: Tk_Button;
begin
if Value("DISPLAY", "")'Length = 0 then
Assert(True, "No display, can't test");
return;
end if;
Create
(Button, ".mybutton",
Button_Options'(Text => To_Tcl_String("NewQuit"), others => <>));
Assert
(Execute_Widget_Command(Button, "cget", "-text").Result = "NewQuit",
"Failed to execute and get result of Tcl command on the selected Tk_Widget.");
Destroy(Button);
-- begin read only
end Test_2_Execute_Widget_Command_test_execute_widget_command2;
-- end read only
-- begin read only
function Wrap_Test_Execute_Widget_Command_7bae5e_9df879
(Widgt: Tk_Widget; Command_Name: String; Options: String := "")
return Tcl_Boolean_Result is
begin
begin
pragma Assert(Widgt /= Null_Widget and Command_Name'Length > 0);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"req_sloc(tk-widget.ads:0):Test_Execute_Widget_Command3 test requirement violated");
end;
declare
Test_Execute_Widget_Command_7bae5e_9df879_Result: constant Tcl_Boolean_Result :=
GNATtest_Generated.GNATtest_Standard.Tk.Widget
.Execute_Widget_Command
(Widgt, Command_Name, Options);
begin
begin
pragma Assert(True);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"ens_sloc(tk-widget.ads:0:):Test_Execute_Widget_Command3 test commitment violated");
end;
return Test_Execute_Widget_Command_7bae5e_9df879_Result;
end;
end Wrap_Test_Execute_Widget_Command_7bae5e_9df879;
-- end read only
-- begin read only
procedure Test_3_Execute_Widget_Command_test_execute_widget_command3
(Gnattest_T: in out Test);
procedure Test_Execute_Widget_Command_7bae5e_9df879
(Gnattest_T: in out Test) renames
Test_3_Execute_Widget_Command_test_execute_widget_command3;
-- id:2.2/7bae5e800ff19112/Execute_Widget_Command/0/0/test_execute_widget_command3/
procedure Test_3_Execute_Widget_Command_test_execute_widget_command3
(Gnattest_T: in out Test) is
function Execute_Widget_Command
(Widgt: Tk_Widget; Command_Name: String; Options: String := "")
return Tcl_Boolean_Result renames
Wrap_Test_Execute_Widget_Command_7bae5e_9df879;
-- end read only
pragma Unreferenced(Gnattest_T);
Entry_Widget: Ttk_Entry;
begin
if Value("DISPLAY", "")'Length = 0 then
Assert(True, "No display, can't test");
return;
end if;
Create(Entry_Widget, ".myentry", Ttk_Entry_Options'(others => <>));
Assert
(not Execute_Widget_Command(Entry_Widget, "selection", "present")
.Result,
"Failed to execute and get boolean result of Tcl command on the selected Tk_Widget.");
Destroy(Entry_Widget);
-- begin read only
end Test_3_Execute_Widget_Command_test_execute_widget_command3;
-- end read only
-- begin read only
-- id:2.2/02/
--
-- This section can be used to add elaboration code for the global state.
--
begin
-- end read only
null;
-- begin read only
-- end read only
end Tk.Widget.Test_Data.Tests;
|
-- CC1221A.ADA
-- Grant of Unlimited Rights
--
-- Under contracts F33600-87-D-0337, F33600-84-D-0280, MDA903-79-C-0687,
-- F08630-91-C-0015, and DCA100-97-D-0025, the U.S. Government obtained
-- unlimited rights in the software and documentation contained herein.
-- Unlimited rights are defined in DFAR 252.227-7013(a)(19). By making
-- this public release, the Government intends to confer upon all
-- recipients unlimited rights equal to those held by the Government.
-- These rights include rights to use, duplicate, release or disclose the
-- released technical data and computer software in whole or in part, in
-- any manner and for any purpose whatsoever, and to have or permit others
-- to do so.
--
-- DISCLAIMER
--
-- ALL MATERIALS OR INFORMATION HEREIN RELEASED, MADE AVAILABLE OR
-- DISCLOSED ARE AS IS. THE GOVERNMENT MAKES NO EXPRESS OR IMPLIED
-- WARRANTY AS TO ANY MATTER WHATSOEVER, INCLUDING THE CONDITIONS OF THE
-- SOFTWARE, DOCUMENTATION OR OTHER INFORMATION RELEASED, MADE AVAILABLE
-- OR DISCLOSED, OR THE OWNERSHIP, MERCHANTABILITY, OR FITNESS FOR A
-- PARTICULAR PURPOSE OF SAID MATERIAL.
--*
-- OBJECTIVE:
-- FOR A FORMAL INTEGER TYPE, CHECK THAT THE FOLLOWING BASIC
-- OPERATIONS ARE IMPLICITLY DECLARED AND ARE THEREFORE AVAILABLE
-- WITHIN THE GENERIC UNIT: ASSIGNMENT, MEMBERSHIP, QUALIFICATION,
-- AND EXPLICIT CONVERSION TO AND FROM OTHER INTEGER TYPES.
-- HISTORY:
-- RJW 09/26/86 CREATED ORIGINAL TEST.
-- BCB 11/12/87 CHANGED HEADER TO STANDARD FORMAT. SPLIT TEST
-- INTO PARTS A, B, C, AND D.
WITH SYSTEM; USE SYSTEM;
WITH REPORT; USE REPORT;
PROCEDURE CC1221A IS
SUBTYPE SUBINT IS INTEGER RANGE -100 .. 100;
TYPE NEWINT IS NEW INTEGER;
TYPE INT IS RANGE -300 .. 300;
BEGIN
TEST ( "CC1221A", "FOR A FORMAL INTEGER TYPE, CHECK THAT THE " &
"FOLLOWING BASIC OPERATIONS ARE IMPLICITLY " &
"DECLARED AND ARE THEREFORE AVAILABLE " &
"WITHIN THE GENERIC UNIT: ASSIGNMENT, " &
"MEMBERSHIP, QUALIFICATION, AND EXPLICIT " &
"CONVERSION TO AND FROM OTHER INTEGER TYPES");
DECLARE -- (A) CHECKS FOR BASIC OPERATIONS OF A DISCRETE TYPE.
-- PART I.
GENERIC
TYPE T IS RANGE <>;
TYPE T1 IS RANGE <>;
I : T;
I1 : T1;
PROCEDURE P (J : T; STR : STRING);
PROCEDURE P (J : T; STR : STRING) IS
SUBTYPE ST IS T RANGE T'VAL (-1) .. T'VAL (1);
K, L : T;
FUNCTION F (X : T) RETURN BOOLEAN IS
BEGIN
RETURN IDENT_BOOL (TRUE);
END F;
FUNCTION F (X : T1) RETURN BOOLEAN IS
BEGIN
RETURN IDENT_BOOL (FALSE);
END F;
BEGIN
K := I;
L := J;
K := L;
IF K /= J THEN
FAILED ( "INCORRECT RESULTS FOR ASSIGNMENT " &
"WITH TYPE - " & STR);
END IF;
IF I IN ST THEN
NULL;
ELSE
FAILED ( "INCORRECT RESULTS FOR ""IN"" WITH " &
"TYPE - " & STR);
END IF;
IF J NOT IN ST THEN
NULL;
ELSE
FAILED ( "INCORRECT RESULTS FOR ""NOT IN"" WITH " &
"TYPE - " & STR);
END IF;
IF T'(I) /= I THEN
FAILED ( "INCORRECT RESULTS FOR QUALIFICATION " &
"WITH TYPE - " & STR & " - 1" );
END IF;
IF F (T'(1)) THEN
NULL;
ELSE
FAILED ( "INCORRECT RESULTS FOR QUALIFICATION " &
"WITH TYPE - " & STR & " - 2" );
END IF;
IF T (I1) /= I THEN
FAILED ( "INCORRECT RESULTS FOR EXPLICIT " &
"CONVERSION WITH TYPE - " & STR &
" - 1" );
END IF;
IF F (T (I1)) THEN
NULL;
ELSE
FAILED ( "INCORRECT RESULTS FOR EXPLICIT " &
"CONVERSION WITH TYPE - " & STR &
" - 2" );
END IF;
END P;
PROCEDURE NP1 IS NEW P (SUBINT, SUBINT, 0, 0);
PROCEDURE NP2 IS NEW P (NEWINT, NEWINT, 0, 0);
PROCEDURE NP3 IS NEW P (INT, INT, 0, 0);
PROCEDURE NP4 IS NEW P (INTEGER, INTEGER, 0, 0);
BEGIN
NP1 (2, "SUBINT");
NP2 (2, "NEWINT");
NP3 (2, "INT");
NP4 (2, "INTEGER");
END; -- (A).
RESULT;
END CC1221A;
|
------------------------------------------------------------------------------
-- Copyright (c) 2016-2017, Natacha Porté --
-- --
-- Permission to use, copy, modify, and distribute this software for any --
-- purpose with or without fee is hereby granted, provided that the above --
-- copyright notice and this permission notice appear in all copies. --
-- --
-- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES --
-- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF --
-- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR --
-- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES --
-- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN --
-- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF --
-- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. --
------------------------------------------------------------------------------
package body Natools.Smaz is
use type Ada.Streams.Stream_Element_Offset;
procedure Find_Entry
(Dict : in Dictionary;
Template : in String;
Index : out Ada.Streams.Stream_Element;
Length : out Natural);
-- Try to find the longest entry in Dict that is a prefix of Template,
-- setting Length to 0 when no such entry exists.
function To_String (Data : in Ada.Streams.Stream_Element_Array)
return String;
-- Convert a stream element array into a string
function Verbatim_Size (Dict : Dictionary; Original_Size : Natural)
return Ada.Streams.Stream_Element_Count;
-- Return the number of bytes needed by the verbatim encoding
-- of Original_Size bytes.
------------------------------
-- Local Helper Subprograms --
------------------------------
procedure Find_Entry
(Dict : in Dictionary;
Template : in String;
Index : out Ada.Streams.Stream_Element;
Length : out Natural)
is
I : Ada.Streams.Stream_Element;
N : Natural;
begin
Index := Ada.Streams.Stream_Element'Last;
Length := 0;
for Last in reverse Template'Range loop
N := Dict.Hash (Template (Template'First .. Last));
if N <= Natural (Dict.Dict_Last) then
I := Ada.Streams.Stream_Element (N);
if Dict_Entry (Dict, I) = Template (Template'First .. Last) then
Index := I;
Length := 1 + Last - Template'First;
return;
end if;
end if;
end loop;
end Find_Entry;
function To_String (Data : in Ada.Streams.Stream_Element_Array)
return String is
begin
return Result : String (1 .. Data'Length) do
for I in Result'Range loop
Result (I) := Character'Val (Data
(Data'First + Ada.Streams.Stream_Element_Offset (I - 1)));
end loop;
end return;
end To_String;
function Verbatim_Size (Dict : Dictionary; Original_Size : Natural)
return Ada.Streams.Stream_Element_Count
is
Verbatim1_Max_Size : constant Ada.Streams.Stream_Element_Count
:= Ada.Streams.Stream_Element_Count
(Ada.Streams.Stream_Element'Last - Dict.Dict_Last)
- Boolean'Pos (Dict.Variable_Length_Verbatim);
Verbatim2_Max_Size : constant Ada.Streams.Stream_Element_Count
:= Ada.Streams.Stream_Element_Count (Ada.Streams.Stream_Element'Last)
+ Verbatim1_Max_Size;
Remaining : Ada.Streams.Stream_Element_Count
:= Ada.Streams.Stream_Element_Count (Original_Size);
Overhead : Ada.Streams.Stream_Element_Count := 0;
begin
if Dict.Variable_Length_Verbatim then
if Remaining >= Verbatim2_Max_Size then
declare
Full_Blocks : constant Ada.Streams.Stream_Element_Count
:= Remaining / Verbatim2_Max_Size;
begin
Overhead := Overhead + 2 * Full_Blocks;
Remaining := Remaining - Verbatim2_Max_Size * Full_Blocks;
end;
end if;
if Remaining > Verbatim1_Max_Size then
Overhead := Overhead + 2;
Remaining := 0;
end if;
end if;
declare
Block_Count : constant Ada.Streams.Stream_Element_Count
:= (Remaining + Verbatim1_Max_Size - 1) / Verbatim1_Max_Size;
begin
Overhead := Overhead + Block_Count;
end;
return Overhead + Ada.Streams.Stream_Element_Count (Original_Size);
end Verbatim_Size;
----------------------
-- Public Interface --
----------------------
function Dict_Entry
(Dict : in Dictionary;
Index : in Ada.Streams.Stream_Element)
return String
is
First : constant Positive := Dict.Offsets (Index);
Last : Natural := Dict.Values'Last;
begin
if Index + 1 in Dict.Offsets'Range then
Last := Dict.Offsets (Index + 1) - 1;
end if;
return Dict.Values (First .. Last);
end Dict_Entry;
function Compressed_Upper_Bound
(Dict : in Dictionary;
Input : in String)
return Ada.Streams.Stream_Element_Count is
begin
return Verbatim_Size (Dict, Input'Length);
end Compressed_Upper_Bound;
procedure Compress
(Dict : in Dictionary;
Input : in String;
Output_Buffer : out Ada.Streams.Stream_Element_Array;
Output_Last : out Ada.Streams.Stream_Element_Offset)
is
procedure Find_Entry;
Verbatim1_Max_Size : constant Natural
:= Natural (Ada.Streams.Stream_Element'Last - Dict.Dict_Last)
- Boolean'Pos (Dict.Variable_Length_Verbatim);
Verbatim2_Max_Size : constant Natural
:= Natural (Ada.Streams.Stream_Element'Last)
+ Verbatim1_Max_Size;
Input_Index : Positive := Input'First;
Length : Natural;
Word : Ada.Streams.Stream_Element;
procedure Find_Entry is
begin
Find_Entry
(Dict,
Input (Input_Index
.. Natural'Min (Input_Index + Dict.Max_Word_Length - 1,
Input'Last)),
Word,
Length);
end Find_Entry;
Previous_Verbatim_Beginning : Natural := 0;
Previous_Verbatim_Last : Ada.Streams.Stream_Element_Offset := 0;
begin
Output_Last := Output_Buffer'First - 1;
Find_Entry;
Main_Loop :
while Input_Index in Input'Range loop
Data_In_Dict :
while Length > 0 loop
Output_Last := Output_Last + 1;
Output_Buffer (Output_Last) := Word;
Input_Index := Input_Index + Length;
exit Main_Loop when Input_Index not in Input'Range;
Find_Entry;
end loop Data_In_Dict;
Verbatim_Block :
declare
Beginning : Positive := Input_Index;
Verbatim_Length, Block_Length : Natural;
begin
Verbatim_Scan :
while Length = 0 and Input_Index in Input'Range loop
Input_Index := Input_Index + 1;
Find_Entry;
end loop Verbatim_Scan;
Verbatim_Length := Input_Index - Beginning;
if Previous_Verbatim_Beginning > 0
and then Output_Last + Verbatim_Size (Dict, Verbatim_Length)
>= Previous_Verbatim_Last + Verbatim_Size
(Dict, Input_Index - Previous_Verbatim_Beginning)
then
Beginning := Previous_Verbatim_Beginning;
Output_Last := Previous_Verbatim_Last;
Verbatim_Length := Input_Index - Beginning;
else
Previous_Verbatim_Beginning := Beginning;
Previous_Verbatim_Last := Output_Last;
end if;
Verbatim_Encode :
while Verbatim_Length > 0 loop
if Dict.Variable_Length_Verbatim
and then Verbatim_Length > Verbatim1_Max_Size
then
Block_Length := Natural'Min
(Verbatim_Length, Verbatim2_Max_Size);
Output_Buffer (Output_Last + 1)
:= Ada.Streams.Stream_Element'Last;
Output_Buffer (Output_Last + 2) := Ada.Streams.Stream_Element
(Block_Length - Verbatim1_Max_Size);
Output_Last := Output_Last + 2;
else
Block_Length := Natural'Min
(Verbatim_Length, Verbatim1_Max_Size);
Output_Last := Output_Last + 1;
Output_Buffer (Output_Last)
:= Ada.Streams.Stream_Element'Last
- Ada.Streams.Stream_Element
(Block_Length - 1
+ Boolean'Pos (Dict.Variable_Length_Verbatim));
end if;
Verbatim_Copy :
for I in Beginning .. Beginning + Block_Length - 1 loop
Output_Last := Output_Last + 1;
Output_Buffer (Output_Last) := Character'Pos (Input (I));
end loop Verbatim_Copy;
Verbatim_Length := Verbatim_Length - Block_Length;
Beginning := Beginning + Block_Length;
end loop Verbatim_Encode;
end Verbatim_Block;
end loop Main_Loop;
end Compress;
function Compress (Dict : in Dictionary; Input : in String)
return Ada.Streams.Stream_Element_Array
is
Result : Ada.Streams.Stream_Element_Array
(1 .. Compressed_Upper_Bound (Dict, Input));
Last : Ada.Streams.Stream_Element_Offset;
begin
Compress (Dict, Input, Result, Last);
return Result (Result'First .. Last);
end Compress;
function Decompressed_Length
(Dict : in Dictionary;
Input : in Ada.Streams.Stream_Element_Array)
return Natural
is
Result : Natural := 0;
Verbatim_Code_Count : constant Ada.Streams.Stream_Element_Offset
:= Ada.Streams.Stream_Element_Offset
(Ada.Streams.Stream_Element'Last - Dict.Dict_Last);
Input_Index : Ada.Streams.Stream_Element_Offset := Input'First;
Input_Byte : Ada.Streams.Stream_Element;
Verbatim_Length : Ada.Streams.Stream_Element_Offset;
begin
while Input_Index in Input'Range loop
Input_Byte := Input (Input_Index);
if Input_Byte in Dict.Offsets'Range then
Result := Result + Dict_Entry (Dict, Input_Byte)'Length;
Input_Index := Input_Index + 1;
else
if not Dict.Variable_Length_Verbatim then
Verbatim_Length := Ada.Streams.Stream_Element_Offset
(Ada.Streams.Stream_Element'Last - Input_Byte) + 1;
elsif Input_Byte < Ada.Streams.Stream_Element'Last then
Verbatim_Length := Ada.Streams.Stream_Element_Offset
(Ada.Streams.Stream_Element'Last - Input_Byte);
else
Input_Index := Input_Index + 1;
Verbatim_Length := Ada.Streams.Stream_Element_Offset
(Input (Input_Index)) + Verbatim_Code_Count - 1;
end if;
Result := Result + Positive (Verbatim_Length);
Input_Index := Input_Index + Verbatim_Length + 1;
end if;
end loop;
return Result;
end Decompressed_Length;
procedure Decompress
(Dict : in Dictionary;
Input : in Ada.Streams.Stream_Element_Array;
Output_Buffer : out String;
Output_Last : out Natural)
is
procedure Append (S : in String);
procedure Append (S : in Ada.Streams.Stream_Element_Array);
procedure Append (S : in String) is
begin
Output_Buffer (Output_Last + 1 .. Output_Last + S'Length) := S;
Output_Last := Output_Last + S'Length;
end Append;
procedure Append (S : in Ada.Streams.Stream_Element_Array) is
begin
Append (To_String (S));
end Append;
Verbatim_Code_Count : constant Ada.Streams.Stream_Element_Offset
:= Ada.Streams.Stream_Element_Offset
(Ada.Streams.Stream_Element'Last - Dict.Dict_Last);
Input_Index : Ada.Streams.Stream_Element_Offset := Input'First;
Input_Byte : Ada.Streams.Stream_Element;
Verbatim_Length : Ada.Streams.Stream_Element_Offset;
begin
Output_Last := Output_Buffer'First - 1;
while Input_Index in Input'Range loop
Input_Byte := Input (Input_Index);
if Input_Byte in Dict.Offsets'Range then
Append (Dict_Entry (Dict, Input_Byte));
Input_Index := Input_Index + 1;
else
if not Dict.Variable_Length_Verbatim then
Verbatim_Length := Ada.Streams.Stream_Element_Offset
(Ada.Streams.Stream_Element'Last - Input_Byte) + 1;
elsif Input_Byte < Ada.Streams.Stream_Element'Last then
Verbatim_Length := Ada.Streams.Stream_Element_Offset
(Ada.Streams.Stream_Element'Last - Input_Byte);
else
Input_Index := Input_Index + 1;
Verbatim_Length := Ada.Streams.Stream_Element_Offset
(Input (Input_Index)) + Verbatim_Code_Count - 1;
end if;
Append (Input (Input_Index + 1 .. Input_Index + Verbatim_Length));
Input_Index := Input_Index + Verbatim_Length + 1;
end if;
end loop;
end Decompress;
function Decompress
(Dict : in Dictionary; Input : in Ada.Streams.Stream_Element_Array)
return String
is
Result : String (1 .. Decompressed_Length (Dict, Input));
Last : Natural;
begin
Decompress (Dict, Input, Result, Last);
pragma Assert (Last = Result'Last);
return Result;
end Decompress;
end Natools.Smaz;
|
with P_StructuralTypes;
use P_StructuralTypes;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
package P_StepHandler is
type T_StepHandler is abstract tagged private;
type Ptr_Handler is access all T_StepHandler'Class;
procedure Handle (Self : in out T_StepHandler) is abstract;
function Get_NextHandler (Self : in out T_StepHandler) return Ptr_Handler;
procedure Set_NextHandler (Self : in out T_StepHandler;
Ptr_StepHandler : Ptr_Handler);
function Get_BinaryContainer (Self : in out T_StepHandler)
return BinaryContainer_Access;
procedure Set_BinaryContainer (Self : in out T_StepHandler;
Ptr_BinaryContainer : BinaryContainer_Access);
PRIVATE
type T_StepHandler is abstract tagged
record
NextHandler : Ptr_Handler;
Ptr_BinaryContainer : BinaryContainer_Access;
end record;
end P_StepHandler;
|
-- C85018A.ADA
-- Grant of Unlimited Rights
--
-- Under contracts F33600-87-D-0337, F33600-84-D-0280, MDA903-79-C-0687,
-- F08630-91-C-0015, and DCA100-97-D-0025, the U.S. Government obtained
-- unlimited rights in the software and documentation contained herein.
-- Unlimited rights are defined in DFAR 252.227-7013(a)(19). By making
-- this public release, the Government intends to confer upon all
-- recipients unlimited rights equal to those held by the Government.
-- These rights include rights to use, duplicate, release or disclose the
-- released technical data and computer software in whole or in part, in
-- any manner and for any purpose whatsoever, and to have or permit others
-- to do so.
--
-- DISCLAIMER
--
-- ALL MATERIALS OR INFORMATION HEREIN RELEASED, MADE AVAILABLE OR
-- DISCLOSED ARE AS IS. THE GOVERNMENT MAKES NO EXPRESS OR IMPLIED
-- WARRANTY AS TO ANY MATTER WHATSOEVER, INCLUDING THE CONDITIONS OF THE
-- SOFTWARE, DOCUMENTATION OR OTHER INFORMATION RELEASED, MADE AVAILABLE
-- OR DISCLOSED, OR THE OWNERSHIP, MERCHANTABILITY, OR FITNESS FOR A
-- PARTICULAR PURPOSE OF SAID MATERIAL.
--*
-- CHECK THAT AN ENTRY FAMILY MEMBER CAN BE RENAMED WITH:
-- 1) DIFFERENT PARAMETER NAMES;
-- 2) DIFFERENT DEFAULT VALUES;
-- AND THAT THE NEW NAMES/DEFAULTS ARE USED WHEN THE NEW NAME
-- IS USED IN A CALL.
-- RJW 6/3/86
WITH REPORT; USE REPORT;
PROCEDURE C85018A IS
BEGIN
TEST( "C85018A", "CHECK THAT AN ENTRY FAMILY MEMBER CAN BE " &
"RENAMED AND THAT THE NEW NAMES/DEFAULTS ARE " &
"THOSE ASSOCIATED WITH THE RENAMED ENTITY" );
DECLARE
RESULTS : INTEGER;
TYPE TA IS ARRAY(1 .. 5) OF INTEGER;
TASK T IS
ENTRY ENT1 (BOOLEAN)
(A : INTEGER := 1; B : TA := (1 .. 5 => 1));
END T;
PROCEDURE ENTA (C : INTEGER := 1; D : TA := (1 .. 5 => 1))
RENAMES T.ENT1 (TRUE);
PROCEDURE ENTB (B : INTEGER := 1; A : TA := (1 .. 5 => 1))
RENAMES T.ENT1 (TRUE);
PROCEDURE ENTC (A : INTEGER := 2; B : TA := (1, 2, 3, 4, 5))
RENAMES T.ENT1 (TRUE);
PROCEDURE ENTD (C : INTEGER := 2; D : TA := (1, 2, 3, 4, 5))
RENAMES T.ENT1 (TRUE);
TASK BODY T IS
BEGIN
LOOP
SELECT
ACCEPT ENT1 (IDENT_BOOL (TRUE))
(A : INTEGER := 1;
B : TA := (1 .. 5 => 1)) DO
IF A IN 1 .. 5 THEN
RESULTS := B(A);
ELSE
RESULTS := 0;
END IF;
END;
OR
TERMINATE;
END SELECT;
END LOOP;
END T;
BEGIN
T.ENT1 (TRUE);
IF RESULTS /= 1 THEN
FAILED ( "PARAMETERS NOT PROPERLY INITIALIZED" );
END IF;
T.ENT1 (TRUE) (A => 6);
IF RESULTS /= 0 THEN
FAILED ( "INCORRECT RESULTS" );
END IF;
ENTA;
IF RESULTS /= 1 THEN
FAILED ( "CASE 1 : INCORRECT RESULTS (DEFAULT)" );
END IF;
ENTA(D => (5, 4, 3, 2, 1));
IF RESULTS /= 5 THEN
FAILED ( "CASE 1 : INCORRECT RESULTS" );
END IF;
ENTB;
IF RESULTS /= 1 THEN
FAILED ( "CASE 1 : INCORRECT RESULTS (DEFAULT)" );
END IF;
ENTB(A => (5, 4, 3, 2, 1), B => 2);
IF RESULTS /= 4 THEN
FAILED ( "CASE 1 : INCORRECT RESULTS " );
END IF;
ENTC;
IF RESULTS /= 2 THEN
FAILED ( "CASE 2 : INCORRECT RESULTS (DEFAULT)" );
END IF;
ENTC(3);
IF RESULTS /= 3 THEN
FAILED ( "CASE 2 : INCORRECT RESULTS " );
END IF;
ENTD;
IF RESULTS /= 2 THEN
FAILED ( "CASE 2 : INCORRECT RESULTS (DEFAULT)" );
END IF;
ENTD(4);
IF RESULTS /= 4 THEN
FAILED ( "CASE 2 : INCORRECT RESULTS " );
END IF;
END;
RESULT;
END C85018A;
|
with interfaces.c.strings;
package body agar.gui.colors is
package cs renames interfaces.c.strings;
use type c.int;
package cbinds is
function load (path : cs.chars_ptr) return c.int;
pragma import (c, load, "AG_ColorsLoad");
function save (path : cs.chars_ptr) return c.int;
pragma import (c, save, "AG_ColorsSave");
function save_default return c.int;
pragma import (c, save_default, "AG_ColorsSaveDefault");
end cbinds;
function load (path : string) return boolean is
ca_path : aliased c.char_array := c.to_c (path);
begin
return cbinds.load (cs.to_chars_ptr (ca_path'unchecked_access)) = 0;
end load;
function save (path : string) return boolean is
ca_path : aliased c.char_array := c.to_c (path);
begin
return cbinds.save (cs.to_chars_ptr (ca_path'unchecked_access)) = 0;
end save;
function save_default return boolean is
begin
return cbinds.save_default = 0;
end save_default;
end agar.gui.colors;
|
-- SPDX-FileCopyrightText: 2021 Max Reznik <reznikmm@gmail.com>
--
-- SPDX-License-Identifier: MIT
-------------------------------------------------------------
with Program.Cross_Reference_Updaters;
with Program.Elements.Case_Statements;
with Program.Interpretations;
package Program.Complete_Contexts.Case_Statements is
pragma Preelaborate;
procedure Case_Statement
(Sets : not null Program.Interpretations.Context_Access;
Setter : not null Program.Cross_Reference_Updaters
.Cross_Reference_Updater_Access;
Element : Program.Elements.Case_Statements.Case_Statement_Access);
end Program.Complete_Contexts.Case_Statements;
|
-- { dg-do compile }
procedure late_overriding is
package Pkg is
type I is interface;
procedure Meth (O : in I) is abstract;
type Root is abstract tagged null record;
type DT1 is abstract new Root and I with null record;
end Pkg;
use Pkg;
type DT2 is new DT1 with null record;
procedure Meth (X : DT2) is begin null; end; -- Test
begin
null;
end;
|
package units with SPARK_Mode is
type Unit_Type is new Float with -- As tagged Type? -> Generics with Unit_Type'Class
Dimension_System =>
((Unit_Name => Meter, Unit_Symbol => 'm', Dim_Symbol => 'L'),
(Unit_Name => Kilogram, Unit_Symbol => "kg", Dim_Symbol => 'M'),
(Unit_Name => Second, Unit_Symbol => 's', Dim_Symbol => 'T'),
(Unit_Name => Ampere, Unit_Symbol => 'A', Dim_Symbol => 'I'),
(Unit_Name => Kelvin, Unit_Symbol => 'K', Dim_Symbol => "Theta"),
(Unit_Name => Radian, Unit_Symbol => "Rad", Dim_Symbol => "A")),
Default_Value => 0.0;
subtype Angle_Type is Unit_Type with
Dimension => (Symbol => "Rad", Radian => 1, others => 0);
Radian : constant Angle_Type := Angle_Type (1.0);
RADIAN_2PI : constant Angle_Type := 2.0 * Radian;
-- idea: shift range to 0 .. X, wrap with mod, shift back
--function wrap_Angle( angle : Angle_Type; min : Angle_Type; max : Angle_Type) return Angle_Type is
-- ( Angle_Type'Remainder( (angle - min - (max-min)/2.0) , (max-min) ) + (max+min)/2.0 );
-- FIXME: Spark error: unbound symbol 'Floating.remainder_'
-- ( if angle > max then max elsif angle < min then min else angle );
-- with
-- pre => max > min,
-- post => wrap_Angle'Result in min .. max;
-- if angle - min < 0.0 * Degree then Angle_Type'Remainder( (angle - min), (max-min) ) + max else
function wrap_angle2 (angle : Angle_Type; min : Angle_Type; max : Angle_Type) return Angle_Type
with Pre => min <= 0.0 * Radian and then
max >= 0.0 * Radian and then
max > min and then
max < Angle_Type'Last / 2.0 and then
min > Angle_Type'First / 2.0,
Post => wrap_angle2'Result >= min and wrap_angle2'Result <= max;
-- Must make no assumptions on input 'angle' here, otherwise caller might fail if it isn't SPARK.
end units;
|
with Ada.Integer_Text_IO;
with Ada.Text_IO;
with Ada.Containers.Ordered_Sets;
with PrimeUtilities;
package body Problem_35 is
package IO renames Ada.Text_IO;
package I_IO renames Ada.Integer_Text_IO;
subtype One_Million is Integer range 1 .. 1_000_000;
package Million_Set is new Ada.Containers.Ordered_Sets(One_Million);
package Million_Primes is new PrimeUtilities(One_Million);
function Magnitude(n : One_Million) return Natural is
begin
if n >= 100_000 then
return 100_000;
elsif n >= 10_000 then
return 10_000;
elsif n >= 1_000 then
return 1_000;
elsif n >= 100 then
return 100;
elsif n >= 10 then
return 10;
else
return 1;
end if;
end Magnitude;
function Rotate(n : One_Million; mag : Natural) return One_Million is
begin
return n mod 10 * mag + n / 10;
end Rotate;
procedure Solve is
primes : Million_Set.Set;
count : Natural := 0;
procedure Check_Rotations(c : Million_Set.Cursor) is
prime : constant One_Million := Million_Set.Element(c);
mag : constant Natural := Magnitude(prime);
possible : One_Million := Rotate(prime, mag);
All_Prime : Boolean := True;
begin
while possible /= prime loop
if not primes.Contains(possible) then
All_Prime := False;
exit;
else
possible := Rotate(possible, mag);
end if;
end loop;
if All_Prime then
count := count + 1;
end if;
end Check_Rotations;
begin
declare
prime : One_Million;
gen : Million_Primes.Prime_Generator := Million_Primes.Make_Generator(One_Million'Last);
begin
loop
Million_Primes.Next_Prime(gen, prime);
exit when prime = 1;
primes.Insert(prime);
end loop;
end;
primes.Iterate(Process => Check_Rotations'Access);
I_IO.Put(count);
IO.New_Line;
end Solve;
end Problem_35;
|
-- Copyright 2015,2016 Steven Stewart-Gallus
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http ://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
-- implied. See the License for the specific language governing
-- permissions and limitations under the License.
package body Linted.Simulate is
use type Types.Int;
use type Types.Nat;
use type Types.Large;
use type Types.Position;
use type Types.Sim_Angle;
procedure Tick (This : in out State) is
X_Thrust : array (Types.Position) of Types.Int := (0, 0, 0);
Y_Thrust : array (Types.Position) of Types.Int := (0, 0, 0);
Z_Thrust : array (Types.Position) of Types.Int := (0, 0, 0);
Thrusts : array (Types.Position) of Types.Int;
Gravity : constant array (Types.Position) of Types.Int := (0, 0, 10);
Normal_Force : array (Types.Position) of Types.Int := (0, 0, 0);
Cos_Z : Types.Int;
Sin_Z : Types.Int;
Retreat_Or_Go_Forth : Types.Int;
Strafe : Types.Int;
begin
Retreat_Or_Go_Forth :=
Boolean'Pos (This.Controls.Back) - Boolean'Pos (This.Controls.Forward);
Strafe :=
Boolean'Pos (This.Controls.Left) - Boolean'Pos (This.Controls.Right);
Cos_Z :=
Types.Downscale
(Types.Int
(Types.Sim_Cos (This.Z_Rotation) * Types.Fixed (Types.Int'Last)),
32);
Sin_Z :=
Types.Downscale
(Types.Int
(Types.Sim_Sin (This.Z_Rotation) * Types.Fixed (Types.Int'Last)),
32);
if This.Objects (This.Objects'First) (Types.Z).Value >= 0 then
Y_Thrust (Types.X) := Retreat_Or_Go_Forth * Sin_Z;
Y_Thrust (Types.Y) := Retreat_Or_Go_Forth * Cos_Z;
X_Thrust (Types.X) := Strafe * Cos_Z;
X_Thrust (Types.Y) := Strafe * (-Sin_Z);
if This.Controls.Jumping then
Z_Thrust (Types.Z) := Types.Downscale (-Types.Int'Last, 512);
end if;
end if;
Normal_Force (Types.Z) := -Boolean'Pos (This.Controls.Left);
for II in Types.Position loop
Thrusts (II) := X_Thrust (II) + (Y_Thrust (II) + Z_Thrust (II));
end loop;
for Ix in This.Objects'Range loop
for II in Types.Position loop
declare
Position : Types.Int;
Old_Position : Types.Int;
Old_Velocity : Types.Int;
Force : Types.Int;
Guess_Velocity : Types.Int;
Mu : Types.Int;
Friction : Types.Int;
New_Velocity : Types.Int;
New_Position : Types.Int;
begin
Position := This.Objects (Ix) (II).Value;
Old_Position := This.Objects (Ix) (II).Old;
if Ix = 1 then
Force := Gravity (II) + (Normal_Force (II) + Thrusts (II));
else
Force :=
Gravity (II) + ((Types.Int (This.Counter) mod 61) - 30);
This.Counter :=
(1664525 * This.Counter + 1013904223) mod 2147483648;
end if;
Old_Velocity := Position - Old_Position;
Guess_Velocity := Types.Sim_Isatadd (Force, Old_Velocity);
if Types.X = II or Types.Y = II then
if This.Objects (Ix) (Types.Z).Value >= 0 then
Mu := 5;
else
Mu := 0;
end if;
else
Mu := 5;
end if;
Friction :=
Types.Min_Int
(Types.Int (Types.Absolute (Guess_Velocity)),
Mu) *
(-Types.Find_Sign (Guess_Velocity));
New_Velocity := Types.Sim_Isatadd (Guess_Velocity, Friction);
if Types.Z = II and
This.Objects (Ix) (Types.Z).Value >= 0 and
New_Velocity > 0
then
New_Velocity := 0;
end if;
New_Position := Types.Sim_Isatadd (Position, New_Velocity);
This.Objects (Ix) (II).Value := New_Position;
This.Objects (Ix) (II).Old := Position;
end;
end loop;
end loop;
This.Z_Rotation :=
Types.Tilt_Rotation
(This.Z_Rotation,
Types.Int (This.Controls.Z_Tilt));
This.X_Rotation :=
Types.Tilt_Clamped_Rotation
(This.X_Rotation,
-Types.Int (This.Controls.X_Tilt));
end Tick;
end Linted.Simulate;
|
with Ada.Strings.Unbounded;
with Lower_Layer_UDP;
package Client_Collections is
package ASU renames Ada.Strings.Unbounded;
package LLU renames Lower_Layer_UDP;
type Collection_Type is limited private;
Client_Collection_Error: exception;
procedure Add_Client (Collection: in out Collection_Type;
EP: in LLU.End_Point_Type;
Nick: in ASU.Unbounded_String;
Unique: in Boolean);
procedure Delete_Client (Collection: in out Collection_Type;
Nick: in ASU.Unbounded_String);
function Search_Client (Collection: in Collection_Type;
EP: in LLU.End_Point_Type)
return ASU.Unbounded_String;
procedure Send_To_All (Collection: in Collection_Type;
P_Buffer: access LLU.Buffer_Type);
function Collection_Image (Collection: in Collection_Type)
return String;
private
type Cell;
type Cell_A is access Cell;
type Cell is record
Client_EP: LLU.End_Point_Type;
Nick: ASU.Unbounded_String;
Next: Cell_A;
end record;
type Collection_Type is record
P_First: Cell_A;
Total: Natural := 0;
end record;
end Client_Collections;
|
-- with Ada.Text_IO, Ada.Real_Time;
-- use Ada.Text_IO, Ada.Real_Time;
package body Use_CPU is
-- T1, T2, T3 : Time;
-- Time_Measured : Time_Span;
-- Tolerance : Time_Span := Microseconds (50);
-- X : Float := 0.0;
-- Min : Integer := 0;
-- Max : Integer := 10_000_000;
-- NTimes : Integer := (Max - Min) / 2; -- Number of iterations to calibrate for 10 ms use of CPU
procedure Iterate (Iterations : in Integer)
with Inline
is
X : Float := 0.0;
begin
for I in 1 .. Iterations loop
X := X + 16.25;
X := X - 16.25;
X := X + 16.25;
X := X - 16.25;
X := X + 16.25;
X := X - 16.25;
end loop;
end Iterate;
procedure Work (Amount_MS : in Natural) is
-- Constant 27464 comes from several calibration runs on the STM32F4 Discovery board
Iterations : Integer := (27464 * Amount_MS) / 10; -- (NTimes * Amount_MS) / 10;
begin
Iterate (Iterations);
end Work;
-- begin
-- Put ("Calibrating nr. of iterations for 10 ms...");
-- loop
-- --Put("Trying" & Integer'Image(NTimes) & " times:");
-- --Put(" ." & Integer'Image(NTimes) );
-- Put (".");
-- T1 := Clock;
-- Iterate (NTimes);
-- T2 := Clock;
-- T3 := Clock;
-- Time_Measured := (T2 - T1 - (T3 - T2));
-- --Put(" Took" & Duration'Image(To_Duration(Time_Measured)) & " seconds.");
-- if abs (Time_Measured - Milliseconds (10)) <= Tolerance then
-- exit;
-- elsif (Time_Measured > Milliseconds (10)) then -- NTimes too large -> reduce
-- Max := NTimes;
-- else -- NTimes too short -> increase
-- Min := NTimes;
-- end if;
-- --Put_Line (" Searching now range" & Integer'Image(Min) & " .. " & Integer'Image(Max));
-- NTimes := Min + ((Max - Min) / 2);
-- end loop;
-- Put_Line (" Done!");
-- Put_Line(" Nr. of iterations for 10 ms =" & Integer'Image(NTimes));
-- New_Line;
end Use_CPU;
|
function Palindrome (Text : String) return Boolean
with Post => Palindrome'Result =
(Text'Length < 2 or else
((Text(Text'First) = Text(Text'Last)) and then
Palindrome(Text(Text'First+1 .. Text'Last-1))));
|
with Ada.Unchecked_Deallocation;
package body Vecteur is
procedure Free is
new Ada.Unchecked_Deallocation (Object => T_Vecteur_Array, Name => T_Vecteur_Access);
procedure Initialiser(Vecteur: out T_Vecteur; Capacite: in Natural) is
begin
Vecteur.Elements := new T_Vecteur_Array(0..Capacite-1);
Vecteur.Taille := 0;
end Initialiser;
procedure Copier(Vecteur: out T_Vecteur; Original: in T_Vecteur) is
begin
Initialiser(Vecteur, Original.Elements'Length);
for I in 0..Original.Taille-1 loop
Ajouter(Vecteur, Original.Elements(I));
end loop;
end Copier;
function Est_Vide (Vecteur: in T_Vecteur) return Boolean is
begin
return Vecteur.Taille = 0;
end Est_Vide;
function Taille (Vecteur: in T_Vecteur) return Integer is
begin
return Vecteur.Taille;
end Taille;
procedure Ajouter (Vecteur : in out T_Vecteur ; Valeur : in T_Type) is
begin
Vecteur.Elements.all(Vecteur.Taille) := Valeur;
Vecteur.Taille := Vecteur.Taille + 1;
end Ajouter;
procedure Modifier (Vecteur : in out T_Vecteur ; Indice: in Integer; Valeur : in T_Type) is
begin
Vecteur.Elements.all(Indice) := Valeur;
end Modifier;
function Valeur(Vecteur: in T_Vecteur; Indice: in Integer) return T_Type is
begin
return Vecteur.Elements.all(Indice);
end Valeur;
procedure Vider (Vecteur : in out T_Vecteur) is
begin
Free(Vecteur.Elements);
Vecteur.Taille := 0;
end Vider;
procedure Intervertir(Vecteur: in T_Vecteur; I: integer; J: Integer) is
Temp: T_Type;
begin
Temp := Vecteur.Elements.all(I);
Vecteur.Elements.all(I) := Vecteur.Elements.all(J);
Vecteur.Elements.all(J) := Temp;
end Intervertir;
procedure Trier (Vecteur: in out T_Vecteur) is
procedure Tri_Rapide(Vecteur: in out T_Vecteur; Inf: in Integer; Sup: in Integer) is
I : Integer := Inf;
begin
if Inf >= Sup then
return;
end if;
for J in Inf+1..Sup loop
if Vecteur.Elements.all(I) < Vecteur.Elements.all(J) then
Intervertir(Vecteur, I, J);
Intervertir(Vecteur, I+1, J);
I := I+1;
end if;
end loop;
Tri_Rapide(Vecteur, Inf, I-1);
Tri_Rapide(Vecteur, I+1, Sup);
end Tri_Rapide;
begin
Tri_Rapide(Vecteur, 0, Vecteur.Taille-1);
end Trier;
procedure Pour_Chaque(Vecteur : in T_Vecteur) is
begin
for J in 0..Vecteur.Taille-1 loop
Traiter(Vecteur.Elements.all(J));
end loop;
end Pour_Chaque;
end Vecteur;
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.