content
stringlengths 23
1.05M
|
|---|
with Ada.Strings.Unbounded;
with Ada.Strings.Unbounded.Text_IO;
with Ada.Text_IO;
with Ada.Command_Line;
package External is
package STR renames Ada.Strings.Unbounded;
package IO renames Ada.Strings.Unbounded.Text_IO;
package IOB renames Ada.Text_IO;
package CMD renames Ada.Command_Line;
function ToMString(Source: in String) return STR.Unbounded_String renames STR.To_Unbounded_String;
procedure PrintUnbounded(S: in Str.Unbounded_String) renames IO.Put_Line;
procedure PrintBounded(S: in String) renames IOB.Put_Line;
subtype MString is STR.Unbounded_String;
end External;
|
with
Shell.Commands,
Ada.Text_IO;
procedure Test_Pipeline_Output
is
use Ada.Text_IO;
begin
Put_Line ("Begin 'Pipeline_Output' test.");
New_Line (2);
declare
use Shell,
Shell.Commands,
Shell.Commands.Forge;
Commands : Command_Array := To_Commands ("ps -A | grep bash | wc");
Output : constant String := +Output_Of (Run (Commands));
begin
Put_Line ("'" & Output & "'");
end;
New_Line (2);
Put_Line ("End 'Pipeline_Output' test.");
end Test_Pipeline_Output;
|
with stm32.gpio; use stm32.gpio;
package body HAL.GPIO is
procedure write (Point : GPIO_Point_Type; Signal : GPIO_Signal_Type) is
begin
case Signal is
when HIGH =>
case Point.Port is
when A => GPIOA_Periph.BSRR.BS.Arr( Point.Pin ) := True;
when B => GPIOB_Periph.BSRR.BS.Arr( Point.Pin ) := True;
when C => GPIOC_Periph.BSRR.BS.Arr( Point.Pin ) := True;
when D => GPIOD_Periph.BSRR.BS.Arr( Point.Pin ) := True;
when E => GPIOE_Periph.BSRR.BS.Arr( Point.Pin ) := True;
when F => GPIOF_Periph.BSRR.BS.Arr( Point.Pin ) := True;
end case;
when LOW =>
case Point.Port is
when A => GPIOA_Periph.BSRR.BR.Arr( Point.Pin ) := True;
when B => GPIOB_Periph.BSRR.BR.Arr( Point.Pin ) := True;
when C => GPIOC_Periph.BSRR.BR.Arr( Point.Pin ) := True;
when D => GPIOD_Periph.BSRR.BR.Arr( Point.Pin ) := True;
when E => GPIOE_Periph.BSRR.BR.Arr( Point.Pin ) := True;
when F => GPIOF_Periph.BSRR.BR.Arr( Point.Pin ) := True;
end case;
end case;
end write;
function read (Point : GPIO_Point_Type) return GPIO_Signal_Type is
begin
return HIGH;
end read;
end HAL.GPIO;
|
-- part of OpenGLAda, (c) 2017 Felix Krause
-- released under the terms of the MIT license, see the file "COPYING"
with Ada.Unchecked_Conversion;
with GL.API;
with GL.Enums.Getter;
with GL.Low_Level.Enums;
package body GL.Buffers is
use type Culling.Face_Selector;
procedure Clear (Bits : Buffer_Bits) is
use type Low_Level.Bitfield;
function Convert is new Ada.Unchecked_Conversion
(Source => Buffer_Bits, Target => Low_Level.Bitfield);
Raw_Bits : constant Low_Level.Bitfield :=
Convert (Bits) and 2#0100011100000000#;
begin
API.Clear (Raw_Bits);
Raise_Exception_On_OpenGL_Error;
end Clear;
procedure Set_Active_Buffer (Selector : Explicit_Color_Buffer_Selector) is
begin
API.Draw_Buffer (Selector);
Raise_Exception_On_OpenGL_Error;
end Set_Active_Buffer;
procedure Set_Active_Buffers (List : Explicit_Color_Buffer_List) is
begin
API.Draw_Buffers (List'Length, List);
Raise_Exception_On_OpenGL_Error;
end Set_Active_Buffers;
procedure Set_Color_Clear_Value (Value : Colors.Color) is
begin
API.Clear_Color (Value (Colors.R), Value (Colors.G), Value (Colors.B),
Value (Colors.A));
Raise_Exception_On_OpenGL_Error;
end Set_Color_Clear_Value;
function Color_Clear_Value return Colors.Color is
Value : Colors.Color;
begin
API.Get_Color (Enums.Getter.Color_Clear_Value, Value);
Raise_Exception_On_OpenGL_Error;
return Value;
end Color_Clear_Value;
procedure Set_Depth_Clear_Value (Value : Depth) is
begin
API.Clear_Depth (Value);
Raise_Exception_On_OpenGL_Error;
end Set_Depth_Clear_Value;
function Depth_Clear_Value return Depth is
Value : aliased Double;
begin
API.Get_Double (Enums.Getter.Depth_Clear_Value, Value'Access);
Raise_Exception_On_OpenGL_Error;
return Value;
end Depth_Clear_Value;
procedure Set_Stencil_Clear_Value (Value : Stencil_Index) is
begin
API.Clear_Stencil (Value);
Raise_Exception_On_OpenGL_Error;
end Set_Stencil_Clear_Value;
function Stencil_Clear_Value return Stencil_Index is
Value : aliased Stencil_Index;
begin
API.Get_Integer (Enums.Getter.Stencil_Clear_Value, Value'Access);
Raise_Exception_On_OpenGL_Error;
return Value;
end Stencil_Clear_Value;
procedure Set_Accum_Clear_Value (Value : Colors.Color) is
begin
API.Clear_Accum (Value (Colors.R), Value (Colors.G), Value (Colors.B),
Value (Colors.A));
Raise_Exception_On_OpenGL_Error;
end Set_Accum_Clear_Value;
function Accum_Clear_Value return Colors.Color is
Value : Colors.Color;
begin
API.Get_Color (Enums.Getter.Accum_Clear_Value, Value);
Raise_Exception_On_OpenGL_Error;
return Value;
end Accum_Clear_Value;
procedure Set_Depth_Function (Func : Compare_Function) is
begin
API.Depth_Func (Func);
Raise_Exception_On_OpenGL_Error;
end Set_Depth_Function;
function Depth_Function return Compare_Function is
Value : aliased Compare_Function;
begin
API.Get_Compare_Function (Enums.Getter.Depth_Func, Value'Access);
Raise_Exception_On_OpenGL_Error;
return Value;
end Depth_Function;
procedure Depth_Mask (Enabled : Boolean) is
begin
API.Depth_Mask (Low_Level.Bool (Enabled));
Raise_Exception_On_OpenGL_Error;
end Depth_Mask;
function Depth_Mask return Boolean is
Value : aliased Low_Level.Bool;
begin
API.Get_Boolean (Enums.Getter.Depth_Writemask, Value'Access);
Raise_Exception_On_OpenGL_Error;
return Boolean (Value);
end Depth_Mask;
procedure Set_Stencil_Function (Func : Compare_Function;
Ref : Int;
Mask : UInt) is
Face : constant Culling.Face_Selector := Culling.Front_And_Back;
begin
Set_Stencil_Function (Face, Func, Ref, Mask);
end Set_Stencil_Function;
procedure Set_Stencil_Function (Face : Culling.Face_Selector;
Func : Compare_Function;
Ref : Int;
Mask : UInt) is
begin
API.Stencil_Func_Separate (Face, Func, Ref, Mask);
Raise_Exception_On_OpenGL_Error;
end Set_Stencil_Function;
function Stencil_Function (Face : Single_Face_Selector) return Compare_Function is
Value : aliased Compare_Function;
begin
if Face = Culling.Front then
API.Get_Compare_Function (Enums.Getter.Stencil_Func, Value'Access);
else
API.Get_Compare_Function (Enums.Getter.Stencil_Back_Func, Value'Access);
end if;
Raise_Exception_On_OpenGL_Error;
return Value;
end Stencil_Function;
function Stencil_Reference_Value (Face : Single_Face_Selector) return Int is
Value : aliased Int;
begin
if Face = Culling.Front then
API.Get_Integer (Enums.Getter.Stencil_Ref, Value'Access);
else
API.Get_Integer (Enums.Getter.Stencil_Back_Ref, Value'Access);
end if;
Raise_Exception_On_OpenGL_Error;
return Value;
end Stencil_Reference_Value;
function Stencil_Value_Mask (Face : Single_Face_Selector) return UInt is
Value : aliased UInt;
begin
if Face = Culling.Front then
API.Get_Unsigned_Integer (Enums.Getter.Stencil_Value_Mask, Value'Access);
else
API.Get_Unsigned_Integer (Enums.Getter.Stencil_Back_Value_Mask, Value'Access);
end if;
Raise_Exception_On_OpenGL_Error;
return Value;
end Stencil_Value_Mask;
procedure Set_Stencil_Operation (Stencil_Fail : Buffers.Stencil_Action;
Depth_Fail : Buffers.Stencil_Action;
Depth_Pass : Buffers.Stencil_Action) is
Face : constant Culling.Face_Selector := Culling.Front_And_Back;
begin
Set_Stencil_Operation (Face, Stencil_Fail, Depth_Fail, Depth_Pass);
end Set_Stencil_Operation;
procedure Set_Stencil_Operation (Face : Culling.Face_Selector;
Stencil_Fail : Buffers.Stencil_Action;
Depth_Fail : Buffers.Stencil_Action;
Depth_Pass : Buffers.Stencil_Action) is
begin
API.Stencil_Op_Separate (Face, Stencil_Fail, Depth_Fail, Depth_Pass);
Raise_Exception_On_OpenGL_Error;
end Set_Stencil_Operation;
function Stencil_Operation_Stencil_Fail (Face : Single_Face_Selector) return Buffers.Stencil_Action is
Value : aliased Buffers.Stencil_Action;
begin
if Face = Culling.Front then
API.Get_Stencil_Action (Enums.Getter.Stencil_Fail, Value'Access);
else
API.Get_Stencil_Action (Enums.Getter.Stencil_Back_Fail, Value'Access);
end if;
Raise_Exception_On_OpenGL_Error;
return Value;
end Stencil_Operation_Stencil_Fail;
function Stencil_Operation_Depth_Fail (Face : Single_Face_Selector) return Buffers.Stencil_Action is
Value : aliased Buffers.Stencil_Action;
begin
if Face = Culling.Front then
API.Get_Stencil_Action (Enums.Getter.Stencil_Pass_Depth_Fail, Value'Access);
else
API.Get_Stencil_Action (Enums.Getter.Stencil_Back_Pass_Depth_Fail, Value'Access);
end if;
Raise_Exception_On_OpenGL_Error;
return Value;
end Stencil_Operation_Depth_Fail;
function Stencil_Operation_Depth_Pass (Face : Single_Face_Selector) return Buffers.Stencil_Action is
Value : aliased Buffers.Stencil_Action;
begin
if Face = Culling.Front then
API.Get_Stencil_Action (Enums.Getter.Stencil_Pass_Depth_Pass, Value'Access);
else
API.Get_Stencil_Action (Enums.Getter.Stencil_Back_Pass_Depth_Pass, Value'Access);
end if;
Raise_Exception_On_OpenGL_Error;
return Value;
end Stencil_Operation_Depth_Pass;
procedure Set_Stencil_Mask (Value : UInt) is
Face : constant Culling.Face_Selector := Culling.Front_And_Back;
begin
Set_Stencil_Mask (Face, Value);
end Set_Stencil_Mask;
procedure Set_Stencil_Mask (Face : Culling.Face_Selector;
Value : UInt) is
begin
API.Stencil_Mask_Separate (Face, Value);
Raise_Exception_On_OpenGL_Error;
end Set_Stencil_Mask;
function Stencil_Mask (Face : Single_Face_Selector) return UInt is
Value : aliased UInt;
begin
if Face = Culling.Front then
API.Get_Unsigned_Integer (Enums.Getter.Stencil_Writemask, Value'Access);
else
API.Get_Unsigned_Integer (Enums.Getter.Stencil_Back_Writemask, Value'Access);
end if;
Raise_Exception_On_OpenGL_Error;
return Value;
end Stencil_Mask;
procedure Clear_Color_Buffers (Selector : Base_Color_Buffer_Selector;
Value : Colors.Color) is
begin
API.Clear_Buffer (Selector, 0, Value);
Raise_Exception_On_OpenGL_Error;
end Clear_Color_Buffers;
procedure Clear_Draw_Buffer (Index : Draw_Buffer_Index;
Value : Colors.Color) is
begin
API.Clear_Draw_Buffer (Low_Level.Enums.Color, Index, Value);
Raise_Exception_On_OpenGL_Error;
end Clear_Draw_Buffer;
procedure Clear_Depth_Buffer (Value : Depth) is
Aliased_Value : aliased constant Depth := Value;
begin
API.Clear_Buffer_Depth (Low_Level.Enums.Depth_Buffer, 0,
Aliased_Value'Unchecked_Access);
Raise_Exception_On_OpenGL_Error;
end Clear_Depth_Buffer;
procedure Clear_Stencil_Buffer (Value : Stencil_Index) is
Aliased_Value : aliased constant Stencil_Index := Value;
begin
API.Clear_Buffer_Stencil (Low_Level.Enums.Stencil, 0,
Aliased_Value'Unchecked_Access);
Raise_Exception_On_OpenGL_Error;
end Clear_Stencil_Buffer;
procedure Clear_Depth_And_Stencil_Buffer (Depth_Value : Depth;
Stencil_Value : Stencil_Index) is
begin
API.Clear_Buffer_Depth_Stencil (Low_Level.Enums.Depth_Stencil, 0,
Depth_Value, Stencil_Value);
Raise_Exception_On_OpenGL_Error;
end Clear_Depth_And_Stencil_Buffer;
end GL.Buffers;
|
with
float_Math.Geometry.D2,
float_Math.Geometry.D3,
float_Math.Algebra.linear.D3;
package Physics
--
-- Provides a physics interface for 2D/3D simulations.
--
is
pragma Pure;
package Math renames float_Math;
package Geometry_2D renames math.Geometry.d2;
package Geometry_3D renames math.Geometry.d3;
package linear_Algebra_3D renames math.Algebra.linear.d3;
use Math;
type Vector_2_array is array (Positive range <>) of Vector_2;
type Vector_3_array is array (Positive range <>) of Vector_3;
type Heightfield is array (Positive range <>,
Positive range <>) of aliased Real;
type space_Kind is (Bullet, Box2D);
max_Models : constant := 2**32 - 1;
type model_Id is range 0 .. max_Models;
null_model_Id : constant physics.model_Id;
unsupported_Error : exception;
--
-- Raised when a shape or joint is not supported in a space.
private
null_model_Id : constant physics.model_Id := 0;
end Physics;
|
-- 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 Ada.Containers.Indefinite_Hashed_Maps;
with Ada.Strings.Fixed;
with Ada.Strings.Hash;
with Ada.Strings.Unbounded;
with Ada.Streams;
with Ada.Unchecked_Conversion;
with GL.Pixels.Extensions;
with GL.Types;
package body Orka.Frame_Graphs is
package PE renames GL.Pixels.Extensions;
type Attachment_Format is (Depth_Stencil, Depth, Stencil, Color);
function Name (Object : Resource_Data) return String is (+Object.Description.Name);
procedure Find_Resource
(Object : in out Builder;
Subject : Resource;
Handle : out Handle_Type;
Found : out Boolean)
is
use type Name_Strings.Bounded_String;
begin
Found := False;
for Index in 1 .. Object.Resources.Length loop
declare
Description : Resource renames Object.Resources (Index).Description;
Implicit : Boolean renames Object.Resources (Index).Implicit;
begin
if Subject.Name = Description.Name and Subject.Version = Description.Version
and not Implicit
then
if Description /= Subject then
raise Constraint_Error with
"Already added different resource '" & (+Subject.Name) & "'";
end if;
Found := True;
Handle := Index;
exit;
end if;
end;
end loop;
end Find_Resource;
procedure Add_Resource
(Object : in out Builder;
Subject : Resource;
Handle : out Handle_Type)
is
Found : Boolean;
begin
Object.Find_Resource (Subject, Handle, Found);
if not Found then
Object.Resources.Append
((Description => Subject,
others => <>));
Handle := Object.Resources.Length;
end if;
end Add_Resource;
procedure Verify_Depth_Stencil
(Pass : Render_Pass_Data;
Format : Attachment_Format) is
begin
if Pass.Has_Depth and then Format in Depth_Stencil | Depth then
raise Program_Error with
"Render pass '" & Name (Pass) & "' already has a depth attachment";
end if;
if Pass.Has_Stencil and then Format in Depth_Stencil | Stencil then
raise Program_Error with
"Render pass '" & Name (Pass) & "' already has a stencil attachment";
end if;
end Verify_Depth_Stencil;
procedure Set_Depth_Stencil
(Pass : in out Render_Pass_Data;
Format : Attachment_Format) is
begin
if Format in Depth_Stencil | Depth then
Pass.Has_Depth := True;
end if;
if Format in Depth_Stencil | Stencil then
Pass.Has_Stencil := True;
end if;
end Set_Depth_Stencil;
function Get_Attachment_Format
(Format : GL.Pixels.Internal_Format) return Attachment_Format is
begin
if PE.Depth_Stencil_Format (Format) then
return Depth_Stencil;
elsif PE.Depth_Format (Format) then
return Depth;
elsif PE.Stencil_Format (Format) then
return Stencil;
else
return Color;
end if;
end Get_Attachment_Format;
procedure Execute_Present (Pass : Render_Pass_Data) is null;
use type GL.Objects.Textures.Texture;
package Texture_Maps is new Ada.Containers.Indefinite_Hashed_Maps
(Key_Type => String,
Element_Type => GL.Objects.Textures.Texture,
Hash => Ada.Strings.Hash,
Equivalent_Keys => "=");
Textures : Texture_Maps.Map;
function Get_Texture (Subject : Resource) return GL.Objects.Textures.Texture is
begin
return Textures.Element (+Subject.Name);
exception
when Constraint_Error =>
declare
Result : GL.Objects.Textures.Texture (Subject.Kind);
begin
Result.Allocate_Storage
(Levels => GL.Types.Size (Subject.Levels),
Samples => GL.Types.Size (Subject.Samples),
Format => Subject.Format,
Width => GL.Types.Size (Subject.Extent.Width),
Height => GL.Types.Size (Subject.Extent.Height),
Depth => GL.Types.Size (Subject.Extent.Depth));
Textures.Insert (+Subject.Name, Result);
return Result;
end;
end Get_Texture;
-----------------------------------------------------------------------------
function "+" (Value : Name_Strings.Bounded_String) return String is
(Name_Strings.To_String (Value));
function "+" (Value : String) return Name_Strings.Bounded_String is
(Name_Strings.To_Bounded_String (Value));
function Name (Object : Render_Pass) return String is
(+Object.Frame_Graph.Passes (Object.Index).Name);
function Name (Pass : Render_Pass_Data) return String is (+Pass.Name);
-----------------------------------------------------------------------------
procedure Add_Input
(Object : Render_Pass;
Subject : Resource;
Read : Read_Mode;
Handle : out Handle_Type;
Implicit : Boolean);
function Add_Pass
(Object : in out Builder;
Name : String;
Execute : not null Execute_Callback;
Side_Effect, Present : Boolean) return Render_Pass'Class is
begin
Object.Passes.Append
((Name => +Name,
Execute => Execute,
Side_Effect => Side_Effect,
others => <>));
return Render_Pass'
(Frame_Graph => Object'Access,
Index => Object.Passes.Length);
end Add_Pass;
function Add_Pass
(Object : in out Builder;
Name : String;
Execute : not null Execute_Callback;
Side_Effect : Boolean := False) return Render_Pass'Class
is (Object.Add_Pass (Name, Execute, Side_Effect => Side_Effect, Present => False));
procedure Add_Present
(Object : in out Builder;
Subject : Resource;
Handle : out Handle_Type)
is
Found : Boolean;
begin
Object.Find_Resource (Subject, Handle, Found);
if not Found then
raise Constraint_Error with "Presented resource not found in graph";
end if;
declare
Pass : constant Render_Pass'Class := Object.Add_Pass
("Present", Execute_Present'Access, Side_Effect => True, Present => True);
Resource : Resource_Data renames Object.Resources (Handle);
begin
-- The present pass does not actually read the resource: the previous
-- render pass will use the default framebuffer to write to the
-- resource or the present pass will blit or render the resource to
-- the default framebuffer
Render_Pass (Pass).Add_Input (Subject, Resource.Input_Mode, Handle, Implicit => False);
Object.Present_Pass := Pass.Index;
end;
end Add_Present;
-----------------------------------------------------------------------------
procedure Add_Output
(Object : Render_Pass;
Subject : Resource;
Write : Write_Mode;
Handle : out Handle_Type;
Implicit : Boolean)
is
Graph : Orka.Frame_Graphs.Builder renames Object.Frame_Graph.all;
Pass : Render_Pass_Data renames Graph.Passes (Object.Index);
Attachment : constant Attachment_Format := Get_Attachment_Format (Subject.Format);
begin
if Pass.Write_Count > 0 and then
Pass.Write_Offset + Pass.Write_Count /= Graph.Write_Handles.Length + 1
then
raise Program_Error with "Cannot interleave Add_Output calls for different passes";
end if;
if Implicit and Write = Framebuffer_Attachment then
Verify_Depth_Stencil (Pass, Attachment);
declare
Handle : Handle_Type;
Prev_Subject : Resource := Subject;
begin
Prev_Subject.Version.Version := Subject.Version.Version - 1;
Object.Add_Input (Prev_Subject, Framebuffer_Attachment, Handle, Implicit => False);
Graph.Resources (Handle).Implicit := True;
end;
end if;
Add_Resource (Graph, Subject, Handle);
declare
Resource : Resource_Data renames Graph.Resources (Handle);
begin
if Resource.Render_Pass /= 0 then
raise Constraint_Error with "Resource '" & Name (Resource) & "'" &
" already written by pass '" & (+Graph.Passes (Resource.Render_Pass).Name) & "'";
end if;
pragma Assert (Resource.Output_Mode = Not_Used);
Resource.Render_Pass := Object.Index;
Resource.Output_Mode := Write;
end;
-- Register resource as 'written' by the render pass
Graph.Write_Handles.Append (Handle);
if Pass.Write_Count = 0 then
Pass.Write_Offset := Graph.Write_Handles.Length;
end if;
Pass.Write_Count := Pass.Write_Count + 1;
Set_Depth_Stencil (Pass, Attachment);
end Add_Output;
procedure Add_Output
(Object : Render_Pass;
Subject : Resource;
Write : Write_Mode)
is
Handle : Handle_Type;
begin
Object.Add_Output (Subject, Write, Handle, Implicit => True);
pragma Assert (Object.Frame_Graph.Resources (Handle).Output_Mode = Write);
end Add_Output;
procedure Add_Input
(Object : Render_Pass;
Subject : Resource;
Read : Read_Mode;
Handle : out Handle_Type;
Implicit : Boolean)
is
Graph : Orka.Frame_Graphs.Builder renames Object.Frame_Graph.all;
Pass : Render_Pass_Data renames Graph.Passes (Object.Index);
Attachment : constant Attachment_Format := Get_Attachment_Format (Subject.Format);
begin
if Pass.Read_Count > 0 and then
Pass.Read_Offset + Pass.Read_Count /= Graph.Read_Handles.Length + 1
then
raise Program_Error with "Cannot interleave Add_Input calls for different passes";
end if;
if Implicit and Read = Framebuffer_Attachment then
if Attachment = Color then
raise Program_Error with "Use Add_Output or Add_Input_Output for color resource";
end if;
Verify_Depth_Stencil (Pass, Attachment);
declare
Handle : Handle_Type;
Next_Subject : Resource := Subject;
begin
Next_Subject.Version.Version := Subject.Version.Version + 1;
Object.Add_Output (Next_Subject, Framebuffer_Attachment, Handle, Implicit => False);
Graph.Resources (Handle).Implicit := True;
end;
end if;
Add_Resource (Graph, Subject, Handle);
declare
Resource : Resource_Data renames Graph.Resources (Handle);
begin
-- Resource is not considered modified if the next version is implicit
if Resource.Modified then
raise Constraint_Error with
"Cannot read old version of modified resource '" & Name (Resource) & "'";
end if;
-- Because a resource records only one input mode, verify this
-- resource is read by multiple render passes using only one
-- particular method
if Resource.Input_Mode /= Not_Used and Resource.Input_Mode /= Read then
raise Constraint_Error with
"Resource '" & Name (Resource) & "' must be read as " & Resource.Input_Mode'Image;
end if;
Resource.Read_Count := Resource.Read_Count + 1;
Resource.Input_Mode := Read;
end;
-- Register resource as 'read' by the render pass
Graph.Read_Handles.Append (Handle);
if Pass.Read_Count = 0 then
Pass.Read_Offset := Graph.Read_Handles.Length;
end if;
Pass.Read_Count := Pass.Read_Count + 1;
Set_Depth_Stencil (Pass, Attachment);
end Add_Input;
procedure Add_Input
(Object : Render_Pass;
Subject : Resource;
Read : Read_Mode)
is
Handle : Handle_Type;
begin
Object.Add_Input (Subject, Read, Handle, Implicit => True);
pragma Assert (Object.Frame_Graph.Resources (Handle).Input_Mode = Read);
end Add_Input;
function Add_Input_Output
(Object : Render_Pass;
Subject : Resource;
Read : Read_Mode;
Write : Write_Mode) return Resource
is
Graph : Orka.Frame_Graphs.Builder renames Object.Frame_Graph.all;
Handle : Handle_Type;
Next_Subject : Resource := Subject;
begin
Object.Add_Input (Subject, Read, Handle, Implicit => False);
declare
Resource : Resource_Data renames Graph.Resources (Handle);
begin
Resource.Modified := True;
end;
Next_Subject.Version.Version := Subject.Version.Version + 1;
Object.Add_Output (Next_Subject, Write, Handle, Implicit => False);
return Next_Subject;
end Add_Input_Output;
function Cull (Object : Builder; Present : Resource) return Graph'Class is
Stack : Handle_Vectors.Vector (Positive (Object.Resources.Length));
Index : Handle_Type;
begin
return Result : Graph
(Maximum_Passes => Object.Maximum_Passes,
Maximum_Handles => Object.Maximum_Handles,
Maximum_Resources => Object.Maximum_Resources)
do
-- Copy data structures before culling
Result.Graph.Passes := Object.Passes;
Result.Graph.Resources := Object.Resources;
Result.Graph.Read_Handles := Object.Read_Handles;
Result.Graph.Write_Handles := Object.Write_Handles;
Add_Present (Result.Graph, Present, Index);
declare
Resource : Resource_Data renames Result.Graph.Resources (Index);
begin
if Resource.Render_Pass = 0 then
raise Constraint_Error with "Presented resource not written by a pass";
end if;
end;
-- Raise an error if there is a render pass that will be
-- culled immediately. This simplifies the stack so that it
-- only needs to contain indices of resources.
for Pass of Result.Graph.Passes loop
Pass.References := Pass.Write_Count;
if not Pass.Side_Effect and Pass.References = 0 then
raise Constraint_Error with
"Render pass '" & (+Pass.Name) & "' does not write to any resource";
end if;
end loop;
for Index in 1 .. Result.Graph.Resources.Length loop
declare
Resource : Resource_Data renames Result.Graph.Resources (Index);
begin
Resource.References := Resource.Read_Count;
if Resource.References = 0 then
if Resource.Render_Pass = 0 then
raise Constraint_Error with
"Resource '" & Name (Resource) & " not connected";
end if;
Stack.Append (Index);
end if;
end;
end loop;
while not Stack.Is_Empty loop
Stack.Remove_Last (Index);
declare
-- Pass is the render pass that writes to the resource
Resource : Resource_Data renames Result.Graph.Resources (Index);
Pass : Render_Pass_Data renames Result.Graph.Passes (Resource.Render_Pass);
-- Assert that the render pass does write to the resource
Write_Offset : Positive renames Pass.Write_Offset;
Write_Count : Natural renames Pass.Write_Count;
pragma Assert
(for some Offset in Write_Offset .. Write_Offset + Write_Count - 1 =>
Result.Graph.Write_Handles (Offset) = Index);
begin
Pass.References := Pass.References - 1;
-- Update ref count of resources read by the render pass
-- if the render pass got culled
if not Pass.Side_Effect and Pass.References = 0 then
for Index in Pass.Read_Offset .. Pass.Read_Offset + Pass.Read_Count - 1 loop
declare
Resource_Handle : constant Handle_Type :=
Result.Graph.Read_Handles (Index);
Resource : Resource_Data renames
Result.Graph.Resources (Resource_Handle);
begin
Resource.References := Resource.References - 1;
if Resource.References = 0 and Resource.Render_Pass /= 0 then
Stack.Append (Resource_Handle);
end if;
end;
end loop;
end if;
end;
end loop;
-- Here we are done with culling. Next step is to iterate over
-- the passes that survived culling and create framebuffers and
-- textures.
end return;
end Cull;
procedure Initialize
(Object : in out Graph;
Default : Rendering.Framebuffers.Framebuffer)
is
subtype Selector_Type is GL.Buffers.Explicit_Color_Buffer_Selector;
subtype Buffer_Type is GL.Buffers.Draw_Buffer_Index;
subtype Point_Type is Rendering.Framebuffers.Color_Attachment_Point;
use type GL.Low_Level.Enums.Texture_Kind;
type Present_Mode_Type is (Use_Default, Blit_To_Default, Render_To_Default);
Present_Pass : Render_Pass_Data renames Object.Graph.Passes (Object.Graph.Present_Pass);
pragma Assert (Present_Pass.Read_Count = 1);
Default_Extent : constant Extent_3D :=
(Natural (Default.Width), Natural (Default.Height), 1);
Last_Pass_Index : Positive;
Present_Mode : Present_Mode_Type;
begin
declare
-- Look up the resource that is going to be presented to the screen
Resource_Handle : constant Handle_Type
:= Object.Graph.Read_Handles (Present_Pass.Read_Offset);
Resource : Resource_Data renames Object.Graph.Resources (Resource_Handle);
-- Look up the last render pass *before* the present pass
Last_Render_Pass : Render_Pass_Data renames Object.Graph.Passes (Resource.Render_Pass);
Attachments : Natural := 0;
Current_Point, Color_Attachment : Point_Type := Point_Type'First;
begin
Last_Pass_Index := Resource.Render_Pass;
-- Mode 1: Previous render pass has one FB color attachment (this resource)
-- Action: Previous render pass can use the default framebuffer
--
-- Mode 2: Previous render pass has multiple FB color attachments
-- or resource is a depth and/or stencil attachment
-- Action: Blit the resource to the default framebuffer
--
-- Mode 3: Resource is not written as a FB color attachment
-- Action: Bind the resource as a texture and render to the
-- default framebuffer
if Resource.Output_Mode /= Framebuffer_Attachment then
-- Mode 3
-- TODO Bind resource as texture and render to default framebuffer
Present_Mode := Render_To_Default;
raise Program_Error with "Not implemented mode 3 yet";
else
for Last_Resource of Object.Output_Resources (Last_Render_Pass) loop
if Last_Resource.Mode = Framebuffer_Attachment and then
Get_Attachment_Format (Last_Resource.Data.Format) = Color
then
Attachments := Attachments + 1;
-- TODO Handle depth/stencil resources for mode 2
-- TODO Getting the attachment point is only needed for mode 2
if Last_Resource.Data = Resource.Description then
Color_Attachment := Current_Point;
end if;
Current_Point := Point_Type'Succ (Current_Point);
end if;
end loop;
if Attachments = 1 and Get_Attachment_Format (Resource.Description.Format) = Color
and Resource.Description.Kind = GL.Low_Level.Enums.Texture_2D
and Resource.Description.Extent = Default_Extent
and Resource.Description.Samples = Natural (Default.Samples)
then
-- Mode 1: Use Default as the framebuffer of Last_Render_Pass
Present_Mode := Use_Default;
else
-- Mode 2
-- TODO Last_Render_Pass.Framebuffer.Set_Read_Buffer (Color_Attachment);
-- TODO Last_Render_Pass.Framebuffer.Resolve_To (Default);
Present_Mode := Blit_To_Default;
raise Program_Error with "Not implemented mode 2 yet";
end if;
end if;
end;
for Index in 1 .. Object.Graph.Passes.Length loop
declare
Pass : Render_Pass_Data renames Object.Graph.Passes (Index);
Width, Height : Natural := Natural'First;
Clear_Mask : GL.Buffers.Buffer_Bits := (others => False);
Invalidate_Mask : GL.Buffers.Buffer_Bits := (others => False);
-- If Clear_Buffers = Render_Buffers then we only need to call
-- Set_Draw_Buffers once after creating the framebuffer, otherwise
-- buffers need to be set before clearing and rendering
Clear_Buffers : GL.Buffers.Color_Buffer_List (0 .. 7) := (others => GL.Buffers.None);
Render_Buffers : GL.Buffers.Color_Buffer_List (0 .. 7) := (others => GL.Buffers.None);
Buffers_Equal : Boolean := False;
-- TODO Use Draw_Buffer_Index as index type and drop some in Set_Draw_Buffers
Invalidate_Points : Rendering.Framebuffers.Use_Point_Array := (others => False);
-- For draw buffers
Current_Selector : Selector_Type := Selector_Type'First;
Current_Buffer : Buffer_Type := Buffer_Type'First;
-- For invalidating color attachments
Current_Point : Point_Type := Point_Type'First;
Depth_Writes, Stencil_Writes : Boolean := True;
Clear_Buffer, Invalidate_Buffer : Boolean;
begin
if Pass.Side_Effect or Pass.References > 0 then
-- Clear input resources read as framebuffer attachments
-- which are new (not written by a previous render pass)
for Resource of Object.Input_Resources (Pass) loop
if Resource.Mode = Framebuffer_Attachment then
Clear_Buffer := not Resource.Written;
if PE.Depth_Stencil_Format (Resource.Data.Format) then
Clear_Mask.Depth := Clear_Buffer;
Clear_Mask.Stencil := Clear_Buffer;
elsif PE.Depth_Format (Resource.Data.Format) then
Clear_Mask.Depth := Clear_Buffer;
elsif PE.Stencil_Format (Resource.Data.Format) then
Clear_Mask.Stencil := Clear_Buffer;
else
-- Clear the color buffers, but only those that
-- do not have a render pass that writes to it
if Clear_Buffer then
Clear_Buffers (Current_Buffer) := Current_Selector;
Clear_Mask.Color := True;
end if;
Current_Selector := Selector_Type'Succ (Current_Selector);
Current_Buffer := Buffer_Type'Succ (Current_Buffer);
end if;
end if;
end loop;
Current_Selector := Selector_Type'First;
Current_Buffer := Buffer_Type'First;
-- Invalidate output attachments that are transcient
-- (not read by a subsequent render pass)
for Resource of Object.Output_Resources (Pass) loop
if Resource.Mode = Framebuffer_Attachment then
Invalidate_Buffer := not Resource.Read;
if PE.Depth_Stencil_Format (Resource.Data.Format) then
Invalidate_Mask.Depth := Invalidate_Buffer;
Invalidate_Mask.Stencil := Invalidate_Buffer;
Depth_Writes := not Resource.Implicit;
Stencil_Writes := not Resource.Implicit;
elsif PE.Depth_Format (Resource.Data.Format) then
Invalidate_Mask.Depth := Invalidate_Buffer;
Depth_Writes := not Resource.Implicit;
elsif PE.Stencil_Format (Resource.Data.Format) then
Invalidate_Mask.Stencil := Invalidate_Buffer;
Stencil_Writes := not Resource.Implicit;
else
-- Invalidate the color buffers, but only those that
-- are not read by a subsequent render pass
if Invalidate_Buffer then
Invalidate_Points (Current_Point) := True;
Invalidate_Mask.Color := True;
end if;
-- Even if the resource is not read, the buffer is
-- still used as a draw buffer because the shader
-- will probably render to it
Render_Buffers (Current_Buffer) := Current_Selector;
Current_Selector := Selector_Type'Succ (Current_Selector);
Current_Buffer := Buffer_Type'Succ (Current_Buffer);
Current_Point := Point_Type'Succ (Current_Point);
end if;
end if;
-- Compute maximum width and height over all the output
-- resources (which may be attached to the framebuffer).
-- Ideally all attachments have the same extent, but the
-- GL spec allows for them to be different. Furthermore,
-- a framebuffer may have zero attachments, so iterate over
-- all resources irrespective of their write mode.
Width := Natural'Max (Width, Resource.Data.Extent.Width);
Height := Natural'Max (Height, Resource.Data.Extent.Height);
end loop;
if Pass.Write_Count = 0 then
pragma Assert (Pass.Side_Effect);
-- Use width and height from default framebuffer
Width := Natural (Default.Width);
Height := Natural (Default.Height);
else
pragma Assert (Width > 0 and Height > 0);
end if;
declare
use type GL.Buffers.Color_Buffer_List;
begin
-- Output attachments always have a corresponding
-- input resource (implicit if necessary), but if
-- the resource is not new (written by previous pass)
-- then the resource is not cleared
Buffers_Equal := Clear_Buffers = Render_Buffers;
end;
Object.Framebuffers.Append
((Index => Index,
Framebuffer => Framebuffer_Holders.To_Holder
(if Present_Mode = Use_Default and Last_Pass_Index = Index then
Default
else
Rendering.Framebuffers.Create_Framebuffer
(Width => GL.Types.Size (Width),
Height => GL.Types.Size (Height))),
Clear_Mask => Clear_Mask,
Invalidate_Mask => Invalidate_Mask,
Clear_Buffers => Clear_Buffers,
Render_Buffers => Render_Buffers,
Buffers_Equal => Buffers_Equal,
Invalidate_Points => Invalidate_Points,
Depth_Writes => Depth_Writes,
Stencil_Writes => Stencil_Writes));
declare
procedure Set_Buffers
(Framebuffer : in out Rendering.Framebuffers.Framebuffer)
is
use type GL.Buffers.Color_Buffer_Selector;
use type GL.Types.UInt;
begin
-- Clear color to black and depth to 0.0 (because of reversed Z)
Framebuffer.Set_Default_Values
((Color => (0.0, 0.0, 0.0, 1.0), Depth => 0.0, others => <>));
if Framebuffer.Default then
-- The resource is 'read' by the present pass
pragma Assert (not Invalidate_Mask.Color);
if not Buffers_Equal then
pragma Assert
(for all Buffer of Clear_Buffers => Buffer = GL.Buffers.None);
end if;
if Present_Mode = Use_Default then
pragma Assert (Render_Buffers
(Render_Buffers'First) = GL.Buffers.Color_Attachment0);
pragma Assert
(for all Index in Render_Buffers'First + 1 .. Render_Buffers'Last =>
Render_Buffers (Index) = GL.Buffers.None);
-- Not calling Set_Draw_Buffers because the default
-- framebuffer already has an initial draw buffer
-- (GL.Buffers.Back_Left for double-buffered context)
end if;
else
if Buffers_Equal then
Framebuffer.Set_Draw_Buffers (Render_Buffers);
end if;
Current_Point := Point_Type'First;
for Resource of Object.Input_Resources (Pass) loop
if Resource.Mode = Framebuffer_Attachment then
-- TODO Use Resource.Data.Extent.Depth if resource is layered
if Get_Attachment_Format (Resource.Data.Format) /= Color then
Framebuffer.Attach (Get_Texture (Resource.Data));
else
Framebuffer.Attach
(Current_Point, Get_Texture (Resource.Data));
Current_Point := Point_Type'Succ (Current_Point);
end if;
end if;
end loop;
end if;
end Set_Buffers;
begin
Object.Framebuffers
(Object.Framebuffers.Length).Framebuffer.Update_Element
(Set_Buffers'Access);
end;
end if;
end;
end loop;
end Initialize;
procedure Render (Object : in out Graph) is
begin
for Data of Object.Framebuffers loop
declare
Pass : Render_Pass_Data renames Object.Graph.Passes (Data.Index);
pragma Assert (Pass.Side_Effect or else Pass.References > 0);
procedure Execute_Pass (Framebuffer : in out Rendering.Framebuffers.Framebuffer) is
begin
Framebuffer.Use_Framebuffer;
-- TODO Only change pipeline state if different w.r.t. previous pass
GL.Buffers.Set_Depth_Mask (True);
GL.Buffers.Set_Stencil_Mask (2#1111_1111#);
if not Data.Buffers_Equal then
Framebuffer.Set_Draw_Buffers (Data.Clear_Buffers);
end if;
Framebuffer.Clear (Data.Clear_Mask);
-- TODO Bind textures and images (or in procedure Cull?)
-- (for Resource of Object.Input_Resources (Pass))
if not Data.Buffers_Equal then
Framebuffer.Set_Draw_Buffers (Data.Render_Buffers);
end if;
-- TODO Only change pipeline state if different w.r.t. previous pass
GL.Buffers.Set_Depth_Mask (Data.Depth_Writes);
GL.Buffers.Set_Stencil_Mask (if Data.Stencil_Writes then 2#1111_1111# else 0);
Pass.Execute (Pass);
-- Invalidate attachments that are transcient
-- (not read by a subsequent render pass)
Framebuffer.Invalidate (Data.Invalidate_Mask);
-- TODO Use Data.Invalidate_Points for the color attachment points
end Execute_Pass;
begin
Data.Framebuffer.Update_Element (Execute_Pass'Access);
end;
end loop;
end Render;
function Input_Resources
(Object : Graph;
Pass : Render_Pass_Data) return Input_Resource_Array is
begin
return Result : Input_Resource_Array (1 .. Pass.Read_Count) do
for Index in 1 .. Pass.Read_Count loop
declare
Data : Resource_Data renames Object.Graph.Resources
(Object.Graph.Read_Handles (Pass.Read_Offset + Index - 1));
begin
Result (Index) := (Mode => Data.Input_Mode,
Data => Data.Description,
Written => Data.Render_Pass /= 0,
Implicit => Data.Implicit);
end;
end loop;
end return;
end Input_Resources;
function Output_Resources
(Object : Graph;
Pass : Render_Pass_Data) return Output_Resource_Array is
begin
return Result : Output_Resource_Array (1 .. Pass.Write_Count) do
for Index in 1 .. Pass.Write_Count loop
declare
Data : Resource_Data renames Object.Graph.Resources
(Object.Graph.Write_Handles (Pass.Write_Offset + Index - 1));
begin
Result (Index) := (Mode => Data.Output_Mode,
Data => Data.Description,
Read => Data.References > 0,
Implicit => Data.Implicit);
end;
end loop;
end return;
end Output_Resources;
----------------------------------------------------------------------
procedure Write_Graph
(Object : in out Graph;
Location : Resources.Locations.Writable_Location_Ptr;
Path : String)
is
package SU renames Ada.Strings.Unbounded;
package SF renames Ada.Strings.Fixed;
function Trim (Value : String) return String is (SF.Trim (Value, Ada.Strings.Both));
function Image (Value : String) return String is ('"' & Value & '"');
function Image (Value : Integer) return String is (Trim (Value'Image));
function Image (Value : Boolean) return String is (if Value then "true" else "false");
Result : SU.Unbounded_String;
First : Boolean;
procedure Append (Key, Value : String; Comma : Boolean := False) is
begin
SU.Append (Result, '"' & Key & '"' & ':' & Value);
if Comma then
SU.Append (Result, ',');
end if;
end Append;
procedure Append_Comma is
begin
if not First then
SU.Append (Result, ',');
end if;
First := False;
end Append_Comma;
begin
SU.Append (Result, "{");
-- Vertices (render passes and resources)
First := True;
Append ("passes", "[");
for Pass of Object.Graph.Passes loop
Append_Comma;
SU.Append (Result, '{');
Append ("name", Image (+Pass.Name), True);
Append ("readCount", Image (Pass.Read_Count), True);
Append ("writeCount", Image (Pass.Write_Count), True);
Append ("sideEffect", Image (Pass.Side_Effect), True);
Append ("references", Image (Pass.References));
SU.Append (Result, '}');
end loop;
SU.Append (Result, "],");
First := True;
Append ("resources", "[");
for Resource of Object.Graph.Resources loop
Append_Comma;
SU.Append (Result, '{');
Append ("name", Image (+Resource.Description.Name), True);
Append ("kind", Image (Resource.Description.Kind'Image), True);
Append ("format", Image (Resource.Description.Format'Image), True);
Append ("version", Image (Resource.Description.Version.Version), True);
Append ("implicit", Image (Resource.Implicit), True);
Append ("readMode", Image (Resource.Input_Mode'Image), True);
Append ("writeMode", Image (Resource.Output_Mode'Image), True);
Append ("readCount", Image (Resource.Read_Count), True);
Append ("references", Image (Resource.References));
SU.Append (Result, '}');
end loop;
SU.Append (Result, "],");
-- Edges (reads and writes)
First := True;
Append ("reads", "[");
for Index in 1 .. Object.Graph.Passes.Length loop
declare
Pass : Render_Pass_Data renames Object.Graph.Passes (Index);
begin
-- Passes reading from resources
for Resource_Index in Pass.Read_Offset .. Pass.Read_Offset + Pass.Read_Count - 1 loop
declare
Handle : Handle_Type renames Object.Graph.Read_Handles (Resource_Index);
begin
Append_Comma;
SU.Append (Result, '{');
Append ("source", Image (Positive (Handle) - 1), True);
Append ("target", Image (Index - 1));
SU.Append (Result, '}');
end;
end loop;
end;
end loop;
SU.Append (Result, "],");
First := True;
Append ("writes", "[");
for Index in 1 .. Object.Graph.Passes.Length loop
declare
Pass : Render_Pass_Data renames Object.Graph.Passes (Index);
begin
-- Passes writing to resources
for Resource_Index in
Pass.Write_Offset .. Pass.Write_Offset + Pass.Write_Count - 1
loop
declare
Handle : Handle_Type renames Object.Graph.Write_Handles (Resource_Index);
begin
Append_Comma;
SU.Append (Result, '{');
Append ("source", Image (Index - 1), True);
Append ("target", Image (Positive (Handle) - 1));
SU.Append (Result, '}');
end;
end loop;
end;
end loop;
SU.Append (Result, "]");
SU.Append (Result, "}");
declare
subtype JSON_Byte_Array is Resources.Byte_Array
(1 .. Ada.Streams.Stream_Element_Offset (SU.Length (Result)));
function Convert is new Ada.Unchecked_Conversion
(Source => String, Target => JSON_Byte_Array);
begin
Location.Write_Data (Path, Convert (SU.To_String (Result)));
end;
end Write_Graph;
end Orka.Frame_Graphs;
|
-- This spec has been automatically generated from STM32F7x9.svd
pragma Restrictions (No_Elaboration_Code);
pragma Ada_2012;
pragma Style_Checks (Off);
with HAL;
with System;
package STM32_SVD.DFSDM is
pragma Preelaborate;
---------------
-- Registers --
---------------
subtype DFSDM_CHCFG0R1_SITP_Field is HAL.UInt2;
subtype DFSDM_CHCFG0R1_SPICKSEL_Field is HAL.UInt2;
subtype DFSDM_CHCFG0R1_DATMPX_Field is HAL.UInt2;
subtype DFSDM_CHCFG0R1_DATPACK_Field is HAL.UInt2;
subtype DFSDM_CHCFG0R1_CKOUTDIV_Field is HAL.UInt8;
-- DFSDM channel configuration 0 register 1
type DFSDM_CHCFG0R1_Register is record
-- Serial interface type for channel 0
SITP : DFSDM_CHCFG0R1_SITP_Field := 16#0#;
-- SPI clock select for channel 0
SPICKSEL : DFSDM_CHCFG0R1_SPICKSEL_Field := 16#0#;
-- unspecified
Reserved_4_4 : HAL.Bit := 16#0#;
-- Short-circuit detector enable on channel 0
SCDEN : Boolean := False;
-- Clock absence detector enable on channel 0
CKABEN : Boolean := False;
-- Channel 0 enable
CHEN : Boolean := False;
-- Channel inputs selection
CHINSEL : Boolean := False;
-- unspecified
Reserved_9_11 : HAL.UInt3 := 16#0#;
-- Input data multiplexer for channel 0
DATMPX : DFSDM_CHCFG0R1_DATMPX_Field := 16#0#;
-- Data packing mode in DFSDM_CHDATINyR register
DATPACK : DFSDM_CHCFG0R1_DATPACK_Field := 16#0#;
-- Output serial clock divider
CKOUTDIV : DFSDM_CHCFG0R1_CKOUTDIV_Field := 16#0#;
-- unspecified
Reserved_24_29 : HAL.UInt6 := 16#0#;
-- Output serial clock source selection
CKOUTSRC : Boolean := False;
-- Global enable for DFSDM interface
DFSDMEN : Boolean := False;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for DFSDM_CHCFG0R1_Register use record
SITP at 0 range 0 .. 1;
SPICKSEL at 0 range 2 .. 3;
Reserved_4_4 at 0 range 4 .. 4;
SCDEN at 0 range 5 .. 5;
CKABEN at 0 range 6 .. 6;
CHEN at 0 range 7 .. 7;
CHINSEL at 0 range 8 .. 8;
Reserved_9_11 at 0 range 9 .. 11;
DATMPX at 0 range 12 .. 13;
DATPACK at 0 range 14 .. 15;
CKOUTDIV at 0 range 16 .. 23;
Reserved_24_29 at 0 range 24 .. 29;
CKOUTSRC at 0 range 30 .. 30;
DFSDMEN at 0 range 31 .. 31;
end record;
subtype DFSDM_CHCFG1R1_SITP_Field is HAL.UInt2;
subtype DFSDM_CHCFG1R1_SPICKSEL_Field is HAL.UInt2;
subtype DFSDM_CHCFG1R1_DATMPX_Field is HAL.UInt2;
subtype DFSDM_CHCFG1R1_DATPACK_Field is HAL.UInt2;
subtype DFSDM_CHCFG1R1_CKOUTDIV_Field is HAL.UInt8;
-- DFSDM channel configuration 1 register 1
type DFSDM_CHCFG1R1_Register is record
-- Serial interface type for channel 1
SITP : DFSDM_CHCFG1R1_SITP_Field := 16#0#;
-- SPI clock select for channel 1
SPICKSEL : DFSDM_CHCFG1R1_SPICKSEL_Field := 16#0#;
-- unspecified
Reserved_4_4 : HAL.Bit := 16#0#;
-- Short-circuit detector enable on channel 1
SCDEN : Boolean := False;
-- Clock absence detector enable on channel 1
CKABEN : Boolean := False;
-- Channel 1 enable
CHEN : Boolean := False;
-- Channel inputs selection
CHINSEL : Boolean := False;
-- unspecified
Reserved_9_11 : HAL.UInt3 := 16#0#;
-- Input data multiplexer for channel 1
DATMPX : DFSDM_CHCFG1R1_DATMPX_Field := 16#0#;
-- Data packing mode in DFSDM_CHDATINyR register
DATPACK : DFSDM_CHCFG1R1_DATPACK_Field := 16#0#;
-- Output serial clock divider
CKOUTDIV : DFSDM_CHCFG1R1_CKOUTDIV_Field := 16#0#;
-- unspecified
Reserved_24_29 : HAL.UInt6 := 16#0#;
-- Output serial clock source selection
CKOUTSRC : Boolean := False;
-- Global enable for DFSDM interface
DFSDMEN : Boolean := False;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for DFSDM_CHCFG1R1_Register use record
SITP at 0 range 0 .. 1;
SPICKSEL at 0 range 2 .. 3;
Reserved_4_4 at 0 range 4 .. 4;
SCDEN at 0 range 5 .. 5;
CKABEN at 0 range 6 .. 6;
CHEN at 0 range 7 .. 7;
CHINSEL at 0 range 8 .. 8;
Reserved_9_11 at 0 range 9 .. 11;
DATMPX at 0 range 12 .. 13;
DATPACK at 0 range 14 .. 15;
CKOUTDIV at 0 range 16 .. 23;
Reserved_24_29 at 0 range 24 .. 29;
CKOUTSRC at 0 range 30 .. 30;
DFSDMEN at 0 range 31 .. 31;
end record;
subtype DFSDM_CHCFG2R1_SITP_Field is HAL.UInt2;
subtype DFSDM_CHCFG2R1_SPICKSEL_Field is HAL.UInt2;
subtype DFSDM_CHCFG2R1_DATMPX_Field is HAL.UInt2;
subtype DFSDM_CHCFG2R1_DATPACK_Field is HAL.UInt2;
subtype DFSDM_CHCFG2R1_CKOUTDIV_Field is HAL.UInt8;
-- DFSDM channel configuration 2 register 1
type DFSDM_CHCFG2R1_Register is record
-- Serial interface type for channel 2
SITP : DFSDM_CHCFG2R1_SITP_Field := 16#0#;
-- SPI clock select for channel 2
SPICKSEL : DFSDM_CHCFG2R1_SPICKSEL_Field := 16#0#;
-- unspecified
Reserved_4_4 : HAL.Bit := 16#0#;
-- Short-circuit detector enable on channel 2
SCDEN : Boolean := False;
-- Clock absence detector enable on channel 2
CKABEN : Boolean := False;
-- Channel 2 enable
CHEN : Boolean := False;
-- Channel inputs selection
CHINSEL : Boolean := False;
-- unspecified
Reserved_9_11 : HAL.UInt3 := 16#0#;
-- Input data multiplexer for channel 2
DATMPX : DFSDM_CHCFG2R1_DATMPX_Field := 16#0#;
-- Data packing mode in DFSDM_CHDATINyR register
DATPACK : DFSDM_CHCFG2R1_DATPACK_Field := 16#0#;
-- Output serial clock divider
CKOUTDIV : DFSDM_CHCFG2R1_CKOUTDIV_Field := 16#0#;
-- unspecified
Reserved_24_29 : HAL.UInt6 := 16#0#;
-- Output serial clock source selection
CKOUTSRC : Boolean := False;
-- Global enable for DFSDM interface
DFSDMEN : Boolean := False;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for DFSDM_CHCFG2R1_Register use record
SITP at 0 range 0 .. 1;
SPICKSEL at 0 range 2 .. 3;
Reserved_4_4 at 0 range 4 .. 4;
SCDEN at 0 range 5 .. 5;
CKABEN at 0 range 6 .. 6;
CHEN at 0 range 7 .. 7;
CHINSEL at 0 range 8 .. 8;
Reserved_9_11 at 0 range 9 .. 11;
DATMPX at 0 range 12 .. 13;
DATPACK at 0 range 14 .. 15;
CKOUTDIV at 0 range 16 .. 23;
Reserved_24_29 at 0 range 24 .. 29;
CKOUTSRC at 0 range 30 .. 30;
DFSDMEN at 0 range 31 .. 31;
end record;
subtype DFSDM_CHCFG3R1_SITP_Field is HAL.UInt2;
subtype DFSDM_CHCFG3R1_SPICKSEL_Field is HAL.UInt2;
subtype DFSDM_CHCFG3R1_DATMPX_Field is HAL.UInt2;
subtype DFSDM_CHCFG3R1_DATPACK_Field is HAL.UInt2;
subtype DFSDM_CHCFG3R1_CKOUTDIV_Field is HAL.UInt8;
-- DFSDM channel configuration 3 register 1
type DFSDM_CHCFG3R1_Register is record
-- Serial interface type for channel 3
SITP : DFSDM_CHCFG3R1_SITP_Field := 16#0#;
-- SPI clock select for channel 3
SPICKSEL : DFSDM_CHCFG3R1_SPICKSEL_Field := 16#0#;
-- unspecified
Reserved_4_4 : HAL.Bit := 16#0#;
-- Short-circuit detector enable on channel 3
SCDEN : Boolean := False;
-- Clock absence detector enable on channel 3
CKABEN : Boolean := False;
-- Channel 3 enable
CHEN : Boolean := False;
-- Channel inputs selection
CHINSEL : Boolean := False;
-- unspecified
Reserved_9_11 : HAL.UInt3 := 16#0#;
-- Input data multiplexer for channel 3
DATMPX : DFSDM_CHCFG3R1_DATMPX_Field := 16#0#;
-- Data packing mode in DFSDM_CHDATINyR register
DATPACK : DFSDM_CHCFG3R1_DATPACK_Field := 16#0#;
-- Output serial clock divider
CKOUTDIV : DFSDM_CHCFG3R1_CKOUTDIV_Field := 16#0#;
-- unspecified
Reserved_24_29 : HAL.UInt6 := 16#0#;
-- Output serial clock source selection
CKOUTSRC : Boolean := False;
-- Global enable for DFSDM interface
DFSDMEN : Boolean := False;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for DFSDM_CHCFG3R1_Register use record
SITP at 0 range 0 .. 1;
SPICKSEL at 0 range 2 .. 3;
Reserved_4_4 at 0 range 4 .. 4;
SCDEN at 0 range 5 .. 5;
CKABEN at 0 range 6 .. 6;
CHEN at 0 range 7 .. 7;
CHINSEL at 0 range 8 .. 8;
Reserved_9_11 at 0 range 9 .. 11;
DATMPX at 0 range 12 .. 13;
DATPACK at 0 range 14 .. 15;
CKOUTDIV at 0 range 16 .. 23;
Reserved_24_29 at 0 range 24 .. 29;
CKOUTSRC at 0 range 30 .. 30;
DFSDMEN at 0 range 31 .. 31;
end record;
subtype DFSDM_CHCFG4R1_SITP_Field is HAL.UInt2;
subtype DFSDM_CHCFG4R1_SPICKSEL_Field is HAL.UInt2;
subtype DFSDM_CHCFG4R1_DATMPX_Field is HAL.UInt2;
subtype DFSDM_CHCFG4R1_DATPACK_Field is HAL.UInt2;
subtype DFSDM_CHCFG4R1_CKOUTDIV_Field is HAL.UInt8;
-- DFSDM channel configuration 4 register 1
type DFSDM_CHCFG4R1_Register is record
-- Serial interface type for channel 4
SITP : DFSDM_CHCFG4R1_SITP_Field := 16#0#;
-- SPI clock select for channel 4
SPICKSEL : DFSDM_CHCFG4R1_SPICKSEL_Field := 16#0#;
-- unspecified
Reserved_4_4 : HAL.Bit := 16#0#;
-- Short-circuit detector enable on channel 4
SCDEN : Boolean := False;
-- Clock absence detector enable on channel 4
CKABEN : Boolean := False;
-- Channel 4 enable
CHEN : Boolean := False;
-- Channel inputs selection
CHINSEL : Boolean := False;
-- unspecified
Reserved_9_11 : HAL.UInt3 := 16#0#;
-- Input data multiplexer for channel 4
DATMPX : DFSDM_CHCFG4R1_DATMPX_Field := 16#0#;
-- Data packing mode in DFSDM_CHDATINyR register
DATPACK : DFSDM_CHCFG4R1_DATPACK_Field := 16#0#;
-- Output serial clock divider
CKOUTDIV : DFSDM_CHCFG4R1_CKOUTDIV_Field := 16#0#;
-- unspecified
Reserved_24_29 : HAL.UInt6 := 16#0#;
-- Output serial clock source selection
CKOUTSRC : Boolean := False;
-- Global enable for DFSDM interface
DFSDMEN : Boolean := False;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for DFSDM_CHCFG4R1_Register use record
SITP at 0 range 0 .. 1;
SPICKSEL at 0 range 2 .. 3;
Reserved_4_4 at 0 range 4 .. 4;
SCDEN at 0 range 5 .. 5;
CKABEN at 0 range 6 .. 6;
CHEN at 0 range 7 .. 7;
CHINSEL at 0 range 8 .. 8;
Reserved_9_11 at 0 range 9 .. 11;
DATMPX at 0 range 12 .. 13;
DATPACK at 0 range 14 .. 15;
CKOUTDIV at 0 range 16 .. 23;
Reserved_24_29 at 0 range 24 .. 29;
CKOUTSRC at 0 range 30 .. 30;
DFSDMEN at 0 range 31 .. 31;
end record;
subtype DFSDM_CHCFG5R1_SITP_Field is HAL.UInt2;
subtype DFSDM_CHCFG5R1_SPICKSEL_Field is HAL.UInt2;
subtype DFSDM_CHCFG5R1_DATMPX_Field is HAL.UInt2;
subtype DFSDM_CHCFG5R1_DATPACK_Field is HAL.UInt2;
subtype DFSDM_CHCFG5R1_CKOUTDIV_Field is HAL.UInt8;
-- DFSDM channel configuration 5 register 1
type DFSDM_CHCFG5R1_Register is record
-- Serial interface type for channel 5
SITP : DFSDM_CHCFG5R1_SITP_Field := 16#0#;
-- SPI clock select for channel 5
SPICKSEL : DFSDM_CHCFG5R1_SPICKSEL_Field := 16#0#;
-- unspecified
Reserved_4_4 : HAL.Bit := 16#0#;
-- Short-circuit detector enable on channel 5
SCDEN : Boolean := False;
-- Clock absence detector enable on channel 5
CKABEN : Boolean := False;
-- Channel 5 enable
CHEN : Boolean := False;
-- Channel inputs selection
CHINSEL : Boolean := False;
-- unspecified
Reserved_9_11 : HAL.UInt3 := 16#0#;
-- Input data multiplexer for channel 5
DATMPX : DFSDM_CHCFG5R1_DATMPX_Field := 16#0#;
-- Data packing mode in DFSDM_CHDATINyR register
DATPACK : DFSDM_CHCFG5R1_DATPACK_Field := 16#0#;
-- Output serial clock divider
CKOUTDIV : DFSDM_CHCFG5R1_CKOUTDIV_Field := 16#0#;
-- unspecified
Reserved_24_29 : HAL.UInt6 := 16#0#;
-- Output serial clock source selection
CKOUTSRC : Boolean := False;
-- Global enable for DFSDM interface
DFSDMEN : Boolean := False;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for DFSDM_CHCFG5R1_Register use record
SITP at 0 range 0 .. 1;
SPICKSEL at 0 range 2 .. 3;
Reserved_4_4 at 0 range 4 .. 4;
SCDEN at 0 range 5 .. 5;
CKABEN at 0 range 6 .. 6;
CHEN at 0 range 7 .. 7;
CHINSEL at 0 range 8 .. 8;
Reserved_9_11 at 0 range 9 .. 11;
DATMPX at 0 range 12 .. 13;
DATPACK at 0 range 14 .. 15;
CKOUTDIV at 0 range 16 .. 23;
Reserved_24_29 at 0 range 24 .. 29;
CKOUTSRC at 0 range 30 .. 30;
DFSDMEN at 0 range 31 .. 31;
end record;
subtype DFSDM_CHCFG6R1_SITP_Field is HAL.UInt2;
subtype DFSDM_CHCFG6R1_SPICKSEL_Field is HAL.UInt2;
subtype DFSDM_CHCFG6R1_DATMPX_Field is HAL.UInt2;
subtype DFSDM_CHCFG6R1_DATPACK_Field is HAL.UInt2;
subtype DFSDM_CHCFG6R1_CKOUTDIV_Field is HAL.UInt8;
-- DFSDM channel configuration 6 register 1
type DFSDM_CHCFG6R1_Register is record
-- Serial interface type for channel 6
SITP : DFSDM_CHCFG6R1_SITP_Field := 16#0#;
-- SPI clock select for channel 6
SPICKSEL : DFSDM_CHCFG6R1_SPICKSEL_Field := 16#0#;
-- unspecified
Reserved_4_4 : HAL.Bit := 16#0#;
-- Short-circuit detector enable on channel 6
SCDEN : Boolean := False;
-- Clock absence detector enable on channel 6
CKABEN : Boolean := False;
-- Channel 6 enable
CHEN : Boolean := False;
-- Channel inputs selection
CHINSEL : Boolean := False;
-- unspecified
Reserved_9_11 : HAL.UInt3 := 16#0#;
-- Input data multiplexer for channel 6
DATMPX : DFSDM_CHCFG6R1_DATMPX_Field := 16#0#;
-- Data packing mode in DFSDM_CHDATINyR register
DATPACK : DFSDM_CHCFG6R1_DATPACK_Field := 16#0#;
-- Output serial clock divider
CKOUTDIV : DFSDM_CHCFG6R1_CKOUTDIV_Field := 16#0#;
-- unspecified
Reserved_24_29 : HAL.UInt6 := 16#0#;
-- Output serial clock source selection
CKOUTSRC : Boolean := False;
-- Global enable for DFSDM interface
DFSDMEN : Boolean := False;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for DFSDM_CHCFG6R1_Register use record
SITP at 0 range 0 .. 1;
SPICKSEL at 0 range 2 .. 3;
Reserved_4_4 at 0 range 4 .. 4;
SCDEN at 0 range 5 .. 5;
CKABEN at 0 range 6 .. 6;
CHEN at 0 range 7 .. 7;
CHINSEL at 0 range 8 .. 8;
Reserved_9_11 at 0 range 9 .. 11;
DATMPX at 0 range 12 .. 13;
DATPACK at 0 range 14 .. 15;
CKOUTDIV at 0 range 16 .. 23;
Reserved_24_29 at 0 range 24 .. 29;
CKOUTSRC at 0 range 30 .. 30;
DFSDMEN at 0 range 31 .. 31;
end record;
subtype DFSDM_CHCFG7R1_SITP_Field is HAL.UInt2;
subtype DFSDM_CHCFG7R1_SPICKSEL_Field is HAL.UInt2;
subtype DFSDM_CHCFG7R1_DATMPX_Field is HAL.UInt2;
subtype DFSDM_CHCFG7R1_DATPACK_Field is HAL.UInt2;
subtype DFSDM_CHCFG7R1_CKOUTDIV_Field is HAL.UInt8;
-- DFSDM channel configuration 7 register 1
type DFSDM_CHCFG7R1_Register is record
-- Serial interface type for channel 7
SITP : DFSDM_CHCFG7R1_SITP_Field := 16#0#;
-- SPI clock select for channel 7
SPICKSEL : DFSDM_CHCFG7R1_SPICKSEL_Field := 16#0#;
-- unspecified
Reserved_4_4 : HAL.Bit := 16#0#;
-- Short-circuit detector enable on channel 7
SCDEN : Boolean := False;
-- Clock absence detector enable on channel 7
CKABEN : Boolean := False;
-- Channel 7 enable
CHEN : Boolean := False;
-- Channel inputs selection
CHINSEL : Boolean := False;
-- unspecified
Reserved_9_11 : HAL.UInt3 := 16#0#;
-- Input data multiplexer for channel 7
DATMPX : DFSDM_CHCFG7R1_DATMPX_Field := 16#0#;
-- Data packing mode in DFSDM_CHDATINyR register
DATPACK : DFSDM_CHCFG7R1_DATPACK_Field := 16#0#;
-- Output serial clock divider
CKOUTDIV : DFSDM_CHCFG7R1_CKOUTDIV_Field := 16#0#;
-- unspecified
Reserved_24_29 : HAL.UInt6 := 16#0#;
-- Output serial clock source selection
CKOUTSRC : Boolean := False;
-- Global enable for DFSDM interface
DFSDMEN : Boolean := False;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for DFSDM_CHCFG7R1_Register use record
SITP at 0 range 0 .. 1;
SPICKSEL at 0 range 2 .. 3;
Reserved_4_4 at 0 range 4 .. 4;
SCDEN at 0 range 5 .. 5;
CKABEN at 0 range 6 .. 6;
CHEN at 0 range 7 .. 7;
CHINSEL at 0 range 8 .. 8;
Reserved_9_11 at 0 range 9 .. 11;
DATMPX at 0 range 12 .. 13;
DATPACK at 0 range 14 .. 15;
CKOUTDIV at 0 range 16 .. 23;
Reserved_24_29 at 0 range 24 .. 29;
CKOUTSRC at 0 range 30 .. 30;
DFSDMEN at 0 range 31 .. 31;
end record;
subtype DFSDM_CHCFG0R2_DTRBS_Field is HAL.UInt5;
subtype DFSDM_CHCFG0R2_OFFSET_Field is HAL.UInt24;
-- DFSDM channel configuration 0 register 2
type DFSDM_CHCFG0R2_Register is record
-- unspecified
Reserved_0_2 : HAL.UInt3 := 16#0#;
-- Data right bit-shift for channel 0
DTRBS : DFSDM_CHCFG0R2_DTRBS_Field := 16#0#;
-- 24-bit calibration offset for channel 0
OFFSET : DFSDM_CHCFG0R2_OFFSET_Field := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for DFSDM_CHCFG0R2_Register use record
Reserved_0_2 at 0 range 0 .. 2;
DTRBS at 0 range 3 .. 7;
OFFSET at 0 range 8 .. 31;
end record;
subtype DFSDM_CHCFG1R2_DTRBS_Field is HAL.UInt5;
subtype DFSDM_CHCFG1R2_OFFSET_Field is HAL.UInt24;
-- DFSDM channel configuration 1 register 2
type DFSDM_CHCFG1R2_Register is record
-- unspecified
Reserved_0_2 : HAL.UInt3 := 16#0#;
-- Data right bit-shift for channel 1
DTRBS : DFSDM_CHCFG1R2_DTRBS_Field := 16#0#;
-- 24-bit calibration offset for channel 1
OFFSET : DFSDM_CHCFG1R2_OFFSET_Field := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for DFSDM_CHCFG1R2_Register use record
Reserved_0_2 at 0 range 0 .. 2;
DTRBS at 0 range 3 .. 7;
OFFSET at 0 range 8 .. 31;
end record;
subtype DFSDM_CHCFG2R2_DTRBS_Field is HAL.UInt5;
subtype DFSDM_CHCFG2R2_OFFSET_Field is HAL.UInt24;
-- DFSDM channel configuration 2 register 2
type DFSDM_CHCFG2R2_Register is record
-- unspecified
Reserved_0_2 : HAL.UInt3 := 16#0#;
-- Data right bit-shift for channel 2
DTRBS : DFSDM_CHCFG2R2_DTRBS_Field := 16#0#;
-- 24-bit calibration offset for channel 2
OFFSET : DFSDM_CHCFG2R2_OFFSET_Field := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for DFSDM_CHCFG2R2_Register use record
Reserved_0_2 at 0 range 0 .. 2;
DTRBS at 0 range 3 .. 7;
OFFSET at 0 range 8 .. 31;
end record;
subtype DFSDM_CHCFG3R2_DTRBS_Field is HAL.UInt5;
subtype DFSDM_CHCFG3R2_OFFSET_Field is HAL.UInt24;
-- DFSDM channel configuration 3 register 2
type DFSDM_CHCFG3R2_Register is record
-- unspecified
Reserved_0_2 : HAL.UInt3 := 16#0#;
-- Data right bit-shift for channel 3
DTRBS : DFSDM_CHCFG3R2_DTRBS_Field := 16#0#;
-- 24-bit calibration offset for channel 3
OFFSET : DFSDM_CHCFG3R2_OFFSET_Field := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for DFSDM_CHCFG3R2_Register use record
Reserved_0_2 at 0 range 0 .. 2;
DTRBS at 0 range 3 .. 7;
OFFSET at 0 range 8 .. 31;
end record;
subtype DFSDM_CHCFG4R2_DTRBS_Field is HAL.UInt5;
subtype DFSDM_CHCFG4R2_OFFSET_Field is HAL.UInt24;
-- DFSDM channel configuration 4 register 2
type DFSDM_CHCFG4R2_Register is record
-- unspecified
Reserved_0_2 : HAL.UInt3 := 16#0#;
-- Data right bit-shift for channel 4
DTRBS : DFSDM_CHCFG4R2_DTRBS_Field := 16#0#;
-- 24-bit calibration offset for channel 4
OFFSET : DFSDM_CHCFG4R2_OFFSET_Field := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for DFSDM_CHCFG4R2_Register use record
Reserved_0_2 at 0 range 0 .. 2;
DTRBS at 0 range 3 .. 7;
OFFSET at 0 range 8 .. 31;
end record;
subtype DFSDM_CHCFG5R2_DTRBS_Field is HAL.UInt5;
subtype DFSDM_CHCFG5R2_OFFSET_Field is HAL.UInt24;
-- DFSDM channel configuration 5 register 2
type DFSDM_CHCFG5R2_Register is record
-- unspecified
Reserved_0_2 : HAL.UInt3 := 16#0#;
-- Data right bit-shift for channel 5
DTRBS : DFSDM_CHCFG5R2_DTRBS_Field := 16#0#;
-- 24-bit calibration offset for channel 5
OFFSET : DFSDM_CHCFG5R2_OFFSET_Field := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for DFSDM_CHCFG5R2_Register use record
Reserved_0_2 at 0 range 0 .. 2;
DTRBS at 0 range 3 .. 7;
OFFSET at 0 range 8 .. 31;
end record;
subtype DFSDM_CHCFG6R2_DTRBS_Field is HAL.UInt5;
subtype DFSDM_CHCFG6R2_OFFSET_Field is HAL.UInt24;
-- DFSDM channel configuration 6 register 2
type DFSDM_CHCFG6R2_Register is record
-- unspecified
Reserved_0_2 : HAL.UInt3 := 16#0#;
-- Data right bit-shift for channel 6
DTRBS : DFSDM_CHCFG6R2_DTRBS_Field := 16#0#;
-- 24-bit calibration offset for channel 6
OFFSET : DFSDM_CHCFG6R2_OFFSET_Field := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for DFSDM_CHCFG6R2_Register use record
Reserved_0_2 at 0 range 0 .. 2;
DTRBS at 0 range 3 .. 7;
OFFSET at 0 range 8 .. 31;
end record;
subtype DFSDM_CHCFG7R2_DTRBS_Field is HAL.UInt5;
subtype DFSDM_CHCFG7R2_OFFSET_Field is HAL.UInt24;
-- DFSDM channel configuration 7 register 2
type DFSDM_CHCFG7R2_Register is record
-- unspecified
Reserved_0_2 : HAL.UInt3 := 16#0#;
-- Data right bit-shift for channel 7
DTRBS : DFSDM_CHCFG7R2_DTRBS_Field := 16#0#;
-- 24-bit calibration offset for channel 7
OFFSET : DFSDM_CHCFG7R2_OFFSET_Field := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for DFSDM_CHCFG7R2_Register use record
Reserved_0_2 at 0 range 0 .. 2;
DTRBS at 0 range 3 .. 7;
OFFSET at 0 range 8 .. 31;
end record;
subtype DFSDM_AWSCD0R_SCDT_Field is HAL.UInt8;
subtype DFSDM_AWSCD0R_BKSCD_Field is HAL.UInt4;
subtype DFSDM_AWSCD0R_AWFOSR_Field is HAL.UInt5;
subtype DFSDM_AWSCD0R_AWFORD_Field is HAL.UInt2;
-- DFSDM analog watchdog and short-circuit detector register
type DFSDM_AWSCD0R_Register is record
-- short-circuit detector threshold for channel 0
SCDT : DFSDM_AWSCD0R_SCDT_Field := 16#0#;
-- unspecified
Reserved_8_11 : HAL.UInt4 := 16#0#;
-- Break signal assignment for short-circuit detector on channel 0
BKSCD : DFSDM_AWSCD0R_BKSCD_Field := 16#0#;
-- Analog watchdog filter oversampling ratio (decimation rate) on
-- channel 0
AWFOSR : DFSDM_AWSCD0R_AWFOSR_Field := 16#0#;
-- unspecified
Reserved_21_21 : HAL.Bit := 16#0#;
-- Analog watchdog Sinc filter order on channel 0
AWFORD : DFSDM_AWSCD0R_AWFORD_Field := 16#0#;
-- unspecified
Reserved_24_31 : HAL.UInt8 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for DFSDM_AWSCD0R_Register use record
SCDT at 0 range 0 .. 7;
Reserved_8_11 at 0 range 8 .. 11;
BKSCD at 0 range 12 .. 15;
AWFOSR at 0 range 16 .. 20;
Reserved_21_21 at 0 range 21 .. 21;
AWFORD at 0 range 22 .. 23;
Reserved_24_31 at 0 range 24 .. 31;
end record;
subtype DFSDM_AWSCD1R_SCDT_Field is HAL.UInt8;
subtype DFSDM_AWSCD1R_BKSCD_Field is HAL.UInt4;
subtype DFSDM_AWSCD1R_AWFOSR_Field is HAL.UInt5;
subtype DFSDM_AWSCD1R_AWFORD_Field is HAL.UInt2;
-- DFSDM analog watchdog and short-circuit detector register
type DFSDM_AWSCD1R_Register is record
-- short-circuit detector threshold for channel 1
SCDT : DFSDM_AWSCD1R_SCDT_Field := 16#0#;
-- unspecified
Reserved_8_11 : HAL.UInt4 := 16#0#;
-- Break signal assignment for short-circuit detector on channel 1
BKSCD : DFSDM_AWSCD1R_BKSCD_Field := 16#0#;
-- Analog watchdog filter oversampling ratio (decimation rate) on
-- channel 1
AWFOSR : DFSDM_AWSCD1R_AWFOSR_Field := 16#0#;
-- unspecified
Reserved_21_21 : HAL.Bit := 16#0#;
-- Analog watchdog Sinc filter order on channel 1
AWFORD : DFSDM_AWSCD1R_AWFORD_Field := 16#0#;
-- unspecified
Reserved_24_31 : HAL.UInt8 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for DFSDM_AWSCD1R_Register use record
SCDT at 0 range 0 .. 7;
Reserved_8_11 at 0 range 8 .. 11;
BKSCD at 0 range 12 .. 15;
AWFOSR at 0 range 16 .. 20;
Reserved_21_21 at 0 range 21 .. 21;
AWFORD at 0 range 22 .. 23;
Reserved_24_31 at 0 range 24 .. 31;
end record;
subtype DFSDM_AWSCD2R_SCDT_Field is HAL.UInt8;
subtype DFSDM_AWSCD2R_BKSCD_Field is HAL.UInt4;
subtype DFSDM_AWSCD2R_AWFOSR_Field is HAL.UInt5;
subtype DFSDM_AWSCD2R_AWFORD_Field is HAL.UInt2;
-- DFSDM analog watchdog and short-circuit detector register
type DFSDM_AWSCD2R_Register is record
-- short-circuit detector threshold for channel 2
SCDT : DFSDM_AWSCD2R_SCDT_Field := 16#0#;
-- unspecified
Reserved_8_11 : HAL.UInt4 := 16#0#;
-- Break signal assignment for short-circuit detector on channel 2
BKSCD : DFSDM_AWSCD2R_BKSCD_Field := 16#0#;
-- Analog watchdog filter oversampling ratio (decimation rate) on
-- channel 2
AWFOSR : DFSDM_AWSCD2R_AWFOSR_Field := 16#0#;
-- unspecified
Reserved_21_21 : HAL.Bit := 16#0#;
-- Analog watchdog Sinc filter order on channel 2
AWFORD : DFSDM_AWSCD2R_AWFORD_Field := 16#0#;
-- unspecified
Reserved_24_31 : HAL.UInt8 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for DFSDM_AWSCD2R_Register use record
SCDT at 0 range 0 .. 7;
Reserved_8_11 at 0 range 8 .. 11;
BKSCD at 0 range 12 .. 15;
AWFOSR at 0 range 16 .. 20;
Reserved_21_21 at 0 range 21 .. 21;
AWFORD at 0 range 22 .. 23;
Reserved_24_31 at 0 range 24 .. 31;
end record;
subtype DFSDM_AWSCD3R_SCDT_Field is HAL.UInt8;
subtype DFSDM_AWSCD3R_BKSCD_Field is HAL.UInt4;
subtype DFSDM_AWSCD3R_AWFOSR_Field is HAL.UInt5;
subtype DFSDM_AWSCD3R_AWFORD_Field is HAL.UInt2;
-- DFSDM analog watchdog and short-circuit detector register
type DFSDM_AWSCD3R_Register is record
-- short-circuit detector threshold for channel 3
SCDT : DFSDM_AWSCD3R_SCDT_Field := 16#0#;
-- unspecified
Reserved_8_11 : HAL.UInt4 := 16#0#;
-- Break signal assignment for short-circuit detector on channel 3
BKSCD : DFSDM_AWSCD3R_BKSCD_Field := 16#0#;
-- Analog watchdog filter oversampling ratio (decimation rate) on
-- channel 3
AWFOSR : DFSDM_AWSCD3R_AWFOSR_Field := 16#0#;
-- unspecified
Reserved_21_21 : HAL.Bit := 16#0#;
-- Analog watchdog Sinc filter order on channel 3
AWFORD : DFSDM_AWSCD3R_AWFORD_Field := 16#0#;
-- unspecified
Reserved_24_31 : HAL.UInt8 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for DFSDM_AWSCD3R_Register use record
SCDT at 0 range 0 .. 7;
Reserved_8_11 at 0 range 8 .. 11;
BKSCD at 0 range 12 .. 15;
AWFOSR at 0 range 16 .. 20;
Reserved_21_21 at 0 range 21 .. 21;
AWFORD at 0 range 22 .. 23;
Reserved_24_31 at 0 range 24 .. 31;
end record;
subtype DFSDM_AWSCD4R_SCDT_Field is HAL.UInt8;
subtype DFSDM_AWSCD4R_BKSCD_Field is HAL.UInt4;
subtype DFSDM_AWSCD4R_AWFOSR_Field is HAL.UInt5;
subtype DFSDM_AWSCD4R_AWFORD_Field is HAL.UInt2;
-- DFSDM analog watchdog and short-circuit detector register
type DFSDM_AWSCD4R_Register is record
-- short-circuit detector threshold for channel 4
SCDT : DFSDM_AWSCD4R_SCDT_Field := 16#0#;
-- unspecified
Reserved_8_11 : HAL.UInt4 := 16#0#;
-- Break signal assignment for short-circuit detector on channel 4
BKSCD : DFSDM_AWSCD4R_BKSCD_Field := 16#0#;
-- Analog watchdog filter oversampling ratio (decimation rate) on
-- channel 4
AWFOSR : DFSDM_AWSCD4R_AWFOSR_Field := 16#0#;
-- unspecified
Reserved_21_21 : HAL.Bit := 16#0#;
-- Analog watchdog Sinc filter order on channel 4
AWFORD : DFSDM_AWSCD4R_AWFORD_Field := 16#0#;
-- unspecified
Reserved_24_31 : HAL.UInt8 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for DFSDM_AWSCD4R_Register use record
SCDT at 0 range 0 .. 7;
Reserved_8_11 at 0 range 8 .. 11;
BKSCD at 0 range 12 .. 15;
AWFOSR at 0 range 16 .. 20;
Reserved_21_21 at 0 range 21 .. 21;
AWFORD at 0 range 22 .. 23;
Reserved_24_31 at 0 range 24 .. 31;
end record;
subtype DFSDM_AWSCD5R_SCDT_Field is HAL.UInt8;
subtype DFSDM_AWSCD5R_BKSCD_Field is HAL.UInt4;
subtype DFSDM_AWSCD5R_AWFOSR_Field is HAL.UInt5;
subtype DFSDM_AWSCD5R_AWFORD_Field is HAL.UInt2;
-- DFSDM analog watchdog and short-circuit detector register
type DFSDM_AWSCD5R_Register is record
-- short-circuit detector threshold for channel 5
SCDT : DFSDM_AWSCD5R_SCDT_Field := 16#0#;
-- unspecified
Reserved_8_11 : HAL.UInt4 := 16#0#;
-- Break signal assignment for short-circuit detector on channel 5
BKSCD : DFSDM_AWSCD5R_BKSCD_Field := 16#0#;
-- Analog watchdog filter oversampling ratio (decimation rate) on
-- channel 5
AWFOSR : DFSDM_AWSCD5R_AWFOSR_Field := 16#0#;
-- unspecified
Reserved_21_21 : HAL.Bit := 16#0#;
-- Analog watchdog Sinc filter order on channel 5
AWFORD : DFSDM_AWSCD5R_AWFORD_Field := 16#0#;
-- unspecified
Reserved_24_31 : HAL.UInt8 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for DFSDM_AWSCD5R_Register use record
SCDT at 0 range 0 .. 7;
Reserved_8_11 at 0 range 8 .. 11;
BKSCD at 0 range 12 .. 15;
AWFOSR at 0 range 16 .. 20;
Reserved_21_21 at 0 range 21 .. 21;
AWFORD at 0 range 22 .. 23;
Reserved_24_31 at 0 range 24 .. 31;
end record;
subtype DFSDM_AWSCD6R_SCDT_Field is HAL.UInt8;
subtype DFSDM_AWSCD6R_BKSCD_Field is HAL.UInt4;
subtype DFSDM_AWSCD6R_AWFOSR_Field is HAL.UInt5;
subtype DFSDM_AWSCD6R_AWFORD_Field is HAL.UInt2;
-- DFSDM analog watchdog and short-circuit detector register
type DFSDM_AWSCD6R_Register is record
-- short-circuit detector threshold for channel 6
SCDT : DFSDM_AWSCD6R_SCDT_Field := 16#0#;
-- unspecified
Reserved_8_11 : HAL.UInt4 := 16#0#;
-- Break signal assignment for short-circuit detector on channel 6
BKSCD : DFSDM_AWSCD6R_BKSCD_Field := 16#0#;
-- Analog watchdog filter oversampling ratio (decimation rate) on
-- channel 6
AWFOSR : DFSDM_AWSCD6R_AWFOSR_Field := 16#0#;
-- unspecified
Reserved_21_21 : HAL.Bit := 16#0#;
-- Analog watchdog Sinc filter order on channel 6
AWFORD : DFSDM_AWSCD6R_AWFORD_Field := 16#0#;
-- unspecified
Reserved_24_31 : HAL.UInt8 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for DFSDM_AWSCD6R_Register use record
SCDT at 0 range 0 .. 7;
Reserved_8_11 at 0 range 8 .. 11;
BKSCD at 0 range 12 .. 15;
AWFOSR at 0 range 16 .. 20;
Reserved_21_21 at 0 range 21 .. 21;
AWFORD at 0 range 22 .. 23;
Reserved_24_31 at 0 range 24 .. 31;
end record;
subtype DFSDM_AWSCD7R_SCDT_Field is HAL.UInt8;
subtype DFSDM_AWSCD7R_BKSCD_Field is HAL.UInt4;
subtype DFSDM_AWSCD7R_AWFOSR_Field is HAL.UInt5;
subtype DFSDM_AWSCD7R_AWFORD_Field is HAL.UInt2;
-- DFSDM analog watchdog and short-circuit detector register
type DFSDM_AWSCD7R_Register is record
-- short-circuit detector threshold for channel 7
SCDT : DFSDM_AWSCD7R_SCDT_Field := 16#0#;
-- unspecified
Reserved_8_11 : HAL.UInt4 := 16#0#;
-- Break signal assignment for short-circuit detector on channel 7
BKSCD : DFSDM_AWSCD7R_BKSCD_Field := 16#0#;
-- Analog watchdog filter oversampling ratio (decimation rate) on
-- channel 7
AWFOSR : DFSDM_AWSCD7R_AWFOSR_Field := 16#0#;
-- unspecified
Reserved_21_21 : HAL.Bit := 16#0#;
-- Analog watchdog Sinc filter order on channel 7
AWFORD : DFSDM_AWSCD7R_AWFORD_Field := 16#0#;
-- unspecified
Reserved_24_31 : HAL.UInt8 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for DFSDM_AWSCD7R_Register use record
SCDT at 0 range 0 .. 7;
Reserved_8_11 at 0 range 8 .. 11;
BKSCD at 0 range 12 .. 15;
AWFOSR at 0 range 16 .. 20;
Reserved_21_21 at 0 range 21 .. 21;
AWFORD at 0 range 22 .. 23;
Reserved_24_31 at 0 range 24 .. 31;
end record;
subtype DFSDM_CHWDAT0R_WDATA_Field is HAL.UInt16;
-- DFSDM channel watchdog filter data register
type DFSDM_CHWDAT0R_Register is record
-- Read-only. Input channel y watchdog data
WDATA : DFSDM_CHWDAT0R_WDATA_Field;
-- unspecified
Reserved_16_31 : HAL.UInt16;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for DFSDM_CHWDAT0R_Register use record
WDATA at 0 range 0 .. 15;
Reserved_16_31 at 0 range 16 .. 31;
end record;
subtype DFSDM_CHWDAT1R_WDATA_Field is HAL.UInt16;
-- DFSDM channel watchdog filter data register
type DFSDM_CHWDAT1R_Register is record
-- Read-only. Input channel y watchdog data
WDATA : DFSDM_CHWDAT1R_WDATA_Field;
-- unspecified
Reserved_16_31 : HAL.UInt16;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for DFSDM_CHWDAT1R_Register use record
WDATA at 0 range 0 .. 15;
Reserved_16_31 at 0 range 16 .. 31;
end record;
subtype DFSDM_CHWDAT2R_WDATA_Field is HAL.UInt16;
-- DFSDM channel watchdog filter data register
type DFSDM_CHWDAT2R_Register is record
-- Read-only. Input channel y watchdog data
WDATA : DFSDM_CHWDAT2R_WDATA_Field;
-- unspecified
Reserved_16_31 : HAL.UInt16;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for DFSDM_CHWDAT2R_Register use record
WDATA at 0 range 0 .. 15;
Reserved_16_31 at 0 range 16 .. 31;
end record;
subtype DFSDM_CHWDAT3R_WDATA_Field is HAL.UInt16;
-- DFSDM channel watchdog filter data register
type DFSDM_CHWDAT3R_Register is record
-- Read-only. Input channel y watchdog data
WDATA : DFSDM_CHWDAT3R_WDATA_Field;
-- unspecified
Reserved_16_31 : HAL.UInt16;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for DFSDM_CHWDAT3R_Register use record
WDATA at 0 range 0 .. 15;
Reserved_16_31 at 0 range 16 .. 31;
end record;
subtype DFSDM_CHWDAT4R_WDATA_Field is HAL.UInt16;
-- DFSDM channel watchdog filter data register
type DFSDM_CHWDAT4R_Register is record
-- Read-only. Input channel y watchdog data
WDATA : DFSDM_CHWDAT4R_WDATA_Field;
-- unspecified
Reserved_16_31 : HAL.UInt16;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for DFSDM_CHWDAT4R_Register use record
WDATA at 0 range 0 .. 15;
Reserved_16_31 at 0 range 16 .. 31;
end record;
subtype DFSDM_CHWDAT5R_WDATA_Field is HAL.UInt16;
-- DFSDM channel watchdog filter data register
type DFSDM_CHWDAT5R_Register is record
-- Read-only. Input channel y watchdog data
WDATA : DFSDM_CHWDAT5R_WDATA_Field;
-- unspecified
Reserved_16_31 : HAL.UInt16;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for DFSDM_CHWDAT5R_Register use record
WDATA at 0 range 0 .. 15;
Reserved_16_31 at 0 range 16 .. 31;
end record;
subtype DFSDM_CHWDAT6R_WDATA_Field is HAL.UInt16;
-- DFSDM channel watchdog filter data register
type DFSDM_CHWDAT6R_Register is record
-- Read-only. Input channel y watchdog data
WDATA : DFSDM_CHWDAT6R_WDATA_Field;
-- unspecified
Reserved_16_31 : HAL.UInt16;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for DFSDM_CHWDAT6R_Register use record
WDATA at 0 range 0 .. 15;
Reserved_16_31 at 0 range 16 .. 31;
end record;
subtype DFSDM_CHWDAT7R_WDATA_Field is HAL.UInt16;
-- DFSDM channel watchdog filter data register
type DFSDM_CHWDAT7R_Register is record
-- Read-only. Input channel y watchdog data
WDATA : DFSDM_CHWDAT7R_WDATA_Field;
-- unspecified
Reserved_16_31 : HAL.UInt16;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for DFSDM_CHWDAT7R_Register use record
WDATA at 0 range 0 .. 15;
Reserved_16_31 at 0 range 16 .. 31;
end record;
-- DFSDM_CHDATIN0R_INDAT array element
subtype DFSDM_CHDATIN0R_INDAT_Element is HAL.UInt16;
-- DFSDM_CHDATIN0R_INDAT array
type DFSDM_CHDATIN0R_INDAT_Field_Array is array (0 .. 1)
of DFSDM_CHDATIN0R_INDAT_Element
with Component_Size => 16, Size => 32;
-- DFSDM channel data input register
type DFSDM_CHDATIN0R_Register
(As_Array : Boolean := False)
is record
case As_Array is
when False =>
-- INDAT as a value
Val : HAL.UInt32;
when True =>
-- INDAT as an array
Arr : DFSDM_CHDATIN0R_INDAT_Field_Array;
end case;
end record
with Unchecked_Union, Size => 32, Volatile_Full_Access,
Bit_Order => System.Low_Order_First;
for DFSDM_CHDATIN0R_Register use record
Val at 0 range 0 .. 31;
Arr at 0 range 0 .. 31;
end record;
-- DFSDM_CHDATIN1R_INDAT array element
subtype DFSDM_CHDATIN1R_INDAT_Element is HAL.UInt16;
-- DFSDM_CHDATIN1R_INDAT array
type DFSDM_CHDATIN1R_INDAT_Field_Array is array (0 .. 1)
of DFSDM_CHDATIN1R_INDAT_Element
with Component_Size => 16, Size => 32;
-- DFSDM channel data input register
type DFSDM_CHDATIN1R_Register
(As_Array : Boolean := False)
is record
case As_Array is
when False =>
-- INDAT as a value
Val : HAL.UInt32;
when True =>
-- INDAT as an array
Arr : DFSDM_CHDATIN1R_INDAT_Field_Array;
end case;
end record
with Unchecked_Union, Size => 32, Volatile_Full_Access,
Bit_Order => System.Low_Order_First;
for DFSDM_CHDATIN1R_Register use record
Val at 0 range 0 .. 31;
Arr at 0 range 0 .. 31;
end record;
-- DFSDM_CHDATIN2R_INDAT array element
subtype DFSDM_CHDATIN2R_INDAT_Element is HAL.UInt16;
-- DFSDM_CHDATIN2R_INDAT array
type DFSDM_CHDATIN2R_INDAT_Field_Array is array (0 .. 1)
of DFSDM_CHDATIN2R_INDAT_Element
with Component_Size => 16, Size => 32;
-- DFSDM channel data input register
type DFSDM_CHDATIN2R_Register
(As_Array : Boolean := False)
is record
case As_Array is
when False =>
-- INDAT as a value
Val : HAL.UInt32;
when True =>
-- INDAT as an array
Arr : DFSDM_CHDATIN2R_INDAT_Field_Array;
end case;
end record
with Unchecked_Union, Size => 32, Volatile_Full_Access,
Bit_Order => System.Low_Order_First;
for DFSDM_CHDATIN2R_Register use record
Val at 0 range 0 .. 31;
Arr at 0 range 0 .. 31;
end record;
-- DFSDM_CHDATIN3R_INDAT array element
subtype DFSDM_CHDATIN3R_INDAT_Element is HAL.UInt16;
-- DFSDM_CHDATIN3R_INDAT array
type DFSDM_CHDATIN3R_INDAT_Field_Array is array (0 .. 1)
of DFSDM_CHDATIN3R_INDAT_Element
with Component_Size => 16, Size => 32;
-- DFSDM channel data input register
type DFSDM_CHDATIN3R_Register
(As_Array : Boolean := False)
is record
case As_Array is
when False =>
-- INDAT as a value
Val : HAL.UInt32;
when True =>
-- INDAT as an array
Arr : DFSDM_CHDATIN3R_INDAT_Field_Array;
end case;
end record
with Unchecked_Union, Size => 32, Volatile_Full_Access,
Bit_Order => System.Low_Order_First;
for DFSDM_CHDATIN3R_Register use record
Val at 0 range 0 .. 31;
Arr at 0 range 0 .. 31;
end record;
-- DFSDM_CHDATIN4R_INDAT array element
subtype DFSDM_CHDATIN4R_INDAT_Element is HAL.UInt16;
-- DFSDM_CHDATIN4R_INDAT array
type DFSDM_CHDATIN4R_INDAT_Field_Array is array (0 .. 1)
of DFSDM_CHDATIN4R_INDAT_Element
with Component_Size => 16, Size => 32;
-- DFSDM channel data input register
type DFSDM_CHDATIN4R_Register
(As_Array : Boolean := False)
is record
case As_Array is
when False =>
-- INDAT as a value
Val : HAL.UInt32;
when True =>
-- INDAT as an array
Arr : DFSDM_CHDATIN4R_INDAT_Field_Array;
end case;
end record
with Unchecked_Union, Size => 32, Volatile_Full_Access,
Bit_Order => System.Low_Order_First;
for DFSDM_CHDATIN4R_Register use record
Val at 0 range 0 .. 31;
Arr at 0 range 0 .. 31;
end record;
-- DFSDM_CHDATIN5R_INDAT array element
subtype DFSDM_CHDATIN5R_INDAT_Element is HAL.UInt16;
-- DFSDM_CHDATIN5R_INDAT array
type DFSDM_CHDATIN5R_INDAT_Field_Array is array (0 .. 1)
of DFSDM_CHDATIN5R_INDAT_Element
with Component_Size => 16, Size => 32;
-- DFSDM channel data input register
type DFSDM_CHDATIN5R_Register
(As_Array : Boolean := False)
is record
case As_Array is
when False =>
-- INDAT as a value
Val : HAL.UInt32;
when True =>
-- INDAT as an array
Arr : DFSDM_CHDATIN5R_INDAT_Field_Array;
end case;
end record
with Unchecked_Union, Size => 32, Volatile_Full_Access,
Bit_Order => System.Low_Order_First;
for DFSDM_CHDATIN5R_Register use record
Val at 0 range 0 .. 31;
Arr at 0 range 0 .. 31;
end record;
-- DFSDM_CHDATIN6R_INDAT array element
subtype DFSDM_CHDATIN6R_INDAT_Element is HAL.UInt16;
-- DFSDM_CHDATIN6R_INDAT array
type DFSDM_CHDATIN6R_INDAT_Field_Array is array (0 .. 1)
of DFSDM_CHDATIN6R_INDAT_Element
with Component_Size => 16, Size => 32;
-- DFSDM channel data input register
type DFSDM_CHDATIN6R_Register
(As_Array : Boolean := False)
is record
case As_Array is
when False =>
-- INDAT as a value
Val : HAL.UInt32;
when True =>
-- INDAT as an array
Arr : DFSDM_CHDATIN6R_INDAT_Field_Array;
end case;
end record
with Unchecked_Union, Size => 32, Volatile_Full_Access,
Bit_Order => System.Low_Order_First;
for DFSDM_CHDATIN6R_Register use record
Val at 0 range 0 .. 31;
Arr at 0 range 0 .. 31;
end record;
-- DFSDM_CHDATIN7R_INDAT array element
subtype DFSDM_CHDATIN7R_INDAT_Element is HAL.UInt16;
-- DFSDM_CHDATIN7R_INDAT array
type DFSDM_CHDATIN7R_INDAT_Field_Array is array (0 .. 1)
of DFSDM_CHDATIN7R_INDAT_Element
with Component_Size => 16, Size => 32;
-- DFSDM channel data input register
type DFSDM_CHDATIN7R_Register
(As_Array : Boolean := False)
is record
case As_Array is
when False =>
-- INDAT as a value
Val : HAL.UInt32;
when True =>
-- INDAT as an array
Arr : DFSDM_CHDATIN7R_INDAT_Field_Array;
end case;
end record
with Unchecked_Union, Size => 32, Volatile_Full_Access,
Bit_Order => System.Low_Order_First;
for DFSDM_CHDATIN7R_Register use record
Val at 0 range 0 .. 31;
Arr at 0 range 0 .. 31;
end record;
subtype DFSDM0_CR1_JEXTSEL_Field is HAL.UInt5;
subtype DFSDM0_CR1_JEXTEN_Field is HAL.UInt2;
subtype DFSDM0_CR1_RCH_Field is HAL.UInt3;
-- DFSDM control register 1
type DFSDM0_CR1_Register is record
-- DFSDM enable
DFEN : Boolean := False;
-- Start a conversion of the injected group of channels
JSWSTART : Boolean := False;
-- unspecified
Reserved_2_2 : HAL.Bit := 16#0#;
-- Launch an injected conversion synchronously with the DFSDM0 JSWSTART
-- trigger
JSYNC : Boolean := False;
-- Scanning conversion mode for injected conversions
JSCAN : Boolean := False;
-- DMA channel enabled to read data for the injected channel group
JDMAEN : Boolean := False;
-- unspecified
Reserved_6_7 : HAL.UInt2 := 16#0#;
-- Trigger signal selection for launching injected conversions
JEXTSEL : DFSDM0_CR1_JEXTSEL_Field := 16#0#;
-- Trigger enable and trigger edge selection for injected conversions
JEXTEN : DFSDM0_CR1_JEXTEN_Field := 16#0#;
-- unspecified
Reserved_15_16 : HAL.UInt2 := 16#0#;
-- Software start of a conversion on the regular channel
RSWSTART : Boolean := False;
-- Continuous mode selection for regular conversions
RCONT : Boolean := False;
-- Launch regular conversion synchronously with DFSDM0
RSYNC : Boolean := False;
-- unspecified
Reserved_20_20 : HAL.Bit := 16#0#;
-- DMA channel enabled to read data for the regular conversion
RDMAEN : Boolean := False;
-- unspecified
Reserved_22_23 : HAL.UInt2 := 16#0#;
-- Regular channel selection
RCH : DFSDM0_CR1_RCH_Field := 16#0#;
-- unspecified
Reserved_27_28 : HAL.UInt2 := 16#0#;
-- Fast conversion mode selection for regular conversions
FAST : Boolean := False;
-- Analog watchdog fast mode select
AWFSEL : Boolean := False;
-- unspecified
Reserved_31_31 : HAL.Bit := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for DFSDM0_CR1_Register use record
DFEN at 0 range 0 .. 0;
JSWSTART at 0 range 1 .. 1;
Reserved_2_2 at 0 range 2 .. 2;
JSYNC at 0 range 3 .. 3;
JSCAN at 0 range 4 .. 4;
JDMAEN at 0 range 5 .. 5;
Reserved_6_7 at 0 range 6 .. 7;
JEXTSEL at 0 range 8 .. 12;
JEXTEN at 0 range 13 .. 14;
Reserved_15_16 at 0 range 15 .. 16;
RSWSTART at 0 range 17 .. 17;
RCONT at 0 range 18 .. 18;
RSYNC at 0 range 19 .. 19;
Reserved_20_20 at 0 range 20 .. 20;
RDMAEN at 0 range 21 .. 21;
Reserved_22_23 at 0 range 22 .. 23;
RCH at 0 range 24 .. 26;
Reserved_27_28 at 0 range 27 .. 28;
FAST at 0 range 29 .. 29;
AWFSEL at 0 range 30 .. 30;
Reserved_31_31 at 0 range 31 .. 31;
end record;
subtype DFSDM1_CR1_JEXTSEL_Field is HAL.UInt5;
subtype DFSDM1_CR1_JEXTEN_Field is HAL.UInt2;
subtype DFSDM1_CR1_RCH_Field is HAL.UInt3;
-- DFSDM control register 1
type DFSDM1_CR1_Register is record
-- DFSDM enable
DFEN : Boolean := False;
-- Start a conversion of the injected group of channels
JSWSTART : Boolean := False;
-- unspecified
Reserved_2_2 : HAL.Bit := 16#0#;
-- Launch an injected conversion synchronously with the DFSDM0 JSWSTART
-- trigger
JSYNC : Boolean := False;
-- Scanning conversion mode for injected conversions
JSCAN : Boolean := False;
-- DMA channel enabled to read data for the injected channel group
JDMAEN : Boolean := False;
-- unspecified
Reserved_6_7 : HAL.UInt2 := 16#0#;
-- Trigger signal selection for launching injected conversions
JEXTSEL : DFSDM1_CR1_JEXTSEL_Field := 16#0#;
-- Trigger enable and trigger edge selection for injected conversions
JEXTEN : DFSDM1_CR1_JEXTEN_Field := 16#0#;
-- unspecified
Reserved_15_16 : HAL.UInt2 := 16#0#;
-- Software start of a conversion on the regular channel
RSWSTART : Boolean := False;
-- Continuous mode selection for regular conversions
RCONT : Boolean := False;
-- Launch regular conversion synchronously with DFSDM0
RSYNC : Boolean := False;
-- unspecified
Reserved_20_20 : HAL.Bit := 16#0#;
-- DMA channel enabled to read data for the regular conversion
RDMAEN : Boolean := False;
-- unspecified
Reserved_22_23 : HAL.UInt2 := 16#0#;
-- Regular channel selection
RCH : DFSDM1_CR1_RCH_Field := 16#0#;
-- unspecified
Reserved_27_28 : HAL.UInt2 := 16#0#;
-- Fast conversion mode selection for regular conversions
FAST : Boolean := False;
-- Analog watchdog fast mode select
AWFSEL : Boolean := False;
-- unspecified
Reserved_31_31 : HAL.Bit := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for DFSDM1_CR1_Register use record
DFEN at 0 range 0 .. 0;
JSWSTART at 0 range 1 .. 1;
Reserved_2_2 at 0 range 2 .. 2;
JSYNC at 0 range 3 .. 3;
JSCAN at 0 range 4 .. 4;
JDMAEN at 0 range 5 .. 5;
Reserved_6_7 at 0 range 6 .. 7;
JEXTSEL at 0 range 8 .. 12;
JEXTEN at 0 range 13 .. 14;
Reserved_15_16 at 0 range 15 .. 16;
RSWSTART at 0 range 17 .. 17;
RCONT at 0 range 18 .. 18;
RSYNC at 0 range 19 .. 19;
Reserved_20_20 at 0 range 20 .. 20;
RDMAEN at 0 range 21 .. 21;
Reserved_22_23 at 0 range 22 .. 23;
RCH at 0 range 24 .. 26;
Reserved_27_28 at 0 range 27 .. 28;
FAST at 0 range 29 .. 29;
AWFSEL at 0 range 30 .. 30;
Reserved_31_31 at 0 range 31 .. 31;
end record;
subtype DFSDM2_CR1_JEXTSEL_Field is HAL.UInt5;
subtype DFSDM2_CR1_JEXTEN_Field is HAL.UInt2;
subtype DFSDM2_CR1_RCH_Field is HAL.UInt3;
-- DFSDM control register 1
type DFSDM2_CR1_Register is record
-- DFSDM enable
DFEN : Boolean := False;
-- Start a conversion of the injected group of channels
JSWSTART : Boolean := False;
-- unspecified
Reserved_2_2 : HAL.Bit := 16#0#;
-- Launch an injected conversion synchronously with the DFSDM0 JSWSTART
-- trigger
JSYNC : Boolean := False;
-- Scanning conversion mode for injected conversions
JSCAN : Boolean := False;
-- DMA channel enabled to read data for the injected channel group
JDMAEN : Boolean := False;
-- unspecified
Reserved_6_7 : HAL.UInt2 := 16#0#;
-- Trigger signal selection for launching injected conversions
JEXTSEL : DFSDM2_CR1_JEXTSEL_Field := 16#0#;
-- Trigger enable and trigger edge selection for injected conversions
JEXTEN : DFSDM2_CR1_JEXTEN_Field := 16#0#;
-- unspecified
Reserved_15_16 : HAL.UInt2 := 16#0#;
-- Software start of a conversion on the regular channel
RSWSTART : Boolean := False;
-- Continuous mode selection for regular conversions
RCONT : Boolean := False;
-- Launch regular conversion synchronously with DFSDM0
RSYNC : Boolean := False;
-- unspecified
Reserved_20_20 : HAL.Bit := 16#0#;
-- DMA channel enabled to read data for the regular conversion
RDMAEN : Boolean := False;
-- unspecified
Reserved_22_23 : HAL.UInt2 := 16#0#;
-- Regular channel selection
RCH : DFSDM2_CR1_RCH_Field := 16#0#;
-- unspecified
Reserved_27_28 : HAL.UInt2 := 16#0#;
-- Fast conversion mode selection for regular conversions
FAST : Boolean := False;
-- Analog watchdog fast mode select
AWFSEL : Boolean := False;
-- unspecified
Reserved_31_31 : HAL.Bit := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for DFSDM2_CR1_Register use record
DFEN at 0 range 0 .. 0;
JSWSTART at 0 range 1 .. 1;
Reserved_2_2 at 0 range 2 .. 2;
JSYNC at 0 range 3 .. 3;
JSCAN at 0 range 4 .. 4;
JDMAEN at 0 range 5 .. 5;
Reserved_6_7 at 0 range 6 .. 7;
JEXTSEL at 0 range 8 .. 12;
JEXTEN at 0 range 13 .. 14;
Reserved_15_16 at 0 range 15 .. 16;
RSWSTART at 0 range 17 .. 17;
RCONT at 0 range 18 .. 18;
RSYNC at 0 range 19 .. 19;
Reserved_20_20 at 0 range 20 .. 20;
RDMAEN at 0 range 21 .. 21;
Reserved_22_23 at 0 range 22 .. 23;
RCH at 0 range 24 .. 26;
Reserved_27_28 at 0 range 27 .. 28;
FAST at 0 range 29 .. 29;
AWFSEL at 0 range 30 .. 30;
Reserved_31_31 at 0 range 31 .. 31;
end record;
subtype DFSDM3_CR1_JEXTSEL_Field is HAL.UInt5;
subtype DFSDM3_CR1_JEXTEN_Field is HAL.UInt2;
subtype DFSDM3_CR1_RCH_Field is HAL.UInt3;
-- DFSDM control register 1
type DFSDM3_CR1_Register is record
-- DFSDM enable
DFEN : Boolean := False;
-- Start a conversion of the injected group of channels
JSWSTART : Boolean := False;
-- unspecified
Reserved_2_2 : HAL.Bit := 16#0#;
-- Launch an injected conversion synchronously with the DFSDM0 JSWSTART
-- trigger
JSYNC : Boolean := False;
-- Scanning conversion mode for injected conversions
JSCAN : Boolean := False;
-- DMA channel enabled to read data for the injected channel group
JDMAEN : Boolean := False;
-- unspecified
Reserved_6_7 : HAL.UInt2 := 16#0#;
-- Trigger signal selection for launching injected conversions
JEXTSEL : DFSDM3_CR1_JEXTSEL_Field := 16#0#;
-- Trigger enable and trigger edge selection for injected conversions
JEXTEN : DFSDM3_CR1_JEXTEN_Field := 16#0#;
-- unspecified
Reserved_15_16 : HAL.UInt2 := 16#0#;
-- Software start of a conversion on the regular channel
RSWSTART : Boolean := False;
-- Continuous mode selection for regular conversions
RCONT : Boolean := False;
-- Launch regular conversion synchronously with DFSDM0
RSYNC : Boolean := False;
-- unspecified
Reserved_20_20 : HAL.Bit := 16#0#;
-- DMA channel enabled to read data for the regular conversion
RDMAEN : Boolean := False;
-- unspecified
Reserved_22_23 : HAL.UInt2 := 16#0#;
-- Regular channel selection
RCH : DFSDM3_CR1_RCH_Field := 16#0#;
-- unspecified
Reserved_27_28 : HAL.UInt2 := 16#0#;
-- Fast conversion mode selection for regular conversions
FAST : Boolean := False;
-- Analog watchdog fast mode select
AWFSEL : Boolean := False;
-- unspecified
Reserved_31_31 : HAL.Bit := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for DFSDM3_CR1_Register use record
DFEN at 0 range 0 .. 0;
JSWSTART at 0 range 1 .. 1;
Reserved_2_2 at 0 range 2 .. 2;
JSYNC at 0 range 3 .. 3;
JSCAN at 0 range 4 .. 4;
JDMAEN at 0 range 5 .. 5;
Reserved_6_7 at 0 range 6 .. 7;
JEXTSEL at 0 range 8 .. 12;
JEXTEN at 0 range 13 .. 14;
Reserved_15_16 at 0 range 15 .. 16;
RSWSTART at 0 range 17 .. 17;
RCONT at 0 range 18 .. 18;
RSYNC at 0 range 19 .. 19;
Reserved_20_20 at 0 range 20 .. 20;
RDMAEN at 0 range 21 .. 21;
Reserved_22_23 at 0 range 22 .. 23;
RCH at 0 range 24 .. 26;
Reserved_27_28 at 0 range 27 .. 28;
FAST at 0 range 29 .. 29;
AWFSEL at 0 range 30 .. 30;
Reserved_31_31 at 0 range 31 .. 31;
end record;
subtype DFSDM0_CR2_EXCH_Field is HAL.UInt8;
subtype DFSDM0_CR2_AWDCH_Field is HAL.UInt8;
-- DFSDM control register 2
type DFSDM0_CR2_Register is record
-- Injected end of conversion interrupt enable
JEOCIE : Boolean := False;
-- Regular end of conversion interrupt enable
REOCIE : Boolean := False;
-- Injected data overrun interrupt enable
JOVRIE : Boolean := False;
-- Regular data overrun interrupt enable
ROVRIE : Boolean := False;
-- Analog watchdog interrupt enable
AWDIE : Boolean := False;
-- Short-circuit detector interrupt enable
SCDIE : Boolean := False;
-- Clock absence interrupt enable
CKABIE : Boolean := False;
-- unspecified
Reserved_7_7 : HAL.Bit := 16#0#;
-- Extremes detector channel selection
EXCH : DFSDM0_CR2_EXCH_Field := 16#0#;
-- Analog watchdog channel selection
AWDCH : DFSDM0_CR2_AWDCH_Field := 16#0#;
-- unspecified
Reserved_24_31 : HAL.UInt8 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for DFSDM0_CR2_Register use record
JEOCIE at 0 range 0 .. 0;
REOCIE at 0 range 1 .. 1;
JOVRIE at 0 range 2 .. 2;
ROVRIE at 0 range 3 .. 3;
AWDIE at 0 range 4 .. 4;
SCDIE at 0 range 5 .. 5;
CKABIE at 0 range 6 .. 6;
Reserved_7_7 at 0 range 7 .. 7;
EXCH at 0 range 8 .. 15;
AWDCH at 0 range 16 .. 23;
Reserved_24_31 at 0 range 24 .. 31;
end record;
subtype DFSDM1_CR2_EXCH_Field is HAL.UInt8;
subtype DFSDM1_CR2_AWDCH_Field is HAL.UInt8;
-- DFSDM control register 2
type DFSDM1_CR2_Register is record
-- Injected end of conversion interrupt enable
JEOCIE : Boolean := False;
-- Regular end of conversion interrupt enable
REOCIE : Boolean := False;
-- Injected data overrun interrupt enable
JOVRIE : Boolean := False;
-- Regular data overrun interrupt enable
ROVRIE : Boolean := False;
-- Analog watchdog interrupt enable
AWDIE : Boolean := False;
-- Short-circuit detector interrupt enable
SCDIE : Boolean := False;
-- Clock absence interrupt enable
CKABIE : Boolean := False;
-- unspecified
Reserved_7_7 : HAL.Bit := 16#0#;
-- Extremes detector channel selection
EXCH : DFSDM1_CR2_EXCH_Field := 16#0#;
-- Analog watchdog channel selection
AWDCH : DFSDM1_CR2_AWDCH_Field := 16#0#;
-- unspecified
Reserved_24_31 : HAL.UInt8 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for DFSDM1_CR2_Register use record
JEOCIE at 0 range 0 .. 0;
REOCIE at 0 range 1 .. 1;
JOVRIE at 0 range 2 .. 2;
ROVRIE at 0 range 3 .. 3;
AWDIE at 0 range 4 .. 4;
SCDIE at 0 range 5 .. 5;
CKABIE at 0 range 6 .. 6;
Reserved_7_7 at 0 range 7 .. 7;
EXCH at 0 range 8 .. 15;
AWDCH at 0 range 16 .. 23;
Reserved_24_31 at 0 range 24 .. 31;
end record;
subtype DFSDM2_CR2_EXCH_Field is HAL.UInt8;
subtype DFSDM2_CR2_AWDCH_Field is HAL.UInt8;
-- DFSDM control register 2
type DFSDM2_CR2_Register is record
-- Injected end of conversion interrupt enable
JEOCIE : Boolean := False;
-- Regular end of conversion interrupt enable
REOCIE : Boolean := False;
-- Injected data overrun interrupt enable
JOVRIE : Boolean := False;
-- Regular data overrun interrupt enable
ROVRIE : Boolean := False;
-- Analog watchdog interrupt enable
AWDIE : Boolean := False;
-- Short-circuit detector interrupt enable
SCDIE : Boolean := False;
-- Clock absence interrupt enable
CKABIE : Boolean := False;
-- unspecified
Reserved_7_7 : HAL.Bit := 16#0#;
-- Extremes detector channel selection
EXCH : DFSDM2_CR2_EXCH_Field := 16#0#;
-- Analog watchdog channel selection
AWDCH : DFSDM2_CR2_AWDCH_Field := 16#0#;
-- unspecified
Reserved_24_31 : HAL.UInt8 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for DFSDM2_CR2_Register use record
JEOCIE at 0 range 0 .. 0;
REOCIE at 0 range 1 .. 1;
JOVRIE at 0 range 2 .. 2;
ROVRIE at 0 range 3 .. 3;
AWDIE at 0 range 4 .. 4;
SCDIE at 0 range 5 .. 5;
CKABIE at 0 range 6 .. 6;
Reserved_7_7 at 0 range 7 .. 7;
EXCH at 0 range 8 .. 15;
AWDCH at 0 range 16 .. 23;
Reserved_24_31 at 0 range 24 .. 31;
end record;
subtype DFSDM3_CR2_EXCH_Field is HAL.UInt8;
subtype DFSDM3_CR2_AWDCH_Field is HAL.UInt8;
-- DFSDM control register 2
type DFSDM3_CR2_Register is record
-- Injected end of conversion interrupt enable
JEOCIE : Boolean := False;
-- Regular end of conversion interrupt enable
REOCIE : Boolean := False;
-- Injected data overrun interrupt enable
JOVRIE : Boolean := False;
-- Regular data overrun interrupt enable
ROVRIE : Boolean := False;
-- Analog watchdog interrupt enable
AWDIE : Boolean := False;
-- Short-circuit detector interrupt enable
SCDIE : Boolean := False;
-- Clock absence interrupt enable
CKABIE : Boolean := False;
-- unspecified
Reserved_7_7 : HAL.Bit := 16#0#;
-- Extremes detector channel selection
EXCH : DFSDM3_CR2_EXCH_Field := 16#0#;
-- Analog watchdog channel selection
AWDCH : DFSDM3_CR2_AWDCH_Field := 16#0#;
-- unspecified
Reserved_24_31 : HAL.UInt8 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for DFSDM3_CR2_Register use record
JEOCIE at 0 range 0 .. 0;
REOCIE at 0 range 1 .. 1;
JOVRIE at 0 range 2 .. 2;
ROVRIE at 0 range 3 .. 3;
AWDIE at 0 range 4 .. 4;
SCDIE at 0 range 5 .. 5;
CKABIE at 0 range 6 .. 6;
Reserved_7_7 at 0 range 7 .. 7;
EXCH at 0 range 8 .. 15;
AWDCH at 0 range 16 .. 23;
Reserved_24_31 at 0 range 24 .. 31;
end record;
subtype DFSDM0_ISR_CKABF_Field is HAL.UInt8;
subtype DFSDM0_ISR_SCDF_Field is HAL.UInt8;
-- DFSDM interrupt and status register
type DFSDM0_ISR_Register is record
-- Read-only. End of injected conversion flag
JEOCF : Boolean;
-- Read-only. End of regular conversion flag
REOCF : Boolean;
-- Read-only. Injected conversion overrun flag
JOVRF : Boolean;
-- Read-only. Regular conversion overrun flag
ROVRF : Boolean;
-- Read-only. Analog watchdog
AWDF : Boolean;
-- unspecified
Reserved_5_12 : HAL.UInt8;
-- Read-only. Injected conversion in progress status
JCIP : Boolean;
-- Read-only. Regular conversion in progress status
RCIP : Boolean;
-- unspecified
Reserved_15_15 : HAL.Bit;
-- Read-only. Clock absence flag
CKABF : DFSDM0_ISR_CKABF_Field;
-- Read-only. short-circuit detector flag
SCDF : DFSDM0_ISR_SCDF_Field;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for DFSDM0_ISR_Register use record
JEOCF at 0 range 0 .. 0;
REOCF at 0 range 1 .. 1;
JOVRF at 0 range 2 .. 2;
ROVRF at 0 range 3 .. 3;
AWDF at 0 range 4 .. 4;
Reserved_5_12 at 0 range 5 .. 12;
JCIP at 0 range 13 .. 13;
RCIP at 0 range 14 .. 14;
Reserved_15_15 at 0 range 15 .. 15;
CKABF at 0 range 16 .. 23;
SCDF at 0 range 24 .. 31;
end record;
subtype DFSDM1_ISR_CKABF_Field is HAL.UInt8;
subtype DFSDM1_ISR_SCDF_Field is HAL.UInt8;
-- DFSDM interrupt and status register
type DFSDM1_ISR_Register is record
-- Read-only. End of injected conversion flag
JEOCF : Boolean;
-- Read-only. End of regular conversion flag
REOCF : Boolean;
-- Read-only. Injected conversion overrun flag
JOVRF : Boolean;
-- Read-only. Regular conversion overrun flag
ROVRF : Boolean;
-- Read-only. Analog watchdog
AWDF : Boolean;
-- unspecified
Reserved_5_12 : HAL.UInt8;
-- Read-only. Injected conversion in progress status
JCIP : Boolean;
-- Read-only. Regular conversion in progress status
RCIP : Boolean;
-- unspecified
Reserved_15_15 : HAL.Bit;
-- Read-only. Clock absence flag
CKABF : DFSDM1_ISR_CKABF_Field;
-- Read-only. short-circuit detector flag
SCDF : DFSDM1_ISR_SCDF_Field;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for DFSDM1_ISR_Register use record
JEOCF at 0 range 0 .. 0;
REOCF at 0 range 1 .. 1;
JOVRF at 0 range 2 .. 2;
ROVRF at 0 range 3 .. 3;
AWDF at 0 range 4 .. 4;
Reserved_5_12 at 0 range 5 .. 12;
JCIP at 0 range 13 .. 13;
RCIP at 0 range 14 .. 14;
Reserved_15_15 at 0 range 15 .. 15;
CKABF at 0 range 16 .. 23;
SCDF at 0 range 24 .. 31;
end record;
subtype DFSDM2_ISR_CKABF_Field is HAL.UInt8;
subtype DFSDM2_ISR_SCDF_Field is HAL.UInt8;
-- DFSDM interrupt and status register
type DFSDM2_ISR_Register is record
-- Read-only. End of injected conversion flag
JEOCF : Boolean;
-- Read-only. End of regular conversion flag
REOCF : Boolean;
-- Read-only. Injected conversion overrun flag
JOVRF : Boolean;
-- Read-only. Regular conversion overrun flag
ROVRF : Boolean;
-- Read-only. Analog watchdog
AWDF : Boolean;
-- unspecified
Reserved_5_12 : HAL.UInt8;
-- Read-only. Injected conversion in progress status
JCIP : Boolean;
-- Read-only. Regular conversion in progress status
RCIP : Boolean;
-- unspecified
Reserved_15_15 : HAL.Bit;
-- Read-only. Clock absence flag
CKABF : DFSDM2_ISR_CKABF_Field;
-- Read-only. short-circuit detector flag
SCDF : DFSDM2_ISR_SCDF_Field;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for DFSDM2_ISR_Register use record
JEOCF at 0 range 0 .. 0;
REOCF at 0 range 1 .. 1;
JOVRF at 0 range 2 .. 2;
ROVRF at 0 range 3 .. 3;
AWDF at 0 range 4 .. 4;
Reserved_5_12 at 0 range 5 .. 12;
JCIP at 0 range 13 .. 13;
RCIP at 0 range 14 .. 14;
Reserved_15_15 at 0 range 15 .. 15;
CKABF at 0 range 16 .. 23;
SCDF at 0 range 24 .. 31;
end record;
subtype DFSDM3_ISR_CKABF_Field is HAL.UInt8;
subtype DFSDM3_ISR_SCDF_Field is HAL.UInt8;
-- DFSDM interrupt and status register
type DFSDM3_ISR_Register is record
-- Read-only. End of injected conversion flag
JEOCF : Boolean;
-- Read-only. End of regular conversion flag
REOCF : Boolean;
-- Read-only. Injected conversion overrun flag
JOVRF : Boolean;
-- Read-only. Regular conversion overrun flag
ROVRF : Boolean;
-- Read-only. Analog watchdog
AWDF : Boolean;
-- unspecified
Reserved_5_12 : HAL.UInt8;
-- Read-only. Injected conversion in progress status
JCIP : Boolean;
-- Read-only. Regular conversion in progress status
RCIP : Boolean;
-- unspecified
Reserved_15_15 : HAL.Bit;
-- Read-only. Clock absence flag
CKABF : DFSDM3_ISR_CKABF_Field;
-- Read-only. short-circuit detector flag
SCDF : DFSDM3_ISR_SCDF_Field;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for DFSDM3_ISR_Register use record
JEOCF at 0 range 0 .. 0;
REOCF at 0 range 1 .. 1;
JOVRF at 0 range 2 .. 2;
ROVRF at 0 range 3 .. 3;
AWDF at 0 range 4 .. 4;
Reserved_5_12 at 0 range 5 .. 12;
JCIP at 0 range 13 .. 13;
RCIP at 0 range 14 .. 14;
Reserved_15_15 at 0 range 15 .. 15;
CKABF at 0 range 16 .. 23;
SCDF at 0 range 24 .. 31;
end record;
subtype DFSDM0_ICR_CLRCKABF_Field is HAL.UInt8;
subtype DFSDM0_ICR_CLRSCDF_Field is HAL.UInt8;
-- DFSDM interrupt flag clear register
type DFSDM0_ICR_Register is record
-- unspecified
Reserved_0_1 : HAL.UInt2 := 16#0#;
-- Clear the injected conversion overrun flag
CLRJOVRF : Boolean := False;
-- Clear the regular conversion overrun flag
CLRROVRF : Boolean := False;
-- unspecified
Reserved_4_15 : HAL.UInt12 := 16#0#;
-- Clear the clock absence flag
CLRCKABF : DFSDM0_ICR_CLRCKABF_Field := 16#0#;
-- Clear the short-circuit detector flag
CLRSCDF : DFSDM0_ICR_CLRSCDF_Field := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for DFSDM0_ICR_Register use record
Reserved_0_1 at 0 range 0 .. 1;
CLRJOVRF at 0 range 2 .. 2;
CLRROVRF at 0 range 3 .. 3;
Reserved_4_15 at 0 range 4 .. 15;
CLRCKABF at 0 range 16 .. 23;
CLRSCDF at 0 range 24 .. 31;
end record;
subtype DFSDM1_ICR_CLRCKABF_Field is HAL.UInt8;
subtype DFSDM1_ICR_CLRSCDF_Field is HAL.UInt8;
-- DFSDM interrupt flag clear register
type DFSDM1_ICR_Register is record
-- unspecified
Reserved_0_1 : HAL.UInt2 := 16#0#;
-- Clear the injected conversion overrun flag
CLRJOVRF : Boolean := False;
-- Clear the regular conversion overrun flag
CLRROVRF : Boolean := False;
-- unspecified
Reserved_4_15 : HAL.UInt12 := 16#0#;
-- Clear the clock absence flag
CLRCKABF : DFSDM1_ICR_CLRCKABF_Field := 16#0#;
-- Clear the short-circuit detector flag
CLRSCDF : DFSDM1_ICR_CLRSCDF_Field := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for DFSDM1_ICR_Register use record
Reserved_0_1 at 0 range 0 .. 1;
CLRJOVRF at 0 range 2 .. 2;
CLRROVRF at 0 range 3 .. 3;
Reserved_4_15 at 0 range 4 .. 15;
CLRCKABF at 0 range 16 .. 23;
CLRSCDF at 0 range 24 .. 31;
end record;
subtype DFSDM2_ICR_CLRCKABF_Field is HAL.UInt8;
subtype DFSDM2_ICR_CLRSCDF_Field is HAL.UInt8;
-- DFSDM interrupt flag clear register
type DFSDM2_ICR_Register is record
-- unspecified
Reserved_0_1 : HAL.UInt2 := 16#0#;
-- Clear the injected conversion overrun flag
CLRJOVRF : Boolean := False;
-- Clear the regular conversion overrun flag
CLRROVRF : Boolean := False;
-- unspecified
Reserved_4_15 : HAL.UInt12 := 16#0#;
-- Clear the clock absence flag
CLRCKABF : DFSDM2_ICR_CLRCKABF_Field := 16#0#;
-- Clear the short-circuit detector flag
CLRSCDF : DFSDM2_ICR_CLRSCDF_Field := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for DFSDM2_ICR_Register use record
Reserved_0_1 at 0 range 0 .. 1;
CLRJOVRF at 0 range 2 .. 2;
CLRROVRF at 0 range 3 .. 3;
Reserved_4_15 at 0 range 4 .. 15;
CLRCKABF at 0 range 16 .. 23;
CLRSCDF at 0 range 24 .. 31;
end record;
subtype DFSDM3_ICR_CLRCKABF_Field is HAL.UInt8;
subtype DFSDM3_ICR_CLRSCDF_Field is HAL.UInt8;
-- DFSDM interrupt flag clear register
type DFSDM3_ICR_Register is record
-- unspecified
Reserved_0_1 : HAL.UInt2 := 16#0#;
-- Clear the injected conversion overrun flag
CLRJOVRF : Boolean := False;
-- Clear the regular conversion overrun flag
CLRROVRF : Boolean := False;
-- unspecified
Reserved_4_15 : HAL.UInt12 := 16#0#;
-- Clear the clock absence flag
CLRCKABF : DFSDM3_ICR_CLRCKABF_Field := 16#0#;
-- Clear the short-circuit detector flag
CLRSCDF : DFSDM3_ICR_CLRSCDF_Field := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for DFSDM3_ICR_Register use record
Reserved_0_1 at 0 range 0 .. 1;
CLRJOVRF at 0 range 2 .. 2;
CLRROVRF at 0 range 3 .. 3;
Reserved_4_15 at 0 range 4 .. 15;
CLRCKABF at 0 range 16 .. 23;
CLRSCDF at 0 range 24 .. 31;
end record;
subtype DFSDM0_JCHGR_JCHG_Field is HAL.UInt8;
-- DFSDM injected channel group selection register
type DFSDM0_JCHGR_Register is record
-- Injected channel group selection
JCHG : DFSDM0_JCHGR_JCHG_Field := 16#0#;
-- unspecified
Reserved_8_31 : HAL.UInt24 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for DFSDM0_JCHGR_Register use record
JCHG at 0 range 0 .. 7;
Reserved_8_31 at 0 range 8 .. 31;
end record;
subtype DFSDM1_JCHGR_JCHG_Field is HAL.UInt8;
-- DFSDM injected channel group selection register
type DFSDM1_JCHGR_Register is record
-- Injected channel group selection
JCHG : DFSDM1_JCHGR_JCHG_Field := 16#0#;
-- unspecified
Reserved_8_31 : HAL.UInt24 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for DFSDM1_JCHGR_Register use record
JCHG at 0 range 0 .. 7;
Reserved_8_31 at 0 range 8 .. 31;
end record;
subtype DFSDM2_JCHGR_JCHG_Field is HAL.UInt8;
-- DFSDM injected channel group selection register
type DFSDM2_JCHGR_Register is record
-- Injected channel group selection
JCHG : DFSDM2_JCHGR_JCHG_Field := 16#0#;
-- unspecified
Reserved_8_31 : HAL.UInt24 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for DFSDM2_JCHGR_Register use record
JCHG at 0 range 0 .. 7;
Reserved_8_31 at 0 range 8 .. 31;
end record;
subtype DFSDM3_JCHGR_JCHG_Field is HAL.UInt8;
-- DFSDM injected channel group selection register
type DFSDM3_JCHGR_Register is record
-- Injected channel group selection
JCHG : DFSDM3_JCHGR_JCHG_Field := 16#0#;
-- unspecified
Reserved_8_31 : HAL.UInt24 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for DFSDM3_JCHGR_Register use record
JCHG at 0 range 0 .. 7;
Reserved_8_31 at 0 range 8 .. 31;
end record;
subtype DFSDM0_FCR_IOSR_Field is HAL.UInt8;
subtype DFSDM0_FCR_FOSR_Field is HAL.UInt10;
subtype DFSDM0_FCR_FORD_Field is HAL.UInt3;
-- DFSDM filter control register
type DFSDM0_FCR_Register is record
-- Integrator oversampling ratio (averaging length)
IOSR : DFSDM0_FCR_IOSR_Field := 16#0#;
-- unspecified
Reserved_8_15 : HAL.UInt8 := 16#0#;
-- Sinc filter oversampling ratio (decimation rate)
FOSR : DFSDM0_FCR_FOSR_Field := 16#0#;
-- unspecified
Reserved_26_28 : HAL.UInt3 := 16#0#;
-- Sinc filter order
FORD : DFSDM0_FCR_FORD_Field := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for DFSDM0_FCR_Register use record
IOSR at 0 range 0 .. 7;
Reserved_8_15 at 0 range 8 .. 15;
FOSR at 0 range 16 .. 25;
Reserved_26_28 at 0 range 26 .. 28;
FORD at 0 range 29 .. 31;
end record;
subtype DFSDM1_FCR_IOSR_Field is HAL.UInt8;
subtype DFSDM1_FCR_FOSR_Field is HAL.UInt10;
subtype DFSDM1_FCR_FORD_Field is HAL.UInt3;
-- DFSDM filter control register
type DFSDM1_FCR_Register is record
-- Integrator oversampling ratio (averaging length)
IOSR : DFSDM1_FCR_IOSR_Field := 16#0#;
-- unspecified
Reserved_8_15 : HAL.UInt8 := 16#0#;
-- Sinc filter oversampling ratio (decimation rate)
FOSR : DFSDM1_FCR_FOSR_Field := 16#0#;
-- unspecified
Reserved_26_28 : HAL.UInt3 := 16#0#;
-- Sinc filter order
FORD : DFSDM1_FCR_FORD_Field := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for DFSDM1_FCR_Register use record
IOSR at 0 range 0 .. 7;
Reserved_8_15 at 0 range 8 .. 15;
FOSR at 0 range 16 .. 25;
Reserved_26_28 at 0 range 26 .. 28;
FORD at 0 range 29 .. 31;
end record;
subtype DFSDM2_FCR_IOSR_Field is HAL.UInt8;
subtype DFSDM2_FCR_FOSR_Field is HAL.UInt10;
subtype DFSDM2_FCR_FORD_Field is HAL.UInt3;
-- DFSDM filter control register
type DFSDM2_FCR_Register is record
-- Integrator oversampling ratio (averaging length)
IOSR : DFSDM2_FCR_IOSR_Field := 16#0#;
-- unspecified
Reserved_8_15 : HAL.UInt8 := 16#0#;
-- Sinc filter oversampling ratio (decimation rate)
FOSR : DFSDM2_FCR_FOSR_Field := 16#0#;
-- unspecified
Reserved_26_28 : HAL.UInt3 := 16#0#;
-- Sinc filter order
FORD : DFSDM2_FCR_FORD_Field := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for DFSDM2_FCR_Register use record
IOSR at 0 range 0 .. 7;
Reserved_8_15 at 0 range 8 .. 15;
FOSR at 0 range 16 .. 25;
Reserved_26_28 at 0 range 26 .. 28;
FORD at 0 range 29 .. 31;
end record;
subtype DFSDM3_FCR_IOSR_Field is HAL.UInt8;
subtype DFSDM3_FCR_FOSR_Field is HAL.UInt10;
subtype DFSDM3_FCR_FORD_Field is HAL.UInt3;
-- DFSDM filter control register
type DFSDM3_FCR_Register is record
-- Integrator oversampling ratio (averaging length)
IOSR : DFSDM3_FCR_IOSR_Field := 16#0#;
-- unspecified
Reserved_8_15 : HAL.UInt8 := 16#0#;
-- Sinc filter oversampling ratio (decimation rate)
FOSR : DFSDM3_FCR_FOSR_Field := 16#0#;
-- unspecified
Reserved_26_28 : HAL.UInt3 := 16#0#;
-- Sinc filter order
FORD : DFSDM3_FCR_FORD_Field := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for DFSDM3_FCR_Register use record
IOSR at 0 range 0 .. 7;
Reserved_8_15 at 0 range 8 .. 15;
FOSR at 0 range 16 .. 25;
Reserved_26_28 at 0 range 26 .. 28;
FORD at 0 range 29 .. 31;
end record;
subtype DFSDM0_JDATAR_JDATACH_Field is HAL.UInt3;
subtype DFSDM0_JDATAR_JDATA_Field is HAL.UInt24;
-- DFSDM data register for injected group
type DFSDM0_JDATAR_Register is record
-- Read-only. Injected channel most recently converted
JDATACH : DFSDM0_JDATAR_JDATACH_Field;
-- unspecified
Reserved_3_7 : HAL.UInt5;
-- Read-only. Injected group conversion data
JDATA : DFSDM0_JDATAR_JDATA_Field;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for DFSDM0_JDATAR_Register use record
JDATACH at 0 range 0 .. 2;
Reserved_3_7 at 0 range 3 .. 7;
JDATA at 0 range 8 .. 31;
end record;
subtype DFSDM1_JDATAR_JDATACH_Field is HAL.UInt3;
subtype DFSDM1_JDATAR_JDATA_Field is HAL.UInt24;
-- DFSDM data register for injected group
type DFSDM1_JDATAR_Register is record
-- Read-only. Injected channel most recently converted
JDATACH : DFSDM1_JDATAR_JDATACH_Field;
-- unspecified
Reserved_3_7 : HAL.UInt5;
-- Read-only. Injected group conversion data
JDATA : DFSDM1_JDATAR_JDATA_Field;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for DFSDM1_JDATAR_Register use record
JDATACH at 0 range 0 .. 2;
Reserved_3_7 at 0 range 3 .. 7;
JDATA at 0 range 8 .. 31;
end record;
subtype DFSDM2_JDATAR_JDATACH_Field is HAL.UInt3;
subtype DFSDM2_JDATAR_JDATA_Field is HAL.UInt24;
-- DFSDM data register for injected group
type DFSDM2_JDATAR_Register is record
-- Read-only. Injected channel most recently converted
JDATACH : DFSDM2_JDATAR_JDATACH_Field;
-- unspecified
Reserved_3_7 : HAL.UInt5;
-- Read-only. Injected group conversion data
JDATA : DFSDM2_JDATAR_JDATA_Field;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for DFSDM2_JDATAR_Register use record
JDATACH at 0 range 0 .. 2;
Reserved_3_7 at 0 range 3 .. 7;
JDATA at 0 range 8 .. 31;
end record;
subtype DFSDM3_JDATAR_JDATACH_Field is HAL.UInt3;
subtype DFSDM3_JDATAR_JDATA_Field is HAL.UInt24;
-- DFSDM data register for injected group
type DFSDM3_JDATAR_Register is record
-- Read-only. Injected channel most recently converted
JDATACH : DFSDM3_JDATAR_JDATACH_Field;
-- unspecified
Reserved_3_7 : HAL.UInt5;
-- Read-only. Injected group conversion data
JDATA : DFSDM3_JDATAR_JDATA_Field;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for DFSDM3_JDATAR_Register use record
JDATACH at 0 range 0 .. 2;
Reserved_3_7 at 0 range 3 .. 7;
JDATA at 0 range 8 .. 31;
end record;
subtype DFSDM0_RDATAR_RDATACH_Field is HAL.UInt3;
subtype DFSDM0_RDATAR_RDATA_Field is HAL.UInt24;
-- DFSDM data register for the regular channel
type DFSDM0_RDATAR_Register is record
-- Read-only. Regular channel most recently converted
RDATACH : DFSDM0_RDATAR_RDATACH_Field;
-- unspecified
Reserved_3_3 : HAL.Bit;
-- Read-only. Regular channel pending data
RPEND : Boolean;
-- unspecified
Reserved_5_7 : HAL.UInt3;
-- Read-only. Regular channel conversion data
RDATA : DFSDM0_RDATAR_RDATA_Field;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for DFSDM0_RDATAR_Register use record
RDATACH at 0 range 0 .. 2;
Reserved_3_3 at 0 range 3 .. 3;
RPEND at 0 range 4 .. 4;
Reserved_5_7 at 0 range 5 .. 7;
RDATA at 0 range 8 .. 31;
end record;
subtype DFSDM1_RDATAR_RDATACH_Field is HAL.UInt3;
subtype DFSDM1_RDATAR_RDATA_Field is HAL.UInt24;
-- DFSDM data register for the regular channel
type DFSDM1_RDATAR_Register is record
-- Read-only. Regular channel most recently converted
RDATACH : DFSDM1_RDATAR_RDATACH_Field;
-- unspecified
Reserved_3_3 : HAL.Bit;
-- Read-only. Regular channel pending data
RPEND : Boolean;
-- unspecified
Reserved_5_7 : HAL.UInt3;
-- Read-only. Regular channel conversion data
RDATA : DFSDM1_RDATAR_RDATA_Field;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for DFSDM1_RDATAR_Register use record
RDATACH at 0 range 0 .. 2;
Reserved_3_3 at 0 range 3 .. 3;
RPEND at 0 range 4 .. 4;
Reserved_5_7 at 0 range 5 .. 7;
RDATA at 0 range 8 .. 31;
end record;
subtype DFSDM2_RDATAR_RDATACH_Field is HAL.UInt3;
subtype DFSDM2_RDATAR_RDATA_Field is HAL.UInt24;
-- DFSDM data register for the regular channel
type DFSDM2_RDATAR_Register is record
-- Read-only. Regular channel most recently converted
RDATACH : DFSDM2_RDATAR_RDATACH_Field;
-- unspecified
Reserved_3_3 : HAL.Bit;
-- Read-only. Regular channel pending data
RPEND : Boolean;
-- unspecified
Reserved_5_7 : HAL.UInt3;
-- Read-only. Regular channel conversion data
RDATA : DFSDM2_RDATAR_RDATA_Field;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for DFSDM2_RDATAR_Register use record
RDATACH at 0 range 0 .. 2;
Reserved_3_3 at 0 range 3 .. 3;
RPEND at 0 range 4 .. 4;
Reserved_5_7 at 0 range 5 .. 7;
RDATA at 0 range 8 .. 31;
end record;
subtype DFSDM3_RDATAR_RDATACH_Field is HAL.UInt3;
subtype DFSDM3_RDATAR_RDATA_Field is HAL.UInt24;
-- DFSDM data register for the regular channel
type DFSDM3_RDATAR_Register is record
-- Read-only. Regular channel most recently converted
RDATACH : DFSDM3_RDATAR_RDATACH_Field;
-- unspecified
Reserved_3_3 : HAL.Bit;
-- Read-only. Regular channel pending data
RPEND : Boolean;
-- unspecified
Reserved_5_7 : HAL.UInt3;
-- Read-only. Regular channel conversion data
RDATA : DFSDM3_RDATAR_RDATA_Field;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for DFSDM3_RDATAR_Register use record
RDATACH at 0 range 0 .. 2;
Reserved_3_3 at 0 range 3 .. 3;
RPEND at 0 range 4 .. 4;
Reserved_5_7 at 0 range 5 .. 7;
RDATA at 0 range 8 .. 31;
end record;
subtype DFSDM0_AWHTR_BKAWH_Field is HAL.UInt4;
subtype DFSDM0_AWHTR_AWHT_Field is HAL.UInt24;
-- DFSDM analog watchdog high threshold register
type DFSDM0_AWHTR_Register is record
-- Break signal assignment to analog watchdog high threshold event
BKAWH : DFSDM0_AWHTR_BKAWH_Field := 16#0#;
-- unspecified
Reserved_4_7 : HAL.UInt4 := 16#0#;
-- Analog watchdog high threshold
AWHT : DFSDM0_AWHTR_AWHT_Field := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for DFSDM0_AWHTR_Register use record
BKAWH at 0 range 0 .. 3;
Reserved_4_7 at 0 range 4 .. 7;
AWHT at 0 range 8 .. 31;
end record;
subtype DFSDM1_AWHTR_BKAWH_Field is HAL.UInt4;
subtype DFSDM1_AWHTR_AWHT_Field is HAL.UInt24;
-- DFSDM analog watchdog high threshold register
type DFSDM1_AWHTR_Register is record
-- Break signal assignment to analog watchdog high threshold event
BKAWH : DFSDM1_AWHTR_BKAWH_Field := 16#0#;
-- unspecified
Reserved_4_7 : HAL.UInt4 := 16#0#;
-- Analog watchdog high threshold
AWHT : DFSDM1_AWHTR_AWHT_Field := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for DFSDM1_AWHTR_Register use record
BKAWH at 0 range 0 .. 3;
Reserved_4_7 at 0 range 4 .. 7;
AWHT at 0 range 8 .. 31;
end record;
subtype DFSDM2_AWHTR_BKAWH_Field is HAL.UInt4;
subtype DFSDM2_AWHTR_AWHT_Field is HAL.UInt24;
-- DFSDM analog watchdog high threshold register
type DFSDM2_AWHTR_Register is record
-- Break signal assignment to analog watchdog high threshold event
BKAWH : DFSDM2_AWHTR_BKAWH_Field := 16#0#;
-- unspecified
Reserved_4_7 : HAL.UInt4 := 16#0#;
-- Analog watchdog high threshold
AWHT : DFSDM2_AWHTR_AWHT_Field := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for DFSDM2_AWHTR_Register use record
BKAWH at 0 range 0 .. 3;
Reserved_4_7 at 0 range 4 .. 7;
AWHT at 0 range 8 .. 31;
end record;
subtype DFSDM3_AWHTR_BKAWH_Field is HAL.UInt4;
subtype DFSDM3_AWHTR_AWHT_Field is HAL.UInt24;
-- DFSDM analog watchdog high threshold register
type DFSDM3_AWHTR_Register is record
-- Break signal assignment to analog watchdog high threshold event
BKAWH : DFSDM3_AWHTR_BKAWH_Field := 16#0#;
-- unspecified
Reserved_4_7 : HAL.UInt4 := 16#0#;
-- Analog watchdog high threshold
AWHT : DFSDM3_AWHTR_AWHT_Field := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for DFSDM3_AWHTR_Register use record
BKAWH at 0 range 0 .. 3;
Reserved_4_7 at 0 range 4 .. 7;
AWHT at 0 range 8 .. 31;
end record;
subtype DFSDM0_AWLTR_BKAWL_Field is HAL.UInt4;
subtype DFSDM0_AWLTR_AWLT_Field is HAL.UInt24;
-- DFSDM analog watchdog low threshold register
type DFSDM0_AWLTR_Register is record
-- Break signal assignment to analog watchdog low threshold event
BKAWL : DFSDM0_AWLTR_BKAWL_Field := 16#0#;
-- unspecified
Reserved_4_7 : HAL.UInt4 := 16#0#;
-- Analog watchdog low threshold
AWLT : DFSDM0_AWLTR_AWLT_Field := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for DFSDM0_AWLTR_Register use record
BKAWL at 0 range 0 .. 3;
Reserved_4_7 at 0 range 4 .. 7;
AWLT at 0 range 8 .. 31;
end record;
subtype DFSDM1_AWLTR_BKAWL_Field is HAL.UInt4;
subtype DFSDM1_AWLTR_AWLT_Field is HAL.UInt24;
-- DFSDM analog watchdog low threshold register
type DFSDM1_AWLTR_Register is record
-- Break signal assignment to analog watchdog low threshold event
BKAWL : DFSDM1_AWLTR_BKAWL_Field := 16#0#;
-- unspecified
Reserved_4_7 : HAL.UInt4 := 16#0#;
-- Analog watchdog low threshold
AWLT : DFSDM1_AWLTR_AWLT_Field := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for DFSDM1_AWLTR_Register use record
BKAWL at 0 range 0 .. 3;
Reserved_4_7 at 0 range 4 .. 7;
AWLT at 0 range 8 .. 31;
end record;
subtype DFSDM2_AWLTR_BKAWL_Field is HAL.UInt4;
subtype DFSDM2_AWLTR_AWLT_Field is HAL.UInt24;
-- DFSDM analog watchdog low threshold register
type DFSDM2_AWLTR_Register is record
-- Break signal assignment to analog watchdog low threshold event
BKAWL : DFSDM2_AWLTR_BKAWL_Field := 16#0#;
-- unspecified
Reserved_4_7 : HAL.UInt4 := 16#0#;
-- Analog watchdog low threshold
AWLT : DFSDM2_AWLTR_AWLT_Field := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for DFSDM2_AWLTR_Register use record
BKAWL at 0 range 0 .. 3;
Reserved_4_7 at 0 range 4 .. 7;
AWLT at 0 range 8 .. 31;
end record;
subtype DFSDM3_AWLTR_BKAWL_Field is HAL.UInt4;
subtype DFSDM3_AWLTR_AWLT_Field is HAL.UInt24;
-- DFSDM analog watchdog low threshold register
type DFSDM3_AWLTR_Register is record
-- Break signal assignment to analog watchdog low threshold event
BKAWL : DFSDM3_AWLTR_BKAWL_Field := 16#0#;
-- unspecified
Reserved_4_7 : HAL.UInt4 := 16#0#;
-- Analog watchdog low threshold
AWLT : DFSDM3_AWLTR_AWLT_Field := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for DFSDM3_AWLTR_Register use record
BKAWL at 0 range 0 .. 3;
Reserved_4_7 at 0 range 4 .. 7;
AWLT at 0 range 8 .. 31;
end record;
subtype DFSDM0_AWSR_AWLTF_Field is HAL.UInt8;
subtype DFSDM0_AWSR_AWHTF_Field is HAL.UInt8;
-- DFSDM analog watchdog status register
type DFSDM0_AWSR_Register is record
-- Read-only. Analog watchdog low threshold flag
AWLTF : DFSDM0_AWSR_AWLTF_Field;
-- Read-only. Analog watchdog high threshold flag
AWHTF : DFSDM0_AWSR_AWHTF_Field;
-- unspecified
Reserved_16_31 : HAL.UInt16;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for DFSDM0_AWSR_Register use record
AWLTF at 0 range 0 .. 7;
AWHTF at 0 range 8 .. 15;
Reserved_16_31 at 0 range 16 .. 31;
end record;
subtype DFSDM1_AWSR_AWLTF_Field is HAL.UInt8;
subtype DFSDM1_AWSR_AWHTF_Field is HAL.UInt8;
-- DFSDM analog watchdog status register
type DFSDM1_AWSR_Register is record
-- Read-only. Analog watchdog low threshold flag
AWLTF : DFSDM1_AWSR_AWLTF_Field;
-- Read-only. Analog watchdog high threshold flag
AWHTF : DFSDM1_AWSR_AWHTF_Field;
-- unspecified
Reserved_16_31 : HAL.UInt16;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for DFSDM1_AWSR_Register use record
AWLTF at 0 range 0 .. 7;
AWHTF at 0 range 8 .. 15;
Reserved_16_31 at 0 range 16 .. 31;
end record;
subtype DFSDM2_AWSR_AWLTF_Field is HAL.UInt8;
subtype DFSDM2_AWSR_AWHTF_Field is HAL.UInt8;
-- DFSDM analog watchdog status register
type DFSDM2_AWSR_Register is record
-- Read-only. Analog watchdog low threshold flag
AWLTF : DFSDM2_AWSR_AWLTF_Field;
-- Read-only. Analog watchdog high threshold flag
AWHTF : DFSDM2_AWSR_AWHTF_Field;
-- unspecified
Reserved_16_31 : HAL.UInt16;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for DFSDM2_AWSR_Register use record
AWLTF at 0 range 0 .. 7;
AWHTF at 0 range 8 .. 15;
Reserved_16_31 at 0 range 16 .. 31;
end record;
subtype DFSDM3_AWSR_AWLTF_Field is HAL.UInt8;
subtype DFSDM3_AWSR_AWHTF_Field is HAL.UInt8;
-- DFSDM analog watchdog status register
type DFSDM3_AWSR_Register is record
-- Read-only. Analog watchdog low threshold flag
AWLTF : DFSDM3_AWSR_AWLTF_Field;
-- Read-only. Analog watchdog high threshold flag
AWHTF : DFSDM3_AWSR_AWHTF_Field;
-- unspecified
Reserved_16_31 : HAL.UInt16;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for DFSDM3_AWSR_Register use record
AWLTF at 0 range 0 .. 7;
AWHTF at 0 range 8 .. 15;
Reserved_16_31 at 0 range 16 .. 31;
end record;
subtype DFSDM0_AWCFR_CLRAWLTF_Field is HAL.UInt8;
subtype DFSDM0_AWCFR_CLRAWHTF_Field is HAL.UInt8;
-- DFSDM analog watchdog clear flag register
type DFSDM0_AWCFR_Register is record
-- Clear the analog watchdog low threshold flag
CLRAWLTF : DFSDM0_AWCFR_CLRAWLTF_Field := 16#0#;
-- Clear the analog watchdog high threshold flag
CLRAWHTF : DFSDM0_AWCFR_CLRAWHTF_Field := 16#0#;
-- unspecified
Reserved_16_31 : HAL.UInt16 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for DFSDM0_AWCFR_Register use record
CLRAWLTF at 0 range 0 .. 7;
CLRAWHTF at 0 range 8 .. 15;
Reserved_16_31 at 0 range 16 .. 31;
end record;
subtype DFSDM1_AWCFR_CLRAWLTF_Field is HAL.UInt8;
subtype DFSDM1_AWCFR_CLRAWHTF_Field is HAL.UInt8;
-- DFSDM analog watchdog clear flag register
type DFSDM1_AWCFR_Register is record
-- Clear the analog watchdog low threshold flag
CLRAWLTF : DFSDM1_AWCFR_CLRAWLTF_Field := 16#0#;
-- Clear the analog watchdog high threshold flag
CLRAWHTF : DFSDM1_AWCFR_CLRAWHTF_Field := 16#0#;
-- unspecified
Reserved_16_31 : HAL.UInt16 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for DFSDM1_AWCFR_Register use record
CLRAWLTF at 0 range 0 .. 7;
CLRAWHTF at 0 range 8 .. 15;
Reserved_16_31 at 0 range 16 .. 31;
end record;
subtype DFSDM2_AWCFR_CLRAWLTF_Field is HAL.UInt8;
subtype DFSDM2_AWCFR_CLRAWHTF_Field is HAL.UInt8;
-- DFSDM analog watchdog clear flag register
type DFSDM2_AWCFR_Register is record
-- Clear the analog watchdog low threshold flag
CLRAWLTF : DFSDM2_AWCFR_CLRAWLTF_Field := 16#0#;
-- Clear the analog watchdog high threshold flag
CLRAWHTF : DFSDM2_AWCFR_CLRAWHTF_Field := 16#0#;
-- unspecified
Reserved_16_31 : HAL.UInt16 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for DFSDM2_AWCFR_Register use record
CLRAWLTF at 0 range 0 .. 7;
CLRAWHTF at 0 range 8 .. 15;
Reserved_16_31 at 0 range 16 .. 31;
end record;
subtype DFSDM3_AWCFR_CLRAWLTF_Field is HAL.UInt8;
subtype DFSDM3_AWCFR_CLRAWHTF_Field is HAL.UInt8;
-- DFSDM analog watchdog clear flag register
type DFSDM3_AWCFR_Register is record
-- Clear the analog watchdog low threshold flag
CLRAWLTF : DFSDM3_AWCFR_CLRAWLTF_Field := 16#0#;
-- Clear the analog watchdog high threshold flag
CLRAWHTF : DFSDM3_AWCFR_CLRAWHTF_Field := 16#0#;
-- unspecified
Reserved_16_31 : HAL.UInt16 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for DFSDM3_AWCFR_Register use record
CLRAWLTF at 0 range 0 .. 7;
CLRAWHTF at 0 range 8 .. 15;
Reserved_16_31 at 0 range 16 .. 31;
end record;
subtype DFSDM0_EXMAX_EXMAXCH_Field is HAL.UInt3;
subtype DFSDM0_EXMAX_EXMAX_Field is HAL.UInt24;
-- DFSDM Extremes detector maximum register
type DFSDM0_EXMAX_Register is record
-- Read-only. Extremes detector maximum data channel
EXMAXCH : DFSDM0_EXMAX_EXMAXCH_Field;
-- unspecified
Reserved_3_7 : HAL.UInt5;
-- Read-only. Extremes detector maximum value
EXMAX : DFSDM0_EXMAX_EXMAX_Field;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for DFSDM0_EXMAX_Register use record
EXMAXCH at 0 range 0 .. 2;
Reserved_3_7 at 0 range 3 .. 7;
EXMAX at 0 range 8 .. 31;
end record;
subtype DFSDM1_EXMAX_EXMAXCH_Field is HAL.UInt3;
subtype DFSDM1_EXMAX_EXMAX_Field is HAL.UInt24;
-- DFSDM Extremes detector maximum register
type DFSDM1_EXMAX_Register is record
-- Read-only. Extremes detector maximum data channel
EXMAXCH : DFSDM1_EXMAX_EXMAXCH_Field;
-- unspecified
Reserved_3_7 : HAL.UInt5;
-- Read-only. Extremes detector maximum value
EXMAX : DFSDM1_EXMAX_EXMAX_Field;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for DFSDM1_EXMAX_Register use record
EXMAXCH at 0 range 0 .. 2;
Reserved_3_7 at 0 range 3 .. 7;
EXMAX at 0 range 8 .. 31;
end record;
subtype DFSDM2_EXMAX_EXMAXCH_Field is HAL.UInt3;
subtype DFSDM2_EXMAX_EXMAX_Field is HAL.UInt24;
-- DFSDM Extremes detector maximum register
type DFSDM2_EXMAX_Register is record
-- Read-only. Extremes detector maximum data channel
EXMAXCH : DFSDM2_EXMAX_EXMAXCH_Field;
-- unspecified
Reserved_3_7 : HAL.UInt5;
-- Read-only. Extremes detector maximum value
EXMAX : DFSDM2_EXMAX_EXMAX_Field;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for DFSDM2_EXMAX_Register use record
EXMAXCH at 0 range 0 .. 2;
Reserved_3_7 at 0 range 3 .. 7;
EXMAX at 0 range 8 .. 31;
end record;
subtype DFSDM3_EXMAX_EXMAXCH_Field is HAL.UInt3;
subtype DFSDM3_EXMAX_EXMAX_Field is HAL.UInt24;
-- DFSDM Extremes detector maximum register
type DFSDM3_EXMAX_Register is record
-- Read-only. Extremes detector maximum data channel
EXMAXCH : DFSDM3_EXMAX_EXMAXCH_Field;
-- unspecified
Reserved_3_7 : HAL.UInt5;
-- Read-only. Extremes detector maximum value
EXMAX : DFSDM3_EXMAX_EXMAX_Field;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for DFSDM3_EXMAX_Register use record
EXMAXCH at 0 range 0 .. 2;
Reserved_3_7 at 0 range 3 .. 7;
EXMAX at 0 range 8 .. 31;
end record;
subtype DFSDM0_EXMIN_EXMINCH_Field is HAL.UInt3;
subtype DFSDM0_EXMIN_EXMIN_Field is HAL.UInt24;
-- DFSDM Extremes detector minimum register
type DFSDM0_EXMIN_Register is record
-- Read-only. Extremes detector minimum data channel
EXMINCH : DFSDM0_EXMIN_EXMINCH_Field;
-- unspecified
Reserved_3_7 : HAL.UInt5;
-- Read-only. Extremes detector minimum value
EXMIN : DFSDM0_EXMIN_EXMIN_Field;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for DFSDM0_EXMIN_Register use record
EXMINCH at 0 range 0 .. 2;
Reserved_3_7 at 0 range 3 .. 7;
EXMIN at 0 range 8 .. 31;
end record;
subtype DFSDM1_EXMIN_EXMINCH_Field is HAL.UInt3;
subtype DFSDM1_EXMIN_EXMIN_Field is HAL.UInt24;
-- DFSDM Extremes detector minimum register
type DFSDM1_EXMIN_Register is record
-- Read-only. Extremes detector minimum data channel
EXMINCH : DFSDM1_EXMIN_EXMINCH_Field;
-- unspecified
Reserved_3_7 : HAL.UInt5;
-- Read-only. Extremes detector minimum value
EXMIN : DFSDM1_EXMIN_EXMIN_Field;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for DFSDM1_EXMIN_Register use record
EXMINCH at 0 range 0 .. 2;
Reserved_3_7 at 0 range 3 .. 7;
EXMIN at 0 range 8 .. 31;
end record;
subtype DFSDM2_EXMIN_EXMINCH_Field is HAL.UInt3;
subtype DFSDM2_EXMIN_EXMIN_Field is HAL.UInt24;
-- DFSDM Extremes detector minimum register
type DFSDM2_EXMIN_Register is record
-- Read-only. Extremes detector minimum data channel
EXMINCH : DFSDM2_EXMIN_EXMINCH_Field;
-- unspecified
Reserved_3_7 : HAL.UInt5;
-- Read-only. Extremes detector minimum value
EXMIN : DFSDM2_EXMIN_EXMIN_Field;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for DFSDM2_EXMIN_Register use record
EXMINCH at 0 range 0 .. 2;
Reserved_3_7 at 0 range 3 .. 7;
EXMIN at 0 range 8 .. 31;
end record;
subtype DFSDM3_EXMIN_EXMINCH_Field is HAL.UInt3;
subtype DFSDM3_EXMIN_EXMIN_Field is HAL.UInt24;
-- DFSDM Extremes detector minimum register
type DFSDM3_EXMIN_Register is record
-- Read-only. Extremes detector minimum data channel
EXMINCH : DFSDM3_EXMIN_EXMINCH_Field;
-- unspecified
Reserved_3_7 : HAL.UInt5;
-- Read-only. Extremes detector minimum value
EXMIN : DFSDM3_EXMIN_EXMIN_Field;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for DFSDM3_EXMIN_Register use record
EXMINCH at 0 range 0 .. 2;
Reserved_3_7 at 0 range 3 .. 7;
EXMIN at 0 range 8 .. 31;
end record;
subtype DFSDM0_CNVTIMR_CNVCNT_Field is HAL.UInt28;
-- DFSDM conversion timer register
type DFSDM0_CNVTIMR_Register is record
-- unspecified
Reserved_0_3 : HAL.UInt4;
-- Read-only. 28-bit timer counting conversion time
CNVCNT : DFSDM0_CNVTIMR_CNVCNT_Field;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for DFSDM0_CNVTIMR_Register use record
Reserved_0_3 at 0 range 0 .. 3;
CNVCNT at 0 range 4 .. 31;
end record;
subtype DFSDM1_CNVTIMR_CNVCNT_Field is HAL.UInt28;
-- DFSDM conversion timer register
type DFSDM1_CNVTIMR_Register is record
-- unspecified
Reserved_0_3 : HAL.UInt4;
-- Read-only. 28-bit timer counting conversion time
CNVCNT : DFSDM1_CNVTIMR_CNVCNT_Field;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for DFSDM1_CNVTIMR_Register use record
Reserved_0_3 at 0 range 0 .. 3;
CNVCNT at 0 range 4 .. 31;
end record;
subtype DFSDM2_CNVTIMR_CNVCNT_Field is HAL.UInt28;
-- DFSDM conversion timer register
type DFSDM2_CNVTIMR_Register is record
-- unspecified
Reserved_0_3 : HAL.UInt4;
-- Read-only. 28-bit timer counting conversion time
CNVCNT : DFSDM2_CNVTIMR_CNVCNT_Field;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for DFSDM2_CNVTIMR_Register use record
Reserved_0_3 at 0 range 0 .. 3;
CNVCNT at 0 range 4 .. 31;
end record;
subtype DFSDM3_CNVTIMR_CNVCNT_Field is HAL.UInt28;
-- DFSDM conversion timer register
type DFSDM3_CNVTIMR_Register is record
-- unspecified
Reserved_0_3 : HAL.UInt4;
-- Read-only. 28-bit timer counting conversion time
CNVCNT : DFSDM3_CNVTIMR_CNVCNT_Field;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for DFSDM3_CNVTIMR_Register use record
Reserved_0_3 at 0 range 0 .. 3;
CNVCNT at 0 range 4 .. 31;
end record;
-----------------
-- Peripherals --
-----------------
-- Digital filter for sigma delta modulators
type DFSDM_Peripheral is record
-- DFSDM channel configuration 0 register 1
DFSDM_CHCFG0R1 : aliased DFSDM_CHCFG0R1_Register;
-- DFSDM channel configuration 1 register 1
DFSDM_CHCFG1R1 : aliased DFSDM_CHCFG1R1_Register;
-- DFSDM channel configuration 2 register 1
DFSDM_CHCFG2R1 : aliased DFSDM_CHCFG2R1_Register;
-- DFSDM channel configuration 3 register 1
DFSDM_CHCFG3R1 : aliased DFSDM_CHCFG3R1_Register;
-- DFSDM channel configuration 4 register 1
DFSDM_CHCFG4R1 : aliased DFSDM_CHCFG4R1_Register;
-- DFSDM channel configuration 5 register 1
DFSDM_CHCFG5R1 : aliased DFSDM_CHCFG5R1_Register;
-- DFSDM channel configuration 6 register 1
DFSDM_CHCFG6R1 : aliased DFSDM_CHCFG6R1_Register;
-- DFSDM channel configuration 7 register 1
DFSDM_CHCFG7R1 : aliased DFSDM_CHCFG7R1_Register;
-- DFSDM channel configuration 0 register 2
DFSDM_CHCFG0R2 : aliased DFSDM_CHCFG0R2_Register;
-- DFSDM channel configuration 1 register 2
DFSDM_CHCFG1R2 : aliased DFSDM_CHCFG1R2_Register;
-- DFSDM channel configuration 2 register 2
DFSDM_CHCFG2R2 : aliased DFSDM_CHCFG2R2_Register;
-- DFSDM channel configuration 3 register 2
DFSDM_CHCFG3R2 : aliased DFSDM_CHCFG3R2_Register;
-- DFSDM channel configuration 4 register 2
DFSDM_CHCFG4R2 : aliased DFSDM_CHCFG4R2_Register;
-- DFSDM channel configuration 5 register 2
DFSDM_CHCFG5R2 : aliased DFSDM_CHCFG5R2_Register;
-- DFSDM channel configuration 6 register 2
DFSDM_CHCFG6R2 : aliased DFSDM_CHCFG6R2_Register;
-- DFSDM channel configuration 7 register 2
DFSDM_CHCFG7R2 : aliased DFSDM_CHCFG7R2_Register;
-- DFSDM analog watchdog and short-circuit detector register
DFSDM_AWSCD0R : aliased DFSDM_AWSCD0R_Register;
-- DFSDM analog watchdog and short-circuit detector register
DFSDM_AWSCD1R : aliased DFSDM_AWSCD1R_Register;
-- DFSDM analog watchdog and short-circuit detector register
DFSDM_AWSCD2R : aliased DFSDM_AWSCD2R_Register;
-- DFSDM analog watchdog and short-circuit detector register
DFSDM_AWSCD3R : aliased DFSDM_AWSCD3R_Register;
-- DFSDM analog watchdog and short-circuit detector register
DFSDM_AWSCD4R : aliased DFSDM_AWSCD4R_Register;
-- DFSDM analog watchdog and short-circuit detector register
DFSDM_AWSCD5R : aliased DFSDM_AWSCD5R_Register;
-- DFSDM analog watchdog and short-circuit detector register
DFSDM_AWSCD6R : aliased DFSDM_AWSCD6R_Register;
-- DFSDM analog watchdog and short-circuit detector register
DFSDM_AWSCD7R : aliased DFSDM_AWSCD7R_Register;
-- DFSDM channel watchdog filter data register
DFSDM_CHWDAT0R : aliased DFSDM_CHWDAT0R_Register;
-- DFSDM channel watchdog filter data register
DFSDM_CHWDAT1R : aliased DFSDM_CHWDAT1R_Register;
-- DFSDM channel watchdog filter data register
DFSDM_CHWDAT2R : aliased DFSDM_CHWDAT2R_Register;
-- DFSDM channel watchdog filter data register
DFSDM_CHWDAT3R : aliased DFSDM_CHWDAT3R_Register;
-- DFSDM channel watchdog filter data register
DFSDM_CHWDAT4R : aliased DFSDM_CHWDAT4R_Register;
-- DFSDM channel watchdog filter data register
DFSDM_CHWDAT5R : aliased DFSDM_CHWDAT5R_Register;
-- DFSDM channel watchdog filter data register
DFSDM_CHWDAT6R : aliased DFSDM_CHWDAT6R_Register;
-- DFSDM channel watchdog filter data register
DFSDM_CHWDAT7R : aliased DFSDM_CHWDAT7R_Register;
-- DFSDM channel data input register
DFSDM_CHDATIN0R : aliased DFSDM_CHDATIN0R_Register;
-- DFSDM channel data input register
DFSDM_CHDATIN1R : aliased DFSDM_CHDATIN1R_Register;
-- DFSDM channel data input register
DFSDM_CHDATIN2R : aliased DFSDM_CHDATIN2R_Register;
-- DFSDM channel data input register
DFSDM_CHDATIN3R : aliased DFSDM_CHDATIN3R_Register;
-- DFSDM channel data input register
DFSDM_CHDATIN4R : aliased DFSDM_CHDATIN4R_Register;
-- DFSDM channel data input register
DFSDM_CHDATIN5R : aliased DFSDM_CHDATIN5R_Register;
-- DFSDM channel data input register
DFSDM_CHDATIN6R : aliased DFSDM_CHDATIN6R_Register;
-- DFSDM channel data input register
DFSDM_CHDATIN7R : aliased DFSDM_CHDATIN7R_Register;
-- DFSDM control register 1
DFSDM0_CR1 : aliased DFSDM0_CR1_Register;
-- DFSDM control register 1
DFSDM1_CR1 : aliased DFSDM1_CR1_Register;
-- DFSDM control register 1
DFSDM2_CR1 : aliased DFSDM2_CR1_Register;
-- DFSDM control register 1
DFSDM3_CR1 : aliased DFSDM3_CR1_Register;
-- DFSDM control register 2
DFSDM0_CR2 : aliased DFSDM0_CR2_Register;
-- DFSDM control register 2
DFSDM1_CR2 : aliased DFSDM1_CR2_Register;
-- DFSDM control register 2
DFSDM2_CR2 : aliased DFSDM2_CR2_Register;
-- DFSDM control register 2
DFSDM3_CR2 : aliased DFSDM3_CR2_Register;
-- DFSDM interrupt and status register
DFSDM0_ISR : aliased DFSDM0_ISR_Register;
-- DFSDM interrupt and status register
DFSDM1_ISR : aliased DFSDM1_ISR_Register;
-- DFSDM interrupt and status register
DFSDM2_ISR : aliased DFSDM2_ISR_Register;
-- DFSDM interrupt and status register
DFSDM3_ISR : aliased DFSDM3_ISR_Register;
-- DFSDM interrupt flag clear register
DFSDM0_ICR : aliased DFSDM0_ICR_Register;
-- DFSDM interrupt flag clear register
DFSDM1_ICR : aliased DFSDM1_ICR_Register;
-- DFSDM interrupt flag clear register
DFSDM2_ICR : aliased DFSDM2_ICR_Register;
-- DFSDM interrupt flag clear register
DFSDM3_ICR : aliased DFSDM3_ICR_Register;
-- DFSDM injected channel group selection register
DFSDM0_JCHGR : aliased DFSDM0_JCHGR_Register;
-- DFSDM injected channel group selection register
DFSDM1_JCHGR : aliased DFSDM1_JCHGR_Register;
-- DFSDM injected channel group selection register
DFSDM2_JCHGR : aliased DFSDM2_JCHGR_Register;
-- DFSDM injected channel group selection register
DFSDM3_JCHGR : aliased DFSDM3_JCHGR_Register;
-- DFSDM filter control register
DFSDM0_FCR : aliased DFSDM0_FCR_Register;
-- DFSDM filter control register
DFSDM1_FCR : aliased DFSDM1_FCR_Register;
-- DFSDM filter control register
DFSDM2_FCR : aliased DFSDM2_FCR_Register;
-- DFSDM filter control register
DFSDM3_FCR : aliased DFSDM3_FCR_Register;
-- DFSDM data register for injected group
DFSDM0_JDATAR : aliased DFSDM0_JDATAR_Register;
-- DFSDM data register for injected group
DFSDM1_JDATAR : aliased DFSDM1_JDATAR_Register;
-- DFSDM data register for injected group
DFSDM2_JDATAR : aliased DFSDM2_JDATAR_Register;
-- DFSDM data register for injected group
DFSDM3_JDATAR : aliased DFSDM3_JDATAR_Register;
-- DFSDM data register for the regular channel
DFSDM0_RDATAR : aliased DFSDM0_RDATAR_Register;
-- DFSDM data register for the regular channel
DFSDM1_RDATAR : aliased DFSDM1_RDATAR_Register;
-- DFSDM data register for the regular channel
DFSDM2_RDATAR : aliased DFSDM2_RDATAR_Register;
-- DFSDM data register for the regular channel
DFSDM3_RDATAR : aliased DFSDM3_RDATAR_Register;
-- DFSDM analog watchdog high threshold register
DFSDM0_AWHTR : aliased DFSDM0_AWHTR_Register;
-- DFSDM analog watchdog high threshold register
DFSDM1_AWHTR : aliased DFSDM1_AWHTR_Register;
-- DFSDM analog watchdog high threshold register
DFSDM2_AWHTR : aliased DFSDM2_AWHTR_Register;
-- DFSDM analog watchdog high threshold register
DFSDM3_AWHTR : aliased DFSDM3_AWHTR_Register;
-- DFSDM analog watchdog low threshold register
DFSDM0_AWLTR : aliased DFSDM0_AWLTR_Register;
-- DFSDM analog watchdog low threshold register
DFSDM1_AWLTR : aliased DFSDM1_AWLTR_Register;
-- DFSDM analog watchdog low threshold register
DFSDM2_AWLTR : aliased DFSDM2_AWLTR_Register;
-- DFSDM analog watchdog low threshold register
DFSDM3_AWLTR : aliased DFSDM3_AWLTR_Register;
-- DFSDM analog watchdog status register
DFSDM0_AWSR : aliased DFSDM0_AWSR_Register;
-- DFSDM analog watchdog status register
DFSDM1_AWSR : aliased DFSDM1_AWSR_Register;
-- DFSDM analog watchdog status register
DFSDM2_AWSR : aliased DFSDM2_AWSR_Register;
-- DFSDM analog watchdog status register
DFSDM3_AWSR : aliased DFSDM3_AWSR_Register;
-- DFSDM analog watchdog clear flag register
DFSDM0_AWCFR : aliased DFSDM0_AWCFR_Register;
-- DFSDM analog watchdog clear flag register
DFSDM1_AWCFR : aliased DFSDM1_AWCFR_Register;
-- DFSDM analog watchdog clear flag register
DFSDM2_AWCFR : aliased DFSDM2_AWCFR_Register;
-- DFSDM analog watchdog clear flag register
DFSDM3_AWCFR : aliased DFSDM3_AWCFR_Register;
-- DFSDM Extremes detector maximum register
DFSDM0_EXMAX : aliased DFSDM0_EXMAX_Register;
-- DFSDM Extremes detector maximum register
DFSDM1_EXMAX : aliased DFSDM1_EXMAX_Register;
-- DFSDM Extremes detector maximum register
DFSDM2_EXMAX : aliased DFSDM2_EXMAX_Register;
-- DFSDM Extremes detector maximum register
DFSDM3_EXMAX : aliased DFSDM3_EXMAX_Register;
-- DFSDM Extremes detector minimum register
DFSDM0_EXMIN : aliased DFSDM0_EXMIN_Register;
-- DFSDM Extremes detector minimum register
DFSDM1_EXMIN : aliased DFSDM1_EXMIN_Register;
-- DFSDM Extremes detector minimum register
DFSDM2_EXMIN : aliased DFSDM2_EXMIN_Register;
-- DFSDM Extremes detector minimum register
DFSDM3_EXMIN : aliased DFSDM3_EXMIN_Register;
-- DFSDM conversion timer register
DFSDM0_CNVTIMR : aliased DFSDM0_CNVTIMR_Register;
-- DFSDM conversion timer register
DFSDM1_CNVTIMR : aliased DFSDM1_CNVTIMR_Register;
-- DFSDM conversion timer register
DFSDM2_CNVTIMR : aliased DFSDM2_CNVTIMR_Register;
-- DFSDM conversion timer register
DFSDM3_CNVTIMR : aliased DFSDM3_CNVTIMR_Register;
end record
with Volatile;
for DFSDM_Peripheral use record
DFSDM_CHCFG0R1 at 16#0# range 0 .. 31;
DFSDM_CHCFG1R1 at 16#4# range 0 .. 31;
DFSDM_CHCFG2R1 at 16#8# range 0 .. 31;
DFSDM_CHCFG3R1 at 16#C# range 0 .. 31;
DFSDM_CHCFG4R1 at 16#10# range 0 .. 31;
DFSDM_CHCFG5R1 at 16#14# range 0 .. 31;
DFSDM_CHCFG6R1 at 16#18# range 0 .. 31;
DFSDM_CHCFG7R1 at 16#1C# range 0 .. 31;
DFSDM_CHCFG0R2 at 16#20# range 0 .. 31;
DFSDM_CHCFG1R2 at 16#24# range 0 .. 31;
DFSDM_CHCFG2R2 at 16#28# range 0 .. 31;
DFSDM_CHCFG3R2 at 16#2C# range 0 .. 31;
DFSDM_CHCFG4R2 at 16#30# range 0 .. 31;
DFSDM_CHCFG5R2 at 16#34# range 0 .. 31;
DFSDM_CHCFG6R2 at 16#38# range 0 .. 31;
DFSDM_CHCFG7R2 at 16#3C# range 0 .. 31;
DFSDM_AWSCD0R at 16#40# range 0 .. 31;
DFSDM_AWSCD1R at 16#44# range 0 .. 31;
DFSDM_AWSCD2R at 16#48# range 0 .. 31;
DFSDM_AWSCD3R at 16#4C# range 0 .. 31;
DFSDM_AWSCD4R at 16#50# range 0 .. 31;
DFSDM_AWSCD5R at 16#54# range 0 .. 31;
DFSDM_AWSCD6R at 16#58# range 0 .. 31;
DFSDM_AWSCD7R at 16#5C# range 0 .. 31;
DFSDM_CHWDAT0R at 16#60# range 0 .. 31;
DFSDM_CHWDAT1R at 16#64# range 0 .. 31;
DFSDM_CHWDAT2R at 16#68# range 0 .. 31;
DFSDM_CHWDAT3R at 16#6C# range 0 .. 31;
DFSDM_CHWDAT4R at 16#70# range 0 .. 31;
DFSDM_CHWDAT5R at 16#74# range 0 .. 31;
DFSDM_CHWDAT6R at 16#78# range 0 .. 31;
DFSDM_CHWDAT7R at 16#7C# range 0 .. 31;
DFSDM_CHDATIN0R at 16#80# range 0 .. 31;
DFSDM_CHDATIN1R at 16#84# range 0 .. 31;
DFSDM_CHDATIN2R at 16#88# range 0 .. 31;
DFSDM_CHDATIN3R at 16#8C# range 0 .. 31;
DFSDM_CHDATIN4R at 16#90# range 0 .. 31;
DFSDM_CHDATIN5R at 16#94# range 0 .. 31;
DFSDM_CHDATIN6R at 16#98# range 0 .. 31;
DFSDM_CHDATIN7R at 16#9C# range 0 .. 31;
DFSDM0_CR1 at 16#A0# range 0 .. 31;
DFSDM1_CR1 at 16#A4# range 0 .. 31;
DFSDM2_CR1 at 16#A8# range 0 .. 31;
DFSDM3_CR1 at 16#AC# range 0 .. 31;
DFSDM0_CR2 at 16#B0# range 0 .. 31;
DFSDM1_CR2 at 16#B4# range 0 .. 31;
DFSDM2_CR2 at 16#B8# range 0 .. 31;
DFSDM3_CR2 at 16#BC# range 0 .. 31;
DFSDM0_ISR at 16#C0# range 0 .. 31;
DFSDM1_ISR at 16#C4# range 0 .. 31;
DFSDM2_ISR at 16#C8# range 0 .. 31;
DFSDM3_ISR at 16#CC# range 0 .. 31;
DFSDM0_ICR at 16#D0# range 0 .. 31;
DFSDM1_ICR at 16#D4# range 0 .. 31;
DFSDM2_ICR at 16#D8# range 0 .. 31;
DFSDM3_ICR at 16#DC# range 0 .. 31;
DFSDM0_JCHGR at 16#E0# range 0 .. 31;
DFSDM1_JCHGR at 16#E4# range 0 .. 31;
DFSDM2_JCHGR at 16#E8# range 0 .. 31;
DFSDM3_JCHGR at 16#EC# range 0 .. 31;
DFSDM0_FCR at 16#F0# range 0 .. 31;
DFSDM1_FCR at 16#F4# range 0 .. 31;
DFSDM2_FCR at 16#F8# range 0 .. 31;
DFSDM3_FCR at 16#FC# range 0 .. 31;
DFSDM0_JDATAR at 16#100# range 0 .. 31;
DFSDM1_JDATAR at 16#104# range 0 .. 31;
DFSDM2_JDATAR at 16#108# range 0 .. 31;
DFSDM3_JDATAR at 16#10C# range 0 .. 31;
DFSDM0_RDATAR at 16#110# range 0 .. 31;
DFSDM1_RDATAR at 16#114# range 0 .. 31;
DFSDM2_RDATAR at 16#118# range 0 .. 31;
DFSDM3_RDATAR at 16#11C# range 0 .. 31;
DFSDM0_AWHTR at 16#120# range 0 .. 31;
DFSDM1_AWHTR at 16#124# range 0 .. 31;
DFSDM2_AWHTR at 16#128# range 0 .. 31;
DFSDM3_AWHTR at 16#12C# range 0 .. 31;
DFSDM0_AWLTR at 16#130# range 0 .. 31;
DFSDM1_AWLTR at 16#134# range 0 .. 31;
DFSDM2_AWLTR at 16#138# range 0 .. 31;
DFSDM3_AWLTR at 16#13C# range 0 .. 31;
DFSDM0_AWSR at 16#140# range 0 .. 31;
DFSDM1_AWSR at 16#144# range 0 .. 31;
DFSDM2_AWSR at 16#148# range 0 .. 31;
DFSDM3_AWSR at 16#14C# range 0 .. 31;
DFSDM0_AWCFR at 16#150# range 0 .. 31;
DFSDM1_AWCFR at 16#154# range 0 .. 31;
DFSDM2_AWCFR at 16#158# range 0 .. 31;
DFSDM3_AWCFR at 16#15C# range 0 .. 31;
DFSDM0_EXMAX at 16#160# range 0 .. 31;
DFSDM1_EXMAX at 16#164# range 0 .. 31;
DFSDM2_EXMAX at 16#168# range 0 .. 31;
DFSDM3_EXMAX at 16#16C# range 0 .. 31;
DFSDM0_EXMIN at 16#170# range 0 .. 31;
DFSDM1_EXMIN at 16#174# range 0 .. 31;
DFSDM2_EXMIN at 16#178# range 0 .. 31;
DFSDM3_EXMIN at 16#17C# range 0 .. 31;
DFSDM0_CNVTIMR at 16#180# range 0 .. 31;
DFSDM1_CNVTIMR at 16#184# range 0 .. 31;
DFSDM2_CNVTIMR at 16#188# range 0 .. 31;
DFSDM3_CNVTIMR at 16#18C# range 0 .. 31;
end record;
-- Digital filter for sigma delta modulators
DFSDM_Periph : aliased DFSDM_Peripheral
with Import, Address => System'To_Address (16#40017400#);
end STM32_SVD.DFSDM;
|
------------------------------------------------------------------------------
-- A d a r u n - t i m e s p e c i f i c a t i o n --
-- ASIS implementation for Gela project, a portable Ada compiler --
-- http://gela.ada-ru.org --
-- - - - - - - - - - - - - - - - --
-- Read copyright and license at the end of ada.ads file --
------------------------------------------------------------------------------
-- $Revision: 209 $ $Date: 2013-11-30 21:03:24 +0200 (Сб., 30 нояб. 2013) $
package Interfaces.C is
pragma Pure(C);
-- Declarations based on C's <limits.h>
CHAR_BIT : constant := implementation-defined; -- typically 8
SCHAR_MIN : constant := implementation-defined; -- typically -128
SCHAR_MAX : constant := implementation-defined; -- typically 127
UCHAR_MAX : constant := implementation-defined; -- typically 255
-- Signed and Unsigned Integers
type int is range implementation-defined .. implementation-defined;
type short is range implementation-defined .. implementation-defined;
type long is range implementation-defined .. implementation-defined;
type signed_char is range SCHAR_MIN .. SCHAR_MAX;
for signed_char'Size use CHAR_BIT;
type unsigned is mod implementation-defined;
type unsigned_short is mod implementation-defined;
type unsigned_long is mod implementation-defined;
type unsigned_char is mod (UCHAR_MAX+1);
for unsigned_char'Size use CHAR_BIT;
subtype plain_char is unsigned_char; -- implementation-defined;
type ptrdiff_t is range implementation-defined .. implementation-defined;
type size_t is mod implementation-defined;
-- Floating Point
type C_float is digits implementation-defined;
type double is digits implementation-defined;
type long_double is digits implementation-defined;
-- Characters and Strings
type char is ('x'); -- implementation-defined character type;
nul : constant char := implementation-defined;
function To_C (Item : in Character) return char;
function To_Ada (Item : in char) return Character;
type char_array is array (size_t range <>) of aliased char;
pragma Pack (char_array);
for char_array'Component_Size use CHAR_BIT;
function Is_Nul_Terminated (Item : in char_array) return Boolean;
function To_C (Item : in String;
Append_Nul : in Boolean := True)
return char_array;
function To_Ada (Item : in char_array;
Trim_Nul : in Boolean := True)
return String;
procedure To_C (Item : in String;
Target : out char_array;
Count : out size_t;
Append_Nul : in Boolean := True);
procedure To_Ada (Item : in char_array;
Target : out String;
Count : out Natural;
Trim_Nul : in Boolean := True);
-- Wide Character and Wide String
type wchar_t is (' '); -- implementation-defined char type;
wide_nul : constant wchar_t := implementation-defined;
function To_C (Item : in Wide_Character) return wchar_t;
function To_Ada (Item : in wchar_t ) return Wide_Character;
type wchar_array is array (size_t range <>) of aliased wchar_t;
pragma Pack (wchar_array);
function Is_Nul_Terminated (Item : in wchar_array) return Boolean;
function To_C (Item : in Wide_String;
Append_Nul : in Boolean := True)
return wchar_array;
function To_Ada (Item : in wchar_array;
Trim_Nul : in Boolean := True)
return Wide_String;
procedure To_C (Item : in Wide_String;
Target : out wchar_array;
Count : out size_t;
Append_Nul : in Boolean := True);
procedure To_Ada (Item : in wchar_array;
Target : out Wide_String;
Count : out Natural;
Trim_Nul : in Boolean := True);
-- ISO/IEC 10646:2003 compatible types defined by ISO/IEC TR 19769:2004.
type char16_t is ('x'); -- implementation-defined character type
char16_nul : constant char16_t := implementation-defined;
function To_C (Item : in Wide_Character) return char16_t;
function To_Ada (Item : in char16_t) return Wide_Character;
type char16_array is array (size_t range <>) of aliased char16_t;
pragma Pack (char16_array);
function Is_Nul_Terminated (Item : in char16_array) return Boolean;
function To_C (Item : in Wide_String;
Append_Nul : in Boolean := True)
return char16_array;
function To_Ada (Item : in char16_array;
Trim_Nul : in Boolean := True)
return Wide_String;
procedure To_C (Item : in Wide_String;
Target : out char16_array;
Count : out size_t;
Append_Nul : in Boolean := True);
procedure To_Ada (Item : in char16_array;
Target : out Wide_String;
Count : out Natural;
Trim_Nul : in Boolean := True);
type char32_t is ('x'); -- implementation-defined character type
char32_nul : constant char32_t := implementation-defined;
function To_C (Item : in Wide_Wide_Character) return char32_t;
function To_Ada (Item : in char32_t) return Wide_Wide_Character;
type char32_array is array (size_t range <>) of aliased char32_t;
pragma Pack (char32_array);
function Is_Nul_Terminated (Item : in char32_array) return Boolean;
function To_C (Item : in Wide_Wide_String;
Append_Nul : in Boolean := True)
return char32_array;
function To_Ada (Item : in char32_array;
Trim_Nul : in Boolean := True)
return Wide_Wide_String;
procedure To_C (Item : in Wide_Wide_String;
Target : out char32_array;
Count : out size_t;
Append_Nul : in Boolean := True);
procedure To_Ada (Item : in char32_array;
Target : out Wide_Wide_String;
Count : out Natural;
Trim_Nul : in Boolean := True);
Terminator_Error : exception;
end Interfaces.C;
|
--------------------------------------------------------------------------------
-- * Spec name vector.ads
-- * Project name ctffttest
-- *
-- * Version 1.0
-- * Last update 11/5/08
-- *
-- * Created by Adrian Hoe on 11/5/08.
-- * Copyright (c) 2008 AdaStar Informatics http://adastarinformatics.com
-- * All rights reserved.
-- *
--------------------------------------------------------------------------------
with Ada.Numerics.Generic_Complex_Types;
package Vector is
subtype Index is Positive;
subtype Real_Number is Long_Long_Float;
package Complex_Types is
new Ada.Numerics.Generic_Complex_Types (Real_Number);
use Complex_Types;
subtype Complex_Number is Complex;
type Real_Vector_Type is array (Index range <>) of Real_Number;
type Real_Vector_Handle is access Real_Vector_Type;
type Complex_Vector_Type is array (Index range <>) of Complex_Number;
type Complex_Vector_Handle is access Complex_Vector_Type;
-- procedure Get (Num : out Real_Vector_Type);
-- procedure Get (File : in File_Type;
-- Num : out Real_Vector_Type);
procedure Put (Data : in Real_Vector_Type;
Width : in Integer := 1);
-- procedure Put (File : in File_Type;
-- Num : in Real_Vector_Type;
-- Width : in Integer := 1);
end Vector;
|
------------------------------------------------------------------------------
-- A d a r u n - t i m e s p e c i f i c a t i o n --
-- ASIS implementation for Gela project, a portable Ada compiler --
-- http://gela.ada-ru.org --
-- - - - - - - - - - - - - - - - --
-- Read copyright and license at the end of ada.ads file --
------------------------------------------------------------------------------
-- $Revision: 209 $ $Date: 2013-11-30 21:03:24 +0200 (Сб., 30 нояб. 2013) $
package Ada.Real_Time.Timing_Events is
type Timing_Event is tagged limited private;
type Timing_Event_Handler is
access protected procedure (Event : in out Timing_Event);
procedure Set_Handler (Event : in out Timing_Event;
At_Time : in Time;
Handler : in Timing_Event_Handler);
procedure Set_Handler (Event : in out Timing_Event;
In_Time : in Time_Span;
Handler : in Timing_Event_Handler);
function Current_Handler (Event : in Timing_Event)
return Timing_Event_Handler;
procedure Cancel_Handler (Event : in out Timing_Event;
Cancelled : out Boolean);
function Time_Of_Event (Event : in Timing_Event) return Time;
private
pragma Import (Ada, Timing_Event);
end Ada.Real_Time.Timing_Events;
|
-- Copyright (c) 2019 Maxim Reznik <reznikmm@gmail.com>
--
-- SPDX-License-Identifier: MIT
-- License-Filename: LICENSE
-------------------------------------------------------------
with Program.Elements.Definitions;
with Program.Element_Vectors;
with Program.Lexical_Elements;
with Program.Elements.Identifiers;
package Program.Elements.Protected_Definitions is
pragma Pure (Program.Elements.Protected_Definitions);
type Protected_Definition is
limited interface and Program.Elements.Definitions.Definition;
type Protected_Definition_Access is access all Protected_Definition'Class
with Storage_Size => 0;
not overriding function Visible_Declarations
(Self : Protected_Definition)
return Program.Element_Vectors.Element_Vector_Access is abstract;
not overriding function Private_Declarations
(Self : Protected_Definition)
return Program.Element_Vectors.Element_Vector_Access is abstract;
not overriding function End_Name
(Self : Protected_Definition)
return Program.Elements.Identifiers.Identifier_Access is abstract;
type Protected_Definition_Text is limited interface;
type Protected_Definition_Text_Access is
access all Protected_Definition_Text'Class with Storage_Size => 0;
not overriding function To_Protected_Definition_Text
(Self : aliased in out Protected_Definition)
return Protected_Definition_Text_Access is abstract;
not overriding function Private_Token
(Self : Protected_Definition_Text)
return not null Program.Lexical_Elements.Lexical_Element_Access
is abstract;
not overriding function End_Token
(Self : Protected_Definition_Text)
return not null Program.Lexical_Elements.Lexical_Element_Access
is abstract;
end Program.Elements.Protected_Definitions;
|
-- --
-- package Copyright (c) Dmitry A. Kazakov --
-- Parsers.Multiline_Source Luebeck --
-- Implementation Winter, 2004 --
-- --
-- Last revision : 13:13 14 Sep 2019 --
-- --
-- This library is free software; you can redistribute it and/or --
-- modify it under the terms of the GNU General Public License as --
-- published by the Free Software Foundation; either version 2 of --
-- the License, or (at your option) any later version. This library --
-- is distributed in the hope that it will be useful, but WITHOUT --
-- ANY WARRANTY; without even the implied warranty of --
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU --
-- General Public License for more details. You should have --
-- received a copy of the GNU General Public License along with --
-- this library; if not, write to the Free Software Foundation, --
-- Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. --
-- --
-- As a special exception, if other files instantiate generics from --
-- this unit, or you link this unit with other files to produce an --
-- executable, this unit does not by itself cause the resulting --
-- executable to be covered by the GNU General Public License. This --
-- exception does not however invalidate any other reasons why the --
-- executable file might be covered by the GNU Public License. --
--____________________________________________________________________--
with Ada.IO_Exceptions; use Ada.IO_Exceptions;
with Strings_Edit.Integers; use Strings_Edit.Integers;
package body Parsers.Multiline_Source is
Initial_Size : constant Integer := 512;
function "<" (Left, Right : Position) return Boolean is
begin
return
( Left.Line < Right.Line
or else
( Left.Line = Right.Line
and then
Left.Column < Right.Column
) );
end "<";
procedure Finalize (Code : in out Source) is
begin
Free (Code.Buffer);
end Finalize;
function End_Of (Code : Source'Class) return Boolean is
begin
return Code.Buffer = null;
end End_Of;
function Get_Line (Code : Source'Class) return String is
begin
if Code.Buffer = null then
raise End_Error;
else
return Code.Buffer (1..Code.Length);
end if;
end Get_Line;
procedure Get_Line
( Code : Source'Class;
Line : out Line_Ptr;
Pointer : out Integer;
Last : out Integer
) is
begin
if Code.Buffer = null then
raise End_Error;
else
Line := Code.Buffer.all'Unchecked_Access;
Pointer := Code.Pointer;
Last := Code.Length;
end if;
end Get_Line;
function Get_Backup_Pointer (Code : Source'Class) return Integer is
begin
return Code.Last;
end Get_Backup_Pointer;
function Get_Location
( Message : String;
Prefix : String := "at "
) return Location is
Pointer : Integer := Message'Last;
Result : Location := ((0, 0), (0, 0));
begin
loop -- An occurence of Prefix
loop -- Searching backwards Message for Prefix
if Pointer < Message'First + Prefix'Length - 1 then
return Result;
end if;
exit when
Message (Pointer - Prefix'Length + 1..Pointer) = Prefix;
Pointer := Pointer - 1;
end loop;
Pointer := Pointer + 1;
-- After the prefix
begin
Get (Message, Pointer, Integer (Result.First.Line));
Result.Next.Line := Result.First.Line;
if ( Pointer >= Message'Last
or else
Message (Pointer) /= ':'
)
then
return Result;
end if;
-- Line:
Pointer := Pointer + 1;
begin
Get (Message, Pointer, Result.First.Column, First => 1);
exception
when others =>
return Result;
end;
-- Line:Column
Result.Next.Column := Result.First.Column;
if ( Pointer + 1 >= Message'Last
or else
Message (Pointer..Pointer + 1) /= ".."
)
then
return Result;
end if;
Pointer := Pointer + 2;
-- Line:Column..
begin
Get (Message, Pointer, Integer (Result.Next.Line));
exception
when others =>
return Result;
end;
-- Line:Column..Line
if ( Pointer >= Message'Last
or else
Message (Pointer) /= ':'
)
then
Result.Next.Column := Integer (Result.Next.Line);
Result.Next.Line := Result.First.Line;
return Result;
end if;
Pointer := Pointer + 1;
-- Line:Column..Line:
begin
Get (Message, Pointer, Result.Next.Column);
-- Line:Column..Line:Column
return Result;
exception
when others =>
Result.Next.Column := Integer (Result.Next.Line);
Result.Next.Line := Result.First.Line;
return Result;
end;
exception
when others =>
return Result;
end;
end loop;
end Get_Location;
function Get_Pointer (Code : Source'Class) return Integer is
begin
return Code.Pointer;
end Get_Pointer;
function Image (Link : Location) return String is
begin
if Link.First = Link.Next then
return
( Image (Integer (Link.First.Line))
& ":"
& Image (Link.First.Column)
);
elsif Link.First.Line = Link.Next.Line then
return
( Image (Integer (Link.First.Line))
& ":"
& Image (Link.First.Column)
& ".."
& Image (Link.Next.Column - 1)
);
else
return
( Image (Integer (Link.First.Line))
& ":"
& Image (Link.First.Column)
& ".."
& Image (Integer (Link.Next.Line))
& ":"
& Image (Link.Next.Column - 1)
);
end if;
end Image;
procedure Initialize (Code : in out Source) is
begin
Code.Buffer := new String (1..Initial_Size);
Next_Line (Code);
exception
when Storage_Error =>
raise;
when others =>
null;
end Initialize;
function Link (Code : Source'Class) return Location is
begin
return ((Code.Line, Code.Last), (Code.Line, Code.Pointer));
end Link;
function "&" (Left, Right : Location) return Location is
Result : Location;
begin
if Left.First < Right.First then
Result.First := Left.First;
else
Result.First := Right.First;
end if;
if Left.Next < Right.Next then
Result.Next := Right.Next;
else
Result.Next := Left.Next;
end if;
return Result;
end "&";
procedure Next_Line (Code : in out Source'Class) is
begin
Code.Pointer := 1;
Code.Last := 1;
Get_Line (Code);
Code.Line := Code.Line + 1;
exception
when End_Error =>
Free (Code.Buffer);
raise;
end Next_Line;
procedure Reset_Pointer (Code : in out Source'Class) is
begin
Code.Pointer := Code.Last;
end Reset_Pointer;
procedure Set_Pointer
( Code : in out Source'Class;
Pointer : Integer
) is
begin
if Code.Buffer = null then
if Pointer /= 1 then
raise Ada.IO_Exceptions.Layout_Error;
end if;
else
if Pointer not in Code.Last..Code.Length + 1 then
raise Ada.IO_Exceptions.Layout_Error;
end if;
end if;
Code.Last := Code.Pointer;
Code.Pointer := Pointer;
end Set_Pointer;
procedure Skip (Code : in out Source'Class; Link : Location) is
begin
if Code.Line > Link.First.Line then
raise Ada.IO_Exceptions.Layout_Error;
end if;
while Code.Line < Link.First.Line loop
Next_Line (Code);
end loop;
Set_Pointer (Code, Link.First.Column);
while Code.Line < Link.Next.Line loop
Next_Line (Code);
end loop;
Set_Pointer (Code, Link.Next.Column);
end Skip;
end Parsers.Multiline_Source;
|
package body BSSNBase.ADM_BSSN is
----------------------------------------------------------------------------
-- from BSSN to ADM
function adm_gab (gBar : MetricPointArray;
phi : Real)
return MetricPointArray
is
begin
return exp(4.0*phi) * gBar;
end;
function adm_Kab (ABar : ExtcurvPointArray;
gBar : MetricPointArray;
phi : Real;
trK : Real)
return ExtcurvPointArray
is
begin
return exp(4.0*phi)*(ABar + ExtcurvPointArray(trK*gBar/3.0));
end;
----------------------------------------------------------------------------
-- from ADM to BSSN
function bssn_phi (gab : MetricPointArray)
return Real
is
g : Real := symm_det (gab);
begin
return log(g)/12.0;
end;
function bssn_trK (Kab : ExtcurvPointArray;
gab : MetricpointArray)
return Real
is
iab : MetricPointArray := symm_inverse (gab);
begin
return symm_trace (Kab, iab);
end;
function bssn_gBar (gab : MetricPointArray)
return MetricPointArray
is
g : Real := symm_det (gab);
begin
return gab / (g**(1.0/3.0));
end;
function bssn_ABar (Kab : ExtcurvPointArray;
gab : MetricPointArray)
return ExtcurvPointArray
is
g : Real := symm_det (gab);
trK : Real := bssn_trK (Kab, gab);
begin
return (Kab - ExtcurvPointArray(trK*gab/3.0))/(g**(1.0/3.0));
end;
end BSSNBase.ADM_BSSN;
|
with Vecteurs; use Vecteurs;
with Liste_Generique;
limited with Courbes.Visiteurs;
package Courbes is
type Courbe is abstract tagged private;
type Courbe_Ptr is access all Courbe'Class;
package Liste_Courbes is new Liste_Generique(Courbe_Ptr);
subtype Coordonnee_Normalisee is Float range 0.0 .. 1.0;
procedure Liberer_Courbe (Self : in out Courbe_Ptr);
-- Obtient un point à la coordonnée X fournie
-- X entre 0 et 1
-- (x, f(x))
-- Abstraite
function Obtenir_Point(Self : Courbe; X : Coordonnee_Normalisee) return Point2D is abstract;
-- Pattern visiteur
procedure Accepter (Self : Courbe; Visiteur : Courbes.Visiteurs.Visiteur_Courbe'Class);
-- Renvoie le debut d'une courbe
function Obtenir_Debut(Self : Courbe) return Point2D;
-- Renvoie la fin d'une courbe
function Obtenir_Fin(Self : Courbe) return Point2D;
private
type Courbe is abstract tagged
record
Debut, Fin : Point2D;
end record;
end Courbes;
|
------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- S Y S T E M . P A R A M E T E R S --
-- --
-- S p e c --
-- --
-- $Revision: 2 $ --
-- --
-- Copyright (c) 1992,1993,1994 NYU, All Rights Reserved --
-- --
-- The GNAT library is free software; you can redistribute it and/or modify --
-- it under terms of the GNU Library General Public License as published by --
-- the Free Software Foundation; either version 2, or (at your option) any --
-- later version. The GNAT library is distributed in the hope that it will --
-- be useful, but WITHOUT ANY WARRANTY; without even the implied warranty --
-- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU --
-- Library General Public License for more details. You should have --
-- received a copy of the GNU Library General Public License along with --
-- the GNAT library; see the file COPYING.LIB. If not, write to the Free --
-- Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. --
-- --
------------------------------------------------------------------------------
-- This package defines some system dependent parameters for GNAT. These
-- constants are referenced at compile time and by the runtime library,
-- and may be changed to customize a particular variant of GNAT.
package System.Parameters is
pragma Pure (Parameters);
Count_Max : constant := Integer'Last;
-- Upper bound of type Ada.Text_IO.Count
Field_Max : constant := 100;
-- Upper bound of type Ada.Text_IO.Field
Exception_Msg_Max : constant := 200;
-- Maximum length of message in exception occurrence
Max_Line_Length : constant := 512;
-- Maximum source line length. This can be set to any value up to
-- 2**15 - 1, a limit imposed by the assumption that column numbers
-- can be stored in 16 bits (see Types.Column_Number).
Max_Name_Length : constant := 1024;
-- Maximum length of unit name (including all dots, and " (spec)") and
-- of file names in the library, must be at least Max_Line_Length, but
-- can be larger.
Max_Instantiations : constant := 2000;
-- Maximum number of instantiations permitted (to stop runaway cases
-- of nested instantiations). These situations probably only occur in
-- specially concocted test cases.
Max_Static_Aggregate_Size : constant := 65_536;
-- Maximum size of aggregate that is built statically (see Sem_Aggr)
Tag_Errors : constant Boolean := False;
-- If set to true, then brief form error messages will be prefaced by
-- the string "error:"
end System.Parameters;
|
with AdaBase;
with Connect;
with CommonText;
with Ada.Text_IO;
with AdaBase.Results.Sets;
with Spatial_Data;
procedure Spatial4 is
package CON renames Connect;
package TIO renames Ada.Text_IO;
package ARS renames AdaBase.Results.Sets;
package CT renames CommonText;
package SD renames Spatial_Data;
begin
CON.connect_database;
declare
use type SD.Geometric_Real;
my_point : SD.Geometry := SD.initialize_as_point ((3.2, 4.775));
my_linestr : SD.Geometry := SD.initialize_as_line
(((-0.034, 14.993), (5.0, 6.0), (-3.0, 19.0), (0.0, -7.1000009)));
wrk_poly : SD.Geometric_Polygon := SD.start_polygon
(((35.0, 10.0), (45.0, 45.0), (15.0, 40.0), (10.0, 20.0), (35.0, 10.0)));
my_polygon : SD.Geometry;
my_mpoly : SD.Geometry;
my_mpoint : SD.Geometry := SD.initialize_as_multi_point ((10.0, 10.0));
my_mline : SD.Geometry := SD.initialize_as_multi_line
(((5.0, 5.0), (0.0, 2.0), (-7.0, 13.0), (99.0, -1.0), (50.0, 50.0)));
my_mixture : SD.Geometry := SD.initialize_as_collection (my_linestr);
begin
SD.append_inner_ring (wrk_poly, ((20.0, 30.0), (35.0, 35.0), (30.0, 20.0), (20.0, 30.0)));
my_polygon := SD.initialize_as_polygon (wrk_poly);
SD.augment_multi_point (my_mpoint, (100.0, 200.0));
SD.augment_multi_point (my_mpoint, (-52.0, 250.0));
SD.augment_multi_line (my_mline, ((20.0, 10.0), (87.0, 88.0)));
my_mpoly := SD.initialize_as_multi_polygon (wrk_poly);
SD.augment_collection (my_mixture, my_polygon);
SD.augment_collection (my_mixture, my_mpoint);
SD.augment_collection (my_mixture, my_point);
SD.augment_collection (my_mixture, my_mline);
declare
template : String := "INSERT INTO spatial_plus " &
"(id, sp_point, sp_linestring, sp_polygon, sp_multi_point," &
" sp_multi_line_string, sp_multi_polygon, sp_geo_collection)" &
" VALUES (10, ST_GeomFromText (:pt, 4326)," &
" ST_GeomFromText (:line, 4326)," &
" ST_GeomFromText (:poly, 4326)," &
" ST_GeomFromText(:mpoint, 4326)," &
" ST_GeomFromText(:mline, 4326)," &
" ST_GeomFromText(:mpoly, 4326)," &
" ST_GeomFromText(:collset, 4326))";
stmt : CON.Stmt_Type := CON.DR.prepare (template);
begin
stmt.assign ("pt", SD.Well_Known_Text (my_point));
stmt.assign ("line", SD.Well_Known_Text (my_linestr));
stmt.assign ("poly", SD.Well_Known_Text (my_polygon));
stmt.assign ("mpoint", SD.Well_Known_Text (my_mpoint));
stmt.assign ("mline", SD.Well_Known_Text (my_mline));
stmt.assign ("mpoly", SD.Well_Known_Text (my_mpoly));
stmt.assign ("collset", SD.Well_Known_Text (my_mixture));
if not stmt.execute then
TIO.Put_Line (stmt.last_driver_message);
CON.DR.rollback;
return;
end if;
declare
row : ARS.Datarow;
s2 : CON.Stmt_Type := CON.DR.query
("SELECT * FROM spatial_plus WHERE id=10");
begin
loop
row := s2.fetch_next;
exit when row.data_exhausted;
for x in Natural range 1 .. row.count loop
TIO.Put (s2.column_name (x) & " : ");
TIO.Put_Line (row.column (x).as_string);
end loop;
end loop;
end;
CON.DR.rollback;
end;
end;
CON.DR.disconnect;
end Spatial4;
|
------------------------------------------------------------------------------
-- --
-- Copyright (C) 2015, AdaCore --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions are --
-- met: --
-- 1. Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- 2. Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in --
-- the documentation and/or other materials provided with the --
-- distribution. --
-- 3. Neither the name of the copyright holder nor the names of its --
-- contributors may be used to endorse or promote products derived --
-- from this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT --
-- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, --
-- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY --
-- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT --
-- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE --
-- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
pragma Restrictions (No_Elaboration_Code);
package STM32.RCC is
procedure BKPSRAM_Clock_Enable with Inline;
procedure AHB_Force_Reset with Inline;
procedure AHB_Release_Reset with Inline;
procedure APB1_Force_Reset with Inline;
procedure APB1_Release_Reset with Inline;
procedure APB2_Force_Reset with Inline;
procedure APB2_Release_Reset with Inline;
procedure Backup_Domain_Reset;
-- Disable LSE clock and RTC and reset its configurations.
---------------------------------------------------------------------------
-- Clock Configuration --------------------------------------------------
---------------------------------------------------------------------------
---------------
-- HSE Clock --
---------------
procedure Set_HSE_Clock
(Enable : Boolean;
Bypass : Boolean := False;
Enable_CSS : Boolean := False)
with Post => HSE_Clock_Enabled = Enable;
function HSE_Clock_Enabled return Boolean;
---------------
-- LSE Clock --
---------------
type HSE_Capability is
(Lowest_Drive,
Low_Drive,
High_Drive,
Highest_Drive)
with Size => 2;
procedure Set_LSE_Clock
(Enable : Boolean;
Bypass : Boolean := False;
Capability : HSE_Capability)
with Post => LSE_Clock_Enabled = Enable;
function LSE_Clock_Enabled return Boolean;
---------------
-- HSI Clock --
---------------
procedure Set_HSI_Clock (Enable : Boolean)
with Post => HSI_Clock_Enabled = Enable;
-- The HSI clock can't be disabled if it is used directly (via SW mux) as
-- system clock or if the HSI is selected as reference clock for PLL with
-- PLL enabled (PLLON bit set to ‘1’). It is set by hardware if it is used
-- directly or indirectly as system clock.
function HSI_Clock_Enabled return Boolean;
---------------
-- LSI Clock --
---------------
procedure Set_LSI_Clock (Enable : Boolean)
with Post => LSI_Clock_Enabled = Enable;
function LSI_Clock_Enabled return Boolean;
------------------
-- System Clock --
------------------
type SYSCLK_Clock_Source is
(SYSCLK_SRC_HSI,
SYSCLK_SRC_HSE,
SYSCLK_SRC_PLL)
with Size => 2;
for SYSCLK_Clock_Source use
(SYSCLK_SRC_HSI => 2#01#,
SYSCLK_SRC_HSE => 2#10#,
SYSCLK_SRC_PLL => 2#11#);
procedure Configure_System_Clock_Mux (Source : SYSCLK_Clock_Source);
------------------------
-- AHB and APB Clocks --
------------------------
type AHB_Prescaler_Enum is
(DIV2, DIV4, DIV8, DIV16,
DIV64, DIV128, DIV256, DIV512)
with Size => 3;
type AHB_Prescaler is record
Enable : Boolean := False;
Value : AHB_Prescaler_Enum := AHB_Prescaler_Enum'First;
end record with Size => 4;
for AHB_Prescaler use record
Enable at 0 range 3 .. 3;
Value at 0 range 0 .. 2;
end record;
procedure Configure_AHB_Clock_Prescaler
(Value : AHB_Prescaler);
-- The AHB clock bus is the CPU clock selected by the AHB prescaler.
-- Example to create a variable:
-- AHB_PRE : AHB_Prescaler := (Enable => True, Value => DIV2);
type APB_Prescaler_Enum is
(DIV2, DIV4, DIV8, DIV16)
with Size => 2;
type APB_Prescaler is record
Enable : Boolean;
Value : APB_Prescaler_Enum := APB_Prescaler_Enum'First;
end record with Size => 3;
for APB_Prescaler use record
Enable at 0 range 2 .. 2;
Value at 0 range 0 .. 1;
end record;
type APB_Clock_Range is (APB_1, APB_2);
procedure Configure_APB_Clock_Prescaler
(Bus : APB_Clock_Range;
Value : APB_Prescaler);
-- The APB1 clock bus is the APB1 peripheral clock selected by the APB1
-- prescaler.
-- The APB2 clock bus is the APB2 peripheral clock selected by the APB2
-- prescaler.
-- Example to create a variable:
-- APB_PRE : APB_Prescaler := (Enable => True, Value => DIV2);
----------------
-- PLL Clocks --
----------------
type PLL_Clock_Source is
(PLL_SRC_HSI,
PLL_SRC_HSE)
with Size => 2;
for PLL_Clock_Source use
(PLL_SRC_HSI => 2#10#,
PLL_SRC_HSE => 2#11#);
procedure Configure_PLL_Source_Mux (Source : PLL_Clock_Source);
subtype PREDIV_Range is Integer range 1 .. 16;
subtype PLLMUL_Range is Integer range 2 .. 16;
procedure Configure_PLL
(Enable : Boolean;
PREDIV : PREDIV_Range := PREDIV_Range'First;
PLLMUL : PLLMUL_Range := PLLMUL_Range'First);
-- Configure PLL according with RM0364 rev 4 Chapter 8.2.3 section "PLL"
-- pg 110.
-------------------
-- Output Clocks --
-------------------
type MCO_Clock_Source is
(MCOSEL_Disabled,
MCOSEL_LSI,
MCOSEL_LSE,
MCOSEL_SYSCLK,
MCOSEL_HSI,
MCOSEL_HSE,
MCOSEL_PLL)
with Size => 3;
for MCO_Clock_Source use
(MCOSEL_Disabled => 2#000#,
MCOSEL_LSI => 2#010#,
MCOSEL_LSE => 2#011#,
MCOSEL_SYSCLK => 2#100#,
MCOSEL_HSI => 2#101#,
MCOSEL_HSE => 2#110#,
MCOSEL_PLL => 2#111#);
type MCO_Prescaler is
(MCOPRE_DIV1,
MCOPRE_DIV2,
MCOPRE_DIV3,
MCOPRE_DIV4,
MCOPRE_DIV5,
MCOPRE_DIV6,
MCOPRE_DIV7,
MCOPRE_DIV8)
with Size => 3;
procedure Configure_MCO_Output_Clock
(Source : MCO_Clock_Source;
Value : MCO_Prescaler;
Nodiv : Boolean := False);
-- Select the source for micro-controller clock output.
------------------
-- Flash Memory --
------------------
-- Flash wait states
type FLASH_Wait_State is (FWS0, FWS1, FWS2)
with Size => 3;
procedure Set_FLASH_Latency (Latency : FLASH_Wait_State);
-- Constants for Flash Latency
-- 000: Zero wait state, if 0 < HCLK ≤ 24 MHz
-- 001: One wait state, if 24 MHz < HCLK ≤ 48 MHz
-- 010: Two wait sates, if 48 < HCLK ≤ 72 MHz
-- RM STM32F334 rev 4 chapter 3.5.1 pg. 66
end STM32.RCC;
|
with AdaBase;
with Connect;
with CommonText;
with Ada.Text_IO;
with Ada.Wide_Text_IO;
with Ada.Wide_Wide_Text_IO;
with AdaBase.Results.Sets;
procedure UTF8 is
package CON renames Connect;
package TIO renames Ada.Text_IO;
package WIO renames Ada.Wide_Text_IO;
package WWO renames Ada.Wide_Wide_Text_IO;
package ARS renames AdaBase.Results.Sets;
package CT renames CommonText;
begin
CON.connect_database;
TIO.Put_Line ("Use terminal encoding UTF-8 or ISO8859-1");
TIO.Put_Line ("Either UTF8 fields or string fields will look right, " &
"but not both");
declare
sql : constant String := "SELECT * FROM funny_names";
stmt : CON.Stmt_Type := CON.DR.query (sql);
row : ARS.Datarow;
begin
loop
row := stmt.fetch_next;
exit when row.data_exhausted;
TIO.Put_Line ("");
TIO.Put_Line (" UTF8: " & row.column ("first_name").as_utf8 &
" " & row.column ("surname").as_utf8);
TIO.Put_Line (" STRING: " & row.column ("first_name").as_string &
" " & row.column ("surname").as_string);
WIO.Put_Line (" WSTRING: " & row.column ("first_name").as_wstring &
" " & row.column ("surname").as_wstring);
WWO.Put_Line ("WWSTRING: " & row.column ("first_name").as_wwstring &
" " & row.column ("surname").as_wwstring);
end loop;
end;
CON.DR.disconnect;
end UTF8;
|
with STM32F4.LCD; use STM32F4.LCD;
package Screen_Interface is
subtype Width is STM32F4.LCD.Width;
subtype Height is STM32F4.LCD.Height;
type Touch_State is record
Touch_Detected : Boolean;
X : Width;
Y : Height;
end record;
type Point is record
X : Width;
Y : Height;
end record;
function "+" (P1, P2 : Point) return Point is (P1.X + P2.X, P1.Y + P2.Y);
function "-" (P1, P2 : Point) return Point is (P1.X - P2.X, P1.Y - P2.Y);
subtype Color is STM32F4.LCD.Pixel;
Black : Color renames STM32F4.LCD.Black;
White : Color renames STM32F4.LCD.White;
Red : Color renames STM32F4.LCD.Red;
Green : Color renames STM32F4.LCD.Green;
Blue : Color renames STM32F4.LCD.Blue;
Gray : Color renames STM32F4.LCD.Gray;
Light_Gray : Color renames STM32F4.LCD.Light_Gray;
Sky_Blue : Color renames STM32F4.LCD.Sky_Blue;
Yellow : Color renames STM32F4.LCD.Yellow;
Orange : Color renames STM32F4.LCD.Orange;
Pink : Color renames STM32F4.LCD.Pink;
Violet : Color renames STM32F4.LCD.Violet;
procedure Initialize;
function Get_Touch_State return Touch_State;
procedure Set_Pixel (P : Point; Col : Color; Layer : LCD_Layer := Layer1);
procedure Fill_Screen (Col : Color; Layer : LCD_Layer := Layer1);
procedure Fast_Horiz_Line (Col : Color; X1: Width; X2 : Width; Y : Height; Layer : LCD_Layer := Layer1);
type RGB_Value is new Natural range 0 .. 255;
function RGB_To_Color (R, G, B : RGB_Value) return Color;
end Screen_Interface;
|
pragma License (Unrestricted);
-- extended unit specialized for Windows
with Ada.IO_Exceptions;
package Ada.Hierarchical_File_Names is
-- "Pure" and detailed version of Ada.Directories.Hierarchical_File_Names.
-- This package is system-specific.
pragma Pure;
-- path delimiter
subtype Path_Delimiter_Type is Character;
-- with Static_Predicate => Path_Delimiter in '/' | '\';
Default_Path_Delimiter : constant Character := '\';
function Is_Path_Delimiter (Item : Character) return Boolean;
pragma Inline (Is_Path_Delimiter);
procedure Include_Trailing_Path_Delimiter (
S : in out String;
Last : in out Natural;
Path_Delimiter : Path_Delimiter_Type := Default_Path_Delimiter);
procedure Exclude_Trailing_Path_Delimiter (
S : String;
Last : in out Natural);
-- operations in Ada.Directories
function Simple_Name (Name : String) return String;
-- extended
-- This function returns null string instead of Name_Error,
-- if Name has no simple name part.
function Unchecked_Simple_Name (Name : String) return String;
function Containing_Directory (Name : String) return String;
-- extended
-- This function returns null string instead of Use_Error,
-- if Name has no directory part.
function Unchecked_Containing_Directory (Name : String) return String;
function Extension (Name : String) return String;
function Base_Name (Name : String) return String;
-- extended
-- There are procedure version.
procedure Simple_Name (
Name : String;
First : out Positive;
Last : out Natural);
procedure Containing_Directory (
Name : String;
First : out Positive;
Last : out Natural);
procedure Extension (
Name : String;
First : out Positive;
Last : out Natural);
procedure Base_Name (
Name : String;
First : out Positive;
Last : out Natural);
-- operations in Ada.Directories.Hierarchical_File_Names
function Is_Simple_Name (Name : String) return Boolean;
function Is_Root_Directory_Name (Name : String) return Boolean;
function Is_Parent_Directory_Name (Name : String) return Boolean;
function Is_Current_Directory_Name (Name : String) return Boolean;
function Is_Full_Name (Name : String) return Boolean;
function Is_Relative_Name (Name : String) return Boolean;
-- function Simple_Name (Name : String) return String
-- renames Directories.Simple_Name;
-- function Containing_Directory (Name : String) return String
-- renames Directories.Containing_Directory;
function Initial_Directory (Name : String) return String;
function Relative_Name (Name : String) return String;
-- extended
-- This function returns null string instead of Name_Error,
-- if Name has no directory part.
function Unchecked_Relative_Name (Name : String) return String;
-- extended
-- There are procedure version.
procedure Initial_Directory (
Name : String;
First : out Positive;
Last : out Natural);
procedure Relative_Name (
Name : String;
First : out Positive;
Last : out Natural);
function Compose (
Directory : String := "";
Relative_Name : String;
Extension : String := "";
Path_Delimiter : Path_Delimiter_Type := Default_Path_Delimiter)
return String;
-- extended
-- This function folds current/parent directory names.
-- For example: Normalized_Compose ("A/B", "../C") = "A/C".
function Normalized_Compose (
Directory : String := "";
Relative_Name : String;
Extension : String := "";
Path_Delimiter : Path_Delimiter_Type := Default_Path_Delimiter)
return String;
-- extended
-- This function returns the relative name from the base directory.
-- For example: Relative_Name ("A", "B") = "../A",
-- Relative_Name (Name, Initial_Directory (Name)) = Relative_Name (Name)
function Relative_Name (
Name : String;
From : String;
Path_Delimiter : Path_Delimiter_Type := Default_Path_Delimiter)
return String;
-- extended
-- There is a procedure version. It also propagates Use_Error.
procedure Relative_Name (
Name : String;
First : out Positive;
Last : out Natural;
From : String;
Parent_Count : out Natural);
-- extended
-- This is a "folded" version of Containing_Directory if Directory /= "".
-- Otherwise, it returns ".." as the parent directory name.
-- For example: Parent_Directory ("A/B/.") = "A"
-- Parent_Directory ("A/B/C/..") = "A"
-- Parent_Directory (Name) = Normalized_Compose (Name, "..")
function Parent_Directory (
Directory : String;
Path_Delimiter : Path_Delimiter_Type := Default_Path_Delimiter)
return String;
-- extended
-- There is a procedure version.
procedure Parent_Directory (
Directory : String;
First : out Positive;
Last : out Natural;
Parent_Count : out Natural);
-- exceptions
Name_Error : exception
renames IO_Exceptions.Name_Error;
Use_Error : exception
renames IO_Exceptions.Use_Error;
end Ada.Hierarchical_File_Names;
|
-- The Village of Vampire by YT, このソースコードはNYSLです
package body Tabula.Villages is
use type Ada.Strings.Unbounded.Unbounded_String;
use type Casts.Person_Sex;
function Same_Id_And_Figure (Left, Right : Person_Type'Class) return Boolean is
begin
return Left.Id = Right.Id and then Left.Image = Right.Image;
end Same_Id_And_Figure;
function Option_Changed (Village : Village_Type) return Boolean is
Result : Boolean := False;
procedure Process (Item : in Root_Option_Item'Class) is
begin
if Item.Available and then Item.Changed then
Result := True;
end if;
end Process;
begin
Iterate_Options (Village_Type'Class (Village), Process'Access);
-- dyamic dispatch
return Result;
end Option_Changed;
function Joined (Village : Village_Type; User_Id : String)
return Person_Index'Base
is
Result : Person_Index'Base := No_Person;
procedure Process (Index : in Person_Index; Item : in Person_Type'Class) is
begin
if Item.Id = User_Id then
Result := Index;
end if;
end Process;
begin
Iterate_People (Village_Type'Class (Village), Process'Access);
return Result;
end Joined;
function Already_Joined_As_Another_Sex (
Village : Village_Type;
User_Id : String;
Sex : Casts.Person_Sex)
return Boolean
is
Result : Boolean := False;
procedure Process (Index : in Person_Index; Item : in Person_Type'Class) is
begin
if Item.Id = User_Id and then Item.Sex /= Sex then
Result := True;
end if;
end Process;
begin
Iterate_Escaped_People (Village_Type'Class (Village), Process'Access);
return Result;
end Already_Joined_As_Another_Sex;
function Male_And_Female (Village : Village_Type) return Boolean is
Existing : array (Casts.Person_Sex) of Boolean := (False, False);
procedure Process (Index : in Person_Index; Item : in Person_Type'Class) is
begin
Existing (Item.Sex) := True;
end Process;
begin
Iterate_People (Village_Type'Class (Village), Process'Access);
return Existing (Casts.Male) and then Existing (Casts.Female);
end Male_And_Female;
procedure Exclude_Taken (
Cast : in out Casts.Cast_Collection;
Village : in Village_Type)
is
procedure Process (Index : in Person_Index; Item : in Person_Type'Class) is
begin
-- remove all duplicated characters
Casts.Exclude_Person (Cast, Item.Name.Constant_Reference, Item.Group);
-- remove one duplicated work
Casts.Exclude_Work (Cast, Item.Work.Constant_Reference);
end Process;
begin
Iterate_People (Village_Type'Class (Village), Process'Access);
end Exclude_Taken;
end Tabula.Villages;
|
------------------------------------------------------------------------------
-- --
-- GNAT LIBRARY COMPONENTS --
-- --
-- ADA.CONTAINERS.FORMAL_DOUBLY_LINKED_LISTS --
-- --
-- S p e c --
-- --
-- Copyright (C) 2004-2020, Free Software Foundation, Inc. --
-- --
-- This specification is derived from the Ada Reference Manual for use with --
-- GNAT. The copyright notice above, and the license provisions that follow --
-- apply solely to the contents of the part following the private keyword. --
-- --
-- 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/>. --
------------------------------------------------------------------------------
with Ada.Containers.Functional_Vectors;
with Ada.Containers.Functional_Maps;
generic
type Element_Type is private;
with function "=" (Left, Right : Element_Type) return Boolean is <>;
package Ada.Containers.Formal_Doubly_Linked_Lists with
SPARK_Mode
is
pragma Annotate (CodePeer, Skip_Analysis);
type List (Capacity : Count_Type) is private with
Iterable => (First => First,
Next => Next,
Has_Element => Has_Element,
Element => Element),
Default_Initial_Condition => Is_Empty (List);
pragma Preelaborable_Initialization (List);
type Cursor is record
Node : Count_Type := 0;
end record;
No_Element : constant Cursor := Cursor'(Node => 0);
Empty_List : constant List;
function Length (Container : List) return Count_Type with
Global => null,
Post => Length'Result <= Container.Capacity;
pragma Unevaluated_Use_Of_Old (Allow);
package Formal_Model with Ghost is
subtype Positive_Count_Type is Count_Type range 1 .. Count_Type'Last;
package M is new Ada.Containers.Functional_Vectors
(Index_Type => Positive_Count_Type,
Element_Type => Element_Type);
function "="
(Left : M.Sequence;
Right : M.Sequence) return Boolean renames M."=";
function "<"
(Left : M.Sequence;
Right : M.Sequence) return Boolean renames M."<";
function "<="
(Left : M.Sequence;
Right : M.Sequence) return Boolean renames M."<=";
function M_Elements_In_Union
(Container : M.Sequence;
Left : M.Sequence;
Right : M.Sequence) return Boolean
-- The elements of Container are contained in either Left or Right
with
Global => null,
Post =>
M_Elements_In_Union'Result =
(for all I in 1 .. M.Length (Container) =>
(for some J in 1 .. M.Length (Left) =>
Element (Container, I) = Element (Left, J))
or (for some J in 1 .. M.Length (Right) =>
Element (Container, I) = Element (Right, J)));
pragma Annotate (GNATprove, Inline_For_Proof, M_Elements_In_Union);
function M_Elements_Included
(Left : M.Sequence;
L_Fst : Positive_Count_Type := 1;
L_Lst : Count_Type;
Right : M.Sequence;
R_Fst : Positive_Count_Type := 1;
R_Lst : Count_Type) return Boolean
-- The elements of the slice from L_Fst to L_Lst in Left are contained
-- in the slide from R_Fst to R_Lst in Right.
with
Global => null,
Pre => L_Lst <= M.Length (Left) and R_Lst <= M.Length (Right),
Post =>
M_Elements_Included'Result =
(for all I in L_Fst .. L_Lst =>
(for some J in R_Fst .. R_Lst =>
Element (Left, I) = Element (Right, J)));
pragma Annotate (GNATprove, Inline_For_Proof, M_Elements_Included);
function M_Elements_Reversed
(Left : M.Sequence;
Right : M.Sequence) return Boolean
-- Right is Left in reverse order
with
Global => null,
Post =>
M_Elements_Reversed'Result =
(M.Length (Left) = M.Length (Right)
and (for all I in 1 .. M.Length (Left) =>
Element (Left, I) =
Element (Right, M.Length (Left) - I + 1))
and (for all I in 1 .. M.Length (Left) =>
Element (Right, I) =
Element (Left, M.Length (Left) - I + 1)));
pragma Annotate (GNATprove, Inline_For_Proof, M_Elements_Reversed);
function M_Elements_Swapped
(Left : M.Sequence;
Right : M.Sequence;
X : Positive_Count_Type;
Y : Positive_Count_Type) return Boolean
-- Elements stored at X and Y are reversed in Left and Right
with
Global => null,
Pre => X <= M.Length (Left) and Y <= M.Length (Left),
Post =>
M_Elements_Swapped'Result =
(M.Length (Left) = M.Length (Right)
and Element (Left, X) = Element (Right, Y)
and Element (Left, Y) = Element (Right, X)
and M.Equal_Except (Left, Right, X, Y));
pragma Annotate (GNATprove, Inline_For_Proof, M_Elements_Swapped);
package P is new Ada.Containers.Functional_Maps
(Key_Type => Cursor,
Element_Type => Positive_Count_Type,
Equivalent_Keys => "=",
Enable_Handling_Of_Equivalence => False);
function "="
(Left : P.Map;
Right : P.Map) return Boolean renames P."=";
function "<="
(Left : P.Map;
Right : P.Map) return Boolean renames P."<=";
function P_Positions_Shifted
(Small : P.Map;
Big : P.Map;
Cut : Positive_Count_Type;
Count : Count_Type := 1) return Boolean
with
Global => null,
Post =>
P_Positions_Shifted'Result =
-- Big contains all cursors of Small
(P.Keys_Included (Small, Big)
-- Cursors located before Cut are not moved, cursors located
-- after are shifted by Count.
and (for all I of Small =>
(if P.Get (Small, I) < Cut then
P.Get (Big, I) = P.Get (Small, I)
else
P.Get (Big, I) - Count = P.Get (Small, I)))
-- New cursors of Big (if any) are between Cut and Cut - 1 +
-- Count.
and (for all I of Big =>
P.Has_Key (Small, I)
or P.Get (Big, I) - Count in Cut - Count .. Cut - 1));
function P_Positions_Swapped
(Left : P.Map;
Right : P.Map;
X : Cursor;
Y : Cursor) return Boolean
-- Left and Right contain the same cursors, but the positions of X and Y
-- are reversed.
with
Ghost,
Global => null,
Post =>
P_Positions_Swapped'Result =
(P.Same_Keys (Left, Right)
and P.Elements_Equal_Except (Left, Right, X, Y)
and P.Has_Key (Left, X)
and P.Has_Key (Left, Y)
and P.Get (Left, X) = P.Get (Right, Y)
and P.Get (Left, Y) = P.Get (Right, X));
function P_Positions_Truncated
(Small : P.Map;
Big : P.Map;
Cut : Positive_Count_Type;
Count : Count_Type := 1) return Boolean
with
Ghost,
Global => null,
Post =>
P_Positions_Truncated'Result =
-- Big contains all cursors of Small at the same position
(Small <= Big
-- New cursors of Big (if any) are between Cut and Cut - 1 +
-- Count.
and (for all I of Big =>
P.Has_Key (Small, I)
or P.Get (Big, I) - Count in Cut - Count .. Cut - 1));
function Mapping_Preserved
(M_Left : M.Sequence;
M_Right : M.Sequence;
P_Left : P.Map;
P_Right : P.Map) return Boolean
with
Ghost,
Global => null,
Post =>
(if Mapping_Preserved'Result then
-- Left and Right contain the same cursors
P.Same_Keys (P_Left, P_Right)
-- Mappings from cursors to elements induced by M_Left, P_Left
-- and M_Right, P_Right are the same.
and (for all C of P_Left =>
M.Get (M_Left, P.Get (P_Left, C)) =
M.Get (M_Right, P.Get (P_Right, C))));
function Model (Container : List) return M.Sequence with
-- The high-level model of a list is a sequence of elements. Cursors are
-- not represented in this model.
Ghost,
Global => null,
Post => M.Length (Model'Result) = Length (Container);
pragma Annotate (GNATprove, Iterable_For_Proof, "Model", Model);
function Positions (Container : List) return P.Map with
-- The Positions map is used to model cursors. It only contains valid
-- cursors and map them to their position in the container.
Ghost,
Global => null,
Post =>
not P.Has_Key (Positions'Result, No_Element)
-- Positions of cursors are smaller than the container's length.
and then
(for all I of Positions'Result =>
P.Get (Positions'Result, I) in 1 .. Length (Container)
-- No two cursors have the same position. Note that we do not
-- state that there is a cursor in the map for each position, as
-- it is rarely needed.
and then
(for all J of Positions'Result =>
(if P.Get (Positions'Result, I) = P.Get (Positions'Result, J)
then I = J)));
procedure Lift_Abstraction_Level (Container : List) with
-- Lift_Abstraction_Level is a ghost procedure that does nothing but
-- assume that we can access to the same elements by iterating over
-- positions or cursors.
-- This information is not generally useful except when switching from
-- a low-level cursor-aware view of a container to a high-level
-- position-based view.
Ghost,
Global => null,
Post =>
(for all Elt of Model (Container) =>
(for some I of Positions (Container) =>
M.Get (Model (Container), P.Get (Positions (Container), I)) =
Elt));
function Element
(S : M.Sequence;
I : Count_Type) return Element_Type renames M.Get;
-- To improve readability of contracts, we rename the function used to
-- access an element in the model to Element.
end Formal_Model;
use Formal_Model;
function "=" (Left, Right : List) return Boolean with
Global => null,
Post => "="'Result = (Model (Left) = Model (Right));
function Is_Empty (Container : List) return Boolean with
Global => null,
Post => Is_Empty'Result = (Length (Container) = 0);
procedure Clear (Container : in out List) with
Global => null,
Post => Length (Container) = 0;
procedure Assign (Target : in out List; Source : List) with
Global => null,
Pre => Target.Capacity >= Length (Source),
Post => Model (Target) = Model (Source);
function Copy (Source : List; Capacity : Count_Type := 0) return List with
Global => null,
Pre => Capacity = 0 or else Capacity >= Source.Capacity,
Post =>
Model (Copy'Result) = Model (Source)
and Positions (Copy'Result) = Positions (Source)
and (if Capacity = 0 then
Copy'Result.Capacity = Source.Capacity
else
Copy'Result.Capacity = Capacity);
function Element
(Container : List;
Position : Cursor) return Element_Type
with
Global => null,
Pre => Has_Element (Container, Position),
Post =>
Element'Result =
Element (Model (Container), P.Get (Positions (Container), Position));
pragma Annotate (GNATprove, Inline_For_Proof, Element);
procedure Replace_Element
(Container : in out List;
Position : Cursor;
New_Item : Element_Type)
with
Global => null,
Pre => Has_Element (Container, Position),
Post =>
Length (Container) = Length (Container)'Old
-- Cursors are preserved
and Positions (Container)'Old = Positions (Container)
-- The element at the position of Position in Container is New_Item
and Element
(Model (Container),
P.Get (Positions (Container), Position)) = New_Item
-- Other elements are preserved
and M.Equal_Except
(Model (Container)'Old,
Model (Container),
P.Get (Positions (Container), Position));
procedure Move (Target : in out List; Source : in out List) with
Global => null,
Pre => Target.Capacity >= Length (Source),
Post => Model (Target) = Model (Source'Old) and Length (Source) = 0;
procedure Insert
(Container : in out List;
Before : Cursor;
New_Item : Element_Type)
with
Global => null,
Pre =>
Length (Container) < Container.Capacity
and then (Has_Element (Container, Before)
or else Before = No_Element),
Post => Length (Container) = Length (Container)'Old + 1,
Contract_Cases =>
(Before = No_Element =>
-- Positions contains a new mapping from the last cursor of
-- Container to its length.
P.Get (Positions (Container), Last (Container)) = Length (Container)
-- Other cursors come from Container'Old
and P.Keys_Included_Except
(Left => Positions (Container),
Right => Positions (Container)'Old,
New_Key => Last (Container))
-- Cursors of Container'Old keep the same position
and Positions (Container)'Old <= Positions (Container)
-- Model contains a new element New_Item at the end
and Element (Model (Container), Length (Container)) = New_Item
-- Elements of Container'Old are preserved
and Model (Container)'Old <= Model (Container),
others =>
-- The elements of Container located before Before are preserved
M.Range_Equal
(Left => Model (Container)'Old,
Right => Model (Container),
Fst => 1,
Lst => P.Get (Positions (Container)'Old, Before) - 1)
-- Other elements are shifted by 1
and M.Range_Shifted
(Left => Model (Container)'Old,
Right => Model (Container),
Fst => P.Get (Positions (Container)'Old, Before),
Lst => Length (Container)'Old,
Offset => 1)
-- New_Item is stored at the previous position of Before in
-- Container.
and Element
(Model (Container),
P.Get (Positions (Container)'Old, Before)) = New_Item
-- A new cursor has been inserted at position Before in Container
and P_Positions_Shifted
(Positions (Container)'Old,
Positions (Container),
Cut => P.Get (Positions (Container)'Old, Before)));
procedure Insert
(Container : in out List;
Before : Cursor;
New_Item : Element_Type;
Count : Count_Type)
with
Global => null,
Pre =>
Length (Container) <= Container.Capacity - Count
and then (Has_Element (Container, Before)
or else Before = No_Element),
Post => Length (Container) = Length (Container)'Old + Count,
Contract_Cases =>
(Before = No_Element =>
-- The elements of Container are preserved
M.Range_Equal
(Left => Model (Container)'Old,
Right => Model (Container),
Fst => 1,
Lst => Length (Container)'Old)
-- Container contains Count times New_Item at the end
and (if Count > 0 then
M.Constant_Range
(Container => Model (Container),
Fst => Length (Container)'Old + 1,
Lst => Length (Container),
Item => New_Item))
-- Container contains Count times New_Item at the end
and M.Constant_Range
(Container => Model (Container),
Fst => Length (Container)'Old + 1,
Lst => Length (Container),
Item => New_Item)
-- A Count cursors have been inserted at the end of Container
and P_Positions_Truncated
(Positions (Container)'Old,
Positions (Container),
Cut => Length (Container)'Old + 1,
Count => Count),
others =>
-- The elements of Container located before Before are preserved
M.Range_Equal
(Left => Model (Container)'Old,
Right => Model (Container),
Fst => 1,
Lst => P.Get (Positions (Container)'Old, Before) - 1)
-- Other elements are shifted by Count
and M.Range_Shifted
(Left => Model (Container)'Old,
Right => Model (Container),
Fst => P.Get (Positions (Container)'Old, Before),
Lst => Length (Container)'Old,
Offset => Count)
-- Container contains Count times New_Item after position Before
and M.Constant_Range
(Container => Model (Container),
Fst => P.Get (Positions (Container)'Old, Before),
Lst =>
P.Get (Positions (Container)'Old, Before) - 1 + Count,
Item => New_Item)
-- Count cursors have been inserted at position Before in
-- Container.
and P_Positions_Shifted
(Positions (Container)'Old,
Positions (Container),
Cut => P.Get (Positions (Container)'Old, Before),
Count => Count));
procedure Insert
(Container : in out List;
Before : Cursor;
New_Item : Element_Type;
Position : out Cursor)
with
Global => null,
Pre =>
Length (Container) < Container.Capacity
and then (Has_Element (Container, Before)
or else Before = No_Element),
Post =>
Length (Container) = Length (Container)'Old + 1
-- Positions is valid in Container and it is located either before
-- Before if it is valid in Container or at the end if it is
-- No_Element.
and P.Has_Key (Positions (Container), Position)
and (if Before = No_Element then
P.Get (Positions (Container), Position) = Length (Container)
else
P.Get (Positions (Container), Position) =
P.Get (Positions (Container)'Old, Before))
-- The elements of Container located before Position are preserved
and M.Range_Equal
(Left => Model (Container)'Old,
Right => Model (Container),
Fst => 1,
Lst => P.Get (Positions (Container), Position) - 1)
-- Other elements are shifted by 1
and M.Range_Shifted
(Left => Model (Container)'Old,
Right => Model (Container),
Fst => P.Get (Positions (Container), Position),
Lst => Length (Container)'Old,
Offset => 1)
-- New_Item is stored at Position in Container
and Element
(Model (Container),
P.Get (Positions (Container), Position)) = New_Item
-- A new cursor has been inserted at position Position in Container
and P_Positions_Shifted
(Positions (Container)'Old,
Positions (Container),
Cut => P.Get (Positions (Container), Position));
procedure Insert
(Container : in out List;
Before : Cursor;
New_Item : Element_Type;
Position : out Cursor;
Count : Count_Type)
with
Global => null,
Pre =>
Length (Container) <= Container.Capacity - Count
and then (Has_Element (Container, Before)
or else Before = No_Element),
Post => Length (Container) = Length (Container)'Old + Count,
Contract_Cases =>
(Count = 0 =>
Position = Before
and Model (Container) = Model (Container)'Old
and Positions (Container) = Positions (Container)'Old,
others =>
-- Positions is valid in Container and it is located either before
-- Before if it is valid in Container or at the end if it is
-- No_Element.
P.Has_Key (Positions (Container), Position)
and (if Before = No_Element then
P.Get (Positions (Container), Position) =
Length (Container)'Old + 1
else
P.Get (Positions (Container), Position) =
P.Get (Positions (Container)'Old, Before))
-- The elements of Container located before Position are preserved
and M.Range_Equal
(Left => Model (Container)'Old,
Right => Model (Container),
Fst => 1,
Lst => P.Get (Positions (Container), Position) - 1)
-- Other elements are shifted by Count
and M.Range_Shifted
(Left => Model (Container)'Old,
Right => Model (Container),
Fst => P.Get (Positions (Container), Position),
Lst => Length (Container)'Old,
Offset => Count)
-- Container contains Count times New_Item after position Position
and M.Constant_Range
(Container => Model (Container),
Fst => P.Get (Positions (Container), Position),
Lst =>
P.Get (Positions (Container), Position) - 1 + Count,
Item => New_Item)
-- Count cursor have been inserted at Position in Container
and P_Positions_Shifted
(Positions (Container)'Old,
Positions (Container),
Cut => P.Get (Positions (Container), Position),
Count => Count));
procedure Prepend (Container : in out List; New_Item : Element_Type) with
Global => null,
Pre => Length (Container) < Container.Capacity,
Post =>
Length (Container) = Length (Container)'Old + 1
-- Elements are shifted by 1
and M.Range_Shifted
(Left => Model (Container)'Old,
Right => Model (Container),
Fst => 1,
Lst => Length (Container)'Old,
Offset => 1)
-- New_Item is the first element of Container
and Element (Model (Container), 1) = New_Item
-- A new cursor has been inserted at the beginning of Container
and P_Positions_Shifted
(Positions (Container)'Old,
Positions (Container),
Cut => 1);
procedure Prepend
(Container : in out List;
New_Item : Element_Type;
Count : Count_Type)
with
Global => null,
Pre => Length (Container) <= Container.Capacity - Count,
Post =>
Length (Container) = Length (Container)'Old + Count
-- Elements are shifted by Count
and M.Range_Shifted
(Left => Model (Container)'Old,
Right => Model (Container),
Fst => 1,
Lst => Length (Container)'Old,
Offset => Count)
-- Container starts with Count times New_Item
and M.Constant_Range
(Container => Model (Container),
Fst => 1,
Lst => Count,
Item => New_Item)
-- Count cursors have been inserted at the beginning of Container
and P_Positions_Shifted
(Positions (Container)'Old,
Positions (Container),
Cut => 1,
Count => Count);
procedure Append (Container : in out List; New_Item : Element_Type) with
Global => null,
Pre => Length (Container) < Container.Capacity,
Post =>
Length (Container) = Length (Container)'Old + 1
-- Positions contains a new mapping from the last cursor of Container
-- to its length.
and P.Get (Positions (Container), Last (Container)) =
Length (Container)
-- Other cursors come from Container'Old
and P.Keys_Included_Except
(Left => Positions (Container),
Right => Positions (Container)'Old,
New_Key => Last (Container))
-- Cursors of Container'Old keep the same position
and Positions (Container)'Old <= Positions (Container)
-- Model contains a new element New_Item at the end
and Element (Model (Container), Length (Container)) = New_Item
-- Elements of Container'Old are preserved
and Model (Container)'Old <= Model (Container);
procedure Append
(Container : in out List;
New_Item : Element_Type;
Count : Count_Type)
with
Global => null,
Pre => Length (Container) <= Container.Capacity - Count,
Post =>
Length (Container) = Length (Container)'Old + Count
-- The elements of Container are preserved
and Model (Container)'Old <= Model (Container)
-- Container contains Count times New_Item at the end
and (if Count > 0 then
M.Constant_Range
(Container => Model (Container),
Fst => Length (Container)'Old + 1,
Lst => Length (Container),
Item => New_Item))
-- Count cursors have been inserted at the end of Container
and P_Positions_Truncated
(Positions (Container)'Old,
Positions (Container),
Cut => Length (Container)'Old + 1,
Count => Count);
procedure Delete (Container : in out List; Position : in out Cursor) with
Global => null,
Depends => (Container =>+ Position, Position => null),
Pre => Has_Element (Container, Position),
Post =>
Length (Container) = Length (Container)'Old - 1
-- Position is set to No_Element
and Position = No_Element
-- The elements of Container located before Position are preserved.
and M.Range_Equal
(Left => Model (Container)'Old,
Right => Model (Container),
Fst => 1,
Lst => P.Get (Positions (Container)'Old, Position'Old) - 1)
-- The elements located after Position are shifted by 1
and M.Range_Shifted
(Left => Model (Container),
Right => Model (Container)'Old,
Fst => P.Get (Positions (Container)'Old, Position'Old),
Lst => Length (Container),
Offset => 1)
-- Position has been removed from Container
and P_Positions_Shifted
(Positions (Container),
Positions (Container)'Old,
Cut => P.Get (Positions (Container)'Old, Position'Old));
procedure Delete
(Container : in out List;
Position : in out Cursor;
Count : Count_Type)
with
Global => null,
Pre => Has_Element (Container, Position),
Post =>
Length (Container) in
Length (Container)'Old - Count .. Length (Container)'Old
-- Position is set to No_Element
and Position = No_Element
-- The elements of Container located before Position are preserved.
and M.Range_Equal
(Left => Model (Container)'Old,
Right => Model (Container),
Fst => 1,
Lst => P.Get (Positions (Container)'Old, Position'Old) - 1),
Contract_Cases =>
-- All the elements after Position have been erased
(Length (Container) - Count < P.Get (Positions (Container), Position) =>
Length (Container) =
P.Get (Positions (Container)'Old, Position'Old) - 1
-- At most Count cursors have been removed at the end of Container
and P_Positions_Truncated
(Positions (Container),
Positions (Container)'Old,
Cut => P.Get (Positions (Container)'Old, Position'Old),
Count => Count),
others =>
Length (Container) = Length (Container)'Old - Count
-- Other elements are shifted by Count
and M.Range_Shifted
(Left => Model (Container),
Right => Model (Container)'Old,
Fst => P.Get (Positions (Container)'Old, Position'Old),
Lst => Length (Container),
Offset => Count)
-- Count cursors have been removed from Container at Position
and P_Positions_Shifted
(Positions (Container),
Positions (Container)'Old,
Cut => P.Get (Positions (Container)'Old, Position'Old),
Count => Count));
procedure Delete_First (Container : in out List) with
Global => null,
Pre => not Is_Empty (Container),
Post =>
Length (Container) = Length (Container)'Old - 1
-- The elements of Container are shifted by 1
and M.Range_Shifted
(Left => Model (Container),
Right => Model (Container)'Old,
Fst => 1,
Lst => Length (Container),
Offset => 1)
-- The first cursor of Container has been removed
and P_Positions_Shifted
(Positions (Container),
Positions (Container)'Old,
Cut => 1);
procedure Delete_First (Container : in out List; Count : Count_Type) with
Global => null,
Contract_Cases =>
-- All the elements of Container have been erased
(Length (Container) <= Count =>
Length (Container) = 0,
others =>
Length (Container) = Length (Container)'Old - Count
-- Elements of Container are shifted by Count
and M.Range_Shifted
(Left => Model (Container),
Right => Model (Container)'Old,
Fst => 1,
Lst => Length (Container),
Offset => Count)
-- The first Count cursors have been removed from Container
and P_Positions_Shifted
(Positions (Container),
Positions (Container)'Old,
Cut => 1,
Count => Count));
procedure Delete_Last (Container : in out List) with
Global => null,
Pre => not Is_Empty (Container),
Post =>
Length (Container) = Length (Container)'Old - 1
-- The elements of Container are preserved
and Model (Container) <= Model (Container)'Old
-- The last cursor of Container has been removed
and not P.Has_Key (Positions (Container), Last (Container)'Old)
-- Other cursors are still valid
and P.Keys_Included_Except
(Left => Positions (Container)'Old,
Right => Positions (Container)'Old,
New_Key => Last (Container)'Old)
-- The positions of other cursors are preserved
and Positions (Container) <= Positions (Container)'Old;
procedure Delete_Last (Container : in out List; Count : Count_Type) with
Global => null,
Contract_Cases =>
-- All the elements of Container have been erased
(Length (Container) <= Count =>
Length (Container) = 0,
others =>
Length (Container) = Length (Container)'Old - Count
-- The elements of Container are preserved
and Model (Container) <= Model (Container)'Old
-- At most Count cursors have been removed at the end of Container
and P_Positions_Truncated
(Positions (Container),
Positions (Container)'Old,
Cut => Length (Container) + 1,
Count => Count));
procedure Reverse_Elements (Container : in out List) with
Global => null,
Post => M_Elements_Reversed (Model (Container)'Old, Model (Container));
procedure Swap
(Container : in out List;
I : Cursor;
J : Cursor)
with
Global => null,
Pre => Has_Element (Container, I) and then Has_Element (Container, J),
Post =>
M_Elements_Swapped
(Model (Container)'Old,
Model (Container),
X => P.Get (Positions (Container)'Old, I),
Y => P.Get (Positions (Container)'Old, J))
and Positions (Container) = Positions (Container)'Old;
procedure Swap_Links
(Container : in out List;
I : Cursor;
J : Cursor)
with
Global => null,
Pre => Has_Element (Container, I) and then Has_Element (Container, J),
Post =>
M_Elements_Swapped
(Model (Container'Old),
Model (Container),
X => P.Get (Positions (Container)'Old, I),
Y => P.Get (Positions (Container)'Old, J))
and P_Positions_Swapped
(Positions (Container)'Old, Positions (Container), I, J);
procedure Splice
(Target : in out List;
Before : Cursor;
Source : in out List)
-- Target and Source should not be aliased
with
Global => null,
Pre =>
Length (Source) <= Target.Capacity - Length (Target)
and then (Has_Element (Target, Before)
or else Before = No_Element),
Post =>
Length (Source) = 0
and Length (Target) = Length (Target)'Old + Length (Source)'Old,
Contract_Cases =>
(Before = No_Element =>
-- The elements of Target are preserved
M.Range_Equal
(Left => Model (Target)'Old,
Right => Model (Target),
Fst => 1,
Lst => Length (Target)'Old)
-- The elements of Source are appended to target, the order is not
-- specified.
and M_Elements_Included
(Left => Model (Source)'Old,
L_Lst => Length (Source)'Old,
Right => Model (Target),
R_Fst => Length (Target)'Old + 1,
R_Lst => Length (Target))
and M_Elements_Included
(Left => Model (Target),
L_Fst => Length (Target)'Old + 1,
L_Lst => Length (Target),
Right => Model (Source)'Old,
R_Lst => Length (Source)'Old)
-- Cursors have been inserted at the end of Target
and P_Positions_Truncated
(Positions (Target)'Old,
Positions (Target),
Cut => Length (Target)'Old + 1,
Count => Length (Source)'Old),
others =>
-- The elements of Target located before Before are preserved
M.Range_Equal
(Left => Model (Target)'Old,
Right => Model (Target),
Fst => 1,
Lst => P.Get (Positions (Target)'Old, Before) - 1)
-- The elements of Source are inserted before Before, the order is
-- not specified.
and M_Elements_Included
(Left => Model (Source)'Old,
L_Lst => Length (Source)'Old,
Right => Model (Target),
R_Fst => P.Get (Positions (Target)'Old, Before),
R_Lst =>
P.Get (Positions (Target)'Old, Before) - 1 +
Length (Source)'Old)
and M_Elements_Included
(Left => Model (Target),
L_Fst => P.Get (Positions (Target)'Old, Before),
L_Lst =>
P.Get (Positions (Target)'Old, Before) - 1 +
Length (Source)'Old,
Right => Model (Source)'Old,
R_Lst => Length (Source)'Old)
-- Other elements are shifted by the length of Source
and M.Range_Shifted
(Left => Model (Target)'Old,
Right => Model (Target),
Fst => P.Get (Positions (Target)'Old, Before),
Lst => Length (Target)'Old,
Offset => Length (Source)'Old)
-- Cursors have been inserted at position Before in Target
and P_Positions_Shifted
(Positions (Target)'Old,
Positions (Target),
Cut => P.Get (Positions (Target)'Old, Before),
Count => Length (Source)'Old));
procedure Splice
(Target : in out List;
Before : Cursor;
Source : in out List;
Position : in out Cursor)
-- Target and Source should not be aliased
with
Global => null,
Pre =>
(Has_Element (Target, Before) or else Before = No_Element)
and then Has_Element (Source, Position)
and then Length (Target) < Target.Capacity,
Post =>
Length (Target) = Length (Target)'Old + 1
and Length (Source) = Length (Source)'Old - 1
-- The elements of Source located before Position are preserved
and M.Range_Equal
(Left => Model (Source)'Old,
Right => Model (Source),
Fst => 1,
Lst => P.Get (Positions (Source)'Old, Position'Old) - 1)
-- The elements located after Position are shifted by 1
and M.Range_Shifted
(Left => Model (Source)'Old,
Right => Model (Source),
Fst => P.Get (Positions (Source)'Old, Position'Old) + 1,
Lst => Length (Source)'Old,
Offset => -1)
-- Position has been removed from Source
and P_Positions_Shifted
(Positions (Source),
Positions (Source)'Old,
Cut => P.Get (Positions (Source)'Old, Position'Old))
-- Positions is valid in Target and it is located either before
-- Before if it is valid in Target or at the end if it is No_Element.
and P.Has_Key (Positions (Target), Position)
and (if Before = No_Element then
P.Get (Positions (Target), Position) = Length (Target)
else
P.Get (Positions (Target), Position) =
P.Get (Positions (Target)'Old, Before))
-- The elements of Target located before Position are preserved
and M.Range_Equal
(Left => Model (Target)'Old,
Right => Model (Target),
Fst => 1,
Lst => P.Get (Positions (Target), Position) - 1)
-- Other elements are shifted by 1
and M.Range_Shifted
(Left => Model (Target)'Old,
Right => Model (Target),
Fst => P.Get (Positions (Target), Position),
Lst => Length (Target)'Old,
Offset => 1)
-- The element located at Position in Source is moved to Target
and Element (Model (Target),
P.Get (Positions (Target), Position)) =
Element (Model (Source)'Old,
P.Get (Positions (Source)'Old, Position'Old))
-- A new cursor has been inserted at position Position in Target
and P_Positions_Shifted
(Positions (Target)'Old,
Positions (Target),
Cut => P.Get (Positions (Target), Position));
procedure Splice
(Container : in out List;
Before : Cursor;
Position : Cursor)
with
Global => null,
Pre =>
(Has_Element (Container, Before) or else Before = No_Element)
and then Has_Element (Container, Position),
Post => Length (Container) = Length (Container)'Old,
Contract_Cases =>
(Before = Position =>
Model (Container) = Model (Container)'Old
and Positions (Container) = Positions (Container)'Old,
Before = No_Element =>
-- The elements located before Position are preserved
M.Range_Equal
(Left => Model (Container)'Old,
Right => Model (Container),
Fst => 1,
Lst => P.Get (Positions (Container)'Old, Position) - 1)
-- The elements located after Position are shifted by 1
and M.Range_Shifted
(Left => Model (Container)'Old,
Right => Model (Container),
Fst => P.Get (Positions (Container)'Old, Position) + 1,
Lst => Length (Container)'Old,
Offset => -1)
-- The last element of Container is the one that was previously at
-- Position.
and Element (Model (Container),
Length (Container)) =
Element (Model (Container)'Old,
P.Get (Positions (Container)'Old, Position))
-- Cursors from Container continue designating the same elements
and Mapping_Preserved
(M_Left => Model (Container)'Old,
M_Right => Model (Container),
P_Left => Positions (Container)'Old,
P_Right => Positions (Container)),
others =>
-- The elements located before Position and Before are preserved
M.Range_Equal
(Left => Model (Container)'Old,
Right => Model (Container),
Fst => 1,
Lst =>
Count_Type'Min
(P.Get (Positions (Container)'Old, Position) - 1,
P.Get (Positions (Container)'Old, Before) - 1))
-- The elements located after Position and Before are preserved
and M.Range_Equal
(Left => Model (Container)'Old,
Right => Model (Container),
Fst =>
Count_Type'Max
(P.Get (Positions (Container)'Old, Position) + 1,
P.Get (Positions (Container)'Old, Before) + 1),
Lst => Length (Container))
-- The elements located after Before and before Position are
-- shifted by 1 to the right.
and M.Range_Shifted
(Left => Model (Container)'Old,
Right => Model (Container),
Fst => P.Get (Positions (Container)'Old, Before) + 1,
Lst => P.Get (Positions (Container)'Old, Position) - 1,
Offset => 1)
-- The elements located after Position and before Before are
-- shifted by 1 to the left.
and M.Range_Shifted
(Left => Model (Container)'Old,
Right => Model (Container),
Fst => P.Get (Positions (Container)'Old, Position) + 1,
Lst => P.Get (Positions (Container)'Old, Before) - 1,
Offset => -1)
-- The element previously at Position is now before Before
and Element
(Model (Container),
P.Get (Positions (Container)'Old, Before)) =
Element
(Model (Container)'Old,
P.Get (Positions (Container)'Old, Position))
-- Cursors from Container continue designating the same elements
and Mapping_Preserved
(M_Left => Model (Container)'Old,
M_Right => Model (Container),
P_Left => Positions (Container)'Old,
P_Right => Positions (Container)));
function First (Container : List) return Cursor with
Global => null,
Contract_Cases =>
(Length (Container) = 0 =>
First'Result = No_Element,
others =>
Has_Element (Container, First'Result)
and P.Get (Positions (Container), First'Result) = 1);
function First_Element (Container : List) return Element_Type with
Global => null,
Pre => not Is_Empty (Container),
Post => First_Element'Result = M.Get (Model (Container), 1);
function Last (Container : List) return Cursor with
Global => null,
Contract_Cases =>
(Length (Container) = 0 =>
Last'Result = No_Element,
others =>
Has_Element (Container, Last'Result)
and P.Get (Positions (Container), Last'Result) =
Length (Container));
function Last_Element (Container : List) return Element_Type with
Global => null,
Pre => not Is_Empty (Container),
Post =>
Last_Element'Result = M.Get (Model (Container), Length (Container));
function Next (Container : List; Position : Cursor) return Cursor with
Global => null,
Pre =>
Has_Element (Container, Position) or else Position = No_Element,
Contract_Cases =>
(Position = No_Element
or else P.Get (Positions (Container), Position) = Length (Container)
=>
Next'Result = No_Element,
others =>
Has_Element (Container, Next'Result)
and then P.Get (Positions (Container), Next'Result) =
P.Get (Positions (Container), Position) + 1);
procedure Next (Container : List; Position : in out Cursor) with
Global => null,
Pre =>
Has_Element (Container, Position) or else Position = No_Element,
Contract_Cases =>
(Position = No_Element
or else P.Get (Positions (Container), Position) = Length (Container)
=>
Position = No_Element,
others =>
Has_Element (Container, Position)
and then P.Get (Positions (Container), Position) =
P.Get (Positions (Container), Position'Old) + 1);
function Previous (Container : List; Position : Cursor) return Cursor with
Global => null,
Pre =>
Has_Element (Container, Position) or else Position = No_Element,
Contract_Cases =>
(Position = No_Element
or else P.Get (Positions (Container), Position) = 1
=>
Previous'Result = No_Element,
others =>
Has_Element (Container, Previous'Result)
and then P.Get (Positions (Container), Previous'Result) =
P.Get (Positions (Container), Position) - 1);
procedure Previous (Container : List; Position : in out Cursor) with
Global => null,
Pre =>
Has_Element (Container, Position) or else Position = No_Element,
Contract_Cases =>
(Position = No_Element
or else P.Get (Positions (Container), Position) = 1
=>
Position = No_Element,
others =>
Has_Element (Container, Position)
and then P.Get (Positions (Container), Position) =
P.Get (Positions (Container), Position'Old) - 1);
function Find
(Container : List;
Item : Element_Type;
Position : Cursor := No_Element) return Cursor
with
Global => null,
Pre =>
Has_Element (Container, Position) or else Position = No_Element,
Contract_Cases =>
-- If Item is not contained in Container after Position, Find returns
-- No_Element.
(not M.Contains
(Container => Model (Container),
Fst =>
(if Position = No_Element then
1
else
P.Get (Positions (Container), Position)),
Lst => Length (Container),
Item => Item)
=>
Find'Result = No_Element,
-- Otherwise, Find returns a valid cursor in Container
others =>
P.Has_Key (Positions (Container), Find'Result)
-- The element designated by the result of Find is Item
and Element
(Model (Container),
P.Get (Positions (Container), Find'Result)) = Item
-- The result of Find is located after Position
and (if Position /= No_Element then
P.Get (Positions (Container), Find'Result) >=
P.Get (Positions (Container), Position))
-- It is the first occurrence of Item in this slice
and not M.Contains
(Container => Model (Container),
Fst =>
(if Position = No_Element then
1
else
P.Get (Positions (Container), Position)),
Lst =>
P.Get (Positions (Container), Find'Result) - 1,
Item => Item));
function Reverse_Find
(Container : List;
Item : Element_Type;
Position : Cursor := No_Element) return Cursor
with
Global => null,
Pre =>
Has_Element (Container, Position) or else Position = No_Element,
Contract_Cases =>
-- If Item is not contained in Container before Position, Find returns
-- No_Element.
(not M.Contains
(Container => Model (Container),
Fst => 1,
Lst =>
(if Position = No_Element then
Length (Container)
else
P.Get (Positions (Container), Position)),
Item => Item)
=>
Reverse_Find'Result = No_Element,
-- Otherwise, Find returns a valid cursor in Container
others =>
P.Has_Key (Positions (Container), Reverse_Find'Result)
-- The element designated by the result of Find is Item
and Element
(Model (Container),
P.Get (Positions (Container), Reverse_Find'Result)) = Item
-- The result of Find is located before Position
and (if Position /= No_Element then
P.Get (Positions (Container), Reverse_Find'Result) <=
P.Get (Positions (Container), Position))
-- It is the last occurrence of Item in this slice
and not M.Contains
(Container => Model (Container),
Fst =>
P.Get (Positions (Container),
Reverse_Find'Result) + 1,
Lst =>
(if Position = No_Element then
Length (Container)
else
P.Get (Positions (Container), Position)),
Item => Item));
function Contains
(Container : List;
Item : Element_Type) return Boolean
with
Global => null,
Post =>
Contains'Result = M.Contains (Container => Model (Container),
Fst => 1,
Lst => Length (Container),
Item => Item);
function Has_Element
(Container : List;
Position : Cursor) return Boolean
with
Global => null,
Post =>
Has_Element'Result = P.Has_Key (Positions (Container), Position);
pragma Annotate (GNATprove, Inline_For_Proof, Has_Element);
generic
with function "<" (Left, Right : Element_Type) return Boolean is <>;
package Generic_Sorting with SPARK_Mode is
package Formal_Model with Ghost is
function M_Elements_Sorted (Container : M.Sequence) return Boolean
with
Global => null,
Post =>
M_Elements_Sorted'Result =
(for all I in 1 .. M.Length (Container) =>
(for all J in I .. M.Length (Container) =>
Element (Container, I) = Element (Container, J)
or Element (Container, I) < Element (Container, J)));
pragma Annotate (GNATprove, Inline_For_Proof, M_Elements_Sorted);
end Formal_Model;
use Formal_Model;
function Is_Sorted (Container : List) return Boolean with
Global => null,
Post => Is_Sorted'Result = M_Elements_Sorted (Model (Container));
procedure Sort (Container : in out List) with
Global => null,
Post =>
Length (Container) = Length (Container)'Old
and M_Elements_Sorted (Model (Container))
and M_Elements_Included
(Left => Model (Container)'Old,
L_Lst => Length (Container),
Right => Model (Container),
R_Lst => Length (Container))
and M_Elements_Included
(Left => Model (Container),
L_Lst => Length (Container),
Right => Model (Container)'Old,
R_Lst => Length (Container));
procedure Merge (Target : in out List; Source : in out List) with
-- Target and Source should not be aliased
Global => null,
Pre => Length (Source) <= Target.Capacity - Length (Target),
Post =>
Length (Target) = Length (Target)'Old + Length (Source)'Old
and Length (Source) = 0
and (if M_Elements_Sorted (Model (Target)'Old)
and M_Elements_Sorted (Model (Source)'Old)
then
M_Elements_Sorted (Model (Target)))
and M_Elements_Included
(Left => Model (Target)'Old,
L_Lst => Length (Target)'Old,
Right => Model (Target),
R_Lst => Length (Target))
and M_Elements_Included
(Left => Model (Source)'Old,
L_Lst => Length (Source)'Old,
Right => Model (Target),
R_Lst => Length (Target))
and M_Elements_In_Union
(Model (Target),
Model (Source)'Old,
Model (Target)'Old);
end Generic_Sorting;
private
pragma SPARK_Mode (Off);
type Node_Type is record
Prev : Count_Type'Base := -1;
Next : Count_Type;
Element : Element_Type;
end record;
function "=" (L, R : Node_Type) return Boolean is abstract;
type Node_Array is array (Count_Type range <>) of Node_Type;
function "=" (L, R : Node_Array) return Boolean is abstract;
type List (Capacity : Count_Type) is record
Free : Count_Type'Base := -1;
Length : Count_Type := 0;
First : Count_Type := 0;
Last : Count_Type := 0;
Nodes : Node_Array (1 .. Capacity);
end record;
Empty_List : constant List := (0, others => <>);
end Ada.Containers.Formal_Doubly_Linked_Lists;
|
------------------------------------------------------------------------------
-- --
-- Copyright (C) 2017, Universidad Politécnica de Madrid --
-- --
-- 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. --
-- --
------------------------------------------------------------------------------
-- Temperature sensor implementation.
-- This version is for a SunFounder DS18B20 sensor connected
-- to a RaspberryPi board through GPIO pin 4.
-- The board OS is Raspbian Linux. The following linux
-- commands must be executed in order to load the sensor driver
-- into the linux kernel:
-- $ sudo modprobe w1-gpio
-- $ sudo modprobe w1-therm
-- The sensor is read by reading the following file:
-- "/sys/bus/w1/devices/"&ID&"/w1_slave";
-- Where ID is a string with identity of the sensor (e.g. "28-0516a0ef7bff")
-- In order to find the ID of your device read the following file:
-- $ cat /sys/bus/w1/devices/w1_bus_master1/w1_master_slaves
-- If the file is not found, a simulated sensor is used instead to provide
-- the readings.
-- The implementation of this package is hardware- and operating system-
-- dependent. This version is for a SunFounder DS18B20 sensor connected
-- to a RaspberryPi board through GPIO pin 4.
-- The board OS is Raspbian Linux. The following linux
-- commands must be executed in order to load the sensor driver
-- into the linux kernel:
-- $ sudo modprobe w1-gpio
-- $ sudo modprobe w1-therm
with Measurements; use Measurements;
with Ada.Directories; use Ada.Directories;
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Strings.Fixed; use Ada.Strings.Fixed;
with Ada.Numerics; use Ada.Numerics;
with Ada.Numerics.Elementary_Functions; use Ada.Numerics.Elementary_Functions;
with Ada.Numerics.Float_Random; use Ada.Numerics.Float_Random;
package body Sensor is
-- DS18B20 id code and value path
ID : constant String := "28-0516a0ef7bff";
Path : constant String := "/sys/bus/w1/devices/"&ID&"/w1_slave";
File : File_Type;
HW : Boolean := False;
Noise : Generator;
-- get temperature value from hw sensor
procedure Get_HW (T : out Temperature) is
Line : String(1..80);
First, Last : Natural;
IT : Integer;
begin
Open (File, In_File, Path);
Get_Line (File, Line, Last);
Get_Line (File, Line, Last);
Close(File);
First := Index(Line, "t=") + 2;
IT := Integer'Value(Line(First..Last));
T := Temperature(Float(IT)/1000.0);
exception
when E : others =>
Put_Line("Sensor error");
Close(File);
end Get_HW;
-- get temperature value from simulator
procedure Get_Simulated (T : out Temperature) is
-- Parameters for simulation
T0 : Temperature := 25.0; -- Celsius
begin
T := T0 + Temperature(Random(Noise)) - 0.5;
end Get_Simulated;
---------
-- Get --
---------
procedure Get (T: out Temperature) is
begin
if HW then
Get_HW(T);
else
Get_Simulated(T);
end if;
end Get;
begin
if Exists (Path) then
HW := True;
pragma Debug(Put_Line("... using DS18B20 sensor"));
else
HW := False;
pragma Debug(Put_Line("... using simulated sensor"));
end if;
end Sensor;
|
-- A83A06A.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 A STATEMENT LABEL INSIDE A BLOCK BODY CAN BE THE
-- SAME AS A VARIABLE, CONSTANT, NAMED LITERAL, SUBPROGRAM,
-- ENUMERATION LITERAL, TYPE, OR PACKAGE DECLARED IN THE
-- ENCLOSING BODY.
-- RM 02/12/80
-- JBG 5/16/83
-- JBG 8/21/83
-- JRK 12/19/83
WITH REPORT; USE REPORT;
PROCEDURE A83A06A IS
LAB_VAR : INTEGER;
LAB_CONST : CONSTANT INTEGER := 12;
LAB_NAMEDLITERAL : CONSTANT := 13;
TYPE ENUM IS ( AA , BB , LAB_ENUMERAL );
TYPE LAB_TYPE IS NEW INTEGER;
PROCEDURE LAB_PROCEDURE IS
BEGIN
NULL;
END LAB_PROCEDURE;
FUNCTION LAB_FUNCTION RETURN INTEGER IS
BEGIN
RETURN 7;
END LAB_FUNCTION;
PACKAGE LAB_PACKAGE IS
INT : INTEGER;
END LAB_PACKAGE;
BEGIN
TEST ("A83A06A", "CHECK THAT STATEMENT LABELS INSIDE A BLOCK " &
"BODY CAN BE THE SAME AS IDENTIFIERS DECLARED "&
"OUTSIDE THE BODY");
LAB_BLOCK_1 : BEGIN NULL; END LAB_BLOCK_1;
LAB_LOOP_1 : LOOP EXIT; END LOOP LAB_LOOP_1;
BEGIN
<< LAB_VAR >> -- OK.
BEGIN NULL; END;
<< LAB_ENUMERAL >> NULL; -- OK.
<< LAB_PROCEDURE >> -- OK.
FOR I IN INTEGER LOOP
<< LAB_CONST >> NULL; -- OK.
<< LAB_TYPE >> NULL; -- OK.
<< LAB_FUNCTION >> EXIT; -- OK.
END LOOP;
<< LAB_NAMEDLITERAL >> NULL;
<< LAB_PACKAGE >> NULL;
END;
LAB_BLOCK_2 : -- OK.
BEGIN NULL; END LAB_BLOCK_2;
LAB_LOOP_2 : -- OK.
LOOP EXIT; END LOOP LAB_LOOP_2;
RESULT;
END A83A06A;
|
pragma License (Unrestricted);
-- implementation unit
with System;
private package Ada.Containers.Hash_Tables is
pragma Preelaborate;
Node_Size : constant := Standard'Address_Size + Hash_Type'Size * 2;
type Node;
type Node_Access is access Node;
type Node is limited record
Next : Node_Access;
Hash : Hash_Type;
Index : Hash_Type;
end record;
for Node'Size use Node_Size;
type Entry_List is limited record
First : Node_Access;
Previous : Node_Access;
end record;
type Entry_Array is array (Hash_Type range <>) of Entry_List;
type Table (Last_Index : Hash_Type) is limited record
First : Node_Access;
Entries : Entry_Array (0 .. Last_Index);
end record;
type Table_Access is access Table;
-- traversing
function First (Container : Table_Access) return Node_Access;
procedure Iterate (
Container : Table_Access;
Process : not null access procedure (Position : not null Node_Access));
function Is_Before (Before, After : Node_Access) return Boolean;
-- search
function Find (
Container : Table_Access;
Hash : Hash_Type;
Params : System.Address;
Equivalent : not null access function (
Position : not null Node_Access;
Params : System.Address)
return Boolean)
return Node_Access;
-- comparison
function Equivalent (
Left : Table_Access;
Left_Length : Count_Type;
Right : Table_Access;
Right_Length : Count_Type;
Equivalent : not null access function (
Left, Right : not null Node_Access)
return Boolean)
return Boolean;
function Overlap (
Left, Right : Table_Access;
Equivalent : not null access function (
Left, Right : not null Node_Access)
return Boolean)
return Boolean;
function Is_Subset (
Subset, Of_Set : Table_Access;
Equivalent : not null access function (
Left, Right : not null Node_Access)
return Boolean)
return Boolean;
-- management
function Capacity (Container : Table_Access) return Count_Type;
procedure Free (
Container : in out Table_Access;
Length : in out Count_Type;
Free : not null access procedure (Object : in out Node_Access));
procedure Copy (
Target : out Table_Access;
Length : out Count_Type;
Source : Table_Access;
New_Capacity : Count_Type;
Copy : not null access procedure (
Target : out Node_Access;
Source : not null Node_Access));
procedure Rebuild (
Container : in out Table_Access;
New_Capacity : Count_Type);
procedure Insert (
Container : in out Table_Access;
Length : in out Count_Type;
Hash : Hash_Type;
New_Item : not null Node_Access);
procedure Remove (
Container : Table_Access;
Length : in out Count_Type;
Item : not null Node_Access);
-- set operations
type Containing is (In_Only_Left, In_Only_Right, In_Both);
pragma Discard_Names (Containing);
type Filter_Type is array (Containing) of Boolean;
pragma Pack (Filter_Type);
pragma Suppress_Initialization (Filter_Type);
procedure Merge (
Target : in out Table_Access;
Length : in out Count_Type;
Source : Table_Access;
Source_Length : Count_Type;
Filter : Filter_Type;
Equivalent : not null access function (
Left, Right : not null Node_Access)
return Boolean;
Copy : access procedure (
Target : out Node_Access;
Source : not null Node_Access);
Free : access procedure (Object : in out Node_Access));
procedure Copying_Merge (
Target : out Table_Access;
Length : out Count_Type;
Left : Table_Access;
Left_Length : Count_Type;
Right : Table_Access;
Right_Length : Count_Type;
Filter : Filter_Type;
Equivalent : not null access function (
Left, Right : not null Node_Access)
return Boolean;
Copy : not null access procedure (
Target : out Node_Access;
Source : not null Node_Access));
end Ada.Containers.Hash_Tables;
|
with Algorithm; use Algorithm;
with Botstate; use Botstate;
with Ada.Command_Line; use Ada.Command_Line;
with Ada.Text_IO; use Ada.Text_IO;
procedure Main is
procedure Usage
is
begin
Put_Line ("./adaroombot <name of tty>");
end Usage;
My_Bot : Bot;
begin
if Argument_Count = 1 then
My_Bot.Init (TTY_Name => Argument(1),
Algo_Type => Pong);
My_Bot.Start;
My_Bot.Kill;
else
Usage;
return;
end if;
end Main;
|
with HAL.UART;
with Cortex_M.NVIC;
with RP2040_SVD.Interrupts;
with RP.Clock;
with RP.Device;
with RP.GPIO;
with RP.UART;
with Pico;
with Pico_UART_Interrupt_Handlers;
procedure Pico_Slave_Interrupt_Main is
subtype Buffer_Range is Integer range 1 .. 1;
UART : RP.UART.UART_Port renames RP.Device.UART_0;
UART_TX : RP.GPIO.GPIO_Point renames Pico.GP0;
UART_RX : RP.GPIO.GPIO_Point renames Pico.GP1;
UART_Buffer_T : HAL.UART.UART_Data_8b (Buffer_Range);
UART_Buffer_R : HAL.UART.UART_Data_8b (Buffer_Range);
UART_Status_T : HAL.UART.UART_Status;
UART_Status_R : HAL.UART.UART_Status;
use HAL;
begin
RP.Clock.Initialize (Pico.XOSC_Frequency);
RP.Clock.Enable (RP.Clock.PERI);
Pico.LED.Configure (RP.GPIO.Output);
RP.Device.Timer.Enable;
UART_TX.Configure (RP.GPIO.Output, RP.GPIO.Pull_Up, RP.GPIO.UART);
UART_RX.Configure (RP.GPIO.Input, RP.GPIO.Floating, RP.GPIO.UART);
UART.Configure
(Config =>
(Baud => 115_200,
Word_Size => 8,
Parity => False,
Stop_Bits => 1,
Enable_FIFOs => False,
others => <>));
-- UART.Enable_IRQ (RP.UART.Transmit);
UART.Enable_IRQ (RP.UART.Receive);
UART.Clear_IRQ (RP.UART.Transmit);
UART.Clear_IRQ (RP.UART.Receive);
Cortex_M.NVIC.Clear_Pending (IRQn => RP2040_SVD.Interrupts.UART0_Interrupt);
Cortex_M.NVIC.Enable_Interrupt (IRQn => RP2040_SVD.Interrupts.UART0_Interrupt);
loop
Pico.LED.Set;
loop
exit when Pico_UART_Interrupt_Handlers.UART0_Data_Received;
end loop;
Pico_UART_Interrupt_Handlers.UART0_Data_Received := False;
UART.Receive (Data => UART_Buffer_R,
Status => UART_Status_R,
Timeout => 0);
Pico.LED.Clear;
for Idx in Buffer_Range loop
UART_Buffer_T (Idx) := not UART_Buffer_R (Idx);
end loop;
Pico.LED.Set;
UART.Transmit (Data => UART_Buffer_T,
Status => UART_Status_T,
Timeout => 0);
Pico.LED.Clear;
end loop;
end Pico_Slave_Interrupt_Main;
|
with Interfaces; use Interfaces;
with Cpu; use Cpu;
with Types; use Types;
package Instruction with
SPARK_Mode => On
is
subtype Opcode is Word;
function Fetch (Cpu : Chip8) return Opcode
with Post => Fetch'Result = Shift_Left(Word(Cpu.Mem(Cpu.PC)), 8) +
Word(Cpu.Mem(Cpu.PC + 1));
procedure Execute (Cpu : in out Chip8; Op : Opcode);
procedure Handler_0 (Cpu : in out Chip8; Op : Opcode)
with Pre => (Op and 16#F000#) = 16#0000#,
Contract_Cases =>
(Op = 16#00E0# => (for all I in Cpu.Screen'Range(1) =>
(for all J in Cpu.Screen'Range(2) =>
Cpu.Screen(I, J) = False)),
Op = 16#00EE# => Cpu.Stack.Size = Cpu.Stack.Size'Old - 1,
Op /= 16#00E0# and then Op /= 16#00EE# => Cpu.PC = Op mod 16#1000#);
procedure Handler_1 (Cpu : in out Chip8; Op : Opcode)
with Pre => (Op and 16#F000#) = 16#1000#,
Post => Cpu.PC = Op mod 16#1000#;
procedure Handler_2 (Cpu : in out Chip8; Op : Opcode)
with Pre => (Op and 16#F000#) = 16#2000#,
Post => Cpu.PC = Op mod 16#1000#
and then Cpu.Stack.Arr(Cpu.Stack.Size'Old) = Cpu.PC'Old;
procedure Handler_3 (Cpu : in out Chip8; Op : Opcode)
with Pre => (Op and 16#F000#) = 16#3000#,
Post => Cpu.PC >= Cpu.PC'Old + 2,
Contract_Cases =>
(Cpu.Regs(Integer(Shift_Right(Op, 8) and 16#F#)) = Byte(Op mod 16#100#)
=> Cpu.PC = Cpu.PC'Old + 4,
Cpu.Regs(Integer(Shift_Right(Op, 8) and 16#F#)) /= Byte(Op mod 16#100#)
=> Cpu.PC = Cpu.PC'Old + 2);
procedure Handler_4 (Cpu : in out Chip8; Op : Opcode)
with Pre => (Op and 16#F000#) = 16#4000#,
Contract_Cases =>
(Cpu.Regs(Integer(Shift_Right(Op, 8) and 16#F#)) /= Byte(Op mod 16#100#)
=> Cpu.PC = Cpu.PC'Old + 4,
Cpu.Regs(Integer(Shift_Right(Op, 8) and 16#F#)) = Byte(Op mod 16#100#)
=> Cpu.PC = Cpu.PC'Old + 2);
procedure Handler_5 (Cpu : in out Chip8; Op : Opcode)
with Pre => (Op and 16#F000#) = 16#5000#,
Post => Cpu.PC >= Cpu.PC'Old + 2,
Contract_Cases =>
(Cpu.Regs(Integer(Shift_Right(Op, 8) and 16#F#)) =
Cpu.Regs(Integer(Shift_Right(Op, 4) and 16#F#)) =>
Cpu.PC = Cpu.PC'Old + 4,
Cpu.Regs(Integer(Shift_Right(Op, 8) and 16#F#)) /=
Cpu.Regs(Integer(Shift_Right(Op, 4) and 16#F#)) =>
Cpu.PC = Cpu.PC'Old + 2);
procedure Handler_6 (Cpu : in out Chip8; Op : Opcode)
with Pre => (Op and 16#F000#) = 16#6000#,
Post => Cpu.Regs(Integer(Shift_Right(Op, 8) and 16#F#)) =
Byte(Op mod 16#100#) and then Cpu.PC = Cpu.PC'Old + 2;
procedure Handler_7 (Cpu : in out Chip8; Op : Opcode)
with Pre => (Op and 16#F000#) = 16#7000#,
Post => Cpu.Regs(Integer(Shift_Right(Op, 8) and 16#F#)) =
Cpu.Regs'Old(Integer(Shift_Right(Op, 8) and 16#F#)) + Byte(Op mod 16#100#)
and then Cpu.PC = Cpu.PC'Old + 2;
procedure Handler_8 (Cpu : in out Chip8; Op : Opcode)
with Pre => (Op and 16#F000#) = 16#8000# and then
(Op mod 16#10# = 0 or Op mod 16#10# = 1 or Op mod 16#10# = 2
or Op mod 16#10# = 3 or Op mod 16#10# = 4 or Op mod 16#10# = 5
or Op mod 16#10# = 6 or Op mod 16#10# = 7 or Op mod 16#10# = 16#E#),
Post => Cpu.PC = Cpu.PC'Old + 2;
procedure Handler_9 (Cpu : in out Chip8; Op : Opcode)
with Pre => (Op and 16#F000#) = 16#9000#,
Post => Cpu.PC >= Cpu.PC'Old + 2,
Contract_Cases =>
(Cpu.Regs(Integer(Shift_Right(Op, 8) and 16#F#)) /=
Cpu.Regs(Integer(Shift_Right(Op, 4) and 16#F#)) =>
Cpu.PC = Cpu.PC'Old + 4,
Cpu.Regs(Integer(Shift_Right(Op, 8) and 16#F#)) =
Cpu.Regs(Integer(Shift_Right(Op, 4) and 16#F#)) =>
Cpu.PC = Cpu.PC'Old + 2);
procedure Handler_A (Cpu : in out Chip8; Op : Opcode)
with Pre => (Op and 16#F000#) = 16#A000#,
Post => Cpu.I = Op mod 16#1000# and then Cpu.PC = Cpu.PC'Old + 2;
procedure Handler_B (Cpu : in out Chip8; Op : Opcode)
with Pre => (Op and 16#F000#) = 16#B000#,
Post => Cpu.PC = (Op mod 16#1000#) + Word(Cpu.Regs(0));
procedure Handler_C (Cpu : in out Chip8; Op : Opcode)
with Pre => (Op and 16#F000#) = 16#C000#,
Post => Cpu.PC = Cpu.PC'Old + 2;
procedure Handler_D (Cpu : in out Chip8; Op : Opcode)
with Pre => (Op and 16#F000#) = 16#D000#,
Post => Cpu.PC = Cpu.PC'Old + 2;
procedure Handler_E (Cpu : in out Chip8; Op : Opcode)
with Pre => (Op and 16#F000#) = 16#E000#
and then (Op mod 16#100# = 16#9E# or Op mod 16#100# = 16#A1#),
Post => Cpu.PC >= Cpu.PC'Old + 2 and then
Cpu.Keys(Integer(Cpu.Regs(Integer(Shift_Right(Op, 8) and 16#F#)))) = False;
procedure Handler_F (Cpu : in out Chip8; Op : Opcode)
with Pre => (Op and 16#F000#) = 16#F000#
and then (Op mod 16#100# = 16#07# or Op mod 16#100# = 16#0A#
or Op mod 16#100# = 16#15# or Op mod 16#100# = 16#18#
or Op mod 16#100# = 16#1E# or Op mod 16#100# = 16#29#
or Op mod 16#100# = 16#33# or Op mod 16#100# = 16#55#
or Op mod 16#100# = 16#65#),
Contract_Cases =>
(Op mod 16#100# = 16#07# =>
Cpu.Regs(Integer(Shift_Right(Op, 8) and 16#F#)) = Cpu.Delay_Timer,
Op mod 16#100# = 16#0A# => True,
Op mod 16#100# = 16#15# => Cpu.Delay_Timer =
Cpu.Regs(Integer(Shift_Right(Op, 8) and 16#F#)),
Op mod 16#100# = 16#18# => Cpu.Sound_Timer =
Cpu.Regs(Integer(Shift_Right(Op, 8) and 16#F#)),
Op mod 16#100# = 16#1E# => Cpu.I = Cpu.I'Old +
Word(Cpu.Regs(Integer(Shift_Right(Op, 8) and 16#F#))),
Op mod 16#100# = 16#29# => Cpu.I =
Word(Cpu.Regs(Integer(Shift_Right(Op, 8) and 16#F#))) * 5,
Op mod 16#100# = 16#33# => Cpu.Mem(Cpu.I) =
Cpu.Regs(Integer(Shift_Right(Op, 8) and 16#F#)) / 100
and then Cpu.Mem(Cpu.I + 1) =
Cpu.Regs(Integer(Shift_Right(Op, 8) and 16#F#)) / 10 mod 10
and then Cpu.Mem(Cpu.I + 2) =
Cpu.Regs(Integer(Shift_Right(Op, 8) and 16#F#)) mod 10,
Op mod 16#100# = 16#55# => True,
Op mod 16#100# = 16#65# => True);
type Instr_Handler is access procedure (Cpu : in out Chip8; Op : Opcode);
type Instr_Handler_Array is array (0 .. 15) of Instr_Handler;
Instr_Handlers : constant Instr_Handler_Array := (Handler_0'Access,
Handler_1'Access,
Handler_2'Access,
Handler_3'Access,
Handler_4'Access,
Handler_5'Access,
Handler_6'Access,
Handler_7'Access,
Handler_8'Access,
Handler_9'Access,
Handler_A'Access,
Handler_B'Access,
Handler_C'Access,
Handler_D'Access,
Handler_E'Access,
Handler_F'Access);
end Instruction;
|
with Ada.Text_IO; use Ada.Text_IO;
package body Father.Son is
function "+" (Left : Son_Type; Right : Father_Type) return Father_Type is
T : Father_Type := Right;
begin
Put_Line ("using this");
Father_What (T);
return Father_Type (3 * Integer (Left) + Integer (T));
end "+";
function "+" (Left : Sonic_Type; Right : Father_Type) return Integer is
begin
Put_Line ("sonic this");
return 2 * Integer (Left) + Integer (Right) - 1;
end "+";
end Father.Son;
|
package Raspio.GPIO.Encoder is
Encoder_Size : constant := 2;
type Encoder_Pins is array (1 .. Encoder_Size) of Pin_Type;
type Encoder_Pin_Values is array (1 .. Encoder_Size) of Pin_State;
type Encoder_Type is limited private;
type Diff_Type is range -1 .. 1;
function Create
(Pin_A : Pin_ID_Type; Pin_B : Pin_ID_Type;
Internal_Resistor : Internal_Resistor_Type) return Encoder_Type;
function Update (Encoder : in out Encoder_Type) return Diff_Type;
private
type Encoder_Type is record
Pins : Encoder_Pins;
Values : Encoder_Pin_Values;
end record;
end Raspio.GPIO.Encoder;
|
------------------------------------------------------------------------------
-- --
-- GNAT LIBRARY COMPONENTS --
-- --
-- A D A . C O N T A I N E R S . F O R M A L _ H A S H E D _ S E T S --
-- --
-- S p e c --
-- --
-- Copyright (C) 2004-2021, Free Software Foundation, Inc. --
-- --
-- This specification is derived from the Ada Reference Manual for use with --
-- GNAT. The copyright notice above, and the license provisions that follow --
-- apply solely to the contents of the part following the private keyword. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. --
-- --
-- --
-- --
-- --
-- --
-- You should have received a copy of the GNU General Public License and --
-- a copy of the GCC Runtime Library Exception along with this program; --
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
-- <http://www.gnu.org/licenses/>. --
------------------------------------------------------------------------------
-- This spec is derived from package Ada.Containers.Bounded_Hashed_Sets in the
-- Ada 2012 RM. The modifications are meant to facilitate formal proofs by
-- making it easier to express properties, and by making the specification of
-- this unit compatible with SPARK 2014. Note that the API of this unit may be
-- subject to incompatible changes as SPARK 2014 evolves.
-- The modifications are:
-- A parameter for the container is added to every function reading the
-- content of a container: Element, Next, Query_Element, Has_Element, Key,
-- Iterate, Equivalent_Elements. This change is motivated by the need to
-- have cursors which are valid on different containers (typically a
-- container C and its previous version C'Old) for expressing properties,
-- which is not possible if cursors encapsulate an access to the underlying
-- container.
with Ada.Containers.Functional_Maps;
with Ada.Containers.Functional_Sets;
with Ada.Containers.Functional_Vectors;
private with Ada.Containers.Hash_Tables;
generic
type Element_Type is private;
with function Hash (Element : Element_Type) return Hash_Type;
with function Equivalent_Elements
(Left : Element_Type;
Right : Element_Type) return Boolean is "=";
package Ada.Containers.Formal_Hashed_Sets with
SPARK_Mode
is
-- Contracts in this unit are meant for analysis only, not for run-time
-- checking.
pragma Assertion_Policy (Pre => Ignore);
pragma Assertion_Policy (Post => Ignore);
pragma Annotate (CodePeer, Skip_Analysis);
type Set (Capacity : Count_Type; Modulus : Hash_Type) is private with
Iterable => (First => First,
Next => Next,
Has_Element => Has_Element,
Element => Element),
Default_Initial_Condition => Is_Empty (Set);
pragma Preelaborable_Initialization (Set);
type Cursor is record
Node : Count_Type;
end record;
No_Element : constant Cursor := (Node => 0);
function Length (Container : Set) return Count_Type with
Global => null,
Post => Length'Result <= Container.Capacity;
pragma Unevaluated_Use_Of_Old (Allow);
package Formal_Model with Ghost is
subtype Positive_Count_Type is Count_Type range 1 .. Count_Type'Last;
package M is new Ada.Containers.Functional_Sets
(Element_Type => Element_Type,
Equivalent_Elements => Equivalent_Elements);
function "="
(Left : M.Set;
Right : M.Set) return Boolean renames M."=";
function "<="
(Left : M.Set;
Right : M.Set) return Boolean renames M."<=";
package E is new Ada.Containers.Functional_Vectors
(Element_Type => Element_Type,
Index_Type => Positive_Count_Type);
function "="
(Left : E.Sequence;
Right : E.Sequence) return Boolean renames E."=";
function "<"
(Left : E.Sequence;
Right : E.Sequence) return Boolean renames E."<";
function "<="
(Left : E.Sequence;
Right : E.Sequence) return Boolean renames E."<=";
function Find
(Container : E.Sequence;
Item : Element_Type) return Count_Type
-- Search for Item in Container
with
Global => null,
Post =>
(if Find'Result > 0 then
Find'Result <= E.Length (Container)
and Equivalent_Elements
(Item, E.Get (Container, Find'Result)));
function E_Elements_Included
(Left : E.Sequence;
Right : E.Sequence) return Boolean
-- The elements of Left are contained in Right
with
Global => null,
Post =>
E_Elements_Included'Result =
(for all I in 1 .. E.Length (Left) =>
Find (Right, E.Get (Left, I)) > 0
and then E.Get (Right, Find (Right, E.Get (Left, I))) =
E.Get (Left, I));
pragma Annotate (GNATprove, Inline_For_Proof, E_Elements_Included);
function E_Elements_Included
(Left : E.Sequence;
Model : M.Set;
Right : E.Sequence) return Boolean
-- The elements of Container contained in Model are in Right
with
Global => null,
Post =>
E_Elements_Included'Result =
(for all I in 1 .. E.Length (Left) =>
(if M.Contains (Model, E.Get (Left, I)) then
Find (Right, E.Get (Left, I)) > 0
and then E.Get (Right, Find (Right, E.Get (Left, I))) =
E.Get (Left, I)));
pragma Annotate (GNATprove, Inline_For_Proof, E_Elements_Included);
function E_Elements_Included
(Container : E.Sequence;
Model : M.Set;
Left : E.Sequence;
Right : E.Sequence) return Boolean
-- The elements of Container contained in Model are in Left and others
-- are in Right.
with
Global => null,
Post =>
E_Elements_Included'Result =
(for all I in 1 .. E.Length (Container) =>
(if M.Contains (Model, E.Get (Container, I)) then
Find (Left, E.Get (Container, I)) > 0
and then E.Get (Left, Find (Left, E.Get (Container, I))) =
E.Get (Container, I)
else
Find (Right, E.Get (Container, I)) > 0
and then E.Get
(Right, Find (Right, E.Get (Container, I))) =
E.Get (Container, I)));
pragma Annotate (GNATprove, Inline_For_Proof, E_Elements_Included);
package P is new Ada.Containers.Functional_Maps
(Key_Type => Cursor,
Element_Type => Positive_Count_Type,
Equivalent_Keys => "=",
Enable_Handling_Of_Equivalence => False);
function "="
(Left : P.Map;
Right : P.Map) return Boolean renames P."=";
function "<="
(Left : P.Map;
Right : P.Map) return Boolean renames P."<=";
function Mapping_Preserved
(E_Left : E.Sequence;
E_Right : E.Sequence;
P_Left : P.Map;
P_Right : P.Map) return Boolean
with
Ghost,
Global => null,
Post =>
(if Mapping_Preserved'Result then
-- Right contains all the cursors of Left
P.Keys_Included (P_Left, P_Right)
-- Right contains all the elements of Left
and E_Elements_Included (E_Left, E_Right)
-- Mappings from cursors to elements induced by E_Left, P_Left
-- and E_Right, P_Right are the same.
and (for all C of P_Left =>
E.Get (E_Left, P.Get (P_Left, C)) =
E.Get (E_Right, P.Get (P_Right, C))));
function Mapping_Preserved_Except
(E_Left : E.Sequence;
E_Right : E.Sequence;
P_Left : P.Map;
P_Right : P.Map;
Position : Cursor) return Boolean
with
Ghost,
Global => null,
Post =>
(if Mapping_Preserved_Except'Result then
-- Right contains all the cursors of Left
P.Keys_Included (P_Left, P_Right)
-- Mappings from cursors to elements induced by E_Left, P_Left
-- and E_Right, P_Right are the same except for Position.
and (for all C of P_Left =>
(if C /= Position then
E.Get (E_Left, P.Get (P_Left, C)) =
E.Get (E_Right, P.Get (P_Right, C)))));
function Model (Container : Set) return M.Set with
-- The high-level model of a set is a set of elements. Neither cursors
-- nor order of elements are represented in this model. Elements are
-- modeled up to equivalence.
Ghost,
Global => null,
Post => M.Length (Model'Result) = Length (Container);
function Elements (Container : Set) return E.Sequence with
-- The Elements sequence represents the underlying list structure of
-- sets that is used for iteration. It stores the actual values of
-- elements in the set. It does not model cursors.
Ghost,
Global => null,
Post =>
E.Length (Elements'Result) = Length (Container)
-- It only contains keys contained in Model
and (for all Item of Elements'Result =>
M.Contains (Model (Container), Item))
-- It contains all the elements contained in Model
and (for all Item of Model (Container) =>
(Find (Elements'Result, Item) > 0
and then Equivalent_Elements
(E.Get (Elements'Result,
Find (Elements'Result, Item)),
Item)))
-- It has no duplicate
and (for all I in 1 .. Length (Container) =>
Find (Elements'Result, E.Get (Elements'Result, I)) = I)
and (for all I in 1 .. Length (Container) =>
(for all J in 1 .. Length (Container) =>
(if Equivalent_Elements
(E.Get (Elements'Result, I),
E.Get (Elements'Result, J))
then I = J)));
pragma Annotate (GNATprove, Iterable_For_Proof, "Model", Elements);
function Positions (Container : Set) return P.Map with
-- The Positions map is used to model cursors. It only contains valid
-- cursors and maps them to their position in the container.
Ghost,
Global => null,
Post =>
not P.Has_Key (Positions'Result, No_Element)
-- Positions of cursors are smaller than the container's length
and then
(for all I of Positions'Result =>
P.Get (Positions'Result, I) in 1 .. Length (Container)
-- No two cursors have the same position. Note that we do not
-- state that there is a cursor in the map for each position, as
-- it is rarely needed.
and then
(for all J of Positions'Result =>
(if P.Get (Positions'Result, I) = P.Get (Positions'Result, J)
then I = J)));
procedure Lift_Abstraction_Level (Container : Set) with
-- Lift_Abstraction_Level is a ghost procedure that does nothing but
-- assume that we can access the same elements by iterating over
-- positions or cursors.
-- This information is not generally useful except when switching from
-- a low-level, cursor-aware view of a container, to a high-level,
-- position-based view.
Ghost,
Global => null,
Post =>
(for all Item of Elements (Container) =>
(for some I of Positions (Container) =>
E.Get (Elements (Container), P.Get (Positions (Container), I)) =
Item));
function Contains
(C : M.Set;
K : Element_Type) return Boolean renames M.Contains;
-- To improve readability of contracts, we rename the function used to
-- search for an element in the model to Contains.
end Formal_Model;
use Formal_Model;
Empty_Set : constant Set;
function "=" (Left, Right : Set) return Boolean with
Global => null,
Post =>
"="'Result =
(Length (Left) = Length (Right)
and E_Elements_Included (Elements (Left), Elements (Right)))
and
"="'Result =
(E_Elements_Included (Elements (Left), Elements (Right))
and E_Elements_Included (Elements (Right), Elements (Left)));
-- For each element in Left, set equality attempts to find the equal
-- element in Right; if a search fails, then set equality immediately
-- returns False. The search works by calling Hash to find the bucket in
-- the Right set that corresponds to the Left element. If the bucket is
-- non-empty, the search calls the generic formal element equality operator
-- to compare the element (in Left) to the element of each node in the
-- bucket (in Right); the search terminates when a matching node in the
-- bucket is found, or the nodes in the bucket are exhausted. (Note that
-- element equality is called here, not Equivalent_Elements. Set equality
-- is the only operation in which element equality is used. Compare set
-- equality to Equivalent_Sets, which does call Equivalent_Elements.)
function Equivalent_Sets (Left, Right : Set) return Boolean with
Global => null,
Post => Equivalent_Sets'Result = (Model (Left) = Model (Right));
-- Similar to set equality, with the difference that the element in Left is
-- compared to the elements in Right using the generic formal
-- Equivalent_Elements operation instead of element equality.
function To_Set (New_Item : Element_Type) return Set with
Global => null,
Post =>
M.Is_Singleton (Model (To_Set'Result), New_Item)
and Length (To_Set'Result) = 1
and E.Get (Elements (To_Set'Result), 1) = New_Item;
-- Constructs a singleton set comprising New_Element. To_Set calls Hash to
-- determine the bucket for New_Item.
function Capacity (Container : Set) return Count_Type with
Global => null,
Post => Capacity'Result = Container.Capacity;
-- Returns the current capacity of the set. Capacity is the maximum length
-- before which rehashing in guaranteed not to occur.
procedure Reserve_Capacity
(Container : in out Set;
Capacity : Count_Type)
with
Global => null,
Pre => Capacity <= Container.Capacity,
Post =>
Model (Container) = Model (Container)'Old
and Length (Container)'Old = Length (Container)
-- Actual elements are preserved
and E_Elements_Included
(Elements (Container), Elements (Container)'Old)
and E_Elements_Included
(Elements (Container)'Old, Elements (Container));
-- If the value of the Capacity actual parameter is less or equal to
-- Container.Capacity, then the operation has no effect. Otherwise it
-- raises Capacity_Error (as no expansion of capacity is possible for a
-- bounded form).
function Is_Empty (Container : Set) return Boolean with
Global => null,
Post => Is_Empty'Result = (Length (Container) = 0);
-- Equivalent to Length (Container) = 0
procedure Clear (Container : in out Set) with
Global => null,
Post => Length (Container) = 0 and M.Is_Empty (Model (Container));
-- Removes all of the items from the set. This will deallocate all memory
-- associated with this set.
procedure Assign (Target : in out Set; Source : Set) with
Global => null,
Pre => Target.Capacity >= Length (Source),
Post =>
Model (Target) = Model (Source)
and Length (Target) = Length (Source)
-- Actual elements are preserved
and E_Elements_Included (Elements (Target), Elements (Source))
and E_Elements_Included (Elements (Source), Elements (Target));
-- If Target denotes the same object as Source, then the operation has no
-- effect. If the Target capacity is less than the Source length, then
-- Assign raises Capacity_Error. Otherwise, Assign clears Target and then
-- copies the (active) elements from Source to Target.
function Copy
(Source : Set;
Capacity : Count_Type := 0) return Set
with
Global => null,
Pre => Capacity = 0 or else Capacity >= Source.Capacity,
Post =>
Model (Copy'Result) = Model (Source)
and Elements (Copy'Result) = Elements (Source)
and Positions (Copy'Result) = Positions (Source)
and (if Capacity = 0 then
Copy'Result.Capacity = Source.Capacity
else
Copy'Result.Capacity = Capacity);
-- Constructs a new set object whose elements correspond to Source. If the
-- Capacity parameter is 0, then the capacity of the result is the same as
-- the length of Source. If the Capacity parameter is equal or greater than
-- the length of Source, then the capacity of the result is the specified
-- value. Otherwise, Copy raises Capacity_Error. If the Modulus parameter
-- is 0, then the modulus of the result is the value returned by a call to
-- Default_Modulus with the capacity parameter determined as above;
-- otherwise the modulus of the result is the specified value.
function Element
(Container : Set;
Position : Cursor) return Element_Type
with
Global => null,
Pre => Has_Element (Container, Position),
Post =>
Element'Result =
E.Get (Elements (Container), P.Get (Positions (Container), Position));
pragma Annotate (GNATprove, Inline_For_Proof, Element);
procedure Replace_Element
(Container : in out Set;
Position : Cursor;
New_Item : Element_Type)
with
Global => null,
Pre => Has_Element (Container, Position),
Post =>
Length (Container) = Length (Container)'Old
-- Position now maps to New_Item
and Element (Container, Position) = New_Item
-- New_Item is contained in Container
and Contains (Model (Container), New_Item)
-- Other elements are preserved
and M.Included_Except
(Model (Container)'Old,
Model (Container),
Element (Container, Position)'Old)
and M.Included_Except
(Model (Container),
Model (Container)'Old,
New_Item)
-- Mapping from cursors to elements is preserved
and Mapping_Preserved_Except
(E_Left => Elements (Container)'Old,
E_Right => Elements (Container),
P_Left => Positions (Container)'Old,
P_Right => Positions (Container),
Position => Position)
and Positions (Container) = Positions (Container)'Old;
function Constant_Reference
(Container : aliased Set;
Position : Cursor) return not null access constant Element_Type
with
Global => null,
Pre => Has_Element (Container, Position),
Post =>
Constant_Reference'Result.all =
E.Get (Elements (Container), P.Get (Positions (Container), Position));
procedure Move (Target : in out Set; Source : in out Set) with
Global => null,
Pre => Target.Capacity >= Length (Source),
Post =>
Length (Source) = 0
and Model (Target) = Model (Source)'Old
and Length (Target) = Length (Source)'Old
-- Actual elements are preserved
and E_Elements_Included (Elements (Target), Elements (Source)'Old)
and E_Elements_Included (Elements (Source)'Old, Elements (Target));
-- Clears Target (if it's not empty), and then moves (not copies) the
-- buckets array and nodes from Source to Target.
procedure Insert
(Container : in out Set;
New_Item : Element_Type;
Position : out Cursor;
Inserted : out Boolean)
with
Global => null,
Pre =>
Length (Container) < Container.Capacity
or Contains (Container, New_Item),
Post =>
Contains (Container, New_Item)
and Has_Element (Container, Position)
and Equivalent_Elements (Element (Container, Position), New_Item),
Contract_Cases =>
-- If New_Item is already in Container, it is not modified and Inserted
-- is set to False.
(Contains (Container, New_Item) =>
not Inserted
and Model (Container) = Model (Container)'Old
and Elements (Container) = Elements (Container)'Old
and Positions (Container) = Positions (Container)'Old,
-- Otherwise, New_Item is inserted in Container and Inserted is set to
-- True.
others =>
Inserted
and Length (Container) = Length (Container)'Old + 1
-- Position now maps to New_Item
and Element (Container, Position) = New_Item
-- Other elements are preserved
and Model (Container)'Old <= Model (Container)
and M.Included_Except
(Model (Container),
Model (Container)'Old,
New_Item)
-- Mapping from cursors to elements is preserved
and Mapping_Preserved
(E_Left => Elements (Container)'Old,
E_Right => Elements (Container),
P_Left => Positions (Container)'Old,
P_Right => Positions (Container))
and P.Keys_Included_Except
(Positions (Container),
Positions (Container)'Old,
Position));
-- Conditionally inserts New_Item into the set. If New_Item is already in
-- the set, then Inserted returns False and Position designates the node
-- containing the existing element (which is not modified). If New_Item is
-- not already in the set, then Inserted returns True and Position
-- designates the newly-inserted node containing New_Item. The search for
-- an existing element works as follows. Hash is called to determine
-- New_Item's bucket; if the bucket is non-empty, then Equivalent_Elements
-- is called to compare New_Item to the element of each node in that
-- bucket. If the bucket is empty, or there were no equivalent elements in
-- the bucket, the search "fails" and the New_Item is inserted in the set
-- (and Inserted returns True); otherwise, the search "succeeds" (and
-- Inserted returns False).
procedure Insert (Container : in out Set; New_Item : Element_Type) with
Global => null,
Pre => Length (Container) < Container.Capacity
and then (not Contains (Container, New_Item)),
Post =>
Length (Container) = Length (Container)'Old + 1
and Contains (Container, New_Item)
and Element (Container, Find (Container, New_Item)) = New_Item
-- Other elements are preserved
and Model (Container)'Old <= Model (Container)
and M.Included_Except
(Model (Container),
Model (Container)'Old,
New_Item)
-- Mapping from cursors to elements is preserved
and Mapping_Preserved
(E_Left => Elements (Container)'Old,
E_Right => Elements (Container),
P_Left => Positions (Container)'Old,
P_Right => Positions (Container))
and P.Keys_Included_Except
(Positions (Container),
Positions (Container)'Old,
Find (Container, New_Item));
-- Attempts to insert New_Item into the set, performing the usual insertion
-- search (which involves calling both Hash and Equivalent_Elements); if
-- the search succeeds (New_Item is equivalent to an element already in the
-- set, and so was not inserted), then this operation raises
-- Constraint_Error. (This version of Insert is similar to Replace, but
-- having the opposite exception behavior. It is intended for use when you
-- want to assert that the item is not already in the set.)
procedure Include (Container : in out Set; New_Item : Element_Type) with
Global => null,
Pre =>
Length (Container) < Container.Capacity
or Contains (Container, New_Item),
Post =>
Contains (Container, New_Item)
and Element (Container, Find (Container, New_Item)) = New_Item,
Contract_Cases =>
-- If an element equivalent to New_Item is already in Container, it is
-- replaced by New_Item.
(Contains (Container, New_Item) =>
-- Elements are preserved modulo equivalence
Model (Container) = Model (Container)'Old
-- Cursors are preserved
and Positions (Container) = Positions (Container)'Old
-- The actual value of other elements is preserved
and E.Equal_Except
(Elements (Container)'Old,
Elements (Container),
P.Get (Positions (Container), Find (Container, New_Item))),
-- Otherwise, New_Item is inserted in Container
others =>
Length (Container) = Length (Container)'Old + 1
-- Other elements are preserved
and Model (Container)'Old <= Model (Container)
and M.Included_Except
(Model (Container),
Model (Container)'Old,
New_Item)
-- Mapping from cursors to elements is preserved
and Mapping_Preserved
(E_Left => Elements (Container)'Old,
E_Right => Elements (Container),
P_Left => Positions (Container)'Old,
P_Right => Positions (Container))
and P.Keys_Included_Except
(Positions (Container),
Positions (Container)'Old,
Find (Container, New_Item)));
-- Attempts to insert New_Item into the set. If an element equivalent to
-- New_Item is already in the set (the insertion search succeeded, and
-- hence New_Item was not inserted), then the value of New_Item is assigned
-- to the existing element. (This insertion operation only raises an
-- exception if cursor tampering occurs. It is intended for use when you
-- want to insert the item in the set, and you don't care whether an
-- equivalent element is already present.)
procedure Replace (Container : in out Set; New_Item : Element_Type) with
Global => null,
Pre => Contains (Container, New_Item),
Post =>
-- Elements are preserved modulo equivalence
Model (Container) = Model (Container)'Old
and Contains (Container, New_Item)
-- Cursors are preserved
and Positions (Container) = Positions (Container)'Old
-- The element equivalent to New_Item in Container is replaced by
-- New_Item.
and Element (Container, Find (Container, New_Item)) = New_Item
and E.Equal_Except
(Elements (Container)'Old,
Elements (Container),
P.Get (Positions (Container), Find (Container, New_Item)));
-- Searches for New_Item in the set; if the search fails (because an
-- equivalent element was not in the set), then it raises
-- Constraint_Error. Otherwise, the existing element is assigned the value
-- New_Item. (This is similar to Insert, but with the opposite exception
-- behavior. It is intended for use when you want to assert that the item
-- is already in the set.)
procedure Exclude (Container : in out Set; Item : Element_Type) with
Global => null,
Post => not Contains (Container, Item),
Contract_Cases =>
-- If Item is not in Container, nothing is changed
(not Contains (Container, Item) =>
Model (Container) = Model (Container)'Old
and Elements (Container) = Elements (Container)'Old
and Positions (Container) = Positions (Container)'Old,
-- Otherwise, Item is removed from Container
others =>
Length (Container) = Length (Container)'Old - 1
-- Other elements are preserved
and Model (Container) <= Model (Container)'Old
and M.Included_Except
(Model (Container)'Old,
Model (Container),
Item)
-- Mapping from cursors to elements is preserved
and Mapping_Preserved
(E_Left => Elements (Container),
E_Right => Elements (Container)'Old,
P_Left => Positions (Container),
P_Right => Positions (Container)'Old)
and P.Keys_Included_Except
(Positions (Container)'Old,
Positions (Container),
Find (Container, Item)'Old));
-- Searches for Item in the set, and if found, removes its node from the
-- set and then deallocates it. The search works as follows. The operation
-- calls Hash to determine the item's bucket; if the bucket is not empty,
-- it calls Equivalent_Elements to compare Item to the element of each node
-- in the bucket. (This is the deletion analog of Include. It is intended
-- for use when you want to remove the item from the set, but don't care
-- whether the item is already in the set.)
procedure Delete (Container : in out Set; Item : Element_Type) with
Global => null,
Pre => Contains (Container, Item),
Post =>
Length (Container) = Length (Container)'Old - 1
-- Item is no longer in Container
and not Contains (Container, Item)
-- Other elements are preserved
and Model (Container) <= Model (Container)'Old
and M.Included_Except
(Model (Container)'Old,
Model (Container),
Item)
-- Mapping from cursors to elements is preserved
and Mapping_Preserved
(E_Left => Elements (Container),
E_Right => Elements (Container)'Old,
P_Left => Positions (Container),
P_Right => Positions (Container)'Old)
and P.Keys_Included_Except
(Positions (Container)'Old,
Positions (Container),
Find (Container, Item)'Old);
-- Searches for Item in the set (which involves calling both Hash and
-- Equivalent_Elements). If the search fails, then the operation raises
-- Constraint_Error. Otherwise it removes the node from the set and then
-- deallocates it. (This is the deletion analog of non-conditional
-- Insert. It is intended for use when you want to assert that the item is
-- already in the set.)
procedure Delete (Container : in out Set; Position : in out Cursor) with
Global => null,
Depends => (Container =>+ Position, Position => null),
Pre => Has_Element (Container, Position),
Post =>
Position = No_Element
and Length (Container) = Length (Container)'Old - 1
-- The element at position Position is no longer in Container
and not Contains (Container, Element (Container, Position)'Old)
and not P.Has_Key (Positions (Container), Position'Old)
-- Other elements are preserved
and Model (Container) <= Model (Container)'Old
and M.Included_Except
(Model (Container)'Old,
Model (Container),
Element (Container, Position)'Old)
-- Mapping from cursors to elements is preserved
and Mapping_Preserved
(E_Left => Elements (Container),
E_Right => Elements (Container)'Old,
P_Left => Positions (Container),
P_Right => Positions (Container)'Old)
and P.Keys_Included_Except
(Positions (Container)'Old,
Positions (Container),
Position'Old);
-- Removes the node designated by Position from the set, and then
-- deallocates the node. The operation calls Hash to determine the bucket,
-- and then compares Position to each node in the bucket until there's a
-- match (it does not call Equivalent_Elements).
procedure Union (Target : in out Set; Source : Set) with
Global => null,
Pre =>
Length (Source) - Length (Target and Source) <=
Target.Capacity - Length (Target),
Post =>
Length (Target) = Length (Target)'Old
- M.Num_Overlaps (Model (Target)'Old, Model (Source))
+ Length (Source)
-- Elements already in Target are still in Target
and Model (Target)'Old <= Model (Target)
-- Elements of Source are included in Target
and Model (Source) <= Model (Target)
-- Elements of Target come from either Source or Target
and M.Included_In_Union
(Model (Target), Model (Source), Model (Target)'Old)
-- Actual value of elements come from either Left or Right
and E_Elements_Included
(Elements (Target),
Model (Target)'Old,
Elements (Target)'Old,
Elements (Source))
and E_Elements_Included
(Elements (Target)'Old, Model (Target)'Old, Elements (Target))
and E_Elements_Included
(Elements (Source),
Model (Target)'Old,
Elements (Source),
Elements (Target))
-- Mapping from cursors of Target to elements is preserved
and Mapping_Preserved
(E_Left => Elements (Target)'Old,
E_Right => Elements (Target),
P_Left => Positions (Target)'Old,
P_Right => Positions (Target));
-- Iterates over the Source set, and conditionally inserts each element
-- into Target.
function Union (Left, Right : Set) return Set with
Global => null,
Pre => Length (Left) <= Count_Type'Last - Length (Right),
Post =>
Length (Union'Result) = Length (Left)
- M.Num_Overlaps (Model (Left), Model (Right))
+ Length (Right)
-- Elements of Left and Right are in the result of Union
and Model (Left) <= Model (Union'Result)
and Model (Right) <= Model (Union'Result)
-- Elements of the result of union come from either Left or Right
and
M.Included_In_Union
(Model (Union'Result), Model (Left), Model (Right))
-- Actual value of elements come from either Left or Right
and E_Elements_Included
(Elements (Union'Result),
Model (Left),
Elements (Left),
Elements (Right))
and E_Elements_Included
(Elements (Left), Model (Left), Elements (Union'Result))
and E_Elements_Included
(Elements (Right),
Model (Left),
Elements (Right),
Elements (Union'Result));
-- The operation first copies the Left set to the result, and then iterates
-- over the Right set to conditionally insert each element into the result.
function "or" (Left, Right : Set) return Set renames Union;
procedure Intersection (Target : in out Set; Source : Set) with
Global => null,
Post =>
Length (Target) =
M.Num_Overlaps (Model (Target)'Old, Model (Source))
-- Elements of Target were already in Target
and Model (Target) <= Model (Target)'Old
-- Elements of Target are in Source
and Model (Target) <= Model (Source)
-- Elements both in Source and Target are in the intersection
and M.Includes_Intersection
(Model (Target), Model (Source), Model (Target)'Old)
-- Actual value of elements of Target is preserved
and E_Elements_Included (Elements (Target), Elements (Target)'Old)
and E_Elements_Included
(Elements (Target)'Old, Model (Source), Elements (Target))
-- Mapping from cursors of Target to elements is preserved
and Mapping_Preserved
(E_Left => Elements (Target),
E_Right => Elements (Target)'Old,
P_Left => Positions (Target),
P_Right => Positions (Target)'Old);
-- Iterates over the Target set (calling First and Next), calling Find to
-- determine whether the element is in Source. If an equivalent element is
-- not found in Source, the element is deleted from Target.
function Intersection (Left, Right : Set) return Set with
Global => null,
Post =>
Length (Intersection'Result) =
M.Num_Overlaps (Model (Left), Model (Right))
-- Elements in the result of Intersection are in Left and Right
and Model (Intersection'Result) <= Model (Left)
and Model (Intersection'Result) <= Model (Right)
-- Elements both in Left and Right are in the result of Intersection
and M.Includes_Intersection
(Model (Intersection'Result), Model (Left), Model (Right))
-- Actual value of elements come from Left
and E_Elements_Included
(Elements (Intersection'Result), Elements (Left))
and E_Elements_Included
(Elements (Left), Model (Right),
Elements (Intersection'Result));
-- Iterates over the Left set, calling Find to determine whether the
-- element is in Right. If an equivalent element is found, it is inserted
-- into the result set.
function "and" (Left, Right : Set) return Set renames Intersection;
procedure Difference (Target : in out Set; Source : Set) with
Global => null,
Post =>
Length (Target) = Length (Target)'Old -
M.Num_Overlaps (Model (Target)'Old, Model (Source))
-- Elements of Target were already in Target
and Model (Target) <= Model (Target)'Old
-- Elements of Target are not in Source
and M.No_Overlap (Model (Target), Model (Source))
-- Elements in Target but not in Source are in the difference
and M.Included_In_Union
(Model (Target)'Old, Model (Target), Model (Source))
-- Actual value of elements of Target is preserved
and E_Elements_Included (Elements (Target), Elements (Target)'Old)
and E_Elements_Included
(Elements (Target)'Old, Model (Target), Elements (Target))
-- Mapping from cursors of Target to elements is preserved
and Mapping_Preserved
(E_Left => Elements (Target),
E_Right => Elements (Target)'Old,
P_Left => Positions (Target),
P_Right => Positions (Target)'Old);
-- Iterates over the Source (calling First and Next), calling Find to
-- determine whether the element is in Target. If an equivalent element is
-- found, it is deleted from Target.
function Difference (Left, Right : Set) return Set with
Global => null,
Post =>
Length (Difference'Result) = Length (Left) -
M.Num_Overlaps (Model (Left), Model (Right))
-- Elements of the result of Difference are in Left
and Model (Difference'Result) <= Model (Left)
-- Elements of the result of Difference are in Right
and M.No_Overlap (Model (Difference'Result), Model (Right))
-- Elements in Left but not in Right are in the difference
and M.Included_In_Union
(Model (Left), Model (Difference'Result), Model (Right))
-- Actual value of elements come from Left
and E_Elements_Included
(Elements (Difference'Result), Elements (Left))
and E_Elements_Included
(Elements (Left),
Model (Difference'Result),
Elements (Difference'Result));
-- Iterates over the Left set, calling Find to determine whether the
-- element is in the Right set. If an equivalent element is not found, the
-- element is inserted into the result set.
function "-" (Left, Right : Set) return Set renames Difference;
procedure Symmetric_Difference (Target : in out Set; Source : Set) with
Global => null,
Pre =>
Length (Source) - Length (Target and Source) <=
Target.Capacity - Length (Target) + Length (Target and Source),
Post =>
Length (Target) = Length (Target)'Old -
2 * M.Num_Overlaps (Model (Target)'Old, Model (Source)) +
Length (Source)
-- Elements of the difference were not both in Source and in Target
and M.Not_In_Both (Model (Target), Model (Target)'Old, Model (Source))
-- Elements in Target but not in Source are in the difference
and M.Included_In_Union
(Model (Target)'Old, Model (Target), Model (Source))
-- Elements in Source but not in Target are in the difference
and M.Included_In_Union
(Model (Source), Model (Target), Model (Target)'Old)
-- Actual value of elements come from either Left or Right
and E_Elements_Included
(Elements (Target),
Model (Target)'Old,
Elements (Target)'Old,
Elements (Source))
and E_Elements_Included
(Elements (Target)'Old, Model (Target), Elements (Target))
and E_Elements_Included
(Elements (Source), Model (Target), Elements (Target));
-- The operation iterates over the Source set, searching for the element
-- in Target (calling Hash and Equivalent_Elements). If an equivalent
-- element is found, it is removed from Target; otherwise it is inserted
-- into Target.
function Symmetric_Difference (Left, Right : Set) return Set with
Global => null,
Pre => Length (Left) <= Count_Type'Last - Length (Right),
Post =>
Length (Symmetric_Difference'Result) = Length (Left) -
2 * M.Num_Overlaps (Model (Left), Model (Right)) +
Length (Right)
-- Elements of the difference were not both in Left and Right
and M.Not_In_Both
(Model (Symmetric_Difference'Result),
Model (Left),
Model (Right))
-- Elements in Left but not in Right are in the difference
and M.Included_In_Union
(Model (Left),
Model (Symmetric_Difference'Result),
Model (Right))
-- Elements in Right but not in Left are in the difference
and M.Included_In_Union
(Model (Right),
Model (Symmetric_Difference'Result),
Model (Left))
-- Actual value of elements come from either Left or Right
and E_Elements_Included
(Elements (Symmetric_Difference'Result),
Model (Left),
Elements (Left),
Elements (Right))
and E_Elements_Included
(Elements (Left),
Model (Symmetric_Difference'Result),
Elements (Symmetric_Difference'Result))
and E_Elements_Included
(Elements (Right),
Model (Symmetric_Difference'Result),
Elements (Symmetric_Difference'Result));
-- The operation first iterates over the Left set. It calls Find to
-- determine whether the element is in the Right set. If no equivalent
-- element is found, the element from Left is inserted into the result. The
-- operation then iterates over the Right set, to determine whether the
-- element is in the Left set. If no equivalent element is found, the Right
-- element is inserted into the result.
function "xor" (Left, Right : Set) return Set
renames Symmetric_Difference;
function Overlap (Left, Right : Set) return Boolean with
Global => null,
Post =>
Overlap'Result = not (M.No_Overlap (Model (Left), Model (Right)));
-- Iterates over the Left set (calling First and Next), calling Find to
-- determine whether the element is in the Right set. If an equivalent
-- element is found, the operation immediately returns True. The operation
-- returns False if the iteration over Left terminates without finding any
-- equivalent element in Right.
function Is_Subset (Subset : Set; Of_Set : Set) return Boolean with
Global => null,
Post => Is_Subset'Result = (Model (Subset) <= Model (Of_Set));
-- Iterates over Subset (calling First and Next), calling Find to determine
-- whether the element is in Of_Set. If no equivalent element is found in
-- Of_Set, the operation immediately returns False. The operation returns
-- True if the iteration over Subset terminates without finding an element
-- not in Of_Set (that is, every element in Subset is equivalent to an
-- element in Of_Set).
function First (Container : Set) return Cursor with
Global => null,
Contract_Cases =>
(Length (Container) = 0 =>
First'Result = No_Element,
others =>
Has_Element (Container, First'Result)
and P.Get (Positions (Container), First'Result) = 1);
-- Returns a cursor that designates the first non-empty bucket, by
-- searching from the beginning of the buckets array.
function Next (Container : Set; Position : Cursor) return Cursor with
Global => null,
Pre =>
Has_Element (Container, Position) or else Position = No_Element,
Contract_Cases =>
(Position = No_Element
or else P.Get (Positions (Container), Position) = Length (Container)
=>
Next'Result = No_Element,
others =>
Has_Element (Container, Next'Result)
and then P.Get (Positions (Container), Next'Result) =
P.Get (Positions (Container), Position) + 1);
-- Returns a cursor that designates the node that follows the current one
-- designated by Position. If Position designates the last node in its
-- bucket, the operation calls Hash to compute the index of this bucket,
-- and searches the buckets array for the first non-empty bucket, starting
-- from that index; otherwise, it simply follows the link to the next node
-- in the same bucket.
procedure Next (Container : Set; Position : in out Cursor) with
Global => null,
Pre =>
Has_Element (Container, Position) or else Position = No_Element,
Contract_Cases =>
(Position = No_Element
or else P.Get (Positions (Container), Position) = Length (Container)
=>
Position = No_Element,
others =>
Has_Element (Container, Position)
and then P.Get (Positions (Container), Position) =
P.Get (Positions (Container), Position'Old) + 1);
-- Equivalent to Position := Next (Position)
function Find
(Container : Set;
Item : Element_Type) return Cursor
with
Global => null,
Contract_Cases =>
-- If Item is not contained in Container, Find returns No_Element
(not Contains (Model (Container), Item) =>
Find'Result = No_Element,
-- Otherwise, Find returns a valid cursor in Container
others =>
P.Has_Key (Positions (Container), Find'Result)
and P.Get (Positions (Container), Find'Result) =
Find (Elements (Container), Item)
-- The element designated by the result of Find is Item
and Equivalent_Elements
(Element (Container, Find'Result), Item));
-- Searches for Item in the set. Find calls Hash to determine the item's
-- bucket; if the bucket is not empty, it calls Equivalent_Elements to
-- compare Item to each element in the bucket. If the search succeeds, Find
-- returns a cursor designating the node containing the equivalent element;
-- otherwise, it returns No_Element.
function Contains (Container : Set; Item : Element_Type) return Boolean with
Global => null,
Post => Contains'Result = Contains (Model (Container), Item);
pragma Annotate (GNATprove, Inline_For_Proof, Contains);
function Has_Element (Container : Set; Position : Cursor) return Boolean
with
Global => null,
Post =>
Has_Element'Result = P.Has_Key (Positions (Container), Position);
pragma Annotate (GNATprove, Inline_For_Proof, Has_Element);
function Default_Modulus (Capacity : Count_Type) return Hash_Type with
Global => null;
generic
type Key_Type (<>) is private;
with function Key (Element : Element_Type) return Key_Type;
with function Hash (Key : Key_Type) return Hash_Type;
with function Equivalent_Keys (Left, Right : Key_Type) return Boolean;
package Generic_Keys with SPARK_Mode is
package Formal_Model with Ghost is
function M_Included_Except
(Left : M.Set;
Right : M.Set;
Key : Key_Type) return Boolean
with
Global => null,
Post =>
M_Included_Except'Result =
(for all E of Left =>
Contains (Right, E)
or Equivalent_Keys (Generic_Keys.Key (E), Key));
end Formal_Model;
use Formal_Model;
function Key (Container : Set; Position : Cursor) return Key_Type with
Global => null,
Post => Key'Result = Key (Element (Container, Position));
pragma Annotate (GNATprove, Inline_For_Proof, Key);
function Element (Container : Set; Key : Key_Type) return Element_Type
with
Global => null,
Pre => Contains (Container, Key),
Post =>
Element'Result = Element (Container, Find (Container, Key));
pragma Annotate (GNATprove, Inline_For_Proof, Element);
procedure Replace
(Container : in out Set;
Key : Key_Type;
New_Item : Element_Type)
with
Global => null,
Pre => Contains (Container, Key),
Post =>
Length (Container) = Length (Container)'Old
-- Key now maps to New_Item
and Element (Container, Key) = New_Item
-- New_Item is contained in Container
and Contains (Model (Container), New_Item)
-- Other elements are preserved
and M_Included_Except
(Model (Container)'Old,
Model (Container),
Key)
and M.Included_Except
(Model (Container),
Model (Container)'Old,
New_Item)
-- Mapping from cursors to elements is preserved
and Mapping_Preserved_Except
(E_Left => Elements (Container)'Old,
E_Right => Elements (Container),
P_Left => Positions (Container)'Old,
P_Right => Positions (Container),
Position => Find (Container, Key))
and Positions (Container) = Positions (Container)'Old;
procedure Exclude (Container : in out Set; Key : Key_Type) with
Global => null,
Post => not Contains (Container, Key),
Contract_Cases =>
-- If Key is not in Container, nothing is changed
(not Contains (Container, Key) =>
Model (Container) = Model (Container)'Old
and Elements (Container) = Elements (Container)'Old
and Positions (Container) = Positions (Container)'Old,
-- Otherwise, Key is removed from Container
others =>
Length (Container) = Length (Container)'Old - 1
-- Other elements are preserved
and Model (Container) <= Model (Container)'Old
and M_Included_Except
(Model (Container)'Old,
Model (Container),
Key)
-- Mapping from cursors to elements is preserved
and Mapping_Preserved
(E_Left => Elements (Container),
E_Right => Elements (Container)'Old,
P_Left => Positions (Container),
P_Right => Positions (Container)'Old)
and P.Keys_Included_Except
(Positions (Container)'Old,
Positions (Container),
Find (Container, Key)'Old));
procedure Delete (Container : in out Set; Key : Key_Type) with
Global => null,
Pre => Contains (Container, Key),
Post =>
Length (Container) = Length (Container)'Old - 1
-- Key is no longer in Container
and not Contains (Container, Key)
-- Other elements are preserved
and Model (Container) <= Model (Container)'Old
and M_Included_Except
(Model (Container)'Old,
Model (Container),
Key)
-- Mapping from cursors to elements is preserved
and Mapping_Preserved
(E_Left => Elements (Container),
E_Right => Elements (Container)'Old,
P_Left => Positions (Container),
P_Right => Positions (Container)'Old)
and P.Keys_Included_Except
(Positions (Container)'Old,
Positions (Container),
Find (Container, Key)'Old);
function Find (Container : Set; Key : Key_Type) return Cursor with
Global => null,
Contract_Cases =>
-- If Key is not contained in Container, Find returns No_Element
((for all E of Model (Container) =>
not Equivalent_Keys (Key, Generic_Keys.Key (E))) =>
Find'Result = No_Element,
-- Otherwise, Find returns a valid cursor in Container
others =>
P.Has_Key (Positions (Container), Find'Result)
-- The key designated by the result of Find is Key
and Equivalent_Keys
(Generic_Keys.Key (Container, Find'Result), Key));
function Contains (Container : Set; Key : Key_Type) return Boolean with
Global => null,
Post =>
Contains'Result =
(for some E of Model (Container) =>
Equivalent_Keys (Key, Generic_Keys.Key (E)));
end Generic_Keys;
private
pragma SPARK_Mode (Off);
pragma Inline (Next);
type Node_Type is
record
Element : aliased Element_Type;
Next : Count_Type;
Has_Element : Boolean := False;
end record;
package HT_Types is new
Ada.Containers.Hash_Tables.Generic_Bounded_Hash_Table_Types (Node_Type);
type Set (Capacity : Count_Type; Modulus : Hash_Type) is record
Content : HT_Types.Hash_Table_Type (Capacity, Modulus);
end record;
use HT_Types;
Empty_Set : constant Set := (Capacity => 0, Modulus => 0, others => <>);
end Ada.Containers.Formal_Hashed_Sets;
|
-- AOC 2020, Day 23
package Day is
type Cup_Number is range 1..9;
type Cup_Number_Mod is mod Cup_Number'Last + 1;
type Cup_Index is range 0..8;
type Cup_Index_Mod is mod Cup_Index'Last + 1;
type Cup_Array is array(Cup_Index) of Cup_Number;
function play(c : in Cup_Array; steps : in Natural) return String;
function play2(c : in Cup_Array; total_cups : in Natural; steps : in Natural) return Long_Integer;
end Day;
|
pragma License (Unrestricted);
package Ada.Streams is
pragma Pure;
type Root_Stream_Type is abstract tagged limited private;
pragma Preelaborable_Initialization (Root_Stream_Type);
type Stream_Element is
mod 2 ** Standard'Storage_Unit; -- implementation-defined
type Stream_Element_Offset is
range -(2 ** 63) .. 2 ** 63 - 1; -- implementation-defined
subtype Stream_Element_Count is
Stream_Element_Offset range 0 .. Stream_Element_Offset'Last;
type Stream_Element_Array is
array (Stream_Element_Offset range <>) of aliased Stream_Element;
procedure Read (
Stream : in out Root_Stream_Type;
Item : out Stream_Element_Array;
Last : out Stream_Element_Offset) is abstract;
procedure Write (
Stream : in out Root_Stream_Type;
Item : Stream_Element_Array) is abstract;
-- extended from here
type Seekable_Stream_Type is
abstract limited new Root_Stream_Type with private;
pragma Preelaborable_Initialization (Seekable_Stream_Type);
subtype Stream_Element_Positive_Count is
Stream_Element_Count range 1 .. Stream_Element_Count'Last;
procedure Set_Index (
Stream : in out Seekable_Stream_Type;
To : Stream_Element_Positive_Count) is abstract;
function Index (Stream : Seekable_Stream_Type)
return Stream_Element_Positive_Count is abstract;
function Size (Stream : Seekable_Stream_Type)
return Stream_Element_Count is abstract;
private
type Root_Stream_Type is abstract tagged limited null record;
type Seekable_Stream_Type is
abstract limited new Root_Stream_Type with null record;
end Ada.Streams;
|
package body Commands is
procedure Host (Bot : in out Irc.Bot.Connection;
Msg : Irc.Message.Message) is
Host : String := GNAT.Sockets.Host_Name;
Target : String := Ada.Strings.Unbounded.To_String
(Msg.Privmsg.Target);
begin
-- Send back our host name to whichever nick/channel
-- triggered the callback
Bot.Privmsg (Target, "I am running on " & Host);
end Host;
end Commands;
|
------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- S E M _ A G G R --
-- --
-- B o d y --
-- --
-- Copyright (C) 1992-2016, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
-- for more details. You should have received a copy of the GNU General --
-- Public License distributed with GNAT; see file COPYING3. If not, go to --
-- http://www.gnu.org/licenses for a complete copy of the license. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
with Aspects; use Aspects;
with Atree; use Atree;
with Checks; use Checks;
with Einfo; use Einfo;
with Elists; use Elists;
with Errout; use Errout;
with Expander; use Expander;
with Exp_Tss; use Exp_Tss;
with Exp_Util; use Exp_Util;
with Freeze; use Freeze;
with Itypes; use Itypes;
with Lib; use Lib;
with Lib.Xref; use Lib.Xref;
with Namet; use Namet;
with Namet.Sp; use Namet.Sp;
with Nmake; use Nmake;
with Nlists; use Nlists;
with Opt; use Opt;
with Restrict; use Restrict;
with Rident; use Rident;
with Sem; use Sem;
with Sem_Aux; use Sem_Aux;
with Sem_Cat; use Sem_Cat;
with Sem_Ch3; use Sem_Ch3;
with Sem_Ch8; use Sem_Ch8;
with Sem_Ch13; use Sem_Ch13;
with Sem_Dim; use Sem_Dim;
with Sem_Eval; use Sem_Eval;
with Sem_Res; use Sem_Res;
with Sem_Util; use Sem_Util;
with Sem_Type; use Sem_Type;
with Sem_Warn; use Sem_Warn;
with Sinfo; use Sinfo;
with Snames; use Snames;
with Stringt; use Stringt;
with Stand; use Stand;
with Style; use Style;
with Targparm; use Targparm;
with Tbuild; use Tbuild;
with Uintp; use Uintp;
package body Sem_Aggr is
type Case_Bounds is record
Lo : Node_Id;
-- Low bound of choice. Once we sort the Case_Table, then entries
-- will be in order of ascending Choice_Lo values.
Hi : Node_Id;
-- High Bound of choice. The sort does not pay any attention to the
-- high bound, so choices 1 .. 4 and 1 .. 5 could be in either order.
Highest : Uint;
-- If there are duplicates or missing entries, then in the sorted
-- table, this records the highest value among Choice_Hi values
-- seen so far, including this entry.
Choice : Node_Id;
-- The node of the choice
end record;
type Case_Table_Type is array (Nat range <>) of Case_Bounds;
-- Table type used by Check_Case_Choices procedure. Entry zero is not
-- used (reserved for the sort). Real entries start at one.
-----------------------
-- Local Subprograms --
-----------------------
procedure Sort_Case_Table (Case_Table : in out Case_Table_Type);
-- Sort the Case Table using the Lower Bound of each Choice as the key. A
-- simple insertion sort is used since the choices in a case statement will
-- usually be in near sorted order.
procedure Check_Can_Never_Be_Null (Typ : Entity_Id; Expr : Node_Id);
-- Ada 2005 (AI-231): Check bad usage of null for a component for which
-- null exclusion (NOT NULL) is specified. Typ can be an E_Array_Type for
-- the array case (the component type of the array will be used) or an
-- E_Component/E_Discriminant entity in the record case, in which case the
-- type of the component will be used for the test. If Typ is any other
-- kind of entity, the call is ignored. Expr is the component node in the
-- aggregate which is known to have a null value. A warning message will be
-- issued if the component is null excluding.
--
-- It would be better to pass the proper type for Typ ???
procedure Check_Expr_OK_In_Limited_Aggregate (Expr : Node_Id);
-- Check that Expr is either not limited or else is one of the cases of
-- expressions allowed for a limited component association (namely, an
-- aggregate, function call, or <> notation). Report error for violations.
-- Expression is also OK in an instance or inlining context, because we
-- have already pre-analyzed and it is known to be type correct.
procedure Check_Qualified_Aggregate (Level : Nat; Expr : Node_Id);
-- Given aggregate Expr, check that sub-aggregates of Expr that are nested
-- at Level are qualified. If Level = 0, this applies to Expr directly.
-- Only issue errors in formal verification mode.
function Is_Top_Level_Aggregate (Expr : Node_Id) return Boolean;
-- Return True of Expr is an aggregate not contained directly in another
-- aggregate.
------------------------------------------------------
-- Subprograms used for RECORD AGGREGATE Processing --
------------------------------------------------------
procedure Resolve_Record_Aggregate (N : Node_Id; Typ : Entity_Id);
-- This procedure performs all the semantic checks required for record
-- aggregates. Note that for aggregates analysis and resolution go
-- hand in hand. Aggregate analysis has been delayed up to here and
-- it is done while resolving the aggregate.
--
-- N is the N_Aggregate node.
-- Typ is the record type for the aggregate resolution
--
-- While performing the semantic checks, this procedure builds a new
-- Component_Association_List where each record field appears alone in a
-- Component_Choice_List along with its corresponding expression. The
-- record fields in the Component_Association_List appear in the same order
-- in which they appear in the record type Typ.
--
-- Once this new Component_Association_List is built and all the semantic
-- checks performed, the original aggregate subtree is replaced with the
-- new named record aggregate just built. Note that subtree substitution is
-- performed with Rewrite so as to be able to retrieve the original
-- aggregate.
--
-- The aggregate subtree manipulation performed by Resolve_Record_Aggregate
-- yields the aggregate format expected by Gigi. Typically, this kind of
-- tree manipulations are done in the expander. However, because the
-- semantic checks that need to be performed on record aggregates really go
-- hand in hand with the record aggregate normalization, the aggregate
-- subtree transformation is performed during resolution rather than
-- expansion. Had we decided otherwise we would have had to duplicate most
-- of the code in the expansion procedure Expand_Record_Aggregate. Note,
-- however, that all the expansion concerning aggregates for tagged records
-- is done in Expand_Record_Aggregate.
--
-- The algorithm of Resolve_Record_Aggregate proceeds as follows:
--
-- 1. Make sure that the record type against which the record aggregate
-- has to be resolved is not abstract. Furthermore if the type is a
-- null aggregate make sure the input aggregate N is also null.
--
-- 2. Verify that the structure of the aggregate is that of a record
-- aggregate. Specifically, look for component associations and ensure
-- that each choice list only has identifiers or the N_Others_Choice
-- node. Also make sure that if present, the N_Others_Choice occurs
-- last and by itself.
--
-- 3. If Typ contains discriminants, the values for each discriminant is
-- looked for. If the record type Typ has variants, we check that the
-- expressions corresponding to each discriminant ruling the (possibly
-- nested) variant parts of Typ, are static. This allows us to determine
-- the variant parts to which the rest of the aggregate must conform.
-- The names of discriminants with their values are saved in a new
-- association list, New_Assoc_List which is later augmented with the
-- names and values of the remaining components in the record type.
--
-- During this phase we also make sure that every discriminant is
-- assigned exactly one value. Note that when several values for a given
-- discriminant are found, semantic processing continues looking for
-- further errors. In this case it's the first discriminant value found
-- which we will be recorded.
--
-- IMPORTANT NOTE: For derived tagged types this procedure expects
-- First_Discriminant and Next_Discriminant to give the correct list
-- of discriminants, in the correct order.
--
-- 4. After all the discriminant values have been gathered, we can set the
-- Etype of the record aggregate. If Typ contains no discriminants this
-- is straightforward: the Etype of N is just Typ, otherwise a new
-- implicit constrained subtype of Typ is built to be the Etype of N.
--
-- 5. Gather the remaining record components according to the discriminant
-- values. This involves recursively traversing the record type
-- structure to see what variants are selected by the given discriminant
-- values. This processing is a little more convoluted if Typ is a
-- derived tagged types since we need to retrieve the record structure
-- of all the ancestors of Typ.
--
-- 6. After gathering the record components we look for their values in the
-- record aggregate and emit appropriate error messages should we not
-- find such values or should they be duplicated.
--
-- 7. We then make sure no illegal component names appear in the record
-- aggregate and make sure that the type of the record components
-- appearing in a same choice list is the same. Finally we ensure that
-- the others choice, if present, is used to provide the value of at
-- least a record component.
--
-- 8. The original aggregate node is replaced with the new named aggregate
-- built in steps 3 through 6, as explained earlier.
--
-- Given the complexity of record aggregate resolution, the primary goal of
-- this routine is clarity and simplicity rather than execution and storage
-- efficiency. If there are only positional components in the aggregate the
-- running time is linear. If there are associations the running time is
-- still linear as long as the order of the associations is not too far off
-- the order of the components in the record type. If this is not the case
-- the running time is at worst quadratic in the size of the association
-- list.
procedure Check_Misspelled_Component
(Elements : Elist_Id;
Component : Node_Id);
-- Give possible misspelling diagnostic if Component is likely to be a
-- misspelling of one of the components of the Assoc_List. This is called
-- by Resolve_Aggr_Expr after producing an invalid component error message.
procedure Check_Static_Discriminated_Subtype (T : Entity_Id; V : Node_Id);
-- An optimization: determine whether a discriminated subtype has a static
-- constraint, and contains array components whose length is also static,
-- either because they are constrained by the discriminant, or because the
-- original component bounds are static.
-----------------------------------------------------
-- Subprograms used for ARRAY AGGREGATE Processing --
-----------------------------------------------------
function Resolve_Array_Aggregate
(N : Node_Id;
Index : Node_Id;
Index_Constr : Node_Id;
Component_Typ : Entity_Id;
Others_Allowed : Boolean) return Boolean;
-- This procedure performs the semantic checks for an array aggregate.
-- True is returned if the aggregate resolution succeeds.
--
-- The procedure works by recursively checking each nested aggregate.
-- Specifically, after checking a sub-aggregate nested at the i-th level
-- we recursively check all the subaggregates at the i+1-st level (if any).
-- Note that for aggregates analysis and resolution go hand in hand.
-- Aggregate analysis has been delayed up to here and it is done while
-- resolving the aggregate.
--
-- N is the current N_Aggregate node to be checked.
--
-- Index is the index node corresponding to the array sub-aggregate that
-- we are currently checking (RM 4.3.3 (8)). Its Etype is the
-- corresponding index type (or subtype).
--
-- Index_Constr is the node giving the applicable index constraint if
-- any (RM 4.3.3 (10)). It "is a constraint provided by certain
-- contexts [...] that can be used to determine the bounds of the array
-- value specified by the aggregate". If Others_Allowed below is False
-- there is no applicable index constraint and this node is set to Index.
--
-- Component_Typ is the array component type.
--
-- Others_Allowed indicates whether an others choice is allowed
-- in the context where the top-level aggregate appeared.
--
-- The algorithm of Resolve_Array_Aggregate proceeds as follows:
--
-- 1. Make sure that the others choice, if present, is by itself and
-- appears last in the sub-aggregate. Check that we do not have
-- positional and named components in the array sub-aggregate (unless
-- the named association is an others choice). Finally if an others
-- choice is present, make sure it is allowed in the aggregate context.
--
-- 2. If the array sub-aggregate contains discrete_choices:
--
-- (A) Verify their validity. Specifically verify that:
--
-- (a) If a null range is present it must be the only possible
-- choice in the array aggregate.
--
-- (b) Ditto for a non static range.
--
-- (c) Ditto for a non static expression.
--
-- In addition this step analyzes and resolves each discrete_choice,
-- making sure that its type is the type of the corresponding Index.
-- If we are not at the lowest array aggregate level (in the case of
-- multi-dimensional aggregates) then invoke Resolve_Array_Aggregate
-- recursively on each component expression. Otherwise, resolve the
-- bottom level component expressions against the expected component
-- type ONLY IF the component corresponds to a single discrete choice
-- which is not an others choice (to see why read the DELAYED
-- COMPONENT RESOLUTION below).
--
-- (B) Determine the bounds of the sub-aggregate and lowest and
-- highest choice values.
--
-- 3. For positional aggregates:
--
-- (A) Loop over the component expressions either recursively invoking
-- Resolve_Array_Aggregate on each of these for multi-dimensional
-- array aggregates or resolving the bottom level component
-- expressions against the expected component type.
--
-- (B) Determine the bounds of the positional sub-aggregates.
--
-- 4. Try to determine statically whether the evaluation of the array
-- sub-aggregate raises Constraint_Error. If yes emit proper
-- warnings. The precise checks are the following:
--
-- (A) Check that the index range defined by aggregate bounds is
-- compatible with corresponding index subtype.
-- We also check against the base type. In fact it could be that
-- Low/High bounds of the base type are static whereas those of
-- the index subtype are not. Thus if we can statically catch
-- a problem with respect to the base type we are guaranteed
-- that the same problem will arise with the index subtype
--
-- (B) If we are dealing with a named aggregate containing an others
-- choice and at least one discrete choice then make sure the range
-- specified by the discrete choices does not overflow the
-- aggregate bounds. We also check against the index type and base
-- type bounds for the same reasons given in (A).
--
-- (C) If we are dealing with a positional aggregate with an others
-- choice make sure the number of positional elements specified
-- does not overflow the aggregate bounds. We also check against
-- the index type and base type bounds as mentioned in (A).
--
-- Finally construct an N_Range node giving the sub-aggregate bounds.
-- Set the Aggregate_Bounds field of the sub-aggregate to be this
-- N_Range. The routine Array_Aggr_Subtype below uses such N_Ranges
-- to build the appropriate aggregate subtype. Aggregate_Bounds
-- information is needed during expansion.
--
-- DELAYED COMPONENT RESOLUTION: The resolution of bottom level component
-- expressions in an array aggregate may call Duplicate_Subexpr or some
-- other routine that inserts code just outside the outermost aggregate.
-- If the array aggregate contains discrete choices or an others choice,
-- this may be wrong. Consider for instance the following example.
--
-- type Rec is record
-- V : Integer := 0;
-- end record;
--
-- type Acc_Rec is access Rec;
-- Arr : array (1..3) of Acc_Rec := (1 .. 3 => new Rec);
--
-- Then the transformation of "new Rec" that occurs during resolution
-- entails the following code modifications
--
-- P7b : constant Acc_Rec := new Rec;
-- RecIP (P7b.all);
-- Arr : array (1..3) of Acc_Rec := (1 .. 3 => P7b);
--
-- This code transformation is clearly wrong, since we need to call
-- "new Rec" for each of the 3 array elements. To avoid this problem we
-- delay resolution of the components of non positional array aggregates
-- to the expansion phase. As an optimization, if the discrete choice
-- specifies a single value we do not delay resolution.
function Array_Aggr_Subtype (N : Node_Id; Typ : Node_Id) return Entity_Id;
-- This routine returns the type or subtype of an array aggregate.
--
-- N is the array aggregate node whose type we return.
--
-- Typ is the context type in which N occurs.
--
-- This routine creates an implicit array subtype whose bounds are
-- those defined by the aggregate. When this routine is invoked
-- Resolve_Array_Aggregate has already processed aggregate N. Thus the
-- Aggregate_Bounds of each sub-aggregate, is an N_Range node giving the
-- sub-aggregate bounds. When building the aggregate itype, this function
-- traverses the array aggregate N collecting such Aggregate_Bounds and
-- constructs the proper array aggregate itype.
--
-- Note that in the case of multidimensional aggregates each inner
-- sub-aggregate corresponding to a given array dimension, may provide a
-- different bounds. If it is possible to determine statically that
-- some sub-aggregates corresponding to the same index do not have the
-- same bounds, then a warning is emitted. If such check is not possible
-- statically (because some sub-aggregate bounds are dynamic expressions)
-- then this job is left to the expander. In all cases the particular
-- bounds that this function will chose for a given dimension is the first
-- N_Range node for a sub-aggregate corresponding to that dimension.
--
-- Note that the Raises_Constraint_Error flag of an array aggregate
-- whose evaluation is determined to raise CE by Resolve_Array_Aggregate,
-- is set in Resolve_Array_Aggregate but the aggregate is not
-- immediately replaced with a raise CE. In fact, Array_Aggr_Subtype must
-- first construct the proper itype for the aggregate (Gigi needs
-- this). After constructing the proper itype we will eventually replace
-- the top-level aggregate with a raise CE (done in Resolve_Aggregate).
-- Of course in cases such as:
--
-- type Arr is array (integer range <>) of Integer;
-- A : Arr := (positive range -1 .. 2 => 0);
--
-- The bounds of the aggregate itype are cooked up to look reasonable
-- (in this particular case the bounds will be 1 .. 2).
procedure Make_String_Into_Aggregate (N : Node_Id);
-- A string literal can appear in a context in which a one dimensional
-- array of characters is expected. This procedure simply rewrites the
-- string as an aggregate, prior to resolution.
------------------------
-- Array_Aggr_Subtype --
------------------------
function Array_Aggr_Subtype
(N : Node_Id;
Typ : Entity_Id) return Entity_Id
is
Aggr_Dimension : constant Pos := Number_Dimensions (Typ);
-- Number of aggregate index dimensions
Aggr_Range : array (1 .. Aggr_Dimension) of Node_Id := (others => Empty);
-- Constrained N_Range of each index dimension in our aggregate itype
Aggr_Low : array (1 .. Aggr_Dimension) of Node_Id := (others => Empty);
Aggr_High : array (1 .. Aggr_Dimension) of Node_Id := (others => Empty);
-- Low and High bounds for each index dimension in our aggregate itype
Is_Fully_Positional : Boolean := True;
procedure Collect_Aggr_Bounds (N : Node_Id; Dim : Pos);
-- N is an array (sub-)aggregate. Dim is the dimension corresponding
-- to (sub-)aggregate N. This procedure collects and removes the side
-- effects of the constrained N_Range nodes corresponding to each index
-- dimension of our aggregate itype. These N_Range nodes are collected
-- in Aggr_Range above.
--
-- Likewise collect in Aggr_Low & Aggr_High above the low and high
-- bounds of each index dimension. If, when collecting, two bounds
-- corresponding to the same dimension are static and found to differ,
-- then emit a warning, and mark N as raising Constraint_Error.
-------------------------
-- Collect_Aggr_Bounds --
-------------------------
procedure Collect_Aggr_Bounds (N : Node_Id; Dim : Pos) is
This_Range : constant Node_Id := Aggregate_Bounds (N);
-- The aggregate range node of this specific sub-aggregate
This_Low : constant Node_Id := Low_Bound (Aggregate_Bounds (N));
This_High : constant Node_Id := High_Bound (Aggregate_Bounds (N));
-- The aggregate bounds of this specific sub-aggregate
Assoc : Node_Id;
Expr : Node_Id;
begin
Remove_Side_Effects (This_Low, Variable_Ref => True);
Remove_Side_Effects (This_High, Variable_Ref => True);
-- Collect the first N_Range for a given dimension that you find.
-- For a given dimension they must be all equal anyway.
if No (Aggr_Range (Dim)) then
Aggr_Low (Dim) := This_Low;
Aggr_High (Dim) := This_High;
Aggr_Range (Dim) := This_Range;
else
if Compile_Time_Known_Value (This_Low) then
if not Compile_Time_Known_Value (Aggr_Low (Dim)) then
Aggr_Low (Dim) := This_Low;
elsif Expr_Value (This_Low) /= Expr_Value (Aggr_Low (Dim)) then
Set_Raises_Constraint_Error (N);
Error_Msg_Warn := SPARK_Mode /= On;
Error_Msg_N ("sub-aggregate low bound mismatch<<", N);
Error_Msg_N ("\Constraint_Error [<<", N);
end if;
end if;
if Compile_Time_Known_Value (This_High) then
if not Compile_Time_Known_Value (Aggr_High (Dim)) then
Aggr_High (Dim) := This_High;
elsif
Expr_Value (This_High) /= Expr_Value (Aggr_High (Dim))
then
Set_Raises_Constraint_Error (N);
Error_Msg_Warn := SPARK_Mode /= On;
Error_Msg_N ("sub-aggregate high bound mismatch<<", N);
Error_Msg_N ("\Constraint_Error [<<", N);
end if;
end if;
end if;
if Dim < Aggr_Dimension then
-- Process positional components
if Present (Expressions (N)) then
Expr := First (Expressions (N));
while Present (Expr) loop
Collect_Aggr_Bounds (Expr, Dim + 1);
Next (Expr);
end loop;
end if;
-- Process component associations
if Present (Component_Associations (N)) then
Is_Fully_Positional := False;
Assoc := First (Component_Associations (N));
while Present (Assoc) loop
Expr := Expression (Assoc);
Collect_Aggr_Bounds (Expr, Dim + 1);
Next (Assoc);
end loop;
end if;
end if;
end Collect_Aggr_Bounds;
-- Array_Aggr_Subtype variables
Itype : Entity_Id;
-- The final itype of the overall aggregate
Index_Constraints : constant List_Id := New_List;
-- The list of index constraints of the aggregate itype
-- Start of processing for Array_Aggr_Subtype
begin
-- Make sure that the list of index constraints is properly attached to
-- the tree, and then collect the aggregate bounds.
Set_Parent (Index_Constraints, N);
Collect_Aggr_Bounds (N, 1);
-- Build the list of constrained indexes of our aggregate itype
for J in 1 .. Aggr_Dimension loop
Create_Index : declare
Index_Base : constant Entity_Id :=
Base_Type (Etype (Aggr_Range (J)));
Index_Typ : Entity_Id;
begin
-- Construct the Index subtype, and associate it with the range
-- construct that generates it.
Index_Typ :=
Create_Itype (Subtype_Kind (Ekind (Index_Base)), Aggr_Range (J));
Set_Etype (Index_Typ, Index_Base);
if Is_Character_Type (Index_Base) then
Set_Is_Character_Type (Index_Typ);
end if;
Set_Size_Info (Index_Typ, (Index_Base));
Set_RM_Size (Index_Typ, RM_Size (Index_Base));
Set_First_Rep_Item (Index_Typ, First_Rep_Item (Index_Base));
Set_Scalar_Range (Index_Typ, Aggr_Range (J));
if Is_Discrete_Or_Fixed_Point_Type (Index_Typ) then
Set_RM_Size (Index_Typ, UI_From_Int (Minimum_Size (Index_Typ)));
end if;
Set_Etype (Aggr_Range (J), Index_Typ);
Append (Aggr_Range (J), To => Index_Constraints);
end Create_Index;
end loop;
-- Now build the Itype
Itype := Create_Itype (E_Array_Subtype, N);
Set_First_Rep_Item (Itype, First_Rep_Item (Typ));
Set_Convention (Itype, Convention (Typ));
Set_Depends_On_Private (Itype, Has_Private_Component (Typ));
Set_Etype (Itype, Base_Type (Typ));
Set_Has_Alignment_Clause (Itype, Has_Alignment_Clause (Typ));
Set_Is_Aliased (Itype, Is_Aliased (Typ));
Set_Depends_On_Private (Itype, Depends_On_Private (Typ));
Copy_Suppress_Status (Index_Check, Typ, Itype);
Copy_Suppress_Status (Length_Check, Typ, Itype);
Set_First_Index (Itype, First (Index_Constraints));
Set_Is_Constrained (Itype, True);
Set_Is_Internal (Itype, True);
-- A simple optimization: purely positional aggregates of static
-- components should be passed to gigi unexpanded whenever possible, and
-- regardless of the staticness of the bounds themselves. Subsequent
-- checks in exp_aggr verify that type is not packed, etc.
Set_Size_Known_At_Compile_Time
(Itype,
Is_Fully_Positional
and then Comes_From_Source (N)
and then Size_Known_At_Compile_Time (Component_Type (Typ)));
-- We always need a freeze node for a packed array subtype, so that we
-- can build the Packed_Array_Impl_Type corresponding to the subtype. If
-- expansion is disabled, the packed array subtype is not built, and we
-- must not generate a freeze node for the type, or else it will appear
-- incomplete to gigi.
if Is_Packed (Itype)
and then not In_Spec_Expression
and then Expander_Active
then
Freeze_Itype (Itype, N);
end if;
return Itype;
end Array_Aggr_Subtype;
--------------------------------
-- Check_Misspelled_Component --
--------------------------------
procedure Check_Misspelled_Component
(Elements : Elist_Id;
Component : Node_Id)
is
Max_Suggestions : constant := 2;
Nr_Of_Suggestions : Natural := 0;
Suggestion_1 : Entity_Id := Empty;
Suggestion_2 : Entity_Id := Empty;
Component_Elmt : Elmt_Id;
begin
-- All the components of List are matched against Component and a count
-- is maintained of possible misspellings. When at the end of the
-- analysis there are one or two (not more) possible misspellings,
-- these misspellings will be suggested as possible corrections.
Component_Elmt := First_Elmt (Elements);
while Nr_Of_Suggestions <= Max_Suggestions
and then Present (Component_Elmt)
loop
if Is_Bad_Spelling_Of
(Chars (Node (Component_Elmt)),
Chars (Component))
then
Nr_Of_Suggestions := Nr_Of_Suggestions + 1;
case Nr_Of_Suggestions is
when 1 => Suggestion_1 := Node (Component_Elmt);
when 2 => Suggestion_2 := Node (Component_Elmt);
when others => null;
end case;
end if;
Next_Elmt (Component_Elmt);
end loop;
-- Report at most two suggestions
if Nr_Of_Suggestions = 1 then
Error_Msg_NE -- CODEFIX
("\possible misspelling of&", Component, Suggestion_1);
elsif Nr_Of_Suggestions = 2 then
Error_Msg_Node_2 := Suggestion_2;
Error_Msg_NE -- CODEFIX
("\possible misspelling of& or&", Component, Suggestion_1);
end if;
end Check_Misspelled_Component;
----------------------------------------
-- Check_Expr_OK_In_Limited_Aggregate --
----------------------------------------
procedure Check_Expr_OK_In_Limited_Aggregate (Expr : Node_Id) is
begin
if Is_Limited_Type (Etype (Expr))
and then Comes_From_Source (Expr)
then
if In_Instance_Body or else In_Inlined_Body then
null;
elsif not OK_For_Limited_Init (Etype (Expr), Expr) then
Error_Msg_N
("initialization not allowed for limited types", Expr);
Explain_Limited_Type (Etype (Expr), Expr);
end if;
end if;
end Check_Expr_OK_In_Limited_Aggregate;
-------------------------------
-- Check_Qualified_Aggregate --
-------------------------------
procedure Check_Qualified_Aggregate (Level : Nat; Expr : Node_Id) is
Comp_Expr : Node_Id;
Comp_Assn : Node_Id;
begin
if Level = 0 then
if Nkind (Parent (Expr)) /= N_Qualified_Expression then
Check_SPARK_05_Restriction ("aggregate should be qualified", Expr);
end if;
else
Comp_Expr := First (Expressions (Expr));
while Present (Comp_Expr) loop
if Nkind (Comp_Expr) = N_Aggregate then
Check_Qualified_Aggregate (Level - 1, Comp_Expr);
end if;
Comp_Expr := Next (Comp_Expr);
end loop;
Comp_Assn := First (Component_Associations (Expr));
while Present (Comp_Assn) loop
Comp_Expr := Expression (Comp_Assn);
if Nkind (Comp_Expr) = N_Aggregate then
Check_Qualified_Aggregate (Level - 1, Comp_Expr);
end if;
Comp_Assn := Next (Comp_Assn);
end loop;
end if;
end Check_Qualified_Aggregate;
----------------------------------------
-- Check_Static_Discriminated_Subtype --
----------------------------------------
procedure Check_Static_Discriminated_Subtype (T : Entity_Id; V : Node_Id) is
Disc : constant Entity_Id := First_Discriminant (T);
Comp : Entity_Id;
Ind : Entity_Id;
begin
if Has_Record_Rep_Clause (T) then
return;
elsif Present (Next_Discriminant (Disc)) then
return;
elsif Nkind (V) /= N_Integer_Literal then
return;
end if;
Comp := First_Component (T);
while Present (Comp) loop
if Is_Scalar_Type (Etype (Comp)) then
null;
elsif Is_Private_Type (Etype (Comp))
and then Present (Full_View (Etype (Comp)))
and then Is_Scalar_Type (Full_View (Etype (Comp)))
then
null;
elsif Is_Array_Type (Etype (Comp)) then
if Is_Bit_Packed_Array (Etype (Comp)) then
return;
end if;
Ind := First_Index (Etype (Comp));
while Present (Ind) loop
if Nkind (Ind) /= N_Range
or else Nkind (Low_Bound (Ind)) /= N_Integer_Literal
or else Nkind (High_Bound (Ind)) /= N_Integer_Literal
then
return;
end if;
Next_Index (Ind);
end loop;
else
return;
end if;
Next_Component (Comp);
end loop;
-- On exit, all components have statically known sizes
Set_Size_Known_At_Compile_Time (T);
end Check_Static_Discriminated_Subtype;
-------------------------
-- Is_Others_Aggregate --
-------------------------
function Is_Others_Aggregate (Aggr : Node_Id) return Boolean is
begin
return No (Expressions (Aggr))
and then
Nkind (First (Choice_List (First (Component_Associations (Aggr))))) =
N_Others_Choice;
end Is_Others_Aggregate;
----------------------------
-- Is_Top_Level_Aggregate --
----------------------------
function Is_Top_Level_Aggregate (Expr : Node_Id) return Boolean is
begin
return Nkind (Parent (Expr)) /= N_Aggregate
and then (Nkind (Parent (Expr)) /= N_Component_Association
or else Nkind (Parent (Parent (Expr))) /= N_Aggregate);
end Is_Top_Level_Aggregate;
--------------------------------
-- Make_String_Into_Aggregate --
--------------------------------
procedure Make_String_Into_Aggregate (N : Node_Id) is
Exprs : constant List_Id := New_List;
Loc : constant Source_Ptr := Sloc (N);
Str : constant String_Id := Strval (N);
Strlen : constant Nat := String_Length (Str);
C : Char_Code;
C_Node : Node_Id;
New_N : Node_Id;
P : Source_Ptr;
begin
P := Loc + 1;
for J in 1 .. Strlen loop
C := Get_String_Char (Str, J);
Set_Character_Literal_Name (C);
C_Node :=
Make_Character_Literal (P,
Chars => Name_Find,
Char_Literal_Value => UI_From_CC (C));
Set_Etype (C_Node, Any_Character);
Append_To (Exprs, C_Node);
P := P + 1;
-- Something special for wide strings???
end loop;
New_N := Make_Aggregate (Loc, Expressions => Exprs);
Set_Analyzed (New_N);
Set_Etype (New_N, Any_Composite);
Rewrite (N, New_N);
end Make_String_Into_Aggregate;
-----------------------
-- Resolve_Aggregate --
-----------------------
procedure Resolve_Aggregate (N : Node_Id; Typ : Entity_Id) is
Loc : constant Source_Ptr := Sloc (N);
Pkind : constant Node_Kind := Nkind (Parent (N));
Aggr_Subtyp : Entity_Id;
-- The actual aggregate subtype. This is not necessarily the same as Typ
-- which is the subtype of the context in which the aggregate was found.
begin
-- Ignore junk empty aggregate resulting from parser error
if No (Expressions (N))
and then No (Component_Associations (N))
and then not Null_Record_Present (N)
then
return;
end if;
-- If the aggregate has box-initialized components, its type must be
-- frozen so that initialization procedures can properly be called
-- in the resolution that follows. The replacement of boxes with
-- initialization calls is properly an expansion activity but it must
-- be done during resolution.
if Expander_Active
and then Present (Component_Associations (N))
then
declare
Comp : Node_Id;
begin
Comp := First (Component_Associations (N));
while Present (Comp) loop
if Box_Present (Comp) then
Insert_Actions (N, Freeze_Entity (Typ, N));
exit;
end if;
Next (Comp);
end loop;
end;
end if;
-- An unqualified aggregate is restricted in SPARK to:
-- An aggregate item inside an aggregate for a multi-dimensional array
-- An expression being assigned to an unconstrained array, but only if
-- the aggregate specifies a value for OTHERS only.
if Nkind (Parent (N)) = N_Qualified_Expression then
if Is_Array_Type (Typ) then
Check_Qualified_Aggregate (Number_Dimensions (Typ), N);
else
Check_Qualified_Aggregate (1, N);
end if;
else
if Is_Array_Type (Typ)
and then Nkind (Parent (N)) = N_Assignment_Statement
and then not Is_Constrained (Etype (Name (Parent (N))))
then
if not Is_Others_Aggregate (N) then
Check_SPARK_05_Restriction
("array aggregate should have only OTHERS", N);
end if;
elsif Is_Top_Level_Aggregate (N) then
Check_SPARK_05_Restriction ("aggregate should be qualified", N);
-- The legality of this unqualified aggregate is checked by calling
-- Check_Qualified_Aggregate from one of its enclosing aggregate,
-- unless one of these already causes an error to be issued.
else
null;
end if;
end if;
-- Check for aggregates not allowed in configurable run-time mode.
-- We allow all cases of aggregates that do not come from source, since
-- these are all assumed to be small (e.g. bounds of a string literal).
-- We also allow aggregates of types we know to be small.
if not Support_Aggregates_On_Target
and then Comes_From_Source (N)
and then (not Known_Static_Esize (Typ) or else Esize (Typ) > 64)
then
Error_Msg_CRT ("aggregate", N);
end if;
-- Ada 2005 (AI-287): Limited aggregates allowed
-- In an instance, ignore aggregate subcomponents tnat may be limited,
-- because they originate in view conflicts. If the original aggregate
-- is legal and the actuals are legal, the aggregate itself is legal.
if Is_Limited_Type (Typ)
and then Ada_Version < Ada_2005
and then not In_Instance
then
Error_Msg_N ("aggregate type cannot be limited", N);
Explain_Limited_Type (Typ, N);
elsif Is_Class_Wide_Type (Typ) then
Error_Msg_N ("type of aggregate cannot be class-wide", N);
elsif Typ = Any_String
or else Typ = Any_Composite
then
Error_Msg_N ("no unique type for aggregate", N);
Set_Etype (N, Any_Composite);
elsif Is_Array_Type (Typ) and then Null_Record_Present (N) then
Error_Msg_N ("null record forbidden in array aggregate", N);
elsif Is_Record_Type (Typ) then
Resolve_Record_Aggregate (N, Typ);
elsif Is_Array_Type (Typ) then
-- First a special test, for the case of a positional aggregate of
-- characters which can be replaced by a string literal.
-- Do not perform this transformation if this was a string literal
-- to start with, whose components needed constraint checks, or if
-- the component type is non-static, because it will require those
-- checks and be transformed back into an aggregate. If the index
-- type is not Integer the aggregate may represent a user-defined
-- string type but the context might need the original type so we
-- do not perform the transformation at this point.
if Number_Dimensions (Typ) = 1
and then Is_Standard_Character_Type (Component_Type (Typ))
and then No (Component_Associations (N))
and then not Is_Limited_Composite (Typ)
and then not Is_Private_Composite (Typ)
and then not Is_Bit_Packed_Array (Typ)
and then Nkind (Original_Node (Parent (N))) /= N_String_Literal
and then Is_OK_Static_Subtype (Component_Type (Typ))
and then Base_Type (Etype (First_Index (Typ))) =
Base_Type (Standard_Integer)
then
declare
Expr : Node_Id;
begin
Expr := First (Expressions (N));
while Present (Expr) loop
exit when Nkind (Expr) /= N_Character_Literal;
Next (Expr);
end loop;
if No (Expr) then
Start_String;
Expr := First (Expressions (N));
while Present (Expr) loop
Store_String_Char (UI_To_CC (Char_Literal_Value (Expr)));
Next (Expr);
end loop;
Rewrite (N, Make_String_Literal (Loc, End_String));
Analyze_And_Resolve (N, Typ);
return;
end if;
end;
end if;
-- Here if we have a real aggregate to deal with
Array_Aggregate : declare
Aggr_Resolved : Boolean;
Aggr_Typ : constant Entity_Id := Etype (Typ);
-- This is the unconstrained array type, which is the type against
-- which the aggregate is to be resolved. Typ itself is the array
-- type of the context which may not be the same subtype as the
-- subtype for the final aggregate.
begin
-- In the following we determine whether an OTHERS choice is
-- allowed inside the array aggregate. The test checks the context
-- in which the array aggregate occurs. If the context does not
-- permit it, or the aggregate type is unconstrained, an OTHERS
-- choice is not allowed (except that it is always allowed on the
-- right-hand side of an assignment statement; in this case the
-- constrainedness of the type doesn't matter).
-- If expansion is disabled (generic context, or semantics-only
-- mode) actual subtypes cannot be constructed, and the type of an
-- object may be its unconstrained nominal type. However, if the
-- context is an assignment, we assume that OTHERS is allowed,
-- because the target of the assignment will have a constrained
-- subtype when fully compiled.
-- Note that there is no node for Explicit_Actual_Parameter.
-- To test for this context we therefore have to test for node
-- N_Parameter_Association which itself appears only if there is a
-- formal parameter. Consequently we also need to test for
-- N_Procedure_Call_Statement or N_Function_Call.
-- The context may be an N_Reference node, created by expansion.
-- Legality of the others clause was established in the source,
-- so the context is legal.
Set_Etype (N, Aggr_Typ); -- May be overridden later on
if Pkind = N_Assignment_Statement
or else (Is_Constrained (Typ)
and then
(Pkind = N_Parameter_Association or else
Pkind = N_Function_Call or else
Pkind = N_Procedure_Call_Statement or else
Pkind = N_Generic_Association or else
Pkind = N_Formal_Object_Declaration or else
Pkind = N_Simple_Return_Statement or else
Pkind = N_Object_Declaration or else
Pkind = N_Component_Declaration or else
Pkind = N_Parameter_Specification or else
Pkind = N_Qualified_Expression or else
Pkind = N_Reference or else
Pkind = N_Aggregate or else
Pkind = N_Extension_Aggregate or else
Pkind = N_Component_Association))
then
Aggr_Resolved :=
Resolve_Array_Aggregate
(N,
Index => First_Index (Aggr_Typ),
Index_Constr => First_Index (Typ),
Component_Typ => Component_Type (Typ),
Others_Allowed => True);
else
Aggr_Resolved :=
Resolve_Array_Aggregate
(N,
Index => First_Index (Aggr_Typ),
Index_Constr => First_Index (Aggr_Typ),
Component_Typ => Component_Type (Typ),
Others_Allowed => False);
end if;
if not Aggr_Resolved then
-- A parenthesized expression may have been intended as an
-- aggregate, leading to a type error when analyzing the
-- component. This can also happen for a nested component
-- (see Analyze_Aggr_Expr).
if Paren_Count (N) > 0 then
Error_Msg_N
("positional aggregate cannot have one component", N);
end if;
Aggr_Subtyp := Any_Composite;
else
Aggr_Subtyp := Array_Aggr_Subtype (N, Typ);
end if;
Set_Etype (N, Aggr_Subtyp);
end Array_Aggregate;
elsif Is_Private_Type (Typ)
and then Present (Full_View (Typ))
and then (In_Inlined_Body or In_Instance_Body)
and then Is_Composite_Type (Full_View (Typ))
then
Resolve (N, Full_View (Typ));
else
Error_Msg_N ("illegal context for aggregate", N);
end if;
-- If we can determine statically that the evaluation of the aggregate
-- raises Constraint_Error, then replace the aggregate with an
-- N_Raise_Constraint_Error node, but set the Etype to the right
-- aggregate subtype. Gigi needs this.
if Raises_Constraint_Error (N) then
Aggr_Subtyp := Etype (N);
Rewrite (N,
Make_Raise_Constraint_Error (Loc, Reason => CE_Range_Check_Failed));
Set_Raises_Constraint_Error (N);
Set_Etype (N, Aggr_Subtyp);
Set_Analyzed (N);
end if;
Check_Function_Writable_Actuals (N);
end Resolve_Aggregate;
-----------------------------
-- Resolve_Array_Aggregate --
-----------------------------
function Resolve_Array_Aggregate
(N : Node_Id;
Index : Node_Id;
Index_Constr : Node_Id;
Component_Typ : Entity_Id;
Others_Allowed : Boolean) return Boolean
is
Loc : constant Source_Ptr := Sloc (N);
Failure : constant Boolean := False;
Success : constant Boolean := True;
Index_Typ : constant Entity_Id := Etype (Index);
Index_Typ_Low : constant Node_Id := Type_Low_Bound (Index_Typ);
Index_Typ_High : constant Node_Id := Type_High_Bound (Index_Typ);
-- The type of the index corresponding to the array sub-aggregate along
-- with its low and upper bounds.
Index_Base : constant Entity_Id := Base_Type (Index_Typ);
Index_Base_Low : constant Node_Id := Type_Low_Bound (Index_Base);
Index_Base_High : constant Node_Id := Type_High_Bound (Index_Base);
-- Ditto for the base type
Others_Present : Boolean := False;
Nb_Choices : Nat := 0;
-- Contains the overall number of named choices in this sub-aggregate
function Add (Val : Uint; To : Node_Id) return Node_Id;
-- Creates a new expression node where Val is added to expression To.
-- Tries to constant fold whenever possible. To must be an already
-- analyzed expression.
procedure Check_Bound (BH : Node_Id; AH : in out Node_Id);
-- Checks that AH (the upper bound of an array aggregate) is less than
-- or equal to BH (the upper bound of the index base type). If the check
-- fails, a warning is emitted, the Raises_Constraint_Error flag of N is
-- set, and AH is replaced with a duplicate of BH.
procedure Check_Bounds (L, H : Node_Id; AL, AH : Node_Id);
-- Checks that range AL .. AH is compatible with range L .. H. Emits a
-- warning if not and sets the Raises_Constraint_Error flag in N.
procedure Check_Length (L, H : Node_Id; Len : Uint);
-- Checks that range L .. H contains at least Len elements. Emits a
-- warning if not and sets the Raises_Constraint_Error flag in N.
function Dynamic_Or_Null_Range (L, H : Node_Id) return Boolean;
-- Returns True if range L .. H is dynamic or null
procedure Get (Value : out Uint; From : Node_Id; OK : out Boolean);
-- Given expression node From, this routine sets OK to False if it
-- cannot statically evaluate From. Otherwise it stores this static
-- value into Value.
function Resolve_Aggr_Expr
(Expr : Node_Id;
Single_Elmt : Boolean) return Boolean;
-- Resolves aggregate expression Expr. Returns False if resolution
-- fails. If Single_Elmt is set to False, the expression Expr may be
-- used to initialize several array aggregate elements (this can happen
-- for discrete choices such as "L .. H => Expr" or the OTHERS choice).
-- In this event we do not resolve Expr unless expansion is disabled.
-- To know why, see the DELAYED COMPONENT RESOLUTION note above.
--
-- NOTE: In the case of "... => <>", we pass the in the
-- N_Component_Association node as Expr, since there is no Expression in
-- that case, and we need a Sloc for the error message.
procedure Resolve_Iterated_Component_Association
(N : Node_Id;
Index_Typ : Entity_Id);
-- For AI12-061
---------
-- Add --
---------
function Add (Val : Uint; To : Node_Id) return Node_Id is
Expr_Pos : Node_Id;
Expr : Node_Id;
To_Pos : Node_Id;
begin
if Raises_Constraint_Error (To) then
return To;
end if;
-- First test if we can do constant folding
if Compile_Time_Known_Value (To)
or else Nkind (To) = N_Integer_Literal
then
Expr_Pos := Make_Integer_Literal (Loc, Expr_Value (To) + Val);
Set_Is_Static_Expression (Expr_Pos);
Set_Etype (Expr_Pos, Etype (To));
Set_Analyzed (Expr_Pos, Analyzed (To));
if not Is_Enumeration_Type (Index_Typ) then
Expr := Expr_Pos;
-- If we are dealing with enumeration return
-- Index_Typ'Val (Expr_Pos)
else
Expr :=
Make_Attribute_Reference
(Loc,
Prefix => New_Occurrence_Of (Index_Typ, Loc),
Attribute_Name => Name_Val,
Expressions => New_List (Expr_Pos));
end if;
return Expr;
end if;
-- If we are here no constant folding possible
if not Is_Enumeration_Type (Index_Base) then
Expr :=
Make_Op_Add (Loc,
Left_Opnd => Duplicate_Subexpr (To),
Right_Opnd => Make_Integer_Literal (Loc, Val));
-- If we are dealing with enumeration return
-- Index_Typ'Val (Index_Typ'Pos (To) + Val)
else
To_Pos :=
Make_Attribute_Reference
(Loc,
Prefix => New_Occurrence_Of (Index_Typ, Loc),
Attribute_Name => Name_Pos,
Expressions => New_List (Duplicate_Subexpr (To)));
Expr_Pos :=
Make_Op_Add (Loc,
Left_Opnd => To_Pos,
Right_Opnd => Make_Integer_Literal (Loc, Val));
Expr :=
Make_Attribute_Reference
(Loc,
Prefix => New_Occurrence_Of (Index_Typ, Loc),
Attribute_Name => Name_Val,
Expressions => New_List (Expr_Pos));
-- If the index type has a non standard representation, the
-- attributes 'Val and 'Pos expand into function calls and the
-- resulting expression is considered non-safe for reevaluation
-- by the backend. Relocate it into a constant temporary in order
-- to make it safe for reevaluation.
if Has_Non_Standard_Rep (Etype (N)) then
declare
Def_Id : Entity_Id;
begin
Def_Id := Make_Temporary (Loc, 'R', Expr);
Set_Etype (Def_Id, Index_Typ);
Insert_Action (N,
Make_Object_Declaration (Loc,
Defining_Identifier => Def_Id,
Object_Definition =>
New_Occurrence_Of (Index_Typ, Loc),
Constant_Present => True,
Expression => Relocate_Node (Expr)));
Expr := New_Occurrence_Of (Def_Id, Loc);
end;
end if;
end if;
return Expr;
end Add;
-----------------
-- Check_Bound --
-----------------
procedure Check_Bound (BH : Node_Id; AH : in out Node_Id) is
Val_BH : Uint;
Val_AH : Uint;
OK_BH : Boolean;
OK_AH : Boolean;
begin
Get (Value => Val_BH, From => BH, OK => OK_BH);
Get (Value => Val_AH, From => AH, OK => OK_AH);
if OK_BH and then OK_AH and then Val_BH < Val_AH then
Set_Raises_Constraint_Error (N);
Error_Msg_Warn := SPARK_Mode /= On;
Error_Msg_N ("upper bound out of range<<", AH);
Error_Msg_N ("\Constraint_Error [<<", AH);
-- You need to set AH to BH or else in the case of enumerations
-- indexes we will not be able to resolve the aggregate bounds.
AH := Duplicate_Subexpr (BH);
end if;
end Check_Bound;
------------------
-- Check_Bounds --
------------------
procedure Check_Bounds (L, H : Node_Id; AL, AH : Node_Id) is
Val_L : Uint;
Val_H : Uint;
Val_AL : Uint;
Val_AH : Uint;
OK_L : Boolean;
OK_H : Boolean;
OK_AL : Boolean;
OK_AH : Boolean;
pragma Warnings (Off, OK_AL);
pragma Warnings (Off, OK_AH);
begin
if Raises_Constraint_Error (N)
or else Dynamic_Or_Null_Range (AL, AH)
then
return;
end if;
Get (Value => Val_L, From => L, OK => OK_L);
Get (Value => Val_H, From => H, OK => OK_H);
Get (Value => Val_AL, From => AL, OK => OK_AL);
Get (Value => Val_AH, From => AH, OK => OK_AH);
if OK_L and then Val_L > Val_AL then
Set_Raises_Constraint_Error (N);
Error_Msg_Warn := SPARK_Mode /= On;
Error_Msg_N ("lower bound of aggregate out of range<<", N);
Error_Msg_N ("\Constraint_Error [<<", N);
end if;
if OK_H and then Val_H < Val_AH then
Set_Raises_Constraint_Error (N);
Error_Msg_Warn := SPARK_Mode /= On;
Error_Msg_N ("upper bound of aggregate out of range<<", N);
Error_Msg_N ("\Constraint_Error [<<", N);
end if;
end Check_Bounds;
------------------
-- Check_Length --
------------------
procedure Check_Length (L, H : Node_Id; Len : Uint) is
Val_L : Uint;
Val_H : Uint;
OK_L : Boolean;
OK_H : Boolean;
Range_Len : Uint;
begin
if Raises_Constraint_Error (N) then
return;
end if;
Get (Value => Val_L, From => L, OK => OK_L);
Get (Value => Val_H, From => H, OK => OK_H);
if not OK_L or else not OK_H then
return;
end if;
-- If null range length is zero
if Val_L > Val_H then
Range_Len := Uint_0;
else
Range_Len := Val_H - Val_L + 1;
end if;
if Range_Len < Len then
Set_Raises_Constraint_Error (N);
Error_Msg_Warn := SPARK_Mode /= On;
Error_Msg_N ("too many elements<<", N);
Error_Msg_N ("\Constraint_Error [<<", N);
end if;
end Check_Length;
---------------------------
-- Dynamic_Or_Null_Range --
---------------------------
function Dynamic_Or_Null_Range (L, H : Node_Id) return Boolean is
Val_L : Uint;
Val_H : Uint;
OK_L : Boolean;
OK_H : Boolean;
begin
Get (Value => Val_L, From => L, OK => OK_L);
Get (Value => Val_H, From => H, OK => OK_H);
return not OK_L or else not OK_H
or else not Is_OK_Static_Expression (L)
or else not Is_OK_Static_Expression (H)
or else Val_L > Val_H;
end Dynamic_Or_Null_Range;
---------
-- Get --
---------
procedure Get (Value : out Uint; From : Node_Id; OK : out Boolean) is
begin
OK := True;
if Compile_Time_Known_Value (From) then
Value := Expr_Value (From);
-- If expression From is something like Some_Type'Val (10) then
-- Value = 10.
elsif Nkind (From) = N_Attribute_Reference
and then Attribute_Name (From) = Name_Val
and then Compile_Time_Known_Value (First (Expressions (From)))
then
Value := Expr_Value (First (Expressions (From)));
else
Value := Uint_0;
OK := False;
end if;
end Get;
-----------------------
-- Resolve_Aggr_Expr --
-----------------------
function Resolve_Aggr_Expr
(Expr : Node_Id;
Single_Elmt : Boolean) return Boolean
is
Nxt_Ind : constant Node_Id := Next_Index (Index);
Nxt_Ind_Constr : constant Node_Id := Next_Index (Index_Constr);
-- Index is the current index corresponding to the expression
Resolution_OK : Boolean := True;
-- Set to False if resolution of the expression failed
begin
-- Defend against previous errors
if Nkind (Expr) = N_Error
or else Error_Posted (Expr)
then
return True;
end if;
-- If the array type against which we are resolving the aggregate
-- has several dimensions, the expressions nested inside the
-- aggregate must be further aggregates (or strings).
if Present (Nxt_Ind) then
if Nkind (Expr) /= N_Aggregate then
-- A string literal can appear where a one-dimensional array
-- of characters is expected. If the literal looks like an
-- operator, it is still an operator symbol, which will be
-- transformed into a string when analyzed.
if Is_Character_Type (Component_Typ)
and then No (Next_Index (Nxt_Ind))
and then Nkind_In (Expr, N_String_Literal, N_Operator_Symbol)
then
-- A string literal used in a multidimensional array
-- aggregate in place of the final one-dimensional
-- aggregate must not be enclosed in parentheses.
if Paren_Count (Expr) /= 0 then
Error_Msg_N ("no parenthesis allowed here", Expr);
end if;
Make_String_Into_Aggregate (Expr);
else
Error_Msg_N ("nested array aggregate expected", Expr);
-- If the expression is parenthesized, this may be
-- a missing component association for a 1-aggregate.
if Paren_Count (Expr) > 0 then
Error_Msg_N
("\if single-component aggregate is intended, "
& "write e.g. (1 ='> ...)", Expr);
end if;
return Failure;
end if;
end if;
-- If it's "... => <>", nothing to resolve
if Nkind (Expr) = N_Component_Association then
pragma Assert (Box_Present (Expr));
return Success;
end if;
-- Ada 2005 (AI-231): Propagate the type to the nested aggregate.
-- Required to check the null-exclusion attribute (if present).
-- This value may be overridden later on.
Set_Etype (Expr, Etype (N));
Resolution_OK := Resolve_Array_Aggregate
(Expr, Nxt_Ind, Nxt_Ind_Constr, Component_Typ, Others_Allowed);
else
-- If it's "... => <>", nothing to resolve
if Nkind (Expr) = N_Component_Association then
pragma Assert (Box_Present (Expr));
return Success;
end if;
-- Do not resolve the expressions of discrete or others choices
-- unless the expression covers a single component, or the
-- expander is inactive.
-- In SPARK mode, expressions that can perform side-effects will
-- be recognized by the gnat2why back-end, and the whole
-- subprogram will be ignored. So semantic analysis can be
-- performed safely.
if Single_Elmt
or else not Expander_Active
or else In_Spec_Expression
then
Analyze_And_Resolve (Expr, Component_Typ);
Check_Expr_OK_In_Limited_Aggregate (Expr);
Check_Non_Static_Context (Expr);
Aggregate_Constraint_Checks (Expr, Component_Typ);
Check_Unset_Reference (Expr);
end if;
end if;
-- If an aggregate component has a type with predicates, an explicit
-- predicate check must be applied, as for an assignment statement,
-- because the aggegate might not be expanded into individual
-- component assignments. If the expression covers several components
-- the analysis and the predicate check take place later.
if Present (Predicate_Function (Component_Typ))
and then Analyzed (Expr)
then
Apply_Predicate_Check (Expr, Component_Typ);
end if;
if Raises_Constraint_Error (Expr)
and then Nkind (Parent (Expr)) /= N_Component_Association
then
Set_Raises_Constraint_Error (N);
end if;
-- If the expression has been marked as requiring a range check,
-- then generate it here. It's a bit odd to be generating such
-- checks in the analyzer, but harmless since Generate_Range_Check
-- does nothing (other than making sure Do_Range_Check is set) if
-- the expander is not active.
if Do_Range_Check (Expr) then
Generate_Range_Check (Expr, Component_Typ, CE_Range_Check_Failed);
end if;
return Resolution_OK;
end Resolve_Aggr_Expr;
--------------------------------------------
-- Resolve_Iterated_Component_Association --
--------------------------------------------
procedure Resolve_Iterated_Component_Association
(N : Node_Id;
Index_Typ : Entity_Id)
is
Id : constant Entity_Id := Defining_Identifier (N);
Loc : constant Source_Ptr := Sloc (N);
Choice : Node_Id;
Dummy : Boolean;
Ent : Entity_Id;
begin
Choice := First (Discrete_Choices (N));
while Present (Choice) loop
if Nkind (Choice) = N_Others_Choice then
Others_Present := True;
else
Analyze_And_Resolve (Choice, Index_Typ);
end if;
Next (Choice);
end loop;
-- Create a scope in which to introduce an index, which is usually
-- visible in the expression for the component, and needed for its
-- analysis.
Ent := New_Internal_Entity (E_Loop, Current_Scope, Loc, 'L');
Set_Etype (Ent, Standard_Void_Type);
Set_Parent (Ent, Parent (N));
-- Decorate the index variable in the current scope. The association
-- may have several choices, each one leading to a loop, so we create
-- this variable only once to prevent homonyms in this scope.
if No (Scope (Id)) then
Enter_Name (Id);
Set_Etype (Id, Index_Typ);
Set_Ekind (Id, E_Variable);
Set_Scope (Id, Ent);
end if;
Push_Scope (Ent);
Dummy := Resolve_Aggr_Expr (Expression (N), False);
End_Scope;
end Resolve_Iterated_Component_Association;
-- Local variables
Assoc : Node_Id;
Choice : Node_Id;
Expr : Node_Id;
Discard : Node_Id;
Aggr_Low : Node_Id := Empty;
Aggr_High : Node_Id := Empty;
-- The actual low and high bounds of this sub-aggregate
Case_Table_Size : Nat;
-- Contains the size of the case table needed to sort aggregate choices
Choices_Low : Node_Id := Empty;
Choices_High : Node_Id := Empty;
-- The lowest and highest discrete choices values for a named aggregate
Delete_Choice : Boolean;
-- Used when replacing a subtype choice with predicate by a list
Nb_Elements : Uint := Uint_0;
-- The number of elements in a positional aggregate
Nb_Discrete_Choices : Nat := 0;
-- The overall number of discrete choices (not counting others choice)
-- Start of processing for Resolve_Array_Aggregate
begin
-- Ignore junk empty aggregate resulting from parser error
if No (Expressions (N))
and then No (Component_Associations (N))
and then not Null_Record_Present (N)
then
return False;
end if;
-- STEP 1: make sure the aggregate is correctly formatted
if Present (Component_Associations (N)) then
Assoc := First (Component_Associations (N));
while Present (Assoc) loop
if Nkind (Assoc) = N_Iterated_Component_Association then
Resolve_Iterated_Component_Association (Assoc, Index_Typ);
end if;
Choice := First (Choice_List (Assoc));
Delete_Choice := False;
while Present (Choice) loop
if Nkind (Choice) = N_Others_Choice then
Others_Present := True;
if Choice /= First (Choice_List (Assoc))
or else Present (Next (Choice))
then
Error_Msg_N
("OTHERS must appear alone in a choice list", Choice);
return Failure;
end if;
if Present (Next (Assoc)) then
Error_Msg_N
("OTHERS must appear last in an aggregate", Choice);
return Failure;
end if;
if Ada_Version = Ada_83
and then Assoc /= First (Component_Associations (N))
and then Nkind_In (Parent (N), N_Assignment_Statement,
N_Object_Declaration)
then
Error_Msg_N
("(Ada 83) illegal context for OTHERS choice", N);
end if;
elsif Is_Entity_Name (Choice) then
Analyze (Choice);
declare
E : constant Entity_Id := Entity (Choice);
New_Cs : List_Id;
P : Node_Id;
C : Node_Id;
begin
if Is_Type (E) and then Has_Predicates (E) then
Freeze_Before (N, E);
if Has_Dynamic_Predicate_Aspect (E) then
Error_Msg_NE
("subtype& has dynamic predicate, not allowed "
& "in aggregate choice", Choice, E);
elsif not Is_OK_Static_Subtype (E) then
Error_Msg_NE
("non-static subtype& has predicate, not allowed "
& "in aggregate choice", Choice, E);
end if;
-- If the subtype has a static predicate, replace the
-- original choice with the list of individual values
-- covered by the predicate. Do not perform this
-- transformation if we need to preserve the source
-- for ASIS use.
-- This should be deferred to expansion time ???
if Present (Static_Discrete_Predicate (E))
and then not ASIS_Mode
then
Delete_Choice := True;
New_Cs := New_List;
P := First (Static_Discrete_Predicate (E));
while Present (P) loop
C := New_Copy (P);
Set_Sloc (C, Sloc (Choice));
Append_To (New_Cs, C);
Next (P);
end loop;
Insert_List_After (Choice, New_Cs);
end if;
end if;
end;
end if;
Nb_Choices := Nb_Choices + 1;
declare
C : constant Node_Id := Choice;
begin
Next (Choice);
if Delete_Choice then
Remove (C);
Nb_Choices := Nb_Choices - 1;
Delete_Choice := False;
end if;
end;
end loop;
Next (Assoc);
end loop;
end if;
-- At this point we know that the others choice, if present, is by
-- itself and appears last in the aggregate. Check if we have mixed
-- positional and discrete associations (other than the others choice).
if Present (Expressions (N))
and then (Nb_Choices > 1
or else (Nb_Choices = 1 and then not Others_Present))
then
Error_Msg_N
("named association cannot follow positional association",
First (Choice_List (First (Component_Associations (N)))));
return Failure;
end if;
-- Test for the validity of an others choice if present
if Others_Present and then not Others_Allowed then
Error_Msg_N
("OTHERS choice not allowed here",
First (Choices (First (Component_Associations (N)))));
return Failure;
end if;
-- Protect against cascaded errors
if Etype (Index_Typ) = Any_Type then
return Failure;
end if;
-- STEP 2: Process named components
if No (Expressions (N)) then
if Others_Present then
Case_Table_Size := Nb_Choices - 1;
else
Case_Table_Size := Nb_Choices;
end if;
Step_2 : declare
function Empty_Range (A : Node_Id) return Boolean;
-- If an association covers an empty range, some warnings on the
-- expression of the association can be disabled.
-----------------
-- Empty_Range --
-----------------
function Empty_Range (A : Node_Id) return Boolean is
R : constant Node_Id := First (Choices (A));
begin
return No (Next (R))
and then Nkind (R) = N_Range
and then Compile_Time_Compare
(Low_Bound (R), High_Bound (R), False) = GT;
end Empty_Range;
-- Local variables
Low : Node_Id;
High : Node_Id;
-- Denote the lowest and highest values in an aggregate choice
S_Low : Node_Id := Empty;
S_High : Node_Id := Empty;
-- if a choice in an aggregate is a subtype indication these
-- denote the lowest and highest values of the subtype
Table : Case_Table_Type (0 .. Case_Table_Size);
-- Used to sort all the different choice values. Entry zero is
-- reserved for sorting purposes.
Single_Choice : Boolean;
-- Set to true every time there is a single discrete choice in a
-- discrete association
Prev_Nb_Discrete_Choices : Nat;
-- Used to keep track of the number of discrete choices in the
-- current association.
Errors_Posted_On_Choices : Boolean := False;
-- Keeps track of whether any choices have semantic errors
-- Start of processing for Step_2
begin
-- STEP 2 (A): Check discrete choices validity
Assoc := First (Component_Associations (N));
while Present (Assoc) loop
Prev_Nb_Discrete_Choices := Nb_Discrete_Choices;
Choice := First (Choice_List (Assoc));
loop
Analyze (Choice);
if Nkind (Choice) = N_Others_Choice then
Single_Choice := False;
exit;
-- Test for subtype mark without constraint
elsif Is_Entity_Name (Choice) and then
Is_Type (Entity (Choice))
then
if Base_Type (Entity (Choice)) /= Index_Base then
Error_Msg_N
("invalid subtype mark in aggregate choice",
Choice);
return Failure;
end if;
-- Case of subtype indication
elsif Nkind (Choice) = N_Subtype_Indication then
Resolve_Discrete_Subtype_Indication (Choice, Index_Base);
if Has_Dynamic_Predicate_Aspect
(Entity (Subtype_Mark (Choice)))
then
Error_Msg_NE
("subtype& has dynamic predicate, "
& "not allowed in aggregate choice",
Choice, Entity (Subtype_Mark (Choice)));
end if;
-- Does the subtype indication evaluation raise CE?
Get_Index_Bounds (Subtype_Mark (Choice), S_Low, S_High);
Get_Index_Bounds (Choice, Low, High);
Check_Bounds (S_Low, S_High, Low, High);
-- Case of range or expression
else
Resolve (Choice, Index_Base);
Check_Unset_Reference (Choice);
Check_Non_Static_Context (Choice);
-- If semantic errors were posted on the choice, then
-- record that for possible early return from later
-- processing (see handling of enumeration choices).
if Error_Posted (Choice) then
Errors_Posted_On_Choices := True;
end if;
-- Do not range check a choice. This check is redundant
-- since this test is already done when we check that the
-- bounds of the array aggregate are within range.
Set_Do_Range_Check (Choice, False);
-- In SPARK, the choice must be static
if not (Is_OK_Static_Expression (Choice)
or else (Nkind (Choice) = N_Range
and then Is_OK_Static_Range (Choice)))
then
Check_SPARK_05_Restriction
("choice should be static", Choice);
end if;
end if;
-- If we could not resolve the discrete choice stop here
if Etype (Choice) = Any_Type then
return Failure;
-- If the discrete choice raises CE get its original bounds
elsif Nkind (Choice) = N_Raise_Constraint_Error then
Set_Raises_Constraint_Error (N);
Get_Index_Bounds (Original_Node (Choice), Low, High);
-- Otherwise get its bounds as usual
else
Get_Index_Bounds (Choice, Low, High);
end if;
if (Dynamic_Or_Null_Range (Low, High)
or else (Nkind (Choice) = N_Subtype_Indication
and then
Dynamic_Or_Null_Range (S_Low, S_High)))
and then Nb_Choices /= 1
then
Error_Msg_N
("dynamic or empty choice in aggregate "
& "must be the only choice", Choice);
return Failure;
end if;
if not (All_Composite_Constraints_Static (Low)
and then All_Composite_Constraints_Static (High)
and then All_Composite_Constraints_Static (S_Low)
and then All_Composite_Constraints_Static (S_High))
then
Check_Restriction (No_Dynamic_Sized_Objects, Choice);
end if;
Nb_Discrete_Choices := Nb_Discrete_Choices + 1;
Table (Nb_Discrete_Choices).Lo := Low;
Table (Nb_Discrete_Choices).Hi := High;
Table (Nb_Discrete_Choices).Choice := Choice;
Next (Choice);
if No (Choice) then
-- Check if we have a single discrete choice and whether
-- this discrete choice specifies a single value.
Single_Choice :=
(Nb_Discrete_Choices = Prev_Nb_Discrete_Choices + 1)
and then (Low = High);
exit;
end if;
end loop;
-- Ada 2005 (AI-231)
if Ada_Version >= Ada_2005
and then Known_Null (Expression (Assoc))
and then not Empty_Range (Assoc)
then
Check_Can_Never_Be_Null (Etype (N), Expression (Assoc));
end if;
-- Ada 2005 (AI-287): In case of default initialized component
-- we delay the resolution to the expansion phase.
if Box_Present (Assoc) then
-- Ada 2005 (AI-287): In case of default initialization of a
-- component the expander will generate calls to the
-- corresponding initialization subprogram. We need to call
-- Resolve_Aggr_Expr to check the rules about
-- dimensionality.
if not Resolve_Aggr_Expr
(Assoc, Single_Elmt => Single_Choice)
then
return Failure;
end if;
elsif Nkind (Assoc) = N_Iterated_Component_Association then
null; -- handled above, in a loop context.
elsif not Resolve_Aggr_Expr
(Expression (Assoc), Single_Elmt => Single_Choice)
then
return Failure;
-- Check incorrect use of dynamically tagged expression
-- We differentiate here two cases because the expression may
-- not be decorated. For example, the analysis and resolution
-- of the expression associated with the others choice will be
-- done later with the full aggregate. In such case we
-- duplicate the expression tree to analyze the copy and
-- perform the required check.
elsif not Present (Etype (Expression (Assoc))) then
declare
Save_Analysis : constant Boolean := Full_Analysis;
Expr : constant Node_Id :=
New_Copy_Tree (Expression (Assoc));
begin
Expander_Mode_Save_And_Set (False);
Full_Analysis := False;
-- Analyze the expression, making sure it is properly
-- attached to the tree before we do the analysis.
Set_Parent (Expr, Parent (Expression (Assoc)));
Analyze (Expr);
-- Compute its dimensions now, rather than at the end of
-- resolution, because in the case of multidimensional
-- aggregates subsequent expansion may lead to spurious
-- errors.
Check_Expression_Dimensions (Expr, Component_Typ);
-- If the expression is a literal, propagate this info
-- to the expression in the association, to enable some
-- optimizations downstream.
if Is_Entity_Name (Expr)
and then Present (Entity (Expr))
and then Ekind (Entity (Expr)) = E_Enumeration_Literal
then
Analyze_And_Resolve
(Expression (Assoc), Component_Typ);
end if;
Full_Analysis := Save_Analysis;
Expander_Mode_Restore;
if Is_Tagged_Type (Etype (Expr)) then
Check_Dynamically_Tagged_Expression
(Expr => Expr,
Typ => Component_Type (Etype (N)),
Related_Nod => N);
end if;
end;
elsif Is_Tagged_Type (Etype (Expression (Assoc))) then
Check_Dynamically_Tagged_Expression
(Expr => Expression (Assoc),
Typ => Component_Type (Etype (N)),
Related_Nod => N);
end if;
Next (Assoc);
end loop;
-- If aggregate contains more than one choice then these must be
-- static. Check for duplicate and missing values.
-- Note: there is duplicated code here wrt Check_Choice_Set in
-- the body of Sem_Case, and it is possible we could just reuse
-- that procedure. To be checked ???
if Nb_Discrete_Choices > 1 then
Check_Choices : declare
Choice : Node_Id;
-- Location of choice for messages
Hi_Val : Uint;
Lo_Val : Uint;
-- High end of one range and Low end of the next. Should be
-- contiguous if there is no hole in the list of values.
Lo_Dup : Uint;
Hi_Dup : Uint;
-- End points of duplicated range
Missing_Or_Duplicates : Boolean := False;
-- Set True if missing or duplicate choices found
procedure Output_Bad_Choices (Lo, Hi : Uint; C : Node_Id);
-- Output continuation message with a representation of the
-- bounds (just Lo if Lo = Hi, else Lo .. Hi). C is the
-- choice node where the message is to be posted.
------------------------
-- Output_Bad_Choices --
------------------------
procedure Output_Bad_Choices (Lo, Hi : Uint; C : Node_Id) is
begin
-- Enumeration type case
if Is_Enumeration_Type (Index_Typ) then
Error_Msg_Name_1 :=
Chars (Get_Enum_Lit_From_Pos (Index_Typ, Lo, Loc));
Error_Msg_Name_2 :=
Chars (Get_Enum_Lit_From_Pos (Index_Typ, Hi, Loc));
if Lo = Hi then
Error_Msg_N ("\\ %!", C);
else
Error_Msg_N ("\\ % .. %!", C);
end if;
-- Integer types case
else
Error_Msg_Uint_1 := Lo;
Error_Msg_Uint_2 := Hi;
if Lo = Hi then
Error_Msg_N ("\\ ^!", C);
else
Error_Msg_N ("\\ ^ .. ^!", C);
end if;
end if;
end Output_Bad_Choices;
-- Start of processing for Check_Choices
begin
Sort_Case_Table (Table);
-- First we do a quick linear loop to find out if we have
-- any duplicates or missing entries (usually we have a
-- legal aggregate, so this will get us out quickly).
for J in 1 .. Nb_Discrete_Choices - 1 loop
Hi_Val := Expr_Value (Table (J).Hi);
Lo_Val := Expr_Value (Table (J + 1).Lo);
if Lo_Val <= Hi_Val
or else (Lo_Val > Hi_Val + 1
and then not Others_Present)
then
Missing_Or_Duplicates := True;
exit;
end if;
end loop;
-- If we have missing or duplicate entries, first fill in
-- the Highest entries to make life easier in the following
-- loops to detect bad entries.
if Missing_Or_Duplicates then
Table (1).Highest := Expr_Value (Table (1).Hi);
for J in 2 .. Nb_Discrete_Choices loop
Table (J).Highest :=
UI_Max
(Table (J - 1).Highest, Expr_Value (Table (J).Hi));
end loop;
-- Loop through table entries to find duplicate indexes
for J in 2 .. Nb_Discrete_Choices loop
Lo_Val := Expr_Value (Table (J).Lo);
Hi_Val := Expr_Value (Table (J).Hi);
-- Case where we have duplicates (the lower bound of
-- this choice is less than or equal to the highest
-- high bound found so far).
if Lo_Val <= Table (J - 1).Highest then
-- We move backwards looking for duplicates. We can
-- abandon this loop as soon as we reach a choice
-- highest value that is less than Lo_Val.
for K in reverse 1 .. J - 1 loop
exit when Table (K).Highest < Lo_Val;
-- Here we may have duplicates between entries
-- for K and J. Get range of duplicates.
Lo_Dup :=
UI_Max (Lo_Val, Expr_Value (Table (K).Lo));
Hi_Dup :=
UI_Min (Hi_Val, Expr_Value (Table (K).Hi));
-- Nothing to do if duplicate range is null
if Lo_Dup > Hi_Dup then
null;
-- Otherwise place proper message. Because
-- of the missing expansion of subtypes with
-- predicates in ASIS mode, do not report
-- spurious overlap errors.
elsif ASIS_Mode
and then
((Is_Type (Entity (Table (J).Choice))
and then Has_Predicates
(Entity (Table (J).Choice)))
or else
(Is_Type (Entity (Table (K).Choice))
and then Has_Predicates
(Entity (Table (K).Choice))))
then
null;
else
-- We place message on later choice, with a
-- line reference to the earlier choice.
if Sloc (Table (J).Choice) <
Sloc (Table (K).Choice)
then
Choice := Table (K).Choice;
Error_Msg_Sloc := Sloc (Table (J).Choice);
else
Choice := Table (J).Choice;
Error_Msg_Sloc := Sloc (Table (K).Choice);
end if;
if Lo_Dup = Hi_Dup then
Error_Msg_N
("index value in array aggregate "
& "duplicates the one given#!", Choice);
else
Error_Msg_N
("index values in array aggregate "
& "duplicate those given#!", Choice);
end if;
Output_Bad_Choices (Lo_Dup, Hi_Dup, Choice);
end if;
end loop;
end if;
end loop;
-- Loop through entries in table to find missing indexes.
-- Not needed if others, since missing impossible.
if not Others_Present then
for J in 2 .. Nb_Discrete_Choices loop
Lo_Val := Expr_Value (Table (J).Lo);
Hi_Val := Table (J - 1).Highest;
if Lo_Val > Hi_Val + 1 then
declare
Error_Node : Node_Id;
begin
-- If the choice is the bound of a range in
-- a subtype indication, it is not in the
-- source lists for the aggregate itself, so
-- post the error on the aggregate. Otherwise
-- post it on choice itself.
Choice := Table (J).Choice;
if Is_List_Member (Choice) then
Error_Node := Choice;
else
Error_Node := N;
end if;
if Hi_Val + 1 = Lo_Val - 1 then
Error_Msg_N
("missing index value "
& "in array aggregate!", Error_Node);
else
Error_Msg_N
("missing index values "
& "in array aggregate!", Error_Node);
end if;
Output_Bad_Choices
(Hi_Val + 1, Lo_Val - 1, Error_Node);
end;
end if;
end loop;
end if;
-- If either missing or duplicate values, return failure
Set_Etype (N, Any_Composite);
return Failure;
end if;
end Check_Choices;
end if;
-- STEP 2 (B): Compute aggregate bounds and min/max choices values
if Nb_Discrete_Choices > 0 then
Choices_Low := Table (1).Lo;
Choices_High := Table (Nb_Discrete_Choices).Hi;
end if;
-- If Others is present, then bounds of aggregate come from the
-- index constraint (not the choices in the aggregate itself).
if Others_Present then
Get_Index_Bounds (Index_Constr, Aggr_Low, Aggr_High);
-- Abandon processing if either bound is already signalled as
-- an error (prevents junk cascaded messages and blow ups).
if Nkind (Aggr_Low) = N_Error
or else
Nkind (Aggr_High) = N_Error
then
return False;
end if;
-- No others clause present
else
-- Special processing if others allowed and not present. This
-- means that the bounds of the aggregate come from the index
-- constraint (and the length must match).
if Others_Allowed then
Get_Index_Bounds (Index_Constr, Aggr_Low, Aggr_High);
-- Abandon processing if either bound is already signalled
-- as an error (stop junk cascaded messages and blow ups).
if Nkind (Aggr_Low) = N_Error
or else
Nkind (Aggr_High) = N_Error
then
return False;
end if;
-- If others allowed, and no others present, then the array
-- should cover all index values. If it does not, we will
-- get a length check warning, but there is two cases where
-- an additional warning is useful:
-- If we have no positional components, and the length is
-- wrong (which we can tell by others being allowed with
-- missing components), and the index type is an enumeration
-- type, then issue appropriate warnings about these missing
-- components. They are only warnings, since the aggregate
-- is fine, it's just the wrong length. We skip this check
-- for standard character types (since there are no literals
-- and it is too much trouble to concoct them), and also if
-- any of the bounds have values that are not known at
-- compile time.
-- Another case warranting a warning is when the length
-- is right, but as above we have an index type that is
-- an enumeration, and the bounds do not match. This is a
-- case where dubious sliding is allowed and we generate a
-- warning that the bounds do not match.
if No (Expressions (N))
and then Nkind (Index) = N_Range
and then Is_Enumeration_Type (Etype (Index))
and then not Is_Standard_Character_Type (Etype (Index))
and then Compile_Time_Known_Value (Aggr_Low)
and then Compile_Time_Known_Value (Aggr_High)
and then Compile_Time_Known_Value (Choices_Low)
and then Compile_Time_Known_Value (Choices_High)
then
-- If any of the expressions or range bounds in choices
-- have semantic errors, then do not attempt further
-- resolution, to prevent cascaded errors.
if Errors_Posted_On_Choices then
return Failure;
end if;
declare
ALo : constant Node_Id := Expr_Value_E (Aggr_Low);
AHi : constant Node_Id := Expr_Value_E (Aggr_High);
CLo : constant Node_Id := Expr_Value_E (Choices_Low);
CHi : constant Node_Id := Expr_Value_E (Choices_High);
Ent : Entity_Id;
begin
-- Warning case 1, missing values at start/end. Only
-- do the check if the number of entries is too small.
if (Enumeration_Pos (CHi) - Enumeration_Pos (CLo))
<
(Enumeration_Pos (AHi) - Enumeration_Pos (ALo))
then
Error_Msg_N
("missing index value(s) in array aggregate??",
N);
-- Output missing value(s) at start
if Chars (ALo) /= Chars (CLo) then
Ent := Prev (CLo);
if Chars (ALo) = Chars (Ent) then
Error_Msg_Name_1 := Chars (ALo);
Error_Msg_N ("\ %??", N);
else
Error_Msg_Name_1 := Chars (ALo);
Error_Msg_Name_2 := Chars (Ent);
Error_Msg_N ("\ % .. %??", N);
end if;
end if;
-- Output missing value(s) at end
if Chars (AHi) /= Chars (CHi) then
Ent := Next (CHi);
if Chars (AHi) = Chars (Ent) then
Error_Msg_Name_1 := Chars (Ent);
Error_Msg_N ("\ %??", N);
else
Error_Msg_Name_1 := Chars (Ent);
Error_Msg_Name_2 := Chars (AHi);
Error_Msg_N ("\ % .. %??", N);
end if;
end if;
-- Warning case 2, dubious sliding. The First_Subtype
-- test distinguishes between a constrained type where
-- sliding is not allowed (so we will get a warning
-- later that Constraint_Error will be raised), and
-- the unconstrained case where sliding is permitted.
elsif (Enumeration_Pos (CHi) - Enumeration_Pos (CLo))
=
(Enumeration_Pos (AHi) - Enumeration_Pos (ALo))
and then Chars (ALo) /= Chars (CLo)
and then
not Is_Constrained (First_Subtype (Etype (N)))
then
Error_Msg_N
("bounds of aggregate do not match target??", N);
end if;
end;
end if;
end if;
-- If no others, aggregate bounds come from aggregate
Aggr_Low := Choices_Low;
Aggr_High := Choices_High;
end if;
end Step_2;
-- STEP 3: Process positional components
else
-- STEP 3 (A): Process positional elements
Expr := First (Expressions (N));
Nb_Elements := Uint_0;
while Present (Expr) loop
Nb_Elements := Nb_Elements + 1;
-- Ada 2005 (AI-231)
if Ada_Version >= Ada_2005 and then Known_Null (Expr) then
Check_Can_Never_Be_Null (Etype (N), Expr);
end if;
if not Resolve_Aggr_Expr (Expr, Single_Elmt => True) then
return Failure;
end if;
-- Check incorrect use of dynamically tagged expression
if Is_Tagged_Type (Etype (Expr)) then
Check_Dynamically_Tagged_Expression
(Expr => Expr,
Typ => Component_Type (Etype (N)),
Related_Nod => N);
end if;
Next (Expr);
end loop;
if Others_Present then
Assoc := Last (Component_Associations (N));
-- Ada 2005 (AI-231)
if Ada_Version >= Ada_2005 and then Known_Null (Assoc) then
Check_Can_Never_Be_Null (Etype (N), Expression (Assoc));
end if;
-- Ada 2005 (AI-287): In case of default initialized component,
-- we delay the resolution to the expansion phase.
if Box_Present (Assoc) then
-- Ada 2005 (AI-287): In case of default initialization of a
-- component the expander will generate calls to the
-- corresponding initialization subprogram. We need to call
-- Resolve_Aggr_Expr to check the rules about
-- dimensionality.
if not Resolve_Aggr_Expr (Assoc, Single_Elmt => False) then
return Failure;
end if;
elsif not Resolve_Aggr_Expr (Expression (Assoc),
Single_Elmt => False)
then
return Failure;
-- Check incorrect use of dynamically tagged expression. The
-- expression of the others choice has not been resolved yet.
-- In order to diagnose the semantic error we create a duplicate
-- tree to analyze it and perform the check.
else
declare
Save_Analysis : constant Boolean := Full_Analysis;
Expr : constant Node_Id :=
New_Copy_Tree (Expression (Assoc));
begin
Expander_Mode_Save_And_Set (False);
Full_Analysis := False;
Analyze (Expr);
Full_Analysis := Save_Analysis;
Expander_Mode_Restore;
if Is_Tagged_Type (Etype (Expr)) then
Check_Dynamically_Tagged_Expression
(Expr => Expr,
Typ => Component_Type (Etype (N)),
Related_Nod => N);
end if;
end;
end if;
end if;
-- STEP 3 (B): Compute the aggregate bounds
if Others_Present then
Get_Index_Bounds (Index_Constr, Aggr_Low, Aggr_High);
else
if Others_Allowed then
Get_Index_Bounds (Index_Constr, Aggr_Low, Discard);
else
Aggr_Low := Index_Typ_Low;
end if;
Aggr_High := Add (Nb_Elements - 1, To => Aggr_Low);
Check_Bound (Index_Base_High, Aggr_High);
end if;
end if;
-- STEP 4: Perform static aggregate checks and save the bounds
-- Check (A)
Check_Bounds (Index_Typ_Low, Index_Typ_High, Aggr_Low, Aggr_High);
Check_Bounds (Index_Base_Low, Index_Base_High, Aggr_Low, Aggr_High);
-- Check (B)
if Others_Present and then Nb_Discrete_Choices > 0 then
Check_Bounds (Aggr_Low, Aggr_High, Choices_Low, Choices_High);
Check_Bounds (Index_Typ_Low, Index_Typ_High,
Choices_Low, Choices_High);
Check_Bounds (Index_Base_Low, Index_Base_High,
Choices_Low, Choices_High);
-- Check (C)
elsif Others_Present and then Nb_Elements > 0 then
Check_Length (Aggr_Low, Aggr_High, Nb_Elements);
Check_Length (Index_Typ_Low, Index_Typ_High, Nb_Elements);
Check_Length (Index_Base_Low, Index_Base_High, Nb_Elements);
end if;
if Raises_Constraint_Error (Aggr_Low)
or else Raises_Constraint_Error (Aggr_High)
then
Set_Raises_Constraint_Error (N);
end if;
Aggr_Low := Duplicate_Subexpr (Aggr_Low);
-- Do not duplicate Aggr_High if Aggr_High = Aggr_Low + Nb_Elements
-- since the addition node returned by Add is not yet analyzed. Attach
-- to tree and analyze first. Reset analyzed flag to ensure it will get
-- analyzed when it is a literal bound whose type must be properly set.
if Others_Present or else Nb_Discrete_Choices > 0 then
Aggr_High := Duplicate_Subexpr (Aggr_High);
if Etype (Aggr_High) = Universal_Integer then
Set_Analyzed (Aggr_High, False);
end if;
end if;
-- If the aggregate already has bounds attached to it, it means this is
-- a positional aggregate created as an optimization by
-- Exp_Aggr.Convert_To_Positional, so we don't want to change those
-- bounds.
if Present (Aggregate_Bounds (N)) and then not Others_Allowed then
Aggr_Low := Low_Bound (Aggregate_Bounds (N));
Aggr_High := High_Bound (Aggregate_Bounds (N));
end if;
Set_Aggregate_Bounds
(N, Make_Range (Loc, Low_Bound => Aggr_Low, High_Bound => Aggr_High));
-- The bounds may contain expressions that must be inserted upwards.
-- Attach them fully to the tree. After analysis, remove side effects
-- from upper bound, if still needed.
Set_Parent (Aggregate_Bounds (N), N);
Analyze_And_Resolve (Aggregate_Bounds (N), Index_Typ);
Check_Unset_Reference (Aggregate_Bounds (N));
if not Others_Present and then Nb_Discrete_Choices = 0 then
Set_High_Bound
(Aggregate_Bounds (N),
Duplicate_Subexpr (High_Bound (Aggregate_Bounds (N))));
end if;
-- Check the dimensions of each component in the array aggregate
Analyze_Dimension_Array_Aggregate (N, Component_Typ);
return Success;
end Resolve_Array_Aggregate;
-----------------------------
-- Resolve_Delta_Aggregate --
-----------------------------
procedure Resolve_Delta_Aggregate (N : Node_Id; Typ : Entity_Id) is
Base : constant Node_Id := Expression (N);
Deltas : constant List_Id := Component_Associations (N);
function Get_Component_Type (Nam : Node_Id) return Entity_Id;
------------------------
-- Get_Component_Type --
------------------------
function Get_Component_Type (Nam : Node_Id) return Entity_Id is
Comp : Entity_Id;
begin
Comp := First_Entity (Typ);
while Present (Comp) loop
if Chars (Comp) = Chars (Nam) then
if Ekind (Comp) = E_Discriminant then
Error_Msg_N ("delta cannot apply to discriminant", Nam);
end if;
return Etype (Comp);
end if;
Comp := Next_Entity (Comp);
end loop;
Error_Msg_NE ("type& has no component with this name", Nam, Typ);
return Any_Type;
end Get_Component_Type;
-- Local variables
Assoc : Node_Id;
Choice : Node_Id;
Comp_Type : Entity_Id;
Index_Type : Entity_Id;
-- Start of processing for Resolve_Delta_Aggregate
begin
if not Is_Composite_Type (Typ) then
Error_Msg_N ("not a composite type", N);
end if;
Analyze_And_Resolve (Base, Typ);
if Is_Array_Type (Typ) then
Index_Type := Etype (First_Index (Typ));
Assoc := First (Deltas);
while Present (Assoc) loop
if Nkind (Assoc) = N_Iterated_Component_Association then
Choice := First (Choice_List (Assoc));
while Present (Choice) loop
if Nkind (Choice) = N_Others_Choice then
Error_Msg_N
("others not allowed in delta aggregate", Choice);
else
Analyze_And_Resolve (Choice, Index_Type);
end if;
Next (Choice);
end loop;
declare
Id : constant Entity_Id := Defining_Identifier (Assoc);
Ent : constant Entity_Id :=
New_Internal_Entity
(E_Loop, Current_Scope, Sloc (Assoc), 'L');
begin
Set_Etype (Ent, Standard_Void_Type);
Set_Parent (Ent, Assoc);
if No (Scope (Id)) then
Enter_Name (Id);
Set_Etype (Id, Index_Type);
Set_Ekind (Id, E_Variable);
Set_Scope (Id, Ent);
end if;
Push_Scope (Ent);
Analyze_And_Resolve
(New_Copy_Tree (Expression (Assoc)), Component_Type (Typ));
End_Scope;
end;
else
Choice := First (Choice_List (Assoc));
while Present (Choice) loop
if Nkind (Choice) = N_Others_Choice then
Error_Msg_N
("others not allowed in delta aggregate", Choice);
else
Analyze (Choice);
if Is_Entity_Name (Choice)
and then Is_Type (Entity (Choice))
then
-- Choice covers a range of values.
if Base_Type (Entity (Choice)) /=
Base_Type (Index_Type)
then
Error_Msg_NE
("choice does mat match index type of",
Choice, Typ);
end if;
else
Resolve (Choice, Index_Type);
end if;
end if;
Next (Choice);
end loop;
Analyze_And_Resolve (Expression (Assoc), Component_Type (Typ));
end if;
Next (Assoc);
end loop;
else
Assoc := First (Deltas);
while Present (Assoc) loop
Choice := First (Choice_List (Assoc));
while Present (Choice) loop
Comp_Type := Get_Component_Type (Choice);
Next (Choice);
end loop;
Analyze_And_Resolve (Expression (Assoc), Comp_Type);
Next (Assoc);
end loop;
end if;
Set_Etype (N, Typ);
end Resolve_Delta_Aggregate;
---------------------------------
-- Resolve_Extension_Aggregate --
---------------------------------
-- There are two cases to consider:
-- a) If the ancestor part is a type mark, the components needed are the
-- difference between the components of the expected type and the
-- components of the given type mark.
-- b) If the ancestor part is an expression, it must be unambiguous, and
-- once we have its type we can also compute the needed components as in
-- the previous case. In both cases, if the ancestor type is not the
-- immediate ancestor, we have to build this ancestor recursively.
-- In both cases, discriminants of the ancestor type do not play a role in
-- the resolution of the needed components, because inherited discriminants
-- cannot be used in a type extension. As a result we can compute
-- independently the list of components of the ancestor type and of the
-- expected type.
procedure Resolve_Extension_Aggregate (N : Node_Id; Typ : Entity_Id) is
A : constant Node_Id := Ancestor_Part (N);
A_Type : Entity_Id;
I : Interp_Index;
It : Interp;
function Valid_Limited_Ancestor (Anc : Node_Id) return Boolean;
-- If the type is limited, verify that the ancestor part is a legal
-- expression (aggregate or function call, including 'Input)) that does
-- not require a copy, as specified in 7.5(2).
function Valid_Ancestor_Type return Boolean;
-- Verify that the type of the ancestor part is a non-private ancestor
-- of the expected type, which must be a type extension.
----------------------------
-- Valid_Limited_Ancestor --
----------------------------
function Valid_Limited_Ancestor (Anc : Node_Id) return Boolean is
begin
if Is_Entity_Name (Anc) and then Is_Type (Entity (Anc)) then
return True;
-- The ancestor must be a call or an aggregate, but a call may
-- have been expanded into a temporary, so check original node.
elsif Nkind_In (Anc, N_Aggregate,
N_Extension_Aggregate,
N_Function_Call)
then
return True;
elsif Nkind (Original_Node (Anc)) = N_Function_Call then
return True;
elsif Nkind (Anc) = N_Attribute_Reference
and then Attribute_Name (Anc) = Name_Input
then
return True;
elsif Nkind (Anc) = N_Qualified_Expression then
return Valid_Limited_Ancestor (Expression (Anc));
else
return False;
end if;
end Valid_Limited_Ancestor;
-------------------------
-- Valid_Ancestor_Type --
-------------------------
function Valid_Ancestor_Type return Boolean is
Imm_Type : Entity_Id;
begin
Imm_Type := Base_Type (Typ);
while Is_Derived_Type (Imm_Type) loop
if Etype (Imm_Type) = Base_Type (A_Type) then
return True;
-- The base type of the parent type may appear as a private
-- extension if it is declared as such in a parent unit of the
-- current one. For consistency of the subsequent analysis use
-- the partial view for the ancestor part.
elsif Is_Private_Type (Etype (Imm_Type))
and then Present (Full_View (Etype (Imm_Type)))
and then Base_Type (A_Type) = Full_View (Etype (Imm_Type))
then
A_Type := Etype (Imm_Type);
return True;
-- The parent type may be a private extension. The aggregate is
-- legal if the type of the aggregate is an extension of it that
-- is not a private extension.
elsif Is_Private_Type (A_Type)
and then not Is_Private_Type (Imm_Type)
and then Present (Full_View (A_Type))
and then Base_Type (Full_View (A_Type)) = Etype (Imm_Type)
then
return True;
else
Imm_Type := Etype (Base_Type (Imm_Type));
end if;
end loop;
-- If previous loop did not find a proper ancestor, report error
Error_Msg_NE ("expect ancestor type of &", A, Typ);
return False;
end Valid_Ancestor_Type;
-- Start of processing for Resolve_Extension_Aggregate
begin
-- Analyze the ancestor part and account for the case where it is a
-- parameterless function call.
Analyze (A);
Check_Parameterless_Call (A);
-- In SPARK, the ancestor part cannot be a type mark
if Is_Entity_Name (A) and then Is_Type (Entity (A)) then
Check_SPARK_05_Restriction ("ancestor part cannot be a type mark", A);
-- AI05-0115: if the ancestor part is a subtype mark, the ancestor
-- must not have unknown discriminants.
if Has_Unknown_Discriminants (Root_Type (Typ)) then
Error_Msg_NE
("aggregate not available for type& whose ancestor "
& "has unknown discriminants", N, Typ);
end if;
end if;
if not Is_Tagged_Type (Typ) then
Error_Msg_N ("type of extension aggregate must be tagged", N);
return;
elsif Is_Limited_Type (Typ) then
-- Ada 2005 (AI-287): Limited aggregates are allowed
if Ada_Version < Ada_2005 then
Error_Msg_N ("aggregate type cannot be limited", N);
Explain_Limited_Type (Typ, N);
return;
elsif Valid_Limited_Ancestor (A) then
null;
else
Error_Msg_N
("limited ancestor part must be aggregate or function call", A);
end if;
elsif Is_Class_Wide_Type (Typ) then
Error_Msg_N ("aggregate cannot be of a class-wide type", N);
return;
end if;
if Is_Entity_Name (A) and then Is_Type (Entity (A)) then
A_Type := Get_Full_View (Entity (A));
if Valid_Ancestor_Type then
Set_Entity (A, A_Type);
Set_Etype (A, A_Type);
Validate_Ancestor_Part (N);
Resolve_Record_Aggregate (N, Typ);
end if;
elsif Nkind (A) /= N_Aggregate then
if Is_Overloaded (A) then
A_Type := Any_Type;
Get_First_Interp (A, I, It);
while Present (It.Typ) loop
-- Only consider limited interpretations in the Ada 2005 case
if Is_Tagged_Type (It.Typ)
and then (Ada_Version >= Ada_2005
or else not Is_Limited_Type (It.Typ))
then
if A_Type /= Any_Type then
Error_Msg_N ("cannot resolve expression", A);
return;
else
A_Type := It.Typ;
end if;
end if;
Get_Next_Interp (I, It);
end loop;
if A_Type = Any_Type then
if Ada_Version >= Ada_2005 then
Error_Msg_N
("ancestor part must be of a tagged type", A);
else
Error_Msg_N
("ancestor part must be of a nonlimited tagged type", A);
end if;
return;
end if;
else
A_Type := Etype (A);
end if;
if Valid_Ancestor_Type then
Resolve (A, A_Type);
Check_Unset_Reference (A);
Check_Non_Static_Context (A);
-- The aggregate is illegal if the ancestor expression is a call
-- to a function with a limited unconstrained result, unless the
-- type of the aggregate is a null extension. This restriction
-- was added in AI05-67 to simplify implementation.
if Nkind (A) = N_Function_Call
and then Is_Limited_Type (A_Type)
and then not Is_Null_Extension (Typ)
and then not Is_Constrained (A_Type)
then
Error_Msg_N
("type of limited ancestor part must be constrained", A);
-- Reject the use of CPP constructors that leave objects partially
-- initialized. For example:
-- type CPP_Root is tagged limited record ...
-- pragma Import (CPP, CPP_Root);
-- type CPP_DT is new CPP_Root and Iface ...
-- pragma Import (CPP, CPP_DT);
-- type Ada_DT is new CPP_DT with ...
-- Obj : Ada_DT := Ada_DT'(New_CPP_Root with others => <>);
-- Using the constructor of CPP_Root the slots of the dispatch
-- table of CPP_DT cannot be set, and the secondary tag of
-- CPP_DT is unknown.
elsif Nkind (A) = N_Function_Call
and then Is_CPP_Constructor_Call (A)
and then Enclosing_CPP_Parent (Typ) /= A_Type
then
Error_Msg_NE
("??must use 'C'P'P constructor for type &", A,
Enclosing_CPP_Parent (Typ));
-- The following call is not needed if the previous warning
-- is promoted to an error.
Resolve_Record_Aggregate (N, Typ);
elsif Is_Class_Wide_Type (Etype (A))
and then Nkind (Original_Node (A)) = N_Function_Call
then
-- If the ancestor part is a dispatching call, it appears
-- statically to be a legal ancestor, but it yields any member
-- of the class, and it is not possible to determine whether
-- it is an ancestor of the extension aggregate (much less
-- which ancestor). It is not possible to determine the
-- components of the extension part.
-- This check implements AI-306, which in fact was motivated by
-- an AdaCore query to the ARG after this test was added.
Error_Msg_N ("ancestor part must be statically tagged", A);
else
Resolve_Record_Aggregate (N, Typ);
end if;
end if;
else
Error_Msg_N ("no unique type for this aggregate", A);
end if;
Check_Function_Writable_Actuals (N);
end Resolve_Extension_Aggregate;
------------------------------
-- Resolve_Record_Aggregate --
------------------------------
procedure Resolve_Record_Aggregate (N : Node_Id; Typ : Entity_Id) is
New_Assoc_List : constant List_Id := New_List;
-- New_Assoc_List is the newly built list of N_Component_Association
-- nodes.
Others_Etype : Entity_Id := Empty;
-- This variable is used to save the Etype of the last record component
-- that takes its value from the others choice. Its purpose is:
--
-- (a) make sure the others choice is useful
--
-- (b) make sure the type of all the components whose value is
-- subsumed by the others choice are the same.
--
-- This variable is updated as a side effect of function Get_Value.
Box_Node : Node_Id;
Is_Box_Present : Boolean := False;
Others_Box : Integer := 0;
-- Ada 2005 (AI-287): Variables used in case of default initialization
-- to provide a functionality similar to Others_Etype. Box_Present
-- indicates that the component takes its default initialization;
-- Others_Box counts the number of components of the current aggregate
-- (which may be a sub-aggregate of a larger one) that are default-
-- initialized. A value of One indicates that an others_box is present.
-- Any larger value indicates that the others_box is not redundant.
-- These variables, similar to Others_Etype, are also updated as a side
-- effect of function Get_Value. Box_Node is used to place a warning on
-- a redundant others_box.
procedure Add_Association
(Component : Entity_Id;
Expr : Node_Id;
Assoc_List : List_Id;
Is_Box_Present : Boolean := False);
-- Builds a new N_Component_Association node which associates Component
-- to expression Expr and adds it to the association list being built,
-- either New_Assoc_List, or the association being built for an inner
-- aggregate.
procedure Add_Discriminant_Values
(New_Aggr : Node_Id;
Assoc_List : List_Id);
-- The constraint to a component may be given by a discriminant of the
-- enclosing type, in which case we have to retrieve its value, which is
-- part of the enclosing aggregate. Assoc_List provides the discriminant
-- associations of the current type or of some enclosing record.
function Discriminant_Present (Input_Discr : Entity_Id) return Boolean;
-- If aggregate N is a regular aggregate this routine will return True.
-- Otherwise, if N is an extension aggregate, then Input_Discr denotes
-- a discriminant whose value may already have been specified by N's
-- ancestor part. This routine checks whether this is indeed the case
-- and if so returns False, signaling that no value for Input_Discr
-- should appear in N's aggregate part. Also, in this case, the routine
-- appends to New_Assoc_List the discriminant value specified in the
-- ancestor part.
--
-- If the aggregate is in a context with expansion delayed, it will be
-- reanalyzed. The inherited discriminant values must not be reinserted
-- in the component list to prevent spurious errors, but they must be
-- present on first analysis to build the proper subtype indications.
-- The flag Inherited_Discriminant is used to prevent the re-insertion.
function Find_Private_Ancestor (Typ : Entity_Id) return Entity_Id;
-- AI05-0115: Find earlier ancestor in the derivation chain that is
-- derived from private view Typ. Whether the aggregate is legal depends
-- on the current visibility of the type as well as that of the parent
-- of the ancestor.
function Get_Value
(Compon : Node_Id;
From : List_Id;
Consider_Others_Choice : Boolean := False) return Node_Id;
-- Given a record component stored in parameter Compon, this function
-- returns its value as it appears in the list From, which is a list
-- of N_Component_Association nodes.
--
-- If no component association has a choice for the searched component,
-- the value provided by the others choice is returned, if there is one,
-- and Consider_Others_Choice is set to true. Otherwise Empty is
-- returned. If there is more than one component association giving a
-- value for the searched record component, an error message is emitted
-- and the first found value is returned.
--
-- If Consider_Others_Choice is set and the returned expression comes
-- from the others choice, then Others_Etype is set as a side effect.
-- An error message is emitted if the components taking their value from
-- the others choice do not have same type.
function New_Copy_Tree_And_Copy_Dimensions
(Source : Node_Id;
Map : Elist_Id := No_Elist;
New_Sloc : Source_Ptr := No_Location;
New_Scope : Entity_Id := Empty) return Node_Id;
-- Same as New_Copy_Tree (defined in Sem_Util), except that this routine
-- also copies the dimensions of Source to the returned node.
procedure Propagate_Discriminants
(Aggr : Node_Id;
Assoc_List : List_Id);
-- Nested components may themselves be discriminated types constrained
-- by outer discriminants, whose values must be captured before the
-- aggregate is expanded into assignments.
procedure Resolve_Aggr_Expr (Expr : Node_Id; Component : Entity_Id);
-- Analyzes and resolves expression Expr against the Etype of the
-- Component. This routine also applies all appropriate checks to Expr.
-- It finally saves a Expr in the newly created association list that
-- will be attached to the final record aggregate. Note that if the
-- Parent pointer of Expr is not set then Expr was produced with a
-- New_Copy_Tree or some such.
---------------------
-- Add_Association --
---------------------
procedure Add_Association
(Component : Entity_Id;
Expr : Node_Id;
Assoc_List : List_Id;
Is_Box_Present : Boolean := False)
is
Choice_List : constant List_Id := New_List;
Loc : Source_Ptr;
begin
-- If this is a box association the expression is missing, so use the
-- Sloc of the aggregate itself for the new association.
if Present (Expr) then
Loc := Sloc (Expr);
else
Loc := Sloc (N);
end if;
Append_To (Choice_List, New_Occurrence_Of (Component, Loc));
Append_To (Assoc_List,
Make_Component_Association (Loc,
Choices => Choice_List,
Expression => Expr,
Box_Present => Is_Box_Present));
end Add_Association;
-----------------------------
-- Add_Discriminant_Values --
-----------------------------
procedure Add_Discriminant_Values
(New_Aggr : Node_Id;
Assoc_List : List_Id)
is
Assoc : Node_Id;
Discr : Entity_Id;
Discr_Elmt : Elmt_Id;
Discr_Val : Node_Id;
Val : Entity_Id;
begin
Discr := First_Discriminant (Etype (New_Aggr));
Discr_Elmt := First_Elmt (Discriminant_Constraint (Etype (New_Aggr)));
while Present (Discr_Elmt) loop
Discr_Val := Node (Discr_Elmt);
-- If the constraint is given by a discriminant then it is a
-- discriminant of an enclosing record, and its value has already
-- been placed in the association list.
if Is_Entity_Name (Discr_Val)
and then Ekind (Entity (Discr_Val)) = E_Discriminant
then
Val := Entity (Discr_Val);
Assoc := First (Assoc_List);
while Present (Assoc) loop
if Present (Entity (First (Choices (Assoc))))
and then Entity (First (Choices (Assoc))) = Val
then
Discr_Val := Expression (Assoc);
exit;
end if;
Next (Assoc);
end loop;
end if;
Add_Association
(Discr, New_Copy_Tree (Discr_Val),
Component_Associations (New_Aggr));
-- If the discriminant constraint is a current instance, mark the
-- current aggregate so that the self-reference can be expanded
-- later. The constraint may refer to the subtype of aggregate, so
-- use base type for comparison.
if Nkind (Discr_Val) = N_Attribute_Reference
and then Is_Entity_Name (Prefix (Discr_Val))
and then Is_Type (Entity (Prefix (Discr_Val)))
and then Base_Type (Etype (N)) = Entity (Prefix (Discr_Val))
then
Set_Has_Self_Reference (N);
end if;
Next_Elmt (Discr_Elmt);
Next_Discriminant (Discr);
end loop;
end Add_Discriminant_Values;
--------------------------
-- Discriminant_Present --
--------------------------
function Discriminant_Present (Input_Discr : Entity_Id) return Boolean is
Regular_Aggr : constant Boolean := Nkind (N) /= N_Extension_Aggregate;
Ancestor_Is_Subtyp : Boolean;
Loc : Source_Ptr;
Ancestor : Node_Id;
Ancestor_Typ : Entity_Id;
Comp_Assoc : Node_Id;
Discr : Entity_Id;
Discr_Expr : Node_Id;
Discr_Val : Elmt_Id := No_Elmt;
Orig_Discr : Entity_Id;
begin
if Regular_Aggr then
return True;
end if;
-- Check whether inherited discriminant values have already been
-- inserted in the aggregate. This will be the case if we are
-- re-analyzing an aggregate whose expansion was delayed.
if Present (Component_Associations (N)) then
Comp_Assoc := First (Component_Associations (N));
while Present (Comp_Assoc) loop
if Inherited_Discriminant (Comp_Assoc) then
return True;
end if;
Next (Comp_Assoc);
end loop;
end if;
Ancestor := Ancestor_Part (N);
Ancestor_Typ := Etype (Ancestor);
Loc := Sloc (Ancestor);
-- For a private type with unknown discriminants, use the underlying
-- record view if it is available.
if Has_Unknown_Discriminants (Ancestor_Typ)
and then Present (Full_View (Ancestor_Typ))
and then Present (Underlying_Record_View (Full_View (Ancestor_Typ)))
then
Ancestor_Typ := Underlying_Record_View (Full_View (Ancestor_Typ));
end if;
Ancestor_Is_Subtyp :=
Is_Entity_Name (Ancestor) and then Is_Type (Entity (Ancestor));
-- If the ancestor part has no discriminants clearly N's aggregate
-- part must provide a value for Discr.
if not Has_Discriminants (Ancestor_Typ) then
return True;
-- If the ancestor part is an unconstrained subtype mark then the
-- Discr must be present in N's aggregate part.
elsif Ancestor_Is_Subtyp
and then not Is_Constrained (Entity (Ancestor))
then
return True;
end if;
-- Now look to see if Discr was specified in the ancestor part
if Ancestor_Is_Subtyp then
Discr_Val :=
First_Elmt (Discriminant_Constraint (Entity (Ancestor)));
end if;
Orig_Discr := Original_Record_Component (Input_Discr);
Discr := First_Discriminant (Ancestor_Typ);
while Present (Discr) loop
-- If Ancestor has already specified Disc value then insert its
-- value in the final aggregate.
if Original_Record_Component (Discr) = Orig_Discr then
if Ancestor_Is_Subtyp then
Discr_Expr := New_Copy_Tree (Node (Discr_Val));
else
Discr_Expr :=
Make_Selected_Component (Loc,
Prefix => Duplicate_Subexpr (Ancestor),
Selector_Name => New_Occurrence_Of (Input_Discr, Loc));
end if;
Resolve_Aggr_Expr (Discr_Expr, Input_Discr);
Set_Inherited_Discriminant (Last (New_Assoc_List));
return False;
end if;
Next_Discriminant (Discr);
if Ancestor_Is_Subtyp then
Next_Elmt (Discr_Val);
end if;
end loop;
return True;
end Discriminant_Present;
---------------------------
-- Find_Private_Ancestor --
---------------------------
function Find_Private_Ancestor (Typ : Entity_Id) return Entity_Id is
Par : Entity_Id;
begin
Par := Typ;
loop
if Has_Private_Ancestor (Par)
and then not Has_Private_Ancestor (Etype (Base_Type (Par)))
then
return Par;
elsif not Is_Derived_Type (Par) then
return Empty;
else
Par := Etype (Base_Type (Par));
end if;
end loop;
end Find_Private_Ancestor;
---------------
-- Get_Value --
---------------
function Get_Value
(Compon : Node_Id;
From : List_Id;
Consider_Others_Choice : Boolean := False) return Node_Id
is
Typ : constant Entity_Id := Etype (Compon);
Assoc : Node_Id;
Expr : Node_Id := Empty;
Selector_Name : Node_Id;
begin
Is_Box_Present := False;
if No (From) then
return Empty;
end if;
Assoc := First (From);
while Present (Assoc) loop
Selector_Name := First (Choices (Assoc));
while Present (Selector_Name) loop
if Nkind (Selector_Name) = N_Others_Choice then
if Consider_Others_Choice and then No (Expr) then
-- We need to duplicate the expression for each
-- successive component covered by the others choice.
-- This is redundant if the others_choice covers only
-- one component (small optimization possible???), but
-- indispensable otherwise, because each one must be
-- expanded individually to preserve side-effects.
-- Ada 2005 (AI-287): In case of default initialization
-- of components, we duplicate the corresponding default
-- expression (from the record type declaration). The
-- copy must carry the sloc of the association (not the
-- original expression) to prevent spurious elaboration
-- checks when the default includes function calls.
if Box_Present (Assoc) then
Others_Box := Others_Box + 1;
Is_Box_Present := True;
if Expander_Active then
return
New_Copy_Tree_And_Copy_Dimensions
(Expression (Parent (Compon)),
New_Sloc => Sloc (Assoc));
else
return Expression (Parent (Compon));
end if;
else
if Present (Others_Etype)
and then Base_Type (Others_Etype) /= Base_Type (Typ)
then
-- If the components are of an anonymous access
-- type they are distinct, but this is legal in
-- Ada 2012 as long as designated types match.
if (Ekind (Typ) = E_Anonymous_Access_Type
or else Ekind (Typ) =
E_Anonymous_Access_Subprogram_Type)
and then Designated_Type (Typ) =
Designated_Type (Others_Etype)
then
null;
else
Error_Msg_N
("components in OTHERS choice must have same "
& "type", Selector_Name);
end if;
end if;
Others_Etype := Typ;
-- Copy the expression so that it is resolved
-- independently for each component, This is needed
-- for accessibility checks on compoents of anonymous
-- access types, even in compile_only mode.
if not Inside_A_Generic then
-- In ASIS mode, preanalyze the expression in an
-- others association before making copies for
-- separate resolution and accessibility checks.
-- This ensures that the type of the expression is
-- available to ASIS in all cases, in particular if
-- the expression is itself an aggregate.
if ASIS_Mode then
Preanalyze_And_Resolve (Expression (Assoc), Typ);
end if;
return
New_Copy_Tree_And_Copy_Dimensions
(Expression (Assoc));
else
return Expression (Assoc);
end if;
end if;
end if;
elsif Chars (Compon) = Chars (Selector_Name) then
if No (Expr) then
-- Ada 2005 (AI-231)
if Ada_Version >= Ada_2005
and then Known_Null (Expression (Assoc))
then
Check_Can_Never_Be_Null (Compon, Expression (Assoc));
end if;
-- We need to duplicate the expression when several
-- components are grouped together with a "|" choice.
-- For instance "filed1 | filed2 => Expr"
-- Ada 2005 (AI-287)
if Box_Present (Assoc) then
Is_Box_Present := True;
-- Duplicate the default expression of the component
-- from the record type declaration, so a new copy
-- can be attached to the association.
-- Note that we always copy the default expression,
-- even when the association has a single choice, in
-- order to create a proper association for the
-- expanded aggregate.
-- Component may have no default, in which case the
-- expression is empty and the component is default-
-- initialized, but an association for the component
-- exists, and it is not covered by an others clause.
-- Scalar and private types have no initialization
-- procedure, so they remain uninitialized. If the
-- target of the aggregate is a constant this
-- deserves a warning.
if No (Expression (Parent (Compon)))
and then not Has_Non_Null_Base_Init_Proc (Typ)
and then not Has_Aspect (Typ, Aspect_Default_Value)
and then not Is_Concurrent_Type (Typ)
and then Nkind (Parent (N)) = N_Object_Declaration
and then Constant_Present (Parent (N))
then
Error_Msg_Node_2 := Typ;
Error_Msg_NE
("component&? of type& is uninitialized",
Assoc, Selector_Name);
-- An additional reminder if the component type
-- is a generic formal.
if Is_Generic_Type (Base_Type (Typ)) then
Error_Msg_NE
("\instance should provide actual type with "
& "initialization for&", Assoc, Typ);
end if;
end if;
return
New_Copy_Tree_And_Copy_Dimensions
(Expression (Parent (Compon)));
else
if Present (Next (Selector_Name)) then
Expr := New_Copy_Tree_And_Copy_Dimensions
(Expression (Assoc));
else
Expr := Expression (Assoc);
end if;
end if;
Generate_Reference (Compon, Selector_Name, 'm');
else
Error_Msg_NE
("more than one value supplied for &",
Selector_Name, Compon);
end if;
end if;
Next (Selector_Name);
end loop;
Next (Assoc);
end loop;
return Expr;
end Get_Value;
---------------------------------------
-- New_Copy_Tree_And_Copy_Dimensions --
---------------------------------------
function New_Copy_Tree_And_Copy_Dimensions
(Source : Node_Id;
Map : Elist_Id := No_Elist;
New_Sloc : Source_Ptr := No_Location;
New_Scope : Entity_Id := Empty) return Node_Id
is
New_Copy : constant Node_Id :=
New_Copy_Tree (Source, Map, New_Sloc, New_Scope);
begin
-- Move the dimensions of Source to New_Copy
Copy_Dimensions (Source, New_Copy);
return New_Copy;
end New_Copy_Tree_And_Copy_Dimensions;
-----------------------------
-- Propagate_Discriminants --
-----------------------------
procedure Propagate_Discriminants
(Aggr : Node_Id;
Assoc_List : List_Id)
is
Loc : constant Source_Ptr := Sloc (N);
Needs_Box : Boolean := False;
procedure Process_Component (Comp : Entity_Id);
-- Add one component with a box association to the inner aggregate,
-- and recurse if component is itself composite.
-----------------------
-- Process_Component --
-----------------------
procedure Process_Component (Comp : Entity_Id) is
T : constant Entity_Id := Etype (Comp);
New_Aggr : Node_Id;
begin
if Is_Record_Type (T) and then Has_Discriminants (T) then
New_Aggr := Make_Aggregate (Loc, New_List, New_List);
Set_Etype (New_Aggr, T);
Add_Association
(Comp, New_Aggr, Component_Associations (Aggr));
-- Collect discriminant values and recurse
Add_Discriminant_Values (New_Aggr, Assoc_List);
Propagate_Discriminants (New_Aggr, Assoc_List);
else
Needs_Box := True;
end if;
end Process_Component;
-- Local variables
Aggr_Type : constant Entity_Id := Base_Type (Etype (Aggr));
Components : constant Elist_Id := New_Elmt_List;
Def_Node : constant Node_Id :=
Type_Definition (Declaration_Node (Aggr_Type));
Comp : Node_Id;
Comp_Elmt : Elmt_Id;
Errors : Boolean;
-- Start of processing for Propagate_Discriminants
begin
-- The component type may be a variant type. Collect the components
-- that are ruled by the known values of the discriminants. Their
-- values have already been inserted into the component list of the
-- current aggregate.
if Nkind (Def_Node) = N_Record_Definition
and then Present (Component_List (Def_Node))
and then Present (Variant_Part (Component_List (Def_Node)))
then
Gather_Components (Aggr_Type,
Component_List (Def_Node),
Governed_By => Component_Associations (Aggr),
Into => Components,
Report_Errors => Errors);
Comp_Elmt := First_Elmt (Components);
while Present (Comp_Elmt) loop
if Ekind (Node (Comp_Elmt)) /= E_Discriminant then
Process_Component (Node (Comp_Elmt));
end if;
Next_Elmt (Comp_Elmt);
end loop;
-- No variant part, iterate over all components
else
Comp := First_Component (Etype (Aggr));
while Present (Comp) loop
Process_Component (Comp);
Next_Component (Comp);
end loop;
end if;
if Needs_Box then
Append_To (Component_Associations (Aggr),
Make_Component_Association (Loc,
Choices => New_List (Make_Others_Choice (Loc)),
Expression => Empty,
Box_Present => True));
end if;
end Propagate_Discriminants;
-----------------------
-- Resolve_Aggr_Expr --
-----------------------
procedure Resolve_Aggr_Expr (Expr : Node_Id; Component : Entity_Id) is
function Has_Expansion_Delayed (Expr : Node_Id) return Boolean;
-- If the expression is an aggregate (possibly qualified) then its
-- expansion is delayed until the enclosing aggregate is expanded
-- into assignments. In that case, do not generate checks on the
-- expression, because they will be generated later, and will other-
-- wise force a copy (to remove side-effects) that would leave a
-- dynamic-sized aggregate in the code, something that gigi cannot
-- handle.
---------------------------
-- Has_Expansion_Delayed --
---------------------------
function Has_Expansion_Delayed (Expr : Node_Id) return Boolean is
begin
return
(Nkind_In (Expr, N_Aggregate, N_Extension_Aggregate)
and then Present (Etype (Expr))
and then Is_Record_Type (Etype (Expr))
and then Expansion_Delayed (Expr))
or else
(Nkind (Expr) = N_Qualified_Expression
and then Has_Expansion_Delayed (Expression (Expr)));
end Has_Expansion_Delayed;
-- Local variables
Expr_Type : Entity_Id := Empty;
New_C : Entity_Id := Component;
New_Expr : Node_Id;
Relocate : Boolean;
-- Set to True if the resolved Expr node needs to be relocated when
-- attached to the newly created association list. This node need not
-- be relocated if its parent pointer is not set. In fact in this
-- case Expr is the output of a New_Copy_Tree call. If Relocate is
-- True then we have analyzed the expression node in the original
-- aggregate and hence it needs to be relocated when moved over to
-- the new association list.
-- Start of processing for Resolve_Aggr_Expr
begin
-- If the type of the component is elementary or the type of the
-- aggregate does not contain discriminants, use the type of the
-- component to resolve Expr.
if Is_Elementary_Type (Etype (Component))
or else not Has_Discriminants (Etype (N))
then
Expr_Type := Etype (Component);
-- Otherwise we have to pick up the new type of the component from
-- the new constrained subtype of the aggregate. In fact components
-- which are of a composite type might be constrained by a
-- discriminant, and we want to resolve Expr against the subtype were
-- all discriminant occurrences are replaced with their actual value.
else
New_C := First_Component (Etype (N));
while Present (New_C) loop
if Chars (New_C) = Chars (Component) then
Expr_Type := Etype (New_C);
exit;
end if;
Next_Component (New_C);
end loop;
pragma Assert (Present (Expr_Type));
-- For each range in an array type where a discriminant has been
-- replaced with the constraint, check that this range is within
-- the range of the base type. This checks is done in the init
-- proc for regular objects, but has to be done here for
-- aggregates since no init proc is called for them.
if Is_Array_Type (Expr_Type) then
declare
Index : Node_Id;
-- Range of the current constrained index in the array
Orig_Index : Node_Id := First_Index (Etype (Component));
-- Range corresponding to the range Index above in the
-- original unconstrained record type. The bounds of this
-- range may be governed by discriminants.
Unconstr_Index : Node_Id := First_Index (Etype (Expr_Type));
-- Range corresponding to the range Index above for the
-- unconstrained array type. This range is needed to apply
-- range checks.
begin
Index := First_Index (Expr_Type);
while Present (Index) loop
if Depends_On_Discriminant (Orig_Index) then
Apply_Range_Check (Index, Etype (Unconstr_Index));
end if;
Next_Index (Index);
Next_Index (Orig_Index);
Next_Index (Unconstr_Index);
end loop;
end;
end if;
end if;
-- If the Parent pointer of Expr is not set, Expr is an expression
-- duplicated by New_Tree_Copy (this happens for record aggregates
-- that look like (Field1 | Filed2 => Expr) or (others => Expr)).
-- Such a duplicated expression must be attached to the tree
-- before analysis and resolution to enforce the rule that a tree
-- fragment should never be analyzed or resolved unless it is
-- attached to the current compilation unit.
if No (Parent (Expr)) then
Set_Parent (Expr, N);
Relocate := False;
else
Relocate := True;
end if;
Analyze_And_Resolve (Expr, Expr_Type);
Check_Expr_OK_In_Limited_Aggregate (Expr);
Check_Non_Static_Context (Expr);
Check_Unset_Reference (Expr);
-- Check wrong use of class-wide types
if Is_Class_Wide_Type (Etype (Expr)) then
Error_Msg_N ("dynamically tagged expression not allowed", Expr);
end if;
if not Has_Expansion_Delayed (Expr) then
Aggregate_Constraint_Checks (Expr, Expr_Type);
end if;
-- If an aggregate component has a type with predicates, an explicit
-- predicate check must be applied, as for an assignment statement,
-- because the aggegate might not be expanded into individual
-- component assignments.
if Present (Predicate_Function (Expr_Type))
and then Analyzed (Expr)
then
Apply_Predicate_Check (Expr, Expr_Type);
end if;
if Raises_Constraint_Error (Expr) then
Set_Raises_Constraint_Error (N);
end if;
-- If the expression has been marked as requiring a range check, then
-- generate it here. It's a bit odd to be generating such checks in
-- the analyzer, but harmless since Generate_Range_Check does nothing
-- (other than making sure Do_Range_Check is set) if the expander is
-- not active.
if Do_Range_Check (Expr) then
Generate_Range_Check (Expr, Expr_Type, CE_Range_Check_Failed);
end if;
-- Add association Component => Expr if the caller requests it
if Relocate then
New_Expr := Relocate_Node (Expr);
-- Since New_Expr is not gonna be analyzed later on, we need to
-- propagate here the dimensions form Expr to New_Expr.
Copy_Dimensions (Expr, New_Expr);
else
New_Expr := Expr;
end if;
Add_Association (New_C, New_Expr, New_Assoc_List);
end Resolve_Aggr_Expr;
-- Local variables
Components : constant Elist_Id := New_Elmt_List;
-- Components is the list of the record components whose value must be
-- provided in the aggregate. This list does include discriminants.
Expr : Node_Id;
Component : Entity_Id;
Component_Elmt : Elmt_Id;
Positional_Expr : Node_Id;
-- Start of processing for Resolve_Record_Aggregate
begin
-- A record aggregate is restricted in SPARK:
-- Each named association can have only a single choice.
-- OTHERS cannot be used.
-- Positional and named associations cannot be mixed.
if Present (Component_Associations (N))
and then Present (First (Component_Associations (N)))
then
if Present (Expressions (N)) then
Check_SPARK_05_Restriction
("named association cannot follow positional one",
First (Choices (First (Component_Associations (N)))));
end if;
declare
Assoc : Node_Id;
begin
Assoc := First (Component_Associations (N));
while Present (Assoc) loop
if List_Length (Choices (Assoc)) > 1 then
Check_SPARK_05_Restriction
("component association in record aggregate must "
& "contain a single choice", Assoc);
end if;
if Nkind (First (Choices (Assoc))) = N_Others_Choice then
Check_SPARK_05_Restriction
("record aggregate cannot contain OTHERS", Assoc);
end if;
Assoc := Next (Assoc);
end loop;
end;
end if;
-- We may end up calling Duplicate_Subexpr on expressions that are
-- attached to New_Assoc_List. For this reason we need to attach it
-- to the tree by setting its parent pointer to N. This parent point
-- will change in STEP 8 below.
Set_Parent (New_Assoc_List, N);
-- STEP 1: abstract type and null record verification
if Is_Abstract_Type (Typ) then
Error_Msg_N ("type of aggregate cannot be abstract", N);
end if;
if No (First_Entity (Typ)) and then Null_Record_Present (N) then
Set_Etype (N, Typ);
return;
elsif Present (First_Entity (Typ))
and then Null_Record_Present (N)
and then not Is_Tagged_Type (Typ)
then
Error_Msg_N ("record aggregate cannot be null", N);
return;
-- If the type has no components, then the aggregate should either
-- have "null record", or in Ada 2005 it could instead have a single
-- component association given by "others => <>". For Ada 95 we flag an
-- error at this point, but for Ada 2005 we proceed with checking the
-- associations below, which will catch the case where it's not an
-- aggregate with "others => <>". Note that the legality of a <>
-- aggregate for a null record type was established by AI05-016.
elsif No (First_Entity (Typ))
and then Ada_Version < Ada_2005
then
Error_Msg_N ("record aggregate must be null", N);
return;
end if;
-- STEP 2: Verify aggregate structure
Step_2 : declare
Assoc : Node_Id;
Bad_Aggregate : Boolean := False;
Selector_Name : Node_Id;
begin
if Present (Component_Associations (N)) then
Assoc := First (Component_Associations (N));
else
Assoc := Empty;
end if;
while Present (Assoc) loop
Selector_Name := First (Choices (Assoc));
while Present (Selector_Name) loop
if Nkind (Selector_Name) = N_Identifier then
null;
elsif Nkind (Selector_Name) = N_Others_Choice then
if Selector_Name /= First (Choices (Assoc))
or else Present (Next (Selector_Name))
then
Error_Msg_N
("OTHERS must appear alone in a choice list",
Selector_Name);
return;
elsif Present (Next (Assoc)) then
Error_Msg_N
("OTHERS must appear last in an aggregate",
Selector_Name);
return;
-- (Ada 2005): If this is an association with a box,
-- indicate that the association need not represent
-- any component.
elsif Box_Present (Assoc) then
Others_Box := 1;
Box_Node := Assoc;
end if;
else
Error_Msg_N
("selector name should be identifier or OTHERS",
Selector_Name);
Bad_Aggregate := True;
end if;
Next (Selector_Name);
end loop;
Next (Assoc);
end loop;
if Bad_Aggregate then
return;
end if;
end Step_2;
-- STEP 3: Find discriminant Values
Step_3 : declare
Discrim : Entity_Id;
Missing_Discriminants : Boolean := False;
begin
if Present (Expressions (N)) then
Positional_Expr := First (Expressions (N));
else
Positional_Expr := Empty;
end if;
-- AI05-0115: if the ancestor part is a subtype mark, the ancestor
-- must not have unknown discriminants.
if Is_Derived_Type (Typ)
and then Has_Unknown_Discriminants (Root_Type (Typ))
and then Nkind (N) /= N_Extension_Aggregate
then
Error_Msg_NE
("aggregate not available for type& whose ancestor "
& "has unknown discriminants ", N, Typ);
end if;
if Has_Unknown_Discriminants (Typ)
and then Present (Underlying_Record_View (Typ))
then
Discrim := First_Discriminant (Underlying_Record_View (Typ));
elsif Has_Discriminants (Typ) then
Discrim := First_Discriminant (Typ);
else
Discrim := Empty;
end if;
-- First find the discriminant values in the positional components
while Present (Discrim) and then Present (Positional_Expr) loop
if Discriminant_Present (Discrim) then
Resolve_Aggr_Expr (Positional_Expr, Discrim);
-- Ada 2005 (AI-231)
if Ada_Version >= Ada_2005
and then Known_Null (Positional_Expr)
then
Check_Can_Never_Be_Null (Discrim, Positional_Expr);
end if;
Next (Positional_Expr);
end if;
if Present (Get_Value (Discrim, Component_Associations (N))) then
Error_Msg_NE
("more than one value supplied for discriminant&",
N, Discrim);
end if;
Next_Discriminant (Discrim);
end loop;
-- Find remaining discriminant values if any among named components
while Present (Discrim) loop
Expr := Get_Value (Discrim, Component_Associations (N), True);
if not Discriminant_Present (Discrim) then
if Present (Expr) then
Error_Msg_NE
("more than one value supplied for discriminant &",
N, Discrim);
end if;
elsif No (Expr) then
Error_Msg_NE
("no value supplied for discriminant &", N, Discrim);
Missing_Discriminants := True;
else
Resolve_Aggr_Expr (Expr, Discrim);
end if;
Next_Discriminant (Discrim);
end loop;
if Missing_Discriminants then
return;
end if;
-- At this point and until the beginning of STEP 6, New_Assoc_List
-- contains only the discriminants and their values.
end Step_3;
-- STEP 4: Set the Etype of the record aggregate
-- ??? This code is pretty much a copy of Sem_Ch3.Build_Subtype. That
-- routine should really be exported in sem_util or some such and used
-- in sem_ch3 and here rather than have a copy of the code which is a
-- maintenance nightmare.
-- ??? Performance WARNING. The current implementation creates a new
-- itype for all aggregates whose base type is discriminated. This means
-- that for record aggregates nested inside an array aggregate we will
-- create a new itype for each record aggregate if the array component
-- type has discriminants. For large aggregates this may be a problem.
-- What should be done in this case is to reuse itypes as much as
-- possible.
if Has_Discriminants (Typ)
or else (Has_Unknown_Discriminants (Typ)
and then Present (Underlying_Record_View (Typ)))
then
Build_Constrained_Itype : declare
Constrs : constant List_Id := New_List;
Loc : constant Source_Ptr := Sloc (N);
Def_Id : Entity_Id;
Indic : Node_Id;
New_Assoc : Node_Id;
Subtyp_Decl : Node_Id;
begin
New_Assoc := First (New_Assoc_List);
while Present (New_Assoc) loop
Append_To (Constrs, Duplicate_Subexpr (Expression (New_Assoc)));
Next (New_Assoc);
end loop;
if Has_Unknown_Discriminants (Typ)
and then Present (Underlying_Record_View (Typ))
then
Indic :=
Make_Subtype_Indication (Loc,
Subtype_Mark =>
New_Occurrence_Of (Underlying_Record_View (Typ), Loc),
Constraint =>
Make_Index_Or_Discriminant_Constraint (Loc,
Constraints => Constrs));
else
Indic :=
Make_Subtype_Indication (Loc,
Subtype_Mark =>
New_Occurrence_Of (Base_Type (Typ), Loc),
Constraint =>
Make_Index_Or_Discriminant_Constraint (Loc,
Constraints => Constrs));
end if;
Def_Id := Create_Itype (Ekind (Typ), N);
Subtyp_Decl :=
Make_Subtype_Declaration (Loc,
Defining_Identifier => Def_Id,
Subtype_Indication => Indic);
Set_Parent (Subtyp_Decl, Parent (N));
-- Itypes must be analyzed with checks off (see itypes.ads)
Analyze (Subtyp_Decl, Suppress => All_Checks);
Set_Etype (N, Def_Id);
Check_Static_Discriminated_Subtype
(Def_Id, Expression (First (New_Assoc_List)));
end Build_Constrained_Itype;
else
Set_Etype (N, Typ);
end if;
-- STEP 5: Get remaining components according to discriminant values
Step_5 : declare
Dnode : Node_Id;
Errors_Found : Boolean := False;
Record_Def : Node_Id;
Parent_Typ : Entity_Id;
Parent_Typ_List : Elist_Id;
Parent_Elmt : Elmt_Id;
Root_Typ : Entity_Id;
begin
if Is_Derived_Type (Typ) and then Is_Tagged_Type (Typ) then
Parent_Typ_List := New_Elmt_List;
-- If this is an extension aggregate, the component list must
-- include all components that are not in the given ancestor type.
-- Otherwise, the component list must include components of all
-- ancestors, starting with the root.
if Nkind (N) = N_Extension_Aggregate then
Root_Typ := Base_Type (Etype (Ancestor_Part (N)));
else
-- AI05-0115: check legality of aggregate for type with a
-- private ancestor.
Root_Typ := Root_Type (Typ);
if Has_Private_Ancestor (Typ) then
declare
Ancestor : constant Entity_Id :=
Find_Private_Ancestor (Typ);
Ancestor_Unit : constant Entity_Id :=
Cunit_Entity
(Get_Source_Unit (Ancestor));
Parent_Unit : constant Entity_Id :=
Cunit_Entity (Get_Source_Unit
(Base_Type (Etype (Ancestor))));
begin
-- Check whether we are in a scope that has full view
-- over the private ancestor and its parent. This can
-- only happen if the derivation takes place in a child
-- unit of the unit that declares the parent, and we are
-- in the private part or body of that child unit, else
-- the aggregate is illegal.
if Is_Child_Unit (Ancestor_Unit)
and then Scope (Ancestor_Unit) = Parent_Unit
and then In_Open_Scopes (Scope (Ancestor))
and then
(In_Private_Part (Scope (Ancestor))
or else In_Package_Body (Scope (Ancestor)))
then
null;
else
Error_Msg_NE
("type of aggregate has private ancestor&!",
N, Root_Typ);
Error_Msg_N ("must use extension aggregate!", N);
return;
end if;
end;
end if;
Dnode := Declaration_Node (Base_Type (Root_Typ));
-- If we don't get a full declaration, then we have some error
-- which will get signalled later so skip this part. Otherwise
-- gather components of root that apply to the aggregate type.
-- We use the base type in case there is an applicable stored
-- constraint that renames the discriminants of the root.
if Nkind (Dnode) = N_Full_Type_Declaration then
Record_Def := Type_Definition (Dnode);
Gather_Components
(Base_Type (Typ),
Component_List (Record_Def),
Governed_By => New_Assoc_List,
Into => Components,
Report_Errors => Errors_Found);
if Errors_Found then
Error_Msg_N
("discriminant controlling variant part is not static",
N);
return;
end if;
end if;
end if;
Parent_Typ := Base_Type (Typ);
while Parent_Typ /= Root_Typ loop
Prepend_Elmt (Parent_Typ, To => Parent_Typ_List);
Parent_Typ := Etype (Parent_Typ);
if Nkind (Parent (Base_Type (Parent_Typ))) =
N_Private_Type_Declaration
or else Nkind (Parent (Base_Type (Parent_Typ))) =
N_Private_Extension_Declaration
then
if Nkind (N) /= N_Extension_Aggregate then
Error_Msg_NE
("type of aggregate has private ancestor&!",
N, Parent_Typ);
Error_Msg_N ("must use extension aggregate!", N);
return;
elsif Parent_Typ /= Root_Typ then
Error_Msg_NE
("ancestor part of aggregate must be private type&",
Ancestor_Part (N), Parent_Typ);
return;
end if;
-- The current view of ancestor part may be a private type,
-- while the context type is always non-private.
elsif Is_Private_Type (Root_Typ)
and then Present (Full_View (Root_Typ))
and then Nkind (N) = N_Extension_Aggregate
then
exit when Base_Type (Full_View (Root_Typ)) = Parent_Typ;
end if;
end loop;
-- Now collect components from all other ancestors, beginning
-- with the current type. If the type has unknown discriminants
-- use the component list of the Underlying_Record_View, which
-- needs to be used for the subsequent expansion of the aggregate
-- into assignments.
Parent_Elmt := First_Elmt (Parent_Typ_List);
while Present (Parent_Elmt) loop
Parent_Typ := Node (Parent_Elmt);
if Has_Unknown_Discriminants (Parent_Typ)
and then Present (Underlying_Record_View (Typ))
then
Parent_Typ := Underlying_Record_View (Parent_Typ);
end if;
Record_Def := Type_Definition (Parent (Base_Type (Parent_Typ)));
Gather_Components (Empty,
Component_List (Record_Extension_Part (Record_Def)),
Governed_By => New_Assoc_List,
Into => Components,
Report_Errors => Errors_Found);
Next_Elmt (Parent_Elmt);
end loop;
-- Typ is not a derived tagged type
else
Record_Def := Type_Definition (Parent (Base_Type (Typ)));
if Null_Present (Record_Def) then
null;
elsif not Has_Unknown_Discriminants (Typ) then
Gather_Components
(Base_Type (Typ),
Component_List (Record_Def),
Governed_By => New_Assoc_List,
Into => Components,
Report_Errors => Errors_Found);
else
Gather_Components
(Base_Type (Underlying_Record_View (Typ)),
Component_List (Record_Def),
Governed_By => New_Assoc_List,
Into => Components,
Report_Errors => Errors_Found);
end if;
end if;
if Errors_Found then
return;
end if;
end Step_5;
-- STEP 6: Find component Values
Component := Empty;
Component_Elmt := First_Elmt (Components);
-- First scan the remaining positional associations in the aggregate.
-- Remember that at this point Positional_Expr contains the current
-- positional association if any is left after looking for discriminant
-- values in step 3.
while Present (Positional_Expr) and then Present (Component_Elmt) loop
Component := Node (Component_Elmt);
Resolve_Aggr_Expr (Positional_Expr, Component);
-- Ada 2005 (AI-231)
if Ada_Version >= Ada_2005 and then Known_Null (Positional_Expr) then
Check_Can_Never_Be_Null (Component, Positional_Expr);
end if;
if Present (Get_Value (Component, Component_Associations (N))) then
Error_Msg_NE
("more than one value supplied for Component &", N, Component);
end if;
Next (Positional_Expr);
Next_Elmt (Component_Elmt);
end loop;
if Present (Positional_Expr) then
Error_Msg_N
("too many components for record aggregate", Positional_Expr);
end if;
-- Now scan for the named arguments of the aggregate
while Present (Component_Elmt) loop
Component := Node (Component_Elmt);
Expr := Get_Value (Component, Component_Associations (N), True);
-- Note: The previous call to Get_Value sets the value of the
-- variable Is_Box_Present.
-- Ada 2005 (AI-287): Handle components with default initialization.
-- Note: This feature was originally added to Ada 2005 for limited
-- but it was finally allowed with any type.
if Is_Box_Present then
Check_Box_Component : declare
Ctyp : constant Entity_Id := Etype (Component);
begin
-- If there is a default expression for the aggregate, copy
-- it into a new association. This copy must modify the scopes
-- of internal types that may be attached to the expression
-- (e.g. index subtypes of arrays) because in general the type
-- declaration and the aggregate appear in different scopes,
-- and the backend requires the scope of the type to match the
-- point at which it is elaborated.
-- If the component has an initialization procedure (IP) we
-- pass the component to the expander, which will generate
-- the call to such IP.
-- If the component has discriminants, their values must
-- be taken from their subtype. This is indispensable for
-- constraints that are given by the current instance of an
-- enclosing type, to allow the expansion of the aggregate to
-- replace the reference to the current instance by the target
-- object of the aggregate.
if Present (Parent (Component))
and then Nkind (Parent (Component)) = N_Component_Declaration
and then Present (Expression (Parent (Component)))
then
Expr :=
New_Copy_Tree_And_Copy_Dimensions
(Expression (Parent (Component)),
New_Scope => Current_Scope,
New_Sloc => Sloc (N));
Add_Association
(Component => Component,
Expr => Expr,
Assoc_List => New_Assoc_List);
Set_Has_Self_Reference (N);
-- A box-defaulted access component gets the value null. Also
-- included are components of private types whose underlying
-- type is an access type. In either case set the type of the
-- literal, for subsequent use in semantic checks.
elsif Present (Underlying_Type (Ctyp))
and then Is_Access_Type (Underlying_Type (Ctyp))
then
-- If the component's type is private with an access type as
-- its underlying type then we have to create an unchecked
-- conversion to satisfy type checking.
if Is_Private_Type (Ctyp) then
declare
Qual_Null : constant Node_Id :=
Make_Qualified_Expression (Sloc (N),
Subtype_Mark =>
New_Occurrence_Of
(Underlying_Type (Ctyp), Sloc (N)),
Expression => Make_Null (Sloc (N)));
Convert_Null : constant Node_Id :=
Unchecked_Convert_To
(Ctyp, Qual_Null);
begin
Analyze_And_Resolve (Convert_Null, Ctyp);
Add_Association
(Component => Component,
Expr => Convert_Null,
Assoc_List => New_Assoc_List);
end;
-- Otherwise the component type is non-private
else
Expr := Make_Null (Sloc (N));
Set_Etype (Expr, Ctyp);
Add_Association
(Component => Component,
Expr => Expr,
Assoc_List => New_Assoc_List);
end if;
-- Ada 2012: If component is scalar with default value, use it
elsif Is_Scalar_Type (Ctyp)
and then Has_Default_Aspect (Ctyp)
then
Add_Association
(Component => Component,
Expr =>
Default_Aspect_Value
(First_Subtype (Underlying_Type (Ctyp))),
Assoc_List => New_Assoc_List);
elsif Has_Non_Null_Base_Init_Proc (Ctyp)
or else not Expander_Active
then
if Is_Record_Type (Ctyp)
and then Has_Discriminants (Ctyp)
and then not Is_Private_Type (Ctyp)
then
-- We build a partially initialized aggregate with the
-- values of the discriminants and box initialization
-- for the rest, if other components are present.
-- The type of the aggregate is the known subtype of
-- the component. The capture of discriminants must be
-- recursive because subcomponents may be constrained
-- (transitively) by discriminants of enclosing types.
-- For a private type with discriminants, a call to the
-- initialization procedure will be generated, and no
-- subaggregate is needed.
Capture_Discriminants : declare
Loc : constant Source_Ptr := Sloc (N);
Expr : Node_Id;
begin
Expr := Make_Aggregate (Loc, New_List, New_List);
Set_Etype (Expr, Ctyp);
-- If the enclosing type has discriminants, they have
-- been collected in the aggregate earlier, and they
-- may appear as constraints of subcomponents.
-- Similarly if this component has discriminants, they
-- might in turn be propagated to their components.
if Has_Discriminants (Typ) then
Add_Discriminant_Values (Expr, New_Assoc_List);
Propagate_Discriminants (Expr, New_Assoc_List);
elsif Has_Discriminants (Ctyp) then
Add_Discriminant_Values
(Expr, Component_Associations (Expr));
Propagate_Discriminants
(Expr, Component_Associations (Expr));
else
declare
Comp : Entity_Id;
begin
-- If the type has additional components, create
-- an OTHERS box association for them.
Comp := First_Component (Ctyp);
while Present (Comp) loop
if Ekind (Comp) = E_Component then
if not Is_Record_Type (Etype (Comp)) then
Append_To
(Component_Associations (Expr),
Make_Component_Association (Loc,
Choices =>
New_List (
Make_Others_Choice (Loc)),
Expression => Empty,
Box_Present => True));
end if;
exit;
end if;
Next_Component (Comp);
end loop;
end;
end if;
Add_Association
(Component => Component,
Expr => Expr,
Assoc_List => New_Assoc_List);
end Capture_Discriminants;
-- Otherwise the component type is not a record, or it has
-- not discriminants, or it is private.
else
Add_Association
(Component => Component,
Expr => Empty,
Assoc_List => New_Assoc_List,
Is_Box_Present => True);
end if;
-- Otherwise we only need to resolve the expression if the
-- component has partially initialized values (required to
-- expand the corresponding assignments and run-time checks).
elsif Present (Expr)
and then Is_Partially_Initialized_Type (Ctyp)
then
Resolve_Aggr_Expr (Expr, Component);
end if;
end Check_Box_Component;
elsif No (Expr) then
-- Ignore hidden components associated with the position of the
-- interface tags: these are initialized dynamically.
if not Present (Related_Type (Component)) then
Error_Msg_NE
("no value supplied for component &!", N, Component);
end if;
else
Resolve_Aggr_Expr (Expr, Component);
end if;
Next_Elmt (Component_Elmt);
end loop;
-- STEP 7: check for invalid components + check type in choice list
Step_7 : declare
Assoc : Node_Id;
New_Assoc : Node_Id;
Selectr : Node_Id;
-- Selector name
Typech : Entity_Id;
-- Type of first component in choice list
begin
if Present (Component_Associations (N)) then
Assoc := First (Component_Associations (N));
else
Assoc := Empty;
end if;
Verification : while Present (Assoc) loop
Selectr := First (Choices (Assoc));
Typech := Empty;
if Nkind (Selectr) = N_Others_Choice then
-- Ada 2005 (AI-287): others choice may have expression or box
if No (Others_Etype) and then Others_Box = 0 then
Error_Msg_N
("OTHERS must represent at least one component", Selectr);
elsif Others_Box = 1 and then Warn_On_Redundant_Constructs then
Error_Msg_N ("others choice is redundant?", Box_Node);
Error_Msg_N
("\previous choices cover all components?", Box_Node);
end if;
exit Verification;
end if;
while Present (Selectr) loop
New_Assoc := First (New_Assoc_List);
while Present (New_Assoc) loop
Component := First (Choices (New_Assoc));
if Chars (Selectr) = Chars (Component) then
if Style_Check then
Check_Identifier (Selectr, Entity (Component));
end if;
exit;
end if;
Next (New_Assoc);
end loop;
-- If no association, this is not a legal component of the type
-- in question, unless its association is provided with a box.
if No (New_Assoc) then
if Box_Present (Parent (Selectr)) then
-- This may still be a bogus component with a box. Scan
-- list of components to verify that a component with
-- that name exists.
declare
C : Entity_Id;
begin
C := First_Component (Typ);
while Present (C) loop
if Chars (C) = Chars (Selectr) then
-- If the context is an extension aggregate,
-- the component must not be inherited from
-- the ancestor part of the aggregate.
if Nkind (N) /= N_Extension_Aggregate
or else
Scope (Original_Record_Component (C)) /=
Etype (Ancestor_Part (N))
then
exit;
end if;
end if;
Next_Component (C);
end loop;
if No (C) then
Error_Msg_Node_2 := Typ;
Error_Msg_N ("& is not a component of}", Selectr);
end if;
end;
elsif Chars (Selectr) /= Name_uTag
and then Chars (Selectr) /= Name_uParent
then
if not Has_Discriminants (Typ) then
Error_Msg_Node_2 := Typ;
Error_Msg_N ("& is not a component of}", Selectr);
else
Error_Msg_N
("& is not a component of the aggregate subtype",
Selectr);
end if;
Check_Misspelled_Component (Components, Selectr);
end if;
elsif No (Typech) then
Typech := Base_Type (Etype (Component));
-- AI05-0199: In Ada 2012, several components of anonymous
-- access types can appear in a choice list, as long as the
-- designated types match.
elsif Typech /= Base_Type (Etype (Component)) then
if Ada_Version >= Ada_2012
and then Ekind (Typech) = E_Anonymous_Access_Type
and then
Ekind (Etype (Component)) = E_Anonymous_Access_Type
and then Base_Type (Designated_Type (Typech)) =
Base_Type (Designated_Type (Etype (Component)))
and then
Subtypes_Statically_Match (Typech, (Etype (Component)))
then
null;
elsif not Box_Present (Parent (Selectr)) then
Error_Msg_N
("components in choice list must have same type",
Selectr);
end if;
end if;
Next (Selectr);
end loop;
Next (Assoc);
end loop Verification;
end Step_7;
-- STEP 8: replace the original aggregate
Step_8 : declare
New_Aggregate : constant Node_Id := New_Copy (N);
begin
Set_Expressions (New_Aggregate, No_List);
Set_Etype (New_Aggregate, Etype (N));
Set_Component_Associations (New_Aggregate, New_Assoc_List);
Set_Check_Actuals (New_Aggregate, Check_Actuals (N));
Rewrite (N, New_Aggregate);
end Step_8;
-- Check the dimensions of the components in the record aggregate
Analyze_Dimension_Extension_Or_Record_Aggregate (N);
end Resolve_Record_Aggregate;
-----------------------------
-- Check_Can_Never_Be_Null --
-----------------------------
procedure Check_Can_Never_Be_Null (Typ : Entity_Id; Expr : Node_Id) is
Comp_Typ : Entity_Id;
begin
pragma Assert
(Ada_Version >= Ada_2005
and then Present (Expr)
and then Known_Null (Expr));
case Ekind (Typ) is
when E_Array_Type =>
Comp_Typ := Component_Type (Typ);
when E_Component
| E_Discriminant
=>
Comp_Typ := Etype (Typ);
when others =>
return;
end case;
if Can_Never_Be_Null (Comp_Typ) then
-- Here we know we have a constraint error. Note that we do not use
-- Apply_Compile_Time_Constraint_Error here to the Expr, which might
-- seem the more natural approach. That's because in some cases the
-- components are rewritten, and the replacement would be missed.
-- We do not mark the whole aggregate as raising a constraint error,
-- because the association may be a null array range.
Error_Msg_N
("(Ada 2005) null not allowed in null-excluding component??", Expr);
Error_Msg_N
("\Constraint_Error will be raised at run time??", Expr);
Rewrite (Expr,
Make_Raise_Constraint_Error
(Sloc (Expr), Reason => CE_Access_Check_Failed));
Set_Etype (Expr, Comp_Typ);
Set_Analyzed (Expr);
end if;
end Check_Can_Never_Be_Null;
---------------------
-- Sort_Case_Table --
---------------------
procedure Sort_Case_Table (Case_Table : in out Case_Table_Type) is
U : constant Int := Case_Table'Last;
K : Int;
J : Int;
T : Case_Bounds;
begin
K := 1;
while K < U loop
T := Case_Table (K + 1);
J := K + 1;
while J > 1
and then Expr_Value (Case_Table (J - 1).Lo) > Expr_Value (T.Lo)
loop
Case_Table (J) := Case_Table (J - 1);
J := J - 1;
end loop;
Case_Table (J) := T;
K := K + 1;
end loop;
end Sort_Case_Table;
end Sem_Aggr;
|
------------------------------------------------------------------------------
-- AGAR CORE LIBRARY --
-- A G A R . D A T A _ S O U R C E --
-- B o d y --
-- --
-- Copyright (c) 2018-2019, Julien Nadeau Carriere (vedge@csoft.net) --
-- Copyright (c) 2010, coreland (mark@coreland.ath.cx) --
-- --
-- Permission to use, copy, modify, and/or distribute this software for any --
-- purpose with or without fee is hereby granted, provided that the above --
-- copyright notice and this permission notice appear in all copies. --
-- --
-- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES --
-- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF --
-- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR --
-- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES --
-- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN --
-- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF --
-- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. --
------------------------------------------------------------------------------
package body Agar.Data_Source is
procedure Open_File
(Path : in String;
Mode : in String;
Source : out Data_Source_Access)
is
Ch_Path : aliased C.char_array := C.To_C (Path);
Ch_Mode : aliased C.char_array := C.To_C (Mode);
begin
Source := AG_OpenFile
(Path => To_Chars_Ptr(Ch_Path'Unchecked_Access),
Mode => To_Chars_Ptr(Ch_Mode'Unchecked_Access));
end;
package body IO is
Element_Bytes : constant AG_Size := Element_Type'Size / System.Storage_Unit;
procedure Read
(Source : in Data_Source_Not_Null_Access;
Buffer : out Element_Array_Type;
Read : out Element_Count_Type;
Status : out IO_Status) is
begin
Status := AG_Read
(Source => Source,
Buffer => Buffer (Buffer'First)'Address,
Size => Element_Bytes,
Members => Buffer'Length);
if Status = Success then
Read := Buffer'Length;
end if;
end Read;
procedure Read_At_Offset
(Source : in Data_Source_Not_Null_Access;
Offset : in AG_Offset;
Buffer : out Element_Array_Type;
Read : out Element_Count_Type;
Status : out IO_Status) is
begin
Status := AG_ReadAt
(Source => Source,
Buffer => Buffer (Buffer'First)'Address,
Size => Element_Bytes,
Members => Buffer'Length,
Offset => Offset);
if Status = Success then
Read := Buffer'Length;
end if;
end Read_At_Offset;
procedure Write
(Source : in Data_Source_Not_Null_Access;
Buffer : in Element_Array_Type;
Wrote : out Element_Count_Type;
Status : out IO_Status) is
begin
Status := AG_Write
(Source => Source,
Buffer => Buffer (Buffer'First)'Address,
Size => Element_Bytes,
Members => Buffer'Length);
if Status = Success then
Wrote := Buffer'Length;
end if;
end;
procedure Write_At_Offset
(Source : in Data_Source_Not_Null_Access;
Offset : in AG_Offset;
Buffer : in Element_Array_Type;
Wrote : out Element_Count_Type;
Status : out IO_Status) is
begin
Status := AG_WriteAt
(Source => Source,
Buffer => Buffer (Buffer'First)'Address,
Size => Element_Bytes,
Offset => Offset,
Members => Buffer'Length);
if Status = Success then
Wrote := Buffer'Length;
else
Wrote := 0;
end if;
end;
end IO;
function Read_String (Source : in Data_Source_Access) return String
is
Result : chars_ptr;
begin
Result := AG_ReadStringLen(Source, AG_Size(LOAD_STRING_MAX));
if Result = Null_Ptr then
raise Program_Error with ERR.Get_Error;
end if;
-- XXX FIXME leak
return C.To_Ada(Value(Result));
end;
function Read_String
(Source : in Data_Source_Access;
Max_Length : in Natural) return String
is
Result : chars_ptr;
begin
Result := AG_ReadStringLen(Source, AG_Size(Max_Length));
if Result = Null_Ptr then
raise Program_Error with ERR.Get_Error;
end if;
-- XXX FIXME leak
return C.To_Ada(Value(Result));
end;
function Read_Padded_String
(Source : in Data_Source_Access;
Length : in Natural) return String
is
Ch_Name : aliased C.char_array := (1 .. C.size_t(Length) => C.nul);
Result : AG_Size;
begin
Result := AG_CopyStringPadded
(Buffer => To_Chars_Ptr(Ch_Name'Unchecked_Access),
Source => Source,
Size => Ch_Name'Length);
if Integer(Result) = 0 then
raise Program_Error with ERR.Get_Error;
end if;
return C.To_Ada(Ch_Name);
end;
procedure Write_String
(Source : in Data_Source_Access;
Data : in String)
is
Ch_Data : aliased C.char_array := C.To_C(Data);
begin
AG_WriteString
(Source => Source,
Data => To_Chars_Ptr(Ch_Data'Unchecked_Access));
end;
procedure Write_Padded_String
(Source : in Data_Source_Access;
Data : in String;
Length : in Natural)
is
Ch_Data : aliased C.char_array := C.To_C(Data);
begin
AG_WriteStringPadded
(Source => Source,
Data => To_Chars_Ptr(Ch_Data'Unchecked_Access),
Length => AG_Size(Length));
end;
end Agar.Data_Source;
|
Pragma Ada_2012;
Package Connection_Types with Pure is
-- Name of the nodes.
Type Node is (A, B, C, D, E, F, G, H);
-- Type for indicating if a node is connected.
Type Connection_List is array(Node) of Boolean
with Size => 8, Object_Size => 8, Pack;
Function "&"( Left : Connection_List; Right : Node ) return Connection_List;
-- The actual map of the network connections.
Network : Constant Array (Node) of Connection_List:=
(
A => (C|D|E => True, others => False),
B => (D|E|F => True, others => False),
C => (A|D|G => True, others => False),
D => (C|A|B|E|H|G => True, others => False),
E => (D|A|B|F|H|G => True, others => False),
F => (B|E|H => True, others => False),
G => (C|D|E => True, others => False),
H => (D|E|F => True, others => False)
);
-- Values of the nodes.
Type Peg is range 1..8;
-- Indicator for which values have been assigned.
Type Used_Peg is array(Peg) of Boolean
with Size => 8, Object_Size => 8, Pack;
Function "&"( Left : Used_Peg; Right : Peg ) return Used_Peg;
-- Type describing the layout of the network.
Type Partial_Board is array(Node range <>) of Peg;
Subtype Board is Partial_Board(Node);
-- Determines if the given board is a solution or partial-solution.
Function Is_Solution ( Input : Partial_Board ) return Boolean;
-- Displays the board as text.
Function Image ( Input : Partial_Board ) Return String;
End Connection_Types;
|
-- { dg-do run }
procedure Pack12 is
type U16 is mod 2 ** 16;
type Key is record
Value : U16;
Valid : Boolean;
end record;
type Key_Buffer is record
Current, Latch : Key;
end record;
type Block is record
Keys : Key_Buffer;
Stamp : U16;
end record;
pragma Pack (Block);
My_Block : Block;
My_Stamp : constant := 16#1234#;
begin
My_Block.Stamp := My_Stamp;
My_Block.Keys.Latch := My_Block.Keys.Current;
if My_Block.Stamp /= My_Stamp then
raise Program_Error;
end if;
end;
|
-- SPDX-FileCopyrightText: 2019 Max Reznik <reznikmm@gmail.com>
--
-- SPDX-License-Identifier: MIT
-------------------------------------------------------------
with Program.Elements.Defining_Identifiers;
with Program.Lexical_Elements;
with Program.Elements.Discrete_Ranges;
with Program.Elements.Loop_Parameter_Specifications;
with Program.Element_Visitors;
package Program.Nodes.Loop_Parameter_Specifications is
pragma Preelaborate;
type Loop_Parameter_Specification is
new Program.Nodes.Node
and Program.Elements.Loop_Parameter_Specifications
.Loop_Parameter_Specification
and Program.Elements.Loop_Parameter_Specifications
.Loop_Parameter_Specification_Text
with private;
function Create
(Name : not null Program.Elements.Defining_Identifiers
.Defining_Identifier_Access;
In_Token : not null Program.Lexical_Elements.Lexical_Element_Access;
Reverse_Token : Program.Lexical_Elements.Lexical_Element_Access;
Definition : not null Program.Elements.Discrete_Ranges
.Discrete_Range_Access)
return Loop_Parameter_Specification;
type Implicit_Loop_Parameter_Specification is
new Program.Nodes.Node
and Program.Elements.Loop_Parameter_Specifications
.Loop_Parameter_Specification
with private;
function Create
(Name : not null Program.Elements.Defining_Identifiers
.Defining_Identifier_Access;
Definition : not null Program.Elements.Discrete_Ranges
.Discrete_Range_Access;
Is_Part_Of_Implicit : Boolean := False;
Is_Part_Of_Inherited : Boolean := False;
Is_Part_Of_Instance : Boolean := False;
Has_Reverse : Boolean := False)
return Implicit_Loop_Parameter_Specification
with Pre =>
Is_Part_Of_Implicit or Is_Part_Of_Inherited or Is_Part_Of_Instance;
private
type Base_Loop_Parameter_Specification is
abstract new Program.Nodes.Node
and Program.Elements.Loop_Parameter_Specifications
.Loop_Parameter_Specification
with record
Name : not null Program.Elements.Defining_Identifiers
.Defining_Identifier_Access;
Definition : not null Program.Elements.Discrete_Ranges
.Discrete_Range_Access;
end record;
procedure Initialize
(Self : in out Base_Loop_Parameter_Specification'Class);
overriding procedure Visit
(Self : not null access Base_Loop_Parameter_Specification;
Visitor : in out Program.Element_Visitors.Element_Visitor'Class);
overriding function Name
(Self : Base_Loop_Parameter_Specification)
return not null Program.Elements.Defining_Identifiers
.Defining_Identifier_Access;
overriding function Definition
(Self : Base_Loop_Parameter_Specification)
return not null Program.Elements.Discrete_Ranges.Discrete_Range_Access;
overriding function Is_Loop_Parameter_Specification
(Self : Base_Loop_Parameter_Specification)
return Boolean;
overriding function Is_Declaration
(Self : Base_Loop_Parameter_Specification)
return Boolean;
type Loop_Parameter_Specification is
new Base_Loop_Parameter_Specification
and Program.Elements.Loop_Parameter_Specifications
.Loop_Parameter_Specification_Text
with record
In_Token : not null Program.Lexical_Elements
.Lexical_Element_Access;
Reverse_Token : Program.Lexical_Elements.Lexical_Element_Access;
end record;
overriding function To_Loop_Parameter_Specification_Text
(Self : in out Loop_Parameter_Specification)
return Program.Elements.Loop_Parameter_Specifications
.Loop_Parameter_Specification_Text_Access;
overriding function In_Token
(Self : Loop_Parameter_Specification)
return not null Program.Lexical_Elements.Lexical_Element_Access;
overriding function Reverse_Token
(Self : Loop_Parameter_Specification)
return Program.Lexical_Elements.Lexical_Element_Access;
overriding function Has_Reverse
(Self : Loop_Parameter_Specification)
return Boolean;
type Implicit_Loop_Parameter_Specification is
new Base_Loop_Parameter_Specification
with record
Is_Part_Of_Implicit : Boolean;
Is_Part_Of_Inherited : Boolean;
Is_Part_Of_Instance : Boolean;
Has_Reverse : Boolean;
end record;
overriding function To_Loop_Parameter_Specification_Text
(Self : in out Implicit_Loop_Parameter_Specification)
return Program.Elements.Loop_Parameter_Specifications
.Loop_Parameter_Specification_Text_Access;
overriding function Is_Part_Of_Implicit
(Self : Implicit_Loop_Parameter_Specification)
return Boolean;
overriding function Is_Part_Of_Inherited
(Self : Implicit_Loop_Parameter_Specification)
return Boolean;
overriding function Is_Part_Of_Instance
(Self : Implicit_Loop_Parameter_Specification)
return Boolean;
overriding function Has_Reverse
(Self : Implicit_Loop_Parameter_Specification)
return Boolean;
end Program.Nodes.Loop_Parameter_Specifications;
|
-----------------------------------------------------------------------
-- asf-navigations-redirect -- Navigator to redirect to another page
-- Copyright (C) 2010, 2011 Stephane Carrez
-- Written by Stephane Carrez (Stephane.Carrez@gmail.com)
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-----------------------------------------------------------------------
with Util.Log.Loggers;
with Util.Beans.Objects;
package body ASF.Navigations.Redirect is
use Util.Log;
-- The logger
Log : constant Loggers.Logger := Loggers.Create ("ASF.Navigations.Redirect");
-- ------------------------------
-- Get the redirection view. Evaluate the EL expressions used in the view name.
-- ------------------------------
function Get_Redirection (Controller : in Redirect_Navigator;
Context : in ASF.Contexts.Faces.Faces_Context'Class)
return String is
Value : constant Util.Beans.Objects.Object
:= Controller.View_Expr.Get_Value (Context.Get_ELContext.all);
begin
if Util.Beans.Objects.Is_Null (Value) then
Log.Error ("The redirection URI is null");
return "";
end if;
return Util.Beans.Objects.To_String (Value);
end Get_Redirection;
-- ------------------------------
-- Navigate to the next page or action according to the controller's navigator.
-- The navigator controller redirects the user to another page.
-- ------------------------------
overriding
procedure Navigate (Controller : in Redirect_Navigator;
Context : in out ASF.Contexts.Faces.Faces_Context'Class) is
View : constant String := Controller.Get_Redirection (Context);
URI : constant String := Controller.View_Handler.Get_Redirect_URL (Context, View);
begin
Log.Debug ("Navigate by redirecting to {0}", URI);
Context.Get_Response.Send_Redirect (Location => URI);
Context.Response_Completed;
end Navigate;
-- ------------------------------
-- Create a navigation case to redirect to another page.
-- ------------------------------
function Create_Redirect_Navigator (To_View : in String;
Context : in EL.Contexts.ELContext'Class)
return Navigation_Access is
use EL.Expressions;
Expr : constant Expression := EL.Expressions.Create_Expression (To_View, Context);
Result : constant Redirect_Navigator_Access := new Redirect_Navigator;
begin
Result.View_Expr := Expr;
return Result.all'Access;
end Create_Redirect_Navigator;
end ASF.Navigations.Redirect;
|
-- { dg-do compile }
with Ada.Exceptions;
package body Noreturn3 is
procedure Raise_Error (E : Enum; ErrorMessage : String) is
function Msg return String is
begin
return "Error :" & ErrorMessage;
end;
begin
case E is
when One =>
Ada.Exceptions.Raise_Exception (Exc1'Identity, Msg);
when Two =>
Ada.Exceptions.Raise_Exception (Exc2'Identity, Msg);
when others =>
Ada.Exceptions.Raise_Exception (Exc3'Identity, Msg);
end case;
end;
end Noreturn3;
|
with Protypo.Api.Engine_Values.Engine_Value_Vectors;
package Callbacks is
use Protypo.Api;
function Sin (X : Engine_Values.Engine_Value_Vectors.Vector)
return Engine_Values.Engine_Value_Vectors.Vector;
end Callbacks;
|
pragma Ada_2012;
pragma Style_Checks (Off);
with Interfaces.C; use Interfaces.C;
limited with bits_types_struct_timeval_h;
limited with bits_types_struct_timespec_h;
limited with bits_types_u_sigset_t_h;
package sys_select_h is
-- unsupported macro: FD_SETSIZE __FD_SETSIZE
-- unsupported macro: NFDBITS __NFDBITS
-- arg-macro: procedure FD_SET (fd, fdsetp)
-- __FD_SET (fd, fdsetp)
-- arg-macro: procedure FD_CLR (fd, fdsetp)
-- __FD_CLR (fd, fdsetp)
-- arg-macro: procedure FD_ISSET (fd, fdsetp)
-- __FD_ISSET (fd, fdsetp)
-- arg-macro: procedure FD_ZERO (fdsetp)
-- __FD_ZERO (fdsetp)
-- `fd_set' type and related macros, and `select'/`pselect' declarations.
-- Copyright (C) 1996-2021 Free Software Foundation, Inc.
-- This file is part of the GNU C Library.
-- The GNU C Library is free software; you can redistribute it and/or
-- modify it under the terms of the GNU Lesser General Public
-- License as published by the Free Software Foundation; either
-- version 2.1 of the License, or (at your option) any later version.
-- The GNU C Library is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-- Lesser General Public License for more details.
-- You should have received a copy of the GNU Lesser General Public
-- License along with the GNU C Library; if not, see
-- <https://www.gnu.org/licenses/>.
-- POSIX 1003.1g: 6.2 Select from File Descriptor Sets <sys/select.h>
-- Get definition of needed basic types.
-- Get __FD_* definitions.
-- Get sigset_t.
-- Get definition of timer specification structures.
-- The fd_set member is required to be an array of longs.
subtype uu_fd_mask is long; -- /usr/include/sys/select.h:49
-- Some versions of <linux/posix_types.h> define this macros.
-- It's easier to assume 8-bit bytes than to get CHAR_BIT.
-- fd_set for select and pselect.
-- XPG4.2 requires this member name. Otherwise avoid the name
-- from the global namespace.
-- skipped anonymous struct anon_2
type fd_set_array947 is array (0 .. 15) of aliased uu_fd_mask;
type fd_set is record
fds_bits : aliased fd_set_array947; -- /usr/include/sys/select.h:64
end record
with Convention => C_Pass_By_Copy; -- /usr/include/sys/select.h:70
-- Maximum number of file descriptors in `fd_set'.
-- Sometimes the fd_set member is assumed to have this type.
subtype fd_mask is uu_fd_mask; -- /usr/include/sys/select.h:77
-- Number of bits per word of `fd_set' (some code assumes this is 32).
-- Access macros for `fd_set'.
-- Check the first NFDS descriptors each in READFDS (if not NULL) for read
-- readiness, in WRITEFDS (if not NULL) for write readiness, and in EXCEPTFDS
-- (if not NULL) for exceptional conditions. If TIMEOUT is not NULL, time out
-- after waiting the interval specified therein. Returns the number of ready
-- descriptors, or -1 for errors.
-- This function is a cancellation point and therefore not marked with
-- __THROW.
function c_select
(uu_nfds : int;
uu_readfds : access fd_set;
uu_writefds : access fd_set;
uu_exceptfds : access fd_set;
uu_timeout : access bits_types_struct_timeval_h.timeval) return int -- /usr/include/sys/select.h:101
with Import => True,
Convention => C,
External_Name => "select";
-- Same as above only that the TIMEOUT value is given with higher
-- resolution and a sigmask which is been set temporarily. This version
-- should be used.
-- This function is a cancellation point and therefore not marked with
-- __THROW.
function pselect
(uu_nfds : int;
uu_readfds : access fd_set;
uu_writefds : access fd_set;
uu_exceptfds : access fd_set;
uu_timeout : access constant bits_types_struct_timespec_h.timespec;
uu_sigmask : access constant bits_types_u_sigset_t_h.uu_sigset_t) return int -- /usr/include/sys/select.h:113
with Import => True,
Convention => C,
External_Name => "pselect";
-- Define some inlines helping to catch common problems.
end sys_select_h;
|
--
-- The author disclaims copyright to this source code. In place of
-- a legal notice, here is a blessing:
--
-- May you do good and not evil.
-- May you find forgiveness for yourself and forgive others.
-- May you share freely, not taking more than you give.
--
with Ada.Strings.Unbounded;
with Ada.Containers.Vectors;
with Types;
limited with Symbols;
with Rule_Lists;
package Rules is
subtype Rule_Access is Rule_Lists.Rule_Access;
subtype Rule_List is Rule_Lists.Lists.List;
type Dot_Type is new Natural;
Ignore : constant Dot_Type := Dot_Type'Last;
type Rule_Symbol_Access is access all Symbols.Symbol_Record;
subtype Line_Number is Types.Line_Number;
package RHS_Vectors is
new Ada.Containers.Vectors (Index_Type => Dot_Type,
Element_Type => Rule_Symbol_Access);
use Ada.Strings.Unbounded;
package Alias_Vectors is
new Ada.Containers.Vectors (Index_Type => Dot_Type,
Element_Type => Unbounded_String);
subtype T_Code is Unbounded_String;
Null_Code : T_Code renames Null_Unbounded_String;
function "=" (Left, Right : in T_Code) return Boolean
renames Ada.Strings.Unbounded."=";
-- A configuration is a production rule of the grammar together with
-- a mark (dot) showing how much of that rule has been processed so far.
-- Configurations also contain a follow-set which is a list of terminal
-- symbols which are allowed to immediately follow the end of the rule.
-- Every configuration is recorded as an instance of the following:
-- Each production rule in the grammar is stored in the following
-- structure.
type Index_Number is new Integer;
type Rule_Number is new Integer;
type Rule_Record is
record
LHS : Rule_Symbol_Access := null;
LHS_Alias : Unbounded_String := Null_Unbounded_String;
-- Alias for the LHS (NULL if none)
LHS_Start : Boolean := False;
-- True if left-hand side is the start symbol
Rule_Line : Line_Number := 0;
-- Line number for the rule
RHS : RHS_Vectors.Vector := RHS_Vectors.Empty_Vector;
-- The RHS symbols
RHS_Alias : Alias_Vectors.Vector := Alias_Vectors.Empty_Vector;
-- An alias for each RHS symbol (NULL if none)
Line : Line_Number := 0;
-- Line number at which code begins
Code : T_Code := Null_Unbounded_String;
-- The code executed when this rule is reduced
Code_Prefix : T_Code := Null_Unbounded_String;
-- Setup code before code[] above
Code_Suffix : T_Code := Null_Unbounded_String;
-- Breakdown code after code[] above
No_Code : Boolean := False;
-- True if this rule has no associated C code
Code_Emitted : Boolean := False;
-- True if the code has been emitted already
Prec_Symbol : Rule_Symbol_Access := null;
-- Precedence symbol for this rule
Index : Index_Number := 0;
-- An index number for this rule
Number : Rule_Number := 0;
-- Rule number as used in the generated tables
Can_Reduce : Boolean := False;
-- True if this rule is ever reduced
Does_Reduce : Boolean := False;
-- Reduce actions occur after optimization
Never_Reduce : Boolean := False;
-- Reduce is theoretically possible, but prevented
-- by actions or other outside implementation
Next_LHS : Rule_Access := null;
-- Next rule with the same LHS
end record;
procedure Rule_Sort (List : in out Rule_List);
-- Sort a list of rules in order of increasing iRule Value
procedure Assing_Sequential_Rule_Numbers (List : in out Rule_List);
end Rules;
|
package openGL.Conversions
is
function to_Vector_4 (From : in lucid_Color) return Vector_4;
function to_Vector_4 (From : in light_Color) return Vector_4;
function to_light_Color (From : in lucid_Color) return light_Color;
function "+" (From : in lucid_Color) return light_Color renames to_light_Color;
end openGL.Conversions;
|
----------------------------------------------------------------------------
-- 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 System;
with Interfaces;
with Interfaces.C;
with Interfaces.C.Pointers;
with Interfaces.C.Strings;
with Ada.Containers.Indefinite_Vectors;
package AdaAugeas is
pragma Elaborate_Body;
package String_Vectors is new Ada.Containers.Indefinite_Vectors
(Natural, String);
use String_Vectors;
subtype aug_flags is Interfaces.C.unsigned;
AUG_NONE : constant aug_flags := 0;
AUG_SAVE_BACKUP : constant aug_flags := 1;
AUG_SAVE_NEWFILE : constant aug_flags := 2;
AUG_TYPE_CHECK : constant aug_flags := 4;
AUG_NO_STDINC : constant aug_flags := 8;
AUG_SAVE_NOOP : constant aug_flags := 16;
AUG_NO_LOAD : constant aug_flags := 32;
AUG_NO_MODL_AUTOLOAD : constant aug_flags := 64;
AUG_ENABLE_SPAN : constant aug_flags := 128;
AUG_NO_ERR_CLOSE : constant aug_flags := 256;
AUG_TRACE_MODULE_LOADING : constant aug_flags := 512;
type Augeas_Type is private;
Null_Augeas : constant Augeas_Type;
procedure Close (Aug : in out Augeas_Type);
function Copy (Aug : Augeas_Type; Src : String; Dst : String)
return Integer;
function Get (Aug : Augeas_Type; Path : String) return String;
function Init
(Aug : out Augeas_Type; Root : String; Loadpath : String;
Flag : aug_flags) return Integer;
function Match (Aug : Augeas_Type; Path : String)
return String_Vectors.Vector;
function Move (Aug : Augeas_Type; Src : String; Dst : String)
return Integer;
function Remove (Aug : Augeas_Type; Path : String) return Integer;
function Save (Aug : Augeas_Type) return Integer;
function Set
(Aug : Augeas_Type; Path : String; Value : String) return Integer;
function Setm
(Aug : Augeas_Type; Base : String; Sub : String; Value : String)
return Integer;
private
type Augeas_Type is new System.Address;
Null_Augeas : constant Augeas_Type := Augeas_Type (System.Null_Address);
subtype CNatural is Interfaces.C.int range 0 .. Interfaces.C.int'Last;
type Vector is array (CNatural range <>) of
aliased Interfaces.C.Strings.chars_ptr;
package Match_Pointer is new Interfaces.C.Pointers (Index => CNatural,
Element => Interfaces.C.Strings.chars_ptr, Element_Array => Vector,
Default_Terminator => Interfaces.C.Strings.Null_Ptr);
-- This is C char **
subtype Chars_Ptr_Ptr is Match_Pointer.Pointer;
end AdaAugeas;
|
-- part of AdaYaml, (c) 2017 Felix Krause
-- released under the terms of the MIT license, see the file "copying.txt"
with Interfaces.C;
package body Lexer.Source.C_Handler is
use type Yaml.C.Bool;
procedure Read_Data (S : in out Instance; Buffer : out String;
Length : out Natural) is
begin
if not S.Handler.all (S.Data, Buffer (Buffer'First)'Address,
Buffer'Length, Interfaces.C.size_t (Length)) then
raise Lexer_Error with "Error when reading into buffer";
end if;
end Read_Data;
function As_Source (Data : System.Address; Handler : Yaml.C.Read_Handler)
return Pointer is
(new Instance'(Source.Instance with
Handler => Handler, Data => Data));
end Lexer.Source.C_Handler;
|
-----------------------------------------------------------------------
-- upload_server -- Example of server with a servlet
-- Copyright (C) 2012, 2015, 2018, 2021 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 Servlet.Server.Web;
with Servlet.Core;
with Upload_Servlet;
with Util.Log.Loggers;
procedure Upload_Server is
CONFIG_PATH : constant String := "samples.properties";
Upload : aliased Upload_Servlet.Servlet;
App : aliased Servlet.Core.Servlet_Registry;
WS : Servlet.Server.Web.AWS_Container;
Log : constant Util.Log.Loggers.Logger := Util.Log.Loggers.Create ("Upload_Server");
begin
Util.Log.Loggers.Initialize (CONFIG_PATH);
-- Register the servlets and filters
App.Add_Servlet (Name => "upload", Server => Upload'Unchecked_Access);
-- Define servlet mappings
App.Add_Mapping (Name => "upload", Pattern => "*.html");
WS.Register_Application ("/upload", App'Unchecked_Access);
Log.Info ("Connect you browser to: http://localhost:8080/upload/upload.html");
WS.Start;
delay 6000.0;
end Upload_Server;
|
-----------------------------------------------------------------------
-- css-analysis-rules -- CSS Analysis Rules
-- Copyright (C) 2017, 2018 Stephane Carrez
-- Written by Stephane Carrez (Stephane.Carrez@gmail.com)
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-----------------------------------------------------------------------
with Ada.Finalization;
with Ada.Containers.Vectors;
private with Ada.Containers.Indefinite_Ordered_Maps;
with CSS.Core.Errors;
with CSS.Core.Values;
with CSS.Core.Properties;
with CSS.Printer;
with CSS.Core.Sheets;
-- == Analysis of CSS Rules ==
-- The <tt>CSS.Analysis.Rules</tt> package defines the rules for the verification of
-- value properties. The list of definition is stored in the rule repository.
-- Each rule is associated with a name. The rule is represented as a tree whose nodes
-- define what is valid for a given property value.
package CSS.Analysis.Rules is
subtype Location is CSS.Core.Location;
type Match_Result;
type Rule_Type is limited new Ada.Finalization.Limited_Controlled with private;
type Rule_Type_Access is access all Rule_Type'Class;
-- Get the source location of the rule definition.
function Get_Location (Rule : in Rule_Type) return Location;
-- Set the min and max repeat for this rule.
procedure Set_Repeat (Rule : in out Rule_Type;
Min : in Natural;
Max : in Natural;
Sep : in Boolean := False);
-- Append the <tt>New_Rule</tt> at end of the rule's list.
procedure Append (Rule : in out Rule_Type;
New_Rule : in Rule_Type_Access);
-- Print the rule definition to the print stream.
procedure Print (Rule : in Rule_Type;
Stream : in out CSS.Printer.File_Type'Class);
-- Check if the value matches the rule.
function Match (Rule : in Rule_Type;
Value : in CSS.Core.Values.Value_Type) return Boolean;
-- Check if the value matches the identifier defined by the rule.
function Match (Rule : access Rule_Type;
Value : in CSS.Core.Values.Value_List;
Result : access Match_Result;
Pos : in Positive := 1) return Natural;
type Match_Info_Type is record
First : Natural := 0;
Last : Natural := 0;
Rule : access Rule_Type'Class;
end record;
package Match_Info_Vectors is
new Ada.Containers.Vectors (Index_Type => Positive,
Element_Type => Match_Info_Type);
type Match_Result is record
List : Match_Info_Vectors.Vector;
end record;
-- Returns True if the two rules refer to the same rule definition.
function Is_Rule (Rule1, Rule2 : access Rule_Type'Class) return Boolean;
-- Rule that describes an identifier such as 'left' or 'right'.
type Ident_Rule_Type (Len : Natural) is new Rule_Type with private;
-- Print the rule definition to the print stream.
overriding
procedure Print (Rule : in Ident_Rule_Type;
Stream : in out CSS.Printer.File_Type'Class);
-- Check if the value matches the identifier defined by the rule.
overriding
function Match (Rule : in Ident_Rule_Type;
Value : in CSS.Core.Values.Value_Type) return Boolean;
type Repository_Type is limited new Ada.Finalization.Limited_Controlled with private;
-- Find a rule that describes a property.
-- Returns the rule or null if there is no rule for the property.
function Find_Property (Repository : in Repository_Type;
Name : in String) return Rule_Type_Access;
-- Create a property rule and add it to the repository under the given name.
-- The rule is empty and is ready to be defined.
procedure Create_Property (Repository : in out Repository_Type;
Name : in String;
Rule : in Rule_Type_Access);
-- Create a rule definition and add it to the repository under the given name.
-- The rule definition is used by other rules to represent complex rules.
-- The rule is empty and is ready to be defined.
procedure Create_Definition (Repository : in out Repository_Type;
Name : in String;
Rule : in Rule_Type_Access);
-- Create a rule that describes an identifier;
function Create_Identifier (Name : in String;
Loc : in Location) return Rule_Type_Access;
-- Create a rule that describes either a definition or a pre-defined type.
function Create_Definition (Repository : in out Repository_Type;
Name : in String;
Loc : in Location) return Rule_Type_Access;
type Group_Type is (GROUP_ONLY_ONE, GROUP_DBAR, GROUP_AND, GROUP_SEQ, GROUP_PARAMS);
-- Create a rule that describes a group of rules whose head is passed in <tt>Rules</tt>.
procedure Append_Group (Into : out Rule_Type_Access;
First : in Rule_Type_Access;
Second : in Rule_Type_Access;
Kind : in Group_Type);
-- Create a rule that describes a function call with parameters.
function Create_Function (Name : in String;
Params : in Rule_Type_Access;
Loc : in Location) return Rule_Type_Access;
procedure Analyze (Repository : in out Repository_Type;
Sheet : in CSS.Core.Sheets.CSSStylesheet;
Report : in out CSS.Core.Errors.Error_Handler'Class);
-- Search for properties that use the given rule and call the Process procedure
-- for each property that uses the rule definition.
procedure Search (Repository : in out Repository_Type;
Sheet : in CSS.Core.Sheets.CSSStylesheet;
Rule : access Rule_Type'Class;
Process : access procedure (Prop : in CSS.Core.Properties.CSSProperty;
Match : in Match_Result));
-- Print the repository rule definitions to the print stream.
procedure Print (Stream : in out CSS.Printer.File_Type'Class;
Repository : in Repository_Type);
private
type Rule_Type_Access_Array is array (Positive range <>) of Rule_Type_Access;
type Rule_Type is limited new Ada.Finalization.Limited_Controlled with record
Used : Natural := 0;
Loc : Location;
Next : Rule_Type_Access;
Min_Repeat : Natural := 0;
Max_Repeat : Natural := 0;
Comma_Sep : Boolean := False;
end record;
overriding
procedure Finalize (Rule : in out Rule_Type);
type Type_Rule_Type (Len : Natural) is new Rule_Type with record
Rule : Rule_Type_Access;
end record;
-- Check if the value matches the type.
overriding
function Match (Rule : in Type_Rule_Type;
Value : in CSS.Core.Values.Value_Type) return Boolean;
type Ident_Rule_Type (Len : Natural) is new Rule_Type with record
Ident : String (1 .. Len);
end record;
type Definition_Rule_Type (Len : Natural) is new Rule_Type with record
Ident : String (1 .. Len);
Rule : Rule_Type_Access;
end record;
type Definition_Rule_Type_Access is access all Definition_Rule_Type'Class;
-- Print the rule definition to the print stream.
overriding
procedure Print (Rule : in Definition_Rule_Type;
Stream : in out CSS.Printer.File_Type'Class);
-- Check if the value matches the rule.
overriding
function Match (Rule : in Definition_Rule_Type;
Value : in CSS.Core.Values.Value_Type) return Boolean;
-- Check if the value matches the identifier defined by the rule.
overriding
function Match (Rule : access Definition_Rule_Type;
Value : in CSS.Core.Values.Value_List;
Result : access Match_Result;
Pos : in Positive := 1) return Natural;
type Group_Rule_Type is new Rule_Type with record
List : Rule_Type_Access;
Count : Natural := 0;
Kind : Group_Type;
end record;
-- Print the rule definition to the print stream.
overriding
procedure Print (Rule : in Group_Rule_Type;
Stream : in out CSS.Printer.File_Type'Class);
-- Check if the value matches the rule.
overriding
function Match (Rule : in Group_Rule_Type;
Value : in CSS.Core.Values.Value_Type) return Boolean;
-- Check if the value matches the identifier defined by the rule.
overriding
function Match (Group : access Group_Rule_Type;
Value : in CSS.Core.Values.Value_List;
Result : access Match_Result;
Pos : in Positive := 1) return Natural;
overriding
procedure Finalize (Rule : in out Group_Rule_Type);
type Function_Rule_Type (Len : Natural) is new Group_Rule_Type with record
Ident : String (1 .. Len);
end record;
-- Print the rule definition to the print stream.
overriding
procedure Print (Rule : in Function_Rule_Type;
Stream : in out CSS.Printer.File_Type'Class);
-- Check if the value matches the function with its parameters.
overriding
function Match (Rule : access Function_Rule_Type;
Value : in CSS.Core.Values.Value_List;
Result : access Match_Result;
Pos : in Positive := 1) return Natural;
package Rule_Maps is
new Ada.Containers.Indefinite_Ordered_Maps (Key_Type => String,
Element_Type => Rule_Type_Access,
"=" => "=",
"<" => "<");
package Rule_Vectors is
new Ada.Containers.Vectors (Index_Type => Positive,
Element_Type => Definition_Rule_Type_Access);
type Repository_Type is limited new Ada.Finalization.Limited_Controlled with record
-- The rule names with their definitions. These rules are noted with: <name>.
Rules : Rule_Maps.Map;
-- The property names which are valid and their associated rule.
Properties : Rule_Maps.Map;
-- The pre-defined and built-in rules used to represent the basic types (ex: <color>).
Types : Rule_Maps.Map;
-- The list of definition rules that have not been found and must be
-- resolved before doing the analysis.
Deferred : Rule_Vectors.Vector;
end record;
procedure Resolve (Repository : in out Repository_Type);
overriding
procedure Initialize (Repository : in out Repository_Type);
-- Release the rules allocated dynamically.
overriding
procedure Finalize (Repository : in out Repository_Type);
-- Erase all the rules that have been loaded in the repository.
procedure Clear (Repository : in out Repository_Type);
procedure Clear (Rules : in out Rule_Maps.Map);
end CSS.Analysis.Rules;
|
package body BBqueue.Buffers.FFI is
function Create (Size : Buffer_Size) return BufferPtr is
begin
return new BBqueue.Buffers.Buffer (Size);
end Create;
procedure Drop (Ptr : in out BufferPtr) is
begin
Free (Ptr);
end Drop;
end BBqueue.Buffers.FFI;
|
with avtas.lmcp.byteBuffers; use avtas.lmcp.byteBuffers;
package -<full_series_name_dots>-.object is
type Object is abstract new avtas.lmcp.object.Object with private;
type Object_Acc is access all Object;
type Object_Any is access all Object'Class;
overriding function getSeriesVersion(this : Object) return UInt16 is (-<series_version>-);
overriding function getSeriesName(this : Object) return String is ("-<series_name>-");
overriding function getSeriesNameAsLong(this : Object) return Int64 is (-<series_id>-);
private
type Object is abstract new avtas.lmcp.object.Object with null record;
end -<full_series_name_dots>-.object;
|
with GL; use GL;
with Glut; use Glut;
package ada_sphere_procs is
procedure display;
procedure reshape (w : Integer; h : Integer);
procedure menu (value : Integer);
procedure init;
end ada_sphere_procs;
|
-----------------------------------------------------------------------
-- asf-utils -- Various utility operations for ASF
-- Copyright (C) 2009, 2010, 2011, 2012, 2013 Stephane Carrez
-- Written by Stephane Carrez (Stephane.Carrez@gmail.com)
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-----------------------------------------------------------------------
with Util.Strings;
with Ada.Strings.Unbounded;
with Util.Texts.Formats;
with Util.Beans.Objects;
package ASF.Utils is
pragma Preelaborate;
-- Add in the <b>names</b> set, the basic text attributes that can be set
-- on HTML elements (dir, lang, style, title).
procedure Set_Text_Attributes (Names : in out Util.Strings.String_Set.Set);
-- Add in the <b>names</b> set, the onXXX attributes that can be set
-- on HTML elements (accesskey, tabindex, onXXX).
procedure Set_Interactive_Attributes (Names : in out Util.Strings.String_Set.Set);
-- Add in the <b>names</b> set, the size attributes that can be set
-- on HTML elements.
procedure Set_Input_Attributes (Names : in out Util.Strings.String_Set.Set);
-- Add in the <b>names</b> set, the size attributes that can be set
-- on <textarea> elements.
procedure Set_Textarea_Attributes (Names : in out Util.Strings.String_Set.Set);
-- Add in the <b>names</b> set, the online and onunload attributes that can be set
-- on <body> elements.
procedure Set_Body_Attributes (Names : in out Util.Strings.String_Set.Set);
-- Add in the <b>names</b> set, the dir, lang attributes that can be set
-- on <head> elements.
procedure Set_Head_Attributes (Names : in out Util.Strings.String_Set.Set);
-- Add in the <b>names</b> set, the onreset and onsubmit attributes that can be set
-- on <form> elements.
procedure Set_Form_Attributes (Names : in out Util.Strings.String_Set.Set);
-- Add in the <b>names</b> set, the attributes which are specific to a link.
procedure Set_Link_Attributes (Names : in out Util.Strings.String_Set.Set);
-- Add in the <b>names</b> set, the attributes which are specific to an input file.
procedure Set_File_Attributes (Names : in out Util.Strings.String_Set.Set);
type Object_Array is array (Positive range <>) of Util.Beans.Objects.Object;
package Formats is
new Util.Texts.Formats (Stream => Ada.Strings.Unbounded.Unbounded_String,
Char => Character,
Input => String,
Value => Util.Beans.Objects.Object,
Value_List => Object_Array,
Put => Ada.Strings.Unbounded.Append,
To_Input => Util.Beans.Objects.To_String);
end ASF.Utils;
|
with Interfaces.C.Strings;
-- Source code reporting using GCC built-ins to avoid dependencies on GNAT
-- libraries.
package Trendy_Locations is
subtype Char_Ptr is Interfaces.C.Strings.chars_ptr;
function File_Line return Natural;
function File_Name return Char_Ptr;
function Subprogram_Name return Char_Ptr;
function Image (Str : Char_Ptr) return String renames Interfaces.C.Strings.Value;
pragma Import (Intrinsic, File_Line, "__builtin_LINE");
pragma Import (Intrinsic, File_Name, "__builtin_FILE");
pragma Import (Intrinsic, Subprogram_Name, "__builtin_FUNCTION");
-- Prevent from having to lug around files and lines separately by
-- simply making them part of the same group.
type Source_Location is record
File : Char_Ptr;
Line : Natural;
end record;
-- Call with no parameters to make a file/line location at the current
-- in the file.
function Make_Source_Location (File : Char_Ptr := File_Name;
Line : Natural := File_Line) return Source_Location;
function Image (Loc : Source_Location) return String;
end Trendy_Locations;
|
------------------------------------------------------------------------------
-- --
-- J E W L . W I N 3 2 _ I N T E R F A C E --
-- --
-- This is a private package containing definitions relating to the --
-- use of the underlying Win32 API targetted by this implementation --
-- of the JEWL.Windows package. --
-- --
-- Copyright (C) John English 2000. Contact address: je@brighton.ac.uk --
-- This software is released under the terms of the GNU General Public --
-- License and is intended primarily for educational use. Please contact --
-- the author to report bugs, suggestions and modifications. --
-- --
------------------------------------------------------------------------------
-- $Id: jewl-win32_interface.ads 1.7 2007/01/08 17:00:00 JE Exp $
------------------------------------------------------------------------------
--
-- $Log: jewl-win32_interface.ads $
-- Revision 1.7 2007/01/08 17:00:00 JE
-- * Fixed linker options in JEWL.Win32_Interface to accommodate changes to GNAT
-- GPL 2006 compiler (thanks to John McCormick for this)
-- * Added delay in message loop to avoid the appearance of hogging 100% of CPU
-- time
--
-- Revision 1.6 2001/11/02 16:00:00 JE
-- * Fixed canvas bug when saving an empty canvas
-- * Restore with no prior save now acts as erase
-- * Removed redundant variable declaration in Image function
--
-- Revision 1.5 2001/08/22 15:00:00 JE
-- * Minor bugfix to Get_Text for combo boxes
-- * Minor changes to documentation (including new example involving dialogs)
--
-- Revision 1.4 2001/01/25 09:00:00 je
-- Changes visible to the user:
--
-- * Added support for drawing bitmaps on canvases (Draw_Image operations
-- and new type Image_Type)
-- * Added Play_Sound
-- * Added several new operations on all windows: Get_Origin, Get_Width,
-- Get_Height, Set_Origin, Set_Size and Focus
-- * Added several functions giving screen and window dimensions: Screen_Width,
-- Screen_Height, Frame_Width, Frame_Height, Dialog_Width, Dialog_Height and
-- Menu_Height
-- * Canvases can now handle keyboard events: new constructor and Key_Code added
-- * Added procedure Play_Sound
-- * Operations "+" and "-" added for Point_Type
-- * Pens can now be zero pixels wide
-- * The absolute origin of a frame can now have be specified when the frame
-- is created
-- * Added new File_Dialog operations Add_Filter and Set_Directory
-- * Added Get_Line renames to JEWL.IO for compatibility with Ada.Text_IO
-- * Added all the Get(File,Item) operations mentioned in documentation but
-- unaccountably missing :-(
-- * Documentation updated to reflect the above changes
-- * HTML versions of public package specifications added with links from
-- main documentation pages
--
-- Other internal changes:
--
-- * Canvas fonts, pens etc. now use JEWL.Reference_Counted_Type rather than
-- reinventing this particular wheel, as do images
-- * Various minor code formatting changes: some code reordered for clarity,
-- some comments added or amended,
-- * Changes introduced in 1.2 to support GNAT 3.10 have been reversed, since
-- GNAT 3.10 still couldn't compile this code correctly... ;-(
--
-- Outstanding issues:
--
-- * Optimisation breaks the code (workaround: don't optimise)
--
-- Revision 1.3 2000/07/07 12:00:00 je
-- * JEWL.Simple_Windows added; JEWL.IO modified to use JEWL.Simple_Windows.
-- * JEWL.IO bug fix: Put_Line to file wrote newline to standard output
-- instead of to the file (thanks to Jeff Carter for pointing this out).
-- * Panels fixed so that mouse clicks are passed on correctly to subwindows.
-- * Memos fixed so that tabs are handled properly.
-- * Password feature added to editboxes.
-- * Minor typos fixed in comments within the package sources.
-- * Documentation corrected and updated following comments from Moti Ben-Ari
-- and Don Overheu.
--
-- Revision 1.2 2000/04/18 20:00:00 je
-- * Minor code changes to enable compilation by GNAT 3.10
-- * Minor documentation errors corrected
-- * Some redundant "with" clauses removed
--
-- Revision 1.1 2000/04/09 21:00:00 je
-- Initial revision
--
------------------------------------------------------------------------------
with Ada.Unchecked_Conversion;
with System;
with Interfaces.C;
private package JEWL.Win32_Interface is
use type Interfaces.C.Unsigned_Long; -- reported by Pierre Breguet to be
-- required by Object Ada compiler
----------------------------------------------------------------------------
-- Win32 flags and constants
----------------------------------------------------------------------------
BI_BITFIELDS : constant := 3;
BITMAP_MAGIC : constant := 16#4D42#; -- "BM"
BLACK_PEN : constant := 7;
BM_GETCHECK : constant := 240;
BM_SETCHECK : constant := 241;
BS_AUTOCHECKBOX : constant := 16#00000003#;
BS_AUTORADIOBUTTON : constant := 16#00000009#;
BS_DEFPUSHBUTTON : constant := 16#00000001#;
BS_GROUPBOX : constant := 16#00000007#;
BS_HOLLOW : constant := 1;
BS_PUSHBUTTON : constant := 16#00000000#;
CBM_INIT : constant := 4;
CBS_AUTOHSCROLL : constant := 16#00000040#;
CBS_DROPDOWN : constant := 16#00000002#;
CBS_DROPDOWNLIST : constant := 16#00000003#;
CB_ADDSTRING : constant := 323;
CB_DELETESTRING : constant := 324;
CB_GETCOUNT : constant := 326;
CB_GETCURSEL : constant := 327;
CB_GETLBTEXT : constant := 328;
CB_GETLBTEXTLEN : constant := 329;
CB_INSERTSTRING : constant := 330;
CB_RESETCONTENT : constant := 331;
CB_SETCURSEL : constant := 334;
CC_RGBINIT : constant := 16#00000001#;
CF_FORCEFONTEXIST : constant := 16#00010000#;
CF_INITTOLOGFONTSTRUCT : constant := 16#00000040#;
CF_SCREENFONTS : constant := 16#00000001#;
COLOR_BTNFACE : constant := 15;
CS_HREDRAW : constant := 16#00000002#;
CS_VREDRAW : constant := 16#00000001#;
CW_USEDEFAULT : constant := Interfaces.C.Int'First;
DIB_RGB_COLORS : constant := 0;
DLGC_WANTMESSAGE : constant := 16#0004#;
DT_CENTER : constant := 16#00000001#;
DT_LEFT : constant := 16#00000000#;
DT_NOCLIP : constant := 16#00000100#;
DT_RIGHT : constant := 16#00000002#;
EM_GETLINE : constant := 196;
EM_GETLINECOUNT : constant := 186;
EM_GETMODIFY : constant := 184;
EM_GETSEL : constant := 176;
EM_LINEFROMCHAR : constant := 201;
EM_LINEINDEX : constant := 187;
EM_LINELENGTH : constant := 193;
EM_REPLACESEL : constant := 194;
EM_SCROLLCARET : constant := 183;
EM_SETMODIFY : constant := 185;
EM_SETSEL : constant := 177;
EM_SETTABSTOPS : constant := 203;
ES_AUTOHSCROLL : constant := 16#0080#;
ES_AUTOVSCROLL : constant := 16#0040#;
ES_MULTILINE : constant := 16#0004#;
ES_NOHIDESEL : constant := 16#0100#;
ES_PASSWORD : constant := 16#0020#;
ES_WANTRETURN : constant := 16#1000#;
GWL_USERDATA : constant := -21;
GWL_WNDPROC : constant := -4;
GW_HWNDNEXT : constant := 2;
IDC_ARROW : constant := 32512;
IDI_APPLICATION : constant := 32512;
IDYES : constant := 6;
LB_ADDSTRING : constant := 384;
LB_DELETESTRING : constant := 386;
LB_GETCOUNT : constant := 395;
LB_GETCURSEL : constant := 392;
LB_GETTEXT : constant := 393;
LB_GETTEXTLEN : constant := 394;
LB_INSERTSTRING : constant := 385;
LB_RESETCONTENT : constant := 388;
LB_SETCURSEL : constant := 390;
LOGPIXELSX : constant := 88;
LOGPIXELSY : constant := 90;
MB_ICONINFORMATION : constant := 16#00000040#;
MB_ICONQUESTION : constant := 16#00000020#;
MB_ICONSTOP : constant := 16#00000010#;
MB_OK : constant := 16#00000000#;
MB_SETFOREGROUND : constant := 16#00010000#;
MB_TASKMODAL : constant := 16#00002000#;
MB_YESNO : constant := 16#00000004#;
MF_BYCOMMAND : constant := 16#0000#;
MF_CHECKED : constant := 16#0008#;
MF_DISABLED : constant := 16#0002#;
MF_ENABLED : constant := 16#0000#;
MF_GRAYED : constant := 16#0001#;
MF_POPUP : constant := 16#0010#;
MF_SEPARATOR : constant := 16#0800#;
MF_STRING : constant := 16#0000#;
MF_UNCHECKED : constant := 16#0000#;
NULL_BRUSH : constant := 5;
NULL_PEN : constant := 8;
OFN_CREATEPROMPT : constant := 16#00002000#;
OFN_FILEMUSTEXIST : constant := 16#00001000#;
OFN_HIDEREADONLY : constant := 16#00000004#;
OFN_OVERWRITEPROMPT : constant := 16#00000002#;
OFN_PATHMUSTEXIST : constant := 16#00000800#;
PM_REMOVE : constant := 1;
SM_CXDLGFRAME : constant := 7;
SM_CXEDGE : constant := 45;
SM_CXFRAME : constant := 32;
SM_CXSCREEN : constant := 0;
SM_CYCAPTION : constant := 4;
SM_CYDLGFRAME : constant := 8;
SM_CYEDGE : constant := 46;
SM_CYFRAME : constant := 33;
SM_CYMENU : constant := 15;
SM_CYSCREEN : constant := 1;
SND_ASYNC : constant := 16#00000001#;
SND_FILENAME : constant := 16#00020000#;
SND_NODEFAULT : constant := 16#00000002#;
SS_CENTER : constant := 16#00000001#;
SS_ETCHEDFRAME : constant := 16#00000012#;
SS_NOPREFIX : constant := 16#00000080#;
SS_RIGHT : constant := 16#00000002#;
SWP_NOMOVE : constant := 16#00000002#;
SWP_NOSIZE : constant := 16#00000001#;
SWP_NOZORDER : constant := 16#00000004#;
SW_HIDE : constant := 0;
SW_SHOW : constant := 5;
SW_SHOWNORMAL : constant := 1;
TRANSPARENT : constant := 1;
WM_ACTIVATE : constant := 6;
WM_CHAR : constant := 258;
WM_CLOSE : constant := 16;
WM_COMMAND : constant := 273;
WM_COPY : constant := 769;
WM_CREATE : constant := 1;
WM_CUT : constant := 768;
WM_DESTROY : constant := 2;
WM_ERASEBKGND : constant := 20;
WM_GETDLGCODE : constant := 135;
WM_GETTEXT : constant := 13;
WM_GETTEXTLENGTH : constant := 14;
WM_KEYDOWN : constant := 256;
WM_LBUTTONDOWN : constant := 513;
WM_LBUTTONUP : constant := 514;
WM_MOUSEMOVE : constant := 512;
WM_PAINT : constant := 15;
WM_PASTE : constant := 770;
WM_SETFONT : constant := 48;
WM_SETTEXT : constant := 12;
WM_SHOWWINDOW : constant := 24;
WM_SIZE : constant := 5;
WM_UNDO : constant := 772;
WS_BORDER : constant := 16#00800000#;
WS_CHILD : constant := 16#40000000#;
WS_DLGFRAME : constant := 16#00400000#;
WS_EX_APPWINDOW : constant := 16#00040000#;
WS_EX_CLIENTEDGE : constant := 16#00000200#;
WS_EX_CONTROLPARENT : constant := 16#00010000#;
WS_GROUP : constant := 16#00020000#;
WS_HSCROLL : constant := 16#00100000#;
WS_OVERLAPPEDWINDOW : constant := 16#00CF0000#;
WS_SYSMENU : constant := 16#00080000#;
WS_TABSTOP : constant := 16#00010000#;
WS_VISIBLE : constant := 16#10000000#;
WS_VSCROLL : constant := 16#00200000#;
----------------------------------------------------------------------------
-- Win32 data types
----------------------------------------------------------------------------
subtype Win32_ATOM is Interfaces.C.Unsigned_Short;
subtype Win32_BOOL is Interfaces.C.Int;
subtype Win32_BYTE is Interfaces.C.Unsigned_Char;
subtype Win32_CHAR is Interfaces.C.Char;
subtype Win32_DWORD is Interfaces.C.Unsigned_Long;
subtype Win32_WORD is Interfaces.C.Unsigned_Short;
subtype Win32_INT is Interfaces.C.Int;
subtype Win32_LONG is Interfaces.C.Long;
subtype Win32_SHORT is Interfaces.C.Short;
subtype Win32_UINT is Interfaces.C.Unsigned;
subtype Win32_WPARAM is Interfaces.C.Unsigned;
subtype Win32_LPARAM is Interfaces.C.Long;
subtype Win32_COLORREF is Interfaces.C.Unsigned_Long;
subtype Win32_SIZE is Interfaces.C.Size_T;
subtype Win32_String is Interfaces.C.Char_Array;
type Win32_LPCSTR is access constant Interfaces.C.Char;
type Win32_LPSTR is access all Interfaces.C.Char;
subtype Win32_LPVOID is System.Address;
subtype Win32_HANDLE is System.Address;
subtype Win32_HWND is System.Address;
subtype Win32_HBRUSH is System.Address;
subtype Win32_HBITMAP is System.Address;
subtype Win32_HDC is System.Address;
subtype Win32_HGDIOBJ is System.Address;
subtype Win32_HFONT is System.Address;
subtype Win32_HMENU is System.Address;
subtype Win32_HCURSOR is System.Address;
subtype Win32_HICON is System.Address;
subtype Win32_HPEN is System.Address;
subtype Win32_HINSTANCE is System.Address;
subtype Win32_HMODULE is System.Address;
type Win32_WNDPROC is
access function (hWnd : Win32_HWND;
Msg : Win32_UINT;
wParam : Win32_WPARAM;
lParam : Win32_LPARAM) return Win32_LONG;
pragma Convention (Stdcall, Win32_WNDPROC);
type Win32_HOOKPROC is
access function (hWnd : Win32_HWND;
Msg : Win32_UINT;
wParam : Win32_WPARAM;
lParam : Win32_LPARAM) return Win32_UINT;
pragma Convention (Stdcall, Win32_HOOKPROC);
type Win32_WNDENUMPROC is
access function (hWnd : Win32_HWND;
lParam : Win32_LPARAM) return Win32_BOOL;
pragma Convention (Stdcall, Win32_WNDENUMPROC);
type Win32_RECT is
record
Left : Win32_LONG;
Top : Win32_LONG;
Right : Win32_LONG;
Bottom : Win32_LONG;
end record;
type Win32_CREATESTRUCT is
record
lpCreateParams : Win32_HANDLE;
hInstance : Win32_HANDLE;
hMenu : Win32_HMENU;
hWndParent : Win32_HWND;
CY : Win32_INT;
CX : Win32_INT;
Y : Win32_INT;
X : Win32_INT;
Style : Win32_LONG;
lpszName : Win32_LPCSTR;
lpszClass : Win32_LPCSTR;
dwExStyle : Win32_DWORD;
end record;
type Win32_POINT is
record
X,Y : Win32_LONG;
end record;
type Win32_POINTS is
record
X,Y : Win32_SHORT;
end record;
type Win32_PAINTSTRUCT is
record
hDC : Win32_HDC;
fErase : Win32_BOOL;
rcPaint : Win32_RECT;
fRestore : Win32_BOOL;
fIncUpdate : Win32_BOOL;
Reserved : Win32_String (0..31);
end record;
type Win32_LOGBRUSH is
record
lbStyle : Win32_UINT;
lbColor : Win32_COLORREF;
lbHatch : Win32_LONG;
end record;
type Win32_LOGFONT is
record
lfHeight : Win32_LONG;
lfWidth : Win32_LONG := 0;
lfEscapement : Win32_LONG := 0;
lfOrientation : Win32_LONG := 0;
lfWeight : Win32_LONG;
lfItalic : Win32_BYTE;
lfUnderline : Win32_BYTE := 0;
lfStrikeOut : Win32_BYTE := 0;
lfCharSet : Win32_BYTE := 0;
lfOutPrecision : Win32_BYTE := 0;
lfClipPrecision : Win32_BYTE := 0;
lfQuality : Win32_BYTE := 0;
lfPitchAndFamily : Win32_BYTE := 0;
lfFaceName : Win32_String(0..31);
end record;
type Win32_MSG is
record
hWnd : Win32_HWND;
Message : Win32_UINT;
wParam : Win32_WPARAM;
lParam : Win32_LPARAM;
Time : Win32_DWORD;
Point : Win32_POINT;
end record;
type Win32_WNDCLASS is
record
Style : Win32_UINT;
lpfnWndProc : Win32_WNDPROC;
cbClsExtra : Win32_INT;
cbWndExtra : Win32_INT;
hInstance : Win32_HINSTANCE;
hIcon : Win32_HICON;
hCursor : Win32_HCURSOR;
hbrBackground : Win32_HBRUSH;
lpszMenuName : Win32_LPCSTR;
lpszClassName : Win32_LPCSTR;
end record;
type Win32_BITMAPFILEHEADER is
record
bfType : Win32_WORD;
bfSize : Win32_DWORD;
bfReserved1 : Win32_WORD;
bfReserved2 : Win32_WORD;
bfOffBits : Win32_DWORD;
end record;
type Win32_BITMAPINFOHEADER is
record
biSize : Win32_DWORD;
biWidth : Win32_LONG;
biHeight : Win32_LONG;
biPlanes : Win32_WORD;
biBitCount : Win32_WORD;
biCompression : Win32_DWORD;
biSizeImage : Win32_DWORD;
biXPelsPerMeter : Win32_LONG;
biYPelsPerMeter : Win32_LONG;
biClrUsed : Win32_DWORD;
biClrImportant : Win32_DWORD;
end record;
type Win32_BITMAP is
record
bmType : Win32_LONG;
bmWidth : Win32_LONG;
bmHeight : Win32_LONG;
bmWidthBytes : Win32_LONG;
bmPlanes : Win32_WORD;
bmBitsPixel : Win32_WORD;
bmBits : Win32_LPVOID;
end record;
type Win32_LPRECT is access all Win32_RECT;
type Win32_LPCREATESTRUCT is access all Win32_CREATESTRUCT;
type Win32_LPPOINT is access all Win32_POINT;
type Win32_LPLOGBRUSH is access all Win32_LOGBRUSH;
type Win32_LPMSG is access all Win32_MSG;
type Win32_LPCOLORREF is access all Win32_COLORREF;
type Win32_LPLOGFONT is access all Win32_LOGFONT;
type Win32_LPBITMAPINFOHEADER is access all Win32_BITMAPINFOHEADER;
type Win32_LPBITMAP is access all Win32_BITMAP;
type Win32_CHOOSEFONT is
record
lStructSize : Win32_DWORD;
hwndOwner : Win32_HWND := System.Null_Address;
hDC : Win32_HDC := System.Null_Address;
lpLogFont : Win32_LPLOGFONT;
iPointSize : Win32_INT := 0;
Flags : Win32_DWORD := CF_SCREENFONTS or
CF_FORCEFONTEXIST or
CF_INITTOLOGFONTSTRUCT;
rgbColors : Win32_COLORREF := 0;
lCustData : Win32_LPARAM := 0;
lpfnHook : Win32_HOOKPROC := null;
lpTemplateName : Win32_LPCSTR := null;
hInstance : Win32_HINSTANCE := System.Null_Address;
lpszStyle : Win32_LPSTR := null;
nFontType : Win32_WORD := 0;
MISSING_ALIGNMENT : Win32_WORD := 0;
nSizeMin : Win32_INT := 0;
nSizeMax : Win32_INT := 0;
end record;
type Win32_CHOOSECOLOR is
record
lStructSize : Win32_DWORD;
hwndOwner : Win32_HWND := System.Null_Address;
hInstance : Win32_HWND := System.Null_Address;
rgbResult : Win32_COLORREF := 0;
lpCustColors : Win32_LPCOLORREF;
Flags : Win32_DWORD := CC_RGBINIT;
lCustData : Win32_LPARAM := 0;
lpfnHook : Win32_HOOKPROC := null;
lpTemplateName : Win32_LPCSTR := null;
end record;
type Win32_OPENFILENAME is
record
lStructSize : Win32_DWORD;
hWndOwner : Win32_HWND := System.Null_Address;
hInstance : Win32_HINSTANCE := System.Null_Address;
lpstrFilter : Win32_LPCSTR := null;
lpstrCustomFilter : Win32_LPSTR := null;
nMaxCustFilter : Win32_DWORD := 0;
nFilterIndex : Win32_DWORD := 1;
lpstrFile : Win32_LPSTR;
nMaxFile : Win32_DWORD;
lpstrFileTitle : Win32_LPSTR := null;
nMaxFileTitle : Win32_DWORD := 0;
lpstrInitialDir : Win32_LPCSTR := null;
lpstrTitle : Win32_LPCSTR;
Flags : Win32_DWORD;
nFileOffset : Win32_WORD;
nFileExtension : Win32_WORD;
lpstrDefExt : Win32_LPCSTR;
lCustData : Win32_LPARAM := 0;
lpfnHook : Win32_HOOKPROC := null;
lpTemplateName : Win32_LPCSTR := null;
end record;
----------------------------------------------------------------------------
-- Dummy variables for unused results from Win32 functions.
----------------------------------------------------------------------------
Bool_Dummy : Win32_BOOL;
Long_Dummy : Win32_LONG;
----------------------------------------------------------------------------
-- The start of the range of Windows message numbers used for commands.
----------------------------------------------------------------------------
WM_USER : constant := 16#0400#;
----------------------------------------------------------------------------
-- Assorted type conversions
----------------------------------------------------------------------------
function To_Handle is new Ada.Unchecked_Conversion
(Integer,System.Address);
function To_LPCSTR is new Ada.Unchecked_Conversion
(Integer,Win32_LPCSTR);
function To_Integer is new Ada.Unchecked_Conversion
(System.Address,Integer);
function To_WPARAM is new Ada.Unchecked_Conversion
(System.Address,Win32_WPARAM);
function To_HDC is new Ada.Unchecked_Conversion
(Win32_WPARAM,Win32_HDC);
function To_LONG is new Ada.Unchecked_Conversion
(System.Address,Win32_LONG);
function To_LONG is new Ada.Unchecked_Conversion
(Win32_WNDPROC, Win32_LONG);
function To_CREATESTRUCT is new Ada.Unchecked_Conversion
(Win32_LPARAM,
Win32_LPCREATESTRUCT);
function To_BMIH is new Ada.Unchecked_Conversion
(System.Address,
Win32_LPBITMAPINFOHEADER);
function To_LPSTR (S : Win32_String) return Win32_LPSTR;
function To_LPCSTR (S : Win32_String) return Win32_LPCSTR;
function To_LPARAM (S : Win32_String) return Win32_LPARAM;
function To_String (S : Win32_String) return String;
function To_Array (S : String) return Win32_String;
----------------------------------------------------------------------------
-- Other utility functions
----------------------------------------------------------------------------
function Message_Box (Message : String;
Title : String;
Flags : Win32_UINT) return Integer;
function Create_Font (Font : Font_Type) return Win32_HFONT;
function Set_Font (Font : Font_Type) return Win32_LOGFONT;
function Get_Font (Font : Win32_LOGFONT) return Font_Type;
function MakePoint (Value : Win32_LPARAM) return Win32_POINTS;
function RGB (Colour : Colour_Type) return Win32_COLORREF;
----------------------------------------------------------------------------
-- Imports from Win32 and RTS libraries
----------------------------------------------------------------------------
function AppendMenu (hMenu : Win32_HMENU;
uFlags : Win32_UINT;
uIDNewItem : Win32_UINT;
lpNewItem : Win32_LPCSTR)
return Win32_BOOL;
function BeginPaint (hWnd : Win32_HWND;
lpPaint : access Win32_PAINTSTRUCT)
return Win32_HDC;
function CallWindowProc (lpPrevWndFunc : Win32_LONG;
hWnd : Win32_HWND;
Msg : Win32_UINT;
wParam : Win32_WPARAM;
lParam : Win32_LPARAM)
return Win32_LONG;
function CheckMenuItem (hMenu : Win32_HMENU;
uIDCheckItem : Win32_UINT;
uCheck : Win32_UINT)
return Win32_DWORD;
function ChooseColor (lpcc : access Win32_CHOOSECOLOR)
return Win32_BOOL;
function ChooseFont (lpcf : access Win32_CHOOSEFONT)
return Win32_BOOL;
function CreateBrushIndirect (lplb : Win32_LPLOGBRUSH)
return Win32_HBRUSH;
function CreateCompatibleDC (hdc : Win32_HDC)
return Win32_HDC;
function CreateDC (lpszDriver : Win32_LPCSTR;
lpszDevice : Win32_LPCSTR;
lpszOutput : Win32_LPCSTR;
lpInitData : Win32_LPVOID)
return Win32_HDC;
function CreateDIBitmap (hdc : Win32_HDC;
lpbmih : Win32_LPBITMAPINFOHEADER;
dwInit : Win32_DWORD;
lpvBits : Win32_LPVOID;
lpbmi : Win32_LPVOID;
fnColorUse : Win32_UINT)
return Win32_HBITMAP;
function CreateDIBitmap (lplb : Win32_LPLOGBRUSH)
return Win32_HBRUSH;
function CreateFontIndirect (lplf : access Win32_LOGFONT)
return Win32_HFONT;
function CreateMenu return Win32_HMENU;
function CreatePen (fnPenStyle : Win32_INT;
nWidth : Win32_INT;
clrref : Win32_COLORREF)
return Win32_HPEN;
function CreateSolidBrush (clrref : Win32_COLORREF)
return Win32_HBRUSH;
function CreateWindowEx (dwExStyle : Win32_DWORD;
lpClassName : Win32_LPCSTR;
lpWindowName : Win32_LPCSTR;
dwStyle : Win32_DWORD;
X : Win32_INT;
Y : Win32_INT;
nWidth : Win32_INT;
nHeight : Win32_INT;
hWndParent : Win32_HWND;
hMenu : Win32_HMENU;
hInstance : Win32_HINSTANCE;
lpParam : Win32_LPVOID)
return Win32_HWND;
function DefWindowProc (hWnd : Win32_HWND;
Msg : Win32_UINT;
wParam : Win32_WPARAM;
lParam : Win32_LPARAM)
return Win32_LONG;
function DeleteDC (hdc : Win32_HDC)
return Win32_BOOL;
function DeleteObject (hgdiobj : Win32_HGDIOBJ)
return Win32_BOOL;
function DestroyWindow (hWnd : Win32_HWND)
return Win32_BOOL;
function DispatchMessage (lpMsg : Win32_LPMSG)
return Win32_LONG;
function DPTOLP (hdc : Win32_HDC;
lpPoints : access Win32_POINT;
nCount : Win32_INT)
return Win32_BOOL;
function DrawMenuBar (hWnd : Win32_HWND)
return Win32_BOOL;
function DrawText (hDC : Win32_HDC;
lpString : Win32_LPCSTR;
nCount : Win32_INT;
lpRect : Win32_LPRECT;
uFormat : Win32_UINT)
return Win32_INT;
function Ellipse (hdc : Win32_HDC;
nLeftRect : Win32_INT;
nTopRect : Win32_INT;
nRightRect : Win32_INT;
nBottomRect : Win32_INT)
return Win32_BOOL;
function EnableMenuItem (hMenu : Win32_HMENU;
uIDEnableItem : Win32_UINT;
uEnable : Win32_UINT)
return Win32_BOOL;
function EnableWindow (hWnd : Win32_HWND;
bEnable : Win32_BOOL)
return Win32_BOOL;
function EndPaint (hWnd : Win32_HWND;
lpPaint : access Win32_PAINTSTRUCT)
return Win32_BOOL;
function EnumChildWindows (hWndParent : Win32_HWND;
lpEnumFunc : Win32_WNDENUMPROC;
lParam : Win32_LPARAM)
return Win32_BOOL;
function EnumThreadWindows (dwThreadId : Win32_DWORD;
lpfn : Win32_WNDENUMPROC;
lParam : Win32_LPARAM)
return Win32_BOOL;
function FillRect (hDC : Win32_HDC;
lprc : Win32_LPRECT;
hbr : Win32_HBRUSH)
return Win32_INT;
function Get_hInstance return Win32_HINSTANCE;
function Get_hPrevInstance return Win32_HINSTANCE;
function GetActiveWindow return Win32_HWND;
function GetClientRect (hWnd : Win32_HWND;
lpRect : Win32_LPRECT)
return Win32_BOOL;
function GetCurrentThreadId return Win32_DWORD;
function GetDC (hWnd : Win32_HWND)
return Win32_HDC;
function GetDeviceCaps (hdc : Win32_HDC;
iCapability : Win32_INT)
return Win32_INT;
function GetFocus return Win32_HWND;
function GetMapMode (hdc : Win32_HDC)
return Win32_INT;
function GetMenu (hWnd : Win32_HWND)
return Win32_HMENU;
function GetMenuState (hMenu : Win32_HMENU;
uId : Win32_UINT;
uFlags : Win32_UINT)
return Win32_UINT;
function GetMenuString (hMenu : Win32_HMENU;
uIDItem : Win32_UINT;
lpString : Win32_LPSTR;
nMaxCount : Win32_INT;
uFlag : Win32_UINT)
return Win32_INT;
function GetObject (hgdiobj : Win32_HGDIOBJ;
cbBuffer : Win32_INT;
lpvObject : Win32_LPVOID)
return Win32_INT;
function GetOpenFileName (lpofn : access Win32_OPENFILENAME)
return Win32_BOOL;
function GetParent (hWnd : Win32_HWND)
return Win32_HWND;
function GetSaveFileName (lpofn : access Win32_OPENFILENAME)
return Win32_BOOL;
function GetStockObject (fnObject : Win32_INT)
return Win32_HGDIOBJ;
function GetSystemMetrics (nIndex : Win32_INT)
return Win32_INT;
function GetWindow (hWnd : Win32_HWND;
uCmd : Win32_UINT)
return Win32_HWND;
function GetWindowLong (hWnd : Win32_HWND;
nIndex : Win32_INT)
return Win32_LONG;
function GetWindowRect (hWnd : Win32_HWND;
lpRect : Win32_LPRECT)
return Win32_BOOL;
function InvalidateRect (hWnd : Win32_HWND;
lpRect : Win32_LPRECT;
bErase : Win32_BOOL)
return Win32_BOOL;
function IsDialogMessage (hDlg : Win32_HWND;
lpMsg : access Win32_MSG)
return Win32_BOOL;
function IsWindow (hWnd : Win32_HWND)
return Win32_BOOL;
function IsWindowEnabled (hWnd : Win32_HWND)
return Win32_BOOL;
function IsWindowVisible (hWnd : Win32_HWND)
return Win32_BOOL;
function LineTo (hdc : Win32_HDC;
xEnd : Win32_INT;
yEnd : Win32_INT)
return Win32_BOOL;
function LoadCursor (hInstance : Win32_HINSTANCE;
lpCursorName : Win32_LPCSTR)
return Win32_HCURSOR;
function LoadIcon (hInstance : Win32_HINSTANCE;
lpIconName : Win32_LPCSTR)
return Win32_HICON;
function MessageBox (hWnd : Win32_HWND;
lpText : Win32_LPCSTR;
lpCaption : Win32_LPCSTR;
uType : Win32_UINT)
return Win32_INT;
function ModifyMenu (hMnu : Win32_HMENU;
uPosition : Win32_UINT;
uFlags : Win32_UINT;
uIDNewItem : Win32_UINT;
lpNewItem : Win32_LPCSTR)
return Win32_BOOL;
function MoveToEx (hdc : Win32_HDC;
X : Win32_INT;
Y : Win32_INT;
lpPoint : Win32_LPPOINT)
return Win32_BOOL;
function PeekMessage (lpMsg : access Win32_MSG;
hWnd : Win32_HWND;
wMsgFilterMin : Win32_UINT;
wMsgFilterMax : Win32_UINT;
wRemoveMsg : Win32_UINT)
return Win32_BOOL;
function PlaySound (pszSound : Win32_LPCSTR;
hmod : Win32_HMODULE;
fdwSound : Win32_DWORD)
return Win32_BOOL;
function Polygon (hdc : Win32_HDC;
lpPoints : Win32_LPPOINT;
nCount : Win32_INT)
return Win32_BOOL;
function Polyline (hdc : Win32_HDC;
lppt : Win32_LPPOINT;
cPoints : Win32_INT)
return Win32_BOOL;
function Rectangle (hdc : Win32_HDC;
nLeftRect : Win32_INT;
nTopRect : Win32_INT;
nRightRect : Win32_INT;
nBottomRect : Win32_INT)
return Win32_BOOL;
function RegisterClass (lpWndClass : access Win32_WNDCLASS)
return Win32_ATOM;
function ReleaseCapture return Win32_BOOL;
function ReleaseDC (hWnd : Win32_HWND;
hDC : Win32_HDC)
return Win32_INT;
function RoundRect (hdc : Win32_HDC;
nLeftRect : Win32_INT;
nTopRect : Win32_INT;
nRightRect : Win32_INT;
nBottomRect : Win32_INT;
nEllipseWidth : Win32_INT;
nEllipseHeight : Win32_INT)
return Win32_BOOL;
function SelectObject (hdc : Win32_HDC;
hgdiobj : Win32_HGDIOBJ)
return Win32_HGDIOBJ;
function SendMessage (hWnd : Win32_HWND;
Msg : Win32_UINT;
wParam : Win32_WPARAM;
lParam : Win32_LPARAM)
return Win32_LONG;
function SetActiveWindow (hWnd : Win32_HWND)
return Win32_HWND;
function SetBkMode (hdc : Win32_HDC;
fnBkMode : Win32_INT)
return Win32_INT;
function SetCapture (hWnd : Win32_HWND)
return Win32_HWND;
function SetFocus (hWnd : Win32_HWND)
return Win32_HWND;
function SetForegroundWindow (hWnd : Win32_HWND)
return Win32_BOOL;
function SetMapMode (hdc : Win32_HDC;
fnmapMode : Win32_INT)
return Win32_INT;
function SetMenu (hWnd : Win32_HWND;
hMenu : Win32_HMENU)
return Win32_BOOL;
function SetWindowLong (hWnd : Win32_HWND;
nIndex : Win32_INT;
dwNewLong : Win32_LONG)
return Win32_LONG;
function SetWindowPos (hWnd : Win32_HWND;
hWndInsertAfter : Win32_HWND;
X : Win32_INT;
Y : Win32_INT;
cx : Win32_INT;
cy : Win32_INT;
uFlags : Win32_UINT)
return Win32_BOOL;
function ShowWindow (hWnd : Win32_HWND;
nCmdShow : Win32_INT)
return Win32_BOOL;
function StretchBlt (hdcDest : Win32_HDC;
nXOriginDest : Win32_INT;
nYOriginDest : Win32_INT;
nWidthDest : Win32_INT;
nHeightDest : Win32_INT;
hdcSrc : Win32_HDC;
nXOriginSrc : Win32_INT;
nYOriginSrc : Win32_INT;
nWidthSrc : Win32_INT;
nHeightSrc : Win32_INT;
dwRop : Win32_DWORD := 16#CC0020#)
return Win32_BOOL;
function TranslateMessage (lpMsg : Win32_LPMSG)
return Win32_BOOL;
function UpdateWindow (hWnd : Win32_HWND)
return Win32_BOOL;
private -- mappings to external libraries
pragma Import (Stdcall, AppendMenu, "AppendMenuA");
pragma Import (Stdcall, BeginPaint, "BeginPaint");
pragma Import (Stdcall, CallWindowProc, "CallWindowProcA");
pragma Import (Stdcall, CheckMenuItem, "CheckMenuItem");
pragma Import (Stdcall, ChooseColor, "ChooseColorA");
pragma Import (Stdcall, ChooseFont, "ChooseFontA");
pragma Import (Stdcall, CreateBrushIndirect, "CreateBrushIndirect");
pragma Import (Stdcall, CreateCompatibleDC, "CreateCompatibleDC");
pragma Import (Stdcall, CreateDC, "CreateDCA");
pragma Import (Stdcall, CreateDIBitmap, "CreateDIBitmap");
pragma Import (Stdcall, CreateFontIndirect, "CreateFontIndirectA");
pragma Import (Stdcall, CreateMenu, "CreateMenu");
pragma Import (Stdcall, CreatePen, "CreatePen");
pragma Import (Stdcall, CreateSolidBrush, "CreateSolidBrush");
pragma Import (Stdcall, CreateWindowEx, "CreateWindowExA");
pragma Import (Stdcall, DefWindowProc, "DefWindowProcA");
pragma Import (Stdcall, DeleteDC, "DeleteDC");
pragma Import (Stdcall, DeleteObject, "DeleteObject");
pragma Import (Stdcall, DestroyWindow, "DestroyWindow");
pragma Import (Stdcall, DispatchMessage, "DispatchMessageA");
pragma Import (Stdcall, DPtoLP, "DPtoLP");
pragma Import (Stdcall, DrawMenuBar, "DrawMenuBar");
pragma Import (Stdcall, DrawText, "DrawTextA");
pragma Import (Stdcall, Ellipse, "Ellipse");
pragma Import (Stdcall, EnableMenuItem, "EnableMenuItem");
pragma Import (Stdcall, EnableWindow, "EnableWindow");
pragma Import (Stdcall, EndPaint, "EndPaint");
pragma Import (Stdcall, EnumChildWindows, "EnumChildWindows");
pragma Import (Stdcall, EnumThreadWindows, "EnumThreadWindows");
pragma Import (Stdcall, FillRect, "FillRect");
pragma Import (C , Get_hInstance , "rts_get_hInstance");
pragma Import (C , Get_hPrevInstance , "rts_get_hPrevInstance");
pragma Import (Stdcall, GetActiveWindow, "GetActiveWindow");
pragma Import (Stdcall, GetClientRect, "GetClientRect");
pragma Import (Stdcall, GetCurrentThreadId, "GetCurrentThreadId");
pragma Import (Stdcall, GetDC, "GetDC");
pragma Import (Stdcall, GetDeviceCaps, "GetDeviceCaps");
pragma Import (Stdcall, GetFocus, "GetFocus");
pragma Import (Stdcall, GetMapMode, "GetMapMode");
pragma Import (Stdcall, GetMenu, "GetMenu");
pragma Import (Stdcall, GetMenuState, "GetMenuState");
pragma Import (Stdcall, GetMenuString, "GetMenuStringA");
pragma Import (Stdcall, GetObject, "GetObjectA");
pragma Import (Stdcall, GetOpenFileName, "GetOpenFileNameA");
pragma Import (Stdcall, GetParent, "GetParent");
pragma Import (Stdcall, GetSaveFileName, "GetSaveFileNameA");
pragma Import (Stdcall, GetStockObject, "GetStockObject");
pragma Import (Stdcall, GetSystemMetrics, "GetSystemMetrics");
pragma Import (Stdcall, GetWindow, "GetWindow");
pragma Import (Stdcall, GetWindowLong, "GetWindowLongA");
pragma Import (Stdcall, GetWindowRect, "GetWindowRect");
pragma Import (Stdcall, InvalidateRect, "InvalidateRect");
pragma Import (Stdcall, IsDialogMessage, "IsDialogMessage");
pragma Import (Stdcall, IsWindow, "IsWindow");
pragma Import (Stdcall, IsWindowEnabled, "IsWindowEnabled");
pragma Import (Stdcall, IsWindowVisible, "IsWindowVisible");
pragma Import (Stdcall, LineTo, "LineTo");
pragma Import (Stdcall, LoadCursor, "LoadCursorA");
pragma Import (Stdcall, LoadIcon, "LoadIconA");
pragma Import (Stdcall, MessageBox, "MessageBoxA");
pragma Import (Stdcall, ModifyMenu, "ModifyMenuA");
pragma Import (Stdcall, MoveToEx, "MoveToEx");
pragma Import (Stdcall, PeekMessage, "PeekMessageA");
pragma Import (Stdcall, PlaySound, "PlaySoundA");
pragma Import (Stdcall, Polygon, "Polygon");
pragma Import (Stdcall, Polyline, "Polyline");
pragma Import (Stdcall, Rectangle, "Rectangle");
pragma Import (Stdcall, RegisterClass, "RegisterClassA");
pragma Import (Stdcall, ReleaseCapture, "ReleaseCapture");
pragma Import (Stdcall, ReleaseDC, "ReleaseDC");
pragma Import (Stdcall, RoundRect, "RoundRect");
pragma Import (Stdcall, SelectObject, "SelectObject");
pragma Import (Stdcall, SendMessage, "SendMessageA");
pragma Import (Stdcall, SetActiveWindow, "SetActiveWindow");
pragma Import (Stdcall, SetBkMode, "SetBkMode");
pragma Import (Stdcall, SetCapture, "SetCapture");
pragma Import (Stdcall, SetFocus, "SetFocus");
pragma Import (Stdcall, SetForegroundWindow, "SetForegroundWindow");
pragma Import (Stdcall, SetMapMode, "SetMapMode");
pragma Import (Stdcall, SetMenu, "SetMenu");
pragma Import (Stdcall, SetWindowLong, "SetWindowLongA");
pragma Import (Stdcall, SetWindowPos, "SetWindowPos");
pragma Import (Stdcall, ShowWindow, "ShowWindow");
pragma Import (Stdcall, StretchBlt, "StretchBlt");
pragma Import (Stdcall, TranslateMessage, "TranslateMessage");
pragma Import (Stdcall, UpdateWindow, "UpdateWindow");
end JEWL.Win32_Interface;
|
with System.Once;
package body Ada.Strings.Canonical_Composites is
type Long_Boolean is new Boolean;
for Long_Boolean'Size use Long_Integer'Size;
function expect (exp, c : Long_Boolean) return Long_Boolean
with Import,
Convention => Intrinsic, External_Name => "__builtin_expect";
procedure unreachable
with Import,
Convention => Intrinsic, External_Name => "__builtin_unreachable";
pragma No_Return (unreachable);
-- decomposition
procedure D_Fill (Map : out D_Map_Array);
procedure D_Fill (Map : out D_Map_Array) is
procedure Fill (
Map : in out D_Map_Array;
I : in out Positive;
Table : UCD.Map_16x1_Type);
procedure Fill (
Map : in out D_Map_Array;
I : in out Positive;
Table : UCD.Map_16x1_Type) is
begin
for J in Table'Range loop
declare
F : UCD.Map_16x1_Item_Type renames Table (J);
begin
Map (I).From := Wide_Wide_Character'Val (F.Code);
Map (I).To (1) := Wide_Wide_Character'Val (F.Mapping);
for K in 2 .. Expanding loop
Map (I).To (K) := Wide_Wide_Character'Val (0);
end loop;
I := I + 1;
end;
end loop;
end Fill;
procedure Fill (
Map : in out D_Map_Array;
I : in out Positive;
Table : UCD.Map_16x2_Type);
procedure Fill (
Map : in out D_Map_Array;
I : in out Positive;
Table : UCD.Map_16x2_Type) is
begin
for J in Table'Range loop
declare
F : UCD.Map_16x2_Item_Type renames Table (J);
begin
Map (I).From := Wide_Wide_Character'Val (F.Code);
for K in 1 .. 2 loop
Map (I).To (K) := Wide_Wide_Character'Val (F.Mapping (K));
end loop;
for K in 3 .. Expanding loop
Map (I).To (K) := Wide_Wide_Character'Val (0);
end loop;
I := I + 1;
end;
end loop;
end Fill;
procedure Fill (
Map : in out D_Map_Array;
I : in out Positive;
Table : UCD.Map_32x2_Type);
procedure Fill (
Map : in out D_Map_Array;
I : in out Positive;
Table : UCD.Map_32x2_Type) is
begin
for J in Table'Range loop
declare
F : UCD.Map_32x2_Item_Type renames Table (J);
begin
Map (I).From := Wide_Wide_Character'Val (F.Code);
for K in 1 .. 2 loop
Map (I).To (K) := Wide_Wide_Character'Val (F.Mapping (K));
end loop;
for K in 3 .. Expanding loop
Map (I).To (K) := Wide_Wide_Character'Val (0);
end loop;
I := I + 1;
end;
end loop;
end Fill;
begin
-- make table
declare
I : Positive := Map'First;
begin
-- 16#00C0# ..
Fill (Map, I, UCD.Normalization.NFD_D_Table_XXXX);
-- 16#0340#
Fill (Map, I, UCD.Normalization.NFD_S_Table_XXXX);
-- 16#0344# ..
Fill (Map, I, UCD.Normalization.NFD_E_Table_XXXX);
-- 16#1109A# ..
Fill (Map, I, UCD.Normalization.NFD_D_Table_XXXXXXXX);
-- 16#1D15E#
Fill (Map, I, UCD.Normalization.NFD_E_Table_XXXXXXXX);
pragma Assert (I = Map'Last + 1);
end;
-- sort
for I in Map'First + 1 .. Map'Last loop
for J in reverse Map'First .. I - 1 loop
exit when Map (J).From <= Map (J + 1).From;
declare
T : constant D_Map_Element := Map (J);
begin
Map (J) := Map (J + 1);
Map (J + 1) := T;
end;
end loop;
end loop;
end D_Fill;
D_Flag : aliased System.Once.Flag := 0;
procedure D_Init;
procedure D_Init is
begin
D_Map := new D_Map_Array;
D_Fill (D_Map.all);
-- expanding re-decomposable
loop
declare
Expanded : Boolean := False;
begin
for I in D_Map'Range loop
declare
To : Decomposed_Wide_Wide_String
renames D_Map (I).To;
To_Last : Natural := Decomposed_Length (To);
J : Natural := To_Last;
begin
while J >= To'First loop
declare
D : constant Natural := D_Find (To (J));
begin
if D > 0 then
Expanded := True;
declare
R_Length : constant Natural :=
Decomposed_Length (D_Map (D).To);
begin
To (J + R_Length .. To_Last + R_Length - 1) :=
To (J + 1 .. To_Last);
To (J .. J + R_Length - 1) :=
D_Map (D).To (1 .. R_Length);
To_Last := To_Last + R_Length - 1;
pragma Assert (To_Last <= Expanding);
J := J + R_Length - 1;
end;
else
J := J - 1;
end if;
end;
end loop;
end;
end loop;
exit when not Expanded;
end;
end loop;
end D_Init;
Unexpanded_D_Flag : aliased System.Once.Flag := 0;
procedure Unexpanded_D_Init;
procedure Unexpanded_D_Init is
begin
Unexpanded_D_Map := new D_Map_Array;
D_Fill (Unexpanded_D_Map.all);
end Unexpanded_D_Init;
-- implementation of decomposition
function Decomposed_Length (Item : Decomposed_Wide_Wide_String)
return Natural is
begin
for I in reverse Item'Range loop
if Item (I) /= Wide_Wide_Character'Val (0) then
return I;
end if;
end loop;
pragma Assert (Boolean'(raise Program_Error));
unreachable;
end Decomposed_Length;
function D_Find (Item : Wide_Wide_Character) return Natural is
L : Positive := D_Map'First;
H : Natural := D_Map'Last;
begin
loop
declare
type Unsigned is mod 2 ** Integer'Size;
M : constant Positive := Integer (Unsigned (L + H) / 2);
M_Item : D_Map_Element
renames D_Map (M);
begin
if Item < M_Item.From then
H := M - 1;
elsif expect (Long_Boolean (Item > M_Item.From), True) then
L := M + 1;
else
return M;
end if;
end;
exit when L > H;
end loop;
return 0;
end D_Find;
procedure Initialize_D is
begin
System.Once.Initialize (D_Flag'Access, D_Init'Access);
end Initialize_D;
procedure Initialize_Unexpanded_D is
begin
System.Once.Initialize (
Unexpanded_D_Flag'Access,
Unexpanded_D_Init'Access);
end Initialize_Unexpanded_D;
-- composition
C_Flag : aliased System.Once.Flag := 0;
procedure C_Init;
procedure C_Init is
procedure Fill (
Map : in out C_Map_Array;
I : in out Positive;
Table : UCD.Map_16x2_Type);
procedure Fill (
Map : in out C_Map_Array;
I : in out Positive;
Table : UCD.Map_16x2_Type) is
begin
for J in Table'Range loop
declare
F : UCD.Map_16x2_Item_Type renames Table (J);
begin
for K in 1 .. 2 loop
Map (I).From (K) := Wide_Wide_Character'Val (F.Mapping (K));
end loop;
Map (I).To := Wide_Wide_Character'Val (F.Code);
I := I + 1;
end;
end loop;
end Fill;
procedure Fill (
Map : in out C_Map_Array;
I : in out Positive;
Table : UCD.Map_32x2_Type);
procedure Fill (
Map : in out C_Map_Array;
I : in out Positive;
Table : UCD.Map_32x2_Type) is
begin
for J in Table'Range loop
declare
F : UCD.Map_32x2_Item_Type renames Table (J);
begin
for K in 1 .. 2 loop
Map (I).From (K) := Wide_Wide_Character'Val (F.Mapping (K));
end loop;
Map (I).To := Wide_Wide_Character'Val (F.Code);
I := I + 1;
end;
end loop;
end Fill;
begin
-- initialize D table, too
Initialize_D;
-- make table
C_Map := new C_Map_Array;
declare
I : Positive := C_Map'First;
begin
-- (16#0041#, 16#0300#) ..
Fill (C_Map.all, I, UCD.Normalization.NFD_D_Table_XXXX);
-- (16#11099#, 16#110BA#) ..
Fill (C_Map.all, I, UCD.Normalization.NFD_D_Table_XXXXXXXX);
pragma Assert (I = C_Map'Last + 1);
end;
-- sort
for I in C_Map'First + 1 .. C_Map'Last loop
for J in reverse C_Map'First .. I - 1 loop
exit when C_Map (J).From <= C_Map (J + 1).From;
declare
T : constant C_Map_Element := C_Map (J);
begin
C_Map (J) := C_Map (J + 1);
C_Map (J + 1) := T;
end;
end loop;
end loop;
end C_Init;
-- implementation of composition
function C_Find (Item : Composing_Wide_Wide_String) return Natural is
L : Positive := C_Map'First;
H : Natural := C_Map'Last;
begin
loop
declare
type Unsigned is mod 2 ** Integer'Size;
M : constant Positive := Integer (Unsigned (L + H) / 2);
M_Item : C_Map_Element
renames C_Map (M);
begin
if Item < M_Item.From then
H := M - 1;
elsif expect (Long_Boolean (Item > M_Item.From), True) then
L := M + 1;
else
return M;
end if;
end;
exit when L > H;
end loop;
return 0;
end C_Find;
procedure Initialize_C is
begin
System.Once.Initialize (C_Flag'Access, C_Init'Access);
end Initialize_C;
end Ada.Strings.Canonical_Composites;
|
-----------------------------------------------------------------------
-- Appenders -- Log appenders
-- Copyright (C) 2001, 2002, 2003, 2006, 2008, 2009, 2010, 2011 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.Text_IO;
with Ada.Strings.Unbounded;
with Ada.Calendar;
with Ada.Finalization;
with Util.Properties;
limited with Util.Log.Loggers;
-- The log <b>Appender</b> will handle the low level operations to write
-- the log content to a file, the console, a database.
package Util.Log.Appenders is
use Ada.Strings.Unbounded;
-- ------------------------------
-- Log event
-- ------------------------------
-- The <b>Log_Event</b> represent a log message reported by one of the
-- <b>log</b> operation (Debug, Info, Warn, Error).
type Log_Event is record
-- The log message (formatted)
Message : Unbounded_String;
-- The timestamp when the message was produced.
Time : Ada.Calendar.Time;
-- The log level
Level : Level_Type;
-- The logger
Logger : access Util.Log.Loggers.Logger_Info;
end record;
-- The layout type to indicate how to format the message.
-- Unlike Logj4, there is no customizable layout.
type Layout_Type
is (
-- The <b>message</b> layout with only the log message.
-- Ex: "Cannot open file"
MESSAGE,
-- The <b>level-message</b> layout with level and message.
-- Ex: "ERROR: Cannot open file"
LEVEL_MESSAGE,
-- The <b>date-level-message</b> layout with date
-- Ex: "2011-03-04 12:13:34 ERROR: Cannot open file"
DATE_LEVEL_MESSAGE,
-- The <b>full</b> layout with everything (the default).
-- Ex: "2011-03-04 12:13:34 ERROR - my.application - Cannot open file"
FULL);
-- ------------------------------
-- Log appender
-- ------------------------------
type Appender is abstract new Ada.Finalization.Limited_Controlled with private;
type Appender_Access is access all Appender'Class;
-- Get the log level that triggers display of the log events
function Get_Level (Self : in Appender) return Level_Type;
-- Set the log level.
procedure Set_Level (Self : in out Appender;
Name : in String;
Properties : in Util.Properties.Manager;
Level : in Level_Type);
-- Set the log layout format.
procedure Set_Layout (Self : in out Appender;
Name : in String;
Properties : in Util.Properties.Manager;
Layout : in Layout_Type);
-- Format the event into a string
function Format (Self : in Appender;
Event : in Log_Event) return String;
-- Append a log event to the appender. Depending on the log level
-- defined on the appender, the event can be taken into account or
-- ignored.
procedure Append (Self : in out Appender;
Event : in Log_Event) is abstract;
-- Flush the log events.
procedure Flush (Self : in out Appender) is abstract;
-- ------------------------------
-- File appender
-- ------------------------------
-- Write log events to a file
type File_Appender is new Appender with private;
type File_Appender_Access is access all File_Appender'Class;
overriding
procedure Append (Self : in out File_Appender;
Event : in Log_Event);
-- Set the file where the appender will write the logs
procedure Set_File (Self : in out File_Appender;
Path : in String);
-- Flush the log events.
overriding
procedure Flush (Self : in out File_Appender);
-- Flush and close the file.
overriding
procedure Finalize (Self : in out File_Appender);
-- Create a file appender and configure it according to the properties
function Create_File_Appender (Name : in String;
Properties : in Util.Properties.Manager;
Default : in Level_Type)
return Appender_Access;
-- ------------------------------
-- Console appender
-- ------------------------------
-- Write log events to the console
type Console_Appender is new Appender with private;
type Console_Appender_Access is access all Console_Appender'Class;
overriding
procedure Append (Self : in out Console_Appender;
Event : in Log_Event);
-- Flush the log events.
overriding
procedure Flush (Self : in out Console_Appender);
-- Create a console appender and configure it according to the properties
function Create_Console_Appender (Name : in String;
Properties : in Util.Properties.Manager;
Default : in Level_Type)
return Appender_Access;
-- ------------------------------
-- List appender
-- ------------------------------
-- Write log events to a list of appenders
type List_Appender is new Appender with private;
type List_Appender_Access is access all List_Appender'Class;
-- Max number of appenders that can be added to the list.
-- In most cases, 2 or 3 appenders will be used.
MAX_APPENDERS : constant Natural := 10;
overriding
procedure Append (Self : in out List_Appender;
Event : in Log_Event);
-- Flush the log events.
overriding
procedure Flush (Self : in out List_Appender);
-- Add the appender to the list.
procedure Add_Appender (Self : in out List_Appender;
Object : in Appender_Access);
-- Create a list appender and configure it according to the properties
function Create_List_Appender return List_Appender_Access;
private
type Appender is abstract new Ada.Finalization.Limited_Controlled with record
Level : Level_Type := INFO_LEVEL;
Layout : Layout_Type := FULL;
end record;
type File_Appender is new Appender with record
Output : Ada.Text_IO.File_Type;
end record;
type Appender_Array_Access is array (1 .. MAX_APPENDERS) of Appender_Access;
type List_Appender is new Appender with record
Appenders : Appender_Array_Access;
Count : Natural := 0;
end record;
type Console_Appender is new Appender with null record;
end Util.Log.Appenders;
|
-- PR ada/28591
-- Reported by Martin Michlmayr <tbm@cyrius.com>
-- { dg-do compile }
-- { dg-options "-g" }
with Interfaces; use Interfaces;
package Unchecked_Union is
type Mode_Type is (Mode_B2);
type Value_Union (Mode : Mode_Type := Mode_B2) is record
case Mode is
when Mode_B2 =>
B2 : Integer_32;
end case;
end record;
pragma Unchecked_Union (Value_Union);
end Unchecked_Union;
|
-------------------------------------------------------------------------------
-- Copyright (c) 2016 Daniel King
--
-- 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 DW1000.Types; use DW1000.Types;
package body DW1000.Ranging.Double_Sided
with SPARK_Mode => On
is
------------------------
-- Compute_Distance --
------------------------
function Compute_Distance
(Tag_Tx_Poll_Timestamp : in Fine_System_Time;
Anchor_Rx_Poll_Timestamp : in Fine_System_Time;
Anchor_Tx_Resp_Timestamp : in Fine_System_Time;
Tag_Rx_Resp_Timestamp : in Fine_System_Time;
Tag_Tx_Final_Timestamp : in Fine_System_Time;
Anchor_Rx_Final_Timestamp : in Fine_System_Time) return Biased_Distance is
Max_Time_Of_Flight : constant := 0.000_1;
-- Limit the Time of Flight to a maximum of 0.000_1 seconds (100 us).
--
-- This prevents overflow during the conversion from time of flight
-- to distance.
--
-- This limits the maximum computable distance to 2990 meters, but this
-- should be plenty as the operational range of the DW1000 is about
-- 10 times below this limit (300 m).
type System_Time_Span_Div2 is
delta System_Time_Span'Delta / 2.0
range 0.0 .. System_Time_Span'Last -- need the same range as System_Time_Span
with Small => System_Time_Span'Small / 2.0;
type System_Time_Span_Div4 is
delta System_Time_Span'Delta / 4.0
range 0.0 .. System_Time_Span'Last / 2.0
with Small => System_Time_Span'Small / 4.0;
type Large_Meters is
delta Meters'Delta
range 0.0 .. (Max_Time_Of_Flight / System_Time_Span_Div4'Delta) * Speed_Of_Light_In_Vacuum;
-- A fixed-point type with a large enough integer part to store the
-- integer representation of a System_Time_Span_Div4 value.
T_Roundtrip1 : constant System_Time_Span := Calculate_Span
(Start_Time => Tag_Tx_Poll_Timestamp,
End_Time => Tag_Rx_Resp_Timestamp);
T_Reply1 : constant System_Time_Span := Calculate_Span
(Start_Time => Anchor_Rx_Poll_Timestamp,
End_Time => Anchor_Tx_Resp_Timestamp);
T_Roundtrip2 : constant System_Time_Span := Calculate_Span
(Start_Time => Anchor_Tx_Resp_Timestamp,
End_Time => Anchor_Rx_Final_Timestamp);
T_Reply2 : constant System_Time_Span := Calculate_Span
(Start_Time => Tag_Rx_Resp_Timestamp,
End_Time => Tag_Tx_Final_Timestamp);
Time_Of_Flight_1 : System_Time_Span_Div2;
Time_Of_Flight_2 : System_Time_Span_Div2;
Time_Of_Flight : System_Time_Span_Div4;
Diff : System_Time_Span;
Sum : System_Time_Span_Div2;
Result : Large_Meters;
begin
if (T_Reply1 > T_Roundtrip1) or (T_Reply2 > T_Roundtrip2) then
Time_Of_Flight := 0.0;
else
Diff := T_Roundtrip1 - T_Reply1;
Time_Of_Flight_1 := System_Time_Span_Div2 (Diff / System_Time_Span (2.0));
Diff := T_Roundtrip2 - T_Reply2;
Time_Of_Flight_2 := System_Time_Span_Div2 (Diff / System_Time_Span (2.0));
Sum := Time_Of_Flight_1 + Time_Of_Flight_2;
Time_Of_Flight := System_Time_Span_Div4 (Sum / System_Time_Span_Div4 (2.0));
end if;
-- Cap ToF to 0.01 seconds to avoid overflow in the following calculations.
if Time_Of_Flight >= Max_Time_Of_Flight then
Time_Of_Flight := Max_Time_Of_Flight;
end if;
pragma Assert_And_Cut (Time_Of_Flight <= Max_Time_Of_Flight);
-- Convert the fixed-point representation to its integer represention
-- (in multiples of the 'Delta).
Result := Large_Meters (Time_Of_Flight / System_Time_Span_Div4 (System_Time_Span_Div4'Delta));
-- Multiply the ToF (s) with the speed of light (m/s) to yield
-- the distance (m) in meters.
Result := Result * Large_Meters (Speed_Of_Light_In_Vacuum);
-- Convert back from integer representation to fixed-point representation.
Result := Result / Large_Meters (1.0 / System_Time_Span_Div4'Delta);
return Biased_Distance (Result);
end Compute_Distance;
------------------------
-- Compute_Distance --
------------------------
function Compute_Distance
(Tag_Tx_Poll_Timestamp : in Fine_System_Time;
Anchor_Rx_Poll_Timestamp : in Fine_System_Time;
Anchor_Tx_Resp_Timestamp : in Fine_System_Time;
Tag_Rx_Resp_Timestamp : in Fine_System_Time;
Tag_Tx_Final_Timestamp : in Fine_System_Time;
Anchor_Rx_Final_Timestamp : in Fine_System_Time;
Channel : in DW1000.Driver.Channel_Number;
PRF : in DW1000.Driver.PRF_Type) return Meters is
Distance_With_Bias : Biased_Distance;
begin
Distance_With_Bias := Compute_Distance
(Tag_Tx_Poll_Timestamp => Tag_Tx_Poll_Timestamp,
Anchor_Rx_Poll_Timestamp => Anchor_Rx_Poll_Timestamp,
Anchor_Tx_Resp_Timestamp => Anchor_Tx_Resp_Timestamp,
Tag_Rx_Resp_Timestamp => Tag_Rx_Resp_Timestamp,
Tag_Tx_Final_Timestamp => Tag_Tx_Final_Timestamp,
Anchor_Rx_Final_Timestamp => Anchor_Rx_Final_Timestamp);
return Remove_Ranging_Bias
(Measured_Distance => Distance_With_Bias,
Channel => Channel,
PRF => PRF);
end Compute_Distance;
end DW1000.Ranging.Double_Sided;
|
-----------------------------------------------------------------------
-- ado-datasets-tests -- Test executing queries and using datasets
-- Copyright (C) 2013, 2014 Stephane Carrez
-- Written by Stephane Carrez (Stephane.Carrez@gmail.com)
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-----------------------------------------------------------------------
with Util.Test_Caller;
with Util.Properties;
with Regtests.Simple.Model;
with ADO.Queries.Loaders;
package body ADO.Datasets.Tests is
package Caller is new Util.Test_Caller (Test, "ADO.Datasets");
package User_List_Query_File is
new ADO.Queries.Loaders.File (Path => "regtests/files/user-list.xml",
Sha1 => "");
package User_List_Query is
new ADO.Queries.Loaders.Query (Name => "user-list",
File => User_List_Query_File.File'Access);
package User_List_Count_Query is
new ADO.Queries.Loaders.Query (Name => "user-list-count",
File => User_List_Query_File.File'Access);
procedure Add_Tests (Suite : in Util.Tests.Access_Test_Suite) is
begin
Caller.Add_Test (Suite, "Test ADO.Datasets.List (from <sql>)",
Test_List'Access);
Caller.Add_Test (Suite, "Test ADO.Datasets.Get_Count (from <sql>)",
Test_Count'Access);
Caller.Add_Test (Suite, "Test ADO.Datasets.Get_Count (from <sql-count>)",
Test_Count_Query'Access);
end Add_Tests;
procedure Test_List (T : in out Test) is
DB : ADO.Sessions.Master_Session := Regtests.Get_Master_Database;
Query : ADO.Queries.Context;
Count : Natural;
Data : ADO.Datasets.Dataset;
Props : constant Util.Properties.Manager := Util.Tests.Get_Properties;
begin
-- Configure the XML query loader.
ADO.Queries.Loaders.Initialize (Props.Get ("ado.queries.paths", ".;db"),
Props.Get ("ado.queries.load", "false") = "true");
Query.Set_Count_Query (User_List_Query.Query'Access);
Query.Bind_Param ("filter", String '("test-list"));
Count := ADO.Datasets.Get_Count (DB, Query);
for I in 1 .. 100 loop
declare
User : Regtests.Simple.Model.User_Ref;
begin
User.Set_Name ("John " & Integer'Image (I));
User.Set_Select_Name ("test-list");
User.Set_Value (ADO.Identifier (I));
User.Save (DB);
end;
end loop;
DB.Commit;
Query.Set_Query (User_List_Query.Query'Access);
ADO.Datasets.List (Data, DB, Query);
Util.Tests.Assert_Equals (T, 100 + Count, Data.Get_Count, "Invalid dataset size");
end Test_List;
procedure Test_Count (T : in out Test) is
DB : constant ADO.Sessions.Master_Session := Regtests.Get_Master_Database;
Query : ADO.Queries.Context;
Count : Natural;
Props : constant Util.Properties.Manager := Util.Tests.Get_Properties;
begin
-- Configure the XML query loader.
ADO.Queries.Loaders.Initialize (Props.Get ("ado.queries.paths", ".;db"),
Props.Get ("ado.queries.load", "false") = "true");
Query.Set_Query (User_List_Count_Query.Query'Access);
Count := ADO.Datasets.Get_Count (DB, Query);
T.Assert (Count > 0,
"The ADO.Datasets.Get_Count query should return a positive count");
end Test_Count;
procedure Test_Count_Query (T : in out Test) is
DB : constant ADO.Sessions.Master_Session := Regtests.Get_Master_Database;
Query : ADO.Queries.Context;
Count : Natural;
Props : constant Util.Properties.Manager := Util.Tests.Get_Properties;
begin
-- Configure the XML query loader.
ADO.Queries.Loaders.Initialize (Props.Get ("ado.queries.paths", ".;db"),
Props.Get ("ado.queries.load", "false") = "true");
Query.Set_Count_Query (User_List_Query.Query'Access);
Query.Bind_Param ("filter", String '("test-list"));
Count := ADO.Datasets.Get_Count (DB, Query);
T.Assert (Count > 0,
"The ADO.Datasets.Get_Count query should return a positive count");
end Test_Count_Query;
end ADO.Datasets.Tests;
|
with Ada.Text_IO;
with Ada.Strings.Unbounded;
package body kv.avm.Log is
Last_Log_Line : Ada.Strings.Unbounded.Unbounded_String;
Last_Error_Line : Ada.Strings.Unbounded.Unbounded_String;
procedure Put(Str : String) is
begin
if Verbose then
Ada.Text_IO.Put(Str);
end if;
end Put;
procedure Put_Line(Str : String) is
begin
Last_Log_Line := Ada.Strings.Unbounded.To_Unbounded_String(Str);
if Verbose then
Ada.Text_IO.Put_Line(Str);
end if;
end Put_Line;
procedure Log_If(Callback : access function return String) is
begin
if Verbose then
Ada.Text_IO.Put_Line(Callback.all);
end if;
end Log_If;
procedure Put_Error(Str : String) is
begin
Last_Error_Line := Ada.Strings.Unbounded.To_Unbounded_String(Str);
Ada.Text_IO.Put_Line(Str);
end Put_Error;
procedure New_Line(Count : Positive := 1) is
begin
if Verbose then
Ada.Text_IO.New_Line(Ada.Text_Io.Count(Count));
end if;
end New_Line;
function Get_Last_Log_Line return String is
begin
return Ada.Strings.Unbounded.To_String(Last_Log_Line);
end Get_Last_Log_Line;
function Get_Last_Error_Line return String is
begin
return Ada.Strings.Unbounded.To_String(Last_Error_Line);
end Get_Last_Error_Line;
end kv.avm.Log;
|
with System; use System;
with Ada.Unchecked_Conversion;
with STM32_SVD.DMA; use STM32_SVD.DMA;
package body STM32GD.USART.Peripheral is
DMA_Index : Integer := 1;
function W is new Ada.Unchecked_Conversion (Address, UInt32);
protected body IRQ_Handler is
entry Wait when Data_Available is
begin
Data_Available := False;
end Wait;
procedure Handler is
begin
USART.ICR.TCCF := 1;
USART.ICR.IDLECF := 1;
USART.ICR.EOBCF := 1;
Data_Available := True;
end Handler;
end IRQ_Handler;
procedure Init is
Int_Scale : constant UInt32 := 4;
Int_Divider : constant UInt32 := (25 * UInt32 (Clock)) / (Int_Scale * Speed);
Frac_Divider : constant UInt32 := Int_Divider rem 100;
begin
USART.BRR.DIV_Fraction :=
STM32_SVD.USART.BRR_DIV_Fraction_Field (((Frac_Divider * 16) + 50) / 100 mod 16);
USART.BRR.DIV_Mantissa :=
STM32_SVD.USART.BRR_DIV_Mantissa_Field (Int_Divider / 100);
USART.CR1.UE := 1;
USART.CR1.TE := 1;
USART.CR1.RE := 1;
USART.ICR.ORECF := 1;
USART.ICR.FECF := 1;
end Init;
procedure Transmit (Data : in Byte) is
begin
USART.ICR.FECF := 1;
while USART.ISR.TXE = 0 loop
null;
end loop;
USART.TDR.TDR := UInt9 (Data);
end Transmit;
function Receive return Byte is
begin
USART.ICR.ORECF := 1;
USART.ICR.FECF := 1;
while USART.ISR.RXNE = 0 loop
null;
end loop;
return Byte (USART.RDR.RDR);
end Receive;
end STM32GD.USART.Peripheral;
|
package discr3 is
type E is range 0..255;
type R1 is range 1..5;
type R2 is range 11..15;
type S1 is array(R1 range <>) of E;
type S2 is array(R2 range <>) of E;
V1 : S1( 2..3) := (0,0);
V2 : S2(12..13) := (1,1);
subtype R3 is R1 range 2..3;
V3 : S1 (R3);
end discr3;
|
--------------------------------------------------------------------
--| Package : Queue_Package Version : 2.0
--------------------------------------------------------------------
--| Abstract : Specification of a classic queue.
--------------------------------------------------------------------
--| File : Spec_Queue.ada
--| Compiler/System : Alsys Ada - IBM AIX/370
--| Author : Dan Stubbs/Neil Webre Date : 2/27/92
--| References : Stubbs & Webre, Data Structures with Abstract
--| Data Types and Ada, Brooks/Cole, 1993, Chapter 3.
--------------------------------------------------------------------
-- Version History: Add a new operation: TAIL 10/19/93 jd
generic
type object_type is private;
package queue_package is
type queue (max_size : positive) is limited private;
queue_empty : exception;
queue_full : exception;
procedure enqueue (the_queue : in out queue; the_object : object_type);
--
-- Results : Adds the_object to the_queue.
--
-- Exceptions : queue_full is raised if the queue contains
-- max_size objects.
--
procedure dequeue (the_queue : in out queue);
--
-- Results : Deletes the object that has been in the_queue
-- the longest.
--
-- Exceptions : queue_empty is raised if the queue is empty.
--
function head (the_queue : queue) return object_type;
--
-- Results : Returns the object that has been in the_queue
-- the longest.
--
-- Exceptions : queue_empty is raised if the_queue is empty.
--
function tail (the_queue : queue) return object_type;
--
-- Results : Returns the object that was most recently added
--
-- Exceptions : queue_empty is raised if the_queue is empty.
--
procedure clear (the_queue : in out queue);
--
-- Results : Sets the number of objects in the_queue to zero.
--
function number_of_objects (the_queue : queue) return natural;
--
-- Results : Returns the number of objects in the_queue.
--
procedure copy (the_queue : queue; the_copy : in out queue);
--
-- Results : the_copy is a duplicate of the_queue.
--
generic
with procedure process (the_object : object_type);
procedure iterate (the_queue : queue);
--
-- Results : Procedure process is applied to each object in the_queue
-- until all objects have been processed.
--
private
type array_of_objects is array (positive range <>) of object_type;
type queue (max_size : positive) is record
size : natural := 0;
first : positive := 1;
last : positive := max_size;
objects : array_of_objects (1 .. max_size);
end record;
end queue_package;
package body queue_package is
procedure enqueue (the_queue : in out queue; the_object : object_type) is
--
-- Length 6 Complexity 2 Performance O(1)
--
begin
if the_queue.size = the_queue.max_size then
raise queue_full;
end if;
the_queue.last := (the_queue.last mod the_queue.max_size) + 1;
the_queue.objects(the_queue.last) := the_object;
the_queue.size := the_queue.size + 1;
end enqueue;
procedure dequeue (the_queue : in out queue) is
--
-- Length 3 Complexity 2 Performance O(1)
--
begin
the_queue.size := the_queue.size - 1;
the_queue.first := (the_queue.first mod the_queue.max_size) + 1;
exception
when constraint_error | numeric_error => raise queue_empty;
end dequeue;
function head (the_queue : queue) return object_type is
--
-- Length 2 Complexity 2 Performance O(1)
--
begin
return the_queue.objects(the_queue.first);
exception
when constraint_error | numeric_error => raise queue_empty;
end head;
function tail (the_queue : queue) return object_type is
--
-- Length 2 Complexity 2 Performance O(1)
--
begin
return the_queue.objects(the_queue.last);
exception
when constraint_error | numeric_error => raise queue_empty;
end tail;
procedure clear (the_queue : in out queue) is
--
-- Length 3 Complexity 1 Performance O(1);
--
begin
the_queue.size := 0;
the_queue.first := 1;
the_queue.last := the_queue.max_size;
end clear;
function number_of_objects (the_queue : queue) return natural is
--
-- Length 1 Complexity 1 Performance O(1)
--
begin
return the_queue.size;
end number_of_objects;
procedure copy (the_queue : queue; the_copy : in out queue) is
--
-- Length 9 Complexity 4 Performance O(n)
-- All objects in the_queue are copied.
--
index : positive := the_queue.first;
begin
if the_queue.size > the_copy.max_size then
raise queue_full;
elsif the_queue.size > 0 then
clear (the_copy);
loop
enqueue (the_copy, the_queue.objects(index));
exit when index = the_queue.last;
index := (index mod the_queue.max_size) + 1;
end loop;
end if;
end copy;
procedure iterate (the_queue : queue) is
--
-- Length 6 Complexity 3 Performance O(n)
-- Each of the n objects in the_queue is processed.
--
index : natural := the_queue.first;
begin
if the_queue.size > 0 then
loop
process (the_queue.objects(index));
exit when index = the_queue.last;
index := (index mod the_queue.max_size) + 1;
end loop;
end if;
end iterate;
end queue_package;
|
-- This file is covered by the Internet Software Consortium (ISC) License
-- Reference: ../License.txt
with Terminal_Interface.Curses;
with Port_Specification;
with HelperText;
package Options_Dialog is
package TIC renames Terminal_Interface.Curses;
package PSP renames Port_Specification;
package HT renames HelperText;
-- Initialize the curses screen.
-- Returns False if no color support (curses not used at all)
function launch_dialog (specification : in out PSP.Portspecs) return Boolean;
dev_error : exception;
private
appline_max : constant Positive := 79;
type zones is (keymenu, dialog);
type group_type is (radio, restrict, unlimited);
type affection is array (1 .. 52) of Boolean;
subtype appline is TIC.Attributed_String (1 .. appline_max);
subtype optentry is String (1 .. 71);
type optentry_rec is record
template : optentry;
relative_vert : Positive;
default_value : Boolean;
current_value : Boolean;
ticked_value : Boolean;
member_group : Natural;
prevents : affection;
implies : affection;
end record;
type grouping_rec is record
template : optentry;
relative_vert : Positive;
behavior : group_type;
end record;
type optstorage is array (1 .. 52) of optentry_rec;
type group_titles is array (1 .. 26) of grouping_rec;
type palette_rec is
record
palette : TIC.Color_Pair;
attribute : TIC.Character_Attribute_Set;
end record;
cursor_vis : TIC.Cursor_Visibility := TIC.Invisible;
app_width : constant TIC.Column_Count := 80;
dialog_height : constant TIC.Line_Count := 82;
normal : constant TIC.Character_Attribute_Set := (others => False);
bright : constant TIC.Character_Attribute_Set := (Bold_Character => True,
others => False);
dimmed : constant TIC.Character_Attribute_Set := (Dim_Character => True,
others => False);
zone_keymenu : TIC.Window;
zone_dialog : TIC.Window;
c_standard : TIC.Color_Pair;
c_key_desc : TIC.Color_Pair;
c_title : TIC.Color_Pair;
c_trimmings : TIC.Color_Pair;
c_optbox_title : TIC.Color_Pair;
c_group_text : TIC.Color_Pair;
c_group_trim : TIC.Color_Pair;
c_letters : TIC.Color_Pair;
c_options : TIC.Color_Pair;
c_inv_gray : TIC.Color_Pair;
c_tick_on : TIC.Color_Pair;
c_tick_delta : TIC.Color_Pair;
c_arrow : TIC.Color_Pair;
last_alphakey : Character := 'A';
num_std_options : Natural;
port_namebase : HT.Text;
port_version : HT.Text;
port_sdesc : HT.Text;
formatted_opts : optstorage;
formatted_grps : group_titles;
num_groups : Natural;
num_options : Natural;
arrow_points : Positive;
offset : Natural;
function establish_colors return Boolean;
function Start_Curses_Mode return Boolean;
function launch_keymenu_zone return Boolean;
function launch_dialog_zone return Boolean;
function zone_window (zone : zones) return TIC.Window;
function index_to_center (display_text : String) return TIC.Column_Position;
function title_bar_contents return String;
procedure Refresh_Zone (zone : zones);
procedure Return_To_Text_Mode;
procedure draw_static_keymenu;
procedure draw_static_dialog;
procedure terminate_dialog;
procedure setup_parameters (specification : PSP.Portspecs);
procedure handle_user_commands;
procedure populate_dialog;
procedure Scrawl
(zone : zones;
information : TIC.Attributed_String;
at_line : TIC.Line_Position;
at_column : TIC.Column_Position := 0);
function custom_message (message : String;
attribute : TIC.Character_Attribute_Set;
pen_color : TIC.Color_Pair) return TIC.Attributed_String;
procedure touch_up (ATS : in out TIC.Attributed_String;
From_index : Positive;
length : Positive;
attribute : TIC.Character_Attribute_Set;
pen_color : TIC.Color_Pair);
function colorize_groups (textdata : String) return TIC.Attributed_String;
function colorize_option (textdata : String) return TIC.Attributed_String;
procedure toggle_option (option_index : Positive);
procedure cascade (option_index : Positive);
procedure save_options;
end Options_Dialog;
|
with
impact.d2.Math;
package Impact.d2.Types
--
-- Internal types.
--
is
use impact.d2.Math;
-- This is an internal structure.
--
type b2Position is
record
c : b2Vec2;
a : float32;
end record;
-- This is an internal structure.
--
type b2Velocity is
record
v : b2Vec2;
w : float32;
end record;
type Position_view is access all b2Position;
type Velocity_view is access all b2Velocity;
type Position_views is array (int32 range <>) of Position_view;
type Velocity_views is array (int32 range <>) of Velocity_view;
type access_Position_views is access all Position_views;
type access_Velocity_views is access all Velocity_views;
end Impact.d2.Types;
|
with
Interfaces.C,
System;
use type
Interfaces.C.int,
System.Address;
package body FLTK.Widgets.Groups.Spinners is
procedure spinner_set_draw_hook
(W, D : in System.Address);
pragma Import (C, spinner_set_draw_hook, "spinner_set_draw_hook");
pragma Inline (spinner_set_draw_hook);
procedure spinner_set_handle_hook
(W, H : in System.Address);
pragma Import (C, spinner_set_handle_hook, "spinner_set_handle_hook");
pragma Inline (spinner_set_handle_hook);
function new_fl_spinner
(X, Y, W, H : in Interfaces.C.int;
Text : in Interfaces.C.char_array)
return System.Address;
pragma Import (C, new_fl_spinner, "new_fl_spinner");
pragma Inline (new_fl_spinner);
procedure free_fl_spinner
(W : in System.Address);
pragma Import (C, free_fl_spinner, "free_fl_spinner");
pragma Inline (free_fl_spinner);
function fl_spinner_get_color
(S : in System.Address)
return Interfaces.C.unsigned;
pragma Import (C, fl_spinner_get_color, "fl_spinner_get_color");
pragma Inline (fl_spinner_get_color);
procedure fl_spinner_set_color
(S : in System.Address;
C : in Interfaces.C.unsigned);
pragma Import (C, fl_spinner_set_color, "fl_spinner_set_color");
pragma Inline (fl_spinner_set_color);
function fl_spinner_get_selection_color
(S : in System.Address)
return Interfaces.C.unsigned;
pragma Import (C, fl_spinner_get_selection_color, "fl_spinner_get_selection_color");
pragma Inline (fl_spinner_get_selection_color);
procedure fl_spinner_set_selection_color
(S : in System.Address;
T : in Interfaces.C.unsigned);
pragma Import (C, fl_spinner_set_selection_color, "fl_spinner_set_selection_color");
pragma Inline (fl_spinner_set_selection_color);
function fl_spinner_get_textcolor
(S : in System.Address)
return Interfaces.C.unsigned;
pragma Import (C, fl_spinner_get_textcolor, "fl_spinner_get_textcolor");
pragma Inline (fl_spinner_get_textcolor);
procedure fl_spinner_set_textcolor
(S : in System.Address;
T : in Interfaces.C.unsigned);
pragma Import (C, fl_spinner_set_textcolor, "fl_spinner_set_textcolor");
pragma Inline (fl_spinner_set_textcolor);
function fl_spinner_get_textfont
(S : in System.Address)
return Interfaces.C.int;
pragma Import (C, fl_spinner_get_textfont, "fl_spinner_get_textfont");
pragma Inline (fl_spinner_get_textfont);
procedure fl_spinner_set_textfont
(S : in System.Address;
T : in Interfaces.C.int);
pragma Import (C, fl_spinner_set_textfont, "fl_spinner_set_textfont");
pragma Inline (fl_spinner_set_textfont);
function fl_spinner_get_textsize
(S : in System.Address)
return Interfaces.C.int;
pragma Import (C, fl_spinner_get_textsize, "fl_spinner_get_textsize");
pragma Inline (fl_spinner_get_textsize);
procedure fl_spinner_set_textsize
(S : in System.Address;
T : in Interfaces.C.int);
pragma Import (C, fl_spinner_set_textsize, "fl_spinner_set_textsize");
pragma Inline (fl_spinner_set_textsize);
function fl_spinner_get_minimum
(S : in System.Address)
return Interfaces.C.double;
pragma Import (C, fl_spinner_get_minimum, "fl_spinner_get_minimum");
pragma Inline (fl_spinner_get_minimum);
procedure fl_spinner_set_minimum
(S : in System.Address;
T : in Interfaces.C.double);
pragma Import (C, fl_spinner_set_minimum, "fl_spinner_set_minimum");
pragma Inline (fl_spinner_set_minimum);
function fl_spinner_get_maximum
(S : in System.Address)
return Interfaces.C.double;
pragma Import (C, fl_spinner_get_maximum, "fl_spinner_get_maximum");
pragma Inline (fl_spinner_get_maximum);
procedure fl_spinner_set_maximum
(S : in System.Address;
T : in Interfaces.C.double);
pragma Import (C, fl_spinner_set_maximum, "fl_spinner_set_maximum");
pragma Inline (fl_spinner_set_maximum);
procedure fl_spinner_range
(S : in System.Address;
A, B : in Interfaces.C.double);
pragma Import (C, fl_spinner_range, "fl_spinner_range");
pragma Inline (fl_spinner_range);
function fl_spinner_get_step
(S : in System.Address)
return Interfaces.C.double;
pragma Import (C, fl_spinner_get_step, "fl_spinner_get_step");
pragma Inline (fl_spinner_get_step);
procedure fl_spinner_set_step
(S : in System.Address;
T : in Interfaces.C.double);
pragma Import (C, fl_spinner_set_step, "fl_spinner_set_step");
pragma Inline (fl_spinner_set_step);
function fl_spinner_get_type
(S : in System.Address)
return Interfaces.C.int;
pragma Import (C, fl_spinner_get_type, "fl_spinner_get_type");
pragma Inline (fl_spinner_get_type);
procedure fl_spinner_set_type
(S : in System.Address;
T : in Interfaces.C.int);
pragma Import (C, fl_spinner_set_type, "fl_spinner_set_type");
pragma Inline (fl_spinner_set_type);
function fl_spinner_get_value
(S : in System.Address)
return Interfaces.C.double;
pragma Import (C, fl_spinner_get_value, "fl_spinner_get_value");
pragma Inline (fl_spinner_get_value);
procedure fl_spinner_set_value
(S : in System.Address;
T : in Interfaces.C.double);
pragma Import (C, fl_spinner_set_value, "fl_spinner_set_value");
pragma Inline (fl_spinner_set_value);
procedure fl_spinner_draw
(W : in System.Address);
pragma Import (C, fl_spinner_draw, "fl_spinner_draw");
pragma Inline (fl_spinner_draw);
function fl_spinner_handle
(W : in System.Address;
E : in Interfaces.C.int)
return Interfaces.C.int;
pragma Import (C, fl_spinner_handle, "fl_spinner_handle");
pragma Inline (fl_spinner_handle);
procedure Finalize
(This : in out Spinner) is
begin
if This.Void_Ptr /= System.Null_Address and then
This in Spinner'Class
then
This.Clear;
free_fl_spinner (This.Void_Ptr);
This.Void_Ptr := System.Null_Address;
end if;
Finalize (Group (This));
end Finalize;
package body Forge is
function Create
(X, Y, W, H : in Integer;
Text : in String)
return Spinner is
begin
return This : Spinner do
This.Void_Ptr := new_fl_spinner
(Interfaces.C.int (X),
Interfaces.C.int (Y),
Interfaces.C.int (W),
Interfaces.C.int (H),
Interfaces.C.To_C (Text));
fl_group_end (This.Void_Ptr);
fl_widget_set_user_data
(This.Void_Ptr,
Widget_Convert.To_Address (This'Unchecked_Access));
spinner_set_draw_hook (This.Void_Ptr, Draw_Hook'Address);
spinner_set_handle_hook (This.Void_Ptr, Handle_Hook'Address);
end return;
end Create;
end Forge;
function Get_Background_Color
(This : in Spinner)
return Color is
begin
return Color (fl_spinner_get_color (This.Void_Ptr));
end Get_Background_Color;
procedure Set_Background_Color
(This : in out Spinner;
To : in Color) is
begin
fl_spinner_set_color (This.Void_Ptr, Interfaces.C.unsigned (To));
end Set_Background_Color;
function Get_Selection_Color
(This : in Spinner)
return Color is
begin
return Color (fl_spinner_get_selection_color (This.Void_Ptr));
end Get_Selection_Color;
procedure Set_Selection_Color
(This : in out Spinner;
To : in Color) is
begin
fl_spinner_set_selection_color (This.Void_Ptr, Interfaces.C.unsigned (To));
end Set_Selection_Color;
function Get_Text_Color
(This : in Spinner)
return Color is
begin
return Color (fl_spinner_get_textcolor (This.Void_Ptr));
end Get_Text_Color;
procedure Set_Text_Color
(This : in out Spinner;
To : in Color) is
begin
fl_spinner_set_textcolor (This.Void_Ptr, Interfaces.C.unsigned (To));
end Set_Text_Color;
function Get_Text_Font
(This : in Spinner)
return Font_Kind is
begin
return Font_Kind'Val (fl_spinner_get_textfont (This.Void_Ptr));
end Get_Text_Font;
procedure Set_Text_Font
(This : in out Spinner;
To : in Font_Kind) is
begin
fl_spinner_set_textfont (This.Void_Ptr, Font_Kind'Pos (To));
end Set_Text_Font;
function Get_Text_Size
(This : in Spinner)
return Font_Size is
begin
return Font_Size (fl_spinner_get_textsize (This.Void_Ptr));
end Get_Text_Size;
procedure Set_Text_Size
(This : in out Spinner;
To : in Font_Size) is
begin
fl_spinner_set_textsize (This.Void_Ptr, Interfaces.C.int (To));
end Set_Text_Size;
function Get_Minimum
(This : in Spinner)
return Long_Float is
begin
return Long_Float (fl_spinner_get_minimum (This.Void_Ptr));
end Get_Minimum;
procedure Set_Minimum
(This : in out Spinner;
To : in Long_Float) is
begin
fl_spinner_set_minimum (This.Void_Ptr, Interfaces.C.double (To));
end Set_Minimum;
function Get_Maximum
(This : in Spinner)
return Long_Float is
begin
return Long_Float (fl_spinner_get_maximum (This.Void_Ptr));
end Get_Maximum;
procedure Set_Maximum
(This : in out Spinner;
To : in Long_Float) is
begin
fl_spinner_set_maximum (This.Void_Ptr, Interfaces.C.double (To));
end Set_Maximum;
procedure Get_Range
(This : in Spinner;
Min, Max : out Long_Float) is
begin
Min := Long_Float (fl_spinner_get_minimum (This.Void_Ptr));
Max := Long_Float (fl_spinner_get_maximum (This.Void_Ptr));
end Get_Range;
procedure Set_Range
(This : in out Spinner;
Min, Max : in Long_Float) is
begin
fl_spinner_range
(This.Void_Ptr,
Interfaces.C.double (Min),
Interfaces.C.double (Max));
end Set_Range;
function Get_Step
(This : in Spinner)
return Long_Float is
begin
return Long_Float (fl_spinner_get_step (This.Void_Ptr));
end Get_Step;
procedure Set_Step
(This : in out Spinner;
To : in Long_Float) is
begin
fl_spinner_set_step (This.Void_Ptr, Interfaces.C.double (To));
end Set_Step;
function Get_Type
(This : in Spinner)
return Spinner_Kind is
begin
return Spinner_Kind'Val (fl_spinner_get_type (This.Void_Ptr) - 1);
end Get_Type;
procedure Set_Type
(This : in out Spinner;
To : in Spinner_Kind) is
begin
fl_spinner_set_type (This.Void_Ptr, Spinner_Kind'Pos (To) + 1);
end Set_Type;
function Get_Value
(This : in Spinner)
return Long_Float is
begin
return Long_Float (fl_spinner_get_value (This.Void_Ptr));
end Get_Value;
procedure Set_Value
(This : in out Spinner;
To : in Long_Float) is
begin
fl_spinner_set_value (This.Void_Ptr, Interfaces.C.double (To));
end Set_Value;
procedure Draw
(This : in out Spinner) is
begin
fl_spinner_draw (This.Void_Ptr);
end Draw;
function Handle
(This : in out Spinner;
Event : in Event_Kind)
return Event_Outcome is
begin
return Event_Outcome'Val
(fl_spinner_handle (This.Void_Ptr, Event_Kind'Pos (Event)));
end Handle;
end FLTK.Widgets.Groups.Spinners;
|
with Ada.Text_IO; use Ada.Text_IO;
with HAL.Block_Drivers;
with Monitor.Block_Drivers; use Monitor.Block_Drivers;
with Dummy_Block_Driver; use Dummy_Block_Driver;
procedure TC_Block_Driver is
BD : aliased Dummy_BD;
Mon : Block_Driver_Monitor (BD'Unchecked_Access,
Put_Line'Access);
Data : HAL.Block_Drivers.Block (1 .. 512);
Unref : Boolean with Unreferenced;
begin
Data := (others => 0);
BD.Should_Fail := True;
Unref := Mon.Read (0, Data);
Unref := Mon.Write (1, Data);
BD.Should_Fail := False;
Unref := Mon.Read (2, Data);
Unref := Mon.Write (3, Data);
end TC_Block_Driver;
|
------------------------------------------------------------------------------
-- Copyright (c) 2013-2014, Natacha Porté --
-- --
-- Permission to use, copy, modify, and distribute this software for any --
-- purpose with or without fee is hereby granted, provided that the above --
-- copyright notice and this permission notice appear in all copies. --
-- --
-- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES --
-- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF --
-- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR --
-- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES --
-- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN --
-- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF --
-- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. --
------------------------------------------------------------------------------
with Natools.S_Expressions.Encodings;
package body Natools.S_Expressions.Parsers is
----------------------
-- Parser Interface --
----------------------
procedure Reset (Self : in out Parser; Hard : in Boolean := False) is
Null_Stack : Lockable.Lock_Stack;
begin
Self.Internal := (State => Waiting);
Self.Next_Event := Events.End_Of_Input;
Self.Latest := Events.Error;
Self.Level := 0;
Self.Lock_Stack := Null_Stack;
Self.Locked := False;
if Hard then
Self.Pending.Hard_Reset;
Self.Buffer.Hard_Reset;
else
Self.Pending.Soft_Reset;
Self.Buffer.Soft_Reset;
end if;
end Reset;
overriding function Current_Event (Self : in Parser) return Events.Event is
begin
if Self.Locked then
return Events.End_Of_Input;
else
return Self.Latest;
end if;
end Current_Event;
overriding function Current_Atom (Self : in Parser) return Atom is
begin
if Self.Locked or Self.Latest /= Events.Add_Atom then
raise Program_Error;
end if;
return Self.Buffer.Data;
end Current_Atom;
overriding function Current_Level (Self : in Parser) return Natural is
begin
if Self.Locked then
return 0;
else
return Self.Level - Lockable.Current_Level (Self.Lock_Stack);
end if;
end Current_Level;
overriding procedure Query_Atom
(Self : in Parser;
Process : not null access procedure (Data : in Atom)) is
begin
if Self.Locked or Self.Latest /= Events.Add_Atom then
raise Program_Error;
end if;
Self.Buffer.Query (Process);
end Query_Atom;
overriding procedure Read_Atom
(Self : in Parser;
Data : out Atom;
Length : out Count) is
begin
if Self.Locked or Self.Latest /= Events.Add_Atom then
raise Program_Error;
end if;
Self.Buffer.Peek (Data, Length);
end Read_Atom;
overriding procedure Next
(Self : in out Parser;
Event : out Events.Event)
is
O : Octet;
begin
if Self.Locked then
Event := Events.End_Of_Input;
return;
end if;
Self.Latest := Events.Error;
loop
-- Process pending events
if Self.Next_Event /= Events.End_Of_Input then
Self.Latest := Self.Next_Event;
Self.Next_Event := Events.End_Of_Input;
case Self.Latest is
when Events.Open_List =>
Self.Level := Self.Level + 1;
when Events.Close_List =>
if Self.Level > 0 then
Self.Level := Self.Level - 1;
end if;
when others => null;
end case;
exit;
end if;
-- Read a single octet from source
if Self.Pending.Length = 0 then
Read_More (Parser'Class (Self), Self.Pending);
if Self.Pending.Length = 0 then
Self.Latest := Events.End_Of_Input;
exit;
end if;
Self.Pending.Invert;
end if;
Self.Pending.Pop (O);
-- Process octet
case Self.Internal.State is
when Waiting =>
Self.Buffer.Soft_Reset;
case O is
when 0 | Encodings.Space | Encodings.HT
| Encodings.CR | Encodings.LF
| Encodings.VT | Encodings.FF =>
null;
when Encodings.List_Begin =>
Self.Latest := Events.Open_List;
Self.Level := Self.Level + 1;
when Encodings.List_End =>
Self.Latest := Events.Close_List;
if Self.Level > 0 then
Self.Level := Self.Level - 1;
end if;
when Encodings.Base64_Atom_Begin =>
Self.Internal
:= (State => Base64_Atom,
Chunk => (Data => <>, Length => 0));
when Encodings.Base64_Expr_Begin =>
Self.Internal
:= (State => Base64_Expr,
Chunk => (Data => <>, Length => 0));
when Encodings.Hex_Atom_Begin =>
Self.Internal := (State => Hex_Atom, Nibble_Buffer => 0);
when Encodings.Quoted_Atom_Begin =>
Self.Internal :=
(State => Quoted_Atom,
Escape => (Data => <>, Length => 0));
when Encodings.Digit_0 .. Encodings.Digit_9 =>
Self.Internal := (State => Number);
Atom_Buffers.Append (Self.Buffer, O);
when others =>
Self.Internal := (State => Token);
Atom_Buffers.Append (Self.Buffer, O);
end case;
when Base64_Atom | Base64_Expr =>
if Encodings.Is_Base64_Digit (O) then
Self.Internal.Chunk.Data (Self.Internal.Chunk.Length) := O;
Self.Internal.Chunk.Length := Self.Internal.Chunk.Length + 1;
if Self.Internal.Chunk.Length = 4 then
Self.Buffer.Append
(Encodings.Decode_Base64 (Self.Internal.Chunk.Data));
Self.Internal.Chunk.Length := 0;
end if;
elsif (O = Encodings.Base64_Atom_End
and Self.Internal.State = Base64_Atom)
or (O = Encodings.Base64_Expr_End
and Self.Internal.State = Base64_Expr)
then
Self.Buffer.Append (Encodings.Decode_Base64
(Self.Internal.Chunk.Data
(0 .. Self.Internal.Chunk.Length - 1)));
if Self.Internal.State = Base64_Atom then
Self.Latest := Events.Add_Atom;
else
Self.Pending.Append_Reverse (Self.Buffer.Data);
Self.Buffer.Soft_Reset;
end if;
Self.Internal := (State => Waiting);
end if;
when Hex_Atom =>
if Encodings.Is_Hex_Digit (O) then
if Encodings.Is_Hex_Digit (Self.Internal.Nibble_Buffer) then
Self.Buffer.Append
(Encodings.Decode_Hex (Self.Internal.Nibble_Buffer, O));
Self.Internal.Nibble_Buffer := 0;
else
Self.Internal.Nibble_Buffer := O;
end if;
elsif O = Encodings.Hex_Atom_End then
Self.Latest := Events.Add_Atom;
Self.Internal := (State => Waiting);
end if;
when Number =>
case O is
when Encodings.Digit_0 .. Encodings.Digit_9 =>
Self.Buffer.Append (O);
when Encodings.Verbatim_Begin =>
Self.Internal := (State => Verbatim_Atom, Size => 0);
for I in 1 .. Self.Buffer.Length loop
Self.Internal.Size := Self.Internal.Size * 10
+ Count (Self.Buffer.Element (I)
- Encodings.Digit_0);
end loop;
Self.Buffer.Soft_Reset;
if Self.Internal.Size = 0 then
Self.Latest := Events.Add_Atom;
Self.Internal := (State => Waiting);
else
Self.Buffer.Preallocate (Self.Internal.Size);
end if;
when 0 | Encodings.Space | Encodings.HT
| Encodings.CR | Encodings.LF
| Encodings.VT | Encodings.FF =>
Self.Latest := Events.Add_Atom;
Self.Internal := (State => Waiting);
when Encodings.List_Begin =>
Self.Internal := (State => Waiting);
Self.Next_Event := Events.Open_List;
Self.Latest := Events.Add_Atom;
when Encodings.List_End =>
Self.Internal := (State => Waiting);
Self.Next_Event := Events.Close_List;
Self.Latest := Events.Add_Atom;
when Encodings.Base64_Atom_Begin =>
Self.Internal
:= (State => Base64_Atom,
Chunk => (Data => <>, Length => 0));
Self.Buffer.Soft_Reset;
when Encodings.Base64_Expr_Begin =>
Self.Internal
:= (State => Base64_Expr,
Chunk => (Data => <>, Length => 0));
Self.Buffer.Soft_Reset;
when Encodings.Hex_Atom_Begin =>
Self.Internal := (State => Hex_Atom, Nibble_Buffer => 0);
Self.Buffer.Soft_Reset;
when Encodings.Quoted_Atom_Begin =>
Self.Internal
:= (State => Quoted_Atom,
Escape => (Data => <>, Length => 0));
Self.Buffer.Soft_Reset;
when others =>
Self.Buffer.Append (O);
Self.Internal := (State => Token);
end case;
when Quoted_Atom =>
case Self.Internal.Escape.Length is
when 0 =>
case O is
when Encodings.Escape =>
Self.Internal.Escape.Data (0) := O;
Self.Internal.Escape.Length := 1;
when Encodings.Quoted_Atom_End =>
Self.Internal := (State => Waiting);
Self.Latest := Events.Add_Atom;
when others =>
Self.Buffer.Append (O);
end case;
when 1 =>
case O is
when Character'Pos ('b') =>
Self.Buffer.Append (8);
Self.Internal.Escape.Length := 0;
when Character'Pos ('t') =>
Self.Buffer.Append (9);
Self.Internal.Escape.Length := 0;
when Character'Pos ('n') =>
Self.Buffer.Append (10);
Self.Internal.Escape.Length := 0;
when Character'Pos ('v') =>
Self.Buffer.Append (11);
Self.Internal.Escape.Length := 0;
when Character'Pos ('f') =>
Self.Buffer.Append (12);
Self.Internal.Escape.Length := 0;
when Character'Pos ('r') =>
Self.Buffer.Append (13);
Self.Internal.Escape.Length := 0;
when Character'Pos (''') | Encodings.Escape
| Encodings.Quoted_Atom_End =>
Self.Buffer.Append (O);
Self.Internal.Escape.Length := 0;
when Encodings.Digit_0 .. Encodings.Digit_0 + 3
| Character'Pos ('x')
| Encodings.CR | Encodings.LF =>
Self.Internal.Escape.Data (1) := O;
Self.Internal.Escape.Length := 2;
when others =>
Self.Buffer.Append (Self.Internal.Escape.Data (0));
Self.Pending.Append (O);
Self.Internal.Escape.Length := 0;
end case;
when 2 =>
if (Self.Internal.Escape.Data (1)
in Encodings.Digit_0 .. Encodings.Digit_0 + 3
and O in Encodings.Digit_0 .. Encodings.Digit_0 + 7)
or (Self.Internal.Escape.Data (1) = Character'Pos ('x')
and then Encodings.Is_Hex_Digit (O))
then
Self.Internal.Escape.Data (2) := O;
Self.Internal.Escape.Length := 3;
elsif Self.Internal.Escape.Data (1) = Encodings.CR
or Self.Internal.Escape.Data (1) = Encodings.LF
then
Self.Internal.Escape.Length := 0;
if not ((O = Encodings.CR or O = Encodings.LF)
and O /= Self.Internal.Escape.Data (1))
then
Self.Pending.Append (O);
end if;
else
Self.Buffer.Append
((Self.Internal.Escape.Data (0),
Self.Internal.Escape.Data (1)));
Self.Pending.Append (O);
Self.Internal.Escape.Length := 0;
end if;
when 3 =>
if Self.Internal.Escape.Data (1)
= Character'Pos ('x')
then
if Encodings.Is_Hex_Digit (O) then
Self.Buffer.Append
(Encodings.Decode_Hex
(Self.Internal.Escape.Data (2), O));
else
Self.Buffer.Append
((Self.Internal.Escape.Data (0),
Self.Internal.Escape.Data (1),
Self.Internal.Escape.Data (2)));
Self.Pending.Append (O);
end if;
else
pragma Assert (Self.Internal.Escape.Data (1)
in Encodings.Digit_0 .. Encodings.Digit_0 + 3);
if O in Encodings.Digit_0 .. Encodings.Digit_0 + 7 then
Atom_Buffers.Append
(Self.Buffer,
(Self.Internal.Escape.Data (1)
- Encodings.Digit_0)
* 2**6 +
(Self.Internal.Escape.Data (2)
- Encodings.Digit_0)
* 2**3 +
(O - Encodings.Digit_0));
else
Self.Buffer.Append
((Self.Internal.Escape.Data (0),
Self.Internal.Escape.Data (1),
Self.Internal.Escape.Data (2)));
Self.Pending.Append (O);
end if;
end if;
Self.Internal.Escape.Length := 0;
when 4 =>
raise Program_Error;
end case;
when Token =>
case O is
when 0 | Encodings.Space | Encodings.HT
| Encodings.CR | Encodings.LF
| Encodings.VT | Encodings.FF =>
Self.Internal := (State => Waiting);
Self.Latest := Events.Add_Atom;
when Encodings.List_Begin =>
Self.Internal := (State => Waiting);
Self.Next_Event := Events.Open_List;
Self.Latest := Events.Add_Atom;
when Encodings.List_End =>
Self.Internal := (State => Waiting);
Self.Next_Event := Events.Close_List;
Self.Latest := Events.Add_Atom;
when others =>
Self.Buffer.Append (O);
end case;
when Verbatim_Atom =>
Self.Buffer.Append (O);
pragma Assert (Self.Buffer.Length <= Self.Internal.Size);
if Self.Buffer.Length = Self.Internal.Size then
Self.Internal := (State => Waiting);
Self.Latest := Events.Add_Atom;
end if;
end case;
exit when Self.Latest /= Events.Error;
end loop;
if Self.Latest = Events.Close_List
and then Self.Level < Lockable.Current_Level (Self.Lock_Stack)
then
Self.Locked := True;
Event := Events.End_Of_Input;
else
Event := Self.Latest;
end if;
end Next;
overriding procedure Lock
(Self : in out Parser;
State : out Lockable.Lock_State) is
begin
Lockable.Push_Level (Self.Lock_Stack, Self.Level, State);
end Lock;
overriding procedure Unlock
(Self : in out Parser;
State : in out Lockable.Lock_State;
Finish : in Boolean := True)
is
Previous_Level : constant Natural
:= Lockable.Current_Level (Self.Lock_Stack);
Event : Events.Event;
begin
Lockable.Pop_Level (Self.Lock_Stack, State);
State := Lockable.Null_State;
if Finish then
Event := Self.Current_Event;
loop
case Event is
when Events.Open_List | Events.Add_Atom =>
null;
when Events.Close_List =>
exit when Self.Level < Previous_Level;
when Events.Error | Events.End_Of_Input =>
exit;
end case;
Self.Next (Event);
end loop;
end if;
Self.Locked := Self.Level < Lockable.Current_Level (Self.Lock_Stack);
end Unlock;
-------------------
-- Stream Parser --
-------------------
overriding procedure Read_More
(Self : in out Stream_Parser;
Buffer : out Atom_Buffers.Atom_Buffer)
is
Item : Ada.Streams.Stream_Element_Array (1 .. 128);
Last : Ada.Streams.Stream_Element_Offset;
begin
Self.Input.Read (Item, Last);
if Last in Item'Range then
Buffer.Append (Item (Item'First .. Last));
end if;
end Read_More;
-------------------
-- Memory Parser --
-------------------
not overriding function Create
(Data : in Ada.Streams.Stream_Element_Array)
return Memory_Parser is
begin
return P : Memory_Parser do
P.Pending.Append (Data);
P.Pending.Invert;
end return;
end Create;
not overriding function Create_From_String
(Data : in String) return Memory_Parser is
begin
return Create (To_Atom (Data));
end Create_From_String;
end Natools.S_Expressions.Parsers;
|
with File_Utilities; use File_Utilities;
with Ada.Command_Line;
with Ada.Text_IO; use Ada.Text_IO;
procedure Test_File_Utilities is
Failure_Count : Natural := 0;
Check_Idx : Positive := 1;
-- --------------------------------------------------------------------------
procedure New_Test (Title : String) is
begin
New_Line;
Put_Line ("## " & Title);
New_Line;
end New_Test;
-- --------------------------------------------------------------------------
procedure Check (Title : String;
Result : String;
Expected : String) is
Tmp : constant String := Positive'Image (Check_Idx);
Idx : constant String := Tmp (2 .. Tmp'Last);
begin
New_Line;
Put_Line (Idx & ". " & Title);
Put_Line ("Expected :");
Put_Line ("""" & Expected & """");
if Result = Expected then
Put_Line ("OK");
else
Put_Line ("**Failed**, got """ & Result & """");
Failure_Count := Failure_Count + 1;
end if;
Check_Idx := Check_Idx + 1;
end Check;
begin
New_Line;
Put_Line ("# File_Utilities unit tests");
New_Line;
-- --------------------------------------------------------------------------
New_Test ("Short_Path");
Check (Title => "Subdir with default Prefix",
Result => Short_Path
(From_Dir => "/home/tests",
To_File => "/home/tests/mysite/site/d1/idx.txt"),
Expected => "mysite/site/d1/idx.txt");
Check (Title => "Dir with final /",
Result => Short_Path
(From_Dir => "/home/tests/",
To_File => "/home/tests/mysite/site/d1/idx.txt"),
Expected => "mysite/site/d1/idx.txt");
Check (Title => "subdir with Prefix",
Result => Short_Path
(From_Dir => "/home/tests",
To_File => "/home/tests/mysite/site/d1/idx.txt",
Prefix => "." & Separator),
Expected => "./mysite/site/d1/idx.txt");
Check (Title => "Sibling subdir",
Result => Short_Path
(From_Dir => "/home/tests/12/34",
To_File => "/home/tests/mysite/site/d1/idx.txt"),
Expected => "../../mysite/site/d1/idx.txt");
Check (Title => "Parent dir",
Result => Short_Path
(From_Dir => "/home/tests/12/34",
To_File => "/home/tests/idx.txt"),
Expected => "../../idx.txt");
Check (Title => "Other Prefix",
Result => Short_Path
(From_Dir => "/home/tests/12/",
To_File => "/home/tests/mysite/site/d1/idx.txt",
Prefix => "$PWD/"),
Expected => "$PWD/../mysite/site/d1/idx.txt");
Check (Title => "Root dir",
Result => Short_Path
(From_Dir => "/",
To_File => "/home/tests/mysite/site/d1/idx.txt"),
Expected => "/home/tests/mysite/site/d1/idx.txt");
Check (Title => "File is over dir",
Result => Short_Path
(From_Dir => "/home/tests/mysite/site/d1",
To_File => "/home/readme.txt"),
Expected => "../../../../readme.txt");
Check (Title => "File is over Dir, Dir with final /",
Result => Short_Path
(From_Dir => "/home/tests/mysite/site/d1/",
To_File => "/home/readme.txt"),
Expected => "../../../../readme.txt");
Check (Title => "File is the current dir",
Result => Short_Path
(From_Dir => "/home/tests/",
To_File => "/home/tests"),
Expected => "./");
Check (Title => "File is over Dir, Dir and File with final /",
Result => Short_Path
(From_Dir => "/home/tests/",
To_File => "/home/tests/"),
Expected => "./");
Check (Title => "No common part",
Result => Short_Path
(From_Dir => "/home/toto/src/tests/",
To_File => "/opt/GNAT/2018/lib64/libgcc_s.so"),
Expected => "/opt/GNAT/2018/lib64/libgcc_s.so");
-- --------------------------------------------------------------------------
New_Line;
if Failure_Count /= 0 then
Put_Line (Natural'Image (Failure_Count)
& " tests fails [Failed](tests_status.md#failed)");
Ada.Command_Line.Set_Exit_Status (Ada.Command_Line.Failure);
else
Put_Line ("All tests OK [Successful](tests_status.md#successful)");
end if;
end Test_File_Utilities;
|
with AUnit.Assertions; use AUnit.Assertions;
with Interfaces.C.Strings;
with Ada.Text_IO;
with ImageIO;
with PixelArray;
with ImageRegions;
with Histogram;
with HistogramGenerator;
use PixelArray;
package body HistogramTests is
procedure Register_Tests (T: in out TestCase) is
use AUnit.Test_Cases.Registration;
begin
Register_Routine (T, testBasicHistograms'Access, "basic histograms");
Register_Routine (T, testRescale'Access, "resizing histograms");
Register_Routine (T, testMultiplication'Access, "multiplication");
Register_Routine (T, testProjections'Access, "projecting images");
Register_Routine (T, testDistance'Access, "histogram distances");
end Register_Tests;
function Name(T: TestCase) return Test_String is
begin
return Format("Histogram Tests");
end Name;
procedure testBasicHistograms(T : in out Test_Cases.Test_Case'Class) is
d: Histogram.Data(5);
d1: Histogram.Data(5);
begin
Assert(d.sum = 0.0, "test 1");
Assert(d.size = 5, "test size");
d.set(0, 5.0);
d.set(1, 4.0);
d.set(2, 3.0);
d.set(3, 2.0);
d.set(4, 1.0);
Assert(d.get(3) = 2.0, "get");
Assert(d.sum = 15.0, "test sum");
Assert(d.average = 3.0, "avg");
d1 := d.normalized;
Assert(d1.sum = 1.0, "test normalized sum");
Assert(d.sum = 15.0, "control sum");
d.normalize;
Assert(d.sum = 1.0, "test normalized sum");
end testBasicHistograms;
procedure testRescale(T : in out Test_Cases.Test_Case'Class) is
d: Histogram.Data(3);
resized: Histogram.Data(4);
begin
d.set(0, 7.0);
d.set(1, 3.0);
d.set(2, 1.0);
resized := d.resized(4);
Assert(resized.get(0) = d.get(0), "0");
Assert(resized.get(1) < d.get(0) and resized.get(1) > d.get(1), "1");
Assert(resized.get(2) < d.get(1) and resized.get(2) > d.get(2), "2");
Assert(resized.get(3) = d.get(2), "3");
resized.set(0, 4.0);
resized.set(1, 1.0);
resized.set(2, 0.0);
resized.set(3, 4.0);
d := resized.resized(3);
Assert(d.get(0) = resized.get(0), "0");
Assert(d.get(1) < resized.get(0) and d.get(1) > resized.get(2), "1");
Assert(d.get(2) = resized.get(3), "2");
end testRescale;
procedure testMultiplication(T: in out Test_Cases.Test_Case'Class) is
h0, h1: Histogram.Data(3);
begin
h0.set(0, 1.0);
h0.set(1, 2.0);
h0.set(2, 3.0);
h1 := h0;
h1.multiply(1.5);
Assert(h1.get(0) = 1.5, "0");
Assert(h1.get(1) = 3.0, "1");
Assert(h1.get(2) = 4.5, "2");
Assert(h1.compare(h0, Histogram.ChiSquare) /= 0.0, "distance not equal");
Assert(h1.compare(h0.multiplied(1.5), Histogram.ChiSquare) = 0.0, "distance equal");
h1 := h0.add(h0);
Assert(h1.compare(h0.multiplied(2.0), Histogram.ChiSquare) = 0.0, "distance equal");
end testMultiplication;
procedure testProjections(T: in out Test_Cases.Test_Case'Class) is
image: PixelArray.ImagePlane := PixelArray.allocate(width => 5, height => 5);
r: ImageRegions.Rect;
begin
r.x := 0;
r.y := 0;
r.width := 5;
r.height := 5;
image.set(Pixel(255));
image.set(2, 0, 0);
image.set(2, 1, 0);
image.set(2, 2, 0);
image.set(2, 3, 0);
image.set(2, 4, 0);
-- horizontal and vertical projections of a straight vertical line
declare
hist: Histogram.Data := HistogramGenerator.horizontalProjection(image, r);
begin
Assert(hist.size = r.width, "hist w");
Assert(hist.sum = 5.0, "hist sum");
Assert(hist.get(0) = 0.0, "hist 0");
Assert(hist.get(1) = 0.0, "hist 1");
Assert(hist.get(2) = 5.0, "hist 2");
Assert(hist.get(3) = 0.0, "hist 3");
Assert(hist.get(4) = 0.0, "hist 4");
hist := HistogramGenerator.verticalProjection(image, r);
Assert(hist.size = r.height, "hist w");
Assert(hist.sum = 5.0, "hist sum");
Assert(hist.get(0) = 1.0, "hist 0");
Assert(hist.get(1) = 1.0, "hist 1");
Assert(hist.get(2) = 1.0, "hist 2");
Assert(hist.get(3) = 1.0, "hist 3");
Assert(hist.get(4) = 1.0, "hist 4");
end;
-- projections of y = x
image.set(Pixel(255));
image.set(0, 0, 0);
image.set(1, 1, 0);
image.set(2, 2, 0);
image.set(3, 3, 0);
image.set(4, 4, 0);
declare
hist: Histogram.Data := HistogramGenerator.horizontalProjection(image, r);
begin
Assert(hist.size = r.width, "hist w");
Assert(hist.sum = 5.0, "hist sum");
Assert(hist.get(0) = 1.0, "hist 0");
Assert(hist.get(1) = 1.0, "hist 1");
Assert(hist.get(2) = 1.0, "hist 2");
Assert(hist.get(3) = 1.0, "hist 3");
Assert(hist.get(4) = 1.0, "hist 4");
hist := HistogramGenerator.verticalProjection(image, r);
Assert(hist.size = r.height, "hist w");
Assert(hist.sum = 5.0, "hist sum");
Assert(hist.get(0) = 1.0, "hist 0");
Assert(hist.get(1) = 1.0, "hist 1");
Assert(hist.get(2) = 1.0, "hist 2");
Assert(hist.get(3) = 1.0, "hist 3");
Assert(hist.get(4) = 1.0, "hist 4");
end;
end testProjections;
procedure testDistance(T: in out Test_Cases.Test_Case'Class) is
h0, h1: Histogram.Data(5);
dist, dist2: Float := 0.0;
method: Histogram.CompareMethod;
begin
method := Histogram.Bhattacharyya;
dist := h0.compare(h1, method);
Assert(dist = 0.0, "compare id");
h0.set(0, 1.0);
h0.set(1, 2.0);
h0.set(2, 3.0);
h0.set(3, 4.0);
h0.set(4, 5.0);
dist := h0.compare(h1, method);
Assert(dist > 0.0, "compare different");
h1.set(0, 10.0);
h1.set(1, 10.0);
h1.set(2, 30.0);
h1.set(3, 40.0);
h1.set(4, 50.0);
dist2 := h0.compare(h1, method);
Assert(dist2 < dist, "similarity");
end testDistance;
end HistogramTests;
|
-- Copyright (c) 2020-2021 Bartek thindil Jasicki <thindil@laeran.pl>
--
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
with Ada.Strings; use Ada.Strings;
with Ada.Strings.Fixed; use Ada.Strings.Fixed;
with Interfaces.C;
with GNAT.Directory_Operations; use GNAT.Directory_Operations;
with CArgv;
with Tcl; use Tcl;
with Tcl.Ada; use Tcl.Ada;
with Tcl.Tk.Ada; use Tcl.Tk.Ada;
with Tcl.Tk.Ada.Widgets; use Tcl.Tk.Ada.Widgets;
with Tcl.Tk.Ada.Widgets.TtkButton; use Tcl.Tk.Ada.Widgets.TtkButton;
with Tcl.Tk.Ada.Widgets.TtkFrame; use Tcl.Tk.Ada.Widgets.TtkFrame;
with Tcl.Tk.Ada.Widgets.TtkLabel; use Tcl.Tk.Ada.Widgets.TtkLabel;
with Tcl.Tk.Ada.Widgets.TtkTreeView; use Tcl.Tk.Ada.Widgets.TtkTreeView;
with Tcl.Tklib.Ada.Tooltip; use Tcl.Tklib.Ada.Tooltip;
with Config; use Config;
with Game; use Game;
with Utils; use Utils;
with Utils.UI; use Utils.UI;
package body Goals.UI is
-- ****o* GUI/GUI.Show_Goals_Command
-- FUNCTION
-- Show goals UI to the player
-- PARAMETERS
-- ClientData - Custom data send to the command. Unused
-- Interp - Tcl interpreter in which command was executed.
-- Argc - Number of arguments passed to the command. Unused
-- Argv - Values of arguments passed to the command.
-- RESULT
-- This function always return TCL_OK
-- COMMANDS
-- ShowGoals buttonpath
-- Buttonpath is path to the button which is used to set the goal
-- SOURCE
function Show_Goals_Command
(ClientData: Integer; Interp: Tcl.Tcl_Interp; Argc: Interfaces.C.int;
Argv: CArgv.Chars_Ptr_Ptr) return Interfaces.C.int with
Convention => C;
-- ****
function Show_Goals_Command
(ClientData: Integer; Interp: Tcl.Tcl_Interp; Argc: Interfaces.C.int;
Argv: CArgv.Chars_Ptr_Ptr) return Interfaces.C.int is
pragma Unreferenced(ClientData, Argc);
Goals_Dialog: constant Ttk_Frame := Get_Widget(".goalsdialog", Interp);
GoalsView: constant Ttk_Tree_View :=
Get_Widget(Goals_Dialog & ".view", Interp);
SelectButton: constant Ttk_Button :=
Get_Widget(Goals_Dialog & ".selectbutton", Interp);
Dialog_Header: constant Ttk_Label :=
Get_Widget(Goals_Dialog & ".header", Interp);
begin
Tcl_EvalFile
(Interp,
To_String(Data_Directory) & "ui" & Dir_Separator & "goals.tcl");
Load_Goals_Loop :
for I in Goals_List.Iterate loop
Insert
(GoalsView,
GoalTypes'Image(Goals_List(I).GType) & " end -id {" &
Trim(Positive'Image(Goals_Container.To_Index(I)), Left) &
"} -text {" & GoalText(Goals_Container.To_Index(I)) & "}");
end loop Load_Goals_Loop;
configure(SelectButton, "-command {SetGoal " & CArgv.Arg(Argv, 1) & "}");
Bind
(Dialog_Header,
"<ButtonPress-" & (if Game_Settings.Right_Button then "3" else "1") &
">",
"{SetMousePosition " & Dialog_Header & " %X %Y}");
Bind
(Dialog_Header, "<Motion>", "{MoveDialog " & Goals_Dialog & " %X %Y}");
Bind
(Dialog_Header,
"<ButtonRelease-" &
(if Game_Settings.Right_Button then "3" else "1") & ">",
"{SetMousePosition " & Dialog_Header & " 0 0}");
return TCL_OK;
end Show_Goals_Command;
-- ****o* GUI/GUI.Set_Goal_Command
-- FUNCTION
-- Set selected goal as a current goal
-- PARAMETERS
-- ClientData - Custom data send to the command. Unused
-- Interp - Tcl interpreter in which command was executed.
-- Argc - Number of arguments passed to the command. Unused
-- Argv - Values of arguments passed to the command.
-- RESULT
-- This function always return TCL_OK
-- COMMANDS
-- SetGoal buttonpath
-- Buttonpath is path to the button which is used to set the goal
-- SOURCE
function Set_Goal_Command
(ClientData: Integer; Interp: Tcl.Tcl_Interp; Argc: Interfaces.C.int;
Argv: CArgv.Chars_Ptr_Ptr) return Interfaces.C.int with
Convention => C;
-- ****
function Set_Goal_Command
(ClientData: Integer; Interp: Tcl.Tcl_Interp; Argc: Interfaces.C.int;
Argv: CArgv.Chars_Ptr_Ptr) return Interfaces.C.int is
pragma Unreferenced(ClientData, Argc);
GoalsView: constant Ttk_Tree_View :=
Get_Widget(".goalsdialog.view", Interp);
SelectedGoal: Natural;
ButtonName: constant String := CArgv.Arg(Argv, 1);
GoalButton: constant Ttk_Button := Get_Widget(ButtonName, Interp);
ButtonText: Unbounded_String;
begin
SelectedGoal := Natural'Value(Selection(GoalsView));
ClearCurrentGoal;
if SelectedGoal > 0 then
CurrentGoal := Goals_List(SelectedGoal);
elsif Index(ButtonName, "newgamemenu") = 0 then
CurrentGoal :=
Goals_List
(Get_Random(Goals_List.First_Index, Goals_List.Last_Index));
end if;
if SelectedGoal > 0 then
ButtonText := To_Unbounded_String(GoalText(SelectedGoal));
Add(GoalButton, To_String(ButtonText));
if Length(ButtonText) > 16 then
ButtonText := Unbounded_Slice(ButtonText, 1, 17) & "...";
end if;
configure(GoalButton, "-text {" & To_String(ButtonText) & "}");
else
configure(GoalButton, "-text {Random}");
end if;
Tcl_Eval(Interp, ".goalsdialog.closebutton invoke");
return TCL_OK;
end Set_Goal_Command;
procedure AddCommands is
begin
Add_Command("ShowGoals", Show_Goals_Command'Access);
Add_Command("SetGoal", Set_Goal_Command'Access);
end AddCommands;
end Goals.UI;
|
-- SPDX-FileCopyrightText: 2019 Max Reznik <reznikmm@gmail.com>
--
-- SPDX-License-Identifier: MIT
-------------------------------------------------------------
with Program.Scanner_Destinations;
package body Program.Scanners is
type First_Stage_Index is mod 16#1100#;
type Second_Stage_Index is mod 16#100#;
generic
type Element_Type is private;
type Second_Stage_Array is
array (Second_Stage_Index) of Element_Type;
type Second_Stage_Array_Access is
not null access constant Second_Stage_Array;
type First_Stage_Array is
array (First_Stage_Index) of Second_Stage_Array_Access;
function Generic_Element (Data : First_Stage_Array; Code : Natural)
return Element_Type;
---------------------
-- Generic_Element --
---------------------
function Generic_Element
(Data : First_Stage_Array;
Code : Natural) return Element_Type is
begin
return Data (First_Stage_Index (Code / Second_Stage_Index'Modulus))
(Second_Stage_Index (Code mod Second_Stage_Index'Modulus));
end Generic_Element;
package body Tables is separate;
procedure On_Accept
(Self : not null access Program.Scanned_Rule_Handlers.Handler'Class;
Scanner : not null access Program.Scanners.Scanner'Class;
Rule : Program.Scanner_States.Rule_Index;
Token : out Program.Lexical_Elements.Lexical_Element_Kind;
Skip : in out Boolean);
----------------
-- Get_Source --
----------------
function Get_Source (Self : Scanner'Class)
return not null Program.Source_Buffers.Source_Buffer_Access is
begin
return Self.Source;
end Get_Source;
--------------
-- Get_Span --
--------------
function Get_Span
(Self : Scanner'Class) return Program.Source_Buffers.Span is
begin
return (Self.From, Self.To);
end Get_Span;
-------------------------
-- Get_Start_Condition --
-------------------------
function Get_Start_Condition
(Self : Scanner'Class)
return Start_Condition
is
begin
return Self.Start;
end Get_Start_Condition;
---------------
-- Get_Token --
---------------
procedure Get_Token
(Self : access Scanner'Class;
Value : out Program.Lexical_Elements.Lexical_Element_Kind)
is
procedure Next;
procedure Next is
begin
Self.Offset :=
Self.Offset + Positive (Self.Classes (Self.Next).Length);
if Self.Next = Self.Classes'Last then
Self.Next := 1;
else
Self.Next := Self.Next + 1;
end if;
end Next;
use type Program.Scanner_States.Character_Class;
Current_State : Program.Scanner_States.State;
Char : Program.Scanner_States.Character_Class;
Skip : Boolean := True;
Valid_Rule : Program.Scanner_States.Rule_Index;
Valid_Next : Buffer_Index;
Valid_From : Positive;
Valid_To : Positive; -- Offset for Valid_Next
begin
if Self.EOF = Self.Next then
Value := Program.Lexical_Elements.End_Of_Input;
return;
end if;
loop
Current_State := Self.Start;
Valid_Rule := 0;
Valid_From := Self.Offset; -- Begin of any token
Valid_Next := Self.Next;
Valid_To := Self.Offset; -- End of token in case of Error
loop
Char := Self.Classes (Self.Next).Class;
if Char /= Error_Character then
Current_State := Tables.Switch (Current_State, Char);
if Current_State not in Scanner_States.Looping_State then
if Current_State in Scanner_States.Final_State then
Valid_Rule := Tables.Rule (Current_State);
Valid_Next := Self.Next;
Valid_To := Self.Offset;
end if;
exit;
elsif Current_State in Scanner_States.Final_State then
Valid_Rule := Tables.Rule (Current_State);
Valid_Next := Self.Next;
Valid_To := Self.Offset;
end if;
Next;
elsif Self.Classes (Self.Next).Length = End_Of_Buffer then
Self.Read_Buffer;
if Self.EOF = Self.Next then
if Valid_Next = Self.Next then
Value := Program.Lexical_Elements.End_Of_Input;
return;
else
exit;
end if;
end if;
else
exit;
end if;
end loop;
Self.Next := Valid_Next;
Self.Offset := Valid_To;
Self.From := Valid_From;
Self.To := Valid_To;
Next;
if Valid_Rule in 0 then
Value := Program.Lexical_Elements.Error;
return;
else
On_Accept (Self.Handler, Self, Valid_Rule, Value, Skip);
if not Skip then
return;
end if;
end if;
end loop;
end Get_Token;
procedure On_Accept
(Self : not null access Program.Scanned_Rule_Handlers.Handler'Class;
Scanner : not null access Program.Scanners.Scanner'Class;
Rule : Program.Scanner_States.Rule_Index;
Token : out Program.Lexical_Elements.Lexical_Element_Kind;
Skip : in out Boolean) is separate;
-----------------
-- Read_Buffer --
-----------------
procedure Read_Buffer (Self : in out Scanner'Class) is
Last : Natural := Buffer_Half_Size;
begin
if Self.Next > Buffer_Half_Size then
Last := Buffer_Index'Last;
end if;
Self.Source.Read (Self.Classes (Self.Next .. Last), Last);
if Last < Self.Next then
Self.EOF := Self.Next;
return;
elsif Last = Buffer_Index'Last then
Last := 1;
else
Last := Last + 1;
end if;
Self.Classes (Last) :=
(Class => Error_Character, Length => End_Of_Buffer);
end Read_Buffer;
-----------------
-- Set_Handler --
-----------------
procedure Set_Handler
(Self : in out Scanner'Class;
Handler : not null Program.Scanned_Rule_Handlers.Handler_Access) is
begin
Self.Handler := Handler;
end Set_Handler;
----------------
-- Set_Source --
----------------
procedure Set_Source
(Self : in out Scanner'Class;
Source : not null Program.Source_Buffers.Source_Buffer_Access)
is
begin
Self.Source := Source;
Self.Source.Rewind;
end Set_Source;
-------------------------
-- Set_Start_Condition --
-------------------------
procedure Set_Start_Condition
(Self : in out Scanner'Class;
Condition : Start_Condition)
is
begin
Self.Start := Condition;
end Set_Start_Condition;
end Program.Scanners;
|
pragma Ada_2012;
with Ada.Strings.UTF_Encoding.Wide_Wide_Strings, Ada.Strings.UTF_Encoding;
use Ada.Strings.UTF_Encoding.Wide_Wide_Strings;
with Ada.Strings;
package body Encoding is
------------
-- Encode --
------------
function Encode (Text : String) return Wide_Wide_String is
Text_String : constant Ada.Strings.UTF_Encoding.UTF_8_String := Text;
begin
return Decode (Text_String);
end Encode;
end Encoding;
|
-- POK header
--
-- The following file is a part of the POK project. Any modification should
-- be made according to the POK licence. You CANNOT use this file or a part
-- of a file for your own project.
--
-- For more information on the POK licence, please see our LICENCE FILE
--
-- Please follow the coding guidelines described in doc/CODING_GUIDELINES
--
-- Copyright (c) 2007-2020 POK team
-- ---------------------------------------------------------------------------
-- --
-- SEMAPHORE constant and type definitions and management services --
-- --
-- ---------------------------------------------------------------------------
with APEX.Processes;
package APEX.Semaphores is
Max_Number_Of_Semaphores : constant := System_Limit_Number_Of_Semaphores;
Max_Semaphore_Value : constant := 32_767;
subtype Semaphore_Name_Type is Name_Type;
type Semaphore_Id_Type is private;
Null_Semaphore_Id : constant Semaphore_Id_Type;
type Semaphore_Value_Type is new APEX_Integer range
0 .. Max_Semaphore_Value;
type Semaphore_Status_Type is record
Current_Value : Semaphore_Value_Type;
Maximum_Value : Semaphore_Value_Type;
Waiting_Processes : APEX.Processes.Waiting_Range_Type;
end record;
procedure Create_Semaphore
(Semaphore_Name : in Semaphore_Name_Type;
Current_Value : in Semaphore_Value_Type;
Maximum_Value : in Semaphore_Value_Type;
Queuing_Discipline : in Queuing_Discipline_Type;
Semaphore_Id : out Semaphore_Id_Type;
Return_Code : out Return_Code_Type);
procedure Wait_Semaphore
(Semaphore_Id : in Semaphore_Id_Type;
Time_Out : in System_Time_Type;
Return_Code : out Return_Code_Type);
procedure Signal_Semaphore
(Semaphore_Id : in Semaphore_Id_Type;
Return_Code : out Return_Code_Type);
procedure Get_Semaphore_Id
(Semaphore_Name : in Semaphore_Name_Type;
Semaphore_Id : out Semaphore_Id_Type;
Return_Code : out Return_Code_Type);
procedure Get_Semaphore_Status
(Semaphore_Id : in Semaphore_Id_Type;
Semaphore_Status : out Semaphore_Status_Type;
Return_Code : out Return_Code_Type);
private
type Semaphore_Id_Type is new APEX_Integer;
Null_Semaphore_Id : constant Semaphore_Id_Type := 0;
pragma Convention (C, Semaphore_Status_Type);
-- POK BINDINGS
pragma Import (C, Create_Semaphore, "CREATE_SEMAPHORE");
pragma Import (C, Wait_Semaphore, "WAIT_SEMAPHORE");
pragma Import (C, Signal_Semaphore, "SIGNAL_SEMAPHORE");
pragma Import (C, Get_Semaphore_Id, "GET_SEMAPHORE_ID");
pragma Import (C, Get_Semaphore_Status, "GET_SEMAPHORE_STATUS");
-- END OF POK BINDINGS
end APEX.Semaphores;
|
------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- G H O S T --
-- --
-- B o d y --
-- --
-- Copyright (C) 2014-2016, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
-- for more details. You should have received a copy of the GNU General --
-- Public License distributed with GNAT; see file COPYING3. If not, go to --
-- http://www.gnu.org/licenses for a complete copy of the license. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
with Alloc; use Alloc;
with Aspects; use Aspects;
with Atree; use Atree;
with Einfo; use Einfo;
with Elists; use Elists;
with Errout; use Errout;
with Lib; use Lib;
with Namet; use Namet;
with Nlists; use Nlists;
with Nmake; use Nmake;
with Sem; use Sem;
with Sem_Aux; use Sem_Aux;
with Sem_Disp; use Sem_Disp;
with Sem_Eval; use Sem_Eval;
with Sem_Prag; use Sem_Prag;
with Sem_Res; use Sem_Res;
with Sem_Util; use Sem_Util;
with Sinfo; use Sinfo;
with Snames; use Snames;
with Table;
package body Ghost is
-- The following table contains the N_Compilation_Unit node for a unit that
-- is either subject to pragma Ghost with policy Ignore or contains ignored
-- Ghost code. The table is used in the removal of ignored Ghost code from
-- units.
package Ignored_Ghost_Units is new Table.Table (
Table_Component_Type => Node_Id,
Table_Index_Type => Int,
Table_Low_Bound => 0,
Table_Initial => Alloc.Ignored_Ghost_Units_Initial,
Table_Increment => Alloc.Ignored_Ghost_Units_Increment,
Table_Name => "Ignored_Ghost_Units");
-----------------------
-- Local Subprograms --
-----------------------
function Ghost_Entity (N : Node_Id) return Entity_Id;
-- Find the entity of a reference to a Ghost entity. Return Empty if there
-- is no such entity.
procedure Install_Ghost_Mode (Mode : Name_Id);
-- Install a specific Ghost mode denoted by Mode by setting global variable
-- Ghost_Mode.
function Is_Subject_To_Ghost (N : Node_Id) return Boolean;
-- Determine whether declaration or body N is subject to aspect or pragma
-- Ghost. This routine must be used in cases where pragma Ghost has not
-- been analyzed yet, but the context needs to establish the "ghostness"
-- of N.
procedure Mark_Ghost_Declaration_Or_Body
(N : Node_Id;
Mode : Name_Id);
-- Mark the defining entity of declaration or body N as Ghost depending on
-- mode Mode. Mark all formals parameters when N denotes a subprogram or a
-- body.
procedure Propagate_Ignored_Ghost_Code (N : Node_Id);
-- Signal all enclosing scopes that they now contain at least one ignored
-- Ghost node denoted by N. Add the compilation unit containing N to table
-- Ignored_Ghost_Units for post processing.
----------------------------
-- Add_Ignored_Ghost_Unit --
----------------------------
procedure Add_Ignored_Ghost_Unit (Unit : Node_Id) is
begin
pragma Assert (Nkind (Unit) = N_Compilation_Unit);
-- Avoid duplicates in the table as pruning the same unit more than once
-- is wasteful. Since ignored Ghost code tends to be grouped up, check
-- the contents of the table in reverse.
for Index in reverse Ignored_Ghost_Units.First ..
Ignored_Ghost_Units.Last
loop
-- If the unit is already present in the table, do not add it again
if Unit = Ignored_Ghost_Units.Table (Index) then
return;
end if;
end loop;
-- If we get here, then this is the first time the unit is being added
Ignored_Ghost_Units.Append (Unit);
end Add_Ignored_Ghost_Unit;
----------------------------
-- Check_Ghost_Completion --
----------------------------
procedure Check_Ghost_Completion
(Prev_Id : Entity_Id;
Compl_Id : Entity_Id)
is
Policy : constant Name_Id := Policy_In_Effect (Name_Ghost);
begin
-- Nothing to do if one of the views is missing
if No (Prev_Id) or else No (Compl_Id) then
null;
-- The Ghost policy in effect at the point of declaration and at the
-- point of completion must match (SPARK RM 6.9(14)).
elsif Is_Checked_Ghost_Entity (Prev_Id)
and then Policy = Name_Ignore
then
Error_Msg_Sloc := Sloc (Compl_Id);
Error_Msg_N ("incompatible ghost policies in effect", Prev_Id);
Error_Msg_N ("\& declared with ghost policy `Check`", Prev_Id);
Error_Msg_N ("\& completed # with ghost policy `Ignore`", Prev_Id);
elsif Is_Ignored_Ghost_Entity (Prev_Id)
and then Policy = Name_Check
then
Error_Msg_Sloc := Sloc (Compl_Id);
Error_Msg_N ("incompatible ghost policies in effect", Prev_Id);
Error_Msg_N ("\& declared with ghost policy `Ignore`", Prev_Id);
Error_Msg_N ("\& completed # with ghost policy `Check`", Prev_Id);
end if;
end Check_Ghost_Completion;
-------------------------
-- Check_Ghost_Context --
-------------------------
procedure Check_Ghost_Context (Ghost_Id : Entity_Id; Ghost_Ref : Node_Id) is
procedure Check_Ghost_Policy (Id : Entity_Id; Ref : Node_Id);
-- Verify that the Ghost policy at the point of declaration of entity Id
-- matches the policy at the point of reference Ref. If this is not the
-- case emit an error at Ref.
function Is_OK_Ghost_Context (Context : Node_Id) return Boolean;
-- Determine whether node Context denotes a Ghost-friendly context where
-- a Ghost entity can safely reside (SPARK RM 6.9(10)).
-------------------------
-- Is_OK_Ghost_Context --
-------------------------
function Is_OK_Ghost_Context (Context : Node_Id) return Boolean is
function Is_OK_Declaration (Decl : Node_Id) return Boolean;
-- Determine whether node Decl is a suitable context for a reference
-- to a Ghost entity. To qualify as such, Decl must either
--
-- * Define a Ghost entity
--
-- * Be subject to pragma Ghost
function Is_OK_Pragma (Prag : Node_Id) return Boolean;
-- Determine whether node Prag is a suitable context for a reference
-- to a Ghost entity. To qualify as such, Prag must either
--
-- * Be an assertion expression pragma
--
-- * Denote pragma Global, Depends, Initializes, Refined_Global,
-- Refined_Depends or Refined_State.
--
-- * Specify an aspect of a Ghost entity
--
-- * Contain a reference to a Ghost entity
function Is_OK_Statement (Stmt : Node_Id) return Boolean;
-- Determine whether node Stmt is a suitable context for a reference
-- to a Ghost entity. To qualify as such, Stmt must either
--
-- * Denote a procedure call to a Ghost procedure
--
-- * Denote an assignment statement whose target is Ghost
-----------------------
-- Is_OK_Declaration --
-----------------------
function Is_OK_Declaration (Decl : Node_Id) return Boolean is
function In_Subprogram_Body_Profile (N : Node_Id) return Boolean;
-- Determine whether node N appears in the profile of a subprogram
-- body.
--------------------------------
-- In_Subprogram_Body_Profile --
--------------------------------
function In_Subprogram_Body_Profile (N : Node_Id) return Boolean is
Spec : constant Node_Id := Parent (N);
begin
-- The node appears in a parameter specification in which case
-- it is either the parameter type or the default expression or
-- the node appears as the result definition of a function.
return
(Nkind (N) = N_Parameter_Specification
or else
(Nkind (Spec) = N_Function_Specification
and then N = Result_Definition (Spec)))
and then Nkind (Parent (Spec)) = N_Subprogram_Body;
end In_Subprogram_Body_Profile;
-- Local variables
Subp_Decl : Node_Id;
Subp_Id : Entity_Id;
-- Start of processing for Is_OK_Declaration
begin
if Is_Ghost_Declaration (Decl) then
return True;
-- Special cases
-- A reference to a Ghost entity may appear within the profile of
-- a subprogram body. This context is treated as suitable because
-- it duplicates the context of the corresponding spec. The real
-- check was already performed during the analysis of the spec.
elsif In_Subprogram_Body_Profile (Decl) then
return True;
-- A reference to a Ghost entity may appear within an expression
-- function which is still being analyzed. This context is treated
-- as suitable because it is not yet known whether the expression
-- function is an initial declaration or a completion. The real
-- check is performed when the expression function is expanded.
elsif Nkind (Decl) = N_Expression_Function
and then not Analyzed (Decl)
then
return True;
-- References to Ghost entities may be relocated in internally
-- generated bodies.
elsif Nkind (Decl) = N_Subprogram_Body
and then not Comes_From_Source (Decl)
then
Subp_Id := Corresponding_Spec (Decl);
if Present (Subp_Id) then
-- The context is the internally built _Postconditions
-- procedure, which is OK because the real check was done
-- before expansion activities.
if Chars (Subp_Id) = Name_uPostconditions then
return True;
else
Subp_Decl :=
Original_Node (Unit_Declaration_Node (Subp_Id));
-- The original context is an expression function that
-- has been split into a spec and a body. The context is
-- OK as long as the initial declaration is Ghost.
if Nkind (Subp_Decl) = N_Expression_Function then
return Is_Ghost_Declaration (Subp_Decl);
end if;
end if;
-- Otherwise this is either an internal body or an internal
-- completion. Both are OK because the real check was done
-- before expansion activities.
else
return True;
end if;
end if;
return False;
end Is_OK_Declaration;
------------------
-- Is_OK_Pragma --
------------------
function Is_OK_Pragma (Prag : Node_Id) return Boolean is
procedure Check_Policies (Prag_Nam : Name_Id);
-- Verify that the Ghost policy in effect is the same as the
-- assertion policy for pragma name Prag_Nam. Emit an error if
-- this is not the case.
--------------------
-- Check_Policies --
--------------------
procedure Check_Policies (Prag_Nam : Name_Id) is
AP : constant Name_Id := Check_Kind (Prag_Nam);
GP : constant Name_Id := Policy_In_Effect (Name_Ghost);
begin
-- If the Ghost policy in effect at the point of a Ghost entity
-- reference is Ignore, then the assertion policy of the pragma
-- must be Ignore (SPARK RM 6.9(18)).
if GP = Name_Ignore and then AP /= Name_Ignore then
Error_Msg_N
("incompatible ghost policies in effect",
Ghost_Ref);
Error_Msg_NE
("\ghost entity & has policy `Ignore`",
Ghost_Ref, Ghost_Id);
Error_Msg_Name_1 := AP;
Error_Msg_N
("\assertion expression has policy %", Ghost_Ref);
end if;
end Check_Policies;
-- Local variables
Prag_Id : Pragma_Id;
Prag_Nam : Name_Id;
-- Start of processing for Is_OK_Pragma
begin
if Nkind (Prag) = N_Pragma then
Prag_Id := Get_Pragma_Id (Prag);
Prag_Nam := Original_Aspect_Pragma_Name (Prag);
-- A pragma that applies to a Ghost construct or specifies an
-- aspect of a Ghost entity is a Ghost pragma (SPARK RM 6.9(3))
if Is_Ghost_Pragma (Prag) then
return True;
-- An assertion expression pragma is Ghost when it contains a
-- reference to a Ghost entity (SPARK RM 6.9(10)).
elsif Assertion_Expression_Pragma (Prag_Id) then
-- Ensure that the assertion policy and the Ghost policy are
-- compatible (SPARK RM 6.9(18)).
Check_Policies (Prag_Nam);
return True;
-- Several pragmas that may apply to a non-Ghost entity are
-- treated as Ghost when they contain a reference to a Ghost
-- entity (SPARK RM 6.9(11)).
elsif Nam_In (Prag_Nam, Name_Global,
Name_Depends,
Name_Initializes,
Name_Refined_Global,
Name_Refined_Depends,
Name_Refined_State)
then
return True;
end if;
end if;
return False;
end Is_OK_Pragma;
---------------------
-- Is_OK_Statement --
---------------------
function Is_OK_Statement (Stmt : Node_Id) return Boolean is
begin
-- An assignment statement is Ghost when the target is a Ghost
-- entity.
if Nkind (Stmt) = N_Assignment_Statement then
return Is_Ghost_Assignment (Stmt);
-- A procedure call is Ghost when it calls a Ghost procedure
elsif Nkind (Stmt) = N_Procedure_Call_Statement then
return Is_Ghost_Procedure_Call (Stmt);
-- Special cases
-- An if statement is a suitable context for a Ghost entity if it
-- is the byproduct of assertion expression expansion. Note that
-- the assertion expression may not be related to a Ghost entity,
-- but it may still contain references to Ghost entities.
elsif Nkind (Stmt) = N_If_Statement
and then Nkind (Original_Node (Stmt)) = N_Pragma
and then Assertion_Expression_Pragma
(Get_Pragma_Id (Original_Node (Stmt)))
then
return True;
end if;
return False;
end Is_OK_Statement;
-- Local variables
Par : Node_Id;
-- Start of processing for Is_OK_Ghost_Context
begin
-- The context is Ghost when it appears within a Ghost package or
-- subprogram.
if Ghost_Mode > None then
return True;
-- A Ghost type may be referenced in a use_type clause
-- (SPARK RM 6.9.10).
elsif Present (Parent (Context))
and then Nkind (Parent (Context)) = N_Use_Type_Clause
then
return True;
-- Routine Expand_Record_Extension creates a parent subtype without
-- inserting it into the tree. There is no good way of recognizing
-- this special case as there is no parent. Try to approximate the
-- context.
elsif No (Parent (Context)) and then Is_Tagged_Type (Ghost_Id) then
return True;
-- Otherwise climb the parent chain looking for a suitable Ghost
-- context.
else
Par := Context;
while Present (Par) loop
if Is_Ignored_Ghost_Node (Par) then
return True;
-- A reference to a Ghost entity can appear within an aspect
-- specification (SPARK RM 6.9(10)).
elsif Nkind (Par) = N_Aspect_Specification then
return True;
elsif Is_OK_Declaration (Par) then
return True;
elsif Is_OK_Pragma (Par) then
return True;
elsif Is_OK_Statement (Par) then
return True;
-- Prevent the search from going too far
elsif Is_Body_Or_Package_Declaration (Par) then
exit;
end if;
Par := Parent (Par);
end loop;
-- The expansion of assertion expression pragmas and attribute Old
-- may cause a legal Ghost entity reference to become illegal due
-- to node relocation. Check the In_Assertion_Expr counter as last
-- resort to try and infer the original legal context.
if In_Assertion_Expr > 0 then
return True;
-- Otherwise the context is not suitable for a reference to a
-- Ghost entity.
else
return False;
end if;
end if;
end Is_OK_Ghost_Context;
------------------------
-- Check_Ghost_Policy --
------------------------
procedure Check_Ghost_Policy (Id : Entity_Id; Ref : Node_Id) is
Policy : constant Name_Id := Policy_In_Effect (Name_Ghost);
begin
-- The Ghost policy in effect a the point of declaration and at the
-- point of use must match (SPARK RM 6.9(13)).
if Is_Checked_Ghost_Entity (Id)
and then Policy = Name_Ignore
and then May_Be_Lvalue (Ref)
then
Error_Msg_Sloc := Sloc (Ref);
Error_Msg_N ("incompatible ghost policies in effect", Ref);
Error_Msg_NE ("\& declared with ghost policy `Check`", Ref, Id);
Error_Msg_NE ("\& used # with ghost policy `Ignore`", Ref, Id);
elsif Is_Ignored_Ghost_Entity (Id) and then Policy = Name_Check then
Error_Msg_Sloc := Sloc (Ref);
Error_Msg_N ("incompatible ghost policies in effect", Ref);
Error_Msg_NE ("\& declared with ghost policy `Ignore`", Ref, Id);
Error_Msg_NE ("\& used # with ghost policy `Check`", Ref, Id);
end if;
end Check_Ghost_Policy;
-- Start of processing for Check_Ghost_Context
begin
-- Once it has been established that the reference to the Ghost entity
-- is within a suitable context, ensure that the policy at the point of
-- declaration and at the point of use match.
if Is_OK_Ghost_Context (Ghost_Ref) then
Check_Ghost_Policy (Ghost_Id, Ghost_Ref);
-- Otherwise the Ghost entity appears in a non-Ghost context and affects
-- its behavior or value (SPARK RM 6.9(10,11)).
else
Error_Msg_N ("ghost entity cannot appear in this context", Ghost_Ref);
end if;
end Check_Ghost_Context;
----------------------------
-- Check_Ghost_Overriding --
----------------------------
procedure Check_Ghost_Overriding
(Subp : Entity_Id;
Overridden_Subp : Entity_Id)
is
Deriv_Typ : Entity_Id;
Over_Subp : Entity_Id;
begin
if Present (Subp) and then Present (Overridden_Subp) then
Over_Subp := Ultimate_Alias (Overridden_Subp);
Deriv_Typ := Find_Dispatching_Type (Subp);
-- A Ghost primitive of a non-Ghost type extension cannot override an
-- inherited non-Ghost primitive (SPARK RM 6.9(8)).
if Is_Ghost_Entity (Subp)
and then Present (Deriv_Typ)
and then not Is_Ghost_Entity (Deriv_Typ)
and then not Is_Ghost_Entity (Over_Subp)
and then not Is_Abstract_Subprogram (Over_Subp)
then
Error_Msg_N ("incompatible overriding in effect", Subp);
Error_Msg_Sloc := Sloc (Over_Subp);
Error_Msg_N ("\& declared # as non-ghost subprogram", Subp);
Error_Msg_Sloc := Sloc (Subp);
Error_Msg_N ("\overridden # with ghost subprogram", Subp);
end if;
-- A non-Ghost primitive of a type extension cannot override an
-- inherited Ghost primitive (SPARK RM 6.9(8)).
if Is_Ghost_Entity (Over_Subp)
and then not Is_Ghost_Entity (Subp)
and then not Is_Abstract_Subprogram (Subp)
then
Error_Msg_N ("incompatible overriding in effect", Subp);
Error_Msg_Sloc := Sloc (Over_Subp);
Error_Msg_N ("\& declared # as ghost subprogram", Subp);
Error_Msg_Sloc := Sloc (Subp);
Error_Msg_N ("\overridden # with non-ghost subprogram", Subp);
end if;
if Present (Deriv_Typ)
and then not Is_Ignored_Ghost_Entity (Deriv_Typ)
then
-- When a tagged type is either non-Ghost or checked Ghost and
-- one of its primitives overrides an inherited operation, the
-- overridden operation of the ancestor type must be ignored Ghost
-- if the primitive is ignored Ghost (SPARK RM 6.9(17)).
if Is_Ignored_Ghost_Entity (Subp) then
-- Both the parent subprogram and overriding subprogram are
-- ignored Ghost.
if Is_Ignored_Ghost_Entity (Over_Subp) then
null;
-- The parent subprogram carries policy Check
elsif Is_Checked_Ghost_Entity (Over_Subp) then
Error_Msg_N
("incompatible ghost policies in effect", Subp);
Error_Msg_Sloc := Sloc (Over_Subp);
Error_Msg_N
("\& declared # with ghost policy `Check`", Subp);
Error_Msg_Sloc := Sloc (Subp);
Error_Msg_N
("\overridden # with ghost policy `Ignore`", Subp);
-- The parent subprogram is non-Ghost
else
Error_Msg_N
("incompatible ghost policies in effect", Subp);
Error_Msg_Sloc := Sloc (Over_Subp);
Error_Msg_N ("\& declared # as non-ghost subprogram", Subp);
Error_Msg_Sloc := Sloc (Subp);
Error_Msg_N
("\overridden # with ghost policy `Ignore`", Subp);
end if;
-- When a tagged type is either non-Ghost or checked Ghost and
-- one of its primitives overrides an inherited operation, the
-- the primitive of the tagged type must be ignored Ghost if the
-- overridden operation is ignored Ghost (SPARK RM 6.9(17)).
elsif Is_Ignored_Ghost_Entity (Over_Subp) then
-- Both the parent subprogram and the overriding subprogram are
-- ignored Ghost.
if Is_Ignored_Ghost_Entity (Subp) then
null;
-- The overriding subprogram carries policy Check
elsif Is_Checked_Ghost_Entity (Subp) then
Error_Msg_N
("incompatible ghost policies in effect", Subp);
Error_Msg_Sloc := Sloc (Over_Subp);
Error_Msg_N
("\& declared # with ghost policy `Ignore`", Subp);
Error_Msg_Sloc := Sloc (Subp);
Error_Msg_N
("\overridden # with Ghost policy `Check`", Subp);
-- The overriding subprogram is non-Ghost
else
Error_Msg_N
("incompatible ghost policies in effect", Subp);
Error_Msg_Sloc := Sloc (Over_Subp);
Error_Msg_N
("\& declared # with ghost policy `Ignore`", Subp);
Error_Msg_Sloc := Sloc (Subp);
Error_Msg_N
("\overridden # with non-ghost subprogram", Subp);
end if;
end if;
end if;
end if;
end Check_Ghost_Overriding;
---------------------------
-- Check_Ghost_Primitive --
---------------------------
procedure Check_Ghost_Primitive (Prim : Entity_Id; Typ : Entity_Id) is
begin
-- The Ghost policy in effect at the point of declaration of a primitive
-- operation and a tagged type must match (SPARK RM 6.9(16)).
if Is_Tagged_Type (Typ) then
if Is_Checked_Ghost_Entity (Prim)
and then Is_Ignored_Ghost_Entity (Typ)
then
Error_Msg_N ("incompatible ghost policies in effect", Prim);
Error_Msg_Sloc := Sloc (Typ);
Error_Msg_NE
("\tagged type & declared # with ghost policy `Ignore`",
Prim, Typ);
Error_Msg_Sloc := Sloc (Prim);
Error_Msg_N
("\primitive subprogram & declared # with ghost policy `Check`",
Prim);
elsif Is_Ignored_Ghost_Entity (Prim)
and then Is_Checked_Ghost_Entity (Typ)
then
Error_Msg_N ("incompatible ghost policies in effect", Prim);
Error_Msg_Sloc := Sloc (Typ);
Error_Msg_NE
("\tagged type & declared # with ghost policy `Check`",
Prim, Typ);
Error_Msg_Sloc := Sloc (Prim);
Error_Msg_N
("\primitive subprogram & declared # with ghost policy `Ignore`",
Prim);
end if;
end if;
end Check_Ghost_Primitive;
----------------------------
-- Check_Ghost_Refinement --
----------------------------
procedure Check_Ghost_Refinement
(State : Node_Id;
State_Id : Entity_Id;
Constit : Node_Id;
Constit_Id : Entity_Id)
is
begin
if Is_Ghost_Entity (State_Id) then
if Is_Ghost_Entity (Constit_Id) then
-- The Ghost policy in effect at the point of abstract state
-- declaration and constituent must match (SPARK RM 6.9(15)).
if Is_Checked_Ghost_Entity (State_Id)
and then Is_Ignored_Ghost_Entity (Constit_Id)
then
Error_Msg_Sloc := Sloc (Constit);
SPARK_Msg_N ("incompatible ghost policies in effect", State);
SPARK_Msg_NE
("\abstract state & declared with ghost policy `Check`",
State, State_Id);
SPARK_Msg_NE
("\constituent & declared # with ghost policy `Ignore`",
State, Constit_Id);
elsif Is_Ignored_Ghost_Entity (State_Id)
and then Is_Checked_Ghost_Entity (Constit_Id)
then
Error_Msg_Sloc := Sloc (Constit);
SPARK_Msg_N ("incompatible ghost policies in effect", State);
SPARK_Msg_NE
("\abstract state & declared with ghost policy `Ignore`",
State, State_Id);
SPARK_Msg_NE
("\constituent & declared # with ghost policy `Check`",
State, Constit_Id);
end if;
-- A constituent of a Ghost abstract state must be a Ghost entity
-- (SPARK RM 7.2.2(12)).
else
SPARK_Msg_NE
("constituent of ghost state & must be ghost",
Constit, State_Id);
end if;
end if;
end Check_Ghost_Refinement;
------------------
-- Ghost_Entity --
------------------
function Ghost_Entity (N : Node_Id) return Entity_Id is
Ref : Node_Id;
begin
-- When the reference denotes a subcomponent, recover the related
-- object (SPARK RM 6.9(1)).
Ref := N;
while Nkind_In (Ref, N_Explicit_Dereference,
N_Indexed_Component,
N_Selected_Component,
N_Slice)
loop
Ref := Prefix (Ref);
end loop;
if Is_Entity_Name (Ref) then
return Entity (Ref);
else
return Empty;
end if;
end Ghost_Entity;
--------------------------------
-- Implements_Ghost_Interface --
--------------------------------
function Implements_Ghost_Interface (Typ : Entity_Id) return Boolean is
Iface_Elmt : Elmt_Id;
begin
-- Traverse the list of interfaces looking for a Ghost interface
if Is_Tagged_Type (Typ) and then Present (Interfaces (Typ)) then
Iface_Elmt := First_Elmt (Interfaces (Typ));
while Present (Iface_Elmt) loop
if Is_Ghost_Entity (Node (Iface_Elmt)) then
return True;
end if;
Next_Elmt (Iface_Elmt);
end loop;
end if;
return False;
end Implements_Ghost_Interface;
----------------
-- Initialize --
----------------
procedure Initialize is
begin
Ignored_Ghost_Units.Init;
end Initialize;
------------------------
-- Install_Ghost_Mode --
------------------------
procedure Install_Ghost_Mode (Mode : Ghost_Mode_Type) is
begin
Ghost_Mode := Mode;
end Install_Ghost_Mode;
procedure Install_Ghost_Mode (Mode : Name_Id) is
begin
if Mode = Name_Check then
Ghost_Mode := Check;
elsif Mode = Name_Ignore then
Ghost_Mode := Ignore;
elsif Mode = Name_None then
Ghost_Mode := None;
end if;
end Install_Ghost_Mode;
-------------------------
-- Is_Ghost_Assignment --
-------------------------
function Is_Ghost_Assignment (N : Node_Id) return Boolean is
Id : Entity_Id;
begin
-- An assignment statement is Ghost when its target denotes a Ghost
-- entity.
if Nkind (N) = N_Assignment_Statement then
Id := Ghost_Entity (Name (N));
return Present (Id) and then Is_Ghost_Entity (Id);
end if;
return False;
end Is_Ghost_Assignment;
--------------------------
-- Is_Ghost_Declaration --
--------------------------
function Is_Ghost_Declaration (N : Node_Id) return Boolean is
Id : Entity_Id;
begin
-- A declaration is Ghost when it elaborates a Ghost entity or is
-- subject to pragma Ghost.
if Is_Declaration (N) then
Id := Defining_Entity (N);
return Is_Ghost_Entity (Id) or else Is_Subject_To_Ghost (N);
end if;
return False;
end Is_Ghost_Declaration;
---------------------
-- Is_Ghost_Pragma --
---------------------
function Is_Ghost_Pragma (N : Node_Id) return Boolean is
begin
return Is_Checked_Ghost_Pragma (N) or else Is_Ignored_Ghost_Pragma (N);
end Is_Ghost_Pragma;
-----------------------------
-- Is_Ghost_Procedure_Call --
-----------------------------
function Is_Ghost_Procedure_Call (N : Node_Id) return Boolean is
Id : Entity_Id;
begin
-- A procedure call is Ghost when it invokes a Ghost procedure
if Nkind (N) = N_Procedure_Call_Statement then
Id := Ghost_Entity (Name (N));
return Present (Id) and then Is_Ghost_Entity (Id);
end if;
return False;
end Is_Ghost_Procedure_Call;
---------------------------
-- Is_Ignored_Ghost_Unit --
---------------------------
function Is_Ignored_Ghost_Unit (N : Node_Id) return Boolean is
begin
-- Inspect the original node of the unit in case removal of ignored
-- Ghost code has already taken place.
return
Nkind (N) = N_Compilation_Unit
and then Is_Ignored_Ghost_Entity
(Defining_Entity (Original_Node (Unit (N))));
end Is_Ignored_Ghost_Unit;
-------------------------
-- Is_Subject_To_Ghost --
-------------------------
function Is_Subject_To_Ghost (N : Node_Id) return Boolean is
function Enables_Ghostness (Arg : Node_Id) return Boolean;
-- Determine whether aspect or pragma argument Arg enables "ghostness"
-----------------------
-- Enables_Ghostness --
-----------------------
function Enables_Ghostness (Arg : Node_Id) return Boolean is
Expr : Node_Id;
begin
Expr := Arg;
if Nkind (Expr) = N_Pragma_Argument_Association then
Expr := Get_Pragma_Arg (Expr);
end if;
-- Determine whether the expression of the aspect or pragma is static
-- and denotes True.
if Present (Expr) then
Preanalyze_And_Resolve (Expr);
return
Is_OK_Static_Expression (Expr)
and then Is_True (Expr_Value (Expr));
-- Otherwise Ghost defaults to True
else
return True;
end if;
end Enables_Ghostness;
-- Local variables
Id : constant Entity_Id := Defining_Entity (N);
Asp : Node_Id;
Decl : Node_Id;
Prev_Id : Entity_Id;
-- Start of processing for Is_Subject_To_Ghost
begin
-- The related entity of the declaration has not been analyzed yet, do
-- not inspect its attributes.
if Ekind (Id) = E_Void then
null;
elsif Is_Ghost_Entity (Id) then
return True;
-- The completion of a type or a constant is not fully analyzed when the
-- reference to the Ghost entity is resolved. Because the completion is
-- not marked as Ghost yet, inspect the partial view.
elsif Is_Record_Type (Id)
or else Ekind (Id) = E_Constant
or else (Nkind (N) = N_Object_Declaration
and then Constant_Present (N))
then
Prev_Id := Incomplete_Or_Partial_View (Id);
if Present (Prev_Id) and then Is_Ghost_Entity (Prev_Id) then
return True;
end if;
end if;
-- Examine the aspect specifications (if any) looking for aspect Ghost
if Permits_Aspect_Specifications (N) then
Asp := First (Aspect_Specifications (N));
while Present (Asp) loop
if Chars (Identifier (Asp)) = Name_Ghost then
return Enables_Ghostness (Expression (Asp));
end if;
Next (Asp);
end loop;
end if;
Decl := Empty;
-- When the context is a [generic] package declaration, pragma Ghost
-- resides in the visible declarations.
if Nkind_In (N, N_Generic_Package_Declaration,
N_Package_Declaration)
then
Decl := First (Visible_Declarations (Specification (N)));
-- When the context is a package or a subprogram body, pragma Ghost
-- resides in the declarative part.
elsif Nkind_In (N, N_Package_Body, N_Subprogram_Body) then
Decl := First (Declarations (N));
-- Otherwise pragma Ghost appears in the declarations following N
elsif Is_List_Member (N) then
Decl := Next (N);
end if;
while Present (Decl) loop
if Nkind (Decl) = N_Pragma
and then Pragma_Name (Decl) = Name_Ghost
then
return
Enables_Ghostness (First (Pragma_Argument_Associations (Decl)));
-- A source construct ends the region where pragma Ghost may appear,
-- stop the traversal. Check the original node as source constructs
-- may be rewritten into something else by expansion.
elsif Comes_From_Source (Original_Node (Decl)) then
exit;
end if;
Next (Decl);
end loop;
return False;
end Is_Subject_To_Ghost;
----------
-- Lock --
----------
procedure Lock is
begin
Ignored_Ghost_Units.Locked := True;
Ignored_Ghost_Units.Release;
end Lock;
-----------------------------------
-- Mark_And_Set_Ghost_Assignment --
-----------------------------------
procedure Mark_And_Set_Ghost_Assignment
(N : Node_Id;
Mode : out Ghost_Mode_Type)
is
Id : Entity_Id;
begin
-- Save the previous Ghost mode in effect
Mode := Ghost_Mode;
-- An assignment statement becomes Ghost when its target denotes a Ghost
-- object. Install the Ghost mode of the target.
Id := Ghost_Entity (Name (N));
if Present (Id) then
if Is_Checked_Ghost_Entity (Id) then
Install_Ghost_Mode (Check);
elsif Is_Ignored_Ghost_Entity (Id) then
Install_Ghost_Mode (Ignore);
Set_Is_Ignored_Ghost_Node (N);
Propagate_Ignored_Ghost_Code (N);
end if;
end if;
end Mark_And_Set_Ghost_Assignment;
-----------------------------
-- Mark_And_Set_Ghost_Body --
-----------------------------
procedure Mark_And_Set_Ghost_Body
(N : Node_Id;
Spec_Id : Entity_Id;
Mode : out Ghost_Mode_Type)
is
Body_Id : constant Entity_Id := Defining_Entity (N);
Policy : Name_Id := No_Name;
begin
-- Save the previous Ghost mode in effect
Mode := Ghost_Mode;
-- A body becomes Ghost when it is subject to aspect or pragma Ghost
if Is_Subject_To_Ghost (N) then
Policy := Policy_In_Effect (Name_Ghost);
-- A body declared within a Ghost region is automatically Ghost
-- (SPARK RM 6.9(2)).
elsif Ghost_Mode = Check then
Policy := Name_Check;
elsif Ghost_Mode = Ignore then
Policy := Name_Ignore;
-- Inherit the "ghostness" of the previous declaration when the body
-- acts as a completion.
elsif Present (Spec_Id) then
if Is_Checked_Ghost_Entity (Spec_Id) then
Policy := Name_Check;
elsif Is_Ignored_Ghost_Entity (Spec_Id) then
Policy := Name_Ignore;
end if;
end if;
-- The Ghost policy in effect at the point of declaration and at the
-- point of completion must match (SPARK RM 6.9(14)).
Check_Ghost_Completion
(Prev_Id => Spec_Id,
Compl_Id => Body_Id);
-- Mark the body as its formals as Ghost
Mark_Ghost_Declaration_Or_Body (N, Policy);
-- Install the appropriate Ghost mode
Install_Ghost_Mode (Policy);
end Mark_And_Set_Ghost_Body;
-----------------------------------
-- Mark_And_Set_Ghost_Completion --
-----------------------------------
procedure Mark_And_Set_Ghost_Completion
(N : Node_Id;
Prev_Id : Entity_Id;
Mode : out Ghost_Mode_Type)
is
Compl_Id : constant Entity_Id := Defining_Entity (N);
Policy : Name_Id := No_Name;
begin
-- Save the previous Ghost mode in effect
Mode := Ghost_Mode;
-- A completion elaborated in a Ghost region is automatically Ghost
-- (SPARK RM 6.9(2)).
if Ghost_Mode = Check then
Policy := Name_Check;
elsif Ghost_Mode = Ignore then
Policy := Name_Ignore;
-- The completion becomes Ghost when its initial declaration is also
-- Ghost.
elsif Is_Checked_Ghost_Entity (Prev_Id) then
Policy := Name_Check;
elsif Is_Ignored_Ghost_Entity (Prev_Id) then
Policy := Name_Ignore;
end if;
-- The Ghost policy in effect at the point of declaration and at the
-- point of completion must match (SPARK RM 6.9(14)).
Check_Ghost_Completion
(Prev_Id => Prev_Id,
Compl_Id => Compl_Id);
-- Mark the completion as Ghost
Mark_Ghost_Declaration_Or_Body (N, Policy);
-- Install the appropriate Ghost mode
Install_Ghost_Mode (Policy);
end Mark_And_Set_Ghost_Completion;
------------------------------------
-- Mark_And_Set_Ghost_Declaration --
------------------------------------
procedure Mark_And_Set_Ghost_Declaration
(N : Node_Id;
Mode : out Ghost_Mode_Type)
is
Par_Id : Entity_Id;
Policy : Name_Id := No_Name;
begin
-- Save the previous Ghost mode in effect
Mode := Ghost_Mode;
-- A declaration becomes Ghost when it is subject to aspect or pragma
-- Ghost.
if Is_Subject_To_Ghost (N) then
Policy := Policy_In_Effect (Name_Ghost);
-- A declaration elaborated in a Ghost region is automatically Ghost
-- (SPARK RM 6.9(2)).
elsif Ghost_Mode = Check then
Policy := Name_Check;
elsif Ghost_Mode = Ignore then
Policy := Name_Ignore;
-- A child package or subprogram declaration becomes Ghost when its
-- parent is Ghost (SPARK RM 6.9(2)).
elsif Nkind_In (N, N_Generic_Function_Renaming_Declaration,
N_Generic_Package_Declaration,
N_Generic_Package_Renaming_Declaration,
N_Generic_Procedure_Renaming_Declaration,
N_Generic_Subprogram_Declaration,
N_Package_Declaration,
N_Package_Renaming_Declaration,
N_Subprogram_Declaration,
N_Subprogram_Renaming_Declaration)
and then Present (Parent_Spec (N))
then
Par_Id := Defining_Entity (Unit (Parent_Spec (N)));
if Is_Checked_Ghost_Entity (Par_Id) then
Policy := Name_Check;
elsif Is_Ignored_Ghost_Entity (Par_Id) then
Policy := Name_Ignore;
end if;
end if;
-- Mark the declaration and its formals as Ghost
Mark_Ghost_Declaration_Or_Body (N, Policy);
-- Install the appropriate Ghost mode
Install_Ghost_Mode (Policy);
end Mark_And_Set_Ghost_Declaration;
--------------------------------------
-- Mark_And_Set_Ghost_Instantiation --
--------------------------------------
procedure Mark_And_Set_Ghost_Instantiation
(N : Node_Id;
Gen_Id : Entity_Id;
Mode : out Ghost_Mode_Type)
is
Policy : Name_Id := No_Name;
begin
-- Save the previous Ghost mode in effect
Mode := Ghost_Mode;
-- An instantiation becomes Ghost when it is subject to pragma Ghost
if Is_Subject_To_Ghost (N) then
Policy := Policy_In_Effect (Name_Ghost);
-- An instantiation declaration within a Ghost region is automatically
-- Ghost (SPARK RM 6.9(2)).
elsif Ghost_Mode = Check then
Policy := Name_Check;
elsif Ghost_Mode = Ignore then
Policy := Name_Ignore;
-- Inherit the "ghostness" of the generic unit
elsif Is_Checked_Ghost_Entity (Gen_Id) then
Policy := Name_Check;
elsif Is_Ignored_Ghost_Entity (Gen_Id) then
Policy := Name_Ignore;
end if;
-- Mark the instantiation as Ghost
Mark_Ghost_Declaration_Or_Body (N, Policy);
-- Install the appropriate Ghost mode
Install_Ghost_Mode (Policy);
end Mark_And_Set_Ghost_Instantiation;
---------------------------------------
-- Mark_And_Set_Ghost_Procedure_Call --
---------------------------------------
procedure Mark_And_Set_Ghost_Procedure_Call
(N : Node_Id;
Mode : out Ghost_Mode_Type)
is
Id : Entity_Id;
begin
-- Save the previous Ghost mode in effect
Mode := Ghost_Mode;
-- A procedure call becomes Ghost when the procedure being invoked is
-- Ghost. Install the Ghost mode of the procedure.
Id := Ghost_Entity (Name (N));
if Present (Id) then
if Is_Checked_Ghost_Entity (Id) then
Install_Ghost_Mode (Check);
elsif Is_Ignored_Ghost_Entity (Id) then
Install_Ghost_Mode (Ignore);
Set_Is_Ignored_Ghost_Node (N);
Propagate_Ignored_Ghost_Code (N);
end if;
end if;
end Mark_And_Set_Ghost_Procedure_Call;
------------------------------------
-- Mark_Ghost_Declaration_Or_Body --
------------------------------------
procedure Mark_Ghost_Declaration_Or_Body
(N : Node_Id;
Mode : Name_Id)
is
Id : constant Entity_Id := Defining_Entity (N);
Mark_Formals : Boolean := False;
Param : Node_Id;
Param_Id : Entity_Id;
begin
-- Mark the related node and its entity
if Mode = Name_Check then
Mark_Formals := True;
Set_Is_Checked_Ghost_Entity (Id);
elsif Mode = Name_Ignore then
Mark_Formals := True;
Set_Is_Ignored_Ghost_Entity (Id);
Set_Is_Ignored_Ghost_Node (N);
Propagate_Ignored_Ghost_Code (N);
end if;
-- Mark all formal parameters when the related node denotes a subprogram
-- or a body. The traversal is performed via the specification because
-- the related subprogram or body may be unanalyzed.
-- ??? could extra formal parameters cause a Ghost leak?
if Mark_Formals
and then Nkind_In (N, N_Abstract_Subprogram_Declaration,
N_Formal_Abstract_Subprogram_Declaration,
N_Formal_Concrete_Subprogram_Declaration,
N_Generic_Subprogram_Declaration,
N_Subprogram_Body,
N_Subprogram_Body_Stub,
N_Subprogram_Declaration,
N_Subprogram_Renaming_Declaration)
then
Param := First (Parameter_Specifications (Specification (N)));
while Present (Param) loop
Param_Id := Defining_Entity (Param);
if Mode = Name_Check then
Set_Is_Checked_Ghost_Entity (Param_Id);
elsif Mode = Name_Ignore then
Set_Is_Ignored_Ghost_Entity (Param_Id);
end if;
Next (Param);
end loop;
end if;
end Mark_Ghost_Declaration_Or_Body;
-----------------------
-- Mark_Ghost_Clause --
-----------------------
procedure Mark_Ghost_Clause (N : Node_Id) is
Nam : Node_Id := Empty;
begin
if Nkind (N) = N_Use_Package_Clause then
Nam := First (Names (N));
elsif Nkind (N) = N_Use_Type_Clause then
Nam := First (Subtype_Marks (N));
elsif Nkind (N) = N_With_Clause then
Nam := Name (N);
end if;
if Present (Nam)
and then Is_Entity_Name (Nam)
and then Present (Entity (Nam))
and then Is_Ignored_Ghost_Entity (Entity (Nam))
then
Set_Is_Ignored_Ghost_Node (N);
Propagate_Ignored_Ghost_Code (N);
end if;
end Mark_Ghost_Clause;
-----------------------
-- Mark_Ghost_Pragma --
-----------------------
procedure Mark_Ghost_Pragma
(N : Node_Id;
Id : Entity_Id)
is
begin
-- A pragma becomes Ghost when it encloses a Ghost entity or relates to
-- a Ghost entity.
if Is_Checked_Ghost_Entity (Id) then
Set_Is_Checked_Ghost_Pragma (N);
elsif Is_Ignored_Ghost_Entity (Id) then
Set_Is_Ignored_Ghost_Pragma (N);
Set_Is_Ignored_Ghost_Node (N);
Propagate_Ignored_Ghost_Code (N);
end if;
end Mark_Ghost_Pragma;
-------------------------
-- Mark_Ghost_Renaming --
-------------------------
procedure Mark_Ghost_Renaming
(N : Node_Id;
Id : Entity_Id)
is
Policy : Name_Id := No_Name;
begin
-- A renaming becomes Ghost when it renames a Ghost entity
if Is_Checked_Ghost_Entity (Id) then
Policy := Name_Check;
elsif Is_Ignored_Ghost_Entity (Id) then
Policy := Name_Ignore;
end if;
Mark_Ghost_Declaration_Or_Body (N, Policy);
end Mark_Ghost_Renaming;
----------------------------------
-- Propagate_Ignored_Ghost_Code --
----------------------------------
procedure Propagate_Ignored_Ghost_Code (N : Node_Id) is
Nod : Node_Id;
Scop : Entity_Id;
begin
-- Traverse the parent chain looking for blocks, packages, and
-- subprograms or their respective bodies.
Nod := Parent (N);
while Present (Nod) loop
Scop := Empty;
if Nkind (Nod) = N_Block_Statement
and then Present (Identifier (Nod))
then
Scop := Entity (Identifier (Nod));
elsif Nkind_In (Nod, N_Package_Body,
N_Package_Declaration,
N_Subprogram_Body,
N_Subprogram_Declaration)
then
Scop := Defining_Entity (Nod);
end if;
-- The current node denotes a scoping construct
if Present (Scop) then
-- Stop the traversal when the scope already contains ignored
-- Ghost code as all enclosing scopes have already been marked.
if Contains_Ignored_Ghost_Code (Scop) then
exit;
-- Otherwise mark this scope and keep climbing
else
Set_Contains_Ignored_Ghost_Code (Scop);
end if;
end if;
Nod := Parent (Nod);
end loop;
-- The unit containing the ignored Ghost code must be post processed
-- before invoking the back end.
Add_Ignored_Ghost_Unit (Cunit (Get_Code_Unit (N)));
end Propagate_Ignored_Ghost_Code;
-------------------------------
-- Remove_Ignored_Ghost_Code --
-------------------------------
procedure Remove_Ignored_Ghost_Code is
procedure Prune_Tree (Root : Node_Id);
-- Remove all code marked as ignored Ghost from the tree of denoted by
-- Root.
----------------
-- Prune_Tree --
----------------
procedure Prune_Tree (Root : Node_Id) is
procedure Prune (N : Node_Id);
-- Remove a given node from the tree by rewriting it into null
function Prune_Node (N : Node_Id) return Traverse_Result;
-- Determine whether node N denotes an ignored Ghost construct. If
-- this is the case, rewrite N as a null statement. See the body for
-- special cases.
-----------
-- Prune --
-----------
procedure Prune (N : Node_Id) is
begin
-- Destroy any aspects that may be associated with the node
if Permits_Aspect_Specifications (N) and then Has_Aspects (N) then
Remove_Aspects (N);
end if;
Rewrite (N, Make_Null_Statement (Sloc (N)));
end Prune;
----------------
-- Prune_Node --
----------------
function Prune_Node (N : Node_Id) return Traverse_Result is
Id : Entity_Id;
begin
-- Do not prune compilation unit nodes because many mechanisms
-- depend on their presence. Note that context items are still
-- being processed.
if Nkind (N) = N_Compilation_Unit then
return OK;
-- The node is either declared as ignored Ghost or is a byproduct
-- of expansion. Destroy it and stop the traversal on this branch.
elsif Is_Ignored_Ghost_Node (N) then
Prune (N);
return Skip;
-- Scoping constructs such as blocks, packages, subprograms and
-- bodies offer some flexibility with respect to pruning.
elsif Nkind_In (N, N_Block_Statement,
N_Package_Body,
N_Package_Declaration,
N_Subprogram_Body,
N_Subprogram_Declaration)
then
if Nkind (N) = N_Block_Statement then
Id := Entity (Identifier (N));
else
Id := Defining_Entity (N);
end if;
-- The scoping construct contains both living and ignored Ghost
-- code, let the traversal prune all relevant nodes.
if Contains_Ignored_Ghost_Code (Id) then
return OK;
-- Otherwise the construct contains only living code and should
-- not be pruned.
else
return Skip;
end if;
-- Otherwise keep searching for ignored Ghost nodes
else
return OK;
end if;
end Prune_Node;
procedure Prune_Nodes is new Traverse_Proc (Prune_Node);
-- Start of processing for Prune_Tree
begin
Prune_Nodes (Root);
end Prune_Tree;
-- Start of processing for Remove_Ignored_Ghost_Code
begin
for Index in Ignored_Ghost_Units.First .. Ignored_Ghost_Units.Last loop
Prune_Tree (Ignored_Ghost_Units.Table (Index));
end loop;
end Remove_Ignored_Ghost_Code;
------------------------
-- Restore_Ghost_Mode --
------------------------
procedure Restore_Ghost_Mode (Mode : Ghost_Mode_Type) is
begin
Ghost_Mode := Mode;
end Restore_Ghost_Mode;
--------------------
-- Set_Ghost_Mode --
--------------------
procedure Set_Ghost_Mode
(N : Node_Or_Entity_Id;
Mode : out Ghost_Mode_Type)
is
procedure Set_Ghost_Mode_From_Entity (Id : Entity_Id);
-- Install the Ghost mode of entity Id
--------------------------------
-- Set_Ghost_Mode_From_Entity --
--------------------------------
procedure Set_Ghost_Mode_From_Entity (Id : Entity_Id) is
begin
if Is_Checked_Ghost_Entity (Id) then
Install_Ghost_Mode (Check);
elsif Is_Ignored_Ghost_Entity (Id) then
Install_Ghost_Mode (Ignore);
else
Install_Ghost_Mode (None);
end if;
end Set_Ghost_Mode_From_Entity;
-- Local variables
Id : Entity_Id;
-- Start of processing for Set_Ghost_Mode
begin
-- Save the previous Ghost mode in effect
Mode := Ghost_Mode;
-- The Ghost mode of an assignment statement depends on the Ghost mode
-- of the target.
if Nkind (N) = N_Assignment_Statement then
Id := Ghost_Entity (Name (N));
if Present (Id) then
Set_Ghost_Mode_From_Entity (Id);
end if;
-- The Ghost mode of a body or a declaration depends on the Ghost mode
-- of its defining entity.
elsif Is_Body (N) or else Is_Declaration (N) then
Set_Ghost_Mode_From_Entity (Defining_Entity (N));
-- The Ghost mode of an entity depends on the entity itself
elsif Nkind (N) in N_Entity then
Set_Ghost_Mode_From_Entity (N);
-- The Ghost mode of a [generic] freeze node depends on the Ghost mode
-- of the entity being frozen.
elsif Nkind_In (N, N_Freeze_Entity, N_Freeze_Generic_Entity) then
Set_Ghost_Mode_From_Entity (Entity (N));
-- The Ghost mode of a pragma depends on the associated entity. The
-- property is encoded in the pragma itself.
elsif Nkind (N) = N_Pragma then
if Is_Checked_Ghost_Pragma (N) then
Install_Ghost_Mode (Check);
elsif Is_Ignored_Ghost_Pragma (N) then
Install_Ghost_Mode (Ignore);
else
Install_Ghost_Mode (None);
end if;
-- The Ghost mode of a procedure call depends on the Ghost mode of the
-- procedure being invoked.
elsif Nkind (N) = N_Procedure_Call_Statement then
Id := Ghost_Entity (Name (N));
if Present (Id) then
Set_Ghost_Mode_From_Entity (Id);
end if;
end if;
end Set_Ghost_Mode;
-------------------------
-- Set_Is_Ghost_Entity --
-------------------------
procedure Set_Is_Ghost_Entity (Id : Entity_Id) is
Policy : constant Name_Id := Policy_In_Effect (Name_Ghost);
begin
if Policy = Name_Check then
Set_Is_Checked_Ghost_Entity (Id);
elsif Policy = Name_Ignore then
Set_Is_Ignored_Ghost_Entity (Id);
end if;
end Set_Is_Ghost_Entity;
end Ghost;
|
-- This spec has been automatically generated from STM32L5x2.svd
pragma Restrictions (No_Elaboration_Code);
pragma Ada_2012;
pragma Style_Checks (Off);
with HAL;
with System;
package STM32_SVD.COMP is
pragma Preelaborate;
---------------
-- Registers --
---------------
subtype COMP1_CSR_COMP1_PWRMODE_Field is HAL.UInt2;
subtype COMP1_CSR_COMP1_INMSEL_Field is HAL.UInt3;
subtype COMP1_CSR_COMP1_HYST_Field is HAL.UInt2;
subtype COMP1_CSR_COMP1_BLANKING_Field is HAL.UInt3;
-- Comparator 1 control and status register
type COMP1_CSR_Register is record
-- Comparator 1 enable bit
COMP1_EN : Boolean := False;
-- unspecified
Reserved_1_1 : HAL.Bit := 16#0#;
-- Power Mode of the comparator 1
COMP1_PWRMODE : COMP1_CSR_COMP1_PWRMODE_Field := 16#0#;
-- Comparator 1 Input Minus connection configuration bit
COMP1_INMSEL : COMP1_CSR_COMP1_INMSEL_Field := 16#0#;
-- Comparator1 input plus selection bit
COMP1_INPSEL : Boolean := False;
-- unspecified
Reserved_8_14 : HAL.UInt7 := 16#0#;
-- Comparator 1 polarity selection bit
COMP1_POLARITY : Boolean := False;
-- Comparator 1 hysteresis selection bits
COMP1_HYST : COMP1_CSR_COMP1_HYST_Field := 16#0#;
-- Comparator 1 blanking source selection bits
COMP1_BLANKING : COMP1_CSR_COMP1_BLANKING_Field := 16#0#;
-- unspecified
Reserved_21_21 : HAL.Bit := 16#0#;
-- Scaler bridge enable
COMP1_BRGEN : Boolean := False;
-- Voltage scaler enable bit
COMP1_SCALEN : Boolean := False;
-- unspecified
Reserved_24_29 : HAL.UInt6 := 16#0#;
-- Read-only. Comparator 1 output status bit
COMP1_VALUE : Boolean := False;
-- Write-only. COMP1_CSR register lock bit
COMP1_LOCK : Boolean := False;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for COMP1_CSR_Register use record
COMP1_EN at 0 range 0 .. 0;
Reserved_1_1 at 0 range 1 .. 1;
COMP1_PWRMODE at 0 range 2 .. 3;
COMP1_INMSEL at 0 range 4 .. 6;
COMP1_INPSEL at 0 range 7 .. 7;
Reserved_8_14 at 0 range 8 .. 14;
COMP1_POLARITY at 0 range 15 .. 15;
COMP1_HYST at 0 range 16 .. 17;
COMP1_BLANKING at 0 range 18 .. 20;
Reserved_21_21 at 0 range 21 .. 21;
COMP1_BRGEN at 0 range 22 .. 22;
COMP1_SCALEN at 0 range 23 .. 23;
Reserved_24_29 at 0 range 24 .. 29;
COMP1_VALUE at 0 range 30 .. 30;
COMP1_LOCK at 0 range 31 .. 31;
end record;
subtype COMP2_CSR_COMP2_PWRMODE_Field is HAL.UInt2;
subtype COMP2_CSR_COMP2_INMSEL_Field is HAL.UInt3;
subtype COMP2_CSR_COMP2_HYST_Field is HAL.UInt2;
subtype COMP2_CSR_COMP2_BLANKING_Field is HAL.UInt3;
-- Comparator 2 control and status register
type COMP2_CSR_Register is record
-- Comparator 2 enable bit
COMP2_EN : Boolean := False;
-- unspecified
Reserved_1_1 : HAL.Bit := 16#0#;
-- Power Mode of the comparator 2
COMP2_PWRMODE : COMP2_CSR_COMP2_PWRMODE_Field := 16#0#;
-- Comparator 2 Input Minus connection configuration bit
COMP2_INMSEL : COMP2_CSR_COMP2_INMSEL_Field := 16#0#;
-- Comparator 2 Input Plus connection configuration bit
COMP2_INPSEL : Boolean := False;
-- unspecified
Reserved_8_8 : HAL.Bit := 16#0#;
-- Windows mode selection bit
COMP2_WINMODE : Boolean := False;
-- unspecified
Reserved_10_14 : HAL.UInt5 := 16#0#;
-- Comparator 2 polarity selection bit
COMP2_POLARITY : Boolean := False;
-- Comparator 2 hysteresis selection bits
COMP2_HYST : COMP2_CSR_COMP2_HYST_Field := 16#0#;
-- Comparator 2 blanking source selection bits
COMP2_BLANKING : COMP2_CSR_COMP2_BLANKING_Field := 16#0#;
-- unspecified
Reserved_21_21 : HAL.Bit := 16#0#;
-- Scaler bridge enable
COMP2_BRGEN : Boolean := False;
-- Voltage scaler enable bit
COMP2_SCALEN : Boolean := False;
-- unspecified
Reserved_24_29 : HAL.UInt6 := 16#0#;
-- Read-only. Comparator 2 output status bit
COMP2_VALUE : Boolean := False;
-- Write-only. COMP2_CSR register lock bit
COMP2_LOCK : Boolean := False;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for COMP2_CSR_Register use record
COMP2_EN at 0 range 0 .. 0;
Reserved_1_1 at 0 range 1 .. 1;
COMP2_PWRMODE at 0 range 2 .. 3;
COMP2_INMSEL at 0 range 4 .. 6;
COMP2_INPSEL at 0 range 7 .. 7;
Reserved_8_8 at 0 range 8 .. 8;
COMP2_WINMODE at 0 range 9 .. 9;
Reserved_10_14 at 0 range 10 .. 14;
COMP2_POLARITY at 0 range 15 .. 15;
COMP2_HYST at 0 range 16 .. 17;
COMP2_BLANKING at 0 range 18 .. 20;
Reserved_21_21 at 0 range 21 .. 21;
COMP2_BRGEN at 0 range 22 .. 22;
COMP2_SCALEN at 0 range 23 .. 23;
Reserved_24_29 at 0 range 24 .. 29;
COMP2_VALUE at 0 range 30 .. 30;
COMP2_LOCK at 0 range 31 .. 31;
end record;
-----------------
-- Peripherals --
-----------------
-- Comparator
type COMP_Peripheral is record
-- Comparator 1 control and status register
COMP1_CSR : aliased COMP1_CSR_Register;
-- Comparator 2 control and status register
COMP2_CSR : aliased COMP2_CSR_Register;
end record
with Volatile;
for COMP_Peripheral use record
COMP1_CSR at 16#0# range 0 .. 31;
COMP2_CSR at 16#4# range 0 .. 31;
end record;
-- Comparator
COMP_Periph : aliased COMP_Peripheral
with Import, Address => System'To_Address (16#40010200#);
-- Comparator
SEC_COMP_Periph : aliased COMP_Peripheral
with Import, Address => System'To_Address (16#50010200#);
end STM32_SVD.COMP;
|
-- Práctica 4: César Borao Moratinos (Hash_Maps_G_Chaining.ads)
generic
type Key_Type is private;
type Value_Type is private;
with function "=" (K1, K2: Key_Type) return Boolean;
type Hash_Range is mod <>;
with function Hash (K: Key_Type) return Hash_Range;
Max: in Natural;
package Hash_Maps_G is
type Map is limited private;
Full_Map : exception;
procedure Get (M: Map;Key: in Key_Type;
Value: out Value_Type;
Success: out Boolean);
procedure Put (M: in out Map;
Key: Key_Type;
Value: Value_Type);
procedure Delete (M: in out Map;
Key: in Key_Type;
Success: out Boolean);
function Map_Length (M : Map) return Natural;
--
-- Cursor Interface for iterating over Map elements
--
type Cursor is limited private;
function First (M: Map) return Cursor;
procedure Next (C: in out Cursor);
function Has_Element (C: Cursor) return Boolean;
type Element_Type is record
Key: Key_Type;
Value: Value_Type;
end record;
No_Element: exception;
--Raises No_Element if Has_Element(C) = False;
function Element (C: Cursor) return Element_Type;
private
type Cell;
type Cell_A is access Cell;
type Cell is record
Key : Key_Type;
Value : Value_Type;
Next: Cell_A;
end record;
type Cell_Array is array (Hash_Range) of Cell_A;
type Cell_Array_A is access Cell_Array;
type Map is record
P_Array: Cell_Array_A;
Length : Natural := 0;
Counter: Natural := 0;
end record;
type Cursor is record
M: Map;
Position: Hash_Range;
Pointer : Cell_A;
end record;
end Hash_Maps_G;
|
generic
type T is private;
Obj : T;
package Layered_Abstraction_P is
Obj2 : T := Obj;
end;
|
------------------------------------------------------------------------------
-- --
-- GNAT RUN-TIME LIBRARY (GNARL) COMPONENTS --
-- --
-- S Y S T E M . B B . P R O T E C T I O N --
-- --
-- B o d y --
-- --
-- Copyright (C) 1999-2002 Universidad Politecnica de Madrid --
-- Copyright (C) 2003-2005 The European Space Agency --
-- Copyright (C) 2003-2021, 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. --
-- --
-- The port of GNARL to bare board targets was initially developed by the --
-- Real-Time Systems Group at the Technical University of Madrid. --
-- --
------------------------------------------------------------------------------
pragma Restrictions (No_Elaboration_Code);
with System.BB.CPU_Primitives;
with System.BB.Parameters;
with System.BB.Threads;
with System.BB.Threads.Queues;
with System.BB.Time;
package body System.BB.Protection is
------------------
-- Enter_Kernel --
------------------
procedure Enter_Kernel is
begin
-- Interrupts are disabled to avoid concurrency problems when modifying
-- kernel data. This way, external interrupts cannot be raised.
CPU_Primitives.Disable_Interrupts;
end Enter_Kernel;
------------------
-- Leave_Kernel --
------------------
procedure Leave_Kernel is
use System.BB.Time;
use type System.BB.Threads.Thread_States;
begin
-- Interrupts are always disabled when entering here
-- Wake up served entry calls
if Parameters.Multiprocessor
and then Wakeup_Served_Entry_Callback /= null
then
Wakeup_Served_Entry_Callback.all;
end if;
-- The idle task is always runnable, so there is always a task to be
-- run.
-- We need to check whether a context switch is needed
if Threads.Queues.Context_Switch_Needed then
-- Perform a context switch because the currently executing thread
-- is blocked or it is no longer the one with the highest priority.
-- Update execution time before context switch
if Scheduling_Event_Hook /= null then
Scheduling_Event_Hook.all;
end if;
CPU_Primitives.Context_Switch;
end if;
-- There is always a running thread (at worst the idle thread)
pragma Assert (Threads.Queues.Running_Thread.State = Threads.Runnable);
-- Now we need to set the hardware interrupt masking level equal to the
-- software priority of the task that is executing.
CPU_Primitives.Enable_Interrupts
(Threads.Queues.Running_Thread.Active_Priority);
end Leave_Kernel;
end System.BB.Protection;
|
-- { dg-do compile }
-- { dg-options "-gnatdm -gnatws" }
with Valued_Proc_Pkg; use Valued_Proc_Pkg;
with System; use System;
procedure Valued_Proc is
Status : UNSIGNED_LONGWORD;
Length : POSITIVE;
begin
GetMsg (Status, UNSIGNED_WORD(Length));
end;
|
with Ada.Numerics.Generic_Elementary_Functions;
package Real_Type is
subtype Real is Long_Float;
package Real_Elementary_Functions is
new Ada.Numerics.Generic_Elementary_Functions (Real);
end Real_Type;
|
-- parse_args_suite-parse_args_tests.ads
-- Unit tests for the Parse_Args project
-- Copyright (c) 2016, James Humphry
--
-- Permission to use, copy, modify, and/or distribute this software for any
-- purpose with or without fee is hereby granted, provided that the above
-- copyright notice and this permission notice appear in all copies.
--
-- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
-- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
-- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
-- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
-- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
-- OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
-- PERFORMANCE OF THIS SOFTWARE.
with AUnit; use AUnit;
with AUnit.Test_Cases; use AUnit.Test_Cases;
package Parse_Args_Suite.Parse_Args_Tests is
type Parse_Args_Test is new Test_Cases.Test_Case with null record;
procedure Register_Tests (T: in out Parse_Args_Test);
function Name (T : Parse_Args_Test) return Test_String;
procedure Set_Up (T : in out Parse_Args_Test);
procedure Check_Basics (T : in out Test_Cases.Test_Case'Class);
procedure Check_Boolean_Usage (T : in out Test_Cases.Test_Case'Class);
procedure Check_Repeated_Usage (T : in out Test_Cases.Test_Case'Class);
procedure Check_Integer_Usage (T : in out Test_Cases.Test_Case'Class);
procedure Check_String_Usage (T : in out Test_Cases.Test_Case'Class);
end Parse_Args_Suite.Parse_Args_Tests;
|
------------------------------------------------------------------------------
-- --
-- GNAT EXAMPLE --
-- --
-- Copyright (C) 2013, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. --
-- --
-- As a special exception under Section 7 of GPL version 3, you are granted --
-- additional permissions described in the GCC Runtime Library Exception, --
-- version 3.1, as published by the Free Software Foundation. --
-- --
-- You should have received a copy of the GNU General Public License and --
-- a copy of the GCC Runtime Library Exception along with this program; --
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
-- <http://www.gnu.org/licenses/>. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
with Ada.Interrupts.Names;
package body Mphone is
protected Input is
pragma Interrupt_Priority;
procedure Init;
entry Wait_Spd_Sample (N : out Natural);
private
procedure Handler;
pragma Attach_Handler (Handler, Ada.Interrupts.Names.SPI2_Interrupt);
-- Interrupt handler
Ready : Boolean := False;
Last_Spd : Natural;
Spd : Natural;
Spd_Count : Natural := 0;
end Input;
Sample_Spd : constant array (Sample_Type) of Natural :=
(0 => 16 * 16, 1 => 15 * 15, 2 => 14 * 14, 3 => 13 * 13,
4 => 12 * 12, 5 => 11 * 11, 6 => 10 * 10, 7 => 9 * 9,
8 => 8 * 8, 9 => 7 * 7, 10 => 6 * 6, 11 => 5 * 5,
12 => 4 * 4, 13 => 3 * 3, 14 => 2 * 2, 15 => 1 * 1,
16 => 0 * 0,
17 => 1 * 1, 18 => 2 * 2, 19 => 3 * 3, 20 => 4 * 4,
21 => 5 * 5, 22 => 6 * 6, 23 => 7 * 7, 24 => 8 * 8,
25 => 9 * 9, 26 => 10 * 10, 27 => 11 * 11, 28 => 12 * 12,
29 => 13 * 13, 30 => 14 * 14, 31 => 15 * 15, 32 => 16 * 16);
Spd_Divisor : constant := 160 * 16;
protected body Input is
procedure Init is
begin
SPI2.I2SCFGR := SPI2.I2SCFGR or SPI_I2SCFGR.I2SE;
SPI2.CR2 := SPI_CR2.RXNEIE or SPI_CR2.ERRIE;
end Init;
entry Wait_Spd_Sample (N : out Natural) when Ready is
begin
N := Last_Spd;
Ready := False;
end Wait_Spd_Sample;
procedure Handler is
SR : constant Word := SPI2.SR;
V : Word;
Sample : Sample_Type;
pragma Volatile (Sample);
begin
if (SR and SPI_SR.RXNE) /= 0 then
-- Read two word (32 bits), LSB first
V := SPI2.DR;
V := V + SPI2.DR * 2**16;
-- Sum by packets of 1 bit
V := ((V / 2**1) and 16#5555_5555#) + (V and 16#5555_5555#);
-- Sum by packets of 2 bits
V := ((V / 2**2) and 16#3333_3333#) + (V and 16#3333_3333#);
-- Sum by packets of 4 bits
V := ((V / 2**4) and 16#0f0f_0f0f#) + (V and 16#0f0f_0f0f#);
-- Sum by packets of 8 bits
V := ((V / 2**8) and 16#00ff_00ff#) + (V and 16#00ff_00ff#);
-- Sum by packets of 16 bits
V := ((V / 2**16) and 16#0000_ffff#) + (V and 16#0000_ffff#);
Sample := Sample_Type (V);
Spd := Spd + Sample_Spd (Sample);
Spd_Count := Spd_Count + 1;
if Spd_Count = Spd_Divisor - 1 then
Spd_Count := 0;
Last_Spd := Spd / (Spd_Divisor / 64);
Spd := 0;
Ready := True;
else
Spd_Count := Spd_Count + 1;
end if;
end if;
end Handler;
end Input;
function Get_Spd_Sample return Natural is
Res : Natural;
begin
Input.Wait_Spd_Sample (Res);
return Res;
end Get_Spd_Sample;
begin
-- Enable clock for GPIO-B (clk) and GPIO-C (pdm)
RCC.AHB1ENR := RCC.AHB1ENR or RCC_AHB1ENR_GPIOB or RCC_AHB1ENR_GPIOC;
-- Configure PC3 and PB10
declare
use GPIO;
V : Bits_8x4;
begin
GPIOB.MODER (10) := Mode_AF;
V := GPIOB.AFRH;
V (10 - 8) := 5; -- I2S2_CLK (cf p61)
GPIOB.AFRH := V;
GPIOB.OTYPER (10) := Type_PP;
GPIOB.OSPEEDR (10) := Speed_50MHz;
GPIOB.PUPDR (10) := No_Pull;
GPIOC.MODER (3) := Mode_AF;
GPIOC.AFRL (3) := 5; -- I2S2_SD (cf p62)
GPIOC.OTYPER (3) := Type_PP;
GPIOC.OSPEEDR (3) := Speed_50MHz;
GPIOC.PUPDR (3) := No_Pull;
end;
-- Enable SPI clock
RCC.APB1ENR := RCC.APB1ENR or RCC_APB1ENR_SPI2;
-- Init PLLI2S clock
declare
-- HSE = 8 Mhz, PLL_M = 8
PLLI2S_N : constant := 192;
PLLI2S_R : constant := 3;
-- I2SCLK = HSE / PLL_M * PLLI2S_N / PLLI2S_R
-- I2SCLK = 8 / 8 * 192 / 3 = 64 Mhz
begin
-- Select PLLI2S clock source
RCC.CFGR := RCC.CFGR and not RCC_CFGR.I2SSRC_PCKIN;
-- Configure
RCC.PLLI2SCFGR := PLLI2S_R * 2**28 or PLLI2S_N * 2**6;
-- Enable
RCC.CR := RCC.CR or RCC_CR.PLLI2SON;
-- Wait until ready
loop
exit when (RCC.CR and RCC_CR.PLLI2SRDY) /= 0;
end loop;
end;
-- Init SPI
SPI2.I2SCFGR := SPI_I2SCFGR.I2SMOD or SPI_I2SCFGR.I2SCFG_MasterRx
or SPI_I2SCFGR.I2SSTD_LSB or SPI_I2SCFGR.CKPOL
or SPI_I2SCFGR.DATLEN_32;
-- Divisor = 62 -- 125
SPI2.I2SPR := 62 or SPI_I2SPR.ODD;
Input.Init;
end Mphone;
|
--*****************************************************************************
--*
--* PROJECT: BingAda
--*
--* FILE: q_bingo_help.adb
--*
--* AUTHOR: Javier Fuica Fernandez
--*
--*****************************************************************************
with Gtk.About_Dialog;
with Gtk.Dialog;
package body Q_Bingo_Help is
use type Gtk.Dialog.Gtk_Response_Type;
--==================================================================
procedure P_Show_Window (V_Parent_Window : Gtk.Window.Gtk_Window) is
V_Dialog : Gtk.About_Dialog.Gtk_About_Dialog;
begin
Gtk.About_Dialog.Gtk_New (V_Dialog);
Gtk.About_Dialog.Set_Transient_For (V_Dialog, V_Parent_Window);
Gtk.About_Dialog.Set_Destroy_With_Parent (V_Dialog, True);
Gtk.About_Dialog.Set_Modal (V_Dialog, True);
Gtk.About_Dialog.Add_Credit_Section
(About => V_Dialog,
Section_Name => "Beta Testers : ",
People =>
(1 => new String'("Wife"),
2 => new String'("Sons")));
Gtk.About_Dialog.Set_Authors
(V_Dialog,
(1 => new String'("Javier Fuica Fernandez <jafuica@gmail.com>")));
Gtk.About_Dialog.Set_Comments (V_Dialog, "Bingo application in GTKAda");
Gtk.About_Dialog.Set_License
(V_Dialog,
"This library is free software; you can redistribute it and/or"
& " modify it under the terms of the GNU General Public"
& " License as published by the Free Software Foundation; either"
& " version 2 of the License, or (at your option) any later version."
& Ascii.Lf
& "This library is distributed in the hope that it will be useful,"
& " but WITHOUT ANY WARRANTY; without even the implied warranty of"
& " MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the"
& " GNU General Public License for more details.");
Gtk.About_Dialog.Set_Wrap_License (V_Dialog, True);
Gtk.About_Dialog.Set_Program_Name (V_Dialog, "BingAda");
Gtk.About_Dialog.Set_Version (V_Dialog, "0.9 Beta");
if Gtk.About_Dialog.Run (V_Dialog) /= Gtk.Dialog.Gtk_Response_Close then
-- Dialog was destroyed by user, not closed through Close button
null;
end if;
Gtk.About_Dialog.Destroy (V_Dialog);
--GTK.ABOUT_DIALOG.ON_ACTIVATE_LINK (V_DIALOG,P_ON_ACTIVATE_LINK'Access);
--GTK.ABOUT_DIALOG.DESTROY (V_DIALOG);
end P_Show_Window;
--==================================================================
end Q_Bingo_Help;
|
-- C93004F.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 WHEN AN EXCEPTION IS RAISED DURING THE ACTIVATION OF A
-- TASK, OTHER TASKS ARE UNAFFECTED.
-- THE ENCLOSING BLOCK RECEIVES TASKING_ERROR.
-- THIS TESTS CHECKS THE CASE IN WHICH THE TASKS ARE CREATED BY THE
-- ALLOCATION OF A RECORD OF TASKS OR AN ARRAY OF TASKS.
-- R. WILLIAMS 8/7/86
WITH REPORT; USE REPORT;
PROCEDURE C93004F IS
BEGIN
TEST ( "C93004F", "CHECK THAT WHEN AN EXCEPTION IS RAISED " &
"DURING THE ACTIVATION OF A TASK, OTHER " &
"TASKS ARE UNAFFECTED. IN THIS TEST, THE " &
"TASKS ARE CREATED BY THE ALLOCATION OF A " &
"RECORD OR AN ARRAY OF TASKS" );
DECLARE
TASK TYPE T IS
ENTRY E;
END T;
TASK TYPE TT;
TASK TYPE TX IS
ENTRY E;
END TX;
TYPE REC IS
RECORD
TR : T;
END RECORD;
TYPE ARR IS ARRAY (IDENT_INT (1) .. IDENT_INT (1)) OF T;
TYPE RECX IS
RECORD
TTX1 : TX;
TTT : TT;
TTX2 : TX;
END RECORD;
TYPE ACCR IS ACCESS REC;
AR : ACCR;
TYPE ACCA IS ACCESS ARR;
AA : ACCA;
TYPE ACCX IS ACCESS RECX;
AX : ACCX;
TASK BODY T IS
BEGIN
ACCEPT E;
END T;
TASK BODY TT IS
BEGIN
AR.TR.E;
EXCEPTION
WHEN OTHERS =>
FAILED ( "TASK AR.TR NOT ACTIVE" );
END TT;
TASK BODY TX IS
I : POSITIVE := IDENT_INT (0); -- RAISE
-- CONSTRAINT_ERROR.
BEGIN
IF I /= IDENT_INT (2) OR I = IDENT_INT (1) + 1 THEN
FAILED ( "TX ACTIVATED OK" );
END IF;
END TX;
BEGIN
AR := NEW REC;
AA := NEW ARR;
AX := NEW RECX;
FAILED ( "TASKING_ERROR NOT RAISED IN MAIN" );
AA.ALL (1).E; -- CLEAN UP.
EXCEPTION
WHEN TASKING_ERROR =>
BEGIN
AA.ALL (1).E;
EXCEPTION
WHEN TASKING_ERROR =>
FAILED ( "AA.ALL (1) NOT ACTIVATED" );
END;
WHEN CONSTRAINT_ERROR =>
FAILED ( "CONSTRAINT_ERROR RAISED IN MAIN" );
WHEN OTHERS =>
FAILED ( "ABNORMAL EXCEPTION IN MAIN" );
END;
RESULT;
END C93004F;
|
with System;
package Crash is
procedure Last_Chance_Handler
(Source_Location : System.Address; Line : Integer);
pragma Export (C, Last_Chance_Handler,
"__gnat_last_chance_handler");
end Crash;
|
with Ada.Strings.Fixed;
with Ada.Integer_Text_IO;
-- Copyright 2021 Melwyn Francis Carlo
procedure A034 is
use Ada.Strings.Fixed;
use Ada.Integer_Text_IO;
Factorials : constant array (Integer range 1 .. 10) of Integer :=
(1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880);
Sum : Integer := 0;
I_Len, Digits_Sum : Integer;
I_Str : String (1 .. 10);
begin
for I in 100 .. 1_00_000 loop
I_Len := Trim (Integer'Image (I), Ada.Strings.Both)'Length;
I_Str (1 .. I_Len) := Trim (Integer'Image (I), Ada.Strings.Both);
Digits_Sum := 0;
for J in 1 .. I_Len loop
Digits_Sum := Digits_Sum
+ Factorials (Character'Pos (I_Str (J))
- Character'Pos ('0') + 1);
end loop;
if Digits_Sum = I then
Sum := Sum + I;
end if;
end loop;
Put (Sum, Width => 0);
end A034;
|
pragma Ada_2020;
with Interfaces;
---- Ada String Format Library
---- @usages:
-- -- specified argumnent index
-- with Fmt, Fmt.Stdtypes;
-- use Fmt, Fmt.Stdtypes;
-- ...
-- Ada.Text_IO.Put_Line(Format("{1:%H-%M-%S} {2}", FAB & Ada.Calendar.Clock & Message));
-- Ada.Text_IO.Put_Line(Format("bin view of {1:b=10} is {1:b=2}", 123));
-- -- auto argument index
-- Ada.Text_IO.Put_Line(Format("{:%H-%M-%S} {} ", FAB & Ada.Calendar.Clock & Message));
-- -- escape character
-- Ada.Text_IO.Put_Line(Format("hello, \n, world"));
package Fmt is
type Argument_Type is interface;
-- Argument_Type bind template variant with specified EDIT
-- e.g
-- Put_Line(Format("{1:w=4,f=0}", To_Argument(123)));
-- INDEX : ^
-- EDIT : ^^^^^^^
procedure Parse (
Self : in out Argument_Type;
Edit : String) is null;
-- Parse "{" [Index] ":" Edit "}" to internal display format settings.
-- @param Edit : type related format. e.g. "w=3,b=16"
function Get_Length (
Self : in out Argument_Type)
return Natural is abstract;
-- Compute output string length in bytes.
-- @remarks : This function called after `Parse`
procedure Put (
Self : in out Argument_Type;
Edit : String;
To : in out String) is abstract;
-- Generate output string
-- @param To : target string with length computed by `Get_Length`
procedure Finalize (Self : in out Argument_Type) is null;
-- this routing call before Format return edited result
type Argument_Ptr is access all Argument_Type'Class;
type Arguments is array(Positive range <>) of Argument_Ptr;
-- Arguments pass to `Format` argument `Values`
function "&" (Values : Arguments; New_Item : Argument_Type'Class) return Arguments
with Inline;
FAB : constant Arguments := [];
-- empty Arguments
function Format (
Template : String;
Values : Arguments := FAB)
return String;
-- Given Template and Values, output final text
-- @param Template : compound by expr and non expr parts
-- the expr part wrapped with "{}", contains an optional Value_Index and some optional Edit info
-- Value_Index is positive, should compound by dec digits
-- if no Value_Index specified, Format will auto increase Value_Index according to Values
-- Edit info interpret by the Argument_Type.Parse
-- the non expr part can use character '\' to output specific character
-- @param Values : values to replace the expr in the Template
-- @example:
-- Format("x + y = {3:b=16,w=8,f=0}, x = {1}, y = {2}\n", FAB & x & y & (x + y))
function Format (
Template : String;
Value : Argument_Type'Class)
return String;
-- Format one argument with given template
generic
type Value_Type (<>) is limited private;
with function To_Argument (V : Value_Type) return Argument_Type'Class is <>;
function Generic_Format (
Template : String;
Value : Value_Type)
return String;
-- Simplified one argument format
procedure Parse_KV_Edit (
Edit : String;
Conf : not null access procedure(K : String; V : String));
-- Routing for implements `Argument_Type.Parse`.
-- Each `key`, `value` pair seperate by delimiter ','.
-- The `key` and `value` seperate by '='.
subtype Decimal_Digit is Character range '0' .. '9';
subtype Hex_Digit is Character
with Static_Predicate => Hex_Digit in '0' .. '9' | 'a' .. 'f' | 'A' .. 'F';
function Is_Decimal_Number (S : String) return Boolean
with Inline;
subtype Text_Align is Character
with Static_Predicate => Text_Align in 'L' | 'M' | 'R';
type Placeholder_Argument_Type is abstract new Argument_Type with record
Length : Natural := 0;
Default_Edit : access constant String := null;
end record;
-- Placeholder_Argument_Type bind template variant with specified format
-- The Argument value may contains multiparts.
-- Each part expressed as placeholder (with prefix %) in the EDIT
-- e.g
-- Format("{:%Y-%m-%d %H:%M:%S}", To_Argument(Ada.Calendar.Clock));
-- EDIT : ^^^^^^^^^^^^^^^^^
-- ^^ -> placeholder Y
-- ^^ -> placeholder m
function Is_Valid_Placeholder (
Self : Placeholder_Argument_Type;
Name : Character)
return Boolean is abstract;
-- Given a character, detect whether it is a placeholder
function Get_Placeholder_Width (
Self : in out Placeholder_Argument_Type;
Name : Character)
return Natural is abstract;
-- Given a placeholder, tell the edit width
procedure Put_Placeholder (
Self : in out Placeholder_Argument_Type;
Name : Character;
To : in out String) is abstract;
-- Replace placeholder with context related text
overriding
procedure Parse (
Self : in out Placeholder_Argument_Type;
Edit : String);
-- Note : if Edit is empty then Default_Edit will apply
overriding
function Get_Length (
Self : in out Placeholder_Argument_Type)
return Natural;
overriding
procedure Put (
Self : in out Placeholder_Argument_Type;
Edit : String;
To : in out String);
---- Note : if Edit is empty then Default_Edit will apply
private
function Safe_Abs (X : Long_Long_Integer) return Interfaces.Unsigned_64
with Inline;
end Fmt;
|
-- This package has been generated automatically by GNATtest.
-- Do not edit any part of it, see GNATtest documentation for more details.
-- begin read only
with Gnattest_Generated;
package Tk.Menu.Test_Data.Tests is
type Test is new GNATtest_Generated.GNATtest_Standard.Tk.Menu.Test_Data
.Test with
null record;
procedure Test_Activate_e310e8_54120b(Gnattest_T: in out Test);
-- tk-menu.ads:336:4:Activate:Test_Activate_Menu
procedure Test_Activate_43ff2b_827a88(Gnattest_T: in out Test);
-- tk-menu.ads:339:4:Activate:Test_Activate_Menu2
procedure Test_Activate_c786dd_e56058(Gnattest_T: in out Test);
-- tk-menu.ads:344:4:Activate:Test_Activate_Menu3
procedure Test_Add_0c595c_5ef6e5(Gnattest_T: in out Test);
-- tk-menu.ads:366:4:Add:Test_Add_Menu
procedure Test_Delete_a9ab1b_9992c1(Gnattest_T: in out Test);
-- tk-menu.ads:443:4:Delete:Test_Delete_Menu
procedure Test_Delete_6e86ea_8b9fc5(Gnattest_T: in out Test);
-- tk-menu.ads:448:4:Delete:Test_Delete_Menu2
procedure Test_Delete_99fa1b_da6433(Gnattest_T: in out Test);
-- tk-menu.ads:453:4:Delete:Test_Delete_Menu3
procedure Test_Entry_Get_Options_ef78cc_729271(Gnattest_T: in out Test);
-- tk-menu.ads:481:4:Entry_Get_Options:Test_Entry_Get_Options_Menu
procedure Test_Entry_Get_Options_0615ce_9f990e(Gnattest_T: in out Test);
-- tk-menu.ads:486:4:Entry_Get_Options:Test_Entry_Get_Options_Menu2
procedure Test_Entry_Get_Options_d1b552_f00eb7(Gnattest_T: in out Test);
-- tk-menu.ads:491:4:Entry_Get_Options:Test_Entry_Get_Options_Menu3
procedure Test_Entry_Configure_1d51e9_fc4fb1(Gnattest_T: in out Test);
-- tk-menu.ads:517:4:Entry_Configure:Test_Entry_Configure_Menu
procedure Test_Entry_Configure_73d2b1_c3ebe5(Gnattest_T: in out Test);
-- tk-menu.ads:522:4:Entry_Configure:Test_Entry_Configure_Menu2
procedure Test_Entry_Configure_138c3b_1d928b(Gnattest_T: in out Test);
-- tk-menu.ads:527:4:Entry_Configure:Test_Entry_Configure_Menu3
procedure Test_Index_d34072_0f3076(Gnattest_T: in out Test);
-- tk-menu.ads:553:4:Index:Test_Index_Menu
procedure Test_Index_032cb4_ad9207(Gnattest_T: in out Test);
-- tk-menu.ads:558:4:Index:Test_Index_Menu2
procedure Test_Index_e3e5f0_c1d386(Gnattest_T: in out Test);
-- tk-menu.ads:562:4:Index:Test_Index_Menu3
procedure Test_Insert_3b526a_33fb34(Gnattest_T: in out Test);
-- tk-menu.ads:591:4:Insert:Test_Insert_Menu
procedure Test_Insert_fde4b6_24d8d2(Gnattest_T: in out Test);
-- tk-menu.ads:596:4:Insert:Test_Insert_Menu2
procedure Test_Insert_3d057c_d006b1(Gnattest_T: in out Test);
-- tk-menu.ads:601:4:Insert:Test_Insert_Menu3
procedure Test_Invoke_49d5a3_7b2d3d(Gnattest_T: in out Test);
-- tk-menu.ads:627:4:Invoke:Test_Invoke_Menu1
procedure Test_Invoke_7593eb_d8311f(Gnattest_T: in out Test);
-- tk-menu.ads:630:4:Invoke:Test_Invoke_Menu3
procedure Test_Invoke_d16f08_c23171(Gnattest_T: in out Test);
-- tk-menu.ads:635:4:Invoke:Test_Invoke_Menu4
procedure Test_Invoke_0a3e65_d5e898(Gnattest_T: in out Test);
-- tk-menu.ads:661:4:Invoke:Test_Invoke_Menu2
procedure Test_Invoke_781f8e_c01adc(Gnattest_T: in out Test);
-- tk-menu.ads:665:4:Invoke:Test_Invoke_Menu5
procedure Test_Invoke_a338ab_66d08a(Gnattest_T: in out Test);
-- tk-menu.ads:670:4:Invoke:Test_Invoke_Menu6
procedure Test_Post_297225_baf848(Gnattest_T: in out Test);
-- tk-menu.ads:695:4:Post:Test_Post_Menu1
procedure Test_Post_311578_f13317(Gnattest_T: in out Test);
-- tk-menu.ads:723:4:Post:Test_Post_Menu2
procedure Test_Post_Cascade_09822b_aeea07(Gnattest_T: in out Test);
-- tk-menu.ads:745:4:Post_Cascade:Test_PostCascade_Menu
procedure Test_Post_Cascade_cc0d55_c83524(Gnattest_T: in out Test);
-- tk-menu.ads:748:4:Post_Cascade:Test_PostCascade_Menu2
procedure Test_Post_Cascade_38af3a_1e3e67(Gnattest_T: in out Test);
-- tk-menu.ads:753:4:Post_Cascade:Test_PostCascade_Menu3
procedure Test_Get_Item_Type_a8752e_8c54de(Gnattest_T: in out Test);
-- tk-menu.ads:777:4:Get_Item_Type:Test_Get_Item_Type_Menu
procedure Test_Get_Item_Type_2b168c_962e70(Gnattest_T: in out Test);
-- tk-menu.ads:781:4:Get_Item_Type:Test_Get_Item_Type_Menu2
procedure Test_Get_Item_Type_8d689d_527e33(Gnattest_T: in out Test);
-- tk-menu.ads:786:4:Get_Item_Type:Test_Get_Item_Type_Menu3
procedure Test_Unpost_74fd1c_cf7a1c(Gnattest_T: in out Test);
-- tk-menu.ads:808:4:Unpost:Test_Unpost_Menu
procedure Test_X_Position_2f4d2c_e9e27f(Gnattest_T: in out Test);
-- tk-menu.ads:835:4:X_Position:Test_X_Position_Menu
procedure Test_X_Position_789329_f6fff3(Gnattest_T: in out Test);
-- tk-menu.ads:839:4:X_Position:Test_X_Position_Menu2
procedure Test_X_Position_a37ded_0ad35d(Gnattest_T: in out Test);
-- tk-menu.ads:844:4:X_Position:Test_X_Position_Menu3
procedure Test_Y_Position_623b60_3f1329(Gnattest_T: in out Test);
-- tk-menu.ads:872:4:Y_Position:Test_Y_Position_Menu
procedure Test_Y_Position_7e1bbe_2e80d9(Gnattest_T: in out Test);
-- tk-menu.ads:876:4:Y_Position:Test_Y_Position_Menu2
procedure Test_Y_Position_9d49dc_1c0642(Gnattest_T: in out Test);
-- tk-menu.ads:881:4:Y_Position:Test_Y_Position_Menu3
end Tk.Menu.Test_Data.Tests;
-- end read only
|
package Boolean_Subtype2_Pkg is
type Node_Id is range 0 .. 099_999_999;
subtype Entity_Id is Node_Id;
function Node20 (N : Node_Id) return Node_Id;
function Flag63 (N : Node_Id) return Boolean;
function Present (N : Node_Id) return Boolean;
end Boolean_Subtype2_Pkg;
|
with Ada.Text_IO;
with Pythagorean_Means;
procedure Main is
My_Set : Pythagorean_Means.Set := (1.0, 2.0, 3.0, 4.0, 5.0,
6.0, 7.0, 8.0, 9.0, 10.0);
Arithmetic_Mean : Float := Pythagorean_Means.Arithmetic_Mean (My_Set);
Geometric_Mean : Float := Pythagorean_Means.Geometric_Mean (My_Set);
Harmonic_Mean : Float := Pythagorean_Means.Harmonic_Mean (My_Set);
begin
Ada.Text_IO.Put_Line (Float'Image (Arithmetic_Mean) & " >= " &
Float'Image (Geometric_Mean) & " >= " &
Float'Image (Harmonic_Mean));
end Main;
|
with GL.Types;
with GL.Types.Colors; use GL.Types.Colors;
with Geosphere;
package Palet is
use GL.Types;
type Draw_Mode_Type is (OD_Shade, OD_Wireframe ,OD_Magnitude, OD_Orientation);
type Draw_Mode is record
Shade : Boolean := False;
Wireframe : Boolean := False;
Magnitude : Boolean := False;
Orientation : Boolean := False;
end record ;
type Draw_State is private;
type Colour_Palet is private;
function Background_Colour (Palet_Data : Colour_Palet) return Color;
function Background_Red (Palet_Data : Colour_Palet) return Single;
function Background_Green (Palet_Data : Colour_Palet) return Single;
function Background_Blue (Palet_Data : Colour_Palet) return Single;
function Current_Sphere return Geosphere.Geosphere;
function Foreground_Alpha (Palet_Data : Colour_Palet) return Single;
function Foreground_Blue (Palet_Data : Colour_Palet) return Single;
function Foreground_Colour (Palet_Data : Colour_Palet) return Color;
function Foreground_Green (Palet_Data : Colour_Palet) return Single;
function Foreground_Red (Palet_Data : Colour_Palet) return Single;
function Get_Draw_Mode return Draw_Mode;
function Get_Plane_Size return Float;
function Is_Null return Colour_Palet;
function Line_Length return Float;
function Orientation return Boolean;
function Magnitude return Boolean;
function Outline_Colour (Palet_Data : Colour_Palet) return Color;
function Point_Size return Float;
function Shade return Boolean;
procedure Set_Background_Alpa (Palet_Data : in out Colour_Palet; Alpa : Float);
procedure Set_Background_Colour (Palet_Data : in out Colour_Palet;
Back_Colour : Color);
procedure Set_Background_Colour (Palet_Data : Colour_Palet);
procedure Set_Current_Sphere (aSphere : Geosphere.Geosphere);
procedure Set_Draw_Mode_Off (Mode : Draw_Mode_Type);
procedure Set_Draw_Mode_On (Mode : Draw_Mode_Type);
procedure Set_Foreground_Alpa (Palet_Data : in out Colour_Palet; Alpa : Float);
procedure Set_Foreground_Colour (Palet_Data : in out Colour_Palet;
Fore_Colour : Color);
procedure Set_Foreground_Colour (Palet_Data : Colour_Palet);
procedure Set_Outline_Alpa (Palet_Data : in out Colour_Palet; Alpa : Float);
procedure Set_Outline_Colour (Palet_Data : in out Colour_Palet;
Outline_Colour : Color);
procedure Set_Outline_Colour (Palet_Data : Colour_Palet);
procedure Set_Point_Size (Point_Size : Float);
function Wireframe return Boolean;
private
type Colour_Palet is record
Off : Boolean := False;
Foreground_Colour : Color := (1.0, 0.0, 0.0, 1.0);
Background_Colour : Color := (0.0, 1.0, 0.0, 1.0);
Outline_Colour : Color := (0.0, 0.0, 0.0, 1.0);
end record;
type Draw_State is record
Ambient : Float := 1.0;
Diffuse : Float := 0.0;
Point_Size : Float := 0.2;
Line_Length : Float := 6.0;
Plane_Size : Float := 6.0;
M_Draw_Mode : Draw_Mode;
M_Sphere : Geosphere.Geosphere;
-- M_Sphere_GL_List : GL.Types.UInt;
end record;
end Palet;
|
with ACO.OD_Types;
generic
type Item_Type is private;
package ACO.Generic_Entry_Types is
-- Numeric type.
-- When filled with byte array the data is byte swapped if needed.
pragma Preelaborate;
use ACO.OD_Types;
type Entry_Type is new ACO.OD_Types.Entry_Base with private;
function Create (Accessability : Access_Mode;
Data : Item_Type)
return Entry_Type;
function Read (This : Entry_Type) return Item_Type;
procedure Write (This : in out Entry_Type;
Data : in Item_Type);
overriding
function Data_Length (This : Entry_Type) return Natural;
overriding
function Read (This : Entry_Type) return Byte_Array
with Post => Read'Result'Length = Item_Type'Size / 8;
overriding
procedure Write (This : in out Entry_Type;
Bytes : in Byte_Array)
with Pre => Bytes'Length = Item_Type'Size / 8;
function "=" (L : Entry_Type; R : Item_Type) return Boolean
with Inline;
function "=" (L : Item_Type; R : Entry_Type) return Boolean
with Inline;
private
function Convert (Data : Item_Type) return Byte_Array;
function Convert (Bytes : Byte_Array) return Item_Type;
type Entry_Type is new ACO.OD_Types.Entry_Base with record
Data : Item_Type;
end record;
end ACO.Generic_Entry_Types;
|
-- Copyright (c) 2017 Maxim Reznik <reznikmm@gmail.com>
--
-- SPDX-License-Identifier: MIT
-- License-Filename: LICENSE
-------------------------------------------------------------
with Ada.Streams;
with LSP.Messages;
with LSP.Message_Handlers;
with LSP.Types;
private with LSP.Notification_Dispatchers;
private with LSP.Request_Dispatchers;
private with League.Stream_Element_Vectors;
package LSP.Servers is
pragma Preelaborate;
type Server is tagged limited private;
not overriding procedure Initialize
(Self : in out Server;
Stream : access Ada.Streams.Root_Stream_Type'Class;
Request : not null LSP.Message_Handlers.Request_Handler_Access;
Notification : not null LSP.Message_Handlers.
Notification_Handler_Access);
not overriding procedure Send_Notification
(Self : in out Server;
Value : in out LSP.Messages.NotificationMessage'Class);
not overriding procedure Run (Self : in out Server);
not overriding procedure Stop (Self : in out Server);
-- Ask server to stop after processing current message
not overriding procedure Workspace_Apply_Edit
(Self : in out Server;
Params : LSP.Messages.ApplyWorkspaceEditParams;
Applied : out Boolean;
Error : out LSP.Messages.Optional_ResponseError);
private
type Server is tagged limited record
Initilized : Boolean;
Stop : Boolean := False;
-- Mark Server as uninitialized until get 'initalize' request
Stream : access Ada.Streams.Root_Stream_Type'Class;
Req_Handler : LSP.Message_Handlers.Request_Handler_Access;
Notif_Handler : LSP.Message_Handlers.Notification_Handler_Access;
Requests : aliased LSP.Request_Dispatchers.Request_Dispatcher;
Notifications : aliased LSP.Notification_Dispatchers
.Notification_Dispatcher;
Last_Request : LSP.Types.LSP_Number := 1;
Vector : League.Stream_Element_Vectors.Stream_Element_Vector;
end record;
end LSP.Servers;
|
with System.Storage_Elements;
package body System.Formatting is
pragma Suppress (All_Checks);
use type Long_Long_Integer_Types.Word_Unsigned;
use type Long_Long_Integer_Types.Long_Long_Unsigned;
subtype Word_Unsigned is Long_Long_Integer_Types.Word_Unsigned;
subtype Long_Long_Unsigned is Long_Long_Integer_Types.Long_Long_Unsigned;
procedure memset (
b : Address;
c : Integer;
n : Storage_Elements.Storage_Count)
with Import,
Convention => Intrinsic, External_Name => "__builtin_memset";
function add_overflow (
a, b : Word_Unsigned;
res : not null access Word_Unsigned)
return Boolean
with Import,
Convention => Intrinsic,
External_Name =>
(if Standard'Word_Size = Integer'Size then
"__builtin_uadd_overflow"
elsif Standard'Word_Size = Long_Integer'Size then
"__builtin_uaddl_overflow"
else "__builtin_uaddll_overflow");
function add_overflow (
a, b : Long_Long_Unsigned;
res : not null access Long_Long_Unsigned)
return Boolean
with Import,
Convention => Intrinsic,
External_Name => "__builtin_uaddll_overflow";
function mul_overflow (
a, b : Word_Unsigned;
res : not null access Word_Unsigned)
return Boolean
with Import,
Convention => Intrinsic,
External_Name =>
(if Standard'Word_Size = Integer'Size then
"__builtin_umul_overflow"
elsif Standard'Word_Size = Long_Integer'Size then
"__builtin_umull_overflow"
else "__builtin_umulll_overflow");
function mul_overflow (
a, b : Long_Long_Unsigned;
res : not null access Long_Long_Unsigned)
return Boolean
with Import,
Convention => Intrinsic,
External_Name => "__builtin_umulll_overflow";
function Width_Digits (Value : Word_Unsigned; Base : Number_Base)
return Positive;
function Width_Digits (Value : Word_Unsigned; Base : Number_Base)
return Positive
is
P : aliased Word_Unsigned := Word_Unsigned (Base);
Result : Positive := 1;
begin
while P <= Value loop
Result := Result + 1;
exit when mul_overflow (P, Word_Unsigned (Base), P'Access);
end loop;
return Result;
end Width_Digits;
function Width_Digits (Value : Long_Long_Unsigned; Base : Number_Base)
return Positive;
function Width_Digits (Value : Long_Long_Unsigned; Base : Number_Base)
return Positive is
begin
if Standard'Word_Size < Long_Long_Unsigned'Size then
-- optimized for 32bit
declare
P : aliased Long_Long_Unsigned := Long_Long_Unsigned (Base);
Result : Positive := 1;
begin
while P <= Value loop
Result := Result + 1;
exit when mul_overflow (P, Long_Long_Unsigned (Base), P'Access);
end loop;
return Result;
end;
else
-- optimized for 64bit
return Width_Digits (Word_Unsigned (Value), Base);
end if;
end Width_Digits;
procedure Fill_Digits (
Value : Word_Unsigned;
Item : out String;
Base : Number_Base;
Set : Type_Set);
procedure Fill_Digits (
Value : Word_Unsigned;
Item : out String;
Base : Number_Base;
Set : Type_Set)
is
V : Word_Unsigned := Value;
begin
for I in reverse Item'Range loop
Image (Digit (V rem Word_Unsigned (Base)), Item (I), Set);
V := V / Word_Unsigned (Base);
end loop;
end Fill_Digits;
procedure Fill_Digits (
Value : Long_Long_Unsigned;
Item : out String;
Base : Number_Base;
Set : Type_Set);
procedure Fill_Digits (
Value : Long_Long_Unsigned;
Item : out String;
Base : Number_Base;
Set : Type_Set) is
begin
if Standard'Word_Size < Long_Long_Unsigned'Size then
-- optimized for 32bit
declare
V : Long_Long_Unsigned := Value;
I : Positive := Item'Last;
begin
while V > Long_Long_Unsigned (Word_Unsigned'Last) loop
Image (Digit (V rem Long_Long_Unsigned (Base)), Item (I), Set);
V := V / Long_Long_Unsigned (Base);
I := I - 1;
end loop;
Fill_Digits (Word_Unsigned (V), Item (Item'First .. I), Base, Set);
end;
else
-- optimized for 64bit
Fill_Digits (Word_Unsigned (Value), Item, Base, Set);
end if;
end Fill_Digits;
procedure Take_Digits (
Item : String;
Last : out Natural;
Result : out Word_Unsigned;
Base : Number_Base;
Skip_Underscore : Boolean;
Overflow : out Boolean);
procedure Take_Digits (
Item : String;
Last : out Natural;
Result : out Word_Unsigned;
Base : Number_Base;
Skip_Underscore : Boolean;
Overflow : out Boolean)
is
R : aliased Word_Unsigned := 0;
begin
Last := Item'First - 1;
Overflow := False;
while Last < Item'Last loop
declare
X : Digit;
Is_Invalid : Boolean;
Next : Positive := Last + 1;
begin
if Item (Next) = '_' then
exit when not Skip_Underscore
or else Next = Item'First
or else Next >= Item'Last;
Next := Next + 1;
end if;
Value (Item (Next), X, Is_Invalid);
exit when Is_Invalid or else X >= Base;
if mul_overflow (R, Word_Unsigned (Base), R'Access)
or else add_overflow (R, Word_Unsigned (X), R'Access)
then
Overflow := True;
exit;
end if;
Last := Next;
end;
end loop;
Result := R;
end Take_Digits;
procedure Take_Digits (
Item : String;
Last : out Natural;
Result : out Long_Long_Unsigned;
Base : Number_Base;
Skip_Underscore : Boolean;
Overflow : out Boolean);
procedure Take_Digits (
Item : String;
Last : out Natural;
Result : out Long_Long_Unsigned;
Base : Number_Base;
Skip_Underscore : Boolean;
Overflow : out Boolean) is
begin
if Standard'Word_Size < Long_Long_Unsigned'Size then
-- optimized for 32bit
declare
R : aliased Long_Long_Unsigned := 0;
begin
Take_Digits (
Item,
Last,
Word_Unsigned (R),
Base,
Skip_Underscore,
Overflow);
if Overflow then
Overflow := False;
while Last < Item'Last loop
declare
X : Digit;
Is_Invalid : Boolean;
Next : Positive := Last + 1;
begin
if Item (Next) = '_' then
exit when not Skip_Underscore
or else Next >= Item'Last;
Next := Next + 1;
end if;
Value (Item (Next), X, Is_Invalid);
exit when Is_Invalid or else X >= Base;
if mul_overflow (R, Long_Long_Unsigned (Base), R'Access)
or else add_overflow (
R,
Long_Long_Unsigned (X),
R'Access)
then
Overflow := True;
exit;
end if;
Last := Next;
end;
end loop;
end if;
Result := R;
end;
else
-- optimized for 64bit
Take_Digits (
Item,
Last,
Word_Unsigned (Result),
Base,
Skip_Underscore,
Overflow);
end if;
end Take_Digits;
-- implementation
function Digits_Width (
Value : Long_Long_Integer_Types.Word_Unsigned;
Base : Number_Base := 10)
return Positive is
begin
return Width_Digits (Value, Base);
end Digits_Width;
function Digits_Width (
Value : Long_Long_Integer_Types.Long_Long_Unsigned;
Base : Number_Base := 10)
return Positive is
begin
if Standard'Word_Size < Long_Long_Unsigned'Size then
-- optimized for 32bit
return Width_Digits (Value, Base);
else
-- optimized for 64bit
return Digits_Width (Word_Unsigned (Value), Base);
end if;
end Digits_Width;
procedure Image (
Value : Digit;
Item : out Character;
Set : Type_Set := Upper_Case) is
begin
case Value is
when 0 .. 9 =>
Item := Character'Val (Character'Pos ('0') + Value);
when 10 .. 15 =>
Item := Character'Val (
Character'Pos ('a')
- 10
- (Character'Pos ('a') - Character'Pos ('A'))
* Type_Set'Pos (Set)
+ Value);
end case;
end Image;
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)
is
W : constant Positive := Formatting.Digits_Width (Value, Base);
Padding_Length : constant Natural := Integer'Max (0, Width - W);
Length : constant Natural := Padding_Length + W;
begin
Error := Item'First + Length - 1 > Item'Last;
if Error then
Last := Item'First - 1;
else
Last := Item'First + Length - 1;
Fill_Padding (
Item (Item'First .. Item'First + Padding_Length - 1),
Fill);
Fill_Digits (
Value,
Item (Item'First + Padding_Length .. Last),
Base,
Set);
end if;
end Image;
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) is
begin
if Standard'Word_Size < Long_Long_Unsigned'Size then
-- optimized for 32bit
declare
W : constant Positive := Formatting.Digits_Width (Value, Base);
Padding_Length : constant Natural := Integer'Max (0, Width - W);
Length : constant Natural := Padding_Length + W;
begin
Error := Item'First + Length - 1 > Item'Last;
if Error then
Last := Item'First - 1;
else
Last := Item'First + Length - 1;
Fill_Padding (
Item (Item'First .. Item'First + Padding_Length - 1),
Fill);
Fill_Digits (
Value,
Item (Item'First + Padding_Length .. Last),
Base,
Set);
end if;
end;
else
-- optimized for 64bit
Image (
Word_Unsigned (Value),
Item,
Last,
Base,
Set,
Width,
Fill,
Error);
end if;
end Image;
procedure Value (
Item : Character;
Result : out Digit;
Error : out Boolean) is
begin
case Item is
when '0' .. '9' =>
Result := Character'Pos (Item) - Character'Pos ('0');
Error := False;
when 'A' .. 'F' =>
Result := Character'Pos (Item) - (Character'Pos ('A') - 10);
Error := False;
when 'a' .. 'f' =>
Result := Character'Pos (Item) - (Character'Pos ('a') - 10);
Error := False;
when others =>
Error := True;
end case;
end Value;
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)
is
Overflow : Boolean;
begin
Take_Digits (Item, Last, Result, Base, Skip_Underscore, Overflow);
if Overflow then
Result := 0;
Last := Item'First - 1;
Error := True;
else
Error := Last < Item'First;
end if;
end Value;
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) is
begin
if Standard'Word_Size < Long_Long_Unsigned'Size then
-- optimized for 32bit
declare
Overflow : Boolean;
begin
Take_Digits (Item, Last, Result, Base, Skip_Underscore, Overflow);
if Overflow then
Result := 0;
Last := Item'First - 1;
Error := True;
else
Error := Last < Item'First;
end if;
end;
else
-- optimized for 64bit
Value (
Item,
Last,
Word_Unsigned (Result),
Base,
Skip_Underscore,
Error);
end if;
end Value;
procedure Fill_Padding (Item : out String; Pad : Character) is
begin
memset (Item'Address, Character'Pos (Pad), Item'Length);
end Fill_Padding;
end System.Formatting;
|
-- PR ada/49732
-- Testcase by Vorfeed Canal
-- { dg-do compile }
-- { dg-options "-gnato" }
with Interfaces.C; use Interfaces.C;
with Interfaces.C.Strings; use Interfaces.C.Strings;
with Interfaces.C.Pointers;
procedure Pointer_Controlled is
function Create (Name : String) return size_t is
type Name_String is new char_array (0 .. Name'Length);
type Name_String_Ptr is access Name_String;
pragma Controlled (Name_String_Ptr);
Name_Str : constant Name_String_Ptr := new Name_String;
Name_Len : size_t;
begin
To_C (Name, Name_Str.all, Name_Len);
return 1;
end;
Test : size_t;
begin
Test := Create("ABC");
end;
|
with Configs;
package body Prop_Links is
procedure Append (Prop_List : in out List;
Config : in Configs.Config_Access)
is
begin
Propagation_Lists.Append (Prop_List, Config_Access (Config));
end Append;
procedure Delete (Prop_List : in out List)
is
begin
Propagation_Lists.Clear (Prop_List);
end Delete;
procedure Copy (To : in out List;
From : in List)
is
use Propagation_Lists;
begin
for Element of From loop
Append (To, Element);
end loop;
end Copy;
end Prop_Links;
|
-- Standard Ada library specification
-- Copyright (c) 2004-2016 AXE Consultants
-- Copyright (c) 2004, 2005, 2006 Ada-Europe
-- Copyright (c) 2000 The MITRE Corporation, Inc.
-- Copyright (c) 1992, 1993, 1994, 1995 Intermetrics, Inc.
-- SPDX-License-Identifier: BSD-3-Clause and LicenseRef-AdaReferenceManual
---------------------------------------------------------------------------
with Ada.Interrupts;
package Ada.Execution_Time.Interrupts is
function Clock (Interrupt : Ada.Interrupts.Interrupt_Id)
return CPU_Time;
function Supported (Interrupt : Ada.Interrupts.Interrupt_Id)
return Boolean;
end Ada.Execution_Time.Interrupts;
|
------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- XML Processor --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2014, 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$
------------------------------------------------------------------------------
package body Matreshka.DOM_Character_Datas is
------------------
-- Constructors --
------------------
package body Constructors is
----------------
-- Initialize --
----------------
procedure Initialize
(Self : not null access Character_Data_Node'Class;
Document : not null Matreshka.DOM_Nodes.Document_Access;
Data : League.Strings.Universal_String) is
begin
Matreshka.DOM_Nodes.Constructors.Initialize (Self, Document);
Self.Data := Data;
end Initialize;
end Constructors;
--------------
-- Get_Data --
--------------
overriding function Get_Data
(Self : not null access constant Character_Data_Node)
return League.Strings.Universal_String is
begin
return Self.Data;
end Get_Data;
------------------
-- Replace_Data --
------------------
overriding procedure Replace_Data
(Self : not null access Character_Data_Node;
Offset : Positive;
Count : Natural;
Arg : League.Strings.Universal_String) is
begin
if Offset <= Self.Data.Length then
-- Position of first character of the replaced slice is inside
-- string. Position of last character of replaced slice can't be
-- greater than length of the string.
Self.Data.Replace
(Offset,
Natural'Min (Offset + Count - 1, Self.Data.Length),
Arg);
elsif Offset = Self.Data.Length + 1 then
-- Position of first character points to first position after
-- position of last character of the string. Specified new data need
-- to be appended to the string.
Self.Data.Append (Arg);
else
-- Position of the first character points outside of current data,
-- DOM_INDEX_SIZE_ERR need to be raised.
Self.Raise_Index_Size_Error;
end if;
end Replace_Data;
--------------
-- Set_Data --
--------------
overriding procedure Set_Data
(Self : not null access Character_Data_Node;
New_Value : League.Strings.Universal_String) is
begin
Self.Data := New_Value;
end Set_Data;
end Matreshka.DOM_Character_Datas;
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.