content
stringlengths 23
1.05M
|
|---|
-- Copyright (c) 2020-2021 Bartek thindil Jasicki <thindil@laeran.pl>
--
-- 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.Characters.Handling; use Ada.Characters.Handling;
with Ada.Strings; use Ada.Strings;
with Ada.Strings.Fixed; use Ada.Strings.Fixed;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
package body Tk.Menu is
-- ****if* Menu/Menu.Options_To_String
-- FUNCTION
-- Convert Ada structure to Tcl command
-- PARAMETERS
-- Options - Ada Menu_Options to convert
-- RESULT
-- String with Tcl command options
-- HISTORY
-- 8.6.0 - Added
-- SOURCE
function Options_To_String(Options: Menu_Options) return String is
-- ****
Options_String: Unbounded_String := Null_Unbounded_String;
begin
Option_Image
(Name => "activebackground", Value => Options.Active_Background,
Options_String => Options_String);
Option_Image
(Name => "activeborderwidth", Value => Options.Active_Border_Width,
Options_String => Options_String);
Option_Image
(Name => "activeforeground", Value => Options.Active_Foreground,
Options_String => Options_String);
Option_Image
(Name => "background", Value => Options.Background,
Options_String => Options_String);
Option_Image
(Name => "borderwidth", Value => Options.Border_Width,
Options_String => Options_String);
Option_Image
(Name => "cursor", Value => Options.Cursor,
Options_String => Options_String);
Option_Image
(Name => "disabledforeground", Value => Options.Disabled_Foreground,
Options_String => Options_String);
Option_Image
(Name => "font", Value => Options.Font,
Options_String => Options_String);
Option_Image
(Name => "foreground", Value => Options.Foreground,
Options_String => Options_String);
Option_Image
(Name => "relief", Value => Options.Relief,
Options_String => Options_String);
Option_Image
(Name => "postcommand", Value => Options.Post_Command,
Options_String => Options_String);
Option_Image
(Name => "selectcolor", Value => Options.Select_Color,
Options_String => Options_String);
Option_Image
(Name => "takefocus", Value => Options.Take_Focus,
Options_String => Options_String);
Option_Image
(Name => "tearoff", Value => Options.Tear_Off,
Options_String => Options_String);
Option_Image
(Name => "tearoffcommand", Value => Options.Tear_Off_Command,
Options_String => Options_String);
Option_Image
(Name => "title", Value => Options.Title,
Options_String => Options_String);
if Options.Menu_Type /= NONE then
Append
(Source => Options_String,
New_Item =>
" -type " &
To_Lower(Item => Menu_Types'Image(Options.Menu_Type)));
end if;
return To_String(Source => Options_String);
end Options_To_String;
function Create
(Path_Name: Tk_Path_String; Options: Menu_Options;
Interpreter: Tcl_Interpreter := Get_Interpreter) return Tk_Menu is
begin
Tcl_Eval
(Tcl_Script =>
"menu " & Path_Name & " " & Options_To_String(Options => Options),
Interpreter => Interpreter);
return Get_Widget(Path_Name => Path_Name, Interpreter => Interpreter);
end Create;
procedure Create
(Menu_Widget: out Tk_Menu; Path_Name: Tk_Path_String;
Options: Menu_Options;
Interpreter: Tcl_Interpreter := Get_Interpreter) is
begin
Menu_Widget :=
Create
(Path_Name => Path_Name, Options => Options,
Interpreter => Interpreter);
end Create;
procedure Activate(Menu_Widget: Tk_Menu; Menu_Index: Tcl_String) is
begin
Execute_Widget_Command
(Widgt => Menu_Widget, Command_Name => "activate",
Options => To_Ada_String(Source => Menu_Index));
end Activate;
procedure Activate
(Menu_Widget: Tk_Menu; Menu_Index: Natural; Is_Index: Boolean := True) is
begin
Execute_Widget_Command
(Widgt => Menu_Widget, Command_Name => "activate",
Options =>
(if Is_Index then "" else "@") &
Trim(Source => Natural'Image(Menu_Index), Side => Left));
end Activate;
procedure Activate(Menu_Widget: Tk_Menu; Menu_Index: Menu_Item_Indexes) is
begin
Execute_Widget_Command
(Widgt => Menu_Widget, Command_Name => "activate",
Options => To_Lower(Item => Menu_Item_Indexes'Image(Menu_Index)));
end Activate;
-- ****if* Menu/Menu.Item_Options_To_String
-- FUNCTION
-- Convert Ada structure to Tcl command
-- PARAMETERS
-- Options - Ada Menu_Item_Options to convert
-- Item_Type - The type of menu item to add
-- RESULT
-- String with Tcl command options
-- HISTORY
-- 8.6.0 - Added
-- SOURCE
function Item_Options_To_String
(Options: Menu_Item_Options; Item_Type: Menu_Item_Types) return String is
-- ****
Options_String: Unbounded_String := Null_Unbounded_String;
begin
if Item_Type = SEPARATOR then
return "";
end if;
Option_Image
(Name => "activebackground", Value => Options.Active_Background,
Options_String => Options_String);
Option_Image
(Name => "activeforeground", Value => Options.Active_Foreground,
Options_String => Options_String);
Option_Image
(Name => "accelerator", Value => Options.Accelerator,
Options_String => Options_String);
Option_Image
(Name => "background", Value => Options.Background,
Options_String => Options_String);
Option_Image
(Name => "bitmap", Value => Options.Bitmap,
Options_String => Options_String);
Option_Image
(Name => "columnbreak", Value => Options.Column_Break,
Options_String => Options_String);
Option_Image
(Name => "command", Value => Options.Command,
Options_String => Options_String);
Option_Image
(Name => "compound", Value => Options.Compound,
Options_String => Options_String);
Option_Image
(Name => "font", Value => Options.Font,
Options_String => Options_String);
Option_Image
(Name => "foreground", Value => Options.Foreground,
Options_String => Options_String);
Option_Image
(Name => "hidemargin", Value => Options.Hide_Margin,
Options_String => Options_String);
Option_Image
(Name => "image", Value => Options.Image,
Options_String => Options_String);
Option_Image
(Name => "label", Value => Options.Label,
Options_String => Options_String);
Option_Image
(Name => "state", Value => Options.State,
Options_String => Options_String);
Option_Image
(Name => "underline", Value => Options.Underline,
Options_String => Options_String);
if Item_Type in CHECKBUTTON | RADIOBUTTON then
Option_Image
(Name => "indicatoron", Value => Options.Indicator_On,
Options_String => Options_String);
Option_Image
(Name => "selectcolor", Value => Options.Select_Color,
Options_String => Options_String);
Option_Image
(Name => "selectimage", Value => Options.Select_Image,
Options_String => Options_String);
Option_Image
(Name => "variable", Value => Options.Variable,
Options_String => Options_String);
end if;
if Item_Type = CHECKBUTTON then
Option_Image
(Name => "offvalue", Value => Options.Off_Value,
Options_String => Options_String);
Option_Image
(Name => "onvalue", Value => Options.On_Value,
Options_String => Options_String);
end if;
if Item_Type = RADIOBUTTON then
Option_Image
(Name => "value", Value => Options.Value,
Options_String => Options_String);
end if;
if Item_Type = CASCADE and then Options.Menu /= Null_Widget then
Append
(Source => Options_String,
New_Item => " -menu " & Tk_Path_Name(Widgt => Options.Menu));
end if;
return To_String(Source => Options_String);
end Item_Options_To_String;
procedure Add(Menu_Widget: Tk_Menu; Options: Menu_Item_Options) is
begin
Execute_Widget_Command
(Widgt => Menu_Widget, Command_Name => "add",
Options =>
To_Lower(Item => Menu_Item_Types'Image(Options.Item_Type)) & " " &
Item_Options_To_String
(Options => Options, Item_Type => Options.Item_Type));
end Add;
function Get_Options(Menu_Widget: Tk_Menu) return Menu_Options is
begin
return Options: Menu_Options := Default_Menu_Options do
Options.Active_Background :=
Option_Value(Widgt => Menu_Widget, Name => "activebackground");
Options.Active_Border_Width :=
Option_Value(Widgt => Menu_Widget, Name => "activeborderwidth");
Options.Active_Foreground :=
Option_Value(Widgt => Menu_Widget, Name => "activeforeground");
Options.Background :=
Option_Value(Widgt => Menu_Widget, Name => "background");
Options.Border_Width :=
Option_Value(Widgt => Menu_Widget, Name => "borderwidth");
Options.Cursor :=
Option_Value(Widgt => Menu_Widget, Name => "cursor");
Options.Disabled_Foreground :=
Option_Value(Widgt => Menu_Widget, Name => "disabledforeground");
Options.Font := Option_Value(Widgt => Menu_Widget, Name => "font");
Options.Foreground :=
Option_Value(Widgt => Menu_Widget, Name => "foreground");
Options.Relief :=
Option_Value(Widgt => Menu_Widget, Name => "relief");
Options.Post_Command :=
Option_Value(Widgt => Menu_Widget, Name => "postcommand");
Options.Select_Color :=
Option_Value(Widgt => Menu_Widget, Name => "selectcolor");
Options.Take_Focus :=
Option_Value(Widgt => Menu_Widget, Name => "takefocus");
Options.Tear_Off :=
Option_Value(Widgt => Menu_Widget, Name => "tearoff");
Options.Tear_Off_Command :=
Option_Value(Widgt => Menu_Widget, Name => "tearoffcommand");
Options.Title := Option_Value(Widgt => Menu_Widget, Name => "title");
Execute_Widget_Command
(Widgt => Menu_Widget, Command_Name => "cget", Options => "-type");
Options.Menu_Type :=
Menu_Types'Value
(Tcl_Get_Result(Interpreter => Tk_Interp(Widgt => Menu_Widget)));
end return;
end Get_Options;
procedure Configure(Menu_Widget: Tk_Menu; Options: Menu_Options) is
begin
Execute_Widget_Command
(Widgt => Menu_Widget, Command_Name => "configure",
Options => Options_To_String(Options => Options));
end Configure;
procedure Delete
(Menu_Widget: Tk_Menu; Index1: Tcl_String;
Index2: Tcl_String := To_Tcl_String(Source => "")) is
begin
Execute_Widget_Command
(Widgt => Menu_Widget, Command_Name => "delete",
Options =>
To_Ada_String(Source => Index1) & " " &
To_Ada_String(Source => Index2));
end Delete;
procedure Delete
(Menu_Widget: Tk_Menu; Index1: Natural; Index2: Extended_Natural := -1;
Is_Index1, Is_Index2: Boolean := True) is
New_Index1: constant String :=
(if Is_Index1 then Trim(Source => Natural'Image(Index1), Side => Left)
else "@" & Trim(Source => Natural'Image(Index1), Side => Left));
New_Index2: constant String :=
(if Is_Index2 then
Trim(Source => Extended_Natural'Image(Index2), Side => Left)
else "@" &
Trim(Source => Extended_Natural'Image(Index2), Side => Left));
begin
Execute_Widget_Command
(Widgt => Menu_Widget, Command_Name => "delete",
Options =>
New_Index1 & (if Index2 > -1 then " " & New_Index2 else ""));
end Delete;
procedure Delete
(Menu_Widget: Tk_Menu; Index1: Menu_Item_Indexes;
Index2: Menu_Item_Indexes := NONE) is
begin
Execute_Widget_Command
(Widgt => Menu_Widget, Command_Name => "delete",
Options =>
To_Lower(Item => Menu_Item_Indexes'Image(Index1)) &
(if Index2 = NONE then ""
else " " & To_Lower(Item => Menu_Item_Indexes'Image(Index2))));
end Delete;
function Entry_Get_Options
(Menu_Widget: Tk_Menu; Menu_Index: Tcl_String) return Menu_Item_Options is
Item_Type: Menu_Item_Types := Default_Menu_Item;
Interpreter: constant Tcl_Interpreter := Tk_Interp(Widgt => Menu_Widget);
function Item_Value(Name: String) return Tcl_String is
begin
return
To_Tcl_String
(Source =>
Execute_Widget_Command
(Widgt => Menu_Widget, Command_Name => "entrycget",
Options =>
To_Ada_String(Source => Menu_Index) & " -" & Name)
.Result);
end Item_Value;
function Item_Value(Name: String) return Extended_Boolean is
begin
Execute_Widget_Command
(Widgt => Menu_Widget, Command_Name => "entrycget",
Options => To_Ada_String(Source => Menu_Index) & " -" & Name);
if Tcl_Get_Result(Interpreter => Interpreter) = 1 then
return TRUE;
end if;
return FALSE;
end Item_Value;
begin
return Options: Menu_Item_Options := Default_Menu_Item_Options do
Execute_Widget_Command
(Widgt => Menu_Widget, Command_Name => "type",
Options => To_Ada_String(Source => Menu_Index));
Item_Type :=
Menu_Item_Types'Value(Tcl_Get_Result(Interpreter => Interpreter));
Options.Active_Background := Item_Value(Name => "activebackground");
Options.Active_Foreground := Item_Value(Name => "activeforeground");
Options.Accelerator := Item_Value(Name => "accelerator");
Options.Background := Item_Value(Name => "background");
Options.Bitmap := Item_Value(Name => "bitmap");
Options.Column_Break := Item_Value(Name => "columnbreak");
Options.Command := Item_Value(Name => "command");
Options.Compound :=
Place_Type'Value
(Execute_Widget_Command
(Widgt => Menu_Widget, Command_Name => "entrycget",
Options => To_Ada_String(Source => Menu_Index) & " -compound")
.Result);
Options.Font := Item_Value(Name => "font");
Options.Foreground := Item_Value(Name => "foreground");
Options.Hide_Margin := Item_Value(Name => "hidemargin");
Options.Image := Item_Value(Name => "image");
Options.Label := Item_Value(Name => "label");
Options.State :=
State_Type'Value
(Execute_Widget_Command
(Widgt => Menu_Widget, Command_Name => "entrycget",
Options => To_Ada_String(Source => Menu_Index) & " -state")
.Result);
Options.Underline :=
Extended_Natural'Value
(Execute_Widget_Command
(Widgt => Menu_Widget, Command_Name => "entrycget",
Options =>
To_Ada_String(Source => Menu_Index) & " -underline")
.Result);
case Item_Type is
when CASCADE =>
Options.Menu :=
Get_Widget
(Path_Name =>
Execute_Widget_Command
(Widgt => Menu_Widget, Command_Name => "entrycget",
Options =>
To_Ada_String(Source => Menu_Index) & " -menu")
.Result,
Interpreter => Interpreter);
when CHECKBUTTON | RADIOBUTTON =>
Options.Indicator_On := Item_Value(Name => "inditatoron");
Options.Select_Color := Item_Value(Name => "selectcolor");
Options.Select_Image := Item_Value(Name => "selectimage");
case Item_Type is
when CHECKBUTTON =>
Options.Off_Value := Item_Value(Name => "offvalue");
Options.On_Value := Item_Value(Name => "onvalue");
when RADIOBUTTON =>
Options.Value := Item_Value(Name => "value");
when others =>
null;
end case;
when others =>
null;
end case;
end return;
end Entry_Get_Options;
function Entry_Get_Options
(Menu_Widget: Tk_Menu; Menu_Index: Natural; Is_Index: Boolean := True)
return Menu_Item_Options is
New_Index: constant Tcl_String :=
(if Is_Index then
To_Tcl_String
(Source =>
Trim(Source => Natural'Image(Menu_Index), Side => Left))
else To_Tcl_String
(Source =>
"@" &
Trim(Source => Natural'Image(Menu_Index), Side => Left)));
begin
return
Entry_Get_Options(Menu_Widget => Menu_Widget, Menu_Index => New_Index);
end Entry_Get_Options;
function Entry_Get_Options
(Menu_Widget: Tk_Menu; Menu_Index: Menu_Item_Indexes)
return Menu_Item_Options is
begin
return
Entry_Get_Options
(Menu_Widget => Menu_Widget,
Menu_Index =>
To_Tcl_String
(Source =>
To_Lower(Item => Menu_Item_Indexes'Image(Menu_Index))));
end Entry_Get_Options;
procedure Entry_Configure
(Menu_Widget: Tk_Menu; Menu_Index: Tcl_String;
Options: Menu_Item_Options) is
begin
Execute_Widget_Command
(Widgt => Menu_Widget, Command_Name => "entryconfigure",
Options =>
To_Ada_String(Source => Menu_Index) & " " &
Item_Options_To_String
(Options => Options,
Item_Type =>
Menu_Item_Types'Value
(Execute_Widget_Command
(Widgt => Menu_Widget, Command_Name => "type",
Options => To_Ada_String(Source => Menu_Index))
.Result)));
end Entry_Configure;
procedure Entry_Configure
(Menu_Widget: Tk_Menu; Menu_Index: Natural; Options: Menu_Item_Options;
Is_Index: Boolean := True) is
New_Index: constant String :=
(if Is_Index then
Trim(Source => Natural'Image(Menu_Index), Side => Left)
else "@" & Trim(Source => Natural'Image(Menu_Index), Side => Left));
begin
Execute_Widget_Command
(Widgt => Menu_Widget, Command_Name => "entryconfigure",
Options =>
New_Index & " " &
Item_Options_To_String
(Options => Options,
Item_Type =>
Menu_Item_Types'Value
(Execute_Widget_Command
(Widgt => Menu_Widget, Command_Name => "type",
Options => New_Index)
.Result)));
end Entry_Configure;
procedure Entry_Configure
(Menu_Widget: Tk_Menu; Menu_Index: Menu_Item_Indexes;
Options: Menu_Item_Options) is
begin
Execute_Widget_Command
(Widgt => Menu_Widget, Command_Name => "entryconfigure",
Options =>
To_Lower(Item => Menu_Item_Indexes'Image(Menu_Index)) & " " &
Item_Options_To_String
(Options => Options,
Item_Type =>
Menu_Item_Types'Value
(Execute_Widget_Command
(Widgt => Menu_Widget, Command_Name => "type",
Options =>
To_Lower(Item => Menu_Item_Indexes'Image(Menu_Index)))
.Result)));
end Entry_Configure;
function Index
(Menu_Widget: Tk_Menu; Menu_Index: Tcl_String) return Extended_Natural is
Interpreter: constant Tcl_Interpreter := Tk_Interp(Widgt => Menu_Widget);
begin
Execute_Widget_Command
(Widgt => Menu_Widget, Command_Name => "index",
Options => To_Ada_String(Source => Menu_Index));
if Tcl_Get_Result(Interpreter => Interpreter) = "none" then
return -1;
end if;
return
Extended_Natural'Value(Tcl_Get_Result(Interpreter => Interpreter));
end Index;
function Index
(Menu_Widget: Tk_Menu; Menu_Index: Natural) return Extended_Natural is
Interpreter: constant Tcl_Interpreter := Tk_Interp(Widgt => Menu_Widget);
begin
Execute_Widget_Command
(Widgt => Menu_Widget, Command_Name => "index",
Options =>
"@" & Trim(Source => Natural'Image(Menu_Index), Side => Left));
if Tcl_Get_Result(Interpreter => Interpreter) = "none" then
return -1;
end if;
return
Extended_Natural'Value(Tcl_Get_Result(Interpreter => Interpreter));
end Index;
function Index
(Menu_Widget: Tk_Menu; Menu_Index: Menu_Item_Indexes)
return Extended_Natural is
Interpreter: constant Tcl_Interpreter := Tk_Interp(Widgt => Menu_Widget);
begin
Execute_Widget_Command
(Widgt => Menu_Widget, Command_Name => "index",
Options => To_Lower(Item => Menu_Item_Indexes'Image(Menu_Index)));
if Tcl_Get_Result(Interpreter => Interpreter) = "none" then
return -1;
end if;
return
Extended_Natural'Value(Tcl_Get_Result(Interpreter => Interpreter));
end Index;
procedure Insert
(Menu_Widget: Tk_Menu; Menu_Index: Tcl_String; Item_Type: Menu_Item_Types;
Options: Menu_Item_Options) is
begin
Execute_Widget_Command
(Widgt => Menu_Widget, Command_Name => "insert",
Options =>
To_Ada_String(Source => Menu_Index) & " " &
To_Lower(Item => Menu_Item_Types'Image(Item_Type)) & " " &
Item_Options_To_String(Options => Options, Item_Type => Item_Type));
end Insert;
procedure Insert
(Menu_Widget: Tk_Menu; Menu_Index: Natural; Item_Type: Menu_Item_Types;
Options: Menu_Item_Options; Is_Index: Boolean := True) is
New_Index: constant String :=
(if Is_Index then
Trim(Source => Natural'Image(Menu_Index), Side => Left)
else "@" & Trim(Source => Natural'Image(Menu_Index), Side => Left));
begin
Execute_Widget_Command
(Widgt => Menu_Widget, Command_Name => "insert",
Options =>
New_Index & " " &
To_Lower(Item => Menu_Item_Types'Image(Item_Type)) & " " &
Item_Options_To_String(Options => Options, Item_Type => Item_Type));
end Insert;
procedure Insert
(Menu_Widget: Tk_Menu; Menu_Index: Menu_Item_Indexes;
Item_Type: Menu_Item_Types; Options: Menu_Item_Options) is
begin
Execute_Widget_Command
(Widgt => Menu_Widget, Command_Name => "insert",
Options =>
To_Lower(Item => Menu_Item_Indexes'Image(Menu_Index)) & " " &
To_Lower(Item => Menu_Item_Types'Image(Item_Type)) & " " &
Item_Options_To_String(Options => Options, Item_Type => Item_Type));
end Insert;
procedure Invoke(Menu_Widget: Tk_Menu; Menu_Index: Tcl_String) is
begin
Execute_Widget_Command
(Widgt => Menu_Widget, Command_Name => "invoke",
Options => To_Ada_String(Source => Menu_Index));
end Invoke;
procedure Invoke
(Menu_Widget: Tk_Menu; Menu_Index: Natural; Is_Index: Boolean := True) is
New_Index: constant String :=
(if Is_Index then
Trim(Source => Natural'Image(Menu_Index), Side => Left)
else "@" & Trim(Source => Natural'Image(Menu_Index), Side => Left));
begin
Execute_Widget_Command
(Widgt => Menu_Widget, Command_Name => "invoke", Options => New_Index);
end Invoke;
procedure Invoke(Menu_Widget: Tk_Menu; Menu_Index: Menu_Item_Indexes) is
begin
Execute_Widget_Command
(Widgt => Menu_Widget, Command_Name => "invoke",
Options => To_Lower(Item => Menu_Item_Indexes'Image(Menu_Index)));
end Invoke;
function Invoke
(Menu_Widget: Tk_Menu; Menu_Index: Tcl_String) return String is
begin
Invoke(Menu_Widget => Menu_Widget, Menu_Index => Menu_Index);
return Tcl_Get_Result(Interpreter => Tk_Interp(Widgt => Menu_Widget));
end Invoke;
function Invoke
(Menu_Widget: Tk_Menu; Menu_Index: Natural; Is_Index: Boolean := True)
return String is
begin
Invoke
(Menu_Widget => Menu_Widget, Menu_Index => Menu_Index,
Is_Index => Is_Index);
return Tcl_Get_Result(Interpreter => Tk_Interp(Widgt => Menu_Widget));
end Invoke;
function Invoke
(Menu_Widget: Tk_Menu; Menu_Index: Menu_Item_Indexes) return String is
begin
Invoke(Menu_Widget => Menu_Widget, Menu_Index => Menu_Index);
return Tcl_Get_Result(Interpreter => Tk_Interp(Widgt => Menu_Widget));
end Invoke;
procedure Post(Menu_Widget: Tk_Menu; X, Y: Natural) is
begin
Execute_Widget_Command
(Widgt => Menu_Widget, Command_Name => "post",
Options =>
Trim(Source => Natural'Image(X), Side => Left) & Natural'Image(Y));
end Post;
function Post(Menu_Widget: Tk_Menu; X, Y: Natural) return String is
begin
Post(Menu_Widget => Menu_Widget, X => X, Y => Y);
return Tcl_Get_Result(Interpreter => Tk_Interp(Widgt => Menu_Widget));
end Post;
procedure Post_Cascade(Menu_Widget: Tk_Menu; Menu_Index: Tcl_String) is
begin
Execute_Widget_Command
(Widgt => Menu_Widget, Command_Name => "postcascade",
Options => To_Ada_String(Source => Menu_Index));
end Post_Cascade;
procedure Post_Cascade
(Menu_Widget: Tk_Menu; Menu_Index: Natural; Is_Index: Boolean := True) is
New_Index: constant String :=
(if Is_Index then
Trim(Source => Natural'Image(Menu_Index), Side => Left)
else "@" & Trim(Source => Natural'Image(Menu_Index), Side => Left));
begin
Execute_Widget_Command
(Widgt => Menu_Widget, Command_Name => "postcascade",
Options => New_Index);
end Post_Cascade;
procedure Post_Cascade
(Menu_Widget: Tk_Menu; Menu_Index: Menu_Item_Indexes) is
begin
Execute_Widget_Command
(Widgt => Menu_Widget, Command_Name => "postcascade",
Options => To_Lower(Item => Menu_Item_Indexes'Image(Menu_Index)));
end Post_Cascade;
function Get_Item_Type
(Menu_Widget: Tk_Menu; Menu_Index: Tcl_String) return Menu_Item_Types is
begin
return
Menu_Item_Types'Value
(Execute_Widget_Command
(Widgt => Menu_Widget, Command_Name => "type",
Options => To_Ada_String(Source => Menu_Index))
.Result);
end Get_Item_Type;
function Get_Item_Type
(Menu_Widget: Tk_Menu; Menu_Index: Natural; Is_Index: Boolean := True)
return Menu_Item_Types is
New_Index: constant String :=
(if Is_Index then
Trim(Source => Natural'Image(Menu_Index), Side => Left)
else "@" & Trim(Source => Natural'Image(Menu_Index), Side => Left));
begin
return
Menu_Item_Types'Value
(Execute_Widget_Command
(Widgt => Menu_Widget, Command_Name => "type",
Options => New_Index)
.Result);
end Get_Item_Type;
function Get_Item_Type
(Menu_Widget: Tk_Menu; Menu_Index: Menu_Item_Indexes)
return Menu_Item_Types is
begin
return
Menu_Item_Types'Value
(Execute_Widget_Command
(Widgt => Menu_Widget, Command_Name => "type",
Options => To_Lower(Item => Menu_Item_Indexes'Image(Menu_Index)))
.Result);
end Get_Item_Type;
procedure Unpost(Menu_Widget: Tk_Menu) is
begin
Execute_Widget_Command(Widgt => Menu_Widget, Command_Name => "unpost");
end Unpost;
function X_Position
(Menu_Widget: Tk_Menu; Menu_Index: Tcl_String) return Natural is
begin
return
Natural'Value
(Execute_Widget_Command
(Widgt => Menu_Widget, Command_Name => "xposition",
Options => To_Ada_String(Source => Menu_Index))
.Result);
end X_Position;
function X_Position
(Menu_Widget: Tk_Menu; Menu_Index: Natural; Is_Index: Boolean := True)
return Natural is
New_Index: constant String :=
(if Is_Index then
Trim(Source => Natural'Image(Menu_Index), Side => Left)
else "@" & Trim(Source => Natural'Image(Menu_Index), Side => Left));
begin
return
Natural'Value
(Execute_Widget_Command
(Widgt => Menu_Widget, Command_Name => "xposition",
Options => New_Index)
.Result);
end X_Position;
function X_Position
(Menu_Widget: Tk_Menu; Menu_Index: Menu_Item_Indexes) return Natural is
begin
return
Natural'Value
(Execute_Widget_Command
(Widgt => Menu_Widget, Command_Name => "xposition",
Options => To_Lower(Item => Menu_Item_Indexes'Image(Menu_Index)))
.Result);
end X_Position;
function Y_Position
(Menu_Widget: Tk_Menu; Menu_Index: Tcl_String) return Natural is
begin
return
Natural'Value
(Execute_Widget_Command
(Widgt => Menu_Widget, Command_Name => "yposition",
Options => To_Ada_String(Source => Menu_Index))
.Result);
end Y_Position;
function Y_Position
(Menu_Widget: Tk_Menu; Menu_Index: Natural; Is_Index: Boolean := True)
return Natural is
New_Index: constant String :=
(if Is_Index then
Trim(Source => Natural'Image(Menu_Index), Side => Left)
else "@" & Trim(Source => Natural'Image(Menu_Index), Side => Left));
begin
return
Natural'Value
(Execute_Widget_Command
(Widgt => Menu_Widget, Command_Name => "yposition",
Options => New_Index)
.Result);
end Y_Position;
function Y_Position
(Menu_Widget: Tk_Menu; Menu_Index: Menu_Item_Indexes) return Natural is
begin
return
Natural'Value
(Execute_Widget_Command
(Widgt => Menu_Widget, Command_Name => "yposition",
Options => To_Lower(Item => Menu_Item_Indexes'Image(Menu_Index)))
.Result);
end Y_Position;
end Tk.Menu;
|
pragma Ada_2012;
with System.Parameters;
generic
type U8 is mod <>;
type U32 is mod <>;
type SZT is mod <>;
package fastpbkdf2_h_generic with
Pure,
Preelaborate
is
pragma Compile_Time_Error
(U8'Modulus /= 2**8, "'U8' type must be mod 2**8");
pragma Compile_Time_Error
(U32'Modulus /= 2**32, "'U32' type must be mod 2**32");
pragma Compile_Time_Error
(SZT'Modulus /= 2**System.Parameters.ptr_bits,
"'SZT' type must be 2**(system ptr bits)");
procedure fastpbkdf2_hmac_sha1
(pw : access constant U8; npw : SZT; salt : access constant U8;
nsalt : SZT; iterations : U32; c_out : access U8; nout : SZT) with
Import => True,
Convention => C,
External_Name => "fastpbkdf2_hmac_sha1";
procedure fastpbkdf2_hmac_sha256
(pw : access constant U8; npw : SZT; salt : access constant U8;
nsalt : SZT; iterations : U32; c_out : access U8; nout : SZT) with
Import => True,
Convention => C,
External_Name => "fastpbkdf2_hmac_sha256";
procedure fastpbkdf2_hmac_sha512
(pw : access constant U8; npw : SZT; salt : access constant U8;
nsalt : SZT; iterations : U32; c_out : access U8; nout : SZT) with
Import => True,
Convention => C,
External_Name => "fastpbkdf2_hmac_sha512";
end fastpbkdf2_h_generic;
|
with AUnit;
with AUnit.Test_Cases;
package Dl.Test_Basics is
type Test_Case is new AUnit.Test_Cases.Test_Case with null record;
procedure Register_Tests (T : in out Test_Case);
-- Register routines to be run
function Name (T : Test_Case)
return Aunit.Message_String;
-- Returns name identifying the test case
end Dl.Test_Basics;
|
with Picosystem.Pins;
with RP.Device;
with RP.UART;
with RP.GPIO;
with HAL.UART;
with HAL;
package body Console is
Initialized : Boolean := False;
Port : RP.UART.UART_Port renames RP.Device.UART_0;
procedure Initialize is
use RP.GPIO;
begin
Port.Configure;
Picosystem.Pins.UART_RX.Configure (Output, Floating, RP.GPIO.UART);
Picosystem.Pins.UART_TX.Configure (Output, Floating, RP.GPIO.UART);
Initialized := True;
end Initialize;
procedure Put
(C : Character)
is
use HAL.UART;
Data : UART_Data_8b (1 .. 1)
with Address => C'Address;
Status : UART_Status;
begin
if Initialized then
Port.Transmit (Data, Status, Timeout => 0);
end if;
end Put;
end Console;
|
with Ada.Text_IO; use Ada.Text_IO;
package body Types.Strings is
package Io is new Ada.Text_IO.Float_IO (Float);
function To_String
(Value : Float)
return String is
begin
-- Use IO package to convert number to a string
-- Use global objects from spec to control formatting
return "";
end To_String;
-- Implement
function To_String
(Value : Miles_T)
return String is
begin
return To_String (Float (Value));
end To_String;
function To_String
(Value : Hours_T)
return String is
begin
return To_String (Float (Value));
end To_String;
-- Implement functions to convert your types to strings
end Types.Strings;
|
with Sodium.Functions; use Sodium.Functions;
with Ada.Text_IO; use Ada.Text_IO;
procedure Demo_Ada
is
message : constant String := "JRM wrote this note.";
begin
if not initialize_sodium_library then
Put_Line ("Initialization failed");
return;
end if;
declare
new_public_sign_key : Public_Sign_Key;
new_secret_sign_key : Secret_Sign_Key;
new_signature_seed : Sign_Key_Seed := Random_Sign_Key_seed;
new_signature : Signature;
begin
Generate_Sign_Keys (new_public_sign_key, new_secret_sign_key);
Put_Line ("Public Key: " & As_Hexidecimal (new_public_sign_key));
Put_Line ("Secret Key: " & As_Hexidecimal (new_secret_sign_key));
new_signature := Obtain_Signature (message, new_secret_sign_key);
Put_Line ("Signature: " & As_Hexidecimal (new_signature));
if Signature_Matches (message, new_signature, new_public_sign_key) then
Put_Line ("Signature matches.");
else
Put_Line ("Signature does NOT match.");
end if;
Put_Line ("");
Put_Line ("Again, but generate key with a seed");
Generate_Sign_Keys (new_public_sign_key, new_secret_sign_key, new_signature_seed);
Put_Line ("Seed: " & As_Hexidecimal (new_signature_seed));
Put_Line ("Public Key: " & As_Hexidecimal (new_public_sign_key));
Put_Line ("Secret Key: " & As_Hexidecimal (new_secret_sign_key));
new_signature := Obtain_Signature (message, new_secret_sign_key);
Put_Line ("Signature: " & As_Hexidecimal (new_signature));
if Signature_Matches (message, new_signature, new_public_sign_key) then
Put_Line ("Signature matches.");
else
Put_Line ("Signature does NOT match.");
end if;
end;
end Demo_Ada;
|
------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- G N A T . S O C K E T S --
-- --
-- B o d y --
-- --
-- $Revision$
-- --
-- Copyright (C) 2001 Ada Core Technologies, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 2, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
-- for more details. You should have received a copy of the GNU General --
-- Public License distributed with GNAT; see file COPYING. If not, write --
-- to the Free Software Foundation, 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. --
-- --
-- GNAT is maintained by Ada Core Technologies Inc (http://www.gnat.com). --
-- --
------------------------------------------------------------------------------
with Ada.Streams; use Ada.Streams;
with Ada.Exceptions; use Ada.Exceptions;
with Ada.Unchecked_Deallocation;
with Ada.Unchecked_Conversion;
with Interfaces.C.Strings;
with GNAT.OS_Lib; use GNAT.OS_Lib;
with GNAT.Sockets.Constants;
with GNAT.Sockets.Thin; use GNAT.Sockets.Thin;
with GNAT.Task_Lock;
with GNAT.Sockets.Linker_Options;
pragma Warnings (Off, GNAT.Sockets.Linker_Options);
-- Need to include pragma Linker_Options which is platform dependent.
with System; use System;
package body GNAT.Sockets is
use type C.int, System.Address;
Finalized : Boolean := False;
Initialized : Boolean := False;
-- Correspondance tables
Families : constant array (Family_Type) of C.int :=
(Family_Inet => Constants.AF_INET,
Family_Inet6 => Constants.AF_INET6);
Levels : constant array (Level_Type) of C.int :=
(Socket_Level => Constants.SOL_SOCKET,
IP_Protocol_For_IP_Level => Constants.IPPROTO_IP,
IP_Protocol_For_UDP_Level => Constants.IPPROTO_UDP,
IP_Protocol_For_TCP_Level => Constants.IPPROTO_TCP);
Modes : constant array (Mode_Type) of C.int :=
(Socket_Stream => Constants.SOCK_STREAM,
Socket_Datagram => Constants.SOCK_DGRAM);
Shutmodes : constant array (Shutmode_Type) of C.int :=
(Shut_Read => Constants.SHUT_RD,
Shut_Write => Constants.SHUT_WR,
Shut_Read_Write => Constants.SHUT_RDWR);
Requests : constant array (Request_Name) of C.int :=
(Non_Blocking_IO => Constants.FIONBIO,
N_Bytes_To_Read => Constants.FIONREAD);
Options : constant array (Option_Name) of C.int :=
(Keep_Alive => Constants.SO_KEEPALIVE,
Reuse_Address => Constants.SO_REUSEADDR,
Broadcast => Constants.SO_BROADCAST,
Send_Buffer => Constants.SO_SNDBUF,
Receive_Buffer => Constants.SO_RCVBUF,
Linger => Constants.SO_LINGER,
Error => Constants.SO_ERROR,
No_Delay => Constants.TCP_NODELAY,
Add_Membership => Constants.IP_ADD_MEMBERSHIP,
Drop_Membership => Constants.IP_DROP_MEMBERSHIP,
Multicast_TTL => Constants.IP_MULTICAST_TTL,
Multicast_Loop => Constants.IP_MULTICAST_LOOP);
Socket_Error_Id : constant Exception_Id := Socket_Error'Identity;
Host_Error_Id : constant Exception_Id := Host_Error'Identity;
Hex_To_Char : constant String (1 .. 16) := "0123456789ABCDEF";
-- Use to print in hexadecimal format
function To_In_Addr is new Ada.Unchecked_Conversion (C.int, In_Addr);
function To_Int is new Ada.Unchecked_Conversion (In_Addr, C.int);
-----------------------
-- Local subprograms --
-----------------------
function Resolve_Error
(Error_Value : Integer;
From_Errno : Boolean := True)
return Error_Type;
-- Associate an enumeration value (error_type) to en error value
-- (errno). From_Errno prevents from mixing h_errno with errno.
function To_Host_Name (N : String) return Host_Name_Type;
function To_String (HN : Host_Name_Type) return String;
-- Conversion functions
function Port_To_Network
(Port : C.unsigned_short)
return C.unsigned_short;
pragma Inline (Port_To_Network);
-- Convert a port number into a network port number
function Network_To_Port
(Net_Port : C.unsigned_short)
return C.unsigned_short
renames Port_To_Network;
-- Symetric operation
function Image
(Val : Inet_Addr_VN_Type;
Hex : Boolean := False)
return String;
-- Output an array of inet address components either in
-- hexadecimal or in decimal mode.
function To_In_Addr (Addr : Inet_Addr_Type) return Thin.In_Addr;
function To_Inet_Addr (Addr : In_Addr) return Inet_Addr_Type;
-- Conversion functions
function To_Host_Entry (Host : Hostent) return Host_Entry_Type;
-- Conversion function
function To_Timeval (Val : Duration) return Timeval;
-- Separate Val in seconds and microseconds
procedure Raise_Socket_Error (Error : Integer);
-- Raise Socket_Error with an exception message describing
-- the error code.
procedure Raise_Host_Error (Error : Integer);
-- Raise Host_Error exception with message describing error code
-- (note hstrerror seems to be obsolete).
-- Types needed for Socket_Set_Type
type Socket_Set_Record is new Fd_Set;
procedure Free is
new Ada.Unchecked_Deallocation (Socket_Set_Record, Socket_Set_Type);
-- Types needed for Datagram_Socket_Stream_Type
type Datagram_Socket_Stream_Type is new Root_Stream_Type with record
Socket : Socket_Type;
To : Sock_Addr_Type;
From : Sock_Addr_Type;
end record;
type Datagram_Socket_Stream_Access is
access all Datagram_Socket_Stream_Type;
procedure Read
(Stream : in out Datagram_Socket_Stream_Type;
Item : out Ada.Streams.Stream_Element_Array;
Last : out Ada.Streams.Stream_Element_Offset);
procedure Write
(Stream : in out Datagram_Socket_Stream_Type;
Item : Ada.Streams.Stream_Element_Array);
-- Types needed for Stream_Socket_Stream_Type
type Stream_Socket_Stream_Type is new Root_Stream_Type with record
Socket : Socket_Type;
end record;
type Stream_Socket_Stream_Access is
access all Stream_Socket_Stream_Type;
procedure Read
(Stream : in out Stream_Socket_Stream_Type;
Item : out Ada.Streams.Stream_Element_Array;
Last : out Ada.Streams.Stream_Element_Offset);
procedure Write
(Stream : in out Stream_Socket_Stream_Type;
Item : Ada.Streams.Stream_Element_Array);
--------------------
-- Abort_Selector --
--------------------
procedure Abort_Selector (Selector : Selector_Type) is
begin
-- Send an empty array to unblock C select system call
if Selector.In_Progress then
declare
Buf : Character;
Res : C.int;
begin
Res := C_Write (C.int (Selector.W_Sig_Socket), Buf'Address, 0);
end;
end if;
end Abort_Selector;
-------------------
-- Accept_Socket --
-------------------
procedure Accept_Socket
(Server : Socket_Type;
Socket : out Socket_Type;
Address : out Sock_Addr_Type)
is
Res : C.int;
Sin : aliased Sockaddr_In;
Len : aliased C.int := Sin'Size / 8;
begin
Res := C_Accept (C.int (Server), Sin'Address, Len'Access);
if Res = Failure then
Raise_Socket_Error (Socket_Errno);
end if;
Socket := Socket_Type (Res);
Address.Addr := To_Inet_Addr (Sin.Sin_Addr);
Address.Port := Port_Type (Network_To_Port (Sin.Sin_Port));
end Accept_Socket;
---------------
-- Addresses --
---------------
function Addresses
(E : Host_Entry_Type;
N : Positive := 1)
return Inet_Addr_Type
is
begin
return E.Addresses (N);
end Addresses;
----------------------
-- Addresses_Length --
----------------------
function Addresses_Length (E : Host_Entry_Type) return Natural is
begin
return E.Addresses_Length;
end Addresses_Length;
-------------
-- Aliases --
-------------
function Aliases
(E : Host_Entry_Type;
N : Positive := 1)
return String
is
begin
return To_String (E.Aliases (N));
end Aliases;
--------------------
-- Aliases_Length --
--------------------
function Aliases_Length (E : Host_Entry_Type) return Natural is
begin
return E.Aliases_Length;
end Aliases_Length;
-----------------
-- Bind_Socket --
-----------------
procedure Bind_Socket
(Socket : Socket_Type;
Address : Sock_Addr_Type)
is
Res : C.int;
Sin : aliased Sockaddr_In;
Len : aliased C.int := Sin'Size / 8;
begin
if Address.Family = Family_Inet6 then
raise Socket_Error;
end if;
Sin.Sin_Family := C.unsigned_short (Families (Address.Family));
Sin.Sin_Port := Port_To_Network (C.unsigned_short (Address.Port));
Res := C_Bind (C.int (Socket), Sin'Address, Len);
if Res = Failure then
Raise_Socket_Error (Socket_Errno);
end if;
end Bind_Socket;
--------------------
-- Check_Selector --
--------------------
procedure Check_Selector
(Selector : in out Selector_Type;
R_Socket_Set : in out Socket_Set_Type;
W_Socket_Set : in out Socket_Set_Type;
Status : out Selector_Status;
Timeout : Duration := Forever)
is
Res : C.int;
Len : C.int;
RSet : aliased Fd_Set;
WSet : aliased Fd_Set;
TVal : aliased Timeval;
TPtr : Timeval_Access;
begin
Status := Completed;
-- No timeout or Forever is indicated by a null timeval pointer.
if Timeout = Forever then
TPtr := null;
else
TVal := To_Timeval (Timeout);
TPtr := TVal'Unchecked_Access;
end if;
-- Copy R_Socket_Set in RSet and add read signalling socket.
if R_Socket_Set = null then
RSet := Null_Fd_Set;
else
RSet := Fd_Set (R_Socket_Set.all);
end if;
Set (RSet, C.int (Selector.R_Sig_Socket));
Len := Max (RSet) + 1;
-- Copy W_Socket_Set in WSet.
if W_Socket_Set = null then
WSet := Null_Fd_Set;
else
WSet := Fd_Set (W_Socket_Set.all);
end if;
Len := C.int'Max (Max (RSet) + 1, Len);
Selector.In_Progress := True;
Res :=
C_Select
(Len,
RSet'Unchecked_Access,
WSet'Unchecked_Access,
null, TPtr);
Selector.In_Progress := False;
-- If Select was resumed because of read signalling socket,
-- read this data and remove socket from set.
if Is_Set (RSet, C.int (Selector.R_Sig_Socket)) then
Clear (RSet, C.int (Selector.R_Sig_Socket));
declare
Buf : Character;
begin
Res := C_Read (C.int (Selector.R_Sig_Socket), Buf'Address, 0);
end;
-- Select was resumed because of read signalling socket, but
-- the call is said aborted only when there is no other read
-- or write event.
if Is_Empty (RSet)
and then Is_Empty (WSet)
then
Status := Aborted;
end if;
elsif Res = 0 then
Status := Expired;
end if;
if R_Socket_Set /= null then
R_Socket_Set.all := Socket_Set_Record (RSet);
end if;
if W_Socket_Set /= null then
W_Socket_Set.all := Socket_Set_Record (WSet);
end if;
end Check_Selector;
-----------
-- Clear --
-----------
procedure Clear
(Item : in out Socket_Set_Type;
Socket : Socket_Type)
is
begin
if Item = null then
Item := new Socket_Set_Record;
Empty (Fd_Set (Item.all));
end if;
Clear (Fd_Set (Item.all), C.int (Socket));
end Clear;
--------------------
-- Close_Selector --
--------------------
procedure Close_Selector (Selector : in out Selector_Type) is
begin
begin
Close_Socket (Selector.R_Sig_Socket);
exception when Socket_Error =>
null;
end;
begin
Close_Socket (Selector.W_Sig_Socket);
exception when Socket_Error =>
null;
end;
end Close_Selector;
------------------
-- Close_Socket --
------------------
procedure Close_Socket (Socket : Socket_Type) is
Res : C.int;
begin
Res := C_Close (C.int (Socket));
if Res = Failure then
Raise_Socket_Error (Socket_Errno);
end if;
end Close_Socket;
--------------------
-- Connect_Socket --
--------------------
procedure Connect_Socket
(Socket : Socket_Type;
Server : in out Sock_Addr_Type)
is
Res : C.int;
Sin : aliased Sockaddr_In;
Len : aliased C.int := Sin'Size / 8;
begin
if Server.Family = Family_Inet6 then
raise Socket_Error;
end if;
Sin.Sin_Family := C.unsigned_short (Families (Server.Family));
Sin.Sin_Addr := To_In_Addr (Server.Addr);
Sin.Sin_Port := Port_To_Network (C.unsigned_short (Server.Port));
Res := C_Connect (C.int (Socket), Sin'Address, Len);
if Res = Failure then
Raise_Socket_Error (Socket_Errno);
end if;
end Connect_Socket;
--------------------
-- Control_Socket --
--------------------
procedure Control_Socket
(Socket : Socket_Type;
Request : in out Request_Type)
is
Arg : aliased C.int;
Res : C.int;
begin
case Request.Name is
when Non_Blocking_IO =>
Arg := C.int (Boolean'Pos (Request.Enabled));
when N_Bytes_To_Read =>
null;
end case;
Res := C_Ioctl
(C.int (Socket),
Requests (Request.Name),
Arg'Unchecked_Access);
if Res = Failure then
Raise_Socket_Error (Socket_Errno);
end if;
case Request.Name is
when Non_Blocking_IO =>
null;
when N_Bytes_To_Read =>
Request.Size := Natural (Arg);
end case;
end Control_Socket;
---------------------
-- Create_Selector --
---------------------
procedure Create_Selector (Selector : out Selector_Type) is
S0 : C.int;
S1 : C.int;
S2 : C.int;
Res : C.int;
Sin : aliased Sockaddr_In;
Len : aliased C.int := Sin'Size / 8;
Err : Integer;
begin
-- We open two signalling sockets. One socket to send a signal
-- to a another socket that always included in a C_Select
-- socket set. When received, it resumes the task suspended in
-- C_Select.
-- Create a listening socket
S0 := C_Socket (Constants.AF_INET, Constants.SOCK_STREAM, 0);
if S0 = Failure then
Raise_Socket_Error (Socket_Errno);
end if;
-- Sin is already correctly initialized. Bind the socket to any
-- unused port.
Res := C_Bind (S0, Sin'Address, Len);
if Res = Failure then
Err := Socket_Errno;
Res := C_Close (S0);
Raise_Socket_Error (Err);
end if;
-- Get the port used by the socket
Res := C_Getsockname (S0, Sin'Address, Len'Access);
if Res = Failure then
Err := Socket_Errno;
Res := C_Close (S0);
Raise_Socket_Error (Err);
end if;
Res := C_Listen (S0, 2);
if Res = Failure then
Err := Socket_Errno;
Res := C_Close (S0);
Raise_Socket_Error (Err);
end if;
S1 := C_Socket (Constants.AF_INET, Constants.SOCK_STREAM, 0);
if S1 = Failure then
Err := Socket_Errno;
Res := C_Close (S0);
Raise_Socket_Error (Err);
end if;
-- Use INADDR_LOOPBACK
Sin.Sin_Addr.S_B1 := 127;
Sin.Sin_Addr.S_B2 := 0;
Sin.Sin_Addr.S_B3 := 0;
Sin.Sin_Addr.S_B4 := 1;
-- Do a connect and accept the connection
Res := C_Connect (S1, Sin'Address, Len);
if Res = Failure then
Err := Socket_Errno;
Res := C_Close (S0);
Res := C_Close (S1);
Raise_Socket_Error (Err);
end if;
S2 := C_Accept (S0, Sin'Address, Len'Access);
if S2 = Failure then
Err := Socket_Errno;
Res := C_Close (S0);
Res := C_Close (S1);
Raise_Socket_Error (Err);
end if;
Res := C_Close (S0);
if Res = Failure then
Raise_Socket_Error (Socket_Errno);
end if;
Selector.R_Sig_Socket := Socket_Type (S1);
Selector.W_Sig_Socket := Socket_Type (S2);
end Create_Selector;
-------------------
-- Create_Socket --
-------------------
procedure Create_Socket
(Socket : out Socket_Type;
Family : Family_Type := Family_Inet;
Mode : Mode_Type := Socket_Stream)
is
Res : C.int;
begin
Res := C_Socket (Families (Family), Modes (Mode), 0);
if Res = Failure then
Raise_Socket_Error (Socket_Errno);
end if;
Socket := Socket_Type (Res);
end Create_Socket;
-----------
-- Empty --
-----------
procedure Empty (Item : in out Socket_Set_Type) is
begin
if Item /= null then
Free (Item);
end if;
end Empty;
--------------
-- Finalize --
--------------
procedure Finalize is
begin
if not Finalized
and then Initialized
then
Finalized := True;
Thin.Finalize;
end if;
end Finalize;
-----------------
-- Get_Address --
-----------------
function Get_Address (Stream : Stream_Access) return Sock_Addr_Type is
begin
if Stream = null then
raise Socket_Error;
elsif Stream.all in Datagram_Socket_Stream_Type then
return Datagram_Socket_Stream_Type (Stream.all).From;
else
return Get_Peer_Name (Stream_Socket_Stream_Type (Stream.all).Socket);
end if;
end Get_Address;
-------------------------
-- Get_Host_By_Address --
-------------------------
function Get_Host_By_Address
(Address : Inet_Addr_Type;
Family : Family_Type := Family_Inet)
return Host_Entry_Type
is
HA : aliased In_Addr := To_In_Addr (Address);
Res : Hostent_Access;
Err : Integer;
begin
-- This C function is not always thread-safe. Protect against
-- concurrent access.
Task_Lock.Lock;
Res := C_Gethostbyaddr (HA'Address, HA'Size / 8, Constants.AF_INET);
if Res = null then
Err := Socket_Errno;
Task_Lock.Unlock;
Raise_Host_Error (Err);
end if;
-- Translate from the C format to the API format
declare
HE : Host_Entry_Type := To_Host_Entry (Res.all);
begin
Task_Lock.Unlock;
return HE;
end;
end Get_Host_By_Address;
----------------------
-- Get_Host_By_Name --
----------------------
function Get_Host_By_Name
(Name : String)
return Host_Entry_Type
is
HN : C.char_array := C.To_C (Name);
Res : Hostent_Access;
Err : Integer;
begin
-- This C function is not always thread-safe. Protect against
-- concurrent access.
Task_Lock.Lock;
Res := C_Gethostbyname (HN);
if Res = null then
Err := Socket_Errno;
Task_Lock.Unlock;
Raise_Host_Error (Err);
end if;
-- Translate from the C format to the API format
declare
HE : Host_Entry_Type := To_Host_Entry (Res.all);
begin
Task_Lock.Unlock;
return HE;
end;
end Get_Host_By_Name;
-------------------
-- Get_Peer_Name --
-------------------
function Get_Peer_Name
(Socket : Socket_Type)
return Sock_Addr_Type
is
Sin : aliased Sockaddr_In;
Len : aliased C.int := Sin'Size / 8;
Res : Sock_Addr_Type (Family_Inet);
begin
if C_Getpeername (C.int (Socket), Sin'Address, Len'Access) = Failure then
Raise_Socket_Error (Socket_Errno);
end if;
Res.Addr := To_Inet_Addr (Sin.Sin_Addr);
Res.Port := Port_Type (Network_To_Port (Sin.Sin_Port));
return Res;
end Get_Peer_Name;
---------------------
-- Get_Socket_Name --
---------------------
function Get_Socket_Name
(Socket : Socket_Type)
return Sock_Addr_Type
is
Sin : aliased Sockaddr_In;
Len : aliased C.int := Sin'Size / 8;
Res : Sock_Addr_Type (Family_Inet);
begin
if C_Getsockname (C.int (Socket), Sin'Address, Len'Access) = Failure then
Raise_Socket_Error (Socket_Errno);
end if;
Res.Addr := To_Inet_Addr (Sin.Sin_Addr);
Res.Port := Port_Type (Network_To_Port (Sin.Sin_Port));
return Res;
end Get_Socket_Name;
-----------------------
-- Get_Socket_Option --
-----------------------
function Get_Socket_Option
(Socket : Socket_Type;
Level : Level_Type := Socket_Level;
Name : Option_Name)
return Option_Type
is
use type C.unsigned_char;
V8 : aliased Two_Int;
V4 : aliased C.int;
V1 : aliased C.unsigned_char;
Len : aliased C.int;
Add : System.Address;
Res : C.int;
Opt : Option_Type (Name);
begin
case Name is
when Multicast_Loop |
Multicast_TTL =>
Len := V1'Size / 8;
Add := V1'Address;
when Keep_Alive |
Reuse_Address |
Broadcast |
No_Delay |
Send_Buffer |
Receive_Buffer |
Error =>
Len := V4'Size / 8;
Add := V4'Address;
when Linger |
Add_Membership |
Drop_Membership =>
Len := V8'Size / 8;
Add := V8'Address;
end case;
Res := C_Getsockopt
(C.int (Socket),
Levels (Level),
Options (Name),
Add, Len'Unchecked_Access);
if Res = Failure then
Raise_Socket_Error (Socket_Errno);
end if;
case Name is
when Keep_Alive |
Reuse_Address |
Broadcast |
No_Delay =>
Opt.Enabled := (V4 /= 0);
when Linger =>
Opt.Enabled := (V8 (V8'First) /= 0);
Opt.Seconds := Natural (V8 (V8'Last));
when Send_Buffer |
Receive_Buffer =>
Opt.Size := Natural (V4);
when Error =>
Opt.Error := Resolve_Error (Integer (V4));
when Add_Membership |
Drop_Membership =>
Opt.Multiaddr := To_Inet_Addr (To_In_Addr (V8 (V8'First)));
Opt.Interface := To_Inet_Addr (To_In_Addr (V8 (V8'Last)));
when Multicast_TTL =>
Opt.Time_To_Live := Integer (V1);
when Multicast_Loop =>
Opt.Enabled := (V1 /= 0);
end case;
return Opt;
end Get_Socket_Option;
---------------
-- Host_Name --
---------------
function Host_Name return String is
Name : aliased C.char_array (1 .. 64);
Res : C.int;
begin
Res := C_Gethostname (Name'Address, Name'Length);
if Res = Failure then
Raise_Socket_Error (Socket_Errno);
end if;
return C.To_Ada (Name);
end Host_Name;
-----------
-- Image --
-----------
function Image
(Val : Inet_Addr_VN_Type;
Hex : Boolean := False)
return String
is
-- The largest Inet_Addr_Comp_Type image occurs with IPv4. It
-- has at most a length of 3 plus one '.' character.
Buffer : String (1 .. 4 * Val'Length);
Length : Natural := 1;
Separator : Character;
procedure Img10 (V : Inet_Addr_Comp_Type);
-- Append to Buffer image of V in decimal format
procedure Img16 (V : Inet_Addr_Comp_Type);
-- Append to Buffer image of V in hexadecimal format
procedure Img10 (V : Inet_Addr_Comp_Type) is
Img : constant String := V'Img;
Len : Natural := Img'Length - 1;
begin
Buffer (Length .. Length + Len - 1) := Img (2 .. Img'Last);
Length := Length + Len;
end Img10;
procedure Img16 (V : Inet_Addr_Comp_Type) is
begin
Buffer (Length) := Hex_To_Char (Natural (V / 16) + 1);
Buffer (Length + 1) := Hex_To_Char (Natural (V mod 16) + 1);
Length := Length + 2;
end Img16;
-- Start of processing for Image
begin
if Hex then
Separator := ':';
else
Separator := '.';
end if;
for J in Val'Range loop
if Hex then
Img16 (Val (J));
else
Img10 (Val (J));
end if;
if J /= Val'Last then
Buffer (Length) := Separator;
Length := Length + 1;
end if;
end loop;
return Buffer (1 .. Length - 1);
end Image;
-----------
-- Image --
-----------
function Image (Value : Inet_Addr_Type) return String is
begin
if Value.Family = Family_Inet then
return Image (Inet_Addr_VN_Type (Value.Sin_V4), Hex => False);
else
return Image (Inet_Addr_VN_Type (Value.Sin_V6), Hex => True);
end if;
end Image;
-----------
-- Image --
-----------
function Image (Value : Sock_Addr_Type) return String is
Port : constant String := Value.Port'Img;
begin
return Image (Value.Addr) & ':' & Port (2 .. Port'Last);
end Image;
-----------
-- Image --
-----------
function Image (Socket : Socket_Type) return String is
begin
return Socket'Img;
end Image;
---------------
-- Inet_Addr --
---------------
function Inet_Addr (Image : String) return Inet_Addr_Type is
use Interfaces.C.Strings;
Img : chars_ptr := New_String (Image);
Res : C.int;
Err : Integer;
begin
Res := C_Inet_Addr (Img);
Err := Errno;
Free (Img);
if Res = Failure then
Raise_Socket_Error (Err);
end if;
return To_Inet_Addr (To_In_Addr (Res));
end Inet_Addr;
----------------
-- Initialize --
----------------
procedure Initialize (Process_Blocking_IO : Boolean := False) is
begin
if not Initialized then
Initialized := True;
Thin.Initialize (Process_Blocking_IO);
end if;
end Initialize;
--------------
-- Is_Empty --
--------------
function Is_Empty (Item : Socket_Set_Type) return Boolean is
begin
return Item = null or else Is_Empty (Fd_Set (Item.all));
end Is_Empty;
------------
-- Is_Set --
------------
function Is_Set
(Item : Socket_Set_Type;
Socket : Socket_Type) return Boolean
is
begin
return Item /= null
and then Is_Set (Fd_Set (Item.all), C.int (Socket));
end Is_Set;
-------------------
-- Listen_Socket --
-------------------
procedure Listen_Socket
(Socket : Socket_Type;
Length : Positive := 15)
is
Res : C.int;
begin
Res := C_Listen (C.int (Socket), C.int (Length));
if Res = Failure then
Raise_Socket_Error (Socket_Errno);
end if;
end Listen_Socket;
-------------------
-- Official_Name --
-------------------
function Official_Name (E : Host_Entry_Type) return String is
begin
return To_String (E.Official);
end Official_Name;
---------------------
-- Port_To_Network --
---------------------
function Port_To_Network
(Port : C.unsigned_short)
return C.unsigned_short
is
use type C.unsigned_short;
begin
if Default_Bit_Order = High_Order_First then
-- No conversion needed. On these platforms, htons() defaults
-- to a null procedure.
return Port;
else
-- We need to swap the high and low byte on this short to make
-- the port number network compliant.
return (Port / 256) + (Port mod 256) * 256;
end if;
end Port_To_Network;
----------------------
-- Raise_Host_Error --
----------------------
procedure Raise_Host_Error (Error : Integer) is
function Error_Message return String;
-- We do not use a C function like strerror because hstrerror
-- that would correspond seems to be obsolete. Return
-- appropriate string for error value.
function Error_Message return String is
begin
case Error is
when Constants.HOST_NOT_FOUND => return "Host not found";
when Constants.TRY_AGAIN => return "Try again";
when Constants.NO_RECOVERY => return "No recovery";
when Constants.NO_ADDRESS => return "No address";
when others => return "Unknown error";
end case;
end Error_Message;
-- Start of processing for Raise_Host_Error
begin
Ada.Exceptions.Raise_Exception (Host_Error'Identity, Error_Message);
end Raise_Host_Error;
------------------------
-- Raise_Socket_Error --
------------------------
procedure Raise_Socket_Error (Error : Integer) is
use type C.Strings.chars_ptr;
function Image (E : Integer) return String;
function Image (E : Integer) return String is
Msg : String := E'Img & "] ";
begin
Msg (Msg'First) := '[';
return Msg;
end Image;
begin
Ada.Exceptions.Raise_Exception
(Socket_Error'Identity, Image (Error) & Socket_Error_Message (Error));
end Raise_Socket_Error;
----------
-- Read --
----------
procedure Read
(Stream : in out Datagram_Socket_Stream_Type;
Item : out Ada.Streams.Stream_Element_Array;
Last : out Ada.Streams.Stream_Element_Offset)
is
First : Ada.Streams.Stream_Element_Offset := Item'First;
Index : Ada.Streams.Stream_Element_Offset := First - 1;
Max : constant Ada.Streams.Stream_Element_Offset := Item'Last;
begin
loop
Receive_Socket
(Stream.Socket,
Item (First .. Max),
Index,
Stream.From);
Last := Index;
-- Exit when all or zero data received. Zero means that
-- the socket peer is closed.
exit when Index < First or else Index = Max;
First := Index + 1;
end loop;
end Read;
----------
-- Read --
----------
procedure Read
(Stream : in out Stream_Socket_Stream_Type;
Item : out Ada.Streams.Stream_Element_Array;
Last : out Ada.Streams.Stream_Element_Offset)
is
First : Ada.Streams.Stream_Element_Offset := Item'First;
Index : Ada.Streams.Stream_Element_Offset := First - 1;
Max : constant Ada.Streams.Stream_Element_Offset := Item'Last;
begin
loop
Receive_Socket (Stream.Socket, Item (First .. Max), Index);
Last := Index;
-- Exit when all or zero data received. Zero means that
-- the socket peer is closed.
exit when Index < First or else Index = Max;
First := Index + 1;
end loop;
end Read;
-------------------
-- Resolve_Error --
-------------------
function Resolve_Error
(Error_Value : Integer;
From_Errno : Boolean := True)
return Error_Type
is
use GNAT.Sockets.Constants;
begin
if not From_Errno then
case Error_Value is
when HOST_NOT_FOUND => return Unknown_Host;
when TRY_AGAIN => return Host_Name_Lookup_Failure;
when NO_RECOVERY => return No_Address_Associated_With_Name;
when NO_ADDRESS => return Unknown_Server_Error;
when others => return Cannot_Resolve_Error;
end case;
end if;
case Error_Value is
when EACCES => return Permission_Denied;
when EADDRINUSE => return Address_Already_In_Use;
when EADDRNOTAVAIL => return Cannot_Assign_Requested_Address;
when EAFNOSUPPORT =>
return Address_Family_Not_Supported_By_Protocol;
when EALREADY => return Operation_Already_In_Progress;
when EBADF => return Bad_File_Descriptor;
when ECONNREFUSED => return Connection_Refused;
when EFAULT => return Bad_Address;
when EINPROGRESS => return Operation_Now_In_Progress;
when EINTR => return Interrupted_System_Call;
when EINVAL => return Invalid_Argument;
when EIO => return Input_Output_Error;
when EISCONN => return Transport_Endpoint_Already_Connected;
when EMSGSIZE => return Message_Too_Long;
when ENETUNREACH => return Network_Is_Unreachable;
when ENOBUFS => return No_Buffer_Space_Available;
when ENOPROTOOPT => return Protocol_Not_Available;
when ENOTCONN => return Transport_Endpoint_Not_Connected;
when EOPNOTSUPP => return Operation_Not_Supported;
when EPROTONOSUPPORT => return Protocol_Not_Supported;
when ESOCKTNOSUPPORT => return Socket_Type_Not_Supported;
when ETIMEDOUT => return Connection_Timed_Out;
when EWOULDBLOCK => return Resource_Temporarily_Unavailable;
when others => return Cannot_Resolve_Error;
end case;
end Resolve_Error;
-----------------------
-- Resolve_Exception --
-----------------------
function Resolve_Exception
(Occurrence : Exception_Occurrence)
return Error_Type
is
Id : Exception_Id := Exception_Identity (Occurrence);
Msg : constant String := Exception_Message (Occurrence);
First : Natural := Msg'First;
Last : Natural;
Val : Integer;
begin
while First <= Msg'Last
and then Msg (First) not in '0' .. '9'
loop
First := First + 1;
end loop;
if First > Msg'Last then
return Cannot_Resolve_Error;
end if;
Last := First;
while Last < Msg'Last
and then Msg (Last + 1) in '0' .. '9'
loop
Last := Last + 1;
end loop;
Val := Integer'Value (Msg (First .. Last));
if Id = Socket_Error_Id then
return Resolve_Error (Val);
elsif Id = Host_Error_Id then
return Resolve_Error (Val, False);
else
return Cannot_Resolve_Error;
end if;
end Resolve_Exception;
--------------------
-- Receive_Socket --
--------------------
procedure Receive_Socket
(Socket : Socket_Type;
Item : out Ada.Streams.Stream_Element_Array;
Last : out Ada.Streams.Stream_Element_Offset)
is
use type Ada.Streams.Stream_Element_Offset;
Res : C.int;
begin
Res := C_Recv
(C.int (Socket),
Item (Item'First)'Address,
Item'Length, 0);
if Res = Failure then
Raise_Socket_Error (Socket_Errno);
end if;
Last := Item'First + Ada.Streams.Stream_Element_Offset (Res - 1);
end Receive_Socket;
--------------------
-- Receive_Socket --
--------------------
procedure Receive_Socket
(Socket : Socket_Type;
Item : out Ada.Streams.Stream_Element_Array;
Last : out Ada.Streams.Stream_Element_Offset;
From : out Sock_Addr_Type)
is
use type Ada.Streams.Stream_Element_Offset;
Res : C.int;
Sin : aliased Sockaddr_In;
Len : aliased C.int := Sin'Size / 8;
begin
Res := C_Recvfrom
(C.int (Socket),
Item (Item'First)'Address,
Item'Length, 0,
Sin'Unchecked_Access,
Len'Unchecked_Access);
if Res = Failure then
Raise_Socket_Error (Socket_Errno);
end if;
Last := Item'First + Ada.Streams.Stream_Element_Offset (Res - 1);
From.Addr := To_Inet_Addr (Sin.Sin_Addr);
From.Port := Port_Type (Network_To_Port (Sin.Sin_Port));
end Receive_Socket;
-----------------
-- Send_Socket --
-----------------
procedure Send_Socket
(Socket : Socket_Type;
Item : Ada.Streams.Stream_Element_Array;
Last : out Ada.Streams.Stream_Element_Offset)
is
use type Ada.Streams.Stream_Element_Offset;
Res : C.int;
begin
Res := C_Send
(C.int (Socket),
Item (Item'First)'Address,
Item'Length, 0);
if Res = Failure then
Raise_Socket_Error (Socket_Errno);
end if;
Last := Item'First + Ada.Streams.Stream_Element_Offset (Res - 1);
end Send_Socket;
-----------------
-- Send_Socket --
-----------------
procedure Send_Socket
(Socket : Socket_Type;
Item : Ada.Streams.Stream_Element_Array;
Last : out Ada.Streams.Stream_Element_Offset;
To : Sock_Addr_Type)
is
use type Ada.Streams.Stream_Element_Offset;
Res : C.int;
Sin : aliased Sockaddr_In;
Len : aliased C.int := Sin'Size / 8;
begin
Sin.Sin_Family := C.unsigned_short (Families (To.Family));
Sin.Sin_Addr := To_In_Addr (To.Addr);
Sin.Sin_Port := Port_To_Network (C.unsigned_short (To.Port));
Res := C_Sendto
(C.int (Socket),
Item (Item'First)'Address,
Item'Length, 0,
Sin'Unchecked_Access,
Len);
if Res = Failure then
Raise_Socket_Error (Socket_Errno);
end if;
Last := Item'First + Ada.Streams.Stream_Element_Offset (Res - 1);
end Send_Socket;
---------
-- Set --
---------
procedure Set (Item : in out Socket_Set_Type; Socket : Socket_Type) is
begin
if Item = null then
Item := new Socket_Set_Record'(Socket_Set_Record (Null_Fd_Set));
end if;
Set (Fd_Set (Item.all), C.int (Socket));
end Set;
-----------------------
-- Set_Socket_Option --
-----------------------
procedure Set_Socket_Option
(Socket : Socket_Type;
Level : Level_Type := Socket_Level;
Option : Option_Type)
is
V8 : aliased Two_Int;
V4 : aliased C.int;
V1 : aliased C.unsigned_char;
Len : aliased C.int;
Add : System.Address := Null_Address;
Res : C.int;
begin
case Option.Name is
when Keep_Alive |
Reuse_Address |
Broadcast |
No_Delay =>
V4 := C.int (Boolean'Pos (Option.Enabled));
Len := V4'Size / 8;
Add := V4'Address;
when Linger =>
V8 (V8'First) := C.int (Boolean'Pos (Option.Enabled));
V8 (V8'Last) := C.int (Option.Seconds);
Len := V8'Size / 8;
Add := V8'Address;
when Send_Buffer |
Receive_Buffer =>
V4 := C.int (Option.Size);
Len := V4'Size / 8;
Add := V4'Address;
when Error =>
V4 := C.int (Boolean'Pos (True));
Len := V4'Size / 8;
Add := V4'Address;
when Add_Membership |
Drop_Membership =>
V8 (V8'First) := To_Int (To_In_Addr (Option.Multiaddr));
V8 (V8'Last) := To_Int (To_In_Addr (Option.Interface));
Len := V8'Size / 8;
Add := V8'Address;
when Multicast_TTL =>
V1 := C.unsigned_char (Option.Time_To_Live);
Len := V1'Size / 8;
Add := V1'Address;
when Multicast_Loop =>
V1 := C.unsigned_char (Boolean'Pos (Option.Enabled));
Len := V1'Size / 8;
Add := V1'Address;
end case;
Res := C_Setsockopt
(C.int (Socket),
Levels (Level),
Options (Option.Name),
Add, Len);
if Res = Failure then
Raise_Socket_Error (Socket_Errno);
end if;
end Set_Socket_Option;
---------------------
-- Shutdown_Socket --
---------------------
procedure Shutdown_Socket
(Socket : Socket_Type;
How : Shutmode_Type := Shut_Read_Write)
is
Res : C.int;
begin
Res := C_Shutdown (C.int (Socket), Shutmodes (How));
if Res = Failure then
Raise_Socket_Error (Socket_Errno);
end if;
end Shutdown_Socket;
------------
-- Stream --
------------
function Stream
(Socket : Socket_Type;
Send_To : Sock_Addr_Type)
return Stream_Access
is
S : Datagram_Socket_Stream_Access;
begin
S := new Datagram_Socket_Stream_Type;
S.Socket := Socket;
S.To := Send_To;
S.From := Get_Socket_Name (Socket);
return Stream_Access (S);
end Stream;
------------
-- Stream --
------------
function Stream
(Socket : Socket_Type)
return Stream_Access
is
S : Stream_Socket_Stream_Access;
begin
S := new Stream_Socket_Stream_Type;
S.Socket := Socket;
return Stream_Access (S);
end Stream;
----------
-- To_C --
----------
function To_C (Socket : Socket_Type) return Integer is
begin
return Integer (Socket);
end To_C;
-------------------
-- To_Host_Entry --
-------------------
function To_Host_Entry
(Host : Hostent)
return Host_Entry_Type
is
use type C.size_t;
Official : constant String :=
C.Strings.Value (Host.H_Name);
Aliases : constant Chars_Ptr_Array :=
Chars_Ptr_Pointers.Value (Host.H_Aliases);
-- H_Aliases points to a list of name aliases. The list is
-- terminated by a NULL pointer.
Addresses : constant In_Addr_Access_Array :=
In_Addr_Access_Pointers.Value (Host.H_Addr_List);
-- H_Addr_List points to a list of binary addresses (in network
-- byte order). The list is terminated by a NULL pointer.
-- H_Length is not used because it is currently only set to 4.
-- H_Addrtype is always AF_INET
Result : Host_Entry_Type
(Aliases_Length => Aliases'Length - 1,
Addresses_Length => Addresses'Length - 1);
-- The last element is a null pointer.
Source : C.size_t;
Target : Natural;
begin
Result.Official := To_Host_Name (Official);
Source := Aliases'First;
Target := Result.Aliases'First;
while Target <= Result.Aliases_Length loop
Result.Aliases (Target) :=
To_Host_Name (C.Strings.Value (Aliases (Source)));
Source := Source + 1;
Target := Target + 1;
end loop;
Source := Addresses'First;
Target := Result.Addresses'First;
while Target <= Result.Addresses_Length loop
Result.Addresses (Target) :=
To_Inet_Addr (Addresses (Source).all);
Source := Source + 1;
Target := Target + 1;
end loop;
return Result;
end To_Host_Entry;
------------------
-- To_Host_Name --
------------------
function To_Host_Name (N : String) return Host_Name_Type is
begin
return (N'Length, N);
end To_Host_Name;
----------------
-- To_In_Addr --
----------------
function To_In_Addr (Addr : Inet_Addr_Type) return Thin.In_Addr is
begin
if Addr.Family = Family_Inet then
return (S_B1 => C.unsigned_char (Addr.Sin_V4 (1)),
S_B2 => C.unsigned_char (Addr.Sin_V4 (2)),
S_B3 => C.unsigned_char (Addr.Sin_V4 (3)),
S_B4 => C.unsigned_char (Addr.Sin_V4 (4)));
end if;
raise Socket_Error;
end To_In_Addr;
------------------
-- To_Inet_Addr --
------------------
function To_Inet_Addr
(Addr : In_Addr)
return Inet_Addr_Type
is
Result : Inet_Addr_Type;
begin
Result.Sin_V4 (1) := Inet_Addr_Comp_Type (Addr.S_B1);
Result.Sin_V4 (2) := Inet_Addr_Comp_Type (Addr.S_B2);
Result.Sin_V4 (3) := Inet_Addr_Comp_Type (Addr.S_B3);
Result.Sin_V4 (4) := Inet_Addr_Comp_Type (Addr.S_B4);
return Result;
end To_Inet_Addr;
---------------
-- To_String --
---------------
function To_String (HN : Host_Name_Type) return String is
begin
return HN.Name (1 .. HN.Length);
end To_String;
----------------
-- To_Timeval --
----------------
function To_Timeval (Val : Duration) return Timeval is
S : Timeval_Unit := Timeval_Unit (Val);
MS : Timeval_Unit := Timeval_Unit (1_000_000 * (Val - Duration (S)));
begin
return (S, MS);
end To_Timeval;
-----------
-- Write --
-----------
procedure Write
(Stream : in out Datagram_Socket_Stream_Type;
Item : Ada.Streams.Stream_Element_Array)
is
First : Ada.Streams.Stream_Element_Offset := Item'First;
Index : Ada.Streams.Stream_Element_Offset := First - 1;
Max : constant Ada.Streams.Stream_Element_Offset := Item'Last;
begin
loop
Send_Socket
(Stream.Socket,
Item (First .. Max),
Index,
Stream.To);
-- Exit when all or zero data sent. Zero means that the
-- socket has been closed by peer.
exit when Index < First or else Index = Max;
First := Index + 1;
end loop;
if Index /= Max then
raise Socket_Error;
end if;
end Write;
-----------
-- Write --
-----------
procedure Write
(Stream : in out Stream_Socket_Stream_Type;
Item : Ada.Streams.Stream_Element_Array)
is
First : Ada.Streams.Stream_Element_Offset := Item'First;
Index : Ada.Streams.Stream_Element_Offset := First - 1;
Max : constant Ada.Streams.Stream_Element_Offset := Item'Last;
begin
loop
Send_Socket (Stream.Socket, Item (First .. Max), Index);
-- Exit when all or zero data sent. Zero means that the
-- socket has been closed by peer.
exit when Index < First or else Index = Max;
First := Index + 1;
end loop;
if Index /= Max then
raise Socket_Error;
end if;
end Write;
end GNAT.Sockets;
|
package Prime_Ada is
cnt : Integer;
procedure Get_Prime (n : Integer);
end Prime_Ada;
|
-- This file is covered by the Internet Software Consortium (ISC) License
-- Reference: ../License.txt
with Ada.Strings.Unbounded;
with Ada.Containers;
package HelperText is
package SU renames Ada.Strings.Unbounded;
package CON renames Ada.Containers;
subtype Text is SU.Unbounded_String;
type Line_Markers is private;
blank : constant Text := SU.Null_Unbounded_String;
-- unpadded numeric image
function int2str (A : Integer) return String;
function int2text (A : Integer) return Text;
-- Trim both sides
function trim (S : String) return String;
-- converters : Text <==> String
function USS (US : Text) return String;
function SUS (S : String) return Text;
-- True if strings are identical
function equivalent (A, B : Text) return Boolean;
function equivalent (A : Text; B : String) return Boolean;
-- Used for mapped containers
function hash (key : Text) return CON.Hash_Type;
-- True if the string is zero length
function IsBlank (US : Text) return Boolean;
function IsBlank (S : String) return Boolean;
-- shorthand for index
function contains (S : String; fragment : String) return Boolean;
function contains (US : Text; fragment : String) return Boolean;
-- Return True if S terminates with fragment exactly
function trails (S : String; fragment : String) return Boolean;
function trails (US : Text; fragment : String) return Boolean;
-- Return True if S leads with fragment exactly
function leads (S : String; fragment : String) return Boolean;
function leads (US : Text; fragment : String) return Boolean;
-- Convert to uppercase
function uppercase (US : Text) return Text;
function uppercase (S : String) return String;
-- Convert to lowercase
function lowercase (US : Text) return Text;
function lowercase (S : String) return String;
-- Head (keep all but last delimiter and field)
function head (US : Text; delimiter : Text) return Text;
function head (S : String; delimiter : String) return String;
-- Tail (keep only last field)
function tail (US : Text; delimiter : Text) return Text;
function tail (S : String; delimiter : String) return String;
-- Return half of a string split by separator
function part_1 (S : String; separator : String := "/") return String;
function part_2 (S : String; separator : String := "/") return String;
-- Numeric image with left-padded zeros
function zeropad (N : Natural; places : Positive) return String;
-- Returns index of first character of fragment (0 if not found)
function start_index (S : String; fragment : String) return Natural;
-- Replace substring with another string
function replace_substring (US : Text;
old_string : String;
new_string : String) return Text;
-- returns S(S'First + left_offset .. S'Last - right_offset)
function substring (S : String; left_offset, right_offset : Natural) return String;
-- Iterate though block of text, LF is delimiter
procedure initialize_markers
(block_text : in String;
shuttle : out Line_Markers);
function next_line_present
(block_text : in String;
shuttle : in out Line_Markers)
return Boolean;
function next_line_with_content_present
(block_text : in String;
start_with : in String;
shuttle : in out Line_Markers)
return Boolean;
function extract_line
(block_text : in String;
shuttle : in Line_Markers)
return String;
function extract_file
(block_text : in String;
shuttle : in out Line_Markers;
file_size : in Natural)
return String;
-- True when trailing white space detected
function trailing_whitespace_present (line : String) return Boolean;
-- True when tab preceded by space character is present
function trapped_space_character_present (line : String) return Boolean;
-- Returns number of instances of a given character in a given string
function count_char (S : String; focus : Character) return Natural;
-- Returns string that is 'First + offset to index(end_marker) - 1
function partial_search
(fullstr : String;
offset : Natural;
end_marker : String) return String;
-- returns first character through (not including) the first line feed (if it exists)
function first_line (S : String) return String;
-- convert boolean to lowercase string
function bool2str (A : Boolean) return String;
function bool2text (A : Boolean) return Text;
-- Return contents of exact line given a block of lines (delimited by LF) and a line number
function specific_line (S : String; line_number : Positive) return String;
-- Given a single line (presumably no line feeds) with data separated by <delimited>,
-- return the field given by field_number (starts counting at 1).
function specific_field
(S : String;
field_number : Positive;
delimiter : String := " ") return String;
-- Replace a single character with another single character (first found)
function replace (S : String; reject, shiny : Character) return String;
-- Replace single character with another single character (all found)
function replace_all (S : String; reject, shiny : Character) return String;
-- Search entire string S for focus character and replace all instances with substring
function replace_char (S : String; focus : Character; substring : String) return String;
-- Filters out control characters from String S
function strip_control (S : String) return String;
-- Replaces 2 or more consecutive spaces with a single space
function strip_excessive_spaces (S : String) return String;
-- Escape certain characters per json specification
function json_escape (S : String) return String;
-- Return input surrounded by double quotation marks
function DQ (txt : String) return String;
-- Return input surrounded by single quotation marks
function SQ (txt : String) return String;
-- Returns literal surrounded by single quotes
function shell_quoted (txt : String) return String;
private
single_LF : constant String (1 .. 1) := (1 => ASCII.LF);
type Line_Markers is
record
back_marker : Natural := 0;
front_marker : Natural := 0;
zero_length : Boolean := False;
utilized : Boolean := False;
end record;
end HelperText;
|
pragma License (Unrestricted);
with Ada.Calendar;
package GNAT.Calendar is
No_Time : constant Ada.Calendar.Time :=
Ada.Calendar.Time_Of (
Year => Ada.Calendar.Year_Number'First,
Month => Ada.Calendar.Month_Number'First,
Day => Ada.Calendar.Day_Number'First);
end GNAT.Calendar;
|
with Ada.Exceptions;
with Ada.Numerics.Generic_Elementary_Functions;
with Ada.Real_Time;
with Ada.Text_IO;
with GL.Buffers;
with GL.Low_Level.Enums;
with GL.Objects.Textures;
with GL.Pixels;
with GL.Toggles;
with GL.Types;
with Orka.Behaviors;
with Orka.Cameras.Rotate_Around_Cameras;
with Orka.Contexts;
with Orka.Debug;
with Orka.Features.Atmosphere.Earth;
with Orka.Features.Terrain.Spheres;
with Orka.Inputs.Joysticks.Filtering;
with Orka.Inputs.Joysticks.Gamepads;
with Orka.Inputs.GLFW;
with Orka.Inputs.Pointers;
with Orka.Loggers.Terminal;
with Orka.Logging;
with Orka.Loops;
with Orka.Rendering.Buffers;
with Orka.Rendering.Drawing;
with Orka.Rendering.Debug.Bounding_Boxes;
with Orka.Rendering.Debug.Coordinate_Axes;
with Orka.Rendering.Debug.Lines;
with Orka.Rendering.Debug.Spheres;
with Orka.Rendering.Effects.Filters;
with Orka.Rendering.Framebuffers;
with Orka.Rendering.Programs.Modules;
with Orka.Rendering.Programs.Uniforms;
with Orka.Rendering.Textures;
with Orka.Resources.Locations.Directories;
with Orka.Windows.GLFW;
with Orka.Timers;
with Orka.Transforms.Doubles.Quaternions;
with Orka.Transforms.Singles.Matrices;
with Orka.Transforms.Singles.Vectors;
with Orka.Transforms.Doubles.Matrices;
with Orka.Transforms.Doubles.Matrix_Conversions;
with Orka.Transforms.Doubles.Vectors;
with Orka.Transforms.Doubles.Vector_Conversions;
with Orka.Types;
with Glfw.Input.Joysticks;
with Atmosphere_Types.Objects;
with Coordinates;
with Planets.Earth;
with Demo.Atmospheres;
with Demo.Terrains;
procedure Orka_Demo is
Window_Width : constant := 1280;
Window_Height : constant := 720;
Width : constant := 1280;
Height : constant := 720;
Samples : constant := 1;
-- Degrees per cell for the white debug grid
Deg_Per_Cell : constant := 3;
Earth_Rotation_Speedup : constant := 1;
-- Camera system rotates around Sphere if speed up is large (>= 1000) :/
Terrain_Parameters : Orka.Features.Terrain.Subdivision_Parameters :=
(Meshlet_Subdivision => 3,
Edge_Length_Target => 16,
Min_LoD_Standard_Dev => 0.00);
Displace_Terrain : constant Boolean := False;
-- To show displaced terrain:
--
-- 1. Set Displace_Terrain to True
-- 2. Set Terrain_Parameters to (1, 16, 1.0)
-- 3. Multiply z * 1000.0 in function planeToSphere in
-- ../orka/orka_plugin_terrain/data/shaders/terrain/terrain-render-sphere.glsl
Terrain_Min_Depth : constant := 6;
Terrain_Max_Depth : constant := 20;
type View_Object_Kind is (Sphere_Kind, Planet_Kind, Satellite_Kind);
Previous_Viewed_Object, Current_Viewed_Object : View_Object_Kind := Sphere_Kind;
View_Azimuth_Angle_Radians : constant := 0.0 * Ada.Numerics.Pi;
View_Zenith_Angle_Radians : constant := 0.1 * Ada.Numerics.Pi;
View_Object_Distance : constant := (if Displace_Terrain then 2500_000.0 else 20_000.0);
type Blur_Kind is (None, Moving_Average, Gaussian);
type Blur_Kernel is (Small, Medium, Large, Very_Large);
Freeze_Terrain_Update : Boolean := False;
Show_Terrain_Wireframe : Boolean := True;
Do_Blur : Blur_Kind := None;
Blur_Kernel_Size : Blur_Kernel := Small;
Use_Smap : Boolean := True;
Do_White_Balance : constant Boolean := True;
Show_White_Grid : constant Boolean := False;
Show_Stationary_Targets : constant Boolean := True;
Show_Satellites : constant Boolean := True;
Render_Terrain : constant Boolean := True;
Render_Debug_Geometry : constant Boolean := True;
Visible_Tiles : Natural := 0;
Min_AU : constant := 0.005;
Planet_Rotations : GL.Types.Double := 0.0;
Height_Above_Surface : GL.Types.Double := 0.0;
Step_Y : GL.Types.Int := 0;
Exposure : GL.Types.Single := 10.0;
function Clamp (Value : GL.Types.Int) return GL.Types.Int is
(GL.Types.Int'Max (0, GL.Types.Int'Min (Value, 20)));
package EF is new Ada.Numerics.Generic_Elementary_Functions (GL.Types.Double);
package Matrices renames Orka.Transforms.Doubles.Matrices;
package Quaternions renames Orka.Transforms.Doubles.Quaternions;
package LE renames GL.Low_Level.Enums;
package MC renames Orka.Transforms.Doubles.Matrix_Conversions;
package GP renames Orka.Inputs.Joysticks.Gamepads;
package Filtering renames Orka.Inputs.Joysticks.Filtering;
package BBoxes renames Orka.Rendering.Debug.Bounding_Boxes;
package Lines renames Orka.Rendering.Debug.Lines;
package Axes renames Orka.Rendering.Debug.Coordinate_Axes;
package Spheres renames Orka.Rendering.Debug.Spheres;
function Image_D (Value : GL.Types.Double) return String is
package Double_IO is new Ada.Text_IO.Float_IO (GL.Types.Double);
Value_String : String := "123456789012.12";
begin
Double_IO.Put (Value_String, Value, Aft => 2, Exp => 0);
return Orka.Logging.Trim (Value_String);
end Image_D;
function Get_White_Points
(Planet : aliased Orka.Features.Atmosphere.Model_Data) return GL.Types.Single_Array
is
use type Orka.Float_64;
R, G, B : Orka.Float_64 := 1.0;
begin
Orka.Features.Atmosphere.Convert_Spectrum_To_Linear_SRGB (Planet, R, G, B);
declare
White_Point : constant Orka.Float_64 := (R + G + B) / 3.0;
begin
return
(Orka.Float_32 (R / White_Point),
Orka.Float_32 (G / White_Point),
Orka.Float_32 (B / White_Point));
end;
end Get_White_Points;
use Ada.Real_Time;
T1 : constant Time := Clock;
Context : constant Orka.Contexts.Context'Class := Orka.Windows.GLFW.Create_Context
(Version => (4, 2), Flags => (Debug => True, others => False));
Window : aliased Orka.Windows.Window'Class := Orka.Windows.GLFW.Create_Window
(Context, Window_Width, Window_Height, Resizable => False);
use Orka.Resources;
use type GL.Types.Double;
Location_Data : constant Locations.Location_Ptr
:= Locations.Directories.Create_Location ("data");
Location_Orka_Shaders : constant Locations.Location_Ptr
:= Locations.Directories.Create_Location ("../orka/orka/data/shaders");
Location_Atmosphere_Shaders : constant Locations.Location_Ptr
:= Locations.Directories.Create_Location ("../orka/orka_plugin_atmosphere/data/shaders");
Location_Terrain_Shaders : constant Locations.Location_Ptr
:= Locations.Directories.Create_Location ("../orka/orka_plugin_terrain/data/shaders");
Location_Precomputed : constant Locations.Writable_Location_Ptr
:= Locations.Directories.Create_Location ("results");
-----------------------------------------------------------------------------
JS : Orka.Inputs.Joysticks.Joystick_Input_Access;
JS_Manager : constant Orka.Inputs.Joysticks.Joystick_Manager_Ptr :=
Orka.Inputs.GLFW.Create_Joystick_Manager;
use type GL.Types.Single;
use type Orka.Inputs.Joysticks.Joystick_Input_Access;
begin
Orka.Logging.Set_Logger (Orka.Loggers.Terminal.Create_Logger (Level => Orka.Loggers.Debug));
Orka.Debug.Set_Log_Messages (Enable => True, Raise_API_Error => True);
Context.Enable (Orka.Contexts.Reversed_Z);
pragma Assert (Samples > 0);
Context.Enable (Orka.Contexts.Multisample);
declare
Mappings : constant String
:= Convert (Orka.Resources.Byte_Array'(Location_Data.Read_Data
("gamecontrollerdb.txt").Get));
begin
Glfw.Input.Joysticks.Update_Gamepad_Mappings (Mappings);
end;
JS_Manager.Acquire (JS);
if JS /= null then
Ada.Text_IO.Put_Line ("Joystick:");
Ada.Text_IO.Put_Line (" Name: " & JS.Name);
Ada.Text_IO.Put_Line (" GUID: " & JS.GUID);
Ada.Text_IO.Put_Line (" Present: " & JS.Is_Present'Image);
Ada.Text_IO.Put_Line (" Gamepad: " & JS.Is_Gamepad'Image);
else
Ada.Text_IO.Put_Line ("No joystick present");
end if;
-- if JS = null then
-- JS := Orka.Inputs.Joysticks.Default.Create_Joystick_Input (Window.Pointer_Input,
-- (0.01, 0.01, 0.01, 0.01));
-- end if;
declare
use Orka.Features.Atmosphere;
use Orka.Features.Terrain;
Earth : aliased constant Model_Data :=
Orka.Features.Atmosphere.Earth.Data (Luminance => None);
Atmosphere_Manager : Demo.Atmospheres.Atmosphere :=
Demo.Atmospheres.Create
(Earth, Planets.Earth.Planet, Location_Atmosphere_Shaders, Location_Precomputed);
--------------------------------------------------------------------------
Terrain_Manager_Helper : Demo.Terrains.Terrain :=
Demo.Terrains.Create_Terrain (Earth, Planets.Earth.Planet,
Atmosphere_Manager, Location_Data, Location_Terrain_Shaders);
Uniform_Smap : Orka.Rendering.Programs.Uniforms.Uniform (LE.Bool_Type);
procedure Initialize_Atmosphere_Terrain_Program
(Program : Orka.Rendering.Programs.Program) is
begin
Program.Uniform_Sampler ("u_DmapSampler").Verify_Compatibility
(Terrain_Manager_Helper.Height_Map);
Program.Uniform_Sampler ("u_SmapSampler").Verify_Compatibility
(Terrain_Manager_Helper.Slope_Map);
Uniform_Smap := Program.Uniform ("u_UseSmap");
end Initialize_Atmosphere_Terrain_Program;
Terrain_Manager : Orka.Features.Terrain.Terrain := Create_Terrain
(Count => 6,
Min_Depth => Terrain_Min_Depth,
Max_Depth => Terrain_Max_Depth,
Scale => (if Displace_Terrain then 1.0 else 0.0),
Wireframe => True,
Location => Location_Terrain_Shaders,
Render_Modules => Terrain_Manager_Helper.Render_Modules,
Initialize_Render => Initialize_Atmosphere_Terrain_Program'Access);
--------------------------------------------------------------------------
Timer_0, Timer_1, Timer_2, Timer_3, Timer_4 : Orka.Timers.Timer := Orka.Timers.Create_Timer;
type Timer_Array is array (Positive range 1 .. 4) of Duration;
Timer_Terrain_Update : Orka.Timers.Timer := Orka.Timers.Create_Timer;
Timer_Terrain_Render : Orka.Timers.Timer := Orka.Timers.Create_Timer;
New_Terrain_Timers : Timer_Array := (others => 0.0);
Terrain_Timers : Timer_Array := (others => 0.0);
GPU_Timers : Timer_Array := (others => 0.0);
use GL.Objects.Textures;
use type GL.Types.Int;
Texture_1 : Texture (if Samples > 0 then LE.Texture_2D_Multisample else LE.Texture_2D);
Texture_2 : Texture (if Samples > 0 then LE.Texture_2D_Multisample else LE.Texture_2D);
Texture_3 : Texture (LE.Texture_Rectangle);
Texture_4 : Texture (LE.Texture_Rectangle);
begin
Texture_3.Allocate_Storage (1, 0, GL.Pixels.RGBA8, Width, Height, 1);
Texture_4.Allocate_Storage (1, 0, GL.Pixels.RGBA8, Width / 2, Height / 2, 1);
declare
use Orka.Rendering.Framebuffers;
use Orka.Rendering.Buffers;
use Orka.Rendering.Programs;
use Orka.Rendering.Effects.Filters;
P_2 : Program := Create_Program (Modules.Module_Array'
(Modules.Create_Module (Location_Orka_Shaders, VS => "oversized-triangle.vert"),
Modules.Create_Module (Location_Data, FS => "demo/resolve.frag")));
FB_1 : Framebuffer := Create_Framebuffer (Width, Height, Samples, Context);
FB_3 : Framebuffer := Create_Framebuffer (Width, Height, 0, Context);
FB_4 : Framebuffer := Create_Framebuffer (Width / 2, Height / 2, 0, Context);
FB_D : constant Framebuffer := Create_Default_Framebuffer (Window_Width, Window_Height);
Blur_Filter_GK : array (Blur_Kernel) of Separable_Filter :=
(Small => Create_Filter
(Location_Orka_Shaders, Texture_4, Kernel => Gaussian_Kernel (Radius => 6)),
Medium => Create_Filter
(Location_Orka_Shaders, Texture_4, Kernel => Gaussian_Kernel (Radius => 24)),
Large => Create_Filter
(Location_Orka_Shaders, Texture_4, Kernel => Gaussian_Kernel (Radius => 48)),
Very_Large => Create_Filter
(Location_Orka_Shaders, Texture_4, Kernel => Gaussian_Kernel (Radius => 96)));
Blur_Filter_MA : array (Blur_Kernel) of Moving_Average_Filter :=
(Small => Create_Filter
(Location_Orka_Shaders, Texture_4, Radius => 1),
Medium => Create_Filter
(Location_Orka_Shaders, Texture_4, Radius => 4),
Large => Create_Filter
(Location_Orka_Shaders, Texture_4, Radius => 8),
Very_Large => Create_Filter
(Location_Orka_Shaders, Texture_4, Radius => 16));
use Orka.Cameras;
Lens : constant Lens_Ptr
:= new Camera_Lens'Class'(Create_Lens
(Width, Height, Transforms.FOV (36.0, 50.0), Context));
Current_Camera : constant Camera_Ptr
:= new Camera'Class'(Camera'Class
(Rotate_Around_Cameras.Create_Camera (Window.Pointer_Input, Lens, FB_1)));
-----------------------------------------------------------------------
use Orka.Transforms.Doubles.Matrices;
Sphere : constant Orka.Behaviors.Behavior_Ptr := new Atmosphere_Types.No_Behavior'
(Position => (0.0, 0.0, 0.0, 1.0));
Planet : constant Orka.Behaviors.Behavior_Ptr := new Atmosphere_Types.No_Behavior'
(Position => (0.0, 0.0, 0.0, 1.0));
Sun : constant Orka.Behaviors.Behavior_Ptr := new Atmosphere_Types.No_Behavior'
(Position => (0.0, 0.0, Planets.AU, 1.0));
use Atmosphere_Types.Objects;
White_Points : constant GL.Types.Single_Array := Get_White_Points (Earth);
procedure Update_Viewed_Object (Camera : Camera_Ptr; Kind : View_Object_Kind) is
Object : constant Orka.Behaviors.Behavior_Ptr :=
(case Current_Viewed_Object is
when Sphere_Kind => Sphere,
when Planet_Kind => Planet,
when Satellite_Kind => Object_01);
-- Object_01: satellite
-- Object_02: position on surface showing atmosphere problem near surface
-- due to flattening of the Earth (atmosphere assumes sphere is not flattened)
-- Object_03: position on surface on the edge of two adjacent terrain tiles
begin
if Camera.all in Observing_Camera'Class then
Observing_Camera'Class (Camera.all).Look_At (Object);
elsif Camera.all in First_Person_Camera'Class then
First_Person_Camera'Class (Camera.all).Set_Position (Object.Position);
end if;
if Camera.all in Rotate_Around_Cameras.Rotate_Around_Camera'Class then
Rotate_Around_Cameras.Rotate_Around_Camera'Class
(Camera.all).Set_Radius
(case Current_Viewed_Object is
when Sphere_Kind | Satellite_Kind => View_Object_Distance,
when Planet_Kind => 20_000_000.0);
end if;
Previous_Viewed_Object := Current_Viewed_Object;
end Update_Viewed_Object;
begin
FB_1.Set_Default_Values
((Color => (0.0, 0.0, 0.0, 1.0),
Depth => (if Context.Enabled (Orka.Contexts.Reversed_Z) then 0.0 else 1.0),
others => <>));
-- Texture_1.Allocate_Storage (1, Samples, GL.Pixels.RGBA16F, Width, Height, 1);
Texture_1.Allocate_Storage (1, Samples, GL.Pixels.R11F_G11F_B10F, Width, Height, 1);
Texture_2.Allocate_Storage (1, Samples, GL.Pixels.Depth_Component32F, Width, Height, 1);
FB_1.Attach (Texture_1);
FB_1.Attach (Texture_2);
FB_3.Attach (Texture_3);
FB_4.Attach (Texture_4);
if Current_Camera.all in Rotate_Around_Cameras.Rotate_Around_Camera'Class then
Rotate_Around_Cameras.Rotate_Around_Camera'Class
(Current_Camera.all).Set_Angles
(View_Azimuth_Angle_Radians, View_Zenith_Angle_Radians);
end if;
Update_Viewed_Object (Current_Camera, Current_Viewed_Object);
Current_Camera.Set_Input_Scale (0.002, 0.002, 50_000.0);
GL.Toggles.Enable (GL.Toggles.Depth_Test);
GL.Toggles.Enable (GL.Toggles.Cull_Face);
declare
Current_Time : Time := Clock - Microseconds (16_667);
Start_Time : constant Time := Clock;
Prev_Time : Time := Start_Time;
BBox : BBoxes.Bounding_Box := BBoxes.Create_Bounding_Box (Location_Orka_Shaders);
Line : Lines.Line := Lines.Create_Line (Location_Orka_Shaders);
Axis : Axes.Coordinate_Axes := Axes.Create_Coordinate_Axes (Location_Orka_Shaders);
Debug_Sphere : Spheres.Sphere := Spheres.Create_Sphere
(Location_Orka_Shaders, Color => (1.0, 1.0, 1.0, 0.5),
-- Cells_Horizontal => 24 * 60, -- 1 min/cell
Cells_Horizontal => 36 * 10 / Deg_Per_Cell,
Cells_Vertical => 18 * 10 / Deg_Per_Cell);
Mutable_Buffer_Flags : constant Orka.Rendering.Buffers.Storage_Bits :=
(Dynamic_Storage => True, others => False);
BBox_Transforms : constant Buffer := Create_Buffer
(Mutable_Buffer_Flags, Orka.Types.Single_Matrix_Type, 3);
BBox_Bounds : constant Buffer := Create_Buffer
(Mutable_Buffer_Flags, Orka.Types.Single_Vector_Type, 6);
Axes_Transforms : constant Buffer := Create_Buffer
(Mutable_Buffer_Flags, Orka.Types.Single_Matrix_Type, 2);
Axes_Sizes : constant Buffer := Create_Buffer
(Mutable_Buffer_Flags, Orka.Types.Single_Type, 1);
S_S_A : constant GL.Types.Single_Array :=
(Orka.Float_32 (Planets.Earth.Planet.Semi_Major_Axis / Earth.Length_Unit_In_Meters),
Orka.Float_32 (Planets.Earth.Planet.Flattening));
Sphere_Params_A : constant Buffer := Create_Buffer ((others => False), S_S_A);
Sphere_Transforms_A : constant Buffer := Create_Buffer
(Mutable_Buffer_Flags, Orka.Types.Single_Matrix_Type,
Sphere_Params_A.Length / 2);
Line_Transforms_ECI : constant Buffer := Create_Buffer
(Mutable_Buffer_Flags, Orka.Types.Single_Matrix_Type, 1);
Line_Transforms_ECEF : constant Buffer := Create_Buffer
(Mutable_Buffer_Flags, Orka.Types.Single_Matrix_Type, 1);
Line_Colors : constant Buffer := Create_Buffer
(Mutable_Buffer_Flags, Orka.Types.Single_Vector_Type, 1);
Line_Points_ECI : constant Buffer := Create_Buffer
(Mutable_Buffer_Flags, Orka.Types.Single_Vector_Type, 4);
Line_Points_ECEF : constant Buffer := Create_Buffer
(Mutable_Buffer_Flags, Orka.Types.Single_Vector_Type, 16);
procedure Render_Scene
(Scene : not null Orka.Behaviors.Behavior_Array_Access;
Camera : Orka.Cameras.Camera_Ptr)
is
P_I : Orka.Inputs.Pointers.Pointer_Input_Ptr renames Window.Pointer_Input;
use Orka.Transforms.Doubles.Vectors;
use Orka.Transforms.Doubles.Vector_Conversions;
use type Quaternions.Quaternion;
use Orka.Cameras.Transforms;
Earth_Rotation : constant Quaternions.Quaternion :=
Quaternions.R (Orka.Transforms.Doubles.Vectors.Normalize ((0.0, 0.0, 1.0, 0.0)),
-2.0 * Ada.Numerics.Pi * (Planet_Rotations + GL.Types.Double
(To_Duration (Clock - Start_Time) /
(Planets.Earth.Planet.Sidereal / Earth_Rotation_Speedup))));
Orientation_ECI : constant Transforms.Matrix4 :=
MC.Convert (Matrices.R (Matrices.Vector4
(Coordinates.Orientation_ECI)));
Orientation_ECEF : constant Transforms.Matrix4 :=
MC.Convert (Matrices.R (Matrices.Vector4
(Earth_Rotation * Coordinates.Orientation_ECI)));
function Translate_To (Object : Orka.Behaviors.Behavior_Ptr)
return Transforms.Matrix4
is
Camera_To_Object : constant Transforms.Vector4 :=
Convert ((Object.Position - Camera.View_Position)
* (1.0 / Earth.Length_Unit_In_Meters));
begin
return T (Camera_To_Object);
end Translate_To;
Move_To_Earth_Center : constant Transforms.Matrix4 := Translate_To (Planet);
Move_To_Sphere_Center : constant Transforms.Matrix4 := Translate_To (Sphere);
Move_To_Satellite_Center : constant Transforms.Matrix4 := Translate_To (Object_01);
New_Time : constant Time := Clock;
DT : constant Duration := To_Duration (New_Time - Current_Time);
begin
Timer_0.Start;
Coordinates.Orientation_ECEF := Earth_Rotation;
Atmosphere_Types.No_Behavior (Sphere.all).Position := Coordinates.Rotate_ECEF *
Planets.Earth.Planet.Geodetic_To_ECEF
(Latitude => 0.0, Longitude => 0.0, Altitude => 1_000.0);
Current_Time := New_Time;
if Current_Time - Prev_Time > Seconds (2) then
Prev_Time := Current_Time;
Terrain_Timers := (others => 0.0);
GPU_Timers := (others => 0.0);
end if;
Camera.Set_Up_Direction (Matrices.Vectors.Normalize
(Observing_Camera'Class (Camera.all).Target_Position - Planet.Position));
Camera.FB.Use_Framebuffer;
Camera.FB.Clear ((Color | Depth => True, others => False));
if JS /= null and then JS.Is_Present then
declare
Dead_Zones : constant array (1 .. 6) of Orka.Inputs.Joysticks.Axis_Position :=
(1 | 3 => 0.05,
2 | 4 => 0.03,
5 .. 6 => 0.0);
K_RC : constant GL.Types.Single := Filtering.RC (10.0);
Last_State : constant Orka.Inputs.Joysticks.Joystick_State := JS.Last_State;
-- TODO Shouldn't this be Current_State?
procedure Process_Axis
(Value : in out Orka.Inputs.Joysticks.Axis_Position;
Index : Positive)
is
DZ : constant Orka.Inputs.Joysticks.Axis_Position := Dead_Zones (Index);
begin
Value := Filtering.Dead_Zone (Value, DZ);
Value := Filtering.Low_Pass_Filter
(Value, Last_State.Axes (Index),
K_RC, GL.Types.Single (DT));
end Process_Axis;
begin
JS.Update_State (Process_Axis'Access);
end;
declare
State : constant Orka.Inputs.Joysticks.Joystick_State := JS.Current_State;
Last_State : constant Orka.Inputs.Joysticks.Joystick_State := JS.Last_State;
use all type Orka.Inputs.Joysticks.Button_State;
use GP;
subtype Gamepad_Button_Index is Glfw.Input.Joysticks.Gamepad_Button_Index;
function Value (Value : Gamepad_Button_Index) return GP.Button is
(GP.Button'Val (Value - Gamepad_Button_Index'First));
begin
for Index in 1 .. State.Button_Count loop
if State.Buttons (Index) /= Last_State.Buttons (Index) then
if Value (Index) = Right_Pad_Left
and State.Buttons (Index) = Pressed
then
Freeze_Terrain_Update := not Freeze_Terrain_Update;
end if;
if Value (Index) = Right_Pad_Right
and State.Buttons (Index) = Pressed
then
Do_Blur := (if Do_Blur /= Blur_Kind'Last then
Blur_Kind'Succ (Do_Blur)
else
Blur_Kind'First);
end if;
if Value (Index) = Right_Pad_Up
and State.Buttons (Index) = Pressed
then
Show_Terrain_Wireframe := not Show_Terrain_Wireframe;
end if;
if Value (Index) = Right_Pad_Down
and State.Buttons (Index) = Pressed
then
Current_Viewed_Object :=
(if Current_Viewed_Object /= View_Object_Kind'Last then
View_Object_Kind'Succ (Current_Viewed_Object)
else
View_Object_Kind'First);
end if;
if Value (Index) = Left_Pad_Up
and State.Buttons (Index) = Pressed
and State.Buttons (GP.Index (Center_Right)) = Pressed
then
Step_Y := Clamp (Step_Y - 1);
end if;
if Value (Index) = Left_Pad_Down
and State.Buttons (Index) = Pressed
and State.Buttons (GP.Index (Center_Right)) = Pressed
then
Step_Y := Clamp (Step_Y + 1);
end if;
if Value (Index) = Left_Pad_Up
and State.Buttons (Index) = Pressed
and State.Buttons (GP.Index (Center_Right)) = Released
and Terrain_Parameters.Meshlet_Subdivision
< Orka.Features.Terrain.Meshlet_Subdivision_Depth'Last
then
Terrain_Parameters.Meshlet_Subdivision :=
Terrain_Parameters.Meshlet_Subdivision + 1;
end if;
if Value (Index) = Left_Pad_Down
and State.Buttons (Index) = Pressed
and State.Buttons (GP.Index (Center_Right)) = Released
and Terrain_Parameters.Meshlet_Subdivision
> Orka.Features.Terrain.Meshlet_Subdivision_Depth'First
then
Terrain_Parameters.Meshlet_Subdivision :=
Terrain_Parameters.Meshlet_Subdivision - 1;
end if;
if Value (Index) = Left_Pad_Left
and State.Buttons (Index) = Pressed
and State.Buttons (GP.Index (Center_Right)) = Released
and Terrain_Parameters.Min_LoD_Standard_Dev
<= 0.9
then
Terrain_Parameters.Min_LoD_Standard_Dev :=
Terrain_Parameters.Min_LoD_Standard_Dev + 0.1;
end if;
if Value (Index) = Left_Pad_Right
and State.Buttons (Index) = Pressed
and State.Buttons (GP.Index (Center_Right)) = Released
and Terrain_Parameters.Min_LoD_Standard_Dev
>= 0.1
then
Terrain_Parameters.Min_LoD_Standard_Dev :=
Terrain_Parameters.Min_LoD_Standard_Dev - 0.1;
end if;
if Value (Index) = Left_Pad_Left
and State.Buttons (Index) = Pressed
and State.Buttons (GP.Index (Center_Right)) = Pressed
and Blur_Kernel_Size /= Blur_Kernel'First
then
Blur_Kernel_Size := Blur_Kernel'Pred (Blur_Kernel_Size);
end if;
if Value (Index) = Left_Pad_Right
and State.Buttons (Index) = Pressed
and State.Buttons (GP.Index (Center_Right)) = Pressed
and Blur_Kernel_Size /= Blur_Kernel'Last
then
Blur_Kernel_Size := Blur_Kernel'Succ (Blur_Kernel_Size);
end if;
if Value (Index) = Center_Left
and State.Buttons (Index) = Pressed
then
Use_Smap := not Use_Smap;
Uniform_Smap.Set_Boolean (Use_Smap);
end if;
if Value (Index) = Left_Shoulder
and State.Buttons (Index) = Pressed
then
Exposure := Exposure + 0.1;
end if;
if Value (Index) = Right_Shoulder
and State.Buttons (Index) = Pressed
then
Exposure := GL.Types.Single'Max (0.0, Exposure - 0.1);
end if;
end if;
if State.Buttons (Index) = Last_State.Buttons (Index) then
if Value (Index) = Left_Shoulder
and State.Buttons (Index) = Pressed
then
Exposure := Exposure + 0.01;
end if;
if Value (Index) = Right_Shoulder
and State.Buttons (Index) = Pressed
then
Exposure := GL.Types.Single'Max (0.0, Exposure - 0.01);
end if;
end if;
end loop;
end;
end if;
if JS /= null then
declare
use Orka.Inputs.Joysticks.Gamepads;
State : constant Orka.Inputs.Joysticks.Joystick_State := JS.Current_State;
C_X : constant GL.Types.Double :=
GL.Types.Double (State.Axes (Index (Left_Stick_X)));
C_Y : constant GL.Types.Double :=
GL.Types.Double (State.Axes (Index (Left_Stick_Y)));
C_Z : constant GL.Types.Double :=
GL.Types.Double (State.Axes (Index (Right_Trigger)));
C_L : constant GL.Types.Double :=
EF.Sqrt (C_X ** 2 + C_Y ** 2);
C_L_A : constant GL.Types.Double :=
(if C_Y = 0.0 and C_X = 0.0 then
0.0
else
Orka.Transforms.Doubles.Vectors.To_Degrees (EF.Arctan (C_X, C_Y)));
begin
if abs C_X > 0.02 or abs C_Y > 0.02 then
Ada.Text_IO.Put_Line
(Image_D (C_X) & " " & Image_D (C_Y) & " = " & C_L'Image &
" d: " & Image_D (C_L_A));
end if;
Planet_Rotations := Planet_Rotations + C_X * 0.001;
-- Atmosphere_Types.No_Behavior (Planet.all).Position :=
-- (Earth.Bottom_Radius * C_X,
-- Earth.Bottom_Radius * C_Y,
-- Earth.Bottom_Radius * 0.0,
-- 1.0);
declare
S_Z : constant GL.Types.Double := GL.Types.Double (Step_Y) * 0.05;
Sun_Distance_AU : constant GL.Types.Double :=
((1.0 - S_Z) * (1.0 - Min_AU) + Min_AU) * Planets.AU;
begin
Atmosphere_Types.No_Behavior (Sun.all).Position :=
(0.0, 0.0, Sun_Distance_AU, 1.0);
end;
end;
end if;
-- if Camera.all in Observing_Camera'Class then
-- TP := Observing_Camera'Class (Camera.all).Target_Position;
-- elsif Camera.all in First_Person_Camera'Class then
-- TP := First_Person_Camera'Class (Camera.all).View_Position;
-- end if;
declare
-- Currently we look at TP from a distance, and set the earth center
-- relative to this TP.
--
-- Try to Set earth center relative to camera and set distance to zero
-- Distance : constant GL.Types.Double := Magnitude (TP - Camera.View_Position);
Distance : constant GL.Types.Double := Length (Sun.Position - Planet.Position);
use Orka.Logging;
begin
Window.Set_Title
-- ("Sun: " & Image_D (Distance / Planets.AU) & " AU "
-- & "H: " & Image_D (Height_Above_Surface) & " m "
("Meshlet:" & Terrain_Parameters.Meshlet_Subdivision'Image & " "
& "LOD stddev: " &
Image_D (Orka.Float_64 (Terrain_Parameters.Min_LoD_Standard_Dev)) & " "
& (if Use_Smap then "smap" else "no smap") & " "
& "Atmos: " & Trim (Image (GPU_Timers (1))) & " "
& "Terrain: " & Trim (Image (GPU_Timers (2))) & " ["
& "upd(" & Trim (Visible_Tiles'Image) & "): " &
Trim (Image (Terrain_Timers (1))) & " "
& "rnd: " & Trim (Image (Terrain_Timers (2))) & "] "
& "Frame: " & Trim (Image (GPU_Timers (3))) & " "
& "Res(" & Do_Blur'Image & "): " &
Trim (Image (GPU_Timers (4))) & " "
-- & " expo:" & Exposure'Image
& "Sat:"
& Integer'Image (Integer (Atmosphere_Types.Physics_Behavior
(Object_01.all).FDM.Altitude)) & " m "
& Image_D (Matrices.Vectors.Length
(Atmosphere_Types.Physics_Behavior
(Object_01.all).Int.State.Velocity)) & " m/s"
);
Timer_2.Start;
if Render_Terrain then
Terrain_Manager_Helper.Render
(Terrain => Terrain_Manager,
Parameters => Terrain_Parameters,
Visible_Tiles => Visible_Tiles,
Camera => Camera,
Planet => Planet,
Star => Sun,
Rotation => Orientation_ECEF,
Center => Move_To_Earth_Center,
Freeze => Freeze_Terrain_Update,
Wires => Show_Terrain_Wireframe,
Timer_Update => Timer_Terrain_Update,
Timer_Render => Timer_Terrain_Render);
end if;
New_Terrain_Timers (1) := Timer_Terrain_Update.GPU_Duration;
New_Terrain_Timers (2) := Timer_Terrain_Render.GPU_Duration;
Timer_2.Stop;
end;
Timer_1.Start;
Atmosphere_Manager.Render (Camera, Planet, Sun);
Timer_1.Stop;
declare
Earth_Center_To_Camera : constant Matrices.Vector4 :=
Matrices.Vectors.Normalize (Coordinates.Inverse_Rotate_ECI
* (Camera.View_Position - Planet.Position));
F_ECTC : constant Matrices.Vector4 :=
Planets.Earth.Planet.Flattened_Vector (Earth_Center_To_Camera, 0.0);
Length_PTC : constant GL.Types.Double :=
Length (Planet.Position - Camera.View_Position);
Length_PTS : constant GL.Types.Double :=
Length ((F_ECTC (Orka.Y), F_ECTC (Orka.Z), F_ECTC (Orka.X), 0.0));
begin
Height_Above_Surface := Length_PTC - Length_PTS;
pragma Assert (Height_Above_Surface >= Orka.Float_64'First);
-- Make compiler happy after removing it from window title
end;
for Index in Terrain_Timers'Range loop
Terrain_Timers (Index) :=
Duration'Max (Terrain_Timers (Index), New_Terrain_Timers (Index));
end loop;
GPU_Timers (1) := Duration'Max (GPU_Timers (1), Timer_1.GPU_Duration);
GPU_Timers (2) := Duration'Max (GPU_Timers (2), Timer_2.GPU_Duration);
GPU_Timers (3) := Duration'Max (GPU_Timers (3), Timer_0.GPU_Duration);
GPU_Timers (4) := Duration'Max (GPU_Timers (4), Timer_4.GPU_Duration);
Timer_3.Start;
if Render_Debug_Geometry then
declare
Radius : constant GL.Types.Single :=
GL.Types.Single
(Planets.Earth.Planet.Semi_Major_Axis / Earth.Length_Unit_In_Meters);
-- Bounding boxes
B_T : constant Orka.Types.Singles.Matrix4_Array :=
(Move_To_Earth_Center,
Move_To_Sphere_Center * Orientation_ECEF,
Move_To_Satellite_Center * Orientation_ECI);
B_B : constant Orka.Types.Singles.Vector4_Array :=
((-Radius, -Radius, -Radius, 0.0), (Radius, Radius, Radius, 0.0),
(-1.0, -1.0, -1.0, 0.0), (1.0, 1.0, 1.0, 0.0),
(-1.0, -1.0, -1.0, 0.0), (1.0, 1.0, 1.0, 0.0));
-- Axes
A_T : constant Orka.Types.Singles.Matrix4_Array :=
(Move_To_Earth_Center,
Move_To_Earth_Center * Orientation_ECEF);
A_S : constant GL.Types.Single_Array := (1 => Radius);
-- Spheres
S_T_A : constant Orka.Types.Singles.Matrix4_Array :=
(1 .. GL.Types.Int (Sphere_Params_A.Length / 2) =>
Move_To_Earth_Center * Orientation_ECEF);
-- Lines
use Transforms.Vectors;
function Get_Lines (Object : Orka.Behaviors.Behavior_Ptr)
return Orka.Types.Singles.Vector4_Array
is
P : constant Orka.Types.Singles.Vector4 :=
Convert (Object.Position * (1.0 / Earth.Length_Unit_In_Meters));
begin
if Object.all in Atmosphere_Types.Physics_Behavior'Class then
declare
use all type Atmosphere_Types.Frame_Type;
PO : Atmosphere_Types.Physics_Behavior
renames Atmosphere_Types.Physics_Behavior (Object.all);
Foo : constant Matrices.Matrix4 :=
(case PO.Frame is
when ECI => Coordinates.Rotate_ECI,
when ECEF => Coordinates.Rotate_ECEF);
V : constant Orka.Types.Singles.Vector4 :=
Convert (Foo * PO.Int.State.Velocity
* (1.0 / Earth.Length_Unit_In_Meters));
begin
return ((0.0, 0.0, 0.0, 0.0), P, P, P + (50.0 * V));
end;
else
return ((0.0, 0.0, 0.0, 0.0), P);
end if;
end Get_Lines;
function Get_Lines (Point_In_ECEF : Orka.Types.Doubles.Vector4)
return Orka.Types.Singles.Vector4_Array
is
Scale_Factor : constant Orka.Float_64 :=
1.0 / Earth.Length_Unit_In_Meters;
Point_In_GL : constant Orka.Types.Singles.Vector4 :=
Convert (Coordinates.Rotate_ECEF * Point_In_ECEF * Scale_Factor);
begin
return ((0.0, 0.0, 0.0, 0.0), Point_In_GL);
end Get_Lines;
use type Orka.Types.Singles.Vector4_Array;
ECEF_XZ_15 : constant Orka.Types.Doubles.Vector4 :=
Planets.Earth.Planet.Geodetic_To_ECEF
(Latitude => 15.0, Longitude => 0.0, Altitude => 0.0);
ECEF_XZ_30 : constant Orka.Types.Doubles.Vector4 :=
Planets.Earth.Planet.Geodetic_To_ECEF
(Latitude => 30.0, Longitude => 0.0, Altitude => 0.0);
ECEF_XZ_45 : constant Orka.Types.Doubles.Vector4 :=
Planets.Earth.Planet.Geodetic_To_ECEF
(Latitude => 45.0, Longitude => 0.0, Altitude => 0.0);
ECEF_XZ_60 : constant Orka.Types.Doubles.Vector4 :=
Planets.Earth.Planet.Geodetic_To_ECEF
(Latitude => 60.0, Longitude => 00.0, Altitude => 0.0);
ECEF_XZ_75 : constant Orka.Types.Doubles.Vector4 :=
Planets.Earth.Planet.Geodetic_To_ECEF
(Latitude => 75.0, Longitude => 00.0, Altitude => 0.0);
To_Surface_At_0_0 : constant Orka.Types.Singles.Vector4_Array :=
(1 => (0.0, 0.0, 0.0, 0.0),
2 => Convert (Coordinates.Rotate_ECEF *
(Planets.Earth.Planet.Semi_Major_Axis, 0.0, 0.0, 1.0) *
(1.0 / Earth.Length_Unit_In_Meters)));
Planet_To_Sun : constant Orka.Types.Singles.Vector4_Array :=
(1 => (0.0, 0.0, 0.0, 0.0),
2 => Convert ((Sun.Position - Planet.Position)
* (1.0 / Earth.Length_Unit_In_Meters)));
-- Move the lines from the camera to the center of the Earth
L_T_ECEF : constant Orka.Types.Singles.Matrix4_Array :=
(1 => Move_To_Earth_Center);
L_T_ECI : constant Orka.Types.Singles.Matrix4_Array :=
(1 => Move_To_Earth_Center);
-- Magenta colored lines
L_C : constant Orka.Types.Singles.Vector4_Array :=
(1 => (1.0, 0.0, 1.0, 1.0));
L_P_ECI : constant Orka.Types.Singles.Vector4_Array :=
Get_Lines (Object_01);
L_P_ECEF : constant Orka.Types.Singles.Vector4_Array :=
-- Get_Lines (Object_02) &
-- Get_Lines (Object_03) &
Get_Lines (ECEF_XZ_15) &
Get_Lines (ECEF_XZ_30) &
Get_Lines (ECEF_XZ_45) &
Get_Lines (ECEF_XZ_60) &
Get_Lines (ECEF_XZ_75);
-- To_Surface_At_0_0;
-- Get_Lines (Sphere);
-- Planet_To_Sun;
begin
BBox_Transforms.Set_Data (B_T);
BBox_Bounds.Set_Data (B_B);
Axes_Transforms.Set_Data (A_T);
Axes_Sizes.Set_Data (A_S);
Sphere_Transforms_A.Set_Data (S_T_A);
Line_Transforms_ECI.Set_Data (L_T_ECI);
Line_Transforms_ECEF.Set_Data (L_T_ECEF);
Line_Colors.Set_Data (L_C);
Line_Points_ECI.Set_Data (L_P_ECI);
Line_Points_ECEF.Set_Data (L_P_ECEF);
BBox.Render
(View => Camera.View_Matrix,
Proj => Lens.Projection_Matrix,
Transforms => BBox_Transforms,
Bounds => BBox_Bounds);
Axis.Render
(View => Camera.View_Matrix,
Proj => Lens.Projection_Matrix,
Transforms => Axes_Transforms,
Sizes => Axes_Sizes);
if Show_White_Grid then
Debug_Sphere.Render
(View => Camera.View_Matrix,
Proj => Lens.Projection_Matrix,
Transforms => Sphere_Transforms_A,
Spheres => Sphere_Params_A);
end if;
if Show_Stationary_Targets then
Line.Render
(View => Camera.View_Matrix,
Proj => Lens.Projection_Matrix,
Transforms => Line_Transforms_ECEF,
Colors => Line_Colors,
Points => Line_Points_ECEF);
end if;
if Show_Satellites then
Line.Render
(View => Camera.View_Matrix,
Proj => Lens.Projection_Matrix,
Transforms => Line_Transforms_ECI,
Colors => Line_Colors,
Points => Line_Points_ECI);
end if;
end;
end if;
Timer_3.Stop;
pragma Assert (Samples > 0);
if Do_Blur /= None then
FB_3.Use_Framebuffer;
else
FB_D.Use_Framebuffer;
end if;
P_2.Use_Program;
Orka.Rendering.Textures.Bind (Texture_1, Orka.Rendering.Textures.Texture, 0);
if Do_White_Balance then
P_2.Uniform ("white_point").Set_Vector
(White_Points);
else
P_2.Uniform ("white_point").Set_Vector
(GL.Types.Single_Array'((1.0, 1.0, 1.0)));
end if;
P_2.Uniform ("samples").Set_Int (Samples);
if Do_Blur /= None then
P_2.Uniform ("screenResolution").Set_Vector
(Orka.Types.Singles.Vector4'
(GL.Types.Single (FB_3.Width), GL.Types.Single (FB_3.Height), 0.0, 0.0));
else
P_2.Uniform ("screenResolution").Set_Vector
(Orka.Types.Singles.Vector4'
(GL.Types.Single (FB_D.Width), GL.Types.Single (FB_D.Height), 0.0, 0.0));
end if;
P_2.Uniform ("exposure").Set_Single
((if Earth.Luminance /= Orka.Features.Atmosphere.None then
Exposure * 1.0e-5
else Exposure));
Timer_4.Start;
GL.Buffers.Set_Depth_Function (GL.Types.Always);
Orka.Rendering.Drawing.Draw (GL.Types.Triangles, 0, 3);
GL.Buffers.Set_Depth_Function (GL.Types.Greater);
case Do_Blur is
when None =>
null;
when Moving_Average =>
FB_3.Resolve_To (FB_4);
Blur_Filter_MA (Blur_Kernel_Size).Render (Passes => 2);
FB_4.Resolve_To (FB_D);
when Gaussian =>
FB_3.Resolve_To (FB_4);
Blur_Filter_GK (Blur_Kernel_Size).Render (Passes => 1);
FB_4.Resolve_To (FB_D);
end case;
Timer_4.Stop;
Timer_0.Stop;
if Previous_Viewed_Object /= Current_Viewed_Object then
Update_Viewed_Object (Camera, Current_Viewed_Object);
end if;
end Render_Scene;
package Loops is new Orka.Loops
(Time_Step => Ada.Real_Time.Microseconds (2_083),
Frame_Limit => Ada.Real_Time.Microseconds (16_667),
Window => Window'Unchecked_Access,
Camera => Current_Camera,
Job_Manager => Demo.Job_System);
T2 : constant Time := Clock;
begin
Ada.Text_IO.Put_Line ("Load time: " &
Duration'Image (To_Duration (T2 - T1)));
Ada.Text_IO.Put_Line ("Bottom radius model: " & Earth.Bottom_Radius'Image);
Loops.Scene.Add (Sphere);
Loops.Scene.Add (Object_01);
Loops.Scene.Add (Object_02);
Loops.Scene.Add (Object_03);
Loops.Handler.Enable_Limit (False);
Loops.Run_Loop (Render_Scene'Access, Loops.Stop_Loop'Access);
end;
end;
end;
Ada.Text_IO.Put_Line ("Shutting down...");
Demo.Job_System.Shutdown;
Ada.Text_IO.Put_Line ("Shut down");
exception
when Error : others =>
Ada.Text_IO.Put_Line ("Error: " & Ada.Exceptions.Exception_Information (Error));
Demo.Job_System.Shutdown;
end Orka_Demo;
|
-----------------------------------------------------------------------
-- security-oauth -- OAuth Security
-- Copyright (C) 2012, 2016, 2017, 2018, 2019, 2020 Stephane Carrez
-- Written by Stephane Carrez (Stephane.Carrez@gmail.com)
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-----------------------------------------------------------------------
with Ada.Strings.Unbounded;
-- = OAuth =
-- The <b>Security.OAuth</b> package defines and implements the OAuth 2.0 authorization
-- framework as defined by the IETF working group in RFC 6749:
-- The OAuth 2.0 Authorization Framework.
--
-- @include security-oauth-clients.ads
-- @include security-oauth-servers.ads
package Security.OAuth is
-- OAuth 2.0: Section 10.2.2. Initial Registry Contents
-- RFC 6749: 11.2.2. Initial Registry Contents
CLIENT_ID : constant String := "client_id";
CLIENT_SECRET : constant String := "client_secret";
RESPONSE_TYPE : constant String := "response_type";
REDIRECT_URI : constant String := "redirect_uri";
SCOPE : constant String := "scope";
STATE : constant String := "state";
CODE : constant String := "code";
ERROR_DESCRIPTION : constant String := "error_description";
ERROR_URI : constant String := "error_uri";
GRANT_TYPE : constant String := "grant_type";
ACCESS_TOKEN : constant String := "access_token";
TOKEN_TYPE : constant String := "token_type";
EXPIRES_IN : constant String := "expires_in";
USERNAME : constant String := "username";
PASSWORD : constant String := "password";
REFRESH_TOKEN : constant String := "refresh_token";
NONCE_TOKEN : constant String := "nonce";
-- RFC 6749: 5.2. Error Response
INVALID_REQUEST : aliased constant String := "invalid_request";
INVALID_CLIENT : aliased constant String := "invalid_client";
INVALID_GRANT : aliased constant String := "invalid_grant";
UNAUTHORIZED_CLIENT : aliased constant String := "unauthorized_client";
UNSUPPORTED_GRANT_TYPE : aliased constant String := "unsupported_grant_type";
INVALID_SCOPE : aliased constant String := "invalid_scope";
-- RFC 6749: 4.1.2.1. Error Response
ACCESS_DENIED : aliased constant String := "access_denied";
UNSUPPORTED_RESPONSE_TYPE : aliased constant String := "unsupported_response_type";
SERVER_ERROR : aliased constant String := "server_error";
TEMPORARILY_UNAVAILABLE : aliased constant String := "temporarily_unavailable";
type Client_Authentication_Type is (AUTH_NONE, AUTH_BASIC);
-- ------------------------------
-- Application
-- ------------------------------
-- The <b>Application</b> holds the necessary information to let a user
-- grant access to its protected resources on the resource server. It contains
-- information that allows the OAuth authorization server to identify the
-- application (client id and secret key).
type Application is tagged private;
-- Get the application identifier.
function Get_Application_Identifier (App : in Application) return String;
-- Set the application identifier used by the OAuth authorization server
-- to identify the application (for example, the App ID in Facebook).
procedure Set_Application_Identifier (App : in out Application;
Client : in String);
-- Set the application secret defined in the OAuth authorization server
-- for the application (for example, the App Secret in Facebook).
procedure Set_Application_Secret (App : in out Application;
Secret : in String);
-- Set the redirection callback that will be used to redirect the user
-- back to the application after the OAuth authorization is finished.
procedure Set_Application_Callback (App : in out Application;
URI : in String);
-- Set the client authentication method used when doing OAuth calls for this application.
-- See RFC 6749, 2.3. Client Authentication
procedure Set_Client_Authentication (App : in out Application;
Method : in Client_Authentication_Type);
private
type Application is tagged record
Client_Id : Ada.Strings.Unbounded.Unbounded_String;
Secret : Ada.Strings.Unbounded.Unbounded_String;
Callback : Ada.Strings.Unbounded.Unbounded_String;
Client_Auth : Client_Authentication_Type := AUTH_NONE;
end record;
end Security.OAuth;
|
-----------------------------------------------------------------------
-- mat-expressions-tests -- Unit tests for MAT expressions
-- Copyright (C) 2014, 2015, 2019 Stephane Carrez
-- Written by Stephane Carrez (Stephane.Carrez@gmail.com)
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-----------------------------------------------------------------------
with Util.Test_Caller;
with Util.Assertions;
package body MAT.Expressions.Tests is
package Caller is new Util.Test_Caller (Test, "Expressions");
procedure Assert_Equals_Kind is
new Util.Assertions.Assert_Equals_T (Value_Type => Kind_Type);
procedure Add_Tests (Suite : in Util.Tests.Access_Test_Suite) is
begin
Caller.Add_Test (Suite, "Test MAT.Expressions.Parse",
Test_Parse_Expression'Access);
end Add_Tests;
-- ------------------------------
-- Test parsing simple expressions
-- ------------------------------
procedure Test_Parse_Expression (T : in out Test) is
Result : MAT.Expressions.Expression_Type;
begin
Result := MAT.Expressions.Parse ("by foo", null);
T.Assert (Result.Node /= null, "Parse 'by foo' must return a expression");
Assert_Equals_Kind (T, N_IN_FUNC, Result.Node.Kind, "Invalid node kind");
Result := MAT.Expressions.Parse ("by direct foo", null);
T.Assert (Result.Node /= null, "Parse 'by direct foo' must return a expression");
Assert_Equals_Kind (T, N_IN_FUNC_DIRECT, Result.Node.Kind, "Invalid node kind");
Result := MAT.Expressions.Parse ("after 10.2", null);
T.Assert (Result.Node /= null, "Parse 'after 10.2' must return a expression");
Assert_Equals_Kind (T, N_RANGE_TIME, Result.Node.Kind, "Invalid node kind");
Result := MAT.Expressions.Parse ("before 3.5", null);
T.Assert (Result.Node /= null, "Parse 'before 3.5' must return a expression");
Assert_Equals_Kind (T, N_RANGE_TIME, Result.Node.Kind, "Invalid node kind");
Result := MAT.Expressions.Parse ("from 2.2 to 3.3", null);
T.Assert (Result.Node /= null, "Parse 'from 2.2 to 3.3' must return a expression");
Assert_Equals_Kind (T, N_RANGE_TIME, Result.Node.Kind, "Invalid node kind");
Result := MAT.Expressions.Parse ("size = 10", null);
T.Assert (Result.Node /= null, "Parse 'size = 10' must return a expression");
Assert_Equals_Kind (T, N_RANGE_SIZE, Result.Node.Kind, "Invalid node kind");
Result := MAT.Expressions.Parse ("size > 10", null);
T.Assert (Result.Node /= null, "Parse 'size > 10' must return a expression");
Assert_Equals_Kind (T, N_RANGE_SIZE, Result.Node.Kind, "Invalid node kind");
Result := MAT.Expressions.Parse ("size < 10", null);
T.Assert (Result.Node /= null, "Parse 'size < 10' must return a expression");
Assert_Equals_Kind (T, N_RANGE_SIZE, Result.Node.Kind, "Invalid node kind");
Result := MAT.Expressions.Parse ("event = 23", null);
T.Assert (Result.Node /= null, "Parse 'event = 23' must return a expression");
Assert_Equals_Kind (T, N_EVENT, Result.Node.Kind, "Invalid node kind");
Result := MAT.Expressions.Parse ("event = 1..100", null);
T.Assert (Result.Node /= null, "Parse 'event = 1..100' must return a expression");
Assert_Equals_Kind (T, N_EVENT, Result.Node.Kind, "Invalid node kind");
end Test_Parse_Expression;
end MAT.Expressions.Tests;
|
With Ada.Text_IO; Use Ada.Text_IO;
Procedure BuscaBinaria is
numeros: array(1..15) of Integer;
target : Integer;
L : Integer;
R : Integer;
mid : Integer;
found: Integer;
-- Leitura String
function Get_String return String is
Line : String (1 .. 1_000);
Last : Natural;
begin
Get_Line (Line, Last);
return Line (1 .. Last);
end Get_String;
-- Leitura Integer
function Get_Integer return Integer is
S : constant String := Get_String;
begin
return Integer'Value (S);
end Get_Integer;
-- Lê 15 elementos do array
procedure Faz_Leitura is
begin
for I in Integer range 1 .. 15 loop
numeros(I) := Get_Integer;
end loop;
end Faz_Leitura;
function binSearch return Integer is
begin
mid := (L + R) / 2;
if numeros(mid) < target then
L := mid + 1;
return binSearch;
end if;
if numeros(mid) > target then
R := mid - 1;
return binSearch;
end if;
return mid;
end binSearch;
begin
Faz_Leitura;
target := Get_Integer;
L := 1;
R := 15;
found := binSearch;
Put_Line(Integer'Image(found));
end BuscaBinaria;
|
------------------------------------------------------------------------------
-- EMAIL: <darkestkhan@gmail.com> --
-- License: ISC --
-- --
-- Copyright © 2015 - 2016 darkestkhan --
------------------------------------------------------------------------------
-- Permission to use, copy, modify, and/or distribute this software for any --
-- purpose with or without fee is hereby granted, provided that the above --
-- copyright notice and this permission notice appear in all copies. --
-- --
-- The software is provided "as is" and the author disclaims all warranties --
-- with regard to this software including all implied warranties of --
-- merchantability and fitness. In no event shall the author be liable for --
-- any special, direct, indirect, or consequential damages or any damages --
-- whatsoever resulting from loss of use, data or profits, whether in an --
-- action of contract, negligence or other tortious action, arising out of --
-- or in connection with the use or performance of this software. --
------------------------------------------------------------------------------
with Imago.IL;
use Imago;
with Lumen.GL;
use Lumen;
package Imago.ILUT is
--------------------------------------------------------------------------
-----------------------
-- C O N S T A N T S --
-----------------------
--------------------------------------------------------------------------
ILUT_VERSION_1_7_8 : constant IL.Enum := 1;
ILUT_VERSION : constant IL.Enum := 178;
-- Attribute Bits.
ILUT_OPENGL_BIT : constant IL.Enum := 16#00000001#;
ILUT_D3D_BIT : constant IL.Enum := 16#00000002#;
ILUT_ALL_ATTRIB_BITS : constant IL.Enum := 16#000FFFFF#;
-- Error Types.
ILUT_INVALID_ENUM : constant IL.Enum := 16#0501#;
ILUT_OUT_OF_MEMORY : constant IL.Enum := 16#0502#;
ILUT_INVALID_VALUE : constant IL.Enum := 16#0505#;
ILUT_ILLEGAL_OPERATION : constant IL.Enum := 16#0506#;
ILUT_INVALID_PARAM : constant IL.Enum := 16#0509#;
ILUT_COULD_NOT_OPEN_FILE : constant IL.Enum := 16#050A#;
ILUT_STACK_OVERFLOW : constant IL.Enum := 16#050E#;
ILUT_STACK_UNDERFLOW : constant IL.Enum := 16#050F#;
ILUT_BAD_DIMENSIONS : constant IL.Enum := 16#0511#;
ILUT_NOT_SUPPORTED : constant IL.Enum := 16#0550#;
-- State Definitions.
ILUT_PALETTE_MODE : constant IL.Enum := 16#0600#;
ILUT_OPENGL_CONV : constant IL.Enum := 16#0610#;
ILUT_D3D_MIPLEVELS : constant IL.Enum := 16#0620#;
ILUT_MAXTEX_WIDTH : constant IL.Enum := 16#0630#;
ILUT_MAXTEX_HEIGHT : constant IL.Enum := 16#0631#;
ILUT_MAXTEX_DEPTH : constant IL.Enum := 16#0632#;
ILUT_GL_USE_S3TC : constant IL.Enum := 16#0634#;
ILUT_D3D_USE_DXTC : constant IL.Enum := 16#0634#;
ILUT_GL_GEN_S3TC : constant IL.Enum := 16#0635#;
ILUT_D3D_GEN_DXTC : constant IL.Enum := 16#0635#;
ILUT_S3TC_FORMAT : constant IL.Enum := 16#0705#;
ILUT_DXTC_FORMAT : constant IL.Enum := 16#0705#;
ILUT_D3D_POOL : constant IL.Enum := 16#0706#;
ILUT_D3D_ALPHA_KEY_COLOR : constant IL.Enum := 16#0707#;
ILUT_D3D_ALPHA_KEY_COLOUR : constant IL.Enum := 16#0707#;
ILUT_FORCE_INTEGER_FORMAT : constant IL.Enum := 16#0636#;
-- This new state does automatic texture target detection
-- if enabled. Currently, only cubemap detection is supported.
-- if the current image is no cubemap, the 2d texture is chosen.
ILUT_GL_AUTODETECT_TEXTURE_TARGET : constant IL.Enum := 16#0807#;
-- Values.
ILUT_VERSION_NUM : constant IL.Enum := IL.IL_VERSION_NUM;
ILUT_VENDOR : constant IL.Enum := IL.IL_VENDOR;
-- The different rendering api's.
-- NOTE: Imago has support only for OpenGL functions.
-- Addition of support for other bindings is not planned.
ILUT_OPENGL : constant IL.Enum := 0;
ILUT_ALLEGRO : constant IL.Enum := 1;
ILUT_WIN32 : constant IL.Enum := 2;
ILUT_DIRECT3D8 : constant IL.Enum := 3;
ILUT_DIRECT3D9 : constant IL.Enum := 4;
ILUT_X11 : constant IL.Enum := 5;
ILUT_DIRECT3D10 : constant IL.Enum := 6;
--------------------------------------------------------------------------
---------------------------
-- S U B P R O G R A M S --
---------------------------
--------------------------------------------------------------------------
-- ImageLib Utility Toolkit Functions.
function Disable (Mode: in IL.Enum) return IL.Bool
with Import => True, Convention => StdCall, External_Name => "ilutDisable";
function Enable (Mode: in IL.Enum) return IL.Bool
with Import => True, Convention => StdCall, External_Name => "ilutEnable";
function Get_Boolean (Mode: in IL.Enum) return IL.Bool
with Import => True, Convention => StdCall,
External_Name => "ilutGetBoolean";
procedure Get_Boolean (Mode: in IL.Enum; Param: in IL.Pointer)
with Import => True, Convention => StdCall,
External_Name => "ilutGetBooleanv";
function Get_Integer (Mode: in IL.Enum) return IL.Int
with Import => True, Convention => StdCall,
External_Name => "ilutGetInteger";
procedure Get_Integer (Mode: in IL.Enum; Param: in IL.Pointer)
with Import => True, Convention => StdCall,
External_Name => "ilutGetIntegerv";
function Get_String (String_Name: in IL.Enum) return String
with Inline => True;
procedure Init
with Import => True, Convention => StdCall, External_Name => "ilutInit";
function Is_Disabled (Mode: in IL.Enum) return IL.Bool
with Import => True, Convention => StdCall,
External_Name => "ilutIsDisabled";
function Is_Enabled (Mode: in IL.Enum) return IL.Bool
with Import => True, Convention => StdCall,
External_Name => "ilutIsEnabled";
procedure Pop_Attrib
with Import => True, Convention => StdCall,
External_Name => "ilutPopAttrib";
procedure Push_Attrib (Bits: in IL.UInt)
with Import => True, Convention => StdCall,
External_Name => "ilutPushAttrib";
procedure Set_Integer (Mode: in IL.Enum; Param: in IL.Int)
with Import => True, Convention => StdCall,
External_Name => "ilutSetInteger";
function Renderer (Renderer: in IL.Enum) return IL.Bool
with Import => True, Convention => StdCall, External_Name => "ilutRenderer";
-- ImageLib Utility Toolkit's OpenGL Functions.
function GL_Bind_Tex_Image return GL.UInt
with Import => True, Convention => StdCall,
External_Name => "ilutGLBindTexImage";
function GL_Bind_Mipmaps return GL.UInt
with Import => True, Convention => StdCall,
External_Name => "ilutGLBindMipmaps";
function GL_Build_Mipmaps return IL.Bool
with Import => True, Convention => StdCall,
External_Name => "ilutGLBuildMipmaps";
function GL_Load_Image (File_Name: in String) return GL.UInt
with Inline => True;
function GL_Screen return IL.Bool
with Import => True, Convention => StdCall, External_Name => "ilutGLScreen";
function GL_Screenie return IL.Bool
with Import => True, Convention => StdCall,
External_Name => "ilutGLScreenie";
function GL_Save_Image
( File_Name: in String; Tex_ID: in GL.UInt
) return IL.Bool
with Inline => True;
function GL_Sub_Tex
( Tex_ID: in GL.UInt; XOff: in IL.UInt; YOff: in IL.UInt
) return IL.Bool
with Import => True, Convention => StdCall,
External_Name => "ilutGLSubTex2D";
function GL_Sub_Tex
( Tex_ID: in GL.UInt; XOff: in IL.UInt;
YOff: in IL.UInt; ZOff: in IL.UInt
) return IL.Bool
with Import => True, Convention => StdCall,
External_Name => "ilutGLSetTex3D";
function GL_Set_Tex_2D (Tex_ID: in GL.UInt) return IL.Bool
with Import => True, Convention => StdCall,
External_Name => "ilutGLSetTex2D";
function GL_Set_Tex_3D (Tex_ID: in GL.UInt) return IL.Bool
with Import => True, Convention => StdCall,
External_Name => "ilutGLSetTex3D";
function GL_Tex_Image (Level: in GL.UInt) return IL.Bool
with Import => True, Convention => StdCall,
External_Name => "ilutGLTexImage";
---------------------------------------------------------------------------
end Imago.ILUT;
|
with Ada.Text_IO;
procedure Pythagorean_Triples is
type Large_Natural is range 0 .. 2**63-1;
-- this is the maximum for gnat
procedure New_Triangle(A, B, C: Large_Natural;
Max_Perimeter: Large_Natural;
Total_Cnt, Primitive_Cnt: in out Large_Natural) is
Perimeter: constant Large_Natural := A + B + C;
begin
if Perimeter <= Max_Perimeter then
Primitive_Cnt := Primitive_Cnt + 1;
Total_Cnt := Total_Cnt + Max_Perimeter / Perimeter;
New_Triangle(A-2*B+2*C, 2*A-B+2*C, 2*A-2*B+3*C, Max_Perimeter, Total_Cnt, Primitive_Cnt);
New_Triangle(A+2*B+2*C, 2*A+B+2*C, 2*A+2*B+3*C, Max_Perimeter, Total_Cnt, Primitive_Cnt);
New_Triangle(2*B+2*C-A, B+2*C-2*A, 2*B+3*C-2*A, Max_Perimeter, Total_Cnt, Primitive_Cnt);
end if;
end New_Triangle;
T_Cnt, P_Cnt: Large_Natural;
begin
for I in 1 .. 9 loop
T_Cnt := 0;
P_Cnt := 0;
New_Triangle(3,4,5, 10**I, Total_Cnt => T_Cnt, Primitive_Cnt => P_Cnt);
Ada.Text_IO.Put_Line("Up to 10 **" & Integer'Image(I) & " :" &
Large_Natural'Image(T_Cnt) & " Triples," &
Large_Natural'Image(P_Cnt) & " Primitives");
end loop;
end Pythagorean_Triples;
|
------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- R E S T R I C T --
-- --
-- S p e c --
-- --
-- $Revision$
-- --
-- Copyright (C) 1992-2001 Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 2, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
-- for more details. You should have received a copy of the GNU General --
-- Public License distributed with GNAT; see file COPYING. If not, write --
-- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
-- MA 02111-1307, USA. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
-- This package deals with the implementation of the Restrictions pragma
with Rident;
with Types; use Types;
with Uintp; use Uintp;
package Restrict is
type Restriction_Id is new Rident.Restriction_Id;
-- The type Restriction_Id defines the set of restriction identifiers,
-- which take no parameter (i.e. they are either present or not present).
-- The actual definition is in the separate package Rident, so that it
-- can easily be accessed by the binder without dragging in lots of stuff.
subtype Partition_Restrictions is
Restriction_Id range
Restriction_Id (Rident.Partition_Restrictions'First) ..
Restriction_Id (Rident.Partition_Restrictions'Last);
-- Range of restriction identifiers that are checked by the binder
subtype Compilation_Unit_Restrictions is
Restriction_Id range
Restriction_Id (Rident.Compilation_Unit_Restrictions'First) ..
Restriction_Id (Rident.Compilation_Unit_Restrictions'Last);
-- Range of restriction identifiers not checked by binder
type Restriction_Parameter_Id is new Rident.Restriction_Parameter_Id;
-- The type Restriction_Parameter_Id records cases where a parameter is
-- present in the corresponding pragma. These cases are not checked for
-- consistency by the binder. The actual definition is in the separate
-- package Rident for consistency.
type Restrictions_Flags is array (Restriction_Id) of Boolean;
-- Type used for arrays indexed by Restriction_Id.
Restrictions : Restrictions_Flags := (others => False);
-- Corresponding entry is False if restriction is not active, and
-- True if the restriction is active, i.e. if a pragma Restrictions
-- has been seen anywhere. Note that we are happy to pick up any
-- restrictions pragmas in with'ed units, since we are required to
-- be consistent at link time, and we might as well find the error
-- at compile time. Clients must NOT use this array for checking to
-- see if a restriction is violated, instead it is required that the
-- Check_Restrictions subprograms be used for this purpose. The only
-- legitimate direct use of this array is when the code is modified
-- as a result of the restriction in some way.
Restrictions_Loc : array (Restriction_Id) of Source_Ptr;
-- Locations of Restrictions pragmas for error message purposes.
-- Valid only if corresponding entry in Restrictions is set.
Main_Restrictions : Restrictions_Flags := (others => False);
-- This variable saves the cumulative restrictions in effect compiling
-- any unit that is part of the extended main unit (i.e. the compiled
-- unit, its spec if any, and its subunits if any). The reason we keep
-- track of this is for the information that goes to the binder about
-- restrictions that are set. The binder will identify a unit that has
-- a restrictions pragma for error message purposes, and we do not want
-- to pick up a restrictions pragma in a with'ed unit for this purpose.
Violations : Restrictions_Flags := (others => False);
-- Corresponding entry is False if the restriction has not been
-- violated in the current main unit, and True if it has been violated.
Restriction_Parameters :
array (Restriction_Parameter_Id) of Uint := (others => No_Uint);
-- This array indicates the setting of restriction parameter identifier
-- values. All values are initially set to No_Uint indicating that the
-- parameter is not set, and are set to the appropriate non-negative
-- value if a Restrictions pragma specifies the corresponding
-- restriction parameter identifier with an appropriate value.
Restriction_Parameters_Loc :
array (Restriction_Parameter_Id) of Source_Ptr;
-- Locations of Restrictions pragmas for error message purposes.
-- Valid only if corresponding entry in Restriction_Parameters is
-- set to a value other than No_Uint.
type Unit_Entry is record
Res_Id : Restriction_Id;
Filenm : String (1 .. 8);
end record;
type Unit_Array_Type is array (Positive range <>) of Unit_Entry;
Unit_Array : constant Unit_Array_Type := (
(No_Asynchronous_Control, "a-astaco"),
(No_Calendar, "a-calend"),
(No_Calendar, "calendar"),
(No_Delay, "a-calend"),
(No_Delay, "calendar"),
(No_Dynamic_Priorities, "a-dynpri"),
(No_IO, "a-direio"),
(No_IO, "directio"),
(No_IO, "a-sequio"),
(No_IO, "sequenio"),
(No_IO, "a-ststio"),
(No_IO, "a-textio"),
(No_IO, "text_io "),
(No_IO, "a-witeio"),
(No_Task_Attributes, "a-tasatt"),
(No_Streams, "a-stream"),
(No_Unchecked_Conversion, "a-unccon"),
(No_Unchecked_Conversion, "unchconv"),
(No_Unchecked_Deallocation, "a-uncdea"),
(No_Unchecked_Deallocation, "unchdeal"));
-- This array defines the mapping between restriction identifiers and
-- predefined language files containing units for which the identifier
-- forbids semantic dependence.
type Save_Compilation_Unit_Restrictions is private;
-- Type used for saving and restoring compilation unit restrictions.
-- See Compilation_Unit_Restrictions_[Save|Restore] subprograms.
-----------------
-- Subprograms --
-----------------
procedure Check_Restricted_Unit (U : Unit_Name_Type; N : Node_Id);
-- Checks if loading of unit U is prohibited by the setting of some
-- restriction (e.g. No_IO restricts the loading of unit Ada.Text_IO).
-- If a restriction exists post error message at the given node.
procedure Check_Restriction (R : Restriction_Id; N : Node_Id);
-- Checks that the given restriction is not set, and if it is set, an
-- appropriate message is posted on the given node. Also records the
-- violation in the violations array. Note that it is mandatory to
-- always use this routine to check if a restriction is violated. Such
-- checks must never be done directly by the caller, since otherwise
-- they are not properly recorded in the violations array.
procedure Check_Restriction
(R : Restriction_Parameter_Id;
N : Node_Id);
-- Checks that the given restriction parameter identifier is not set to
-- zero. If it is set to zero, then the node N is replaced by a node
-- that raises Storage_Error, and a warning is issued.
procedure Check_Restriction
(R : Restriction_Parameter_Id;
V : Uint;
N : Node_Id);
-- Checks that the count in V does not exceed the maximum value of the
-- restriction parameter value corresponding to the given restriction
-- parameter identifier (if it has been set). If the count in V exceeds
-- the maximum, then post an error message on node N.
procedure Check_Elaboration_Code_Allowed (N : Node_Id);
-- Tests to see if elaboration code is allowed by the current restrictions
-- settings. This function is called by Gigi when it needs to define
-- an elaboration routine. If elaboration code is not allowed, an error
-- message is posted on the node given as argument.
function No_Exception_Handlers_Set return Boolean;
-- Test to see if current restrictions settings specify that no exception
-- handlers are present. This function is called by Gigi when it needs to
-- expand an AT END clean up identifier with no exception handler.
function Compilation_Unit_Restrictions_Save
return Save_Compilation_Unit_Restrictions;
-- This function saves the compilation unit restriction settings, and
-- resets them to False. This is used e.g. when compiling a with'ed
-- unit to avoid incorrectly propagating restrictions. Note that it
-- would not be wrong to also save and reset the partition restrictions,
-- since the binder would catch inconsistencies, but actually it is a
-- good thing to acquire restrictions from with'ed units if they are
-- required to be partition wide, because it allows the restriction
-- violation message to be given at compile time instead of link time.
procedure Compilation_Unit_Restrictions_Restore
(R : Save_Compilation_Unit_Restrictions);
-- This is the corresponding restore procedure to restore restrictions
-- previously saved by Compilation_Unit_Restrictions_Save.
procedure Disallow_In_No_Run_Time_Mode (Enode : Node_Id);
-- If in No_Run_Time mode, then the construct represented by Enode is
-- not permitted, and will be appropriately flagged.
procedure Set_No_Run_Time_Mode;
-- Set the no run time mode, and associated restriction pragmas.
function Get_Restriction_Id
(N : Name_Id)
return Restriction_Id;
-- Given an identifier name, determines if it is a valid restriction
-- identifier, and if so returns the corresponding Restriction_Id
-- value, otherwise returns Not_A_Restriction_Id.
function Get_Restriction_Parameter_Id
(N : Name_Id)
return Restriction_Parameter_Id;
-- Given an identifier name, determines if it is a valid restriction
-- parameter identifier, and if so returns the corresponding
-- Restriction_Parameter_Id value, otherwise returns
-- Not_A_Restriction_Parameter_Id.
function Abort_Allowed return Boolean;
pragma Inline (Abort_Allowed);
-- Tests to see if abort is allowed by the current restrictions settings.
-- For abort to be allowed, either No_Abort_Statements must be False,
-- or Max_Asynchronous_Select_Nesting must be non-zero.
function Restricted_Profile return Boolean;
-- Tests to see if tasking operations follow the GNAT restricted run time
-- profile.
procedure Set_Ravenscar;
-- Sets the set of rerstrictions fro Ravenscar
procedure Set_Restricted_Profile;
-- Sets the set of restrictions for pragma Restricted_Run_Time
function Tasking_Allowed return Boolean;
pragma Inline (Tasking_Allowed);
-- Tests to see if tasking operations are allowed by the current
-- restrictions settings. For tasking to be allowed Max_Tasks must
-- be non-zero.
private
type Save_Compilation_Unit_Restrictions is
array (Compilation_Unit_Restrictions) of Boolean;
-- Type used for saving and restoring compilation unit restrictions.
-- See Compilation_Unit_Restrictions_[Save|Restore] subprograms.
end Restrict;
|
------------------------------------------------------------------------------
-- --
-- GNAT RUN-TIME COMPONENTS --
-- --
-- Copyright (C) 2016-2017, AdaCore --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. --
-- --
-- As a special exception under Section 7 of GPL version 3, you are granted --
-- additional permissions described in the GCC Runtime Library Exception, --
-- version 3.1, as published by the Free Software Foundation. --
-- --
-- You should have received a copy of the GNU General Public License and --
-- a copy of the GCC Runtime Library Exception along with this program; --
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
-- <http://www.gnu.org/licenses/>. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
with System;
with Interfaces; use Interfaces;
with Ada.Unchecked_Conversion;
with Interfaces.SF2; use Interfaces.SF2;
with Interfaces.SF2.System_Registers; use Interfaces.SF2.System_Registers;
package body System.SF2.UART is
TX_FIFO_SIZE : constant := 16;
procedure Configure_Baud_Rate
(This : in out MSS_UART;
Baud_Rate : MSS_UART_Baud_Rate;
Status : out Boolean);
-------------------------
-- Configure_Baud_Rate --
-------------------------
procedure Configure_Baud_Rate
(This : in out MSS_UART;
Baud_Rate : MSS_UART_Baud_Rate;
Status : out Boolean)
is
BR_Value : constant Unsigned_32 :=
MSS_UART_Baud_Rate'Enum_Rep (Baud_Rate);
Clocks : constant System_Clocks := Get_System_Clocks;
Pclk_Freq : Unsigned_32;
Value_By_128 : Unsigned_32;
Value_By_64 : Unsigned_32;
Baud_Value : Unsigned_32;
Fractional_Value : Unsigned_32;
begin
-- Reset the peripheral
if This'Address = MMUART_0_Base then
Pclk_Freq := Unsigned_32 (Clocks.PCLK0);
else
Pclk_Freq := Unsigned_32 (Clocks.PCLK1);
end if;
Status := True; -- Assume configuration is fine
Value_By_128 := (8 * Pclk_Freq) / BR_Value;
Value_By_64 := Value_By_128 / 2;
Baud_Value := Value_By_64 / 64;
Fractional_Value := Value_By_128 - (128 * Baud_Value) -
Value_By_64 + (64 * Baud_Value);
if Baud_Value > Unsigned_32 (UInt16'Last) then
Status := False;
return;
end if;
-- Set divisor latch
This.Regs.LCR.DLAB := True;
This.Regs.DMR := Byte (Baud_Value / 256);
This.Regs.DLR := Byte (Baud_Value and 16#FF#);
-- Reset divisor latch
This.Regs.LCR.DLAB := False;
if Fractional_Value > 1 then
-- Enable fractional baud rate
This.Regs.MM0.EFBR := True;
This.Regs.DFR.DFR := UInt6 (Fractional_Value);
else
-- Do not use Fractional Baud Rate divisors.
This.Regs.MM0.EFBR := False;
end if;
end Configure_Baud_Rate;
---------------
-- Configure --
---------------
procedure Configure
(This : in out MSS_UART;
Baud_Rate : MSS_UART_Baud_Rate;
Line_Config : MSS_UART_Line_Configuration;
Status : out Boolean)
is
begin
-- Reset the peripheral
if This'Address = MMUART_0_Base then
System_Registers_Periph.SOFT_RESET_CR.MMUART0_SOFTRESET := True;
System_Registers_Periph.SOFT_RESET_CR.MMUART0_SOFTRESET := False;
elsif This'Address = MMUART_0_Base then
System_Registers_Periph.SOFT_RESET_CR.MMUART1_SOFTRESET := True;
System_Registers_Periph.SOFT_RESET_CR.MMUART1_SOFTRESET := False;
else
Status := False;
return;
end if;
-- Disable interrupts.
This.Regs.IER := (others => <>);
-- FIFO configuration
This.Regs.FCR := (others => <>);
-- Clear the receiver and transmitter FIFO
This.Regs.FCR.CLEAR_RX_FIFO := True;
This.Regs.FCR.CLEAR_TX_FIFO := True;
-- Set default READY mode
This.Regs.FCR.ENABLE_TXRDY_RXRDY := True;
-- Disable loopback
This.Regs.MCR.Loopback := False;
This.Regs.MCR.RLoop := MMUART.Disabled;
-- Set default TX/RX endian
This.Regs.MM1.E_MSB_TX := False;
This.Regs.MM1.E_MSB_RX := False;
-- Default AFM: disabled
This.Regs.MM2.EAFM := False;
-- Disable TX time guard
This.Regs.MM0.ETTG := False;
-- Set default RX timeout
This.Regs.MM0.EFBR := False;
-- Disable fractional baud-rate
This.Regs.MM0.EFBR := False;
-- Disable single-wire mode
This.Regs.MM2.ESWM := False;
-- Set filter to minimum value
This.Regs.GFR.GLR := MMUART.Two_Flip_Flops_No_Spike;
-- Default TX time guard
This.Regs.TTG := 0;
-- Default RX timeout
This.Regs.RTO := 0;
-- Configure baud rate divisors
Configure_Baud_Rate (This, Baud_Rate, Status);
if not Status then
return;
end if;
-- Set the line configuration
declare
LCR : Interfaces.SF2.MMUART.LCR_Register;
begin
case Line_Config.Word_Length is
when Length_5_Bits =>
LCR.WLS := MMUART.Length_5_Bits;
when Length_6_Bits =>
LCR.WLS := MMUART.Length_6_Bits;
when Length_7_Bits =>
LCR.WLS := MMUART.Length_7_Bits;
when Length_8_Bits =>
LCR.WLS := MMUART.Length_8_Bits;
end case;
case Line_Config.Stop_Bits is
when Stop_Bit_1 =>
LCR.STB := MMUART.Stop_Bit_1;
when Stop_Bit_1_AND_HALF =>
LCR.STB := MMUART.Stop_Bit_1_AND_HALF;
end case;
LCR.PEN := Line_Config.Parity_Enable;
case Line_Config.Even_Parity_Enable is
when Odd =>
LCR.EPS := MMUART.Odd;
when Even =>
LCR.EPS := MMUART.Even;
end case;
LCR.SP := Line_Config.Stick_Parity;
LCR.SB := Line_Config.Set_Break;
LCR.DLAB := Line_Config.Divisor_Latch_Access_Bit;
This.Regs.LCR := LCR;
end;
-- Disable LIN mode
This.Regs.MM0.ELIN := False;
-- Disable IrDA mode
This.Regs.MM1.EIRD := False;
-- Disable SmartCard Mode
This.Regs.MM2.EERR := False;
end Configure;
----------
-- Send --
----------
procedure Send
(This : in out MSS_UART;
Data : UART_Data)
is
Index : Natural := Data'First;
Transmit : Natural;
begin
loop
-- Check if TX FIFO is empty.
if This.Regs.LSR.THRE then
if Index + TX_FIFO_SIZE - 1 <= Data'Last then
Transmit := TX_FIFO_SIZE;
else
Transmit := Data'Last - Index + 1;
end if;
for J in 1 .. Transmit loop
This.Regs.THR := Interfaces.SF2.Byte (Data (Index));
Index := Index + 1;
end loop;
exit when Index > Data'Last;
end if;
end loop;
end Send;
----------
-- Send --
----------
procedure Send
(This : in out MSS_UART;
Data : String)
is
subtype My_String is String (Data'Range);
subtype My_Data is UART_Data (Data'Range);
function To_Data is new Ada.Unchecked_Conversion (My_String, My_Data);
begin
Send (This, To_Data (My_String (Data)));
end Send;
end System.SF2.UART;
|
Function INI.Section_to_Vector( Object : in Instance;
Section: in String:= ""
) return NSO.Types.String_Vector.Vector is
Use NSO.Types.String_Vector;
Begin
Return Result : Vector do
For Item in Object(Section).Iterate loop
Declare
Key : String renames KEY_VALUE_MAP.Key( Item );
Value : Value_Object renames KEY_Value_MAP.Element(Item);
Image : String renames -- "ABS"(Value);
String'(if Value.Kind = vt_String then Value.String_Value
else ABS Value);
Begin
Result.Append( Image );
End;
end loop;
Exception
when CONSTRAINT_ERROR => null;
End return;
End INI.Section_to_Vector;
|
pragma Ada_2012;
with Ada.Numerics.Elementary_Functions;
package body Callbacks is
use Ada.Numerics.Elementary_Functions;
use Engine_Values;
use Engine_Values.Engine_Value_Vectors;
---------
-- Sin --
---------
function Sin (X : Engine_Value_Vectors.Vector)
return Engine_Value_Vectors.Vector
is
begin
return To_Vector (Create (Sin (Get_Float (X.First_Element))), 1);
end Sin;
end Callbacks;
|
-----------------------------------------------------------------------
-- components-ajax-includes -- AJAX Include component
-- Copyright (C) 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 ASF.Applications.Main;
with ASF.Applications.Views;
with ASF.Components.Root;
with ASF.Contexts.Writer;
package body ASF.Components.Ajax.Includes is
-- ------------------------------
-- Get the HTML layout that must be used for the include container.
-- The default layout is a "div".
-- Returns "div", "span", "pre", "b".
-- ------------------------------
function Get_Layout (UI : in UIInclude;
Context : in ASF.Contexts.Faces.Faces_Context'Class) return String is
Layout : constant String := UI.Get_Attribute (Name => LAYOUT_ATTR_NAME,
Context => Context,
Default => "div");
begin
if Layout = "div" or Layout = "span" or Layout = "pre" or Layout = "b" then
return Layout;
else
return "div";
end if;
end Get_Layout;
-- ------------------------------
-- The included XHTML file is rendered according to the <b>async</b> attribute:
--
-- When <b>async</b> is false, render the specified XHTML file in such a way that inner
-- forms will be posted on the included view.
--
-- When <b>async</b> is true, trigger an AJAX call to include the specified
-- XHTML view when the page is loaded.
--
--
-- ------------------------------
overriding
procedure Encode_Children (UI : in UIInclude;
Context : in out ASF.Contexts.Faces.Faces_Context'Class) is
begin
if not UI.Is_Rendered (Context) then
return;
end if;
declare
App : constant ASF.Contexts.Faces.Application_Access := Context.Get_Application;
View_Handler : constant access ASF.Applications.Views.View_Handler'Class
:= App.Get_View_Handler;
Id : constant Ada.Strings.Unbounded.Unbounded_String := UI.Get_Client_Id;
Layout : constant String := UIInclude'Class (UI).Get_Layout (Context);
Async : constant Boolean := UI.Get_Attribute (Name => ASYNC_ATTR_NAME,
Context => Context,
Default => False);
Page : constant String := UI.Get_Attribute (Name => SRC_ATTR_NAME,
Context => Context,
Default => "");
Writer : constant Contexts.Writer.Response_Writer_Access := Context.Get_Response_Writer;
begin
Writer.Start_Element (Layout);
UI.Render_Attributes (Context, Writer);
-- In Async mode, generate the javascript code to trigger the async update of
-- the generated div/span.
if Async then
Writer.Write_Attribute ("id", Id);
Writer.Queue_Script ("ASF.Update(null,""");
Writer.Queue_Script (View_Handler.Get_Action_URL (Context, Page));
Writer.Queue_Script (""", ""#");
Writer.Queue_Script (Id);
Writer.Queue_Script (""");");
else
-- Include the view content as if the user fetched the patch. This has almost the
-- same final result except that the inner content is returned now and not by
-- another async http GET request.
declare
View : constant ASF.Components.Root.UIViewRoot := Context.Get_View_Root;
Include_View : ASF.Components.Root.UIViewRoot;
Is_Ajax : constant Boolean := Context.Is_Ajax_Request;
Content_Type : constant String := Context.Get_Response.Get_Content_Type;
begin
Context.Set_Ajax_Request (True);
View_Handler.Restore_View (Page, Context, Include_View);
Context.Set_View_Root (Include_View);
View_Handler.Render_View (Context, Include_View);
Context.Get_Response.Set_Content_Type (Content_Type);
Context.Set_View_Root (View);
Context.Set_Ajax_Request (Is_Ajax);
exception
when others =>
Context.Get_Response.Set_Content_Type (Content_Type);
Context.Set_View_Root (View);
Context.Set_Ajax_Request (Is_Ajax);
raise;
end;
end if;
Writer.End_Element (Layout);
end;
end Encode_Children;
end ASF.Components.Ajax.Includes;
|
with HAL; use HAL;
with HAL.GPIO;
with SAM.Device;
with SAM.Port;
with SAM.ADC;
with SAM.Clock_Generator;
with SAM.Clock_Generator.IDs;
with SAM.Main_Clock;
with SAM.Functions;
package body PyGamer.Controls is
type Buttons_State is array (Buttons) of Boolean;
Current_Pressed : Buttons_State := (others => False);
Previous_Pressed : Buttons_State := (others => False);
Clk : SAM.Port.GPIO_Point renames SAM.Device.PB31;
Latch : SAM.Port.GPIO_Point renames SAM.Device.PB00;
Input : SAM.Port.GPIO_Point renames SAM.Device.PB30;
Joy_X : SAM.Port.GPIO_Point renames SAM.Device.PB07;
Joy_Y : SAM.Port.GPIO_Point renames SAM.Device.PB06;
Joy_X_AIN : constant SAM.ADC.Positive_Selection := SAM.ADC.AIN9;
Joy_Y_AIN : constant SAM.ADC.Positive_Selection := SAM.ADC.AIN8;
Joy_X_Last : Joystick_Range := 0;
Joy_Y_Last : Joystick_Range := 0;
Joystick_Threshold : constant := 64;
ADC : SAM.ADC.ADC_Device renames SAM.Device.ADC1;
procedure Initialize;
function Read_ADC (AIN : SAM.ADC.Positive_Selection) return Joystick_Range;
----------------
-- Initialize --
----------------
procedure Initialize is
begin
-- Buttons --
Clk.Clear;
Clk.Set_Mode (HAL.GPIO.Output);
Latch.Clear;
Latch.Set_Mode (HAL.GPIO.Output);
Input.Set_Mode (HAL.GPIO.Input);
-- Joystick --
Joy_X.Set_Mode (HAL.GPIO.Input);
Joy_X.Set_Pull_Resistor (HAL.GPIO.Floating);
Joy_X.Set_Function (SAM.Functions.PB07_ADC1_AIN9);
Joy_Y.Set_Mode (HAL.GPIO.Input);
Joy_Y.Set_Pull_Resistor (HAL.GPIO.Floating);
Joy_Y.Set_Function (SAM.Functions.PB06_ADC1_AIN8);
SAM.Clock_Generator.Configure_Periph_Channel
(SAM.Clock_Generator.IDs.ADC1, Clk_48Mhz);
SAM.Main_Clock.ADC1_On;
ADC.Configure (Resolution => SAM.ADC.Res_8bit,
Reference => SAM.ADC.VDDANA,
Prescaler => SAM.ADC.Pre_16,
Free_Running => False,
Differential_Mode => False);
end Initialize;
--------------
-- Read_ADC --
--------------
function Read_ADC (AIN : SAM.ADC.Positive_Selection) return Joystick_Range is
Result : UInt16;
begin
ADC.Enable;
ADC.Set_Inputs (SAM.ADC.GND, AIN);
-- Read twice and disacard the first value.
-- See AT11481: ADC Configurations with Examples:
-- "Discard the first conversion result whenever there is a change in ADC
-- configuration like voltage reference / ADC channel change"
for X in 1 .. 2 loop
ADC.Software_Start;
while not ADC.Conversion_Done loop
null;
end loop;
Result := ADC.Result;
end loop;
ADC.Disable;
return Joystick_Range (Integer (Result) - 128);
end Read_ADC;
----------
-- Scan --
----------
procedure Scan is
type IO_Count is range 0 .. 7;
State : array (IO_Count) of Boolean;
begin
-- Buttons --
Previous_Pressed := Current_Pressed;
-- Set initial clock state
Clk.Set;
-- Load the inputs
Latch.Clear;
Latch.Set;
for X in IO_Count loop
Clk.Clear;
State (X) := Input.Set;
Clk.Set;
end loop;
Current_Pressed (B) := State (0);
Current_Pressed (A) := State (1);
Current_Pressed (Start) := State (2);
Current_Pressed (Sel) := State (3);
-- Joystick --
Joy_X_Last := Read_ADC (Joy_X_AIN);
Joy_Y_Last := Read_ADC (Joy_Y_AIN);
if (abs Integer (Joy_X_Last)) < Joystick_Threshold then
Current_Pressed (Left) := False;
Current_Pressed (Right) := False;
elsif Joy_X_Last > 0 then
Current_Pressed (Left) := False;
Current_Pressed (Right) := True;
else
Current_Pressed (Left) := True;
Current_Pressed (Right) := False;
end if;
if (abs Integer (Joy_Y_Last)) < Joystick_Threshold then
Current_Pressed (Up) := False;
Current_Pressed (Down) := False;
elsif Joy_Y_Last > 0 then
Current_Pressed (Up) := False;
Current_Pressed (Down) := True;
else
Current_Pressed (Up) := True;
Current_Pressed (Down) := False;
end if;
end Scan;
-------------
-- Pressed --
-------------
function Pressed (Button : Buttons) return Boolean
is (Current_Pressed (Button));
------------
-- Rising --
------------
function Rising (Button : Buttons) return Boolean
is (Previous_Pressed (Button) and then not Current_Pressed (Button));
-------------
-- Falling --
-------------
function Falling (Button : Buttons) return Boolean
is (not Previous_Pressed (Button) and then Current_Pressed (Button));
----------------
-- Joystick_X --
----------------
function Joystick_X return Joystick_Range
is (Joy_X_Last);
----------------
-- Joystick_Y --
----------------
function Joystick_Y return Joystick_Range
is (Joy_Y_Last);
begin
Initialize;
end PyGamer.Controls;
|
-------------------------------------------------------------------------------
-- Copyright 2021, The Septum Developers (see AUTHORS file)
-- 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.Command_Line;
with Ada.Exceptions;
with Ada.Text_IO;
with GNAT.Traceback.Symbolic;
with SP.Config;
with SP.Interactive;
procedure Septum is
use Ada.Text_IO;
begin
-- Look for a single "--version" flag
if Ada.Command_Line.Argument_Count = 1
and then Ada.Command_Line.Argument (1) = "--version"
then
Put_Line (SP.Version);
return;
end if;
-- Create a local configuration file in the current directory.
if Ada.Command_Line.Argument_Count = 1
and then Ada.Command_Line.Argument (1) = "init"
then
SP.Config.Create_Local_Config;
return;
end if;
-- Don't recognize any other arguments.
if Ada.Command_Line.Argument_Count /= 0 then
Put_Line ("Unrecognized command line arguments.");
New_Line;
Put_Line ("Usage: septum --version print program version");
Put_Line (" septum init creates config directory with empty config");
Put_Line (" septum run interactive search mode");
return;
end if;
SP.Interactive.Main;
exception
when Err : others =>
Put_Line (Ada.Exceptions.Exception_Information (Err));
Put_Line ("Exception traceback: " & GNAT.Traceback.Symbolic.Symbolic_Traceback (Err));
end Septum;
|
package body Buffer_Package is
procedure Enable_Undo (B : in out Buffer) is
begin
B.Can_Undo := True;
end Enable_Undo;
procedure Clear_Tag (B : in out Buffer; T : Tag_Type) is
begin
if T < TAG_MAX then
declare
Val : constant Integer := Tag_Type'Pos (T);
begin
B.Tags (Val).P1 := (NONE, NONE);
B.Tags (Val).P2 := (NONE, NONE);
end;
end if;
end Clear_Tag;
procedure Set_Tag
(B : out Buffer;
T : Tag_Type;
P1 : Pos;
P2 : Pos;
V : Integer)
is
begin
if T < TAG_MAX
and P1.L /= NONE
and P1.C /= NONE
and P2.L /= NONE
and P2.C /= NONE
then
declare
Val : constant Integer := Tag_Type'Pos (T);
begin
B.Tags (Val).P1 := P1;
B.Tags (Val).P2 := P2;
B.Tags (Val).V := V;
end;
end if;
end Set_Tag;
end Buffer_Package;
|
{% load kdev_filters %}
{% block license_header %}
{% if license %}
--
{{ license|lines_prepend:"-- " }}
--
{% endif %}
{% endblock license_header %}
{% if baseClasses %}
with {% for b in baseClasses %}b.baseType{% if not forloop.last %}, {% endif %}{% endfor %};
{% endif %}
package body {{ name }} is
{% for f in functions %}
{% with f.arguments as arguments %}
{% if f.returnType == "" %}
procedure {{ f.name }}({% include "arguments_types_names.txt" %}) is
begin
raise Todo;
end;
{% else %}
function {{ f.name }}({% include "arguments_types_names.txt" %}) return {{ f.returnType }} is
begin
raise Todo;
end;
{% endif %}
{% endwith %}
{% endfor %}
end {{ name }};
|
with Interfaces.C;
with Interfaces.C.Strings;
with Ada.Containers;
with Cups.String_Maps;
private with CUPS.Cups_Cups_H;
with System;
with Ada.Strings.Bounded;
with Ada.Sequential_IO; use Ada;
with Ada.Text_IO;
package CUPS.CUPS is
use Interfaces.C.Strings;
use Interfaces.C;
use Ada.Containers;
function GetDefault return String;
--
-- Get the default printer or class for the default server.
-- This function returns the default printer or class as defined by the
-- LPDEST or PRINTER environment variables.
-- If these environment variables are not set, the
-- server default destination is returned.
-- Applications should use the cupsGetDests and cupsGetDest functions to
-- get the user-defined default printer,
-- as this function does not support the lpoptions-defined default printer.
procedure CancelJob
(Name : String := Cups.GetDefault;
JobId : Integer := -1 );
--
-- Cancel a job in the queue
-- JobId -1 yields a termination of all jobs
function GetDefaultPrinterState return String;
--
-- Get the state of the default printer
procedure PrintString ( Str : String; Raw : Boolean);
--
-- Print a string on the default printer
-- Set RAW True if raw printing is wanted
-------------------------------------------------------------------------------
private
use Cups_Cups_H;
type Option_T is access Cups_Option_T;
type Destination_T is access all Cups_Dest_T;
procedure SetRawPrinting (Num_Options : in out Job_ID;
Options : aliased Option_T);
--
-- Initialises RAW printing and USB-no-reattach-default
function AddOption
(Name : String;
Value : String;
Num_Options : Job_Id;
Options : aliased Option_T) return Job_Id;
--
-- Add an option to an option array
function GetOption
(Name : String;
Num_Options : Job_Id;
Options : Option_T) return String;
--
-- Get an Option Value or Null
-- For instance, "printer-state" tells if the printer is idle, processing etc..
function PrintFile
(Name : String;
Filename : String;
Title : String;
Num_Options : Job_Id;
Options : Option_T) return Job_Id;
--
-- Print a file to a printer or class on the default server.
end CUPS.CUPS;
|
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
procedure Table_Pythagore is
Taille: Integer; -- taille de la table
begin
-- Demander la taille
Get (Taille);
-- Afficher la table de Pythagore
for I in 0 .. Taille loop
for J in 0 .. Taille loop
if I = 0 and J = 0 then
Put("X");
elsif I = 0 then
Put(J, 3);
elsif J = 0 then
Put(I, 1);
else
Put(I*J, 3);
end if;
end loop;
New_Line;
end loop;
end Table_Pythagore;
|
-- AOC 2020, Day 16
with Ada.Containers.Vectors;
with Ada.Containers; use Ada.Containers;
package Day is
type Tickets is private;
function load_file(filename : in String) return Tickets;
function sum_error_rate(t : in Tickets) return Natural;
function departure_fields(t : in Tickets) return Long_Integer;
private
type Field_Rule is record
Min, Max : Natural;
end record;
type Combined_Rules is array(1..2) of Field_Rule;
package Rule_Vectors is new Ada.Containers.Vectors
(Index_Type => Natural,
Element_Type => Combined_Rules);
use Rule_Vectors;
package Value_Vectors is new Ada.Containers.Vectors
(Index_Type => Natural,
Element_Type => Natural);
use Value_Vectors;
package Nested_Vectors is new Ada.Containers.Vectors
(Index_Type => Natural,
Element_Type => Value_Vectors.Vector);
use Nested_Vectors;
type Tickets is record
Rules : Rule_Vectors.Vector := Rule_Vectors.Empty_Vector;
Values : Nested_Vectors.Vector := Nested_Vectors.Empty_Vector;
Ticket : Value_Vectors.Vector := Value_Vectors.Empty_Vector;
end record;
end Day;
|
-- for ZCX
pragma Check_Policy (Trace => Ignore);
with C.unwind;
separate (System.Unwind.Backtrace)
package body Separated is
pragma Suppress (All_Checks);
type Data is record
Item : not null access Tracebacks_Array;
Last : Natural;
Exclude_Min : Address;
Exclude_Max : Address;
end record;
pragma Suppress_Initialization (Data);
function Unwind_Trace (
Context : access C.unwind.struct_Unwind_Context;
Argument : C.void_ptr)
return C.unwind.Unwind_Reason_Code
with Convention => C;
function Unwind_Trace (
Context : access C.unwind.struct_Unwind_Context;
Argument : C.void_ptr)
return C.unwind.Unwind_Reason_Code
is
pragma Check (Trace, Ada.Debug.Put ("enter"));
D : Data;
for D'Address use Address (Argument);
IP : constant Address :=
System'To_Address (C.unwind.Unwind_GetIP (Context));
begin
if IP >= D.Exclude_Min and then IP <= D.Exclude_Max then
D.Last := Tracebacks_Array'First - 1; -- reset
pragma Check (Trace, Ada.Debug.Put ("exclude"));
else
D.Last := D.Last + 1;
D.Item (D.Last) := IP;
pragma Check (Trace, Ada.Debug.Put ("fill"));
if D.Last >= Tracebacks_Array'Last then
pragma Check (Trace, Ada.Debug.Put ("leave, over"));
return C.unwind.URC_NORMAL_STOP;
end if;
end if;
pragma Check (Trace, Ada.Debug.Put ("leave"));
return C.unwind.URC_NO_REASON;
end Unwind_Trace;
procedure Backtrace (
Item : aliased out Tracebacks_Array;
Last : out Natural;
Exclude_Min : Address;
Exclude_Max : Address)
is
D : aliased Data := (
Item'Unchecked_Access,
Tracebacks_Array'First - 1,
Exclude_Min,
Exclude_Max);
Dummy : C.unwind.Unwind_Reason_Code;
begin
pragma Check (Trace, Ada.Debug.Put ("start"));
Dummy := C.unwind.Unwind_Backtrace (
Unwind_Trace'Access,
C.void_ptr (D'Address));
pragma Check (Trace, Ada.Debug.Put ("end"));
Last := D.Last;
end Backtrace;
end Separated;
|
-- SPDX-License-Identifier: Apache-2.0
--
-- Copyright (c) 2016 onox <denkpadje@gmail.com>
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
with GL.Drawing;
package body Orka.Rendering.Drawing is
use GL.Types;
procedure Draw
(Mode : GL.Types.Connection_Mode;
Offset, Count : Natural;
Instances : Positive := 1) is
begin
GL.Drawing.Draw_Arrays
(Mode,
Offset => Size (Offset),
Count => Size (Count),
Instances => Size (Instances));
end Draw;
procedure Draw_Indexed
(Mode : GL.Types.Connection_Mode;
Index_Buffer : Buffers.Buffer;
Offset, Count : Natural;
Instances : Positive := 1)
is
use all type Rendering.Buffers.Buffer_Target;
begin
Index_Buffer.Bind (Index);
GL.Drawing.Draw_Elements
(Mode,
Count => Size (Count),
Index_Kind => Orka.Types.Convert (Index_Buffer.Kind),
Index_Offset => Offset,
Instances => Size (Instances));
end Draw_Indexed;
-----------------------------------------------------------------------------
procedure Draw_Indirect
(Mode : GL.Types.Connection_Mode;
Buffer : Buffers.Buffer;
Offset, Count : Natural)
is
use all type Rendering.Buffers.Buffer_Target;
begin
Buffer.Bind (Draw_Indirect);
GL.Drawing.Draw_Multiple_Arrays_Indirect
(Mode, Count => Size (Count), Offset => Size (Offset));
end Draw_Indirect;
procedure Draw_Indirect
(Mode : GL.Types.Connection_Mode;
Buffer : Buffers.Buffer) is
begin
Draw_Indirect (Mode, Buffer, Offset => 0, Count => Buffer.Length);
end Draw_Indirect;
procedure Draw_Indirect
(Mode : GL.Types.Connection_Mode;
Buffer, Count : Buffers.Buffer)
is
use all type Rendering.Buffers.Buffer_Target;
begin
Buffer.Bind (Draw_Indirect);
Count.Bind (Parameter);
GL.Drawing.Draw_Multiple_Arrays_Indirect_Count
(Mode, GL.Types.Size (Buffer.Length));
end Draw_Indirect;
-----------------------------------------------------------------------------
procedure Draw_Indexed_Indirect
(Mode : GL.Types.Connection_Mode;
Index_Buffer : Buffers.Buffer;
Buffer : Buffers.Buffer;
Offset, Count : Natural)
is
use all type Rendering.Buffers.Buffer_Target;
begin
Index_Buffer.Bind (Index);
Buffer.Bind (Draw_Indirect);
GL.Drawing.Draw_Multiple_Elements_Indirect
(Mode, Orka.Types.Convert (Index_Buffer.Kind),
Count => Size (Count), Offset => Size (Offset));
end Draw_Indexed_Indirect;
procedure Draw_Indexed_Indirect
(Mode : GL.Types.Connection_Mode;
Index_Buffer : Buffers.Buffer;
Buffer : Buffers.Buffer) is
begin
Draw_Indexed_Indirect (Mode, Index_Buffer, Buffer, Offset => 0, Count => Buffer.Length);
end Draw_Indexed_Indirect;
procedure Draw_Indexed_Indirect
(Mode : GL.Types.Connection_Mode;
Index_Buffer : Buffers.Buffer;
Buffer, Count : Buffers.Buffer)
is
use all type Rendering.Buffers.Buffer_Target;
begin
Index_Buffer.Bind (Index);
Buffer.Bind (Draw_Indirect);
Count.Bind (Parameter);
GL.Drawing.Draw_Multiple_Elements_Indirect_Count
(Mode, Orka.Types.Convert (Index_Buffer.Kind), GL.Types.Size (Buffer.Length));
end Draw_Indexed_Indirect;
end Orka.Rendering.Drawing;
|
-- with Ada.Text_IO; -- Debug.
with Ada.Unchecked_Deallocation,
Ada.Strings.Fixed,
Ada.Characters.Handling;
package body ARM_Database is
--
-- Ada reference manual formatter (ARM_Form).
--
-- This package contains the database to store items for non-normative
-- appendixes.
--
-- ---------------------------------------
-- Copyright 2000, 2004, 2005, 2006, 2009, 2011, 2012
-- AXE Consultants. All rights reserved.
-- P.O. Box 1512, Madison WI 53701
-- E-Mail: randy@rrsoftware.com
--
-- ARM_Form is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License version 3
-- as published by the Free Software Foundation.
--
-- AXE CONSULTANTS MAKES THIS TOOL AND SOURCE CODE AVAILABLE ON AN "AS IS"
-- BASIS AND MAKES NO WARRANTY, EXPRESS OR IMPLIED, AS TO THE ACCURACY,
-- CAPABILITY, EFFICIENCY, MERCHANTABILITY, OR FUNCTIONING OF THIS TOOL.
-- IN NO EVENT WILL AXE CONSULTANTS BE LIABLE FOR ANY GENERAL,
-- CONSEQUENTIAL, INDIRECT, INCIDENTAL, EXEMPLARY, OR SPECIAL DAMAGES,
-- EVEN IF AXE CONSULTANTS HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
-- DAMAGES.
--
-- A copy of the GNU General Public License is available in the file
-- gpl-3-0.txt in the standard distribution of the ARM_Form tool.
-- Otherwise, see <http://www.gnu.org/licenses/>.
--
-- If the GPLv3 license is not satisfactory for your needs, a commercial
-- use license is available for this tool. Contact Randy at AXE Consultants
-- for more information.
--
-- ---------------------------------------
--
-- Edit History:
--
-- 5/16/00 - RLB - Created package.
-- 8/28/00 - RLB - Added revision info to database.
-- 10/28/04 - RLB - Added Inserted_Normal_Number change kind.
-- 11/02/04 - RLB - Added Deleted_Inserted_Number change kind.
-- 12/06/04 - RLB - Added Revised_Inserted_Number change kind.
-- 12/14/04 - RLB - Made the hang item bigger.
-- 1/19/05 - RLB - Added Added_Version.
-- 10/17/05 - RLB - Fixed indexing of the Glossary.
-- 10/18/06 - RLB - Added No_Deleted_Paragraph_Messages to Report.
-- 11/30/09 - RLB - Made the hang item bigger again (to make room to
-- handle commands like @ChgAdded).
-- 10/18/11 - RLB - Changed to GPLv3 license.
-- 10/20/11 - RLB - Added Initial_Version parameter.
-- 3/19/12 - RLB - Added code to suppress indexing of deleted glossary items.
type String_Ptr is access String;
type Item is record
Next : Item_List;
Sort_Key : String(1 .. 50);
Hang : String(1 .. 75);
Hang_Len : Natural;
Text : String_Ptr;
Change_Kind : Paragraph_Change_Kind_Type;
Version : Character;
Initial_Version : Character;
end record;
procedure Free is new Ada.Unchecked_Deallocation (Item, Item_List);
procedure Free is new Ada.Unchecked_Deallocation (String, String_Ptr);
procedure Create (Database_Object : in out Database_Type) is
-- Initialize a database object.
begin
Database_Object.Is_Valid := True;
Database_Object.List := null;
Database_Object.Item_Count := 0;
end Create;
procedure Destroy (Database_Object : in out Database_Type) is
-- Destroy a database object, freeing any resources used.
Temp : Item_List;
begin
if not Database_Object.Is_Valid then
raise Not_Valid_Error;
end if;
while Database_Object.List /= null loop
Temp := Database_Object.List;
Database_Object.List := Temp.Next;
Free (Temp.Text);
Free (Temp);
end loop;
Database_Object.Is_Valid := False;
end Destroy;
procedure Insert (Database_Object : in out Database_Type;
Sort_Key : in String;
Hang_Item : in String;
Text : in String;
Change_Kind : in Paragraph_Change_Kind_Type := ARM_Database.None;
Version : in Character := '0';
Initial_Version : in Character := '0') is
-- Insert an item into the database object.
-- Sort_Key is the string on which this item will be sorted (if it
-- is sorted). Hang_Item is the item which hangs out for the item
-- in the report (if any). Text is the text for the item; the text
-- may include formatting codes. Change_Kind and Version are the
-- revision status for this item. Initial_Version is the version of
-- the initial text for this item.
Temp_Item : Item;
begin
if not Database_Object.Is_Valid then
raise Not_Valid_Error;
end if;
Ada.Strings.Fixed.Move (Target => Temp_Item.Sort_Key,
Source => Ada.Characters.Handling.To_Lower(Sort_Key),
Drop => Ada.Strings.Right,
Pad => ' ');
Ada.Strings.Fixed.Move (Target => Temp_Item.Hang,
Source => Hang_Item,
Drop => Ada.Strings.Error,
Pad => ' ');
Temp_Item.Hang_Len := Hang_Item'Length;
-- Note: If this second item doesn't fit, we error so we can make
-- the size larger.
Temp_Item.Text := new String'(Text);
Temp_Item.Change_Kind := Change_Kind;
Temp_Item.Version := Version;
Temp_Item.Initial_Version := Initial_Version;
Temp_Item.Next := Database_Object.List;
Database_Object.List := new Item'(Temp_Item);
Database_Object.Item_Count := Database_Object.Item_Count + 1;
end Insert;
--generic
-- with procedure Format_Text (Text : in String;
-- Text_Name : in String);
procedure Report (Database_Object : in out Database_Type;
In_Format : in Format_Type;
Sorted : in Boolean;
Added_Version : Character := '0';
No_Deleted_Paragraph_Messages : in Boolean := False) is
-- Output the items with the appropriate format to the
-- "Format_Text" routine. "Format_Text" allows all commands
-- for the full formatter. (Text_Name is an identifying name
-- for error messages). This is an added list for Added_Version
-- ('0' meaning it is not added); in that case, use normal numbers
-- for items with a version less than or equal to Added_Version.
-- (This is intended to be used to output the items to
-- appropriate Format and Output objects; but we can't do that
-- directly because that would make this unit recursive with
-- ARM_Format.
-- No paragraphs will be have deleted paragraph messages if
-- No_Deleted_Paragraph_Messages is True.
Temp : Item_List;
function Change_if_Needed (Item : in Item_List) return String is
begin
-- Note: In the report, we always decide inserted/not inserted
-- as determined by the initial version number, and not the
-- original class.
case Item.Change_Kind is
when None => return "";
when Inserted | Inserted_Normal_Number =>
if Item.Initial_Version <= Added_Version then
return "@ChgRef{Version=[" & Item.Version &
"],Kind=[AddedNormal]}";
else
return "@ChgRef{Version=[" & Item.Version &
"],Kind=[Added]}";
end if;
when Revised | Revised_Inserted_Number =>
if Item.Initial_Version <= Added_Version then
return "@ChgRef{Version=[" & Item.Version &
"],Kind=[Revised]}";
else
return "@ChgRef{Version=[" & Item.Version &
"],Kind=[RevisedAdded]}";
end if;
when Deleted | Deleted_Inserted_Number =>
if Item.Initial_Version <= Added_Version then
if No_Deleted_Paragraph_Messages then
return "@ChgRef{Version=[" & Item.Version &
"],Kind=[DeletedNoDelMsg]}";
else
return "@ChgRef{Version=[" & Item.Version &
"],Kind=[Deleted]}";
end if;
else
if No_Deleted_Paragraph_Messages then
return "@ChgRef{Version=[" & Item.Version &
"],Kind=[DeletedAddedNoDelMsg]}";
else
return "@ChgRef{Version=[" & Item.Version &
"],Kind=[DeletedAdded]}";
end if;
end if;
when Deleted_No_Delete_Message |
Deleted_Inserted_Number_No_Delete_Message =>
if Item.Initial_Version <= Added_Version then
return "@ChgRef{Version=[" & Item.Version &
"],Kind=[DeletedNoDelMsg]}";
else
return "@ChgRef{Version=[" & Item.Version &
"],Kind=[DeletedAddedNoDelMsg]}";
end if;
end case;
end Change_if_Needed;
begin
if not Database_Object.Is_Valid then
raise Not_Valid_Error;
end if;
if Sorted then
declare
Items : array (1..Database_Object.Item_Count) of Item_List;
begin
-- Load the items:
Temp := Database_Object.List;
for I in Items'range loop
Items(I) := Temp;
Temp := Temp.Next;
end loop;
-- Sort the items array (use an insertion sort because it is
-- stable):
declare
Left : Natural; -- Left sorting stop
begin
for Right In Items'First+1 .. Items'Last loop -- Right sorting stop
Temp := Items(Right);
Left := Right - 1;
while Temp.Sort_Key <= Items(Left).Sort_Key loop -- Switch items
Items(Left + 1) := Items(Left);
Left := Left - 1;
exit when Left = 0;
end loop;
Items(Left + 1) := Temp;
end loop;
end;
-- Relink the items in the sorted order:
for I in Items'First .. Items'Last - 1 loop
Items(I).Next := Items(I+1);
end loop;
if Items'Length > 0 then
Items(Items'Last).Next := null;
Database_Object.List := Items(1);
else
Database_Object.List := null;
end if;
end;
end if;
case In_Format is
when Hanging_List =>
Format_Text ("@begin(description)" & Ascii.LF, "Prefix");
Temp := Database_Object.List;
while Temp /= null loop
--** Debug:
--Ada.Text_IO.Put_Line ("^^ " & Paragraph_Change_Kind_Type'Image(Temp.Change_Kind) &
-- " for " & Temp.Hang(1..Temp.Hang_Len) & " ref=" & Change_if_Needed (Temp));
--Ada.Text_IO.Put_Line (" " & Change_if_Needed (Temp) &
--Temp.Hang(1..Temp.Hang_Len) & "@\" &
--Temp.Text.all & Ascii.LF & Ascii.LF);
Format_Text (Change_if_Needed (Temp) &
Temp.Hang(1..Temp.Hang_Len) & "@\" &
Temp.Text.all & Ascii.LF & Ascii.LF, Temp.Sort_Key);
Temp := Temp.Next;
end loop;
Format_Text ("@end(description)" & Ascii.LF, "Suffix");
when Bullet_List =>
Format_Text ("@begin(itemize)" & Ascii.LF, "Prefix");
Temp := Database_Object.List;
while Temp /= null loop
Format_Text (Change_if_Needed (Temp) &
Temp.Text.all & Ascii.LF & Ascii.LF, Temp.Sort_Key);
Temp := Temp.Next;
end loop;
Format_Text ("@end(itemize)" & Ascii.LF, "Suffix");
when Normal_List =>
Format_Text ("@begin(intro)" & Ascii.LF, "Prefix");
Temp := Database_Object.List;
while Temp /= null loop
Format_Text (Change_if_Needed (Temp) &
Temp.Text.all & Ascii.LF & Ascii.LF, Temp.Sort_Key);
Temp := Temp.Next;
end loop;
Format_Text ("@end(intro)" & Ascii.LF, "Suffix");
when Normal_Indexed_List =>
Format_Text ("@begin(intro)" & Ascii.LF, "Prefix");
Temp := Database_Object.List;
while Temp /= null loop
case Temp.Change_Kind is
when None |
Inserted | Inserted_Normal_Number |
Revised | Revised_Inserted_Number =>
--** Debug:
--Ada.Text_IO.Put_Line("Format " & Change_if_Needed (Temp) &
-- "@defn{" & Ada.Strings.Fixed.Trim (Temp.Sort_Key, Ada.Strings.Right) & "}" & Ascii.LF &
-- Temp.Text.all);
-- Index this item.
Format_Text (Change_if_Needed (Temp) &
"@defn{" & Ada.Strings.Fixed.Trim (Temp.Sort_Key, Ada.Strings.Right) & "}" & Ascii.LF &
Temp.Text.all & Ascii.LF & Ascii.LF, Temp.Sort_Key);
when Deleted | Deleted_Inserted_Number |
Deleted_No_Delete_Message |
Deleted_Inserted_Number_No_Delete_Message =>
--** Debug:
--Ada.Text_IO.Put_Line("Format " & Change_if_Needed (Temp) & Ascii.LF &
-- Temp.Text.all);
-- Don't index deleted items.
Format_Text (Change_if_Needed (Temp) & Ascii.LF &
Temp.Text.all & Ascii.LF & Ascii.LF, Temp.Sort_Key);
end case;
Temp := Temp.Next;
end loop;
Format_Text ("@end(intro)" & Ascii.LF, "Suffix");
end case;
end Report;
end ARM_Database;
|
pragma License (Unrestricted);
-- Ada 2012
private with Ada.Finalization;
private with System.Synchronous_Objects;
package Ada.Synchronous_Barriers is
pragma Preelaborate;
subtype Barrier_Limit is
Positive range 1 .. Natural'Last; -- implementation-defined
type Synchronous_Barrier (
Release_Threshold : Barrier_Limit) is limited private;
procedure Wait_For_Release (
The_Barrier : in out Synchronous_Barrier;
Notified : out Boolean);
private
type Synchronous_Barrier (
Release_Threshold : Barrier_Limit) is
limited new Finalization.Limited_Controlled with
record
Mutex : System.Synchronous_Objects.Mutex;
Event : System.Synchronous_Objects.Event;
Blocked : Natural;
Unblocked : Natural;
end record;
overriding procedure Initialize (Object : in out Synchronous_Barrier);
overriding procedure Finalize (Object : in out Synchronous_Barrier);
end Ada.Synchronous_Barriers;
|
package gel.Dolly.simple
--
-- Provides a simple camera dolly.
--
is
type Item is new gel.Dolly.item with private;
type View is access all Item'Class;
---------
--- Forge
--
overriding
procedure define (Self : in out Item);
overriding
procedure destroy (Self : in out Item);
--------------
--- Operations
--
overriding
procedure freshen (Self : in out Item);
private
type Direction_Flags is array (Direction) of Boolean;
type Item is new gel.Dolly.item with null record;
end gel.Dolly.simple;
|
with PathPackage, IntrospectorPackage, ObjectPack, PositionPackage;
use PathPackage, IntrospectorPackage, ObjectPack, PositionPackage;
package EnvironmentPackage is
DEFAULT_LENGTH : constant Integer := 8;
SUCCESS : constant Integer := 0;
FAILURE : constant Integer := 1;
IDENTITY : constant Integer := 2;
type Environment is new Object with
record
current : Integer;
omega : IntArrayPtr := null;
introspector : IntrospectorPtr;
status : Integer := EnvironmentPackage.SUCCESS;
subterm : ObjectPtrArrayPtr := null; --subterms must inherit from Object
end record;
type EnvironmentPtr is access all Environment;
procedure makeEnvironment(env: in out Environment);
procedure makeEnvironment(env: in out Environment; intro: IntrospectorPtr);
function newEnvironment return EnvironmentPtr;
function newEnvironment(intro: IntrospectorPtr) return EnvironmentPtr;
function clone(env: Environment) return Environment;
function equals(env1, env2 : Environment) return Boolean;
function hashCode(env: Environment) return Integer;
function getStatus(env: Environment) return Integer;
procedure setStatus(env: in out Environment; s: Integer);
function getRoot(env: Environment) return ObjectPtr;
procedure setRoot(env: in out Environment; r: ObjectPtr);
function getCurrentStack(env: Environment) return ObjectPtrArray;
function getAncestor(env: Environment) return ObjectPtr;
function getSubject(env: Environment) return ObjectPtr;
procedure setSubject(env: in out Environment; root: ObjectPtr);
function getIntrospector(env: Environment) return IntrospectorPtr;
procedure setIntrospector(env: in out Environment; i: IntrospectorPtr);
function getSubOmega(env: Environment) return Integer;
function depth(env: Environment) return Integer;
function getPosition(env: Environment) return Position;
procedure up(env: in out Environment);
procedure upLocal(env: in out Environment);
procedure down(env: in out Environment; n: Integer);
procedure followPath(env: in out Environment; p: Path'Class);
procedure followPathLocal(env: in out Environment; p: Path'Class);
procedure goToPosition(env: in out Environment; p: Position);
function toString(env: Environment) return String;
private
procedure makeEnvironment(env: in out Environment; len: Integer ; intro: IntrospectorPtr);
procedure ensureLength(env: in out Environment; minLength: Integer);
procedure genericFollowPath(env: in out Environment; p: Path'Class; local: Boolean);
end EnvironmentPackage;
|
package dispatch1_p is
type I1 is interface;
type DT_I1 is new I1 with null record;
end;
|
pragma Style_Checks (Off);
-- This spec has been automatically generated from STM32G474xx.svd
pragma Restrictions (No_Elaboration_Code);
with HAL;
with System;
package STM32_SVD.FMAC is
pragma Preelaborate;
---------------
-- Registers --
---------------
subtype X1BUFCFG_X1_BASE_Field is HAL.UInt8;
subtype X1BUFCFG_X1_BUF_SIZE_Field is HAL.UInt8;
subtype X1BUFCFG_FULL_WM_Field is HAL.UInt2;
-- FMAC X1 Buffer Configuration register
type X1BUFCFG_Register is record
-- X1_BASE
X1_BASE : X1BUFCFG_X1_BASE_Field := 16#0#;
-- X1_BUF_SIZE
X1_BUF_SIZE : X1BUFCFG_X1_BUF_SIZE_Field := 16#0#;
-- unspecified
Reserved_16_23 : HAL.UInt8 := 16#0#;
-- FULL_WM
FULL_WM : X1BUFCFG_FULL_WM_Field := 16#0#;
-- unspecified
Reserved_26_31 : HAL.UInt6 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for X1BUFCFG_Register use record
X1_BASE at 0 range 0 .. 7;
X1_BUF_SIZE at 0 range 8 .. 15;
Reserved_16_23 at 0 range 16 .. 23;
FULL_WM at 0 range 24 .. 25;
Reserved_26_31 at 0 range 26 .. 31;
end record;
subtype X2BUFCFG_X2_BASE_Field is HAL.UInt8;
subtype X2BUFCFG_X2_BUF_SIZE_Field is HAL.UInt8;
-- FMAC X2 Buffer Configuration register
type X2BUFCFG_Register is record
-- X1_BASE
X2_BASE : X2BUFCFG_X2_BASE_Field := 16#0#;
-- X1_BUF_SIZE
X2_BUF_SIZE : X2BUFCFG_X2_BUF_SIZE_Field := 16#0#;
-- unspecified
Reserved_16_31 : HAL.UInt16 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for X2BUFCFG_Register use record
X2_BASE at 0 range 0 .. 7;
X2_BUF_SIZE at 0 range 8 .. 15;
Reserved_16_31 at 0 range 16 .. 31;
end record;
subtype YBUFCFG_Y_BASE_Field is HAL.UInt8;
subtype YBUFCFG_Y_BUF_SIZE_Field is HAL.UInt8;
subtype YBUFCFG_EMPTY_WM_Field is HAL.UInt2;
-- FMAC Y Buffer Configuration register
type YBUFCFG_Register is record
-- X1_BASE
Y_BASE : YBUFCFG_Y_BASE_Field := 16#0#;
-- X1_BUF_SIZE
Y_BUF_SIZE : YBUFCFG_Y_BUF_SIZE_Field := 16#0#;
-- unspecified
Reserved_16_23 : HAL.UInt8 := 16#0#;
-- EMPTY_WM
EMPTY_WM : YBUFCFG_EMPTY_WM_Field := 16#0#;
-- unspecified
Reserved_26_31 : HAL.UInt6 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for YBUFCFG_Register use record
Y_BASE at 0 range 0 .. 7;
Y_BUF_SIZE at 0 range 8 .. 15;
Reserved_16_23 at 0 range 16 .. 23;
EMPTY_WM at 0 range 24 .. 25;
Reserved_26_31 at 0 range 26 .. 31;
end record;
subtype PARAM_P_Field is HAL.UInt8;
subtype PARAM_Q_Field is HAL.UInt8;
subtype PARAM_R_Field is HAL.UInt8;
subtype PARAM_FUNC_Field is HAL.UInt7;
-- FMAC Parameter register
type PARAM_Register is record
-- P
P : PARAM_P_Field := 16#0#;
-- Q
Q : PARAM_Q_Field := 16#0#;
-- R
R : PARAM_R_Field := 16#0#;
-- FUNC
FUNC : PARAM_FUNC_Field := 16#0#;
-- START
START : Boolean := False;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for PARAM_Register use record
P at 0 range 0 .. 7;
Q at 0 range 8 .. 15;
R at 0 range 16 .. 23;
FUNC at 0 range 24 .. 30;
START at 0 range 31 .. 31;
end record;
-- FMAC Control register
type CR_Register is record
-- RIEN
RIEN : Boolean := False;
-- WIEN
WIEN : Boolean := False;
-- OVFLIEN
OVFLIEN : Boolean := False;
-- UNFLIEN
UNFLIEN : Boolean := False;
-- SATIEN
SATIEN : Boolean := False;
-- unspecified
Reserved_5_7 : HAL.UInt3 := 16#0#;
-- DMAREN
DMAREN : Boolean := False;
-- DMAWEN
DMAWEN : Boolean := False;
-- unspecified
Reserved_10_14 : HAL.UInt5 := 16#0#;
-- CLIPEN
CLIPEN : Boolean := False;
-- RESET
RESET : Boolean := False;
-- unspecified
Reserved_17_31 : HAL.UInt15 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for CR_Register use record
RIEN at 0 range 0 .. 0;
WIEN at 0 range 1 .. 1;
OVFLIEN at 0 range 2 .. 2;
UNFLIEN at 0 range 3 .. 3;
SATIEN at 0 range 4 .. 4;
Reserved_5_7 at 0 range 5 .. 7;
DMAREN at 0 range 8 .. 8;
DMAWEN at 0 range 9 .. 9;
Reserved_10_14 at 0 range 10 .. 14;
CLIPEN at 0 range 15 .. 15;
RESET at 0 range 16 .. 16;
Reserved_17_31 at 0 range 17 .. 31;
end record;
-- FMAC Status register
type SR_Register is record
-- Read-only. YEMPTY
YEMPTY : Boolean;
-- Read-only. X1FULL
X1FULL : Boolean;
-- unspecified
Reserved_2_7 : HAL.UInt6;
-- Read-only. OVFL
OVFL : Boolean;
-- Read-only. UNFL
UNFL : Boolean;
-- Read-only. SAT
SAT : Boolean;
-- unspecified
Reserved_11_31 : HAL.UInt21;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for SR_Register use record
YEMPTY at 0 range 0 .. 0;
X1FULL at 0 range 1 .. 1;
Reserved_2_7 at 0 range 2 .. 7;
OVFL at 0 range 8 .. 8;
UNFL at 0 range 9 .. 9;
SAT at 0 range 10 .. 10;
Reserved_11_31 at 0 range 11 .. 31;
end record;
subtype WDATA_WDATA_Field is HAL.UInt16;
-- FMAC Write Data register
type WDATA_Register is record
-- Write-only. WDATA
WDATA : WDATA_WDATA_Field := 16#0#;
-- unspecified
Reserved_16_31 : HAL.UInt16 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for WDATA_Register use record
WDATA at 0 range 0 .. 15;
Reserved_16_31 at 0 range 16 .. 31;
end record;
subtype RDATA_RDATA_Field is HAL.UInt16;
-- FMAC Read Data register
type RDATA_Register is record
-- Read-only. RDATA
RDATA : RDATA_RDATA_Field;
-- unspecified
Reserved_16_31 : HAL.UInt16;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for RDATA_Register use record
RDATA at 0 range 0 .. 15;
Reserved_16_31 at 0 range 16 .. 31;
end record;
-----------------
-- Peripherals --
-----------------
-- Filter Math Accelerator
type FMAC_Peripheral is record
-- FMAC X1 Buffer Configuration register
X1BUFCFG : aliased X1BUFCFG_Register;
-- FMAC X2 Buffer Configuration register
X2BUFCFG : aliased X2BUFCFG_Register;
-- FMAC Y Buffer Configuration register
YBUFCFG : aliased YBUFCFG_Register;
-- FMAC Parameter register
PARAM : aliased PARAM_Register;
-- FMAC Control register
CR : aliased CR_Register;
-- FMAC Status register
SR : aliased SR_Register;
-- FMAC Write Data register
WDATA : aliased WDATA_Register;
-- FMAC Read Data register
RDATA : aliased RDATA_Register;
end record
with Volatile;
for FMAC_Peripheral use record
X1BUFCFG at 16#0# range 0 .. 31;
X2BUFCFG at 16#4# range 0 .. 31;
YBUFCFG at 16#8# range 0 .. 31;
PARAM at 16#C# range 0 .. 31;
CR at 16#10# range 0 .. 31;
SR at 16#14# range 0 .. 31;
WDATA at 16#18# range 0 .. 31;
RDATA at 16#1C# range 0 .. 31;
end record;
-- Filter Math Accelerator
FMAC_Periph : aliased FMAC_Peripheral
with Import, Address => FMAC_Base;
end STM32_SVD.FMAC;
|
with Ada.Text_IO; use Ada.Text_IO;
procedure Test is
begin
for I in 'a' .. 10 loop
New_Line;
end loop;
end;
|
with Ada.Real_Time;
with ACO.CANopen;
with ACO.Messages;
with ACO.OD;
with ACO.SDO_Sessions;
private with Interfaces;
private with ACO.Log;
private with ACO.Utils.Generic_Alarms;
private with ACO.Configuration;
private with ACO.SDO_Commands;
private with ACO.OD_Types;
package ACO.Protocols.Service_Data is
SDO_S2C_Id : constant ACO.Messages.Function_Code := 16#B#;
SDO_C2S_Id : constant ACO.Messages.Function_Code := 16#C#;
type SDO
(Handler : not null access ACO.CANopen.Handler;
Od : not null access ACO.OD.Object_Dictionary'Class)
is abstract new Protocol with private;
function Tx_CAN_Id
(This : SDO;
Parameter : ACO.SDO_Sessions.SDO_Parameters)
return ACO.Messages.Id_Type is abstract;
function Rx_CAN_Id
(This : SDO;
Parameter : ACO.SDO_Sessions.SDO_Parameters)
return ACO.Messages.Id_Type is abstract;
function Get_Endpoint
(This : SDO;
Rx_CAN_Id : ACO.Messages.Id_Type)
return ACO.SDO_Sessions.Endpoint_Type is abstract;
procedure Result_Callback
(This : in out SDO;
Session : in ACO.SDO_Sessions.SDO_Session;
Result : in ACO.SDO_Sessions.SDO_Result) is abstract;
overriding
function Is_Valid
(This : in out SDO;
Msg : in ACO.Messages.Message)
return Boolean;
procedure Message_Received
(This : in out SDO'Class;
Msg : in ACO.Messages.Message)
with Pre => This.Is_Valid (Msg);
procedure Periodic_Actions
(This : in out SDO;
T_Now : in Ada.Real_Time.Time);
procedure Clear
(This : in out SDO;
Id : in ACO.SDO_Sessions.Valid_Endpoint_Nr);
private
type Error_Type is
(Nothing,
Unknown,
General_Error,
Invalid_Value_For_Parameter,
Toggle_Bit_Not_Altered,
SDO_Protocol_Timed_Out,
Command_Specifier_Not_Valid_Or_Unknown,
Object_Does_Not_Exist_In_The_Object_Dictionary,
Attempt_To_Read_A_Write_Only_Object,
Attempt_To_Write_A_Read_Only_Object,
Failed_To_Transfer_Or_Store_Data,
Failed_To_Transfer_Or_Store_Data_Due_To_Local_Control);
Abort_Code : constant array (Error_Type) of ACO.SDO_Commands.Abort_Code_Type :=
(Nothing => 16#0000_0000#,
Unknown => 16#0000_0000#,
General_Error => 16#0800_0000#,
Invalid_Value_For_Parameter => 16#0609_0030#,
Toggle_Bit_Not_Altered => 16#0503_0000#,
SDO_Protocol_Timed_Out => 16#0504_0000#,
Command_Specifier_Not_Valid_Or_Unknown => 16#0504_0001#,
Object_Does_Not_Exist_In_The_Object_Dictionary => 16#0602_0000#,
Attempt_To_Read_A_Write_Only_Object => 16#0601_0001#,
Attempt_To_Write_A_Read_Only_Object => 16#0601_0002#,
Failed_To_Transfer_Or_Store_Data => 16#0800_0020#,
Failed_To_Transfer_Or_Store_Data_Due_To_Local_Control => 16#0800_0021#);
package Alarms is new ACO.Utils.Generic_Alarms
(Configuration.Max_Nof_Simultaneous_SDO_Sessions);
type Alarm
(SDO_Ref : access SDO'Class := null)
is new Alarms.Alarm_Type with record
Id : ACO.SDO_Sessions.Endpoint_Nr := ACO.SDO_Sessions.No_Endpoint_Id;
end record;
overriding
procedure Signal
(This : access Alarm;
T_Now : in Ada.Real_Time.Time);
type Alarm_Array is array (ACO.SDO_Sessions.Valid_Endpoint_Nr'Range)
of aliased Alarm;
type SDO
(Handler : not null access ACO.CANopen.Handler;
Od : not null access ACO.OD.Object_Dictionary'Class)
--Wrap : not null access SDO_Wrapper_Base'Class)
is abstract new Protocol (Od) with record
Sessions : ACO.SDO_Sessions.Session_Manager;
Timers : Alarms.Alarm_Manager;
Alarms : Alarm_Array :=
(others => (SDO'Access, ACO.SDO_Sessions.No_Endpoint_Id));
end record;
procedure Indicate_Status
(This : in out SDO'Class;
Session : in ACO.SDO_Sessions.SDO_Session;
Status : in ACO.SDO_Sessions.SDO_Status);
procedure Handle_Message
(This : in out SDO;
Msg : in ACO.Messages.Message;
Endpoint : in ACO.SDO_Sessions.Endpoint_Type) is null;
procedure SDO_Log
(This : in out SDO;
Level : in ACO.Log.Log_Level;
Message : in String);
procedure Start_Alarm
(This : in out SDO;
Id : in ACO.SDO_Sessions.Valid_Endpoint_Nr);
procedure Stop_Alarm
(This : in out SDO;
Id : in ACO.SDO_Sessions.Valid_Endpoint_Nr);
procedure Abort_All
(This : in out SDO;
Msg : in ACO.Messages.Message;
Endpoint : in ACO.SDO_Sessions.Endpoint_Type);
procedure Write
(This : in out SDO;
Index : in ACO.OD_Types.Entry_Index;
Data : in ACO.Messages.Data_Array;
Error : out Error_Type);
procedure Send_SDO
(This : in out SDO'Class;
Endpoint : in ACO.SDO_Sessions.Endpoint_Type;
Raw_Data : in ACO.Messages.Msg_Data);
procedure Send_Abort
(This : in out SDO;
Endpoint : in ACO.SDO_Sessions.Endpoint_Type;
Error : in Error_Type;
Index : in ACO.OD_Types.Entry_Index := (0,0));
function Hex_Str
(X : Interfaces.Unsigned_32;
Trim : Boolean := True)
return String;
end ACO.Protocols.Service_Data;
|
-- --
-- package Parsers Copyright (c) Dmitry A. Kazakov --
-- Interface Luebeck --
-- Winter, 2004 --
-- --
-- Last revision : 15:35 29 Apr 2012 --
-- --
-- This library is free software; you can redistribute it and/or --
-- modify it under the terms of the GNU General Public License as --
-- published by the Free Software Foundation; either version 2 of --
-- the License, or (at your option) any later version. This library --
-- is distributed in the hope that it will be useful, but WITHOUT --
-- ANY WARRANTY; without even the implied warranty of --
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU --
-- General Public License for more details. You should have --
-- received a copy of the GNU General Public License along with --
-- this library; if not, write to the Free Software Foundation, --
-- Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. --
-- --
-- As a special exception, if other files instantiate generics from --
-- this unit, or you link this unit with other files to produce an --
-- executable, this unit does not by itself cause the resulting --
-- executable to be covered by the GNU General Public License. This --
-- exception does not however invalidate any other reasons why the --
-- executable file might be covered by the GNU Public License. --
--____________________________________________________________________--
package Parsers is
pragma Pure (Parsers);
--
-- Token_Class -- Lexical tokens
--
-- (o) Bracket is an order or aggregate bracket; left or right
-- (o) Comma
-- (o) Index is a left index or function bracket
-- (o) Operator is a prefix, postfix or infix one
-- (o) Ligature (a comma with an attached binary operation, such as
-- "=>" in Ada)
-- (o) Sublist_Close is an argument separator that closes a sublist
-- (o) Sublist_Separator separates sublists of arguments
-- (o) Sublist_Open is an argument separator that opens a sublist, as
-- "with" does in Ada's extension aggregates
-- (o) Postmodifier of an operation or argument
-- (o) Premodifier of an operation
--
type Token_Class is
( Operator,
Bracket,
Comma,
Ligature,
Index,
Sublist_Close,
Sublist_Separator,
Sublist_Open,
Postmodifier,
Premodifier
);
subtype Semicolon_Class is Token_Class
range Sublist_Close..Sublist_Open;
subtype Modifier_Class is Token_Class
range Postmodifier..Premodifier;
--
-- Syntax_Error -- The exception used by token lexer (see the package
-- Parsers.Generic_Token.Generic_Lexer). This exception
-- has information attached containing the error description and
-- location.
--
Syntax_Error : exception;
--
-- The following exceptions are used by the operation stack. The are
-- low-level ones that never not propagate out of a lexer.
--
Association_Error : exception;
Missing_Right_Bracket : exception;
Unexpected_Operation : exception;
Unexpected_Comma : exception;
Unexpected_Right_Bracket : exception;
Wrong_Comma_Type : exception;
Wrong_Right_Bracket_Type : exception;
--
-- Association_Error. This exception indicates that the operation being
-- pushed onto the stack cannot be associated with an operation on
-- the left, i.e when "and" returns false. The left operation is on
-- the stack top. A handler may push a compatible operation instead.
--
-- Missing_Right_Bracket. The left bracket is on the stack top. A
-- handler may push an assumed right bracket to close it and then try
-- to close the operation stack again.
--
-- Unexpected_Comma | Unexpected_Right_Bracket. The stub is on the
-- operation stack top. A handler has an option to get the unexpected
-- delimiter back and successfully complete the expression
-- evaluation.
--
-- Unexpected_Operation. The operation is not allowed outside brackets.
-- The stub is on the operation stack top. A handler has an option
-- push another operation instead.
--
-- Wrong_Comma_Type. The right bracket descriptor is on the operation
-- stack top. A handler may push a proper delimiter instead.
--
-- Wrong_Right_Bracket_Type. The right bracket descriptor is on the
-- operation stack top. A handler may push a proper right bracket and
-- then either discard the improper one or try to push it once again.
--
end Parsers;
|
-- Automatically generated, do not edit.
with Interfaces.C;
with System;
with OpenAL.Types;
package OpenAL.Thin is
package C renames Interfaces.C;
-- Constants
AL_BITS : constant := 16#2002#;
AL_BUFFER : constant := 16#1009#;
AL_BUFFERS_PROCESSED : constant := 16#1016#;
AL_BUFFERS_QUEUED : constant := 16#1015#;
AL_BYTE_OFFSET : constant := 16#1026#;
AL_CHANNELS : constant := 16#2003#;
AL_CONE_INNER_ANGLE : constant := 16#1001#;
AL_CONE_OUTER_ANGLE : constant := 16#1002#;
AL_CONE_OUTER_GAIN : constant := 16#1022#;
AL_DIRECTION : constant := 16#1005#;
AL_DISTANCE_MODEL : constant := 16#D000#;
AL_DOPPLER_FACTOR : constant := 16#C000#;
AL_DOPPLER_VELOCITY : constant := 16#C001#;
AL_EXPONENT_DISTANCE : constant := 16#D005#;
AL_EXPONENT_DISTANCE_CLAMPED : constant := 16#D006#;
AL_EXTENSIONS : constant := 16#B004#;
AL_FALSE : constant := 16#0#;
AL_FORMAT_MONO16 : constant := 16#1101#;
AL_FORMAT_MONO8 : constant := 16#1100#;
AL_FORMAT_STEREO16 : constant := 16#1103#;
AL_FORMAT_STEREO8 : constant := 16#1102#;
AL_FREQUENCY : constant := 16#2001#;
AL_GAIN : constant := 16#100A#;
AL_ILLEGAL_COMMAND : constant := 16#A004#;
AL_ILLEGAL_ENUM : constant := 16#A002#;
AL_INITIAL : constant := 16#1011#;
AL_INVALID : constant := -16#1#;
AL_INVALID_ENUM : constant := 16#A002#;
AL_INVALID_NAME : constant := 16#A001#;
AL_INVALID_OPERATION : constant := 16#A004#;
AL_INVALID_VALUE : constant := 16#A003#;
AL_INVERSE_DISTANCE : constant := 16#D001#;
AL_INVERSE_DISTANCE_CLAMPED : constant := 16#D002#;
AL_LINEAR_DISTANCE : constant := 16#D003#;
AL_LINEAR_DISTANCE_CLAMPED : constant := 16#D004#;
AL_LOOPING : constant := 16#1007#;
AL_MAX_DISTANCE : constant := 16#1023#;
AL_MAX_GAIN : constant := 16#100E#;
AL_MIN_GAIN : constant := 16#100D#;
AL_NONE : constant := 16#0#;
AL_NO_ERROR : constant := 16#0#;
AL_ORIENTATION : constant := 16#100F#;
AL_OUT_OF_MEMORY : constant := 16#A005#;
AL_PAUSED : constant := 16#1013#;
AL_PENDING : constant := 16#2011#;
AL_PITCH : constant := 16#1003#;
AL_PLAYING : constant := 16#1012#;
AL_POSITION : constant := 16#1004#;
AL_PROCESSED : constant := 16#2012#;
AL_REFERENCE_DISTANCE : constant := 16#1020#;
AL_RENDERER : constant := 16#B003#;
AL_ROLLOFF_FACTOR : constant := 16#1021#;
AL_SAMPLE_OFFSET : constant := 16#1025#;
AL_SEC_OFFSET : constant := 16#1024#;
AL_SIZE : constant := 16#2004#;
AL_SOURCE_RELATIVE : constant := 16#202#;
AL_SOURCE_STATE : constant := 16#1010#;
AL_SOURCE_TYPE : constant := 16#1027#;
AL_SPEED_OF_SOUND : constant := 16#C003#;
AL_STATIC : constant := 16#1028#;
AL_STOPPED : constant := 16#1014#;
AL_STREAMING : constant := 16#1029#;
AL_TRUE : constant := 16#1#;
AL_UNDETERMINED : constant := 16#1030#;
AL_UNUSED : constant := 16#2010#;
AL_VELOCITY : constant := 16#1006#;
AL_VENDOR : constant := 16#B001#;
AL_VERSION : constant := 16#B002#;
--
-- OpenAL 1.1
--
procedure Buffer_3f
(Buffer_ID : Types.Unsigned_Integer_t;
Parameter : Types.Enumeration_t;
Value_1 : Types.Float_t;
Value_2 : Types.Float_t;
Value_3 : Types.Float_t);
pragma Import (C, Buffer_3f, "alBuffer3f");
procedure Buffer_3i
(Buffer_ID : Types.Unsigned_Integer_t;
Parameter : Types.Enumeration_t;
Value_1 : Types.Integer_t;
Value_2 : Types.Integer_t;
Value_3 : Types.Integer_t);
pragma Import (C, Buffer_3i, "alBuffer3i");
procedure Buffer_Data
(Buffer_ID : Types.Unsigned_Integer_t;
Format : Types.Enumeration_t;
Data : System.Address;
Size : Types.Size_t;
Frequency : Types.Size_t);
pragma Import (C, Buffer_Data, "alBufferData");
procedure Bufferf
(Buffer_ID : Types.Unsigned_Integer_t;
Parameter : Types.Enumeration_t;
Value : Types.Float_t);
pragma Import (C, Bufferf, "alBufferf");
procedure Bufferfv
(Buffer_ID : Types.Unsigned_Integer_t;
Parameter : Types.Enumeration_t;
Values : System.Address);
pragma Import (C, Bufferfv, "alBufferfv");
procedure Bufferi
(Buffer_ID : Types.Unsigned_Integer_t;
Parameter : Types.Enumeration_t;
Value : Types.Integer_t);
pragma Import (C, Bufferi, "alBufferi");
procedure Bufferiv
(Buffer_ID : Types.Unsigned_Integer_t;
Parameter : Types.Enumeration_t;
Values : System.Address);
pragma Import (C, Bufferiv, "alBufferiv");
procedure Delete_Buffers
(Size : Types.Size_t;
Sources : System.Address);
pragma Import (C, Delete_Buffers, "alDeleteBuffers");
procedure Delete_Sources
(Size : Types.Size_t;
Sources : System.Address);
pragma Import (C, Delete_Sources, "alDeleteSources");
procedure Disable
(Capability : Types.Enumeration_t);
pragma Import (C, Disable, "alDisable");
procedure Distance_Model
(Distance_Model : Types.Enumeration_t);
pragma Import (C, Distance_Model, "alDistanceModel");
procedure Doppler_Factor
(Value : Types.Float_t);
pragma Import (C, Doppler_Factor, "alDopplerFactor");
procedure Doppler_Velocity
(Value : Types.Float_t);
pragma Import (C, Doppler_Velocity, "alDopplerVelocity");
procedure Enable
(Capability : Types.Enumeration_t);
pragma Import (C, Enable, "alEnable");
procedure Gen_Buffers
(Size : Types.Size_t;
Buffers : System.Address);
pragma Import (C, Gen_Buffers, "alGenBuffers");
procedure Gen_Sources
(Size : Types.Size_t;
Sources : System.Address);
pragma Import (C, Gen_Sources, "alGenSources");
function Get_Boolean
(Parameter : Types.Enumeration_t) return Types.Boolean_t;
pragma Import (C, Get_Boolean, "alGetBoolean");
procedure Get_Booleanv
(Parameter : Types.Enumeration_t;
Data : System.Address);
pragma Import (C, Get_Booleanv, "alGetBooleanv");
procedure Get_Buffer_3f
(Buffer_ID : Types.Unsigned_Integer_t;
Parameter : Types.Enumeration_t;
Value_1 : System.Address;
Value_2 : System.Address;
Value_3 : System.Address);
pragma Import (C, Get_Buffer_3f, "alGetBuffer3f");
procedure Get_Buffer_3i
(Buffer_ID : Types.Unsigned_Integer_t;
Parameter : Types.Enumeration_t;
Value_1 : System.Address;
Value_2 : System.Address;
Value_3 : System.Address);
pragma Import (C, Get_Buffer_3i, "alGetBuffer3i");
procedure Get_Bufferf
(Buffer_ID : Types.Unsigned_Integer_t;
Parameter : Types.Enumeration_t;
Value : System.Address);
pragma Import (C, Get_Bufferf, "alGetBufferf");
procedure Get_Bufferfv
(Buffer_ID : Types.Unsigned_Integer_t;
Parameter : Types.Enumeration_t;
Values : System.Address);
pragma Import (C, Get_Bufferfv, "alGetBufferfv");
procedure Get_Bufferi
(Buffer_ID : Types.Unsigned_Integer_t;
Parameter : Types.Enumeration_t;
Value : System.Address);
pragma Import (C, Get_Bufferi, "alGetBufferi");
procedure Get_Bufferiv
(Buffer_ID : Types.Unsigned_Integer_t;
Parameter : Types.Enumeration_t;
Values : System.Address);
pragma Import (C, Get_Bufferiv, "alGetBufferiv");
function Get_Double
(Parameter : Types.Enumeration_t) return Types.Double_t;
pragma Import (C, Get_Double, "alGetDouble");
procedure Get_Doublev
(Parameter : Types.Enumeration_t;
Values : System.Address);
pragma Import (C, Get_Doublev, "alGetDoublev");
function Get_Enum_Value
(Name : System.Address) return Types.Enumeration_t;
pragma Import (C, Get_Enum_Value, "alGetEnumValue");
function Get_Error return Types.Enumeration_t;
pragma Import (C, Get_Error, "alGetError");
function Get_Float
(Parameter : Types.Enumeration_t) return Types.Float_t;
pragma Import (C, Get_Float, "alGetFloat");
procedure Get_Floatv
(Parameter : Types.Enumeration_t;
Values : System.Address);
pragma Import (C, Get_Floatv, "alGetFloatv");
function Get_Integer
(Parameter : Types.Enumeration_t) return Types.Integer_t;
pragma Import (C, Get_Integer, "alGetInteger");
procedure Get_Integerv
(Paremeter : Types.Enumeration_t;
Values : System.Address);
pragma Import (C, Get_Integerv, "alGetIntegerv");
procedure Get_Listener_3f
(Parameter : Types.Enumeration_t;
Value_1 : System.Address;
Value_2 : System.Address;
Value_3 : System.Address);
pragma Import (C, Get_Listener_3f, "alGetListener3f");
procedure Get_Listener_3i
(Parameter : Types.Enumeration_t;
Value_1 : System.Address;
Value_2 : System.Address;
Value_3 : System.Address);
pragma Import (C, Get_Listener_3i, "alGetListener3i");
procedure Get_Listenerf
(Parameter : Types.Enumeration_t;
Value : System.Address);
pragma Import (C, Get_Listenerf, "alGetListenerf");
procedure Get_Listenerfv
(Parameter : Types.Enumeration_t;
Values : System.Address);
pragma Import (C, Get_Listenerfv, "alGetListenerfv");
procedure Get_Listeneri
(Parameter : Types.Enumeration_t;
Value : System.Address);
pragma Import (C, Get_Listeneri, "alGetListeneri");
procedure Get_Listeneriv
(Parameter : Types.Enumeration_t;
Values : System.Address);
pragma Import (C, Get_Listeneriv, "alGetListeneriv");
function Get_Proc_Address
(Name : System.Address) return Types.Void_Pointer_t;
pragma Import (C, Get_Proc_Address, "alGetProcAddress");
procedure Get_Source_3f
(Source_ID : Types.Unsigned_Integer_t;
Parameter : Types.Enumeration_t;
Value_1 : System.Address;
Value_2 : System.Address;
Value_3 : System.Address);
pragma Import (C, Get_Source_3f, "alGetSource3f");
procedure Get_Source_3i
(Source_ID : Types.Unsigned_Integer_t;
Parameter : Types.Enumeration_t;
Value_1 : System.Address;
Value_2 : System.Address;
Value_3 : System.Address);
pragma Import (C, Get_Source_3i, "alGetSource3i");
procedure Get_Sourcef
(Source_ID : Types.Unsigned_Integer_t;
Parameter : Types.Enumeration_t;
Value : System.Address);
pragma Import (C, Get_Sourcef, "alGetSourcef");
procedure Get_Sourcefv
(Source_ID : Types.Unsigned_Integer_t;
Parameter : Types.Enumeration_t;
Values : System.Address);
pragma Import (C, Get_Sourcefv, "alGetSourcefv");
procedure Get_Sourcei
(Source_ID : Types.Unsigned_Integer_t;
Parameter : Types.Enumeration_t;
Value : System.Address);
pragma Import (C, Get_Sourcei, "alGetSourcei");
procedure Get_Sourceiv
(Source_ID : Types.Unsigned_Integer_t;
Parameter : Types.Enumeration_t;
Values : System.Address);
pragma Import (C, Get_Sourceiv, "alGetSourceiv");
function Get_String
(Parameter : Types.Enumeration_t) return System.Address;
pragma Import (C, Get_String, "alGetString");
function Is_Buffer
(Buffer_ID : Types.Unsigned_Integer_t) return Types.Boolean_t;
pragma Import (C, Is_Buffer, "alIsBuffer");
function Is_Enabled
(Parameter : Types.Enumeration_t) return Types.Boolean_t;
pragma Import (C, Is_Enabled, "alIsEnabled");
function Is_Extension_Present
(Name : System.Address) return Types.Boolean_t;
pragma Import (C, Is_Extension_Present, "alIsExtensionPresent");
function Is_Source
(Source_ID : Types.Unsigned_Integer_t) return Types.Boolean_t;
pragma Import (C, Is_Source, "alIsSource");
procedure Listener_3f
(Parameter : Types.Enumeration_t;
Value_1 : Types.Float_t;
Value_2 : Types.Float_t;
Value_3 : Types.Float_t);
pragma Import (C, Listener_3f, "alListener3f");
procedure Listener_3i
(Parameter : Types.Enumeration_t;
Value_1 : Types.Integer_t;
Value_2 : Types.Integer_t;
Value_3 : Types.Integer_t);
pragma Import (C, Listener_3i, "alListener3i");
procedure Listenerf
(Parameter : Types.Enumeration_t;
Value : Types.Float_t);
pragma Import (C, Listenerf, "alListenerf");
procedure Listenerfv
(Parameter : Types.Enumeration_t;
Values : System.Address);
pragma Import (C, Listenerfv, "alListenerfv");
procedure Listeneri
(Parameter : Types.Enumeration_t;
Value : Types.Integer_t);
pragma Import (C, Listeneri, "alListeneri");
procedure Listeneriv
(Parameter : Types.Enumeration_t;
Values : System.Address);
pragma Import (C, Listeneriv, "alListeneriv");
procedure Source_3f
(Source_ID : Types.Unsigned_Integer_t;
Parameter : Types.Enumeration_t;
Value_1 : Types.Float_t;
Value_2 : Types.Float_t;
Value_3 : Types.Float_t);
pragma Import (C, Source_3f, "alSource3f");
procedure Source_3i
(Source_ID : Types.Unsigned_Integer_t;
Parameter : Types.Enumeration_t;
Value_1 : Types.Integer_t;
Value_2 : Types.Integer_t;
Value_3 : Types.Integer_t);
pragma Import (C, Source_3i, "alSource3i");
procedure Source_Pause
(Source_ID : Types.Unsigned_Integer_t);
pragma Import (C, Source_Pause, "alSourcePause");
procedure Source_Pausev
(Size : Types.Size_t;
Source_IDs : System.Address);
pragma Import (C, Source_Pausev, "alSourcePausev");
procedure Source_Play
(Source_ID : Types.Unsigned_Integer_t);
pragma Import (C, Source_Play, "alSourcePlay");
procedure Source_Playv
(Size : Types.Size_t;
Source_IDs : System.Address);
pragma Import (C, Source_Playv, "alSourcePlayv");
procedure Source_Queue_Buffers
(Source_ID : Types.Unsigned_Integer_t;
Size : Types.Size_t;
Buffer_IDs : System.Address);
pragma Import (C, Source_Queue_Buffers, "alSourceQueueBuffers");
procedure Source_Rewind
(Source_ID : Types.Unsigned_Integer_t);
pragma Import (C, Source_Rewind, "alSourceRewind");
procedure Source_Rewindv
(Size : Types.Size_t;
Source_IDs : System.Address);
pragma Import (C, Source_Rewindv, "alSourceRewindv");
procedure Source_Stop
(Source_ID : Types.Unsigned_Integer_t);
pragma Import (C, Source_Stop, "alSourceStop");
procedure Source_Stopv
(Size : Types.Size_t;
Source_IDs : System.Address);
pragma Import (C, Source_Stopv, "alSourceStopv");
procedure Source_Unqueue_Buffers
(Source_ID : Types.Unsigned_Integer_t;
Size : Types.Size_t;
Buffer_IDs : System.Address);
pragma Import (C, Source_Unqueue_Buffers, "alSourceUnqueueBuffers");
procedure Sourcef
(Source_ID : Types.Unsigned_Integer_t;
Parameter : Types.Enumeration_t;
Value : Types.Float_t);
pragma Import (C, Sourcef, "alSourcef");
procedure Sourcefv
(Source_ID : Types.Unsigned_Integer_t;
Parameter : Types.Enumeration_t;
Values : System.Address);
pragma Import (C, Sourcefv, "alSourcefv");
procedure Sourcei
(Source_ID : Types.Unsigned_Integer_t;
Parameter : Types.Enumeration_t;
Value : Types.Integer_t);
pragma Import (C, Sourcei, "alSourcei");
procedure Sourceiv
(Source_ID : Types.Unsigned_Integer_t;
Parameter : Types.Enumeration_t;
Values : System.Address);
pragma Import (C, Sourceiv, "alSourceiv");
procedure Speed_Of_Sound
(Value : Types.Float_t);
pragma Import (C, Speed_Of_Sound, "alSpeedOfSound");
end OpenAL.Thin;
|
-- SPDX-License-Identifier: Apache-2.0
--
-- Copyright (c) 2018 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.Text_IO;
with GL.Types;
with GL.Toggles;
with Orka.Cameras.Rotate_Around_Cameras;
with Orka.Contexts.AWT;
with Orka.Rendering.Buffers;
with Orka.Rendering.Drawing;
with Orka.Rendering.Framebuffers;
with Orka.Rendering.Programs.Modules;
with Orka.Rendering.Programs.Uniforms;
with Orka.Resources.Locations.Directories;
with Orka.Transforms.Doubles.Vector_Conversions;
with Orka.Transforms.Singles.Matrices;
with Orka.Types;
with Orka.Windows;
with AWT;
-- In this example we render many instances of a cube, each at a different
-- position.
procedure Orka_11_Instancing is
Width : constant := 500;
Height : constant := 500;
Context : constant Orka.Contexts.Context'Class := Orka.Contexts.AWT.Create_Context
(Version => (4, 2), Flags => (Debug => True, others => False));
Window : constant Orka.Windows.Window'Class
:= Orka.Contexts.AWT.Create_Window (Context, Width, Height, Resizable => False);
use Orka.Rendering.Buffers;
use Orka.Rendering.Framebuffers;
use Orka.Rendering.Programs;
use type Orka.Integer_32;
use type Orka.Float_32;
use type Orka.Float_64;
use GL.Types;
Instances_Dimension : constant := 40;
Space_Between_Cubes : constant := 0.2;
function Create_Matrices return Orka.Types.Singles.Matrix4_Array is
package Transforms renames Orka.Transforms.Singles.Matrices;
Distance_Multiplier : constant := 1.0 + Space_Between_Cubes;
Matrices : Orka.Types.Singles.Matrix4_Array (1 .. Instances_Dimension**3);
Index : Int := Matrices'First;
X, Y, Z : Single;
Offset : constant := Instances_Dimension / 2;
begin
for Index_X in 1 .. Instances_Dimension loop
X := Single (Index_X - Offset) * Distance_Multiplier;
for Index_Y in 1 .. Instances_Dimension loop
Y := Single (Index_Y - Offset) * Distance_Multiplier;
for Index_Z in 1 .. Instances_Dimension loop
Z := Single (Index_Z - Offset) * Distance_Multiplier;
Matrices (Index) := Transforms.T ((X, Y, Z, 0.0));
Index := Index + 1;
end loop;
end loop;
end loop;
return Matrices;
end Create_Matrices;
Indices : constant UInt_Array
:= (1, 2, 0, -- Back
0, 2, 3,
1, 0, 5, -- Top
5, 0, 4,
5, 4, 6, -- Front
6, 4, 7,
1, 5, 2, -- Right
2, 5, 6,
7, 4, 3, -- Left
3, 4, 0,
3, 2, 7, -- Bottom
7, 2, 6);
Vertices : constant Single_Array
:= (-0.5, 0.5, -0.5, 1.0, 1.0, 1.0, 1.0, 1.0,
0.5, 0.5, -0.5, 1.0, 0.0, 1.0, 0.0, 1.0,
0.5, -0.5, -0.5, 1.0, 0.0, 0.0, 1.0, 1.0,
-0.5, -0.5, -0.5, 1.0, 1.0, 0.0, 0.0, 1.0,
-0.5, 0.5, 0.5, 1.0, 0.0, 0.0, 1.0, 1.0,
0.5, 0.5, 0.5, 1.0, 1.0, 0.0, 0.0, 1.0,
0.5, -0.5, 0.5, 1.0, 1.0, 1.0, 1.0, 1.0,
-0.5, -0.5, 0.5, 1.0, 0.0, 1.0, 0.0, 1.0);
-- vec4 in_Position
-- vec4 in_Color
Matrices : constant Orka.Types.Singles.Matrix4_Array := Create_Matrices;
-- Create buffers containing attributes and indices
Buffer_1 : constant Buffer := Create_Buffer ((others => False), Vertices);
Buffer_2 : constant Buffer := Create_Buffer ((others => False), Indices);
Buffer_3 : constant Buffer := Create_Buffer ((others => False), Matrices);
use Orka.Resources;
Location_Shaders : constant Locations.Location_Ptr
:= Locations.Directories.Create_Location ("data/shaders");
Program_1 : Program := Create_Program (Modules.Create_Module
(Location_Shaders, VS => "instancing.vert", FS => "instancing.frag"));
Uni_View : constant Uniforms.Uniform := Program_1.Uniform ("view");
Uni_Proj : constant Uniforms.Uniform := Program_1.Uniform ("proj");
FB_D : Framebuffer := Create_Default_Framebuffer (Width, Height);
use Orka.Cameras;
Lens : constant Camera_Lens := Create_Lens (Width, Height, 45.0, Context);
Current_Camera : Rotate_Around_Cameras.Rotate_Around_Camera :=
Rotate_Around_Cameras.Create_Camera (Lens);
begin
Ada.Text_IO.Put_Line ("Instances of cube: " & Positive'Image (Matrices'Length));
declare
Distance_Center : Double := Double (Instances_Dimension);
begin
Distance_Center := Distance_Center + (Distance_Center - 1.0) * Space_Between_Cubes;
Current_Camera.Set_Radius (1.5 * Distance_Center);
end;
FB_D.Set_Default_Values ((Color => (0.0, 0.0, 0.0, 1.0), Depth => 1.0, others => <>));
Program_1.Use_Program;
-- Projection matrix
Uni_Proj.Set_Matrix (Current_Camera.Projection_Matrix);
GL.Toggles.Enable (GL.Toggles.Cull_Face);
GL.Toggles.Enable (GL.Toggles.Depth_Test);
Buffer_1.Bind (Shader_Storage, 0);
Buffer_3.Bind (Shader_Storage, 1);
while not Window.Should_Close loop
AWT.Process_Events (0.001);
Current_Camera.Update (0.01666);
declare
VP : constant Transforms.Vector4 :=
Orka.Transforms.Doubles.Vector_Conversions.Convert (Current_Camera.View_Position);
use Transforms.Vectors;
use Transforms;
TM : constant Transforms.Matrix4 := Transforms.T (Transforms.Zero_Point - VP);
begin
Uni_View.Set_Matrix (Current_Camera.View_Matrix * TM);
end;
FB_D.Clear ((Color | Depth => True, others => False));
Orka.Rendering.Drawing.Draw_Indexed
(Triangles, Buffer_2, 0, Indices'Length, Matrices'Length);
-- Swap front and back buffers and process events
Window.Swap_Buffers;
end loop;
end Orka_11_Instancing;
|
package YAML is
type Node_Types is (Tree, Leaf);
end YAML;
|
pragma License (Unrestricted);
with GNAT.Traceback;
with System;
package Ada.Exceptions.Traceback is
subtype Code_Loc is System.Address;
subtype Tracebacks_Array is GNAT.Traceback.Tracebacks_Array;
function Get_PC (TB_Entry : System.Address) return Code_Loc;
end Ada.Exceptions.Traceback;
|
-- Shoot'n'loot
-- Copyright (c) 2020 Fabien Chouteau
with Game_Assets; use Game_Assets;
with GESTE;
package Monsters is
Max_Nbr_Of_Monsters : constant := 5;
procedure Init (Objects : Object_Array)
with Pre => Objects'Length <= Max_Nbr_Of_Monsters;
function Check_Hit (Pt : GESTE.Pix_Point;
Lethal : Boolean)
return Boolean;
-- Return True if the Pt is within one of the monter. If Lethal is True, the
-- monster is killed.
function All_Killed return Boolean;
procedure Update;
end Monsters;
|
pragma License (Unrestricted);
-- implementation unit
package System.Unbounded_Stack_Allocators.Debug is
pragma Preelaborate;
-- dump the secondary stack of current task
procedure Dump (Allocator : aliased in out Allocator_Type);
end System.Unbounded_Stack_Allocators.Debug;
|
-----------------------------------------------------------------------
-- util-beans-vectors -- Object vectors
-- Copyright (C) 2011, 2017, 2019 Stephane Carrez
-- Written by Stephane Carrez (Stephane.Carrez@gmail.com)
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-----------------------------------------------------------------------
package body Util.Beans.Objects.Vectors is
-- ------------------------------
-- Get the value identified by the name.
-- If the name cannot be found, the method should return the Null object.
-- ------------------------------
function Get_Value (From : in Vector_Bean;
Name : in String) return Object is
begin
if Name = "count" then
return To_Object (Natural (From.Length));
else
return Null_Object;
end if;
end Get_Value;
-- ------------------------------
-- Get the number of elements in the list.
-- ------------------------------
overriding
function Get_Count (From : in Vector_Bean) return Natural is
begin
return Natural (From.Length);
end Get_Count;
-- ------------------------------
-- Get the element at the given position.
-- ------------------------------
overriding
function Get_Row (From : in Vector_Bean;
Position : in Natural) return Util.Beans.Objects.Object is
begin
return From.Element (Position);
end Get_Row;
-- -----------------------
-- Create an object that contains a <tt>Vector_Bean</tt> instance.
-- -----------------------
function Create return Object is
M : constant Vector_Bean_Access := new Vector_Bean;
begin
return To_Object (Value => M, Storage => DYNAMIC);
end Create;
end Util.Beans.Objects.Vectors;
|
with Ada.Text_IO;
with GC;
procedure version is
begin
Ada.Text_IO.Put_Line (GC.Version);
end version;
|
-- Copyright (C) 2020 Glen Cornell <glen.m.cornell@gmail.com>
--
-- 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/>.
package body Aof.Core.Objects is
use type Object_List.Cursor;
use type Ada.Strings.Unbounded.Unbounded_String;
function Get_Name (This : in Object'Class) return String is
begin
return Ada.Strings.Unbounded.To_String(This.Name.Get);
end;
procedure Set_Name
(This : in out Object'Class;
Name : in String) is
begin
This.Name.Set(Ada.Strings.Unbounded.To_Unbounded_String(Name));
end;
function Get_Parent (This : in Object'Class) return Access_Object is
begin
return This.Parent;
end;
procedure Set_Parent
(This : in out Object'Class;
Parent : in not null Access_Object) is
This_Ptr : Access_Object := This'Unchecked_Access;
begin
-- If the parent is found in this objects list of children(recursively), then fail
if This.Contains(Parent) or This_Ptr = Parent then
raise Circular_Reference_Exception;
end if;
-- unlink this from its existing parent
if This.Parent /= null then
This.Parent.Delete_Child(This_Ptr);
end if;
-- add the object "This" to the "Children" container belonging
-- to the object "Parent"
Parent.Children.Append(New_Item => This_Ptr);
This.Parent := Parent;
end;
function Get_Children
(This : in Object'Class) return Object_List.List is
begin
return This.Children;
end;
function Find_Child
(This : in Object'Class;
Name : in Ada.Strings.Unbounded.Unbounded_String;
Options : in Find_Child_Options := Find_Children_Recursively) return Access_Object is
begin
for Obj of This.Children loop
if Name = Obj.Name.Get then
return Obj;
end if;
if Options = Find_Children_Recursively then
return Obj.Find_Child(Name, Options);
end if;
end loop;
return null;
end;
function Find_Child
(This : in Object'Class;
Name : in String;
Options : in Find_Child_Options := Find_Children_Recursively)
return Access_Object is
The_Name : constant Ada.Strings.Unbounded.Unbounded_String :=
Ada.Strings.Unbounded.To_Unbounded_String(Name);
begin
return This.Find_Child(The_Name, Options);
end;
function Find_Children
(This : in Object'Class;
Name : in Ada.Strings.Unbounded.Unbounded_String;
Options : in Find_Child_Options := Find_Children_Recursively)
return Object_List.List is
Obj_List : Object_List.List;
begin
for Obj of This.Children loop
if Name = Obj.Name.Get then
Obj_List.Append(Obj);
end if;
if Options = Find_Children_Recursively then
declare
Children : Object_List.List := Obj.Find_Children(Name, Options);
begin
Obj_List.Splice(Before => Object_List.No_Element,
Source => Children);
end;
end if;
end loop;
return Obj_List;
end;
function Find_Children
(This : in Object'Class;
Name : in String;
Options : in Find_Child_Options := Find_Children_Recursively)
return Object_List.List is
The_Name : constant Ada.Strings.Unbounded.Unbounded_String :=
Ada.Strings.Unbounded.To_Unbounded_String(Name);
begin
return This.Find_Children(The_Name, Options);
end;
procedure Iterate
(This : in Access_Object;
Options : in Find_Child_Options := Find_Children_Recursively) is
begin
for Child of This.Children loop
if Options = Find_Children_Recursively then
Iterate(This => Child, Options => Options);
end if;
Proc(Child);
end loop;
end;
function Contains
(This : in out Object'Class;
Child : in not null Access_Object)
return Boolean is
This_Ptr : constant Access_Object := This'Unchecked_Access;
Obj : Access_Object := Child.Parent;
begin
while Obj /= null loop
if Obj = This_Ptr then
return True;
end if;
Obj := Obj.Parent;
end loop;
return False;
end;
procedure Delete_Child
(This : in out Object'Class;
Child : in out not null Access_Object;
Options : in Find_Child_Options := Find_Children_Recursively) is
I : Object_List.Cursor := This.Children.First;
Obj : Access_Object := null;
begin
loop
Obj := Object_List.Element(I);
if Obj = Child then
Obj.Parent := null;
This.Children.Delete(I);
return;
end if;
if Options = Find_Children_Recursively then
Obj.Delete_Child(Child, Options);
end if;
exit when I = This.Children.Last;
I := Object_List.Next(I);
end loop;
end;
procedure Finalize (This : in out Public_Part) is
begin
This.Destroyed.Emit(This'Unchecked_Access);
end Finalize;
procedure Finalize (This : in out Object) is
begin
-- TODO: delete all children?
null;
end Finalize;
end Aof.Core.Objects;
|
-- { dg-do compile }
-- { dg-options "-fdump-tree-gimple" }
with VFA1_Pkg; use VFA1_Pkg;
procedure VFA1_2 is
Temp : Int8_t;
function F (I : Int8_t) return Int8_t is
begin
return I;
end;
function F2 return Int8_t is
begin
return Int8_t(Timer1(1));
end;
procedure P3 (I : out Int8_t) is
begin
null;
end;
begin
Temp := Timer1(1);
Timer1(2) := Temp;
Temp := Timer2(1);
Timer2(2) := Temp;
Temp := Timer1(1) + Timer2(2);
if Timer1(1) /= Timer2(2) then
raise Program_Error;
end if;
Temp := F(Timer1(1));
Timer2(2) := F(Temp);
Temp := F(Timer2(2));
Timer1(1) := F(Temp);
Temp := F2;
P3 (Timer2(2));
end;
-- { dg-final { scan-tree-dump-times "atomic_load\[^\n\r\]*&vfa1_pkg__timer1" 7 "gimple"} }
-- { dg-final { scan-tree-dump-times "atomic_load\[^\n\r\]*&vfa1_pkg__timer2" 7 "gimple"} }
-- { dg-final { scan-tree-dump-times "atomic_load\[^\n\r\]*&temp" 0 "gimple"} }
-- { dg-final { scan-tree-dump-times "atomic_store\[^\n\r\]*&vfa1_pkg__timer1" 2 "gimple"} }
-- { dg-final { scan-tree-dump-times "atomic_store\[^\n\r\]*&vfa1_pkg__timer2" 3 "gimple"} }
-- { dg-final { scan-tree-dump-times "atomic_store\[^\n\r\]*&temp" 0 "gimple"} }
|
-------------------------------------------------------------------------------
-- DEpendency PLOtter for ada packages (DePlo) --
-- --
-- Copyright (C) 2012, Riccardo Bernardini --
-- --
-- This file is part of DePlo. --
-- --
-- DePlo 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. --
-- --
-- DePlo 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 DePlo. If not, see <http://www.gnu.org/licenses/>. --
-------------------------------------------------------------------------------
with Ada.Characters.Latin_1;
with Ada.Strings.Unbounded;
use Ada.Strings.Unbounded;
package body Line_Arrays is
use Ada.Characters;
-----------
-- Split --
-----------
function Split
(Input : String;
Terminator : Line_Terminator := Any)
return Line_Array
is
procedure Check_EOL (Cursor : Positive;
Is_At_EOL : out Boolean;
End_EOL : out Positive);
pragma Precondition (Cursor <= Input'Last);
pragma Postcondition ((not Is_At_EOL) or else (End_EOL <= Input'Last));
-- Check if Cursor points to the beginning of a line terminator
-- If it does, set Is_At_EOL equal to true and set End_EOL to the
-- position of the last char of the line terminator (that is
-- equal to Cursor unless the line terminator is a CRLF)
procedure Check_EOL (Cursor : Positive;
Is_At_EOL : out Boolean;
End_EOL : out Positive)
is
EOL_Type : Line_Terminator;
begin
case Input (Cursor) is
when Latin_1.CR =>
if Cursor < Input'Last and then Input (Cursor + 1) = Latin_1.LF then
EOL_Type := CRLF;
else
EOL_Type := CR;
end if;
when Latin_1.LF =>
EOL_Type := LF;
when others =>
Is_At_EOL := False;
return;
end case;
if Terminator = Any or Terminator = EOL_Type then
Is_At_EOL := True;
if EOL_Type = CRLF then
End_EOL := Cursor + 1;
else
End_EOL := Cursor;
end if;
else
Is_At_EOL := False;
end if;
end Check_EOL;
Result : Line_Array;
Cursor : Positive := Input'First;
Previous_End : Natural := Input'First - 1;
End_EOL : Positive;
Is_At_EOL : Boolean;
begin
while Cursor <= Input'Last loop
Check_EOL (Cursor, Is_At_EOL, End_EOL);
if Is_At_EOL then
Result.Append (Input (Previous_End + 1 .. Cursor - 1));
Cursor := End_EOL;
Previous_End := Cursor;
end if;
Cursor := Cursor + 1;
end loop;
if Previous_End < Input'Last then
Result.Append (Input (Previous_End + 1 .. Input'Last));
end if;
return Result;
end Split;
function Join
(Input : Line_Array;
Terminator : String)
return String
is
use Line_Containers;
Result : Unbounded_String := Null_Unbounded_String;
begin
for I in Input.First_Index .. Input.Last_Index loop
Result := Result & Input.Element (I);
if I < Input.Last_Index then
Result := Result & Terminator;
end if;
end loop;
return To_String (Result);
end Join;
----------
-- Join --
----------
function Join
(Input : Line_Array;
Terminator : Valid_Line_Terminator := CR)
return String
is
begin
case Terminator is
when LF =>
return Join (Input, "" & Latin_1.CR);
when CR =>
return Join (Input, "" & Latin_1.LF);
when CRLF =>
return Join (Input, Latin_1.CR & Latin_1.LF);
end case;
end Join;
function "=" (Left, Right : Line_Array) return Boolean
is
use Ada.Containers;
Diff : constant Integer := Right.First_Index - Left.First_Index;
begin
if Left.Length /= Right.Length then
return False;
end if;
for I in Left.First_Index .. Left.Last_Index loop
if Left.Element (I) /= Right.Element (I + Diff) then
return False;
end if;
end loop;
return True;
end "=";
function Read
(Input : Character_IO.File_Type;
Terminator : Line_Terminator := Any)
return Line_Array
is
use Character_IO;
Tmp : Unbounded_String;
Ch : Character := 'x';
begin
while not End_Of_File (Input) loop
Read (Input, Ch);
Tmp := Tmp & Ch;
end loop;
return Split (To_String (Tmp), Terminator);
end Read;
function Read
(Filename : String;
Terminator : Line_Terminator := Any)
return Line_Array
is
Input : Character_IO.File_Type;
Result : Line_Array;
begin
Character_IO.Open (File => Input,
Mode => Character_IO.In_File,
Name => Filename);
Result := Read (Input, Terminator);
Character_IO.Close (Input);
return Result;
end Read;
end Line_Arrays;
|
-- MIT License
-- Copyright (c) 2021 Stephen Merrony
-- Permission is hereby granted, free of charge, to any person obtaining a copy
-- of this software and associated documentation files (the "Software"), to deal
-- in the Software without restriction, including without limitation the rights
-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-- copies of the Software, and to permit persons to whom the Software is
-- furnished to do so, subject to the following conditions:
-- The above copyright notice and this permission notice shall be included in all
-- copies or substantial portions of the Software.
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-- SOFTWARE.
with Ada.Text_IO; use Ada.Text_IO;
package body Processor.Nova_Op_P is
procedure Do_Nova_Op (I : in Decoded_Instr_T; CPU : in out CPU_T) is
Wide_Shifter : Dword_T;
Narrow_Shifter : Word_T;
Tmp_Acs, Tmp_Acd : Word_T;
Saved_Carry, Tmp_Carry : Boolean;
PC_Inc : Phys_Addr_T;
begin
Tmp_Acs := DG_Types.Lower_Word (CPU.AC(I.Acs));
Tmp_Acd := DG_Types.Lower_Word (CPU.AC(I.Acd));
Saved_Carry := CPU.Carry;
case I.Carry is
when None => null;
when Z => CPU.Carry := false;
when O => CPU.Carry := true;
when C => CPU.Carry := not CPU.Carry;
end case;
case I.Instruction is
when I_ADC =>
Wide_Shifter := Dword_T(Tmp_Acd) + Dword_T(not Tmp_Acs);
Narrow_Shifter := DG_Types.Lower_Word (Wide_Shifter);
if Wide_Shifter > 65535 then
CPU.Carry := not CPU.Carry;
end if;
when I_ADD => -- unsigned
Wide_Shifter := Dword_T(Tmp_Acd) + Dword_T(Tmp_Acs);
Narrow_Shifter := DG_Types.Lower_Word (Wide_Shifter);
if Wide_Shifter > 65535 then
CPU.Carry := not CPU.Carry;
end if;
when I_AND =>
Narrow_Shifter := Tmp_Acd and Tmp_Acs;
when I_COM =>
Narrow_Shifter := not Tmp_Acs;
when I_INC =>
Narrow_Shifter := Tmp_Acs + 1;
if Tmp_Acs = 16#ffff# then
CPU.Carry := not CPU.Carry;
end if;
when I_MOV =>
Narrow_Shifter := Tmp_Acs;
when I_NEG =>
Narrow_Shifter := DG_Types.Integer_16_To_Word(- Word_To_Integer_16(Tmp_Acs));
-- Narrow_Shifter := Word_T(-Integer_16(Tmp_Acs)); -- TODO Check this
if Tmp_Acs = 0 then
CPU.Carry := not CPU.Carry;
end if;
when I_SUB =>
Narrow_Shifter := Tmp_Acd - Tmp_Acs;
if Tmp_Acs <= Tmp_Acd then
CPU.Carry := not CPU.Carry;
end if;
when others =>
Put_Line ("ERROR: NOVA_OP instruction " & To_String(I.Mnemonic) &
" not yet implemented");
raise Execution_Failure with "ERROR: NOVA_OP instruction " & To_String(I.Mnemonic) &
" not yet implemented";
end case;
case I.Sh is
when None => null;
when L =>
Tmp_Carry := CPU.Carry;
CPU.Carry := Test_W_Bit (Narrow_Shifter, 0);
Narrow_Shifter := Shift_Left (Narrow_Shifter, 1);
if Tmp_Carry then
Narrow_Shifter := Narrow_Shifter or 16#0001#;
end if;
when R =>
Tmp_Carry := CPU.Carry;
CPU.Carry := Test_W_Bit (Narrow_Shifter, 15);
Narrow_Shifter := Shift_Right (Narrow_Shifter, 1);
if Tmp_Carry then
Narrow_Shifter := Narrow_Shifter or 16#8000#;
end if;
when S =>
Narrow_Shifter := Swap_Bytes (Narrow_Shifter);
end case;
case I.Skip is
when None => PC_Inc := 1;
when SKP => PC_Inc := 2;
when SZC => if not CPU.Carry then PC_Inc := 2; else PC_Inc := 1; end if;
when SNC => if CPU.Carry then PC_Inc := 2; else PC_Inc := 1; end if;
when SZR => if Narrow_Shifter = 0 then PC_Inc := 2; else PC_Inc := 1; end if;
when SNR => if Narrow_Shifter /= 0 then PC_Inc := 2; else PC_Inc := 1; end if;
when SEZ => if (not CPU.Carry) or (Narrow_Shifter = 0) then PC_Inc := 2; else PC_Inc := 1; end if;
when SBN => if CPU.Carry and (Narrow_Shifter /= 0) then PC_Inc := 2; else PC_Inc := 1; end if;
end case;
if I.No_Load then
-- don't load the result from the shifter, restore the Carry flag
CPU.Carry := Saved_Carry;
else
CPU.AC(I.Acd) := Dword_T(Narrow_Shifter) and 16#0000_ffff#;
end if;
CPU.PC := CPU.PC + PC_Inc;
end Do_Nova_Op;
end Processor.Nova_Op_P;
|
-- Project: StratoX
-- Department: Real-Time Computer Systems (RCS)
-- Project: StratoX
-- Authors: Martin Becker (becker@rcs.ei.tum.de)
--
-- XXX! Nothing here is proven thread-safe!
with Ada.Unchecked_Conversion;
with FAT_Filesystem; use FAT_Filesystem;
-- @summary File handling for FAT FS
package body FAT_Filesystem.Directories.Files is
-------------------
-- File_Create
-------------------
function File_Create
(Parent : in out Directory_Handle;
newname : String;
Overwrite : Boolean := False;
File : out File_Handle) return Status_Code
is
subtype Entry_Data is Block (1 .. 32);
function From_Entry is new Ada.Unchecked_Conversion
(FAT_Directory_Entry, Entry_Data);
F_Entry : FAT_Directory_Entry;
Ent_Addr : FAT_Address;
Status : Status_Code;
begin
File.Is_Open := False;
if Parent.FS.Version /= FAT32 then
-- we only support FAT32 for now.
return Internal_Error;
end if;
-- find a place for another entry and return it
Status := Allocate_Entry (Parent, newname, Ent_Addr);
if Status /= OK then
if Status = Already_Exists and Overwrite then
---------------
-- Overwrite
---------------
if not Get_Entry (Parent => Parent, E_Name => newname, Ent => File.D_Entry) then
return Internal_Error;
end if;
if File.D_Entry.Attributes.Subdirectory then
return Already_Exists; -- overwrite subdirectory with file -> no!
end if;
-- wipe cluster chain in FAT..just keep first cluster
declare
cluster_cur : Unsigned_32 := File.D_Entry.Start_Cluster;
cluster_info : Unsigned_32;
FAT_updated : Boolean;
begin
Wipe_Chain_Loop :
loop
cluster_info := Parent.FS.Get_FAT (cluster_cur);
-- either points to next cluster, or indicates that
-- current cluster is bad (FIXME) or free
if cluster_cur = File.D_Entry.Start_Cluster then
-- mark as tail
FAT_updated := Parent.FS.Set_FAT (cluster_cur, LAST_CLUSTER_VALUE);
else
-- mark unused
FAT_updated := Parent.FS.Set_FAT (cluster_cur, FREE_CLUSTER_VALUE);
end if;
if not FAT_updated then
return Internal_Error;
end if;
-- check FAT entry for successor cluster
if Parent.FS.Is_Last_Cluster (cluster_info) or
Parent.FS.Is_Free_Cluster (cluster_info) -- for robustness
then
exit Wipe_Chain_Loop;
end if;
cluster_cur := cluster_info;
end loop Wipe_Chain_Loop;
end;
File.D_Entry.Size := 0;
File.D_Entry.Attributes.Archive := True; -- for backup
-- no need to write the FAT entry, yet.
else
return Status;
end if;
else
--------------
-- new file
--------------
declare
new_cluster : constant Unsigned_32 := Parent.FS.Get_Free_Cluster;
begin
if new_cluster = INVALID_CLUSTER then
return Device_Full;
end if;
-- allocate first cluster for data
if not Parent.FS.Allocate_Cluster (new_cluster)
then
return Allocation_Error;
end if;
-- read complete block to write the entry
Status := Parent.FS.Ensure_Block (Ent_Addr.Block_LBA);
if Status /= OK then
return Status;
end if;
-- fill entry attrs to make it a directory
File.D_Entry.FS := Parent.FS;
File.D_Entry.Attributes.Read_Only := False;
File.D_Entry.Attributes.Hidden := False;
File.D_Entry.Attributes.Archive := True; -- for backup: mark new files with archive flag
File.D_Entry.Attributes.System_File := False;
File.D_Entry.Attributes.Volume_Label := False;
File.D_Entry.Attributes.Subdirectory := False;
File.D_Entry.Start_Cluster := new_cluster;
File.D_Entry.Entry_Address := Ent_Addr;
File.D_Entry.Size := 0; -- file is empty, yet
Set_Name (newname, File.D_Entry);
-- encode into FAT entry
Status := Directory_To_FAT_Entry (File.D_Entry, F_Entry);
if Status /= OK then
return Status;
end if;
-- copy FAT entry to window
Parent.FS.Window (Ent_Addr.Block_Off .. Ent_Addr.Block_Off +
ENTRY_SIZE - 1) := From_Entry (F_Entry);
-- write back the window to disk
Status := Parent.FS.Write_Window (Ent_Addr.Block_LBA);
if Status /= OK then
return Status;
end if;
end;
end if;
-- set up file handle
File.FS := Parent.FS;
File.Start_Cluster := File.D_Entry.Start_Cluster;
File.Current_Cluster := File.D_Entry.Start_Cluster;
File.Current_Block := Parent.FS.Cluster_To_Block (File.D_Entry.Start_Cluster);
File.Buffer_Level := 0;
File.Mode := Write_Mode;
File.Bytes_Total := 0;
File.Is_Open := True;
return OK;
end File_Create;
-------------------
-- Update_Entry
-------------------
function Update_Entry (File : in out File_Handle) return Status_Code is
Status : Status_Code;
begin
Status := File.FS.Ensure_Block (File.D_Entry.Entry_Address.Block_LBA);
if Status /= OK then
return Status;
end if;
-- a bit of a hack, to save us from the work of re-generating the entire entry
declare
Size_Off : constant Unsigned_16 := 28;
subtype Entry_Data is Block (1 .. 4);
function Bytes_From_Size is new Ada.Unchecked_Conversion
(Unsigned_32, Entry_Data);
win_lo : constant Unsigned_16 := File.D_Entry.Entry_Address.Block_Off + Size_Off;
win_hi : constant Unsigned_16 := win_lo + 3;
begin
File.FS.Window (win_lo .. win_hi) := Bytes_From_Size (File.D_Entry.Size);
end;
Status := File.FS.Write_Window (File.D_Entry.Entry_Address.Block_LBA);
return Status;
end Update_Entry;
-------------------
-- File_Write
-------------------
function File_Write
(File : in out File_Handle;
Data : File_Data;
Status : out Status_Code) return Integer
is
n_processed : Natural := 0;
this_chunk : Natural := 0;
begin
if not File.Is_Open or File.Mode /= Write_Mode then
return -1;
end if;
if Data'Length < 1 then
return 0;
end if;
-- if buffer is full, write to disk
Write_Loop : loop
-- determine how much the buffer can take
declare
n_remain : constant Natural := Data'Length - n_processed;
cap : Natural;
begin
cap := File.Buffer'Length - File.Buffer_Level;
this_chunk := (if cap >= n_remain then n_remain else cap);
end;
-- copy max amount to buffer.
declare
newlevel : constant Natural := File.Buffer_Level + this_chunk;
buf_lo : constant Unsigned_16 := File.Buffer'First + Unsigned_16 (File.Buffer_Level);
buf_hi : constant Unsigned_16 := File.Buffer'First + Unsigned_16 (newlevel) - 1;
cnk_lo : constant Unsigned_16 := Data'First + Unsigned_16 (n_processed);
cnk_hi : constant Unsigned_16 := cnk_lo + Unsigned_16 (this_chunk) - 1;
begin
-- FIXME: save this copy if we have a full buffer. takes ~16usec
File.Buffer (buf_lo .. buf_hi) := Data (cnk_lo .. cnk_hi);
File.Buffer_Level := newlevel;
end;
-- book keeping
File.Bytes_Total := File.Bytes_Total + Unsigned_32 (this_chunk);
File.D_Entry.Size := File.Bytes_Total;
-- write buffer to disk only if full
if File.Buffer_Level = File.Buffer'Length then
File.FS.Window := File.Buffer;
Status := File.FS.Write_Window (File.Current_Block); -- ~2.7msec (too slow!)
if Status /= OK then
return n_processed;
end if;
-- now check whether the next block fits in the cluster.
-- Otherwise alloc next cluster and update FAT.
File.Current_Block := File.Current_Block + 1;
if File.Current_Block - File.FS.Cluster_To_Block (File.Current_Cluster) =
Unsigned_32 (File.FS.Number_Of_Blocks_Per_Cluster)
then
-- require another cluster
declare
New_Cluster : Unsigned_32;
begin
Status := File.FS.Append_Cluster
(Last_Cluster => File.Current_Cluster,
New_Cluster => New_Cluster);
if Status /= OK then
return n_processed;
end if;
File.Current_Cluster := New_Cluster;
File.Current_Block := File.FS.Cluster_To_Block (File.Current_Cluster);
end;
end if;
File.Buffer_Level := 0; -- now it is empty
-- update directory entry on disk (size has changed)
declare
Status_Up : Status_Code := Update_Entry (File);
pragma Unreferenced (Status_Up); -- don't care, that size is optional for us
begin
null;
end;
end if;
n_processed := n_processed + this_chunk;
exit Write_Loop when n_processed = Data'Length;
end loop Write_Loop;
return n_processed;
end File_Write;
------------------------
-- File_Open_Readonly
------------------------
function File_Open_Readonly
(Ent : in out Directory_Entry;
File : in out File_Data) return Status_Code
is
pragma Unreferenced (Ent, File);
begin
-- TODO: not yet implemented
return Internal_Error;
end File_Open_Readonly;
---------------
-- File_Read
---------------
function File_Read
(File : in out File_Handle;
Data : out File_Data) return Integer
is
pragma Unreferenced (Data);
begin
if not File.Is_Open or File.Mode /= Read_Mode then
return -1;
end if;
-- TODO: not yet implemented
File.Bytes_Total := File.Bytes_Total + 0;
return -1;
end File_Read;
----------------
-- File_Close
----------------
procedure File_Close (File : in out File_Handle) is
begin
if not File.Is_Open then
return;
end if;
if File.Mode = Write_Mode and then File.Buffer_Level > 0 then
-- flush buffer to disk
File.FS.Window := File.Buffer;
declare
Status : Status_Code := File.FS.Write_Window (File.Current_Block);
pragma Unreferenced (Status);
begin
null;
end;
-- we assume that the directory entry is already maintained by File_Write
end if;
File.Is_Open := False;
end File_Close;
----------------
-- File_Flush
----------------
function File_Flush (File : in out File_Handle) return Status_Code is
Status : Status_Code;
begin
if not File.Is_Open then
return Invalid_Object_Entry;
end if;
if File.Mode = Write_Mode and then File.Buffer_Level > 0 then
-- flush data block, even if not full
File.FS.Window := File.Buffer;
Status := File.FS.Write_Window (File.Current_Block);
-- force-update directory entry on disk
declare
Status_Up : Status_Code := Update_Entry (File);
pragma Unreferenced (Status_Up); -- don't care, that size is optional for us
begin
null;
end;
end if;
return Status;
end File_Flush;
----------------
-- File_Size
----------------
function File_Size (File : File_Handle) return Unsigned_32 is (File.Bytes_Total);
end FAT_Filesystem.Directories.Files;
|
--
-- Copyright (C) 2017, AdaCore
--
-- This spec has been automatically generated from ATSAMG55J19.svd
pragma Ada_2012;
pragma Style_Checks (Off);
with System;
-- Embedded Flash Controller
package Interfaces.SAM.EFC is
pragma Preelaborate;
pragma No_Elaboration_Code_All;
---------------
-- Registers --
---------------
subtype EFC_FMR_FWS_Field is Interfaces.SAM.UInt4;
-- EEFC Flash Mode Register
type EFC_FMR_Register is record
-- Flash Ready Interrupt Enable
FRDY : Boolean := False;
-- unspecified
Reserved_1_7 : Interfaces.SAM.UInt7 := 16#0#;
-- Flash Wait State
FWS : EFC_FMR_FWS_Field := 16#0#;
-- unspecified
Reserved_12_15 : Interfaces.SAM.UInt4 := 16#0#;
-- Sequential Code Optimization Disable
SCOD : Boolean := False;
-- unspecified
Reserved_17_23 : Interfaces.SAM.UInt7 := 16#0#;
-- Flash Access Mode
FAM : Boolean := False;
-- unspecified
Reserved_25_25 : Interfaces.SAM.Bit := 16#0#;
-- Code Loop Optimization Enable
CLOE : Boolean := True;
-- unspecified
Reserved_27_31 : Interfaces.SAM.UInt5 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for EFC_FMR_Register use record
FRDY at 0 range 0 .. 0;
Reserved_1_7 at 0 range 1 .. 7;
FWS at 0 range 8 .. 11;
Reserved_12_15 at 0 range 12 .. 15;
SCOD at 0 range 16 .. 16;
Reserved_17_23 at 0 range 17 .. 23;
FAM at 0 range 24 .. 24;
Reserved_25_25 at 0 range 25 .. 25;
CLOE at 0 range 26 .. 26;
Reserved_27_31 at 0 range 27 .. 31;
end record;
-- Flash Command
type FCR_FCMD_Field is
(
-- Get Flash descriptor
Getd,
-- Write page
Wp,
-- Write page and lock
Wpl,
-- Erase page and write page
Ewp,
-- Erase page and write page then lock
Ewpl,
-- Erase all
Ea,
-- Erase pages
Epa,
-- Set lock bit
Slb,
-- Clear lock bit
Clb,
-- Get lock bit
Glb,
-- Set GPNVM bit
Sgpb,
-- Clear GPNVM bit
Cgpb,
-- Get GPNVM bit
Ggpb,
-- Start read unique identifier
Stui,
-- Stop read unique identifier
Spui,
-- Get CALIB bit
Gcalb,
-- Erase sector
Es,
-- Write user signature
Wus,
-- Erase user signature
Eus,
-- Start read user signature
Stus,
-- Stop read user signature
Spus)
with Size => 8;
for FCR_FCMD_Field use
(Getd => 0,
Wp => 1,
Wpl => 2,
Ewp => 3,
Ewpl => 4,
Ea => 5,
Epa => 7,
Slb => 8,
Clb => 9,
Glb => 10,
Sgpb => 11,
Cgpb => 12,
Ggpb => 13,
Stui => 14,
Spui => 15,
Gcalb => 16,
Es => 17,
Wus => 18,
Eus => 19,
Stus => 20,
Spus => 21);
subtype EFC_FCR_FARG_Field is Interfaces.SAM.UInt16;
-- Flash Writing Protection Key
type FCR_FKEY_Field is
(
-- Reset value for the field
Fcr_Fkey_Field_Reset,
-- The 0x5A value enables the command defined by the bits of the
-- register. If the field is written with a different value, the write
-- is not performed and no action is started.
Passwd)
with Size => 8;
for FCR_FKEY_Field use
(Fcr_Fkey_Field_Reset => 0,
Passwd => 90);
-- EEFC Flash Command Register
type EFC_FCR_Register is record
-- Write-only. Flash Command
FCMD : FCR_FCMD_Field := Interfaces.SAM.EFC.Getd;
-- Write-only. Flash Command Argument
FARG : EFC_FCR_FARG_Field := 16#0#;
-- Write-only. Flash Writing Protection Key
FKEY : FCR_FKEY_Field := Fcr_Fkey_Field_Reset;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for EFC_FCR_Register use record
FCMD at 0 range 0 .. 7;
FARG at 0 range 8 .. 23;
FKEY at 0 range 24 .. 31;
end record;
-- EEFC Flash Status Register
type EFC_FSR_Register is record
-- Read-only. Flash Ready Status
FRDY : Boolean;
-- Read-only. Flash Command Error Status
FCMDE : Boolean;
-- Read-only. Flash Lock Error Status
FLOCKE : Boolean;
-- Read-only. Flash Error Status
FLERR : Boolean;
-- unspecified
Reserved_4_31 : Interfaces.SAM.UInt28;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for EFC_FSR_Register use record
FRDY at 0 range 0 .. 0;
FCMDE at 0 range 1 .. 1;
FLOCKE at 0 range 2 .. 2;
FLERR at 0 range 3 .. 3;
Reserved_4_31 at 0 range 4 .. 31;
end record;
-- Write Protection Key
type WPMR_WPKEY_Field is
(
-- Reset value for the field
Wpmr_Wpkey_Field_Reset,
-- Writing any other value in this field aborts the write
-- operation.Always reads as 0.
Passwd)
with Size => 24;
for WPMR_WPKEY_Field use
(Wpmr_Wpkey_Field_Reset => 0,
Passwd => 4539971);
-- Write Protection Mode Register
type EFC_WPMR_Register is record
-- Write Protection Enable
WPEN : Boolean := False;
-- unspecified
Reserved_1_7 : Interfaces.SAM.UInt7 := 16#0#;
-- Write Protection Key
WPKEY : WPMR_WPKEY_Field := Wpmr_Wpkey_Field_Reset;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for EFC_WPMR_Register use record
WPEN at 0 range 0 .. 0;
Reserved_1_7 at 0 range 1 .. 7;
WPKEY at 0 range 8 .. 31;
end record;
-----------------
-- Peripherals --
-----------------
-- Embedded Flash Controller
type EFC_Peripheral is record
-- EEFC Flash Mode Register
FMR : aliased EFC_FMR_Register;
-- EEFC Flash Command Register
FCR : aliased EFC_FCR_Register;
-- EEFC Flash Status Register
FSR : aliased EFC_FSR_Register;
-- EEFC Flash Result Register
FRR : aliased Interfaces.SAM.UInt32;
-- Write Protection Mode Register
WPMR : aliased EFC_WPMR_Register;
end record
with Volatile;
for EFC_Peripheral use record
FMR at 16#0# range 0 .. 31;
FCR at 16#4# range 0 .. 31;
FSR at 16#8# range 0 .. 31;
FRR at 16#C# range 0 .. 31;
WPMR at 16#E4# range 0 .. 31;
end record;
-- Embedded Flash Controller
EFC_Periph : aliased EFC_Peripheral
with Import, Address => EFC_Base;
end Interfaces.SAM.EFC;
|
package body openGL.Raster
is
procedure set_Window_Position (X, Y : in Real;
Z : in Real := 0.0;
W : in Real := 1.0)
is
pragma Unreferenced (Z, W);
begin
raise Program_Error with "TODO: unimplemented";
end set_Window_Position;
end openGL.Raster;
|
package xample1 is
procedure SayWelcome;
procedure xercise;
-- procedure Goodbye;
end xample1;
|
with AWS.Config.Set;
with AWS.Services.Dispatchers.URI;
with AWS.Server;
with @_Project_Name_@.Dispatchers;
procedure @_Project_Name_@.Main is
use AWS;
Web_Server : Server.HTTP;
Web_Config : Config.Object;
Web_Dispatcher : Services.Dispatchers.URI.Handler;
Default_Dispatcher : Dispatchers.Default;
CSS_Dispatcher : Dispatchers.CSS;
Image_Dispatcher : Dispatchers.Image;
begin
-- Setup server
Config.Set.Server_Host (Web_Config, Host);
Config.Set.Server_Port (Web_Config, Port);
-- Setup dispatchers
Dispatchers.Initialize (Web_Config);
Services.Dispatchers.URI.Register
(Web_Dispatcher,
URI => "/css",
Action => CSS_Dispatcher,
Prefix => True);
Services.Dispatchers.URI.Register
(Web_Dispatcher,
URI => "/img",
Action => Image_Dispatcher,
Prefix => True);
Services.Dispatchers.URI.Register_Default_Callback
(Web_Dispatcher,
Action => Default_Dispatcher);
-- Start the server
Server.Start (Web_Server, Web_Dispatcher, Web_Config);
-- Wait for the Q key
Server.Wait (Server.Q_Key_Pressed);
-- Stop the server
Server.Shutdown (Web_Server);
end @_Project_Name_@.Main;
|
-- SipHash24
-- An instantiation of SipHash with recommended parameters.
-- The key must be set with SetKey before use, or there will be no protection
-- from hash flooding attacks.
-- Copyright (c) 2015, James Humphry - see LICENSE file for details
pragma Spark_Mode;
with SipHash;
pragma Elaborate_All(SipHash);
package SipHash24 is new SipHash(c_rounds => 2,
d_rounds => 4,
k0 => 16#0706050403020100#,
k1 => 16#0f0e0d0c0b0a0908#);
|
------------------------------------------------------------------------------
-- Copyright (c) 2014-2017, Natacha Porté --
-- --
-- Permission to use, copy, modify, and distribute this software for any --
-- purpose with or without fee is hereby granted, provided that the above --
-- copyright notice and this permission notice appear in all copies. --
-- --
-- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES --
-- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF --
-- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR --
-- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES --
-- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN --
-- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF --
-- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. --
------------------------------------------------------------------------------
------------------------------------------------------------------------------
-- Natools.S_Expressions.File_Writers provides a pretty printer --
-- implementation using Stream_IO as backend. --
------------------------------------------------------------------------------
with Natools.S_Expressions.Printers.Pretty;
private with Ada.Finalization;
private with Ada.Streams.Stream_IO;
package Natools.S_Expressions.File_Writers is
type Writer is limited new Printers.Pretty.Printer with private;
function Create (Name : String; Form : String := "") return Writer;
function Open (Name : String; Form : String := "") return Writer;
-- Constructors using respectively Stream_IO.Create and Stream_IO.Open
procedure Create
(Self : in out Writer;
Name : in String;
Form : in String := "");
procedure Open
(Self : in out Writer;
Name : in String;
Form : in String := "");
-- Reinitialize Self using Stream_IO.Create or Stream_IO.Open
function Open_Or_Create (Name : String; Form : String := "") return Writer;
procedure Open_Or_Create
(Self : in out Writer;
Name : in String;
Form : in String := "");
-- Construct or reinitialize a writer, trying a regular open first
-- and attempting to create if it doesn't work.
-- Note that there is some time between failure to open and actual
-- file creation, which might lead to race conditions.
function Name (Self : Writer) return String;
-- Return the underlying file name
private
type Autoclose is new Ada.Finalization.Limited_Controlled with record
File : Ada.Streams.Stream_IO.File_Type;
end record;
overriding procedure Finalize (Object : in out Autoclose);
-- Close the underlying file if it was opened
type Writer is limited new Printers.Pretty.Printer with record
Holder : Autoclose;
end record;
overriding procedure Write_Raw
(Output : in out Writer;
Data : in Ada.Streams.Stream_Element_Array);
-- Write data into the underlying stream
end Natools.S_Expressions.File_Writers;
|
-----------------------------------------------------------------------
-- secret-attributes -- Attribute list representation
-- Copyright (C) 2017 Stephane Carrez
-- Written by Stephane Carrez (Stephane.Carrez@gmail.com)
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-----------------------------------------------------------------------
-- === Secret Attributes ===
-- The secret attributes describes the key/value pairs that allows the secret service to
-- identify and retrieve a given secret value. The secret attributes are displayed by the
-- keyring manager to the user in the "technical details" section.
--
-- The <tt>Secret.Attributes</tt> package defines the <tt>Map</tt> type for the representation
-- of attributes and it provides operations to populate the attributes.
--
-- The <tt>Map</tt> instances use reference counting and they can be shared.
package Secret.Attributes is
-- Represents a hashmap to store attributes.
type Map is new Secret.Object_Type with null record;
-- Insert into the map the attribute with the given name and value.
procedure Insert (Into : in out Map;
Name : in String;
Value : in String);
private
overriding
procedure Adjust (Object : in out Map);
overriding
procedure Finalize (Object : in out Map);
end Secret.Attributes;
|
------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- S E M --
-- --
-- S p e c --
-- --
-- Copyright (C) 1992-2005, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 2, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
-- for more details. You should have received a copy of the GNU General --
-- Public License distributed with GNAT; see file COPYING. If not, write --
-- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
-- Boston, MA 02110-1301, USA. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
--------------------------------------
-- Semantic Analysis: General Model --
--------------------------------------
-- Semantic processing involves 3 phases which are highly interwined
-- (ie mutually recursive):
-- Analysis implements the bulk of semantic analysis such as
-- name analysis and type resolution for declarations,
-- instructions and expressions. The main routine
-- driving this process is procedure Analyze given below.
-- This analysis phase is really a bottom up pass that is
-- achieved during the recursive traversal performed by the
-- Analyze_... procedures implemented in the sem_* packages.
-- For expressions this phase determines unambiguous types
-- and collects sets of possible types where the
-- interpretation is potentially ambiguous.
-- Resolution is carried out only for expressions to finish type
-- resolution that was initiated but not necessarily
-- completed during analysis (because of overloading
-- ambiguities). Specifically, after completing the bottom
-- up pass carried out during analysis for expressions, the
-- Resolve routine (see the spec of sem_res for more info)
-- is called to perform a top down resolution with
-- recursive calls to itself to resolve operands.
-- Expansion if we are not generating code this phase is a no-op.
-- otherwise this phase expands, ie transforms, original
-- declaration, expressions or instructions into simpler
-- structures that can be handled by the back-end. This
-- phase is also in charge of generating code which is
-- implicit in the original source (for instance for
-- default initializations, controlled types, etc.)
-- There are two separate instances where expansion is
-- invoked. For declarations and instructions, expansion is
-- invoked just after analysis since no resolution needs
-- to be performed. For expressions, expansion is done just
-- after resolution. In both cases expansion is done from the
-- bottom up just before the end of Analyze for instructions
-- and declarations or the call to Resolve for expressions.
-- The main routine driving expansion is Expand.
-- See the spec of Expander for more details.
-- To summarize, in normal code generation mode we recursively traverse the
-- abstract syntax tree top-down performing semantic analysis bottom
-- up. For instructions and declarations, before the call to the Analyze
-- routine completes we perform expansion since at that point we have all
-- semantic information needed. For expression nodes, after the call to
-- Analysis terminates we invoke the Resolve routine to transmit top-down
-- the type that was gathered by Analyze which will resolve possible
-- ambiguities in the expression. Just before the call to Resolve
-- terminates, the expression can be expanded since all the semantic
-- information is available at that point.
-- If we are not generating code then the expansion phase is a no-op
-- When generating code there are a number of exceptions to the basic
-- Analysis-Resolution-Expansion model for expressions. The most prominent
-- examples are the handling of default expressions and aggregates.
----------------------------------------------------
-- Handling of Default and Per-Object Expressions --
----------------------------------------------------
-- The default expressions in component declarations and in procedure
-- specifications (but not the ones in object declarations) are quite
-- tricky to handle. The problem is that some processing is required
-- at the point where the expression appears:
-- visibility analysis (including user defined operators)
-- freezing of static expressions
-- but other processing must be deferred until the enclosing entity
-- (record or procedure specification) is frozen:
-- freezing of any other types in the expression
-- expansion
-- A similar situation occurs with the argument of priority and interrupt
-- priority pragmas that appear in task and protected definition specs and
-- other cases of per-object expressions (see RM 3.8(18)).
-- Expansion has to be deferred since you can't generate code for
-- expressions that refernce types that have not been frozen yet. As an
-- example, consider the following:
-- type x is delta 0.5 range -10.0 .. +10.0;
-- ...
-- type q is record
-- xx : x := y * z;
-- end record;
-- for x'small use 0.25
-- The expander is in charge of dealing with fixed-point, and of course
-- the small declaration, which is not too late, since the declaration of
-- type q does *not* freeze type x, definitely affects the expanded code.
-- Another reason that we cannot expand early is that expansion can generate
-- range checks. These range checks need to be inserted not at the point of
-- definition but at the point of use. The whole point here is that the value
-- of the expression cannot be obtained at the point of declaration, only at
-- the point of use.
-- Generally our model is to combine analysis resolution and expansion, but
-- this is the one case where this model falls down. Here is how we patch
-- it up without causing too much distortion to our basic model.
-- A switch (sede below) is set to indicate that we are in the initial
-- occurence of a default expression. The analyzer is then called on this
-- expression with the switch set true. Analysis and resolution proceed
-- almost as usual, except that Freeze_Expression will not freeze
-- non-static expressions if this switch is set, and the call to Expand at
-- the end of resolution is skipped. This also skips the code that normally
-- sets the Analyzed flag to True). The result is that when we are done the
-- tree is still marked as unanalyzed, but all types for static expressions
-- are frozen as required, and all entities of variables have been
-- recorded. We then turn off the switch, and later on reanalyze the
-- expression with the switch off. The effect is that this second analysis
-- freezes the rest of the types as required, and generates code but
-- visibility analysis is not repeated since all the entities are marked.
-- The second analysis (the one that generates code) is in the context
-- where the code is required. For a record field default, this is in
-- the initialization procedure for the record and for a subprogram
-- default parameter, it is at the point the subprogram is frozen.
-- For a priority or storage size pragma it is in the context of the
-- Init_Proc for the task or protected object.
------------------
-- Pre-Analysis --
------------------
-- For certain kind of expressions, such as aggregates, we need to defer
-- expansion of the aggregate and its inner expressions after the whole
-- set of expressions appearing inside the aggregate have been analyzed.
-- Consider, for instance the following example:
--
-- (1 .. 100 => new Thing (Function_Call))
--
-- The normal Analysis-Resolution-Expansion mechanism where expansion
-- of the children is performed before expansion of the parent does not
-- work if the code generated for the children by the expander needs
-- to be evaluated repeatdly (for instance in the above aggregate
-- "new Thing (Function_Call)" needs to be called 100 times.)
-- The reason why this mecanism does not work is that, the expanded code
-- for the children is typically inserted above the parent and thus
-- when the father gets expanded no re-evaluation takes place. For instance
-- in the case of aggregates if "new Thing (Function_Call)" is expanded
-- before of the aggregate the expanded code will be placed outside
-- of the aggregate and when expanding the aggregate the loop from 1 to 100
-- will not surround the expanded code for "new Thing (Function_Call)".
--
-- To remedy this situation we introduce a new flag which signals whether
-- we want a full analysis (ie expansion is enabled) or a pre-analysis
-- which performs Analysis and Resolution but no expansion.
--
-- After the complete pre-analysis of an expression has been carried out
-- we can transform the expression and then carry out the full
-- Analyze-Resolve-Expand cycle on the transformed expression top-down
-- so that the expansion of inner expressions happens inside the newly
-- generated node for the parent expression.
--
-- Note that the difference between processing of default expressions and
-- pre-analysis of other expressions is that we do carry out freezing in
-- the latter but not in the former (except for static scalar expressions).
-- The routine that performs pre-analysis is called Pre_Analyze_And_Resolve
-- and is in Sem_Res.
with Alloc;
with Einfo; use Einfo;
with Opt; use Opt;
with Table;
with Types; use Types;
package Sem is
New_Nodes_OK : Int := 1;
-- Temporary flag for use in checking out HLO. Set non-zero if it is
-- OK to generate new nodes.
-----------------------------
-- Semantic Analysis Flags --
-----------------------------
Explicit_Overriding : Boolean := False;
-- Switch to indicate whether checking mechanism described in AI-218
-- is enforced: subprograms that override inherited operations must be
-- be marked explicitly, to prevent accidental or omitted overriding.
Full_Analysis : Boolean := True;
-- Switch to indicate whether we are doing a full analysis or a
-- pre-analysis. In normal analysis mode (Analysis-Expansion for
-- instructions or declarations) or (Analysis-Resolution-Expansion for
-- expressions) this flag is set. Note that if we are not generating
-- code the expansion phase merely sets the Analyzed flag to True in
-- this case. If we are in Pre-Analysis mode (see above) this flag is
-- set to False then the expansion phase is skipped.
-- When this flag is False the flag Expander_Active is also False
-- (the Expander_Activer flag defined in the spec of package Expander
-- tells you whether expansion is currently enabled).
-- You should really regard this as a read only flag.
In_Default_Expression : Boolean := False;
-- Switch to indicate that we are in a default expression, as described
-- above. Note that this must be recursively saved on a Semantics call
-- since it is possible for the analysis of an expression to result in
-- a recursive call (e.g. to get the entity for System.Address as part
-- of the processing of an Address attribute reference).
-- When this switch is True then Full_Analysis above must be False.
-- You should really regard this as a read only flag.
In_Deleted_Code : Boolean := False;
-- If the condition in an if-statement is statically known, the branch
-- that is not taken is analyzed with expansion disabled, and the tree
-- is deleted after analysis. Itypes generated in deleted code must be
-- frozen from start, because the tree on which they depend will not
-- be available at the freeze point.
In_Inlined_Body : Boolean := False;
-- Switch to indicate that we are analyzing and resolving an inlined
-- body. Type checking is disabled in this context, because types are
-- known to be compatible. This avoids problems with private types whose
-- full view is derived from private types.
Inside_A_Generic : Boolean := False;
-- This flag is set if we are processing a generic specification,
-- generic definition, or generic body. When this flag is True the
-- Expander_Active flag is False to disable any code expansion (see
-- package Expander). Only the generic processing can modify the
-- status of this flag, any other client should regard it as read-only.
Unloaded_Subunits : Boolean := False;
-- This flag is set True if we have subunits that are not loaded. This
-- occurs when the main unit is a subunit, and contains lower level
-- subunits that are not loaded. We use this flag to suppress warnings
-- about unused variables, since these warnings are unreliable in this
-- case. We could perhaps do a more accurate job and retain some of the
-- warnings, but it is quite a tricky job. See test 4323-002.
-----------------
-- Scope Stack --
-----------------
-- The scope stack holds all entries of the scope table. As in the parser,
-- we use Last as the stack pointer, so that we can always find the scope
-- that is currently open in Scope_Stack.Table (Scope_Stack.Last). The
-- oldest entry, at Scope_Stack (0) is Standard. The entries in the table
-- include the entity for the referenced scope, together with information
-- used to restore the proper setting of check suppressions on scope exit.
type Scope_Stack_Entry is record
Entity : Entity_Id;
-- Entity representing the scope
Last_Subprogram_Name : String_Ptr;
-- Pointer to name of last subprogram body in this scope. Used for
-- testing proper alpha ordering of subprogram bodies in scope.
Save_Scope_Suppress : Suppress_Array;
-- Save contents of Scope_Suppress on entry
Save_Local_Entity_Suppress : Int;
-- Save contents of Local_Entity_Suppress.Last on entry
Is_Transient : Boolean;
-- Marks Transient Scopes (See Exp_Ch7 body for details)
Previous_Visibility : Boolean;
-- Used when installing the parent (s) of the current compilation
-- unit. The parent may already be visible because of an ongoing
-- compilation, and the proper visibility must be restored on exit.
Node_To_Be_Wrapped : Node_Id;
-- Only used in transient scopes. Records the node which will
-- be wrapped by the transient block.
Actions_To_Be_Wrapped_Before : List_Id;
Actions_To_Be_Wrapped_After : List_Id;
-- Actions that have to be inserted at the start or at the end of a
-- transient block. Used to temporarily hold these actions until the
-- block is created, at which time the actions are moved to the
-- block.
Pending_Freeze_Actions : List_Id;
-- Used to collect freeze entity nodes and associated actions that
-- are generated in a inner context but need to be analyzed outside,
-- such as records and initialization procedures. On exit from the
-- scope, this list of actions is inserted before the scope construct
-- and analyzed to generate the corresponding freeze processing and
-- elaboration of other associated actions.
First_Use_Clause : Node_Id;
-- Head of list of Use_Clauses in current scope. The list is built
-- when the declarations in the scope are processed. The list is
-- traversed on scope exit to undo the effect of the use clauses.
Component_Alignment_Default : Component_Alignment_Kind;
-- Component alignment to be applied to any record or array types
-- that are declared for which a specific component alignment pragma
-- does not set the alignment.
Is_Active_Stack_Base : Boolean;
-- Set to true only when entering the scope for Standard_Standard from
-- from within procedure Semantics. Indicates the base of the current
-- active set of scopes. Needed by In_Open_Scopes to handle cases
-- where Standard_Standard can be pushed in the middle of the active
-- set of scopes (occurs for instantiations of generic child units).
end record;
package Scope_Stack is new Table.Table (
Table_Component_Type => Scope_Stack_Entry,
Table_Index_Type => Int,
Table_Low_Bound => 0,
Table_Initial => Alloc.Scope_Stack_Initial,
Table_Increment => Alloc.Scope_Stack_Increment,
Table_Name => "Sem.Scope_Stack");
-----------------------------------
-- Handling of Check Suppression --
-----------------------------------
-- There are two kinds of suppress checks: scope based suppress checks,
-- and entity based suppress checks.
-- Scope based suppress chems (from initial command line arguments,
-- or from Suppress pragmas not including an entity name) are recorded
-- in the Sem.Supress variable, and all that is necessary is to save the
-- state of this variable on scope entry, and restore it on scope exit.
-- Entity based suppress checks, from Suppress pragmas giving an Entity_Id,
-- are handled as follows. If a suppress or unsuppress pragma is
-- encountered for a given entity, then the flag Checks_May_Be_Suppressed
-- is set in the entity and an entry is made in either the
-- Local_Entity_Suppress table (case of pragma that appears in other than
-- a package spec), or in the Global_Entity_Suppress table (case of pragma
-- that appears in a package spec, which is by the rule of RM 11.5(7)
-- applicable throughout the life of the entity).
-- If the Checks_May_Be_Suppressed flag is set in an entity then the
-- procedure is to search first the local and then the global suppress
-- tables (the local one being searched in reverse order, i.e. last in
-- searched first). The only other point is that we have to make sure
-- that we have proper nested interaction between such specific pragmas
-- and locally applied general pragmas applying to all entities. This
-- is achieved by including in the Local_Entity_Suppress table dummy
-- entries with an empty Entity field that are applicable to all entities.
Scope_Suppress : Suppress_Array := Suppress_Options;
-- This array contains the current scope based settings of the suppress
-- switches. It is initialized from the options as shown, and then modified
-- by pragma Suppress. On entry to each scope, the current setting is saved
-- the scope stack, and then restored on exit from the scope. This record
-- may be rapidly checked to determine the current status of a check if
-- no specific entity is involved or if the specific entity involved is
-- one for which no specific Suppress/Unsuppress pragma has been set (as
-- indicated by the Checks_May_Be_Suppressed flag being set).
-- This scheme is a little complex, but serves the purpose of enabling
-- a very rapid check in the common case where no entity specific pragma
-- applies, and gives the right result when such pragmas are used even
-- in complex cases of nested Suppress and Unsuppress pragmas.
type Entity_Check_Suppress_Record is record
Entity : Entity_Id;
-- Entity to which the check applies, or Empty for a local check
-- that has no entity name (and thus applies to all entities).
Check : Check_Id;
-- Check which is set (note this cannot be All_Checks, if the All_Checks
-- case, a sequence of eentries appears for the individual checks.
Suppress : Boolean;
-- Set True for Suppress, and False for Unsuppress
end record;
-- The Local_Entity_Suppress table is a stack, to which new entries are
-- added for Suppress and Unsuppress pragmas appearing in other than
-- package specs. Such pragmas are effective only to the end of the scope
-- in which they appear. This is achieved by marking the stack on entry
-- to a scope and then cutting back the stack to that marked point on
-- scope exit.
package Local_Entity_Suppress is new Table.Table (
Table_Component_Type => Entity_Check_Suppress_Record,
Table_Index_Type => Int,
Table_Low_Bound => 0,
Table_Initial => Alloc.Entity_Suppress_Initial,
Table_Increment => Alloc.Entity_Suppress_Increment,
Table_Name => "Local_Entity_Suppress");
-- The Global_Entity_Suppress table is used for entities which have
-- a Suppress or Unsuppress pragma naming a specific entity in a
-- package spec. Such pragmas always refer to entities in the package
-- spec and are effective throughout the lifetime of the named entity.
package Global_Entity_Suppress is new Table.Table (
Table_Component_Type => Entity_Check_Suppress_Record,
Table_Index_Type => Int,
Table_Low_Bound => 0,
Table_Initial => Alloc.Entity_Suppress_Initial,
Table_Increment => Alloc.Entity_Suppress_Increment,
Table_Name => "Global_Entity_Suppress");
-----------------
-- Subprograms --
-----------------
procedure Initialize;
-- Initialize internal tables
procedure Lock;
-- Lock internal tables before calling back end
procedure Semantics (Comp_Unit : Node_Id);
-- This procedure is called to perform semantic analysis on the specified
-- node which is the N_Compilation_Unit node for the unit.
procedure Analyze (N : Node_Id);
procedure Analyze (N : Node_Id; Suppress : Check_Id);
-- This is the recursive procedure which is applied to individual nodes
-- of the tree, starting at the top level node (compilation unit node)
-- and then moving down the tree in a top down traversal. It calls
-- individual routines with names Analyze_xxx to analyze node xxx. Each
-- of these routines is responsible for calling Analyze on the components
-- of the subtree.
--
-- Note: In the case of expression components (nodes whose Nkind is in
-- N_Subexpr), the call to Analyze does not complete the semantic analysis
-- of the node, since the type resolution cannot be completed until the
-- complete context is analyzed. The completion of the type analysis occurs
-- in the corresponding Resolve routine (see Sem_Res).
--
-- Note: for integer and real literals, the analyzer sets the flag to
-- indicate that the result is a static expression. If the expander
-- generates a literal that does NOT correspond to a static expression,
-- e.g. by folding an expression whose value is known at compile-time,
-- but is not technically static, then the caller should reset the
-- Is_Static_Expression flag after analyzing but before resolving.
--
-- If the Suppress argument is present, then the analysis is done
-- with the specified check suppressed (can be All_Checks to suppress
-- all checks).
procedure Analyze_List (L : List_Id);
procedure Analyze_List (L : List_Id; Suppress : Check_Id);
-- Analyzes each element of a list. If the Suppress argument is present,
-- then the analysis is done with the specified check suppressed (can
-- be All_Checks to suppress all checks).
procedure Copy_Suppress_Status
(C : Check_Id;
From : Entity_Id;
To : Entity_Id);
-- If From is an entity for which check C is explicitly suppressed
-- then also explicitly suppress the corresponding check in To.
procedure Insert_List_After_And_Analyze
(N : Node_Id; L : List_Id);
procedure Insert_List_After_And_Analyze
(N : Node_Id; L : List_Id; Suppress : Check_Id);
-- Inserts list L after node N using Nlists.Insert_List_After, and then,
-- after this insertion is complete, analyzes all the nodes in the list,
-- including any additional nodes generated by this analysis. If the list
-- is empty or be No_List, the call has no effect. If the Suppress
-- argument is present, then the analysis is done with the specified
-- check suppressed (can be All_Checks to suppress all checks).
procedure Insert_List_Before_And_Analyze
(N : Node_Id; L : List_Id);
procedure Insert_List_Before_And_Analyze
(N : Node_Id; L : List_Id; Suppress : Check_Id);
-- Inserts list L before node N using Nlists.Insert_List_Before, and then,
-- after this insertion is complete, analyzes all the nodes in the list,
-- including any additional nodes generated by this analysis. If the list
-- is empty or be No_List, the call has no effect. If the Suppress
-- argument is present, then the analysis is done with the specified
-- check suppressed (can be All_Checks to suppress all checks).
procedure Insert_After_And_Analyze
(N : Node_Id; M : Node_Id);
procedure Insert_After_And_Analyze
(N : Node_Id; M : Node_Id; Suppress : Check_Id);
-- Inserts node M after node N and then after the insertion is complete,
-- analyzes the inserted node and all nodes that are generated by
-- this analysis. If the node is empty, the call has no effect. If the
-- Suppress argument is present, then the analysis is done with the
-- specified check suppressed (can be All_Checks to suppress all checks).
procedure Insert_Before_And_Analyze
(N : Node_Id; M : Node_Id);
procedure Insert_Before_And_Analyze
(N : Node_Id; M : Node_Id; Suppress : Check_Id);
-- Inserts node M before node N and then after the insertion is complete,
-- analyzes the inserted node and all nodes that could be generated by
-- this analysis. If the node is empty, the call has no effect. If the
-- Suppress argument is present, then the analysis is done with the
-- specified check suppressed (can be All_Checks to suppress all checks).
function External_Ref_In_Generic (E : Entity_Id) return Boolean;
-- Return True if we are in the context of a generic and E is
-- external (more global) to it.
procedure Enter_Generic_Scope (S : Entity_Id);
-- Shall be called each time a Generic subprogram or package scope is
-- entered. S is the entity of the scope.
-- ??? At the moment, only called for package specs because this mechanism
-- is only used for avoiding freezing of external references in generics
-- and this can only be an issue if the outer generic scope is a package
-- spec (otherwise all external entities are already frozen)
procedure Exit_Generic_Scope (S : Entity_Id);
-- Shall be called each time a Generic subprogram or package scope is
-- exited. S is the entity of the scope.
-- ??? At the moment, only called for package specs exit.
function Explicit_Suppress (E : Entity_Id; C : Check_Id) return Boolean;
-- This function returns True if an explicit pragma Suppress for check C
-- is present in the package defining E.
function Is_Check_Suppressed (E : Entity_Id; C : Check_Id) return Boolean;
-- This function is called if Checks_May_Be_Suppressed (E) is True to
-- determine whether check C is suppressed either on the entity E or
-- as the result of a scope suppress pragma. If Checks_May_Be_Suppressed
-- is False, then the status of the check can be determined simply by
-- examining Scope_Checks (C), so this routine is not called in that case.
end Sem;
|
with AUnit.Reporter.Text;
with AUnit.Run;
with Unbound_Array_Suite;
with Safe_Alloc_Suite;
with GNAT.OS_Lib;
with Text_IO;
with Spark_Unbound;
procedure Tests is
use type AUnit.Status;
Reporter : AUnit.Reporter.Text.Text_Reporter;
function Unbound_Array_Test_Runner is new AUnit.Run.Test_Runner_With_Status(Unbound_Array_Suite.Suite);
function Safe_Alloc_Test_Runner is new AUnit.Run.Test_Runner_With_Status(Safe_Alloc_Suite.Suite);
begin
-- Run Unbound_Array tests
if Unbound_Array_Test_Runner(Reporter) /= AUnit.Success then
GNAT.OS_Lib.OS_Exit(1);
end if;
-- Run Safe_Alloc tests
if Safe_Alloc_Test_Runner(Reporter) /= AUnit.Success then
GNAT.OS_Lib.OS_Exit(1);
end if;
end Tests;
|
-- SPDX-License-Identifier: Apache-2.0
--
-- Copyright (c) 2018 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.
private with GL.Low_Level.Enums;
with Orka.Rendering.Buffers;
with Orka.Resources.Locations;
with Orka.Transforms.Singles.Matrices;
with Orka.Types;
private with Orka.Rendering.Programs.Uniforms;
private with Orka.Algorithms.Prefix_Sums;
package Orka.Culling is
pragma Preelaborate;
package Transforms renames Orka.Transforms.Singles.Matrices;
type Culler is tagged private;
type Culler_Ptr is not null access all Culler'Class;
procedure Bind (Object : in out Culler; View_Projection : Transforms.Matrix4);
function Create_Culler
(Location : Resources.Locations.Location_Ptr) return Culler;
-----------------------------------------------------------------------------
type Cull_Instance is tagged private;
procedure Cull
(Object : in out Cull_Instance;
Transforms : Rendering.Buffers.Bindable_Buffer'Class;
Bounds, Commands : Rendering.Buffers.Buffer;
Compacted_Transforms, Compacted_Commands : out Rendering.Buffers.Buffer;
Instances : Natural);
function Create_Instance
(Culler : Culler_Ptr; Transforms, Commands : Natural) return Cull_Instance
with Pre => Transforms mod 4 = 0;
private
package LE renames GL.Low_Level.Enums;
package Programs renames Rendering.Programs;
type Culler is tagged record
Program_Frustum : Programs.Program;
Program_Compact : Programs.Program;
PS_Factory : Algorithms.Prefix_Sums.Factory;
Uniform_VP : Programs.Uniforms.Uniform (LE.Single_Matrix4);
Uniform_CF_Instances : Programs.Uniforms.Uniform (LE.UInt_Type);
Uniform_CC_Instances : Programs.Uniforms.Uniform (LE.UInt_Type);
end record;
type Cull_Instance is tagged record
Buffer_Visibles : Rendering.Buffers.Buffer (Types.UInt_Type);
Buffer_Indices : Rendering.Buffers.Buffer (Types.UInt_Type);
Culler : Culler_Ptr;
Prefix_Sum : Algorithms.Prefix_Sums.Prefix_Sum;
Work_Groups : Natural;
Compacted_Transforms : Rendering.Buffers.Buffer (Types.Single_Matrix_Type);
Compacted_Commands : Rendering.Buffers.Buffer (Types.Elements_Command_Type);
end record;
end Orka.Culling;
|
with Ada.Strings.Hash_Case_Insensitive;
with Ada.Containers;
with Symbol_Tables.Generic_Symbol_Table;
with Protypo.API.Engine_Values;
--
-- This package defines the symbol tables used by the engine. They
-- are basically structures that map symbol names into Engine_Value's
--
package Protypo.API.Symbols is
subtype Symbol_Name is ID;
function Hash (X : Symbol_Name) return Ada.Containers.Hash_Type
is (Ada.Strings.Hash_Case_Insensitive (String (X)));
function Equivalent (X, Y : Symbol_Name) return Boolean
is (X = Y);
package Protypo_Tables is
new Symbol_Tables.Generic_Symbol_Table
(Symbol_Name => Symbol_Name,
Symbol_Value => Engine_Values.Engine_Value,
Hash => Hash,
Equivalent_Names => Equivalent);
subtype Table is Protypo_Tables.Symbol_Table;
function Copy_Globals (X : Table) return Table
renames Protypo_Tables.Copy_Globals;
end Protypo.API.Symbols;
|
-----------------------------------------------------------------------
-- awa-converters-dates -- Date Converters
-- Copyright (C) 2012 Stephane Carrez
-- Written by Stephane Carrez (Stephane.Carrez@gmail.com)
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-----------------------------------------------------------------------
with ASF.Converters;
with ASF.Converters.Dates;
with ASF.Contexts.Faces;
with ASF.Components.Base;
with Util.Beans.Objects;
package AWA.Converters.Dates is
-- ------------------------------
-- Relative Date Converter
-- ------------------------------
-- The <b>Relative_Date_Converter</b> translates a date value into a relative presentation
-- for a human. The date is converted relatively to the current time to display a message
-- in one of the following forms:
--
-- o 'a moment ago', if D - now < 60 secs
-- o 'X minutes ago', if D - now < 60 mins
-- o 'X hours ago', if D - now < 24 hours
-- o 'X days ago', if D - now < 7 days
-- o date
type Relative_Date_Converter is new ASF.Converters.Dates.Date_Converter with null record;
type Relative_Date_Converter_Access is access all Relative_Date_Converter'Class;
-- Convert the object value into a string. The object value is associated
-- with the specified component.
-- If the string cannot be converted, the Invalid_Conversion exception should be raised.
overriding
function To_String (Convert : in Relative_Date_Converter;
Context : in ASF.Contexts.Faces.Faces_Context'Class;
Component : in ASF.Components.Base.UIComponent'Class;
Value : in Util.Beans.Objects.Object) return String;
end AWA.Converters.Dates;
|
with Ada.Text_Io;
with Ada.Integer_Text_IO;
procedure Integer_Arithmetic is
use Ada.Text_IO;
use Ada.Integer_Text_Io;
A, B : Integer;
begin
Get(A);
Get(B);
Put_Line("a+b = " & Integer'Image(A + B));
Put_Line("a-b = " & Integer'Image(A - B));
Put_Line("a*b = " & Integer'Image(A * B));
Put_Line("a/b = " & Integer'Image(A / B) & ", remainder " & Integer'Image(A mod B));
Put_Line("a**b = " & Integer'Image(A ** B));
end Integer_Arithmetic;
|
-- -*- Mode: Ada -*-
-- Filename : console.ads
-- Description : Definition of a console for PC using VGA text mode.
-- Author : Luke A. Guest
-- Created On : Thu Jun 14 12:08:58 2012
-- Licence : See LICENCE in the root directory.
-------------------------------------------------------------------------------
with System;
package Console is
pragma Preelaborate (Console);
TE : exception;
type Background_Colour is
(Black,
Blue,
Green,
Cyan,
Red,
Magenta,
Brown,
Light_Grey);
for Background_Colour use
(Black => 16#0#,
Blue => 16#1#,
Green => 16#2#,
Cyan => 16#3#,
Red => 16#4#,
Magenta => 16#5#,
Brown => 16#6#,
Light_Grey => 16#7#);
for Background_Colour'Size use 4;
type Foreground_Colour is
(Black,
Blue,
Green,
Cyan,
Red,
Magenta,
Brown,
Light_Grey,
Dark_Grey,
Light_Blue,
Light_Green,
Light_Cyan,
Light_Red,
Light_Magenta,
Yellow,
White);
for Foreground_Colour use
(Black => 16#0#,
Blue => 16#1#,
Green => 16#2#,
Cyan => 16#3#,
Red => 16#4#,
Magenta => 16#5#,
Brown => 16#6#,
Light_Grey => 16#7#,
Dark_Grey => 16#8#,
Light_Blue => 16#9#,
Light_Green => 16#A#,
Light_Cyan => 16#B#,
Light_Red => 16#C#,
Light_Magenta => 16#D#,
Yellow => 16#E#,
White => 16#F#);
for Foreground_Colour'Size use 4;
type Cell_Colour is
record
Foreground : Foreground_Colour;
Background : Background_Colour;
end record;
for Cell_Colour use
record
Foreground at 0 range 0 .. 3;
Background at 0 range 4 .. 7;
end record;
for Cell_Colour'Size use 8;
type Cell is
record
Char : Character;
Colour : Cell_Colour;
end record;
for Cell'Size use 16;
Screen_Width : constant Natural := 80;
Screen_Height : constant Natural := 25;
subtype Screen_Width_Range is Natural range 1 .. Screen_Width;
subtype Screen_Height_Range is Natural range 1 .. Screen_Height;
type Row is array (Screen_Width_Range) of Cell;
type Screen is array (Screen_Height_Range) of Row;
Video_Memory : Screen;
for Video_Memory'Address use System'To_Address (16#000B_8000#);
pragma Import (Ada, Video_Memory);
procedure Put
(Char : Character;
X : Screen_Width_Range;
Y : Screen_Height_Range;
Foreground : Foreground_Colour := White;
Background : Background_Colour := Black);
procedure Put
(Str : String;
X : Screen_Width_Range;
Y : Screen_Height_Range;
Foreground : Foreground_Colour := White;
Background : Background_Colour := Black);
-- procedure Put
-- (Data : in Natural;
-- X : in Screen_Width_Range;
-- Y : in Screen_Height_Range;
-- Foreground : in Foreground_Colour := White;
-- Background : in Background_Colour := Black);
procedure Clear (Background : Background_Colour := Black);
end Console;
|
with Ada.Text_IO;
with Ada.Calendar;
with Pendulums;
procedure Main is
package Float_Pendulum is new Pendulums (Float, -9.81);
use Float_Pendulum;
use type Ada.Calendar.Time;
My_Pendulum : Pendulum := New_Pendulum (10.0, 30.0);
Now, Before : Ada.Calendar.Time;
begin
Before := Ada.Calendar.Clock;
loop
Delay 0.1;
Now := Ada.Calendar.Clock;
Update_Pendulum (My_Pendulum, Now - Before);
Before := Now;
-- output positions relative to origin
-- replace with graphical output if wanted
Ada.Text_IO.Put_Line (" X: " & Float'Image (Get_X (My_Pendulum)) &
" Y: " & Float'Image (Get_Y (My_Pendulum)));
end loop;
end Main;
|
package body problem_14 is
function Solution_1 return Integer is
Upper : constant Integer := 1_000_000;
Max : Integer := 0;
Ret : Integer;
Num : Integer;
Current : Int64;
begin
for I in reverse 1 .. Upper loop
Num := 1;
Current := Int64(I);
while Current /= 1 loop
if Current mod 2 = 0 then
Current := Current / 2;
else
Current := 3*Current + 1;
end if;
Num := Num + 1;
end loop;
if Num > Max then
Max := Num;
Ret := I;
end if;
end loop;
return Ret;
end Solution_1;
procedure Test_Solution_1 is
Solution : constant Integer := 837799;
begin
Assert( Solution_1 = Solution );
end;
function Get_Solutions return Solution_Case is
Ret : Solution_Case;
begin
Set_Name( Ret, "Problem 14" );
Add_Test( Ret, Test_Solution_1'access );
return Ret;
end Get_Solutions;
end problem_14;
|
------------------------------------------------------------------------------
-- G E L A A S I S --
-- ASIS implementation for Gela project, a portable Ada compiler --
-- http://gela.ada-ru.org --
-- - - - - - - - - - - - - - - - --
-- Read copyright and license at the end of this file --
------------------------------------------------------------------------------
-- $Revision: 209 $ $Date: 2013-11-30 21:03:24 +0200 (Сб., 30 нояб. 2013) $
with Ada.Unchecked_Deallocation;
with Ada.Text_IO;
package body Gela.Repository.Dictionary is
------------
-- Get_ID --
------------
procedure Get_ID
(This : in out Gela_Dictionary;
Value : in Code_Point_Array;
Result : out ID)
is
use Gela.Hash.CRC.b16;
Position : Positive := 1;
-- Insert --
procedure Insert
is
Point : ID_Point;
begin
Point.Num := Result;
Point.Data := new Code_Point_Array'(Value);
Point.Used := True;
Insert (This, Position, Point);
This.Changed := True;
end Insert;
begin
if Value = "" then
Result := 0;
return;
end if;
Result := Wide_Wide_Calculate (Value);
Position := Find (This, Result);
if Position > Count (this) then
Insert;
return;
end if;
if This.Data (Position).Num = Result then
if This.Data (Position).Data.all /= Value then
Ada.Text_IO.Put_Line ("Gela.Repository.Dictionary bug detected");
Ada.Text_IO.Put_Line ("dublicate ID (CRC16) for differetn values");
raise Constraint_Error;
end if;
This.Data (Position).Used := True;
else
Insert;
end if;
end Get_ID;
--------------
-- Get_Name --
--------------
function Get_Name
(This : in Gela_Dictionary;
Value : in ID)
return Code_Point_Array
is
Position : Positive := Find (This, Value);
begin
if Position > Count (this) then
return "";
end if;
if This.Data (Position).Num = Value then
This.Data (Position).Used := True;
return This.Data (Position).Data.all;
else
return "";
end if;
end Get_Name;
-----------
-- Marck --
-----------
procedure Marck
(This : in Gela_Dictionary;
Value : in ID)
is
Position : Positive := Find (This, Value);
begin
if Position <= Count (this) then
if This.Data (Position).Num = Value then
This.Data (Position).Used := True;
end if;
end if;
end Marck;
-----------
-- Clear --
-----------
procedure Deallocate is
new Ada.Unchecked_Deallocation
(Code_Point_Array, Code_Point_Array_Access);
procedure Deallocate is
new Ada.Unchecked_Deallocation
(ID_Point_Array, ID_Point_Array_Access);
procedure Clear
(This : in out Gela_Dictionary)
is
begin
if This.Data = null then
return;
end if;
for Index in reverse This.Data'Range loop
Deallocate (This.Data (Index).Data);
end loop;
Deallocate (This.Data);
end Clear;
-----------
-- Count --
-----------
function Count
(This : in Gela_Dictionary)
return Natural
is
begin
if This.Data = null then
return 0;
else
return This.Data'Length;
end if;
end Count;
--------------
-- Finalize --
--------------
procedure Finalize
(This : in out Gela_Dictionary)
is
begin
Free_Unused (This);
if This.Changed then
Redirect_Save (This);
end if;
Clear (This);
end Finalize;
-----------------
-- Free_Unused --
-----------------
procedure Free_Unused
(This : in out Gela_Dictionary)
is
begin
if This.Data = null then
return;
end if;
for Index in reverse This.Data'Range loop
if not This.Data (Index).Used then
Delete (This, Index);
This.Changed := True;
end if;
end loop;
end Free_Unused;
-------------------
-- Redirect_Save --
-------------------
procedure Redirect_Save
(This : in out Gela_Dictionary'Class)
is
begin
Save (This);
end Redirect_Save;
----------
-- Save --
----------
procedure Save
(This : in out Gela_Dictionary)
is
begin
null;
end Save;
----------
-- Find --
----------
function Find
(This : in Gela_Dictionary;
Num : in ID)
return Natural
is
L, H, I : Natural;
begin
if This.Data = null then
return 1;
end if;
L := 1;
H := This.Data'Last;
while L <= H loop
I := (L + H) / 2;
if This.Data (I).Num < Num then
L := I + 1;
else
H := I - 1;
if This.Data (I).Num = Num then
L := I;
end if;
end if;
end loop;
return L;
end Find;
------------
-- Insert --
------------
procedure Insert
(This : in out Gela_Dictionary;
Index : in Positive;
Point : in ID_Point)
is
begin
if This.Data = null then
This.Data := new ID_Point_Array (1 .. 1);
This.Data (1) := Point;
else
declare
Internal_Array : constant ID_Point_Array_Access :=
new ID_Point_Array (1 .. This.Data'Last + 1);
begin
Internal_Array (1 .. Index - 1) := This.Data (1 .. Index - 1);
Internal_Array (Index) := Point;
Internal_Array (Index + 1 .. Internal_Array'Last) :=
This.Data (Index .. This.Data'Last);
Deallocate (This.Data);
This.Data := Internal_Array;
end;
end if;
end Insert;
------------
-- Delete --
------------
procedure Delete
(This : in out Gela_Dictionary;
Index : in Positive)
is
begin
if This.Data'Length = 1 then
Deallocate (This.Data);
else
declare
Internal_Array : constant ID_Point_Array_Access :=
new ID_Point_Array (1 .. This.Data'Last - 1);
begin
Internal_Array (1 .. Index - 1) := This.Data (1 .. Index - 1);
Internal_Array (Index .. Internal_Array'Last) :=
This.Data (Index + 1 .. This.Data'Last);
Deallocate (This.Data);
This.Data := Internal_Array;
end;
end if;
end Delete;
end Gela.Repository.Dictionary;
------------------------------------------------------------------------------
-- Copyright (c) 2006, Andry Ogorodnik
-- All rights reserved.
--
-- Redistribution and use in source and binary forms, with or without
-- modification, are permitted provided that the following conditions are met:
--
-- * Redistributions of source code must retain the above copyright notice,
-- * this list of conditions and the following disclaimer.
-- * Redistributions in binary form must reproduce the above copyright
-- * notice, this list of conditions and the following disclaimer in the
-- * documentation and/or other materials provided with the distribution.
--
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
-- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-- POSSIBILITY OF SUCH DAMAGE.
------------------------------------------------------------------------------
------------------------------------------------------------------------------
-- Copyright (c) 2006-2013, Maxim Reznik
-- All rights reserved.
--
-- Redistribution and use in source and binary forms, with or without
-- modification, are permitted provided that the following conditions are met:
--
-- * Redistributions of source code must retain the above copyright notice,
-- this list of conditions and the following disclaimer.
-- * Redistributions in binary form must reproduce the above copyright
-- notice, this list of conditions and the following disclaimer in the
-- documentation and/or other materials provided with the distribution.
-- * Neither the name of the Maxim Reznik, IE nor the names of its
-- contributors may be used to endorse or promote products derived from
-- this software without specific prior written permission.
--
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
-- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-- POSSIBILITY OF SUCH DAMAGE.
------------------------------------------------------------------------------
|
------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Ada Modeling Framework --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2011-2012, Vadim Godunko <vgodunko@gmail.com> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
with AMF.Elements;
with AMF.Factories.UML_Factories;
with AMF.Internals.Helpers;
with AMF.Internals.Tables.UML_Attributes;
with AMF.Stores;
with AMF.UML.Literal_Integers;
with AMF.UML.Literal_Unlimited_Naturals;
package body AMF.Internals.UML_Multiplicity_Elements is
use type AMF.UML.Value_Specifications.UML_Value_Specification_Access;
UML_URI : constant League.Strings.Universal_String
:= League.Strings.To_Universal_String
("http://www.omg.org/spec/UML/20100901");
--------------------
-- Get_Is_Ordered --
--------------------
overriding function Get_Is_Ordered
(Self : not null access constant UML_Multiplicity_Element_Proxy)
return Boolean is
begin
return
AMF.Internals.Tables.UML_Attributes.Internal_Get_Is_Ordered
(Self.Element);
end Get_Is_Ordered;
-------------------
-- Get_Is_Unique --
-------------------
overriding function Get_Is_Unique
(Self : not null access constant UML_Multiplicity_Element_Proxy)
return Boolean is
begin
return
AMF.Internals.Tables.UML_Attributes.Internal_Get_Is_Unique
(Self.Element);
end Get_Is_Unique;
---------------
-- Get_Lower --
---------------
overriding function Get_Lower
(Self : not null access constant UML_Multiplicity_Element_Proxy)
return AMF.Optional_Integer is
begin
-- [UML2.4.1] 7.3.33 MultiplicityElement (from Kernel)
--
-- [5] The derived lower attribute must equal the lowerBound.
--
-- lower = lowerBound()
return UML_Multiplicity_Element_Proxy'Class (Self.all).Lower_Bound;
end Get_Lower;
---------------------
-- Get_Lower_Value --
---------------------
overriding function Get_Lower_Value
(Self : not null access constant UML_Multiplicity_Element_Proxy)
return AMF.UML.Value_Specifications.UML_Value_Specification_Access is
begin
return
AMF.UML.Value_Specifications.UML_Value_Specification_Access
(AMF.Internals.Helpers.To_Element
(AMF.Internals.Tables.UML_Attributes.Internal_Get_Lower_Value
(Self.Element)));
end Get_Lower_Value;
---------------
-- Get_Upper --
---------------
overriding function Get_Upper
(Self : not null access constant UML_Multiplicity_Element_Proxy)
return AMF.Optional_Unlimited_Natural is
begin
-- [UML2.4.1] 7.3.33 MultiplicityElement (from Kernel)
--
-- [6] The derived upper attribute must equal the upperBound.
--
-- upper = upperBound()
return UML_Multiplicity_Element_Proxy'Class (Self.all).Upper_Bound;
end Get_Upper;
---------------------
-- Get_Upper_Value --
---------------------
overriding function Get_Upper_Value
(Self : not null access constant UML_Multiplicity_Element_Proxy)
return AMF.UML.Value_Specifications.UML_Value_Specification_Access is
begin
return
AMF.UML.Value_Specifications.UML_Value_Specification_Access
(AMF.Internals.Helpers.To_Element
(AMF.Internals.Tables.UML_Attributes.Internal_Get_Upper_Value
(Self.Element)));
end Get_Upper_Value;
--------------------
-- Is_Multivalued --
--------------------
overriding function Is_Multivalued
(Self : not null access constant UML_Multiplicity_Element_Proxy)
return Boolean
is
-- 7.3.33 MultiplicityElement (from Kernel)
--
-- [1] The query isMultivalued() checks whether this multiplicity has an
-- upper bound greater than one.
--
-- MultiplicityElement::isMultivalued() : Boolean;
-- pre: upperBound()->notEmpty()
-- isMultivalued = (upperBound() > 1)
Upper_Bound : constant Optional_Unlimited_Natural
:= UML_Multiplicity_Element_Proxy'Class (Self.all).Upper_Bound;
begin
if Upper_Bound.Is_Empty then
raise Constraint_Error;
end if;
return Upper_Bound.Value > 1;
end Is_Multivalued;
-----------------
-- Lower_Bound --
-----------------
overriding function Lower_Bound
(Self : not null access constant UML_Multiplicity_Element_Proxy)
return AMF.Optional_Integer
is
-- 7.3.33 MultiplicityElement (from Kernel)
--
-- [4] The query lowerBound() returns the lower bound of the
-- multiplicity as an integer.
--
-- MultiplicityElement::lowerBound() : [Integer];
-- lowerBound =
-- if lowerValue->isEmpty() then 1
-- else lowerValue.integerValue() endif
Lower_Value : constant
AMF.UML.Value_Specifications.UML_Value_Specification_Access
:= UML_Multiplicity_Element_Proxy'Class (Self.all).Get_Lower_Value;
begin
if Lower_Value = null then
return (False, 1);
else
return Lower_Value.Integer_Value;
end if;
end Lower_Bound;
--------------------
-- Set_Is_Ordered --
--------------------
overriding procedure Set_Is_Ordered
(Self : not null access UML_Multiplicity_Element_Proxy;
To : Boolean) is
begin
AMF.Internals.Tables.UML_Attributes.Internal_Set_Is_Ordered
(Self.Element, To);
end Set_Is_Ordered;
-------------------
-- Set_Is_Unique --
-------------------
overriding procedure Set_Is_Unique
(Self : not null access UML_Multiplicity_Element_Proxy;
To : Boolean) is
begin
AMF.Internals.Tables.UML_Attributes.Internal_Set_Is_Unique (Self.Element, To);
end Set_Is_Unique;
---------------
-- Set_Lower --
---------------
overriding procedure Set_Lower
(Self : not null access UML_Multiplicity_Element_Proxy;
To : AMF.Optional_Integer)
is
Lower : AMF.UML.Value_Specifications.UML_Value_Specification_Access
:= UML_Multiplicity_Element_Proxy'Class (Self.all).Get_Lower_Value;
Factory : AMF.Factories.UML_Factories.UML_Factory_Access;
begin
if To.Is_Empty then
if Lower /= null then
-- XXX Remove of the element is not implemented.
raise Program_Error;
end if;
else
if Lower = null then
Factory :=
AMF.Factories.UML_Factories.UML_Factory_Access
(AMF.Stores.Store'Class (Self.Extent.all).Get_Factory (UML_URI));
Lower :=
AMF.UML.Value_Specifications.UML_Value_Specification_Access
(Factory.Create_Literal_Integer);
UML_Multiplicity_Element_Proxy'Class
(Self.all).Set_Lower_Value (Lower);
end if;
AMF.UML.Literal_Integers.UML_Literal_Integer'Class
(Lower.all).Set_Value (To.Value);
end if;
end Set_Lower;
---------------------
-- Set_Lower_Value --
---------------------
overriding procedure Set_Lower_Value
(Self : not null access UML_Multiplicity_Element_Proxy;
To : AMF.UML.Value_Specifications.UML_Value_Specification_Access) is
begin
AMF.Internals.Tables.UML_Attributes.Internal_Set_Lower_Value
(Self.Element,
AMF.Internals.Helpers.To_Element
(AMF.Elements.Element_Access (To)));
end Set_Lower_Value;
---------------
-- Set_Upper --
---------------
overriding procedure Set_Upper
(Self : not null access UML_Multiplicity_Element_Proxy;
To : AMF.Optional_Unlimited_Natural)
is
Upper : AMF.UML.Value_Specifications.UML_Value_Specification_Access
:= UML_Multiplicity_Element_Proxy'Class (Self.all).Get_Upper_Value;
Factory : AMF.Factories.UML_Factories.UML_Factory_Access;
begin
if To.Is_Empty then
if Upper /= null then
-- XXX Remove of the element is not implemented.
raise Program_Error;
end if;
else
if Upper = null then
Factory :=
AMF.Factories.UML_Factories.UML_Factory_Access
(AMF.Stores.Store'Class (Self.Extent.all).Get_Factory (UML_URI));
Upper :=
AMF.UML.Value_Specifications.UML_Value_Specification_Access
(Factory.Create_Literal_Unlimited_Natural);
UML_Multiplicity_Element_Proxy'Class
(Self.all).Set_Upper_Value (Upper);
end if;
AMF.UML.Literal_Unlimited_Naturals.UML_Literal_Unlimited_Natural'Class
(Upper.all).Set_Value (To.Value);
end if;
end Set_Upper;
---------------------
-- Set_Upper_Value --
---------------------
overriding procedure Set_Upper_Value
(Self : not null access UML_Multiplicity_Element_Proxy;
To : AMF.UML.Value_Specifications.UML_Value_Specification_Access) is
begin
AMF.Internals.Tables.UML_Attributes.Internal_Set_Upper_Value
(Self.Element,
AMF.Internals.Helpers.To_Element
(AMF.Elements.Element_Access (To)));
end Set_Upper_Value;
-----------------
-- Upper_Bound --
-----------------
overriding function Upper_Bound
(Self : not null access constant UML_Multiplicity_Element_Proxy)
return AMF.Optional_Unlimited_Natural
is
-- 7.3.33 MultiplicityElement (from Kernel)
--
-- [5] The query upperBound() returns the upper bound of the
-- multiplicity for a bounded multiplicity as an unlimited natural.
--
-- MultiplicityElement::upperBound() : [UnlimitedNatural];
-- upperBound =
-- if upperValue->isEmpty() then 1
-- else upperValue.unlimitedValue() endif
Upper_Value : constant
AMF.UML.Value_Specifications.UML_Value_Specification_Access
:= UML_Multiplicity_Element_Proxy'Class (Self.all).Get_Upper_Value;
begin
if Upper_Value = null then
return (False, (False, 1));
else
return Upper_Value.Unlimited_Value;
end if;
end Upper_Bound;
end AMF.Internals.UML_Multiplicity_Elements;
|
generic
type Table_Component_Type is private;
type Table_Index_Type is range <>;
Table_Low_Bound : Table_Index_Type;
package Opt46_Pkg is
type Table_Type is
array (Table_Index_Type range <>) of Table_Component_Type;
subtype Big_Table_Type is
Table_Type (Table_Low_Bound .. Table_Index_Type'Last);
type Table_Ptr is access all Big_Table_Type;
type Table_Private is private;
type Instance is record
Table : aliased Table_Ptr := null;
P : Table_Private;
end record;
function Last (T : Instance) return Table_Index_Type;
private
type Table_Private is record
Last_Val : Integer;
end record;
end Opt46_Pkg;
|
pragma License (Unrestricted);
-- implementation unit required by compiler
package System.Bit_Ops is
pragma Preelaborate;
-- It can not be Pure, subprograms would become __attribute__((const)).
-- required for "=" packed boolean array by compiler (s-bitop.ads)
function Bit_Eq (
Left : Address;
Llen : Natural;
Right : Address;
Rlen : Natural)
return Boolean;
pragma Machine_Attribute (Bit_Eq, "pure");
-- required by compiler ??? (s-bitop.ads)
-- procedure Bit_Not (
-- Opnd : Address;
-- Len : Natural;
-- Result : Address);
-- procedure Bit_And (
-- Left : Address;
-- Llen : Natural;
-- Right : Address;
-- Rlen : Natural;
-- Result : Address);
-- procedure Bit_Or (
-- Left : Address;
-- Llen : Natural;
-- Right : Address;
-- Rlen : Natural;
-- Result : Address);
-- procedure Bit_Xor (
-- Left : Address;
-- Llen : Natural;
-- Right : Address;
-- Rlen : Natural;
-- Result : Address);
end System.Bit_Ops;
|
package body EU_Projects.Times is
-----------------
-- To_Duration --
-----------------
function To_Duration (X : Instant) return Duration is
begin
return Duration(X);
end To_Duration;
function Is_Empty (X : Interval) return Boolean
is
begin
return X.Start > X.Stop;
end Is_Empty;
function "<" (L, R : Interval) return Boolean
is
begin
return (not Is_Empty(L)) and then (not Is_Empty(R)) and then R.Stop < L.Start;
end "<";
function "and" (L, R : Interval) return Interval
is
begin
if Is_Empty (L) or Is_Empty (R) then
return Empty_Interval;
else
return Interval'(Start => Max (L.Start, R.Start),
Stop => Min (L.Stop, R.Stop));
end if;
end "and";
function "or" (L, R : Interval) return Interval
is
begin
if Is_Empty (L) then
return R;
elsif Is_Empty (R) then
return L;
elsif Is_Empty (L and R) then
raise Constraint_Error;
else
return Interval'(Start => Min (L.Start, R.Start),
Stop => Max (L.Stop, R.Stop));
end if;
end "or";
---------
-- "<" --
---------
function "=" (L, R : Instant) return Boolean
is (if L.Tbd /= R.Tbd then
False
elsif L.Tbd then
Standard.True
else
L.N = R.N);
function "<" (L, R : Instant) return Boolean
is (if L.Tbd then
False
elsif R.Tbd then
Standard.True
else
L.N < R.N);
----------
-- "<=" --
----------
function "<=" (L, R : Instant) return Boolean
is (L = R or else L < R);
---------
-- ">" --
---------
function ">" (L, R : Instant) return Boolean
is (R < L);
----------
-- ">=" --
----------
function ">=" (L, R : Instant) return Boolean
is (R <= L);
----------------
-- To_Instant --
----------------
function To_Instant
(Month : Natural;
Week : Natural := 0)
return Instant
is
begin
return Scalar (4 * Integer (Month) + Integer (Week));
end To_Instant;
---------------
-- To_Months --
---------------
function Months (Item : Instant)
return Integer
is (if Item.Tbd then
raise Constraint_Error
else
Item.N / 4);
-----------------
-- To_Duration --
-----------------
function To_Duration
(Month : Natural;
Week : Natural := 0)
return Duration
is
begin
return Duration (Scalar (4 * Integer (Month) + Integer (Week)));
end To_Duration;
---------------
-- To_Months --
---------------
function To_Months
(Item : Duration)
return Integer
is (if Item.Tbd then
raise Constraint_Error
else
Item.N / 4);
-----------------
-- To_Interval --
-----------------
function To_Interval (From, To : Instant) return Interval is
begin
return Interval'(Start => From,
Stop => To);
end To_Interval;
---------
-- "-" --
---------
function "-" (L, R : Instant) return Duration is
begin
return Duration(abs (Scalar_Type (L)-Scalar_Type (R)));
end "-";
---------
-- "+" --
---------
function "+" (L : Instant; R : Duration) return Instant is
begin
return Instant (Scalar_Type (L) + Scalar_Type (R));
end "+";
---------
-- "-" --
---------
function "-" (L : Instant; R : Duration) return Instant is
begin
return Instant (Scalar_Type (L) - Scalar_Type (R));
end "-";
---------
-- "+" --
---------
function "+" (L : Duration; R : Instant) return Instant is
begin
return Instant (L) + R;
end "+";
---------
-- "*" --
---------
function "*" (L : Duration; R : Float) return Duration is
begin
return L * Duration (Scalar (Integer (R)));
end "*";
--------------
-- Start_Of --
--------------
function Start_Of (Item : Interval) return Instant is
begin
return Item.Start;
end Start_Of;
------------
-- End_Of --
------------
function End_Of (Item : Interval) return Instant is
begin
return Item.Stop;
end End_Of;
-----------------
-- Duration_Of --
-----------------
function Duration_Of (Item : Interval) return Duration is
begin
return Item.Stop - Item.Start;
end Duration_Of;
----------------
-- Set_Option --
----------------
function Set_Option (Formatter : Time_Formatter;
Option : Formatting_Option;
Value : String)
return Time_Formatter
is
Result : Time_Formatter := Formatter;
begin
case Option is
when To_Be_Decided_Image =>
Result.Tbd_Image := To_Unbounded_String (Value);
end case;
return Result;
end Set_Option;
-----------
-- Image --
-----------
function Image (Formatter : Time_Formatter;
Item : Instant;
Unit : Unit_Type := Months;
Write_Unit : Boolean := False) return String
is
begin
if Item.Tbd then
return To_String (Formatter.Tbd_Image);
end if;
case Unit is
when Weeks =>
return Image (Item.N) & (if Write_Unit then "w" else "");
when Months =>
declare
Months : constant Scalar_Base := Item.N / 4;
Weeks : constant Scalar_Base := Item.N mod 4;
begin
if Write_Unit then
if Weeks = 0 then
return Chop (Natural'Image (Months)) & "m";
else
return
Image (Months) & "m"
& Image (Weeks) & "w";
end if;
else
return Image (Months);
end if;
end;
end case;
end Image;
end EU_Projects.Times;
|
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
with Ada.Float_Text_IO; use Ada.Float_Text_IO;
with Ada.Calendar; use Ada.Calendar;
with Ada.Calendar.Formatting; use Ada.Calendar.Formatting;
with Ada.Calendar.Time_Zones; use Ada.Calendar.Time_Zones;
procedure test_puiss is
procedure System_Time is
Now : Time := Clock;
begin
Put_line(Image(Date => Now, Time_Zone => 2*60));
end System_Time;
function somme_fact (n : Integer; x : Integer) return Float is
res : Float := 0.0;
fact : Integer := 1;
begin
for i in 1..n loop
fact := fact * i;
res := res + Float(Float(x) ** i) / Float(fact);
end loop;
return res;
end somme_fact;
function somme_fact_2 (n : Integer; x : Integer) return Float is
res : Float := 0.0;
puiss : Integer := 1;
fact : Integer := 1;
begin
for i in 1..n loop
fact := fact * i;
puiss := puiss * x;
res := res + Float(puiss) / Float(fact);
end loop;
return res;
end somme_fact_2;
test : Float := 0.0;
n : Integer := 1000000000;
begin
System_Time;
for i in 1..n loop
test := somme_fact(5, 3);
end loop;
System_Time;
for i in 1..n loop
test := somme_fact_2(5, 3);
end loop;
System_Time;
end test_puiss;
|
-- part of OpenGLAda, (c) 2017 Felix Krause
-- released under the terms of the MIT license, see the file "COPYING"
with GL.Types;
private with GL.Low_Level;
package GL.Rasterization is
pragma Preelaborate;
use GL.Types;
subtype Line_Width_Range is Singles.Vector2;
type Polygon_Mode_Type is (Point, Line, Fill);
procedure Set_Line_Width (Value : Single);
function Line_Width return Single;
function Aliased_Line_Width_Range return Line_Width_Range;
function Smooth_Line_Width_Range return Line_Width_Range;
function Smooth_Line_Width_Granularity return Single;
procedure Set_Polygon_Mode (Value : Polygon_Mode_Type);
function Polygon_Mode return Polygon_Mode_Type;
procedure Set_Polygon_Offset (Factor, Units : Single := 0.0);
procedure Set_Point_Size (Value : Single);
function Point_Size return Single;
function Point_Size_Range return Singles.Vector2;
function Point_Size_Granularity return Single;
procedure Set_Point_Fade_Threshold_Size (Value : Single);
function Point_Fade_Threshold_Size return Single;
private
for Polygon_Mode_Type use (Point => 16#1B00#,
Line => 16#1B01#,
Fill => 16#1B02#);
for Polygon_Mode_Type'Size use Low_Level.Enum'Size;
end GL.Rasterization;
|
------------------------------------------------------------------------------
-- --
-- Copyright (C) 2016-2020, AdaCore --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions are --
-- met: --
-- 1. Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- 2. Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in --
-- the documentation and/or other materials provided with the --
-- distribution. --
-- 3. Neither the name of the copyright holder nor the names of its --
-- contributors may be used to endorse or promote products derived --
-- from this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT --
-- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, --
-- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY --
-- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT --
-- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE --
-- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
with NRF_SVD.CLOCK; use NRF_SVD.CLOCK;
with nRF.Tasks; use nRF.Tasks;
package body nRF.Clock is
--------------------------------------
-- Set_High_Freq_External_Frequency --
--------------------------------------
procedure Set_High_Freq_External_Frequency
(Freq : High_Freq_Ext_Freq) is separate;
--------------------------
-- Set_High_Freq_Source --
--------------------------
procedure Set_High_Freq_Source (Src : High_Freq_Source_Kind) is
begin
CLOCK_Periph.HFCLKSTAT.SRC := (case Src is
when HFCLK_RC => Rc,
when HFCLK_XTAL => Xtal);
end Set_High_Freq_Source;
----------------------
-- High_Freq_Source --
----------------------
function High_Freq_Source return High_Freq_Source_Kind is
begin
case CLOCK_Periph.HFCLKSTAT.SRC is
when Rc => return HFCLK_RC;
when Xtal => return HFCLK_XTAL;
end case;
end High_Freq_Source;
-----------------------
-- High_Freq_Running --
-----------------------
function High_Freq_Running return Boolean is
begin
return CLOCK_Periph.HFCLKSTAT.STATE = Running;
end High_Freq_Running;
---------------------
-- Start_High_Freq --
---------------------
procedure Start_High_Freq is
begin
Tasks.Trigger (Tasks.Clock_HFCLKSTART);
end Start_High_Freq;
--------------------
-- Stop_High_Freq --
--------------------
procedure Stop_High_Freq is
begin
Tasks.Trigger (Tasks.Clock_HFCLKSTOP);
end Stop_High_Freq;
-------------------------
-- Set_Low_Freq_Source --
-------------------------
procedure Set_Low_Freq_Source (Src : Low_Freq_Source_Kind) is
begin
CLOCK_Periph.LFCLKSRC.SRC := (case Src is
when LFCLK_RC => Rc,
when LFCLK_XTAL => Xtal,
when LFCLK_SYNTH => Synth);
end Set_Low_Freq_Source;
---------------------
-- Low_Freq_Source --
---------------------
function Low_Freq_Source return Low_Freq_Source_Kind is
begin
case CLOCK_Periph.LFCLKSTAT.SRC is
when Rc => return LFCLK_RC;
when Xtal => return LFCLK_XTAL;
when Synth => return LFCLK_SYNTH;
end case;
end Low_Freq_Source;
----------------------
-- Low_Freq_Running --
----------------------
function Low_Freq_Running return Boolean is
begin
return CLOCK_Periph.LFCLKSTAT.STATE = Running;
end Low_Freq_Running;
--------------------
-- Start_Low_Freq --
--------------------
procedure Start_Low_Freq is
begin
Tasks.Trigger (Tasks.Clock_LFCLKSTART);
end Start_Low_Freq;
-------------------
-- Stop_Low_Freq --
-------------------
procedure Stop_Low_Freq is
begin
Tasks.Trigger (Tasks.Clock_LFCLKSTOP);
end Stop_Low_Freq;
end nRF.Clock;
|
-- Copyright (c) 2010 - 2018, Nordic Semiconductor ASA
--
-- All rights reserved.
--
-- Redistribution and use in source and binary forms, with or without modification,
-- are permitted provided that the following conditions are met:
--
-- 1. Redistributions of source code must retain the above copyright notice, this
-- list of conditions and the following disclaimer.
--
-- 2. Redistributions in binary form, except as embedded into a Nordic
-- Semiconductor ASA integrated circuit in a product or a software update for
-- such product, must reproduce the above copyright notice, this list of
-- conditions and the following disclaimer in the documentation and/or other
-- materials provided with the distribution.
--
-- 3. Neither the name of Nordic Semiconductor ASA nor the names of its
-- contributors may be used to endorse or promote products derived from this
-- software without specific prior written permission.
--
-- 4. This software, with or without modification, must only be used with a
-- Nordic Semiconductor ASA integrated circuit.
--
-- 5. Any software provided in binary form under this license must not be reverse
-- engineered, decompiled, modified and/or disassembled.
--
-- THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
-- OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
-- OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
-- DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
-- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
-- GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-- HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-- LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
-- OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
--
-- This spec has been automatically generated from nrf52.svd
pragma Restrictions (No_Elaboration_Code);
pragma Ada_2012;
pragma Style_Checks (Off);
with HAL;
with System;
package NRF_SVD.SPIS is
pragma Preelaborate;
---------------
-- Registers --
---------------
-- Shortcut between END event and ACQUIRE task
type SHORTS_END_ACQUIRE_Field is
(-- Disable shortcut
Disabled,
-- Enable shortcut
Enabled)
with Size => 1;
for SHORTS_END_ACQUIRE_Field use
(Disabled => 0,
Enabled => 1);
-- Shortcut register
type SHORTS_Register is record
-- unspecified
Reserved_0_1 : HAL.UInt2 := 16#0#;
-- Shortcut between END event and ACQUIRE task
END_ACQUIRE : SHORTS_END_ACQUIRE_Field := NRF_SVD.SPIS.Disabled;
-- unspecified
Reserved_3_31 : HAL.UInt29 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for SHORTS_Register use record
Reserved_0_1 at 0 range 0 .. 1;
END_ACQUIRE at 0 range 2 .. 2;
Reserved_3_31 at 0 range 3 .. 31;
end record;
-- Write '1' to Enable interrupt for END event
type INTENSET_END_Field is
(-- Read: Disabled
Disabled,
-- Read: Enabled
Enabled)
with Size => 1;
for INTENSET_END_Field use
(Disabled => 0,
Enabled => 1);
-- Write '1' to Enable interrupt for END event
type INTENSET_END_Field_1 is
(-- Reset value for the field
Intenset_End_Field_Reset,
-- Enable
Set)
with Size => 1;
for INTENSET_END_Field_1 use
(Intenset_End_Field_Reset => 0,
Set => 1);
-- Write '1' to Enable interrupt for ENDRX event
type INTENSET_ENDRX_Field is
(-- Read: Disabled
Disabled,
-- Read: Enabled
Enabled)
with Size => 1;
for INTENSET_ENDRX_Field use
(Disabled => 0,
Enabled => 1);
-- Write '1' to Enable interrupt for ENDRX event
type INTENSET_ENDRX_Field_1 is
(-- Reset value for the field
Intenset_Endrx_Field_Reset,
-- Enable
Set)
with Size => 1;
for INTENSET_ENDRX_Field_1 use
(Intenset_Endrx_Field_Reset => 0,
Set => 1);
-- Write '1' to Enable interrupt for ACQUIRED event
type INTENSET_ACQUIRED_Field is
(-- Read: Disabled
Disabled,
-- Read: Enabled
Enabled)
with Size => 1;
for INTENSET_ACQUIRED_Field use
(Disabled => 0,
Enabled => 1);
-- Write '1' to Enable interrupt for ACQUIRED event
type INTENSET_ACQUIRED_Field_1 is
(-- Reset value for the field
Intenset_Acquired_Field_Reset,
-- Enable
Set)
with Size => 1;
for INTENSET_ACQUIRED_Field_1 use
(Intenset_Acquired_Field_Reset => 0,
Set => 1);
-- Enable interrupt
type INTENSET_Register is record
-- unspecified
Reserved_0_0 : HAL.Bit := 16#0#;
-- Write '1' to Enable interrupt for END event
END_k : INTENSET_END_Field_1 := Intenset_End_Field_Reset;
-- unspecified
Reserved_2_3 : HAL.UInt2 := 16#0#;
-- Write '1' to Enable interrupt for ENDRX event
ENDRX : INTENSET_ENDRX_Field_1 := Intenset_Endrx_Field_Reset;
-- unspecified
Reserved_5_9 : HAL.UInt5 := 16#0#;
-- Write '1' to Enable interrupt for ACQUIRED event
ACQUIRED : INTENSET_ACQUIRED_Field_1 :=
Intenset_Acquired_Field_Reset;
-- unspecified
Reserved_11_31 : HAL.UInt21 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for INTENSET_Register use record
Reserved_0_0 at 0 range 0 .. 0;
END_k at 0 range 1 .. 1;
Reserved_2_3 at 0 range 2 .. 3;
ENDRX at 0 range 4 .. 4;
Reserved_5_9 at 0 range 5 .. 9;
ACQUIRED at 0 range 10 .. 10;
Reserved_11_31 at 0 range 11 .. 31;
end record;
-- Write '1' to Disable interrupt for END event
type INTENCLR_END_Field is
(-- Read: Disabled
Disabled,
-- Read: Enabled
Enabled)
with Size => 1;
for INTENCLR_END_Field use
(Disabled => 0,
Enabled => 1);
-- Write '1' to Disable interrupt for END event
type INTENCLR_END_Field_1 is
(-- Reset value for the field
Intenclr_End_Field_Reset,
-- Disable
Clear)
with Size => 1;
for INTENCLR_END_Field_1 use
(Intenclr_End_Field_Reset => 0,
Clear => 1);
-- Write '1' to Disable interrupt for ENDRX event
type INTENCLR_ENDRX_Field is
(-- Read: Disabled
Disabled,
-- Read: Enabled
Enabled)
with Size => 1;
for INTENCLR_ENDRX_Field use
(Disabled => 0,
Enabled => 1);
-- Write '1' to Disable interrupt for ENDRX event
type INTENCLR_ENDRX_Field_1 is
(-- Reset value for the field
Intenclr_Endrx_Field_Reset,
-- Disable
Clear)
with Size => 1;
for INTENCLR_ENDRX_Field_1 use
(Intenclr_Endrx_Field_Reset => 0,
Clear => 1);
-- Write '1' to Disable interrupt for ACQUIRED event
type INTENCLR_ACQUIRED_Field is
(-- Read: Disabled
Disabled,
-- Read: Enabled
Enabled)
with Size => 1;
for INTENCLR_ACQUIRED_Field use
(Disabled => 0,
Enabled => 1);
-- Write '1' to Disable interrupt for ACQUIRED event
type INTENCLR_ACQUIRED_Field_1 is
(-- Reset value for the field
Intenclr_Acquired_Field_Reset,
-- Disable
Clear)
with Size => 1;
for INTENCLR_ACQUIRED_Field_1 use
(Intenclr_Acquired_Field_Reset => 0,
Clear => 1);
-- Disable interrupt
type INTENCLR_Register is record
-- unspecified
Reserved_0_0 : HAL.Bit := 16#0#;
-- Write '1' to Disable interrupt for END event
END_k : INTENCLR_END_Field_1 := Intenclr_End_Field_Reset;
-- unspecified
Reserved_2_3 : HAL.UInt2 := 16#0#;
-- Write '1' to Disable interrupt for ENDRX event
ENDRX : INTENCLR_ENDRX_Field_1 := Intenclr_Endrx_Field_Reset;
-- unspecified
Reserved_5_9 : HAL.UInt5 := 16#0#;
-- Write '1' to Disable interrupt for ACQUIRED event
ACQUIRED : INTENCLR_ACQUIRED_Field_1 :=
Intenclr_Acquired_Field_Reset;
-- unspecified
Reserved_11_31 : HAL.UInt21 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for INTENCLR_Register use record
Reserved_0_0 at 0 range 0 .. 0;
END_k at 0 range 1 .. 1;
Reserved_2_3 at 0 range 2 .. 3;
ENDRX at 0 range 4 .. 4;
Reserved_5_9 at 0 range 5 .. 9;
ACQUIRED at 0 range 10 .. 10;
Reserved_11_31 at 0 range 11 .. 31;
end record;
-- Semaphore status
type SEMSTAT_SEMSTAT_Field is
(-- Semaphore is free
Free,
-- Semaphore is assigned to CPU
Cpu,
-- Semaphore is assigned to SPI slave
Spis,
-- Semaphore is assigned to SPI but a handover to the CPU is pending
Cpupending)
with Size => 2;
for SEMSTAT_SEMSTAT_Field use
(Free => 0,
Cpu => 1,
Spis => 2,
Cpupending => 3);
-- Semaphore status register
type SEMSTAT_Register is record
-- Read-only. Semaphore status
SEMSTAT : SEMSTAT_SEMSTAT_Field;
-- unspecified
Reserved_2_31 : HAL.UInt30;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for SEMSTAT_Register use record
SEMSTAT at 0 range 0 .. 1;
Reserved_2_31 at 0 range 2 .. 31;
end record;
-- TX buffer over-read detected, and prevented
type STATUS_OVERREAD_Field is
(-- Read: error not present
Notpresent,
-- Read: error present
Present)
with Size => 1;
for STATUS_OVERREAD_Field use
(Notpresent => 0,
Present => 1);
-- TX buffer over-read detected, and prevented
type STATUS_OVERREAD_Field_1 is
(-- Reset value for the field
Status_Overread_Field_Reset,
-- Write: clear error on writing '1'
Clear)
with Size => 1;
for STATUS_OVERREAD_Field_1 use
(Status_Overread_Field_Reset => 0,
Clear => 1);
-- RX buffer overflow detected, and prevented
type STATUS_OVERFLOW_Field is
(-- Read: error not present
Notpresent,
-- Read: error present
Present)
with Size => 1;
for STATUS_OVERFLOW_Field use
(Notpresent => 0,
Present => 1);
-- RX buffer overflow detected, and prevented
type STATUS_OVERFLOW_Field_1 is
(-- Reset value for the field
Status_Overflow_Field_Reset,
-- Write: clear error on writing '1'
Clear)
with Size => 1;
for STATUS_OVERFLOW_Field_1 use
(Status_Overflow_Field_Reset => 0,
Clear => 1);
-- Status from last transaction
type STATUS_Register is record
-- TX buffer over-read detected, and prevented
OVERREAD : STATUS_OVERREAD_Field_1 := Status_Overread_Field_Reset;
-- RX buffer overflow detected, and prevented
OVERFLOW : STATUS_OVERFLOW_Field_1 := Status_Overflow_Field_Reset;
-- unspecified
Reserved_2_31 : HAL.UInt30 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for STATUS_Register use record
OVERREAD at 0 range 0 .. 0;
OVERFLOW at 0 range 1 .. 1;
Reserved_2_31 at 0 range 2 .. 31;
end record;
-- Enable or disable SPI slave
type ENABLE_ENABLE_Field is
(-- Disable SPI slave
Disabled,
-- Enable SPI slave
Enabled)
with Size => 4;
for ENABLE_ENABLE_Field use
(Disabled => 0,
Enabled => 2);
-- Enable SPI slave
type ENABLE_Register is record
-- Enable or disable SPI slave
ENABLE : ENABLE_ENABLE_Field := NRF_SVD.SPIS.Disabled;
-- unspecified
Reserved_4_31 : HAL.UInt28 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for ENABLE_Register use record
ENABLE at 0 range 0 .. 3;
Reserved_4_31 at 0 range 4 .. 31;
end record;
-----------------------------------
-- SPIS_PSEL cluster's Registers --
-----------------------------------
subtype SCK_PSEL_PIN_Field is HAL.UInt5;
-- Connection
type SCK_CONNECT_Field is
(-- Connect
Connected,
-- Disconnect
Disconnected)
with Size => 1;
for SCK_CONNECT_Field use
(Connected => 0,
Disconnected => 1);
-- Pin select for SCK
type SCK_PSEL_Register is record
-- Pin number
PIN : SCK_PSEL_PIN_Field := 16#1F#;
-- unspecified
Reserved_5_30 : HAL.UInt26 := 16#3FFFFFF#;
-- Connection
CONNECT : SCK_CONNECT_Field := NRF_SVD.SPIS.Disconnected;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for SCK_PSEL_Register use record
PIN at 0 range 0 .. 4;
Reserved_5_30 at 0 range 5 .. 30;
CONNECT at 0 range 31 .. 31;
end record;
subtype MISO_PSEL_PIN_Field is HAL.UInt5;
-- Connection
type MISO_CONNECT_Field is
(-- Connect
Connected,
-- Disconnect
Disconnected)
with Size => 1;
for MISO_CONNECT_Field use
(Connected => 0,
Disconnected => 1);
-- Pin select for MISO signal
type MISO_PSEL_Register is record
-- Pin number
PIN : MISO_PSEL_PIN_Field := 16#1F#;
-- unspecified
Reserved_5_30 : HAL.UInt26 := 16#3FFFFFF#;
-- Connection
CONNECT : MISO_CONNECT_Field := NRF_SVD.SPIS.Disconnected;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for MISO_PSEL_Register use record
PIN at 0 range 0 .. 4;
Reserved_5_30 at 0 range 5 .. 30;
CONNECT at 0 range 31 .. 31;
end record;
subtype MOSI_PSEL_PIN_Field is HAL.UInt5;
-- Connection
type MOSI_CONNECT_Field is
(-- Connect
Connected,
-- Disconnect
Disconnected)
with Size => 1;
for MOSI_CONNECT_Field use
(Connected => 0,
Disconnected => 1);
-- Pin select for MOSI signal
type MOSI_PSEL_Register is record
-- Pin number
PIN : MOSI_PSEL_PIN_Field := 16#1F#;
-- unspecified
Reserved_5_30 : HAL.UInt26 := 16#3FFFFFF#;
-- Connection
CONNECT : MOSI_CONNECT_Field := NRF_SVD.SPIS.Disconnected;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for MOSI_PSEL_Register use record
PIN at 0 range 0 .. 4;
Reserved_5_30 at 0 range 5 .. 30;
CONNECT at 0 range 31 .. 31;
end record;
subtype CSN_PSEL_PIN_Field is HAL.UInt5;
-- Connection
type CSN_CONNECT_Field is
(-- Connect
Connected,
-- Disconnect
Disconnected)
with Size => 1;
for CSN_CONNECT_Field use
(Connected => 0,
Disconnected => 1);
-- Pin select for CSN signal
type CSN_PSEL_Register is record
-- Pin number
PIN : CSN_PSEL_PIN_Field := 16#1F#;
-- unspecified
Reserved_5_30 : HAL.UInt26 := 16#3FFFFFF#;
-- Connection
CONNECT : CSN_CONNECT_Field := NRF_SVD.SPIS.Disconnected;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for CSN_PSEL_Register use record
PIN at 0 range 0 .. 4;
Reserved_5_30 at 0 range 5 .. 30;
CONNECT at 0 range 31 .. 31;
end record;
-- Unspecified
type SPIS_PSEL_Cluster is record
-- Pin select for SCK
SCK : aliased SCK_PSEL_Register;
-- Pin select for MISO signal
MISO : aliased MISO_PSEL_Register;
-- Pin select for MOSI signal
MOSI : aliased MOSI_PSEL_Register;
-- Pin select for CSN signal
CSN : aliased CSN_PSEL_Register;
end record
with Size => 128;
for SPIS_PSEL_Cluster use record
SCK at 16#0# range 0 .. 31;
MISO at 16#4# range 0 .. 31;
MOSI at 16#8# range 0 .. 31;
CSN at 16#C# range 0 .. 31;
end record;
----------------------------------
-- SPIS_RXD cluster's Registers --
----------------------------------
subtype MAXCNT_RXD_MAXCNT_Field is HAL.UInt8;
-- Maximum number of bytes in receive buffer
type MAXCNT_RXD_Register is record
-- Maximum number of bytes in receive buffer
MAXCNT : MAXCNT_RXD_MAXCNT_Field := 16#0#;
-- unspecified
Reserved_8_31 : HAL.UInt24 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for MAXCNT_RXD_Register use record
MAXCNT at 0 range 0 .. 7;
Reserved_8_31 at 0 range 8 .. 31;
end record;
subtype AMOUNT_RXD_AMOUNT_Field is HAL.UInt8;
-- Number of bytes received in last granted transaction
type AMOUNT_RXD_Register is record
-- Read-only. Number of bytes received in the last granted transaction
AMOUNT : AMOUNT_RXD_AMOUNT_Field;
-- unspecified
Reserved_8_31 : HAL.UInt24;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for AMOUNT_RXD_Register use record
AMOUNT at 0 range 0 .. 7;
Reserved_8_31 at 0 range 8 .. 31;
end record;
-- Unspecified
type SPIS_RXD_Cluster is record
-- RXD data pointer
PTR : aliased HAL.UInt32;
-- Maximum number of bytes in receive buffer
MAXCNT : aliased MAXCNT_RXD_Register;
-- Number of bytes received in last granted transaction
AMOUNT : aliased AMOUNT_RXD_Register;
end record
with Size => 96;
for SPIS_RXD_Cluster use record
PTR at 16#0# range 0 .. 31;
MAXCNT at 16#4# range 0 .. 31;
AMOUNT at 16#8# range 0 .. 31;
end record;
----------------------------------
-- SPIS_TXD cluster's Registers --
----------------------------------
subtype MAXCNT_TXD_MAXCNT_Field is HAL.UInt8;
-- Maximum number of bytes in transmit buffer
type MAXCNT_TXD_Register is record
-- Maximum number of bytes in transmit buffer
MAXCNT : MAXCNT_TXD_MAXCNT_Field := 16#0#;
-- unspecified
Reserved_8_31 : HAL.UInt24 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for MAXCNT_TXD_Register use record
MAXCNT at 0 range 0 .. 7;
Reserved_8_31 at 0 range 8 .. 31;
end record;
subtype AMOUNT_TXD_AMOUNT_Field is HAL.UInt8;
-- Number of bytes transmitted in last granted transaction
type AMOUNT_TXD_Register is record
-- Read-only. Number of bytes transmitted in last granted transaction
AMOUNT : AMOUNT_TXD_AMOUNT_Field;
-- unspecified
Reserved_8_31 : HAL.UInt24;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for AMOUNT_TXD_Register use record
AMOUNT at 0 range 0 .. 7;
Reserved_8_31 at 0 range 8 .. 31;
end record;
-- Unspecified
type SPIS_TXD_Cluster is record
-- TXD data pointer
PTR : aliased HAL.UInt32;
-- Maximum number of bytes in transmit buffer
MAXCNT : aliased MAXCNT_TXD_Register;
-- Number of bytes transmitted in last granted transaction
AMOUNT : aliased AMOUNT_TXD_Register;
end record
with Size => 96;
for SPIS_TXD_Cluster use record
PTR at 16#0# range 0 .. 31;
MAXCNT at 16#4# range 0 .. 31;
AMOUNT at 16#8# range 0 .. 31;
end record;
-- Bit order
type CONFIG_ORDER_Field is
(-- Most significant bit shifted out first
Msbfirst,
-- Least significant bit shifted out first
Lsbfirst)
with Size => 1;
for CONFIG_ORDER_Field use
(Msbfirst => 0,
Lsbfirst => 1);
-- Serial clock (SCK) phase
type CONFIG_CPHA_Field is
(-- Sample on leading edge of clock, shift serial data on trailing edge
Leading,
-- Sample on trailing edge of clock, shift serial data on leading edge
Trailing)
with Size => 1;
for CONFIG_CPHA_Field use
(Leading => 0,
Trailing => 1);
-- Serial clock (SCK) polarity
type CONFIG_CPOL_Field is
(-- Active high
Activehigh,
-- Active low
Activelow)
with Size => 1;
for CONFIG_CPOL_Field use
(Activehigh => 0,
Activelow => 1);
-- Configuration register
type CONFIG_Register is record
-- Bit order
ORDER : CONFIG_ORDER_Field := NRF_SVD.SPIS.Msbfirst;
-- Serial clock (SCK) phase
CPHA : CONFIG_CPHA_Field := NRF_SVD.SPIS.Leading;
-- Serial clock (SCK) polarity
CPOL : CONFIG_CPOL_Field := NRF_SVD.SPIS.Activehigh;
-- unspecified
Reserved_3_31 : HAL.UInt29 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for CONFIG_Register use record
ORDER at 0 range 0 .. 0;
CPHA at 0 range 1 .. 1;
CPOL at 0 range 2 .. 2;
Reserved_3_31 at 0 range 3 .. 31;
end record;
subtype DEF_DEF_Field is HAL.UInt8;
-- Default character. Character clocked out in case of an ignored
-- transaction.
type DEF_Register is record
-- Default character. Character clocked out in case of an ignored
-- transaction.
DEF : DEF_DEF_Field := 16#0#;
-- unspecified
Reserved_8_31 : HAL.UInt24 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for DEF_Register use record
DEF at 0 range 0 .. 7;
Reserved_8_31 at 0 range 8 .. 31;
end record;
subtype ORC_ORC_Field is HAL.UInt8;
-- Over-read character
type ORC_Register is record
-- Over-read character. Character clocked out after an over-read of the
-- transmit buffer.
ORC : ORC_ORC_Field := 16#0#;
-- unspecified
Reserved_8_31 : HAL.UInt24 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for ORC_Register use record
ORC at 0 range 0 .. 7;
Reserved_8_31 at 0 range 8 .. 31;
end record;
-----------------------------------
-- SPIS_PSEL cluster's Registers --
-----------------------------------
----------------------------------
-- SPIS_RXD cluster's Registers --
----------------------------------
----------------------------------
-- SPIS_TXD cluster's Registers --
----------------------------------
-----------------------------------
-- SPIS_PSEL cluster's Registers --
-----------------------------------
----------------------------------
-- SPIS_RXD cluster's Registers --
----------------------------------
----------------------------------
-- SPIS_TXD cluster's Registers --
----------------------------------
-----------------
-- Peripherals --
-----------------
-- SPI Slave 0
type SPIS_Peripheral is record
-- Acquire SPI semaphore
TASKS_ACQUIRE : aliased HAL.UInt32;
-- Release SPI semaphore, enabling the SPI slave to acquire it
TASKS_RELEASE : aliased HAL.UInt32;
-- Granted transaction completed
EVENTS_END : aliased HAL.UInt32;
-- End of RXD buffer reached
EVENTS_ENDRX : aliased HAL.UInt32;
-- Semaphore acquired
EVENTS_ACQUIRED : aliased HAL.UInt32;
-- Shortcut register
SHORTS : aliased SHORTS_Register;
-- Enable interrupt
INTENSET : aliased INTENSET_Register;
-- Disable interrupt
INTENCLR : aliased INTENCLR_Register;
-- Semaphore status register
SEMSTAT : aliased SEMSTAT_Register;
-- Status from last transaction
STATUS : aliased STATUS_Register;
-- Enable SPI slave
ENABLE : aliased ENABLE_Register;
-- Unspecified
PSEL : aliased SPIS_PSEL_Cluster;
-- Unspecified
RXD : aliased SPIS_RXD_Cluster;
-- Unspecified
TXD : aliased SPIS_TXD_Cluster;
-- Configuration register
CONFIG : aliased CONFIG_Register;
-- Default character. Character clocked out in case of an ignored
-- transaction.
DEF : aliased DEF_Register;
-- Over-read character
ORC : aliased ORC_Register;
end record
with Volatile;
for SPIS_Peripheral use record
TASKS_ACQUIRE at 16#24# range 0 .. 31;
TASKS_RELEASE at 16#28# range 0 .. 31;
EVENTS_END at 16#104# range 0 .. 31;
EVENTS_ENDRX at 16#110# range 0 .. 31;
EVENTS_ACQUIRED at 16#128# range 0 .. 31;
SHORTS at 16#200# range 0 .. 31;
INTENSET at 16#304# range 0 .. 31;
INTENCLR at 16#308# range 0 .. 31;
SEMSTAT at 16#400# range 0 .. 31;
STATUS at 16#440# range 0 .. 31;
ENABLE at 16#500# range 0 .. 31;
PSEL at 16#508# range 0 .. 127;
RXD at 16#534# range 0 .. 95;
TXD at 16#544# range 0 .. 95;
CONFIG at 16#554# range 0 .. 31;
DEF at 16#55C# range 0 .. 31;
ORC at 16#5C0# range 0 .. 31;
end record;
-- SPI Slave 0
SPIS0_Periph : aliased SPIS_Peripheral
with Import, Address => SPIS0_Base;
-- SPI Slave 1
SPIS1_Periph : aliased SPIS_Peripheral
with Import, Address => SPIS1_Base;
-- SPI Slave 2
SPIS2_Periph : aliased SPIS_Peripheral
with Import, Address => SPIS2_Base;
end NRF_SVD.SPIS;
|
with System;
package NAT1 is
Nat_One_Storage : constant Natural := 1;
One_Address : constant System.Address := Nat_One_Storage'Address;
end;
|
-- C97307A.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 TIMED ENTRY CALL THAT IS CANCELED (BECAUSE THE DELAY HAS
-- EXPIRED) IS REMOVED FROM THE QUEUE OF THE CALLED TASK'S ENTRY.
-- WRG 7/14/86
with Impdef;
WITH REPORT; USE REPORT;
PROCEDURE C97307A IS
BEGIN
TEST ("C97307A", "CHECK THAT A TIMED ENTRY CALL THAT IS " &
"CANCELED (BECAUSE THE DELAY HAS EXPIRED) IS " &
"REMOVED FROM THE QUEUE OF THE CALLED TASK'S " &
"ENTRY");
DECLARE
DELAY_TIME : CONSTANT DURATION := 2 * 60.0 * Impdef.One_Second;
TASK EXPIRED IS
ENTRY INCREMENT;
ENTRY READ (COUNT : OUT NATURAL);
END EXPIRED;
TASK TYPE NON_TIMED_CALLER IS
ENTRY NAME (N : NATURAL);
END NON_TIMED_CALLER;
TASK TYPE TIMED_CALLER IS
ENTRY NAME (N : NATURAL);
END TIMED_CALLER;
CALLER1 : TIMED_CALLER;
CALLER2 : NON_TIMED_CALLER;
CALLER3 : TIMED_CALLER;
CALLER4 : NON_TIMED_CALLER;
CALLER5 : TIMED_CALLER;
TASK T IS
ENTRY E (NAME : NATURAL);
END T;
TASK DISPATCH IS
ENTRY READY;
END DISPATCH;
--------------------------------------------------
TASK BODY EXPIRED IS
EXPIRED_CALLS : NATURAL := 0;
BEGIN
LOOP
SELECT
ACCEPT INCREMENT DO
EXPIRED_CALLS := EXPIRED_CALLS + 1;
END INCREMENT;
OR
ACCEPT READ (COUNT : OUT NATURAL) DO
COUNT := EXPIRED_CALLS;
END READ;
OR
TERMINATE;
END SELECT;
END LOOP;
END EXPIRED;
--------------------------------------------------
TASK BODY NON_TIMED_CALLER IS
MY_NAME : NATURAL;
BEGIN
ACCEPT NAME (N : NATURAL) DO
MY_NAME := N;
END NAME;
T.E (MY_NAME);
END NON_TIMED_CALLER;
--------------------------------------------------
TASK BODY TIMED_CALLER IS
MY_NAME : NATURAL;
BEGIN
ACCEPT NAME (N : NATURAL) DO
MY_NAME := N;
END NAME;
SELECT
T.E (MY_NAME);
FAILED ("TIMED ENTRY CALL NOT CANCELED FOR CALLER" &
NATURAL'IMAGE(MY_NAME));
OR
DELAY DELAY_TIME;
EXPIRED.INCREMENT;
END SELECT;
EXCEPTION
WHEN OTHERS =>
FAILED ("EXCEPTION RAISED IN TIMED_CALLER -- " &
"CALLER" & NATURAL'IMAGE(MY_NAME));
END TIMED_CALLER;
--------------------------------------------------
TASK BODY DISPATCH IS
BEGIN
CALLER1.NAME (1);
ACCEPT READY;
CALLER2.NAME (2);
ACCEPT READY;
CALLER3.NAME (3);
ACCEPT READY;
CALLER4.NAME (4);
ACCEPT READY;
CALLER5.NAME (5);
END DISPATCH;
--------------------------------------------------
TASK BODY T IS
DESIRED_QUEUE_LENGTH : NATURAL := 1;
EXPIRED_CALLS : NATURAL;
ACCEPTED : ARRAY (1..5) OF NATURAL RANGE 0..5
:= (OTHERS => 0);
ACCEPTED_INDEX : NATURAL := 0;
BEGIN
LOOP
LOOP
EXPIRED.READ (EXPIRED_CALLS);
EXIT WHEN E'COUNT >= DESIRED_QUEUE_LENGTH -
EXPIRED_CALLS;
DELAY 2.0 * Impdef.One_Long_Second;
END LOOP;
EXIT WHEN DESIRED_QUEUE_LENGTH = 5;
DISPATCH.READY;
DESIRED_QUEUE_LENGTH := DESIRED_QUEUE_LENGTH + 1;
END LOOP;
-- AT THIS POINT, FIVE TASKS WERE QUEUED.
-- LET THE TIMED ENTRY CALLS ISSUED BY CALLER1,
-- CALLER3, AND CALLER5 EXPIRE:
DELAY DELAY_TIME + 10.0 * Impdef.One_Long_Second;
-- AT THIS POINT, ALL THE TIMED ENTRY CALLS MUST HAVE
-- EXPIRED AND BEEN REMOVED FROM THE ENTRY QUEUE FOR E,
-- OTHERWISE THE IMPLEMENTATION HAS FAILED THIS TEST.
WHILE E'COUNT > 0 LOOP
ACCEPT E (NAME : NATURAL) DO
ACCEPTED_INDEX := ACCEPTED_INDEX + 1;
ACCEPTED (ACCEPTED_INDEX) := NAME;
END E;
END LOOP;
IF ACCEPTED /= (2, 4, 0, 0, 0) THEN
FAILED ("SOME TIMED CALLS NOT REMOVED FROM ENTRY " &
"QUEUE");
COMMENT ("ORDER ACCEPTED WAS:" &
NATURAL'IMAGE (ACCEPTED (1)) & ',' &
NATURAL'IMAGE (ACCEPTED (2)) & ',' &
NATURAL'IMAGE (ACCEPTED (3)) & ',' &
NATURAL'IMAGE (ACCEPTED (4)) & ',' &
NATURAL'IMAGE (ACCEPTED (5)) );
END IF;
END T;
--------------------------------------------------
BEGIN
NULL;
END;
RESULT;
END C97307A;
|
------------------------------------------------------------------------------
-- Copyright (c) 2019, Natacha Porté --
-- --
-- Permission to use, copy, modify, and distribute this software for any --
-- purpose with or without fee is hereby granted, provided that the above --
-- copyright notice and this permission notice appear in all copies. --
-- --
-- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES --
-- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF --
-- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR --
-- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES --
-- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN --
-- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF --
-- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. --
------------------------------------------------------------------------------
------------------------------------------------------------------------------
-- Lithium.Photo_Process provides a programmable processor for JPEG images. --
------------------------------------------------------------------------------
with Natools.S_Expressions.Lockable;
private with Ada.Finalization;
private with Interfaces.C;
private with Natools.References;
private with Natools.S_Expressions.Atom_Refs;
private with Natools.Storage_Pools;
private with TurboJPEG_Thin;
package Lithium.Photo_Process is
package Sx renames Natools.S_Expressions;
type Process_Description is private;
function Create (Arguments : in out Sx.Lockable.Descriptor'Class)
return Process_Description;
package Orientations is
type Enum is
(Top_Left, Top_Right, Bottom_Right, Bottom_Left,
Left_Top, Right_Top, Right_Bottom, Left_Bottom);
end Orientations;
type Image is tagged private;
function Create
(File_Name : in String;
Orientation : in Orientations.Enum)
return Image;
procedure Run
(Object : in Image;
Base_Name : in String;
Description : in Process_Description);
private
type Process_Description is record
Max_Width : Natural := 0;
Max_Height : Natural := 0;
Quality : Natural := 85;
Path : Sx.Atom_Refs.Immutable_Reference;
Prefix : Sx.Atom_Refs.Immutable_Reference;
Suffix : Sx.Atom_Refs.Immutable_Reference;
end record;
type Buffer is new Ada.Finalization.Limited_Controlled with record
Data : TurboJPEG_Thin.Bytes.Pointer := null;
Size : Interfaces.C.unsigned_long := 0;
end record;
function Create (Size : in Interfaces.C.int) return Buffer;
function Create (File_Name : in String) return Buffer;
overriding procedure Finalize (Self : in out Buffer);
function Plane_Size
(Label : in TurboJPEG_Thin.Plane_Label;
Width, Height : in Positive;
Sub_Samp : in Interfaces.C.int)
return Interfaces.C.unsigned_long
is (TurboJPEG_Thin.Plane_Size_YUV
(TurboJPEG_Thin.Plane_Label'Pos (Label),
Interfaces.C.int (Width),
0, -- Stride
Interfaces.C.int (Height),
Sub_Samp));
function Create
(Label : in TurboJPEG_Thin.Plane_Label;
Width, Height : in Positive;
Sub_Samp : in Interfaces.C.int)
return Buffer
is (Create (Interfaces.C.int
(Plane_Size (Label, Width, Height, Sub_Samp))));
type Planes_Buffer is array (TurboJPEG_Thin.Plane_Label) of Buffer;
function "+" (Buffer : Planes_Buffer) return TurboJPEG_Thin.Planes_Buffer
is ((TurboJPEG_Thin.Y => Buffer (TurboJPEG_Thin.Y).Data,
TurboJPEG_Thin.Cb => Buffer (TurboJPEG_Thin.Cb).Data,
TurboJPEG_Thin.Cr => Buffer (TurboJPEG_Thin.Cr).Data));
type Image_Data is limited record
Width : Positive;
Height : Positive;
Sub_Samp : Interfaces.C.int;
Planes : Planes_Buffer;
end record;
function Create
(Width, Height : in Positive;
Sub_Samp : in Interfaces.C.int)
return Image_Data
is (Width => Width,
Height => Height,
Sub_Samp => Sub_Samp,
Planes =>
(TurboJPEG_Thin.Y
=> Create (TurboJPEG_Thin.Y, Width, Height, Sub_Samp),
TurboJPEG_Thin.Cb
=> Create (TurboJPEG_Thin.Cb, Width, Height, Sub_Samp),
TurboJPEG_Thin.Cr
=> Create (TurboJPEG_Thin.Cr, Width, Height, Sub_Samp)));
package Data_Refs is new Natools.References
(Image_Data,
Natools.Storage_Pools.Access_In_Default_Pool'Storage_Pool,
Natools.Storage_Pools.Access_In_Default_Pool'Storage_Pool);
type Image is tagged record
Ref : Data_Refs.Immutable_Reference;
end record;
end Lithium.Photo_Process;
|
package RCP.User is
-- a user process class with discriminants
-- for use by the constructor
task type User_T
(Id : Positive;
Extent : Use_T;
Demand : Request_T;
Interval : Positive);
end RCP.User;
|
-- part of AdaYaml, (c) 2017 Felix Krause
-- released under the terms of the MIT license, see the file "copying.txt"
with Ada.Containers;
with Ada.Finalization;
with Text.Pool;
generic
type Value_Type is private;
package Yaml.Text_Set is
type Reference is new Ada.Finalization.Limited_Controlled with private;
type Holder is record
Hash : Ada.Containers.Hash_Type;
Key : Text.Reference;
Value : Value_Type;
end record;
function Get (Object : in out Reference; S : Standard.String;
Create : Boolean) return not null access Holder;
function Set (Object : in out Reference; S : Standard.String;
Value : Value_Type) return Boolean;
procedure Init (Object : in out Reference; Pool : Text.Pool.Reference;
Initial_Size : Positive);
procedure Clear (Object : in out Reference);
private
type Holder_Array is array (Natural range <>) of aliased Holder;
type Holder_Array_Access is access Holder_Array;
type Reference is new Ada.Finalization.Limited_Controlled with record
Count : Natural;
Elements : Holder_Array_Access;
Pool : Text.Pool.Reference;
end record;
overriding procedure Finalize (Object : in out Reference);
end Yaml.Text_Set;
|
------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- S Y S T E M . P O O L _ S I Z E --
-- --
-- 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. --
-- --
------------------------------------------------------------------------------
with System.Storage_Pools;
with System.Storage_Elements;
package System.Pool_Size is
pragma Elaborate_Body;
-- Needed to ensure that library routines can execute allocators
------------------------
-- Stack_Bounded_Pool --
------------------------
-- Allocation strategy:
-- Pool is a regular stack array, no use of malloc
-- user specified size
-- Space of pool is globally reclaimed by normal stack management
-- Used in the compiler for access types with 'STORAGE_SIZE rep. clause
-- Only used for allocating objects of the same type.
type Stack_Bounded_Pool
(Pool_Size : System.Storage_Elements.Storage_Count;
Elmt_Size : System.Storage_Elements.Storage_Count;
Alignment : System.Storage_Elements.Storage_Count)
is
new System.Storage_Pools.Root_Storage_Pool with record
First_Free : System.Storage_Elements.Storage_Count;
First_Empty : System.Storage_Elements.Storage_Count;
Aligned_Elmt_Size : System.Storage_Elements.Storage_Count;
The_Pool : System.Storage_Elements.Storage_Array
(1 .. Pool_Size);
end record;
function Storage_Size
(Pool : Stack_Bounded_Pool)
return System.Storage_Elements.Storage_Count;
procedure Allocate
(Pool : in out Stack_Bounded_Pool;
Address : out System.Address;
Storage_Size : System.Storage_Elements.Storage_Count;
Alignment : System.Storage_Elements.Storage_Count);
procedure Deallocate
(Pool : in out Stack_Bounded_Pool;
Address : System.Address;
Storage_Size : System.Storage_Elements.Storage_Count;
Alignment : System.Storage_Elements.Storage_Count);
procedure Initialize (Pool : in out Stack_Bounded_Pool);
end System.Pool_Size;
|
-- Copyright 2016-2019 NXP
-- All rights reserved.SPDX-License-Identifier: BSD-3-Clause
-- This spec has been automatically generated from LPC55S6x.svd
pragma Restrictions (No_Elaboration_Code);
pragma Ada_2012;
pragma Style_Checks (Off);
with HAL;
with System;
package NXP_SVD.WWDT is
pragma Preelaborate;
---------------
-- Registers --
---------------
-- Watchdog enable bit. Once this bit is set to one and a watchdog feed is
-- performed, the watchdog timer will run permanently.
type MOD_WDEN_Field is
(
-- Stop. The watchdog timer is stopped.
Stop,
-- Run. The watchdog timer is running.
Run)
with Size => 1;
for MOD_WDEN_Field use
(Stop => 0,
Run => 1);
-- Watchdog reset enable bit. Once this bit has been written with a 1 it
-- cannot be re-written with a 0.
type MOD_WDRESET_Field is
(
-- Interrupt. A watchdog time-out will not cause a chip reset.
Interrupt,
-- Reset. A watchdog time-out will cause a chip reset.
Reset)
with Size => 1;
for MOD_WDRESET_Field use
(Interrupt => 0,
Reset => 1);
-- Watchdog update mode. This bit can be set once by software and is only
-- cleared by a reset.
type MOD_WDPROTECT_Field is
(
-- Flexible. The watchdog time-out value (TC) can be changed at any
-- time.
Flexible,
-- Threshold. The watchdog time-out value (TC) can be changed only after
-- the counter is below the value of WDWARNINT and WDWINDOW.
Threshold)
with Size => 1;
for MOD_WDPROTECT_Field use
(Flexible => 0,
Threshold => 1);
-- Watchdog mode register. This register contains the basic mode and status
-- of the Watchdog Timer.
type MOD_Register is record
-- Watchdog enable bit. Once this bit is set to one and a watchdog feed
-- is performed, the watchdog timer will run permanently.
WDEN : MOD_WDEN_Field := NXP_SVD.WWDT.Stop;
-- Watchdog reset enable bit. Once this bit has been written with a 1 it
-- cannot be re-written with a 0.
WDRESET : MOD_WDRESET_Field := NXP_SVD.WWDT.Interrupt;
-- Watchdog time-out flag. Set when the watchdog timer times out, by a
-- feed error, or by events associated with WDPROTECT. Cleared by
-- software writing a 0 to this bit position. Causes a chip reset if
-- WDRESET = 1.
WDTOF : Boolean := False;
-- Warning interrupt flag. Set when the timer is at or below the value
-- in WDWARNINT. Cleared by software writing a 1 to this bit position.
-- Note that this bit cannot be cleared while the WARNINT value is equal
-- to the value of the TV register. This can occur if the value of
-- WARNINT is 0 and the WDRESET bit is 0 when TV decrements to 0.
WDINT : Boolean := False;
-- Watchdog update mode. This bit can be set once by software and is
-- only cleared by a reset.
WDPROTECT : MOD_WDPROTECT_Field := NXP_SVD.WWDT.Flexible;
-- unspecified
Reserved_5_31 : HAL.UInt27 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for MOD_Register use record
WDEN at 0 range 0 .. 0;
WDRESET at 0 range 1 .. 1;
WDTOF at 0 range 2 .. 2;
WDINT at 0 range 3 .. 3;
WDPROTECT at 0 range 4 .. 4;
Reserved_5_31 at 0 range 5 .. 31;
end record;
subtype TC_COUNT_Field is HAL.UInt24;
-- Watchdog timer constant register. This 24-bit register determines the
-- time-out value.
type TC_Register is record
-- Watchdog time-out value.
COUNT : TC_COUNT_Field := 16#FF#;
-- unspecified
Reserved_24_31 : HAL.UInt8 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for TC_Register use record
COUNT at 0 range 0 .. 23;
Reserved_24_31 at 0 range 24 .. 31;
end record;
subtype FEED_FEED_Field is HAL.UInt8;
-- Watchdog feed sequence register. Writing 0xAA followed by 0x55 to this
-- register reloads the Watchdog timer with the value contained in TC.
type FEED_Register is record
-- Write-only. Feed value should be 0xAA followed by 0x55.
FEED : FEED_FEED_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 FEED_Register use record
FEED at 0 range 0 .. 7;
Reserved_8_31 at 0 range 8 .. 31;
end record;
subtype TV_COUNT_Field is HAL.UInt24;
-- Watchdog timer value register. This 24-bit register reads out the
-- current value of the Watchdog timer.
type TV_Register is record
-- Read-only. Counter timer value.
COUNT : TV_COUNT_Field;
-- unspecified
Reserved_24_31 : HAL.UInt8;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for TV_Register use record
COUNT at 0 range 0 .. 23;
Reserved_24_31 at 0 range 24 .. 31;
end record;
subtype WARNINT_WARNINT_Field is HAL.UInt10;
-- Watchdog Warning Interrupt compare value.
type WARNINT_Register is record
-- Watchdog warning interrupt compare value.
WARNINT : WARNINT_WARNINT_Field := 16#0#;
-- unspecified
Reserved_10_31 : HAL.UInt22 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for WARNINT_Register use record
WARNINT at 0 range 0 .. 9;
Reserved_10_31 at 0 range 10 .. 31;
end record;
subtype WINDOW_WINDOW_Field is HAL.UInt24;
-- Watchdog Window compare value.
type WINDOW_Register is record
-- Watchdog window value.
WINDOW : WINDOW_WINDOW_Field := 16#FFFFFF#;
-- unspecified
Reserved_24_31 : HAL.UInt8 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for WINDOW_Register use record
WINDOW at 0 range 0 .. 23;
Reserved_24_31 at 0 range 24 .. 31;
end record;
-----------------
-- Peripherals --
-----------------
-- Windowed Watchdog Timer (WWDT)
type WWDT_Peripheral is record
-- Watchdog mode register. This register contains the basic mode and
-- status of the Watchdog Timer.
MOD_k : aliased MOD_Register;
-- Watchdog timer constant register. This 24-bit register determines the
-- time-out value.
TC : aliased TC_Register;
-- Watchdog feed sequence register. Writing 0xAA followed by 0x55 to
-- this register reloads the Watchdog timer with the value contained in
-- TC.
FEED : aliased FEED_Register;
-- Watchdog timer value register. This 24-bit register reads out the
-- current value of the Watchdog timer.
TV : aliased TV_Register;
-- Watchdog Warning Interrupt compare value.
WARNINT : aliased WARNINT_Register;
-- Watchdog Window compare value.
WINDOW : aliased WINDOW_Register;
end record
with Volatile;
for WWDT_Peripheral use record
MOD_k at 16#0# range 0 .. 31;
TC at 16#4# range 0 .. 31;
FEED at 16#8# range 0 .. 31;
TV at 16#C# range 0 .. 31;
WARNINT at 16#14# range 0 .. 31;
WINDOW at 16#18# range 0 .. 31;
end record;
-- Windowed Watchdog Timer (WWDT)
WWDT_Periph : aliased WWDT_Peripheral
with Import, Address => System'To_Address (16#4000C000#);
end NXP_SVD.WWDT;
|
package body impact.d3.min_max
is
function btClamped (a : in Real; lower_Bound, upper_Bound : in Real) return Real
is
begin
if a < lower_Bound then
return lower_Bound;
elsif upper_Bound < a then
return upper_Bound;
else
return a;
end if;
end btClamped;
procedure btSetMin (a : in out Real; b : in Real)
is
begin
if b < a then
a := b;
end if;
end btSetMin;
procedure btSetMax (a : in out Real; b : in Real)
is
begin
if a < b then
a := b;
end if;
end btSetMax;
procedure btClamp (a : in out Real; lower_Bound, upper_Bound : in Real)
is
begin
if a < lower_Bound then
a := lower_Bound;
elsif upper_Bound < a then
a := upper_Bound;
end if;
end btClamp;
end impact.d3.min_max;
|
-- SPDX-FileCopyrightText: 2021 Max Reznik <reznikmm@gmail.com>
--
-- SPDX-License-Identifier: MIT
-------------------------------------------------------------
package Program.Resolvers.Name_In_Region is
pragma Preelaborate;
procedure Resolve_Name
(Region : Program.Visibility.View;
Name : Program.Elements.Expressions.Expression_Access;
Setter : not null
Program.Cross_Reference_Updaters.Cross_Reference_Updater_Access);
-- Resolve direct Name in a given region (no overloading).
end Program.Resolvers.Name_In_Region;
|
private
package Tokenize.Private_Token_Lists with SPARK_Mode => On is
type Token_List (<>) is tagged private;
function Create (N : Token_Count) return Token_List
with
Pre'Class => Integer(N) < Positive'Last,
Post => Create'Result.Length = 0 and Create'Result.Capacity = N;
function Capacity (Item : Token_List) return Token_Count;
function Length (Item : Token_List) return Token_Count
with Post => Length'Result <= Item.Capacity;
procedure Append (List : in out Token_List;
What : String)
with Pre'Class => List.Length < List.Capacity,
Post => List.Length = List.Length'Old + 1
and List.Capacity = List.Capacity'Old;
function Element (List : Token_List;
N : Token_Count)
return String
with Pre'Class => List.Length >= N;
private
type Token_List (Length : Token_Count) is tagged
record
Tokens : Token_Array (1 .. Length) := (others => Null_Unbounded_String);
First_Free : Token_Count := 1;
end record
with Predicate => First_Free <= Length + 1
and Tokens'Length = Length;
function Create (N : Token_Count) return Token_List
is (Token_List'(Length => N,
Tokens => (others => Null_Unbounded_String),
First_Free => 1));
function Capacity (Item : Token_List) return Token_Count
is (Item.Tokens'Last);
function Length (Item : Token_List) return Token_Count
is (Item.First_Free - 1);
function Element (List : Token_List;
N : Token_Count)
return String
is (To_String (List.Tokens (N)));
end Tokenize.Private_Token_Lists;
|
------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- S Y S T E M . M A C H I N E _ C O D E --
-- --
-- S p e c --
-- --
-- Copyright (C) 1992-2021, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. --
-- --
-- --
-- --
-- --
-- --
-- You should have received a copy of the GNU General Public License and --
-- a copy of the GCC Runtime Library Exception along with this program; --
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
-- <http://www.gnu.org/licenses/>. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
-- This package provides machine code support, both for intrinsic machine
-- operations, and also for machine code statements. See GNAT documentation
-- for full details.
package System.Machine_Code is
pragma No_Elaboration_Code_All;
pragma Pure;
-- All identifiers in this unit are implementation defined
pragma Implementation_Defined;
type Asm_Input_Operand is private;
type Asm_Output_Operand is private;
-- These types are never used directly, they are declared only so that
-- the calls to Asm are type correct according to Ada semantic rules.
No_Input_Operands : constant Asm_Input_Operand;
No_Output_Operands : constant Asm_Output_Operand;
type Asm_Input_Operand_List is
array (Integer range <>) of Asm_Input_Operand;
type Asm_Output_Operand_List is
array (Integer range <>) of Asm_Output_Operand;
type Asm_Insn is private;
-- This type is not used directly. It is declared only so that the
-- aggregates used in code statements are type correct by Ada rules.
procedure Asm (
Template : String;
Outputs : Asm_Output_Operand_List;
Inputs : Asm_Input_Operand_List;
Clobber : String := "";
Volatile : Boolean := False);
procedure Asm (
Template : String;
Outputs : Asm_Output_Operand := No_Output_Operands;
Inputs : Asm_Input_Operand_List;
Clobber : String := "";
Volatile : Boolean := False);
procedure Asm (
Template : String;
Outputs : Asm_Output_Operand_List;
Inputs : Asm_Input_Operand := No_Input_Operands;
Clobber : String := "";
Volatile : Boolean := False);
procedure Asm (
Template : String;
Outputs : Asm_Output_Operand := No_Output_Operands;
Inputs : Asm_Input_Operand := No_Input_Operands;
Clobber : String := "";
Volatile : Boolean := False);
function Asm (
Template : String;
Outputs : Asm_Output_Operand_List;
Inputs : Asm_Input_Operand_List;
Clobber : String := "";
Volatile : Boolean := False) return Asm_Insn;
function Asm (
Template : String;
Outputs : Asm_Output_Operand := No_Output_Operands;
Inputs : Asm_Input_Operand_List;
Clobber : String := "";
Volatile : Boolean := False) return Asm_Insn;
function Asm (
Template : String;
Outputs : Asm_Output_Operand_List;
Inputs : Asm_Input_Operand := No_Input_Operands;
Clobber : String := "";
Volatile : Boolean := False) return Asm_Insn;
function Asm (
Template : String;
Outputs : Asm_Output_Operand := No_Output_Operands;
Inputs : Asm_Input_Operand := No_Input_Operands;
Clobber : String := "";
Volatile : Boolean := False) return Asm_Insn;
pragma Import (Intrinsic, Asm);
private
type Asm_Input_Operand is new Integer;
type Asm_Output_Operand is new Integer;
type Asm_Insn is new Integer;
-- All three of these types are dummy types, to meet the requirements of
-- type consistency. No values of these types are ever referenced.
No_Input_Operands : constant Asm_Input_Operand := 0;
No_Output_Operands : constant Asm_Output_Operand := 0;
end System.Machine_Code;
|
pragma Warnings (Off);
pragma Style_Checks (Off);
-------------------------------------------------------------------------
-- GLOBE_3D - GL - based, real - time, 3D engine
--
-- Copyright (c) Gautier de Montmollin/Rod Kay 2007
-- CH - 8810 Horgen
-- SWITZERLAND
-- Permission granted to use this software, without any warranty,
-- for any purpose, provided this copyright note remains attached
-- and unmodified if sources are distributed further.
-------------------------------------------------------------------------
with GL.Textures, GL.Skins;
package GLOBE_3D.tri_Mesh is
-- triangle mesh Object base class
--
type tri_Mesh is abstract new Visual with
record
null;
end record;
type p_tri_Mesh is access all tri_Mesh'Class;
type p_tri_Mesh_array is array (Positive range <>) of p_tri_Mesh;
type p_tri_Mesh_grid is array (Positive range <>, Positive range <>) of p_tri_Mesh;
procedure set_Vertices (Self : in out tri_Mesh; To : access GL.geometry.GL_vertex_Array) is abstract;
procedure set_Indices (Self : in out tri_Mesh; To : access GL.geometry.vertex_Id_array) is abstract;
procedure Skin_is (o : in out tri_Mesh; Now : in GL.skins.p_Skin) is abstract;
private
procedure dummy;
end GLOBE_3D.tri_Mesh;
|
with Ada.Finalization;
generic
I : Integer;
package Controlled6_Pkg.Iterators is
type Iterator_Type is new Ada.Finalization.Controlled with record
Current : Node_Access_Type;
end record;
function Find return Iterator_Type;
function Current (Iterator : in Iterator_Type) return T;
pragma Inline (Current);
procedure Find_Next (Iterator : in out Iterator_Type);
function Is_Null (Iterator : in Iterator_Type) return Boolean;
end Controlled6_Pkg.Iterators;
|
-----------------------------------------------------------------------
-- ado-connections-mysql -- MySQL Database connections
-- Copyright (C) 2009, 2010, 2011, 2012, 2013, 2015, 2017, 2018, 2019 Stephane Carrez
-- Written by Stephane Carrez (Stephane.Carrez@gmail.com)
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-----------------------------------------------------------------------
with Ada.Task_Identification;
with Ada.Directories;
with Interfaces.C.Strings;
with Util.Log;
with Util.Log.Loggers;
with Util.Properties;
with Util.Processes.Tools;
with ADO.Sessions.Sources;
with ADO.Sessions.Factory;
with ADO.Statements.Mysql;
with ADO.Schemas.Mysql;
with ADO.Parameters;
with ADO.Queries;
with ADO.C;
with Mysql.Lib; use Mysql.Lib;
package body ADO.Connections.Mysql is
use ADO.Statements.Mysql;
use Util.Log;
use Interfaces.C;
pragma Linker_Options (MYSQL_LIB_NAME);
Log : constant Loggers.Logger := Loggers.Create ("ADO.Databases.Mysql");
Driver_Name : aliased constant String := "mysql";
Driver : aliased Mysql_Driver;
-- ------------------------------
-- Get the database driver which manages this connection.
-- ------------------------------
overriding
function Get_Driver (Database : in Database_Connection)
return ADO.Connections.Driver_Access is
pragma Unreferenced (Database);
begin
return Driver'Access;
end Get_Driver;
overriding
function Create_Statement (Database : in Database_Connection;
Table : in ADO.Schemas.Class_Mapping_Access)
return Query_Statement_Access is
begin
return Create_Statement (Database => Database.Server, Table => Table);
end Create_Statement;
overriding
function Create_Statement (Database : in Database_Connection;
Query : in String)
return Query_Statement_Access is
begin
return Create_Statement (Database => Database.Server, Query => Query);
end Create_Statement;
-- ------------------------------
-- Create a delete statement.
-- ------------------------------
overriding
function Create_Statement (Database : in Database_Connection;
Table : in ADO.Schemas.Class_Mapping_Access)
return Delete_Statement_Access is
begin
return Create_Statement (Database => Database.Server, Table => Table);
end Create_Statement;
-- ------------------------------
-- Create an insert statement.
-- ------------------------------
overriding
function Create_Statement (Database : in Database_Connection;
Table : in ADO.Schemas.Class_Mapping_Access)
return Insert_Statement_Access is
begin
return Create_Statement (Database => Database.Server, Table => Table);
end Create_Statement;
-- ------------------------------
-- Create an update statement.
-- ------------------------------
overriding
function Create_Statement (Database : in Database_Connection;
Table : in ADO.Schemas.Class_Mapping_Access)
return Update_Statement_Access is
begin
return Create_Statement (Database => Database.Server, Table => Table);
end Create_Statement;
-- ------------------------------
-- Start a transaction.
-- ------------------------------
overriding
procedure Begin_Transaction (Database : in out Database_Connection) is
begin
if Database.Autocommit then
Database.Execute ("set autocommit=0");
Database.Autocommit := False;
end if;
Database.Execute ("start transaction;");
end Begin_Transaction;
-- ------------------------------
-- Commit the current transaction.
-- ------------------------------
overriding
procedure Commit (Database : in out Database_Connection) is
Result : char;
begin
if Database.Server = null then
Log.Warn ("Commit while the connection is closed");
raise ADO.Sessions.Session_Error with "Database connection is closed";
end if;
Result := mysql_commit (Database.Server);
if Result /= nul then
raise Database_Error with "Cannot commit transaction";
end if;
end Commit;
-- ------------------------------
-- Rollback the current transaction.
-- ------------------------------
overriding
procedure Rollback (Database : in out Database_Connection) is
Result : char;
begin
if Database.Server = null then
Log.Warn ("Rollback while the connection is closed");
raise ADO.Sessions.Session_Error with "Database connection is closed";
end if;
Result := mysql_rollback (Database.Server);
if Result /= nul then
raise Database_Error with "Cannot rollback transaction";
end if;
end Rollback;
-- ------------------------------
-- Load the database schema definition for the current database.
-- ------------------------------
overriding
procedure Load_Schema (Database : in Database_Connection;
Schema : out ADO.Schemas.Schema_Definition) is
begin
ADO.Schemas.Mysql.Load_Schema (Database, Schema);
end Load_Schema;
-- ------------------------------
-- Execute a simple SQL statement
-- ------------------------------
procedure Execute (Database : in out Database_Connection;
SQL : in Query_String) is
SQL_Stat : constant ADO.C.String_Ptr := ADO.C.To_String_Ptr (SQL);
Result : int;
begin
Log.Debug ("Execute SQL: {0}", SQL);
if Database.Server = null then
Log.Warn ("Database connection is not open");
raise ADO.Sessions.Session_Error with "Database connection is closed";
end if;
Result := Mysql_Query (Database.Server, ADO.C.To_C (SQL_Stat));
if Result /= 0 then
declare
Error : constant Strings.chars_ptr := Mysql_Error (Database.Server);
Msg : constant String := Strings.Value (Error);
begin
Log.Error ("Error: {0}", Msg);
raise ADO.Statements.SQL_Error with "SQL error: " & Msg;
end;
end if;
end Execute;
-- ------------------------------
-- Closes the database connection
-- ------------------------------
overriding
procedure Close (Database : in out Database_Connection) is
begin
if Database.Server /= null then
Log.Info ("Closing connection {0}/{1}", Database.Name, Database.Ident);
mysql_close (Database.Server);
Database.Server := null;
end if;
end Close;
-- ------------------------------
-- Releases the mysql connection if it is open
-- ------------------------------
overriding
procedure Finalize (Database : in out Database_Connection) is
begin
Log.Debug ("Release connection {0}/{1}", Database.Name, Database.Ident);
Database.Close;
end Finalize;
-- ------------------------------
-- Initialize the database connection manager.
--
-- mysql://localhost:3306/db
--
-- ------------------------------
procedure Create_Connection (D : in out Mysql_Driver;
Config : in Configuration'Class;
Result : in out Ref.Ref'Class) is
Host : constant ADO.C.String_Ptr := ADO.C.To_String_Ptr (Config.Get_Server);
Name : constant ADO.C.String_Ptr := ADO.C.To_String_Ptr (Config.Get_Database);
Login : constant ADO.C.String_Ptr := ADO.C.To_String_Ptr (Config.Get_Property ("user"));
Password : constant ADO.C.String_Ptr := C.To_String_Ptr (Config.Get_Property ("password"));
Socket : ADO.C.String_Ptr;
Port : unsigned := unsigned (Config.Get_Port);
Flags : constant unsigned_long := 0;
Connection : Mysql_Access;
Socket_Path : constant String := Config.Get_Property ("socket");
Server : Mysql_Access;
begin
if Socket_Path /= "" then
ADO.C.Set_String (Socket, Socket_Path);
end if;
if Port = 0 then
Port := 3306;
end if;
Log.Info ("Task {0} connecting to {1}:{2}",
Ada.Task_Identification.Image (Ada.Task_Identification.Current_Task),
Config.Get_Server, Config.Get_Database);
if Config.Get_Property ("password") = "" then
Log.Debug ("MySQL connection with user={0}", Config.Get_Property ("user"));
else
Log.Debug ("MySQL connection with user={0} password=XXXXXXXX",
Config.Get_Property ("user"));
end if;
Connection := mysql_init (null);
Server := mysql_real_connect (Connection, ADO.C.To_C (Host),
ADO.C.To_C (Login), ADO.C.To_C (Password),
ADO.C.To_C (Name), Port, ADO.C.To_C (Socket), Flags);
if Server = null then
declare
Message : constant String := Strings.Value (Mysql_Error (Connection));
begin
Log.Error ("Cannot connect to '{0}': {1}", Config.Get_Log_URI, Message);
mysql_close (Connection);
raise ADO.Configs.Connection_Error with "Cannot connect to mysql server: " & Message;
end;
end if;
D.Id := D.Id + 1;
declare
Ident : constant String := Util.Strings.Image (D.Id);
Database : constant Database_Connection_Access := new Database_Connection;
procedure Configure (Name : in String;
Item : in Util.Properties.Value);
function Is_Number (Value : in String) return Boolean is
(for all C of Value => C >= '0' and C <= '9');
procedure Configure (Name : in String;
Item : in Util.Properties.Value) is
Value : constant String := Util.Properties.To_String (Item);
begin
if Name = "encoding" then
Database.Execute ("SET NAMES " & Value);
Database.Execute ("SET CHARACTER SET " & Value);
Database.Execute ("SET CHARACTER_SET_SERVER = '" & Value & "'");
Database.Execute ("SET CHARACTER_SET_DATABASE = '" & Value & "'");
elsif Util.Strings.Index (Name, '.') = 0
and Name /= "user" and Name /= "password" and Name /= "socket"
then
if Is_Number (Value) then
Database.Execute ("SET " & Name & "=" & Value);
else
Database.Execute ("SET " & Name & "='" & Value & "'");
end if;
end if;
end Configure;
begin
Database.Ident (1 .. Ident'Length) := Ident;
Database.Server := Server;
Database.Name := To_Unbounded_String (Config.Get_Database);
-- Configure the connection by setting up the MySQL 'SET X=Y' SQL commands.
-- Typical configuration includes:
-- encoding=utf8
-- collation_connection=utf8_general_ci
Config.Iterate (Process => Configure'Access);
Result := Ref.Create (Database.all'Access);
end;
end Create_Connection;
-- ------------------------------
-- Create the database and initialize it with the schema SQL file.
-- The `Admin` parameter describes the database connection with administrator access.
-- The `Config` parameter describes the target database connection.
-- ------------------------------
overriding
procedure Create_Database (D : in out Mysql_Driver;
Admin : in Configs.Configuration'Class;
Config : in Configs.Configuration'Class;
Schema_Path : in String;
Messages : out Util.Strings.Vectors.Vector) is
pragma Unreferenced (D);
-- Create the MySQL tables in the database. The tables are created by launching
-- the external command 'mysql' and using the create-xxx-mysql.sql generated scripts.
procedure Create_Mysql_Tables (Path : in String;
Config : in Configs.Configuration'Class);
-- Create the database identified by the given name.
procedure Create_Database (DB : in ADO.Sessions.Master_Session;
Name : in String);
-- Create the user and grant him access to the database.
procedure Create_User_Grant (DB : in ADO.Sessions.Master_Session;
Name : in String;
User : in String;
Password : in String);
-- ------------------------------
-- Check if the database with the given name exists.
-- ------------------------------
function Has_Database (DB : in ADO.Sessions.Session'Class;
Name : in String) return Boolean is
Stmt : ADO.Statements.Query_Statement;
begin
Stmt := DB.Create_Statement ("SHOW DATABASES");
Stmt.Execute;
while Stmt.Has_Elements loop
declare
D : constant String := Stmt.Get_String (0);
begin
if Name = D then
return True;
end if;
end;
Stmt.Next;
end loop;
return False;
end Has_Database;
-- ------------------------------
-- Check if the database with the given name has some tables.
-- ------------------------------
function Has_Tables (DB : in ADO.Sessions.Session'Class;
Name : in String) return Boolean is
Stmt : ADO.Statements.Query_Statement;
begin
Stmt := DB.Create_Statement ("SHOW TABLES FROM `:name`");
Stmt.Bind_Param ("name", ADO.Parameters.Token (Name));
Stmt.Execute;
return Stmt.Has_Elements;
end Has_Tables;
-- ------------------------------
-- Create the database identified by the given name.
-- ------------------------------
procedure Create_Database (DB : in ADO.Sessions.Master_Session;
Name : in String) is
Stmt : ADO.Statements.Query_Statement;
begin
Log.Info ("Creating database '{0}'", Name);
Stmt := DB.Create_Statement ("CREATE DATABASE `:name`");
Stmt.Bind_Param ("name", ADO.Parameters.Token (Name));
Stmt.Execute;
end Create_Database;
-- ------------------------------
-- Create the user and grant him access to the database.
-- ------------------------------
procedure Create_User_Grant (DB : in ADO.Sessions.Master_Session;
Name : in String;
User : in String;
Password : in String) is
Query : ADO.Queries.Context;
Stmt : ADO.Statements.Query_Statement;
begin
Log.Info ("Granting access for user '{0}' to database '{1}'", User, Name);
if Password'Length > 0 then
Query.Set_SQL ("GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, "
& "CREATE TEMPORARY TABLES, EXECUTE, SHOW VIEW ON "
& "`:name`.* to `:user`@'localhost' IDENTIFIED BY :password");
else
Query.Set_SQL ("GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, "
& "CREATE TEMPORARY TABLES, EXECUTE, SHOW VIEW ON "
& "`:name`.* to `:user`@'localhost'");
end if;
Stmt := DB.Create_Statement (Query);
Stmt.Bind_Param ("name", ADO.Parameters.Token (Name));
Stmt.Bind_Param ("user", ADO.Parameters.Token (User));
if Password'Length > 0 then
Stmt.Bind_Param ("password", Password);
end if;
Stmt.Execute;
Stmt := DB.Create_Statement ("FLUSH PRIVILEGES");
Stmt.Execute;
end Create_User_Grant;
-- ------------------------------
-- Create the MySQL tables in the database. The tables are created by launching
-- the external command 'mysql' and using the create-xxx-mysql.sql generated scripts.
-- ------------------------------
procedure Create_Mysql_Tables (Path : in String;
Config : in Configs.Configuration'Class) is
Database : constant String := Config.Get_Database;
Username : constant String := Config.Get_Property ("user");
Password : constant String := Config.Get_Property ("password");
Status : Integer;
begin
Log.Info ("Creating database tables using schema '{0}'", Path);
if not Ada.Directories.Exists (Path) then
Log.Error ("SQL file '{0}' does not exist.", Path);
Log.Error ("Please, run the following command: dynamo generate db");
return;
end if;
if Password'Length > 0 then
Util.Processes.Tools.Execute ("mysql --user='" & Username & "' --password='"
& Password & "' "
& Database, Path, Messages, Status);
else
Util.Processes.Tools.Execute ("mysql --user='" & Username & "' "
& Database, Path, Messages, Status);
end if;
end Create_Mysql_Tables;
Factory : ADO.Sessions.Factory.Session_Factory;
begin
Log.Info ("Connecting to {0} for database setup", Admin.Get_Log_URI);
-- Initialize the session factory to connect to the
-- database defined by root connection (which should allow the database creation).
Factory.Create (ADO.Sessions.Sources.Data_Source (Admin));
declare
DB : constant ADO.Sessions.Master_Session := Factory.Get_Master_Session;
begin
-- Create the database only if it does not already exists.
if not Has_Database (DB, Config.Get_Database) then
Create_Database (DB, Config.Get_Database);
end if;
-- If some tables exist, don't try to create tables again.
-- We could improve by reading the current database schema, comparing with our
-- schema and create what is missing (new tables, new columns).
if Has_Tables (DB, Config.Get_Database) then
Log.Error ("The database {0} exists", Config.Get_Database);
else
if "" /= Config.Get_Property ("user") then
-- Create the user grant. On MySQL, it is safe to do this several times.
Create_User_Grant (DB, Config.Get_Database,
Config.Get_Property ("user"),
Config.Get_Property ("password"));
end if;
-- And now create the tables by using the SQL script.
Create_Mysql_Tables (Schema_Path, Config);
end if;
end;
end Create_Database;
-- ------------------------------
-- Initialize the Mysql driver.
-- ------------------------------
procedure Initialize is
use type Util.Strings.Name_Access;
begin
Log.Debug ("Initializing mysql driver");
if Driver.Name = null then
Driver.Name := Driver_Name'Access;
Register (Driver'Access);
end if;
end Initialize;
-- ------------------------------
-- Deletes the Mysql driver.
-- ------------------------------
overriding
procedure Finalize (D : in out Mysql_Driver) is
pragma Unreferenced (D);
begin
Log.Debug ("Deleting the mysql driver");
mysql_server_end;
end Finalize;
end ADO.Connections.Mysql;
|
-----------------------------------------------------------------------
-- package body Runge_Coeffs_PD_8, coefficients for Prince-Dormand Runge Kutta
-- Copyright (C) 2008-2018 Jonathan S. Parker.
--
-- Permission to use, copy, modify, and/or distribute this software for any
-- purpose with or without fee is hereby granted, provided that the above
-- copyright notice and this permission notice appear in all copies.
-- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
-- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
-- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
-- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
-- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-------------------------------------------------------------------------------
--
-----------------------------------------------------------------------
with Text_IO; use Text_IO;
package body Runge_Coeffs_PD_8 is
Print_to_Screen_Desired : constant Boolean := False;
-----------------------
-- Test_Runge_Coeffs --
-----------------------
procedure Test_Runge_Coeffs
is
Factors : array(Stages, Stages) of Real := (others => (others => 0.0));
Factorial, Sum, Error, Max_Error : Real := +0.0;
begin
for i in RK_Range loop
for j in RK_Range loop
Error := Abs Real((A_rational(i)(j)) - (A_extended(i)(j)));
if Error > Max_Error then Max_Error := Error; end if;
end loop;
end loop;
if Print_to_Screen_Desired then
new_line(1);
put ("Error in A coeffients: "); put (Real'Image (Max_Error));
end if;
if Max_Error > 1.0e-14 then
put ("Problem with the Runge Kutta Coeffs in Runge_Coeffs_PD_8 (0).");
raise Program_Error;
end if;
for I in Stages loop
Factors(I,Stages'First) := 1.0;
end loop;
-- K(I = 1) = h*F*Y J = 1..0
--
-- K(I = 2) = h*F*(Y + K(1)*A21) J = 1..1
--
-- K(I = 3) = h*F*(Y + K(1)*A31 + K(2)*A32) J = 1..2
--
-- K(I = 4) = h*F*(Y + K(1)*A41 + K(2)*A42 + K(3)*A43) J = 1..3
for I in stages range 1..Stages'Last loop
for J in Stages range Stages'First..I-1 loop
for Order in Stages range Stages'First+1..J+1 loop
Factors(I,Order) := Factors(I,Order) + A(I)(J)*Factors(J,Order-1);
end loop;
end loop;
end loop;
-- Now should have SUM(B(i) * Factors(i,n)) = 1/n! up to the order of the
-- the Taylors series.
for Order in Stages range 1..8 loop
Sum := 0.0;
for I in Stages loop
Sum := Sum + B8(I) * Factors (I, Order-1);
end loop;
-- Calculate 1.0 / Order! to get
Factorial := 1.0;
for N in Stages range 2..Order loop
Factorial := Factorial * Real(N);
end loop;
Factorial := 1.0 / Factorial;
if Print_to_Screen_Desired then
new_line(2);
put (" "); put (Real'Image (Sum));
new_line;
put ("Should be: "); put (Real'Image (Factorial));
new_line;
end if;
Error := Abs (Sum - Factorial);
if Error > 1.0e-14 then
put ("Problem with the Runge Kutta Coeffs in Runge_Coeffs_PD_8 (1).");
raise Program_Error;
end if;
end loop;
for Order in Stages range 1..7 loop
Sum := 0.0;
for I in Stages loop
Sum := Sum + B7(I) * Factors (I, Order-1);
end loop;
-- Calculate 1.0 / Order! to get
Factorial := 1.0;
for N in Stages range 2..Order loop
Factorial := Factorial * Real(N);
end loop;
Factorial := 1.0 / Factorial;
if Print_to_Screen_Desired then
new_line(2);
put (" "); put (Real'Image (Sum));
new_line;
put ("Should be: "); put (Real'Image (Factorial));
new_line;
end if;
Error := Abs (Sum - Factorial);
if Error > 1.0e-14 then
put ("Problem with the Runge Kutta Coeffs in Runge_Coeffs_PD_8 (2).");
raise Program_Error;
end if;
end loop;
end Test_Runge_Coeffs;
end Runge_Coeffs_PD_8;
|
-- Copyright (c) 2021 Bartek thindil Jasicki <thindil@laeran.pl>
--
-- 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 Tcl.Strings; use Tcl.Strings;
with Tk.Widget; use Tk.Widget;
with Tk.TtkWidget; use Tk.TtkWidget;
-- ****h* Tk/TtkEntry
-- FUNCTION
-- Provides code for manipulate Tk widget ttk::entry
-- SOURCE
package Tk.TtkEntry is
-- ****
--## rule off REDUCEABLE_SCOPE
-- ****t* TtkEntry/TtkEntry.Ttk_Entry
-- FUNCTION
-- The Tk identifier of the ttk::entry
-- HISTORY
-- 8.6.0 - Added
-- SOURCE
subtype Ttk_Entry is Ttk_Widget;
-- ****
-- ****t* TtkEntry/TtkEntry.Entry_State_Type
-- FUNCTION
-- Available states of Ttk_Entry widget
-- OPTIONS
-- NONE - Used mostly when setting default state for widget
-- NORMAL - The normal state of widget, can be edited
-- DISABLED - The widget can't be edited and text can't be selected
-- READONLY - The widget can't be edited but text can be selected
-- HISTORY
-- 8.6.0 - Added
-- SOURCE
type Entry_State_Type is (NONE, NORMAL, DISABLED, READONLY) with
Default_Value => NONE;
-- ****
-- ****d* TtkEntry/TtkEntry.Default_Entry_State
-- FUNCTION
-- The default state of the Ttk_Entry widget
-- HISTORY
-- 8.6.0 - Added
-- SOURCE
Default_Entry_State: constant Entry_State_Type := NORMAL;
-- ****
-- ****t* TtkEntry/TtkEntry.Validate_Type
-- FUNCTION
-- Available types of Ttk_Entry widget text validation
-- OPTIONS
-- EMPTY - Used mostly when setting default validation state for
-- widget
-- NONE - No validation of text
-- FOCUS - Validate text when Ttk_Widget receive or loss focus
-- FOCUSIN - Validate text when Ttk_Widget receive focus
-- FOCUSOUT - Validate text when Ttk_Widget loss focus
-- KEY - Validate text before insert or delete it
-- VALIDATEALL - Validate text for all above conditions
-- HISTORY
-- 8.6.0 - Added
-- SOURCE
type Validate_Type is
(EMPTY, NONE, FOCUS, FOCUSIN, FOCUSOUT, KEY, VALIDATEALL) with
Default_Value => EMPTY;
-- ****
-- ****d* TtkEntry/TtkEntry.Default_Validate
-- FUNCTION
-- The default validation condition for Ttk_Entry widget
-- HISTORY
-- 8.6.0 - Added
-- SOURCE
Default_Validate: constant Validate_Type := EMPTY;
-- ****
-- ****s* TtkEntry/TtkEntry.Ttk_Entry_Options
-- FUNCTION
-- Data structure for all available options for the Tk Ttk_Entry
-- OPTIONS
-- X_Scroll_Command - Tcl command used to communicate with the horizontal
-- scrollbars. When the view of the Ttk_Entry changes, it
-- will execute that command with two parameters. The
-- first is fraction between 1 and 0 for the first
-- visible position in the entry, the second, also
-- fraction between 1 and 0 is the last visible position
-- in the entry.
-- Export_Selection - If true, synchronize selection in Ttk_Entry with the
-- system selection (deselect other windows selections, etc.)
-- Invalid_Command - Tcl command which will be executed when the content of
-- Ttk_Entry is invalid
-- Justify - Specifies how the text in Ttk_Entry should be justified
-- Show - If True, show the content of the Ttk_Entry. If false,
-- show the content as bullet or "*".
-- State - The state of the Ttk_Entry
-- Text_Variable - The name of the Tcl variable which contains the content
-- of the Ttk_Entry. When its value change, the content
-- will be changed too and vice versa.
-- Validation - Set the validation mode for the Ttk_Entry
-- Validate_Command - Tcl command which will be executed to validate the
-- content of the Ttk_Entry. That command must return 1
-- for valid content and 0 for invalid.
-- Width - The width of Ttk_Entry in characters
-- HISTORY
-- 8.6.0 - Added
-- SOURCE
type Ttk_Entry_Options is new Ttk_Widget_Options with record
X_Scroll_Command: Tcl_String := Null_Tcl_String;
Export_Selection: Extended_Boolean := NONE;
Invalid_Command: Tcl_String := Null_Tcl_String;
Justify: Justify_Type := NONE;
Show: Extended_Boolean := NONE;
State: Entry_State_Type := NONE;
Text_Variable: Tcl_String := Null_Tcl_String;
Validation: Validate_Type := EMPTY;
Validate_Command: Tcl_String := Null_Tcl_String;
Width: Natural := 0;
end record;
-- ****
-- ****t* TtkEntry/TtkEntry.Entry_Index_Type
-- FUNCTION
-- Available types of Ttk_Entry indices
-- OPTIONS
-- LASTCHARACTER - The position just after the last character in Ttk_Entry
-- INSERT - The current position of the insert cursor in Ttk_Entry
-- SELECTIONFIRST - The first character in the selection in Ttk_Entry
-- SELECTIONLAST - The last character in the selection in Ttk_Entry
-- NONE - Used mostly when setting empty position in Ttk_Entry
-- HISTORY
-- 8.6.0 - Added
-- SOURCE
type Entry_Index_Type is
(LASTCHARACTER, INSERT, SELECTIONFIRST, SELECTIONLAST, NONE) with
Default_Value => NONE;
-- ****
-- ****d* TtkEntry/TtkEntry.Default_Entry_Index
-- FUNCTION
-- The default type of Ttk_Entry indice
-- HISTORY
-- 8.6.0 - Added
-- SOURCE
Default_Entry_Index: constant Entry_Index_Type := NONE;
-- ****
-- ****t* TtkEntry/TtkEntry.Fraction_Type
-- FUNCTION
-- Type used to get or set visible fraction of Ttk_Entry. Value 0 means the
-- start of the Ttk_Entry on the left, 1.0 end of the Ttk_Entry on the
-- right.
-- HISTORY
-- 8.6.0 - Added
-- SOURCE
type Fraction_Type is digits 2 range 0.0 .. 1.0 with
Default_Value => 0.0;
-- ****
-- ****d* TtkEntry/TtkEntry.Default_Fraction
-- FUNCTION
-- Default fraciton value for Ttk_Entry (left side of the widget)
-- HISTORY
-- 8.6.0 - Added
-- SOURCE
Default_Fraction: constant Fraction_Type := 0.0;
-- ****
-- ****t* TtkEntry/TtkEntry.Scroll_Unit_Type
-- FUNCTION
-- Types of unit used in setting scrolling position
-- OPTIONS
-- UNITS - The value used to scroll is in characters
-- PAGES - The value used to scroll is in screens
-- HISTORY
-- 8.6.0 - Added
-- SOURCE
type Scroll_Unit_Type is (UNITS, PAGES) with
Default_Value => UNITS;
-- ****
-- ****d* TtkEntry/TtkEntry.Default_Scroll_Unit
-- FUNCTION
-- Default type of unit used in setting scrolling position
-- HISTORY
-- 8.6.0 - Added
-- SOURCE
Default_Scroll_Unit: constant Scroll_Unit_Type := UNITS;
-- ****
-- ****t* TtkEntry/TtkEntry.Fractions_Array
-- FUNCTION
-- Used to get the current view fraction of the Ttk_Entry. The first value
-- is the fraction of the first visible element in the widget. The second
-- value is the fraction of the last visible element in the widget.
-- HISTORY
-- 8.6.0 - Added
-- SOURCE
type Fractions_Array is array(1 .. 2) of Fraction_Type with
Default_Component_Value => Default_Fraction;
-- ****
-- ****d* TtkEntry/TtkEntry.Default_Fractions_Array
-- FUNCTION
-- The default or empty array of fractions
-- HISTORY
-- 8.6.0 - Added
-- SOURCE
Default_Fractions_Array: constant Fractions_Array := (others => <>);
-- ****
-- ****f* TtkEntry/TtkEntry.Create_(function)
-- FUNCTION
-- Create a new Tk ttk::entry widget with the selected pathname and options
-- PARAMETERS
-- Path_Name - Tk pathname for the newly created entry
-- Options - Options for the newly created entry
-- Interpreter - Tcl interpreter on which the entry will be created. Can
-- be empty. Default value is the default Tcl interpreter
-- RESULT
-- The Tk identifier of the newly created entry widget
-- HISTORY
-- 8.6.0 - Added
-- EXAMPLE
-- -- Create the entry with pathname .myentry, with width 15 characters
-- My_Entry: constant Ttk_Entry := Create(".myentry", (Width => 15, others => <>));
-- SEE ALSO
-- TtkEntry.Create_(procedure)
-- COMMANDS
-- ttk::entry Path_Name Options
-- SOURCE
function Create
(Path_Name: Tk_Path_String; Options: Ttk_Entry_Options;
Interpreter: Tcl_Interpreter := Get_Interpreter) return Ttk_Entry with
Pre'Class => Path_Name'Length > 0 and Interpreter /= Null_Interpreter,
Test_Case => (Name => "Test_Create_TtkEntry1", Mode => Nominal);
-- ****
-- ****f* TtkEntry/TtkEntry.Create_(procedure)
-- FUNCTION
-- Create a new Tk ttk::entry widget with the selected pathname and options
-- PARAMETERS
-- Entry_Widget - Ttk_Entry identifier which will be returned
-- Path_Name - Tk pathname for the newly created entry
-- Options - Options for the newly created entry
-- Interpreter - Tcl interpreter on which the entry will be created. Can
-- be empty. Default value is the default Tcl interpreter
-- OUTPUT
-- The Entry_Widget parameter as Tk identifier of the newly created entry widget
-- HISTORY
-- 8.6.0 - Added
-- EXAMPLE
-- -- Create the entry with pathname .myentry, disabled by default
-- declare
-- My_Entry: Ttk_Entry;
-- begin
-- Create(My_Entry, ".myentry", (State => DISABLED, others => <>));
-- end;
-- SEE ALSO
-- TtkEntry.Create_(function)
-- COMMANDS
-- ttk::entry Path_Name Options
-- SOURCE
procedure Create
(Entry_Widget: out Ttk_Entry; Path_Name: Tk_Path_String;
Options: Ttk_Entry_Options;
Interpreter: Tcl_Interpreter := Get_Interpreter) with
Pre'Class => Path_Name'Length > 0 and Interpreter /= Null_Interpreter,
Test_Case => (Name => "Test_Create_TtkEntry2", Mode => Nominal);
-- ****
-- ****f* TtkEntry/TtkEntry.Get_Options
-- FUNCTION
-- Get all values of Tk options of the selected entry
-- PARAMETERS
-- Entry_Widget - Ttk_Entry which options' values will be taken
-- RESULT
-- Ttk_Entry_Options record with values of the selected entry options
-- HISTORY
-- 8.6.0 - Added
-- EXAMPLE
-- -- Get all values of option of Ttk_Entry with pathname .myentry
-- My_Entry_Options: constant Ttk_Entry_Options := Get_Options(Get_Widget(".myentry"));
-- SEE ALSO
-- TtkEntry.Configure
-- COMMANDS
-- Entry_Widget configure
-- SOURCE
function Get_Options(Entry_Widget: Ttk_Entry) return Ttk_Entry_Options with
Pre'Class => Entry_Widget /= Null_Widget,
Test_Case => (Name => "Test_Get_Options_TtkEntry", Mode => Nominal);
-- ****
-- ****f* TtkEntry/TtkEntry.Configure
-- FUNCTION
-- Set the selected options for the selected Ttk_Entry
-- PARAMETERS
-- Entry_Widget - Ttk_Entry which options will be set
-- Options - The record with new values for the entry options
-- HISTORY
-- 8.6.0 - Added
-- EXAMPLE
-- -- Disable entry with pathname .myentry
-- Configure(Get_Widget(".myentry"), (State => DISABLED, others => <>));
-- SEE ALSO
-- TtkEntry.Get_Options
-- COMMANDS
-- Entry_Widget configure Options
-- SOURCE
procedure Configure
(Entry_Widget: Ttk_Entry; Options: Ttk_Entry_Options) with
Pre'Class => Entry_Widget /= Null_Widget,
Test_Case => (Name => "Test_Configure_TtkEntry", Mode => Nominal);
-- ****
-- ****d* TtkEntry/TtkEntry.Default_Ttk_Entry_Options
-- FUNCTION
-- The default options for the Ttk_Entry
-- HISTORY
-- 8.6.0 - Added
-- SOURCE
Default_Ttk_Entry_Options: constant Ttk_Entry_Options :=
Ttk_Entry_Options'(others => <>);
-- ****
-- ****f* TtkEntry/TtkEntry.Get_Bounding_Box_(numeric_index)
-- FUNCTION
-- Get the bouding box for the character in Ttk_Entry with the selected
-- numerical index
-- PARAMETERS
-- Entry_Widget - The Ttk_Entry widget which bouding box will be get
-- Index - The index or X coordinate of the character in
-- Entry_Widget.
-- Is_Index - If True, Index is numerical index of the character. If
-- False, Index is X coordinate of the character. Can be
-- empty. Default value is True.
-- RESULT
-- BBox_Data with 4 values. The first two are staring point (x, y) of
-- the bounding box, the third is width and the fourth is height of the
-- bounding box.
-- HISTORY
-- 8.6.0 - Added
-- EXAMPLE
-- -- Get the bouding box of the second character in Ttk_Entry My_Entry widget
-- Bounding_Box: constant BBox_Data := Get_Bounding_Box(My_Entry, 1);
-- SEE ALSO
-- TtkEntry.Get_Bounding_Box_(entry_index_type)
-- COMMANDS
-- Entry_Widget bbox Index
-- SOURCE
function Get_Bounding_Box
(Entry_Widget: Ttk_Entry; Index: Natural; Is_Index: Boolean := True)
return Bbox_Data with
Pre => Entry_Widget /= Null_Widget,
Test_Case => (Name => "Test_Bounding_Box", Mode => Nominal);
-- ****
-- ****f* TtkEntry/TtkEntry.Get_Bounding_Box_(entry_index_type)
-- FUNCTION
-- Get the bouding box for the character in Ttk_Entry with the selected
-- Entry_Index_Type index
-- PARAMETERS
-- Entry_Widget - The Ttk_Entry widget which bouding box will be get
-- Index - The index of the character in Entry_Widget.
-- RESULT
-- BBox_Data with 4 values. The first two are staring point (x, y) of
-- the bounding box, the third is width and the fourth is height of the
-- bounding box.
-- HISTORY
-- 8.6.0 - Added
-- EXAMPLE
-- -- Get the bouding box of the last character in Ttk_Entry My_Entry widget
-- Bounding_Box: constant BBox_Data := Get_Bounding_Box(My_Entry, LASTCHARACTER);
-- SEE ALSO
-- TtkEntry.Get_Bounding_Box_(numerical_index)
-- COMMANDS
-- Entry_Widget bbox Index
-- SOURCE
function Get_Bounding_Box
(Entry_Widget: Ttk_Entry; Index: Entry_Index_Type) return Bbox_Data with
Pre => Entry_Widget /= Null_Widget,
Test_Case => (Name => "Test_Bounding_Box2", Mode => Nominal);
-- ****
-- ****f* TtkEntry/TtkEntry.Delete_(natural_indexes)
-- FUNCTION
-- Delete one or more elements from the Ttk_Entry
-- PARAMETERS
-- Entry_Widget - The Ttk_Entry widget in which the characters will be
-- deleted
-- First - The index or X coordinate of the first character to
-- delete
-- Last - The index or X coordinate after the last character
-- to delete. Can be empty. Default value is 0.
-- Is_First_Index - If True, the First index is numerical index, otherwise
-- it is X coordinate. Can be empty. Default value is
-- True.
-- Is_Last_Index - If True, the Last index is numerical index, otherwise
-- it is X coordinate. Can be empty. Default value is
-- True. Means nothing if Last is equal to 0.
-- HISTORY
-- 8.6.0 - Added
-- EXAMPLE
-- -- Delete the first character in Ttk_Entry My_Entry
-- Delete(My_Entry, 0);
-- SEE ALSO
-- TtkEntry.Delete_(entry_index_type),
-- TtkEntry.Delete_(numerical_entry_index_type),
-- TtkEntry.Delete_(entry_index_type_numerical)
-- COMMANDS
-- Entry_Widget delete First ?Last?
-- SOURCE
procedure Delete
(Entry_Widget: Ttk_Entry; First: Natural; Last: Natural := 0;
Is_First_Index, Is_Last_Index: Boolean := True) with
Pre => Entry_Widget /= Null_Widget,
Test_Case => (Name => "Test_Delete", Mode => Nominal);
-- ****
-- ****f* TtkEntry/TtkEntry.Delete_(entry_index_type)
-- FUNCTION
-- Delete one or more elements from the Ttk_Entry
-- PARAMETERS
-- Entry_Widget - The Ttk_Entry widget in which the characters will be
-- deleted
-- First - The index of the first character to delete
-- Last - The index after the last character to delete. Can be
-- empty. Default value is NONE.
-- HISTORY
-- 8.6.0 - Added
-- EXAMPLE
-- -- Delete the last character in Ttk_Entry My_Entry
-- Delete(My_Entry, LASTCHARACTER);
-- SEE ALSO
-- TtkEntry.Delete_(numerical_indexes),
-- TtkEntry.Delete_(numerical_entry_index_type),
-- TtkEntry.Delete_(entry_index_type_numerical)
-- COMMANDS
-- Entry_Widget delete First ?Last?
-- SOURCE
procedure Delete
(Entry_Widget: Ttk_Entry; First: Entry_Index_Type;
Last: Entry_Index_Type := NONE) with
Pre => Entry_Widget /= Null_Widget,
Test_Case => (Name => "Test_Delete2", Mode => Nominal);
-- ****
-- ****f* TtkEntry/TtkEntry.Delete_(numerical_entry_index_type)
-- FUNCTION
-- Delete one or more elements from the Ttk_Entry
-- PARAMETERS
-- Entry_Widget - The Ttk_Entry widget in which the characters will be
-- deleted
-- First - The index or X coordinate of the first character to
-- delete
-- Last - The index after the last character to delete. Can be
-- empty. Default value is NONE.
-- Is_First_Index - If True, the First index is numerical index, otherwise
-- it is X coordinate. Can be empty. Default value is
-- True.
-- HISTORY
-- 8.6.0 - Added
-- EXAMPLE
-- -- Delete the whole content of the Ttk_Entry My_Entry
-- Delete(My_Entry, 0, LASTCHARACTER);
-- SEE ALSO
-- TtkEntry.Delete_(numerical_indexes),
-- TtkEntry.Delete_(entry_index_type),
-- TtkEntry.Delete_(entry_index_type_numerical)
-- COMMANDS
-- Entry_Widget delete First ?Last?
-- SOURCE
procedure Delete
(Entry_Widget: Ttk_Entry; First: Natural; Last: Entry_Index_Type := NONE;
Is_First_Index: Boolean := True) with
Pre => Entry_Widget /= Null_Widget,
Test_Case => (Name => "Test_Delete3", Mode => Nominal);
-- ****
-- ****f* TtkEntry/TtkEntry.Delete_(entry_index_type_numerical)
-- FUNCTION
-- Delete one or more elements from the Ttk_Entry
-- PARAMETERS
-- Entry_Widget - The Ttk_Entry widget in which the characters will be
-- deleted
-- First - The index of the first character to delete
-- Last - The index or X coordinate after the last character
-- to delete. Can be empty. Default value is 0.
-- Is_Last_Index - If True, the Last index is numerical index, otherwise
-- it is X coordinate. Can be empty. Default value is
-- True. Means nothing if Last is equal to 0.
-- HISTORY
-- 8.6.0 - Added
-- EXAMPLE
-- -- Delete the last selected character in Ttk_Entry My_Entry
-- Delete(My_Entry, SELECTIONLAST);
-- SEE ALSO
-- TtkEntry.Delete_(numerical_indexes),
-- TtkEntry.Delete_(entry_index_type),
-- TtkEntry.Delete_(numerical_entry_index_type),
-- COMMANDS
-- Entry_Widget delete First ?Last?
-- SOURCE
procedure Delete
(Entry_Widget: Ttk_Entry; First: Entry_Index_Type; Last: Natural := 0;
Is_Last_Index: Boolean := True) with
Pre => Entry_Widget /= Null_Widget,
Test_Case => (Name => "Test_Delete4", Mode => Nominal);
-- ****
-- ****f* TtkEntry/TtkEntry.Get_Text
-- FUNCTION
-- Get the content of the selected Ttk_Entry
-- PARAMETERS
-- Entry_Widget - Ttk_Entry which content will be get
-- RESULT
-- String with the content of the selected Entry_Widget
-- HISTORY
-- 8.6.0 - Added
-- EXAMPLE
-- -- Get the content of Ttk_Entry My_Entry
-- My_Text: constant String := Get_Text(My_Entry);
-- COMMANDS
-- Entry_Widget get
-- SOURCE
function Get_Text(Entry_Widget: Ttk_Entry) return String with
Pre => Entry_Widget /= Null_Widget,
Test_Case => (Name => "Test_Get_Text", Mode => Nominal);
-- ****
-- ****f* TtkEntry/TtkEntry.Set_Insert_Cursor_(numerical_index)
-- FUNCTION
-- Set the insertion cursor to the selected position in the selected
-- Ttk_Entry
-- PARAMETERS
-- Entry_Widget - Ttk_Entry in which the insertion cursor will be set
-- Index - The index or X coordinate of the character on which
-- the insertion cursor will be set
-- Is_Index - If True, Index is numerical index of the character. If
-- False, Index is X coordinate of the character. Can be
-- empty. Default value is True.
-- HISTORY
-- 8.6.0 - Added
-- EXAMPLE
-- -- Set the insertion cursor at the beginning of Ttk_Entry My_Entry
-- Set_Insert_Cursor(My_Entry, 0);
-- SEE ALSO
-- TtkEntry.Set_Insert_Cursor_(entry_index_type)
-- COMMANDS
-- Entry_Widget icursor Index
-- SOURCE
procedure Set_Insert_Cursor
(Entry_Widget: Ttk_Entry; Index: Natural; Is_Index: Boolean := True) with
Pre => Entry_Widget /= Null_Widget,
Test_Case => (Name => "Test_Set_Insert_Cursor", Mode => Nominal);
-- ****
-- ****f* TtkEntry/TtkEntry.Set_Insert_Cursor_(entry_index_type)
-- FUNCTION
-- Set the insertion cursor to the selected position in the selected
-- Ttk_Entry
-- PARAMETERS
-- Entry_Widget - Ttk_Entry in which the insertion cursor will be set
-- Index - The index of the character on which the insertion
-- cursor will be set
-- HISTORY
-- 8.6.0 - Added
-- EXAMPLE
-- -- Set the insertion cursor at the end of Ttk_Entry My_Entry
-- Set_Insert_Cursor(My_Entry, LASTCHARACTER);
-- SEE ALSO
-- TtkEntry.Set_Insert_Cursor_(numerical_index)
-- COMMANDS
-- Entry_Widget icursor Index
-- SOURCE
procedure Set_Insert_Cursor
(Entry_Widget: Ttk_Entry; Index: Entry_Index_Type) with
Pre => Entry_Widget /= Null_Widget,
Test_Case => (Name => "Test_Set_Insert_Cursor2", Mode => Nominal);
-- ****
-- ****f* TtkEntry/TtkEntry.Get_Index_(x_coordinate)
-- FUNCTION
-- Get the numerical index of the character in Ttk_Entry at the selected
-- X coordinate
-- PARAMETERS
-- Entry_Widget - Ttk_Entry in which the index will be get
-- X - The X coordinate at which the index will be get
-- RESULT
-- The numerical index of the character at the selected X position in
-- Entry_Widget
-- HISTORY
-- 8.6.0 - Added
-- EXAMPLE
-- -- Get the numerical index at start of My_Entry Ttk_Entry widget
-- Index: constant Natural := Get_Index(My_Entry, 0);
-- SEE ALSO
-- TtkEntry.Get_Index_(entry_index_type)
-- COMAMNDS
-- Entry_Widget index X
-- SOURCE
function Get_Index(Entry_Widget: Ttk_Entry; X: Natural) return Natural with
Pre => Entry_Widget /= Null_Widget,
Test_Case => (Name => "Test_Get_Index", Mode => Nominal);
-- ****
-- ****f* TtkEntry/TtkEntry.Get_Index_(entry_index_type)
-- FUNCTION
-- Get the numerical index of the character in Ttk_Entry at the selected
-- Entry_Index_Type index
-- PARAMETERS
-- Entry_Widget - Ttk_Entry in which the index will be get
-- Index - The Entry_Index_Type index at which the index will be get
-- RESULT
-- The numerical index of the character at the selected Index in Entry_Widget
-- HISTORY
-- 8.6.0 - Added
-- EXAMPLE
-- -- Get the numerical index at end of My_Entry Ttk_Entry widget
-- Index: constant Natural := Get_Index(My_Entry, LASTCHARACTER);
-- SEE ALSO
-- TtkEntry.Get_Index_(x_coordinate)
-- COMAMNDS
-- Entry_Widget index Index
-- SOURCE
function Get_Index
(Entry_Widget: Ttk_Entry; Index: Entry_Index_Type) return Natural with
Pre => Entry_Widget /= Null_Widget,
Test_Case => (Name => "Test_Get_Index2", Mode => Nominal);
-- ****
-- ****f* TtkEntry/TtkEntry.Insert_Text_(numerical_index)
-- FUNCTION
-- Insert the text at the selected position into the selected Ttk_Entry
-- PARAMETERS
-- Entry_Widget - The Ttk_Entry in which the text will be inserted
-- Index - The index or X coordinate of the character on which
-- the text will be inserted
-- Text - The text to insert to the Ttk_Entry
-- Is_Index - If True, Index is numerical index of the character. If
-- False, Index is X coordinate of the character. Can be
-- empty. Default value is True.
-- HISTORY
-- 8.6.0 - Added
-- EXAMPLE
-- -- Insert text my text at the start of My_Entry widget
-- Insert_Text(My_Entry, 0, To_Tcl_String("my text"));
-- SEE ALSO
-- TtkEntry.Insert_Text_(entry_index_type)
-- COMMANDS
-- Entry_Widget insert Index Text
-- SOURCE
procedure Insert_Text
(Entry_Widget: Ttk_Entry; Index: Natural; Text: Tcl_String;
Is_Index: Boolean := True) with
Pre => Entry_Widget /= Null_Widget and Length(Source => Text) > 0,
Test_Case => (Name => "Test_Insert_Text", Mode => Nominal);
-- ****
-- ****f* TtkEntry/TtkEntry.Insert_Text_(entry_index_type)
-- FUNCTION
-- Insert the text at the selected position into the selected Ttk_Entry
-- PARAMETERS
-- Entry_Widget - The Ttk_Entry in which the text will be inserted
-- Index - The index of the character in Entry_Widget at which the
-- text will be inserted
-- Text - The text to insert to the Ttk_Entry
-- HISTORY
-- 8.6.0 - Added
-- EXAMPLE
-- -- Insert text my text at the end of My_Entry widget
-- Insert_Text(My_Entry, LASTCHARACTER, To_Tcl_String("my text"));
-- SEE ALSO
-- TtkEntry.Insert_Text_(numerical_index)
-- COMMANDS
-- Entry_Widget insert Index Text
-- SOURCE
procedure Insert_Text
(Entry_Widget: Ttk_Entry; Index: Entry_Index_Type; Text: Tcl_String) with
Pre => Entry_Widget /= Null_Widget and Length(Source => Text) > 0,
Test_Case => (Name => "Test_Insert_Text", Mode => Nominal);
-- ****
-- ****f* TtkEntry/TtkEntry.Selection_Clear
-- FUNCTION
-- Clear the selection in the selected Ttk_Entry
-- PARAMETERS
-- Entry_Widget - The Ttk_Entry which selection will be cleared
-- HISTORY
-- 8.6.0 - Added
-- EXAMPLE
-- -- Clear the selection in My_Entry widget
-- Selection_Clear(My_Entry);
-- COMMANDS
-- Entry_Widget selection clear
-- SOURCE
procedure Selection_Clear(Entry_Widget: Ttk_Entry) with
Pre => Entry_Widget /= Null_Widget,
Test_Case => (Name => "Test_Selection_Clear", Mode => Nominal);
-- ****
-- ****f* TtkEntry/TtkEntry.Selection_Present
-- FUNCTION
-- Check if the selection is set in the selected Ttk_Entry
-- PARAMETERS
-- Entry_Widget - The Ttk_Entry which will be check for a selection
-- RESULT
-- True if there is a character selected in the Entry_Widget, otherwise
-- False
-- HISTORY
-- 8.6.0 - Added
-- EXAMPLE
-- -- Check if selection exists in widget My_Entry
-- Has_Selection: constant Boolean := Selection_Present(My_Entry);
-- COMMANDS
-- Entry_Widget selection present
-- SOURCE
function Selection_Present(Entry_Widget: Ttk_Entry) return Boolean with
Pre => Entry_Widget /= Null_Widget,
Test_Case => (Name => "Test_Selection_Present", Mode => Nominal);
-- ****
-- ****f* TtkEntry/TtkEntry.Selection_Range_(numeric_indexes)
-- FUNCTION
-- Set the selection in the selected Ttk_Entry
-- PARAMETERS
-- Entry_Widget - The Ttk_Entry in which the selection will be set
-- Start_Index - The index or X coordinate of the first character in
-- the selection
-- End_Index - The index or X coordinate of the last character in
-- the selection
-- Is_Start_Index - If True, the Start_Index index is numerical index,
-- otherwise it is X coordinate. Can be empty. Default
-- value is True.
-- Is_End_Index - If True, the End_Index index is numerical index,
-- otherwise it is X coordinate. Can be empty. Default
-- value is True.
-- HISTORY
-- 8.6.0 - Added
-- EXAMPLE
-- -- Set the selection in My_Entry widget to the first two characters
-- Selection_Range(My_Entry, 0, 1);
-- SEE ALSO
-- TtkEntry.Selection_Range_(entry_index_type),
-- TtkEntry.Selection_Range_(numerical_entry_index_type),
-- TtkEntry.Selection_Range_(entry_index_type_numerical)
-- COMMANDS
-- Entry_Widget selection range Start_Index End_Index
-- SOURCE
procedure Selection_Range
(Entry_Widget: Ttk_Entry; Start_Index, End_Index: Natural;
Is_Start_Index, Is_End_Index: Boolean := True) with
Pre => Entry_Widget /= Null_Widget,
Test_Case => (Name => "Test_Selection_Range", Mode => Nominal);
-- ****
-- ****f* TtkEntry/TtkEntry.Selection_Range_(entry_index_type)
-- FUNCTION
-- Set the selection in the selected Ttk_Entry
-- PARAMETERS
-- Entry_Widget - The Ttk_Entry in which the selection will be set
-- Start_Index - The index of the first character in the selection
-- End_Index - The index of the last character in the selection
-- HISTORY
-- 8.6.0 - Added
-- EXAMPLE
-- -- Set the selection in My_Entry widget from the insertion cursor to the end
-- Selection_Range(My_Entry, INSERT, LASTCHARACTER);
-- SEE ALSO
-- TtkEntry.Selection_Range_(numerical_indexes),
-- TtkEntry.Selection_Range_(numerical_entry_index_type),
-- TtkEntry.Selection_Range_(entry_index_type_numerical)
-- COMMANDS
-- Entry_Widget selection range Start_Index End_Index
-- SOURCE
procedure Selection_Range
(Entry_Widget: Ttk_Entry; Start_Index, End_Index: Entry_Index_Type) with
Pre => Entry_Widget /= Null_Widget,
Test_Case => (Name => "Test_Selection_Range2", Mode => Nominal);
-- ****
-- ****f* TtkEntry/TtkEntry.Selection_Range_(numerical_entry_index_type)
-- FUNCTION
-- Set the selection in the selected Ttk_Entry
-- PARAMETERS
-- Entry_Widget - The Ttk_Entry in which the selection will be set
-- Start_Index - The index or X coordinate of the first character in
-- the selection
-- End_Index - The index of the last character in the selection
-- Is_Start_Index - If True, the Start_Index index is numerical index,
-- otherwise it is X coordinate. Can be empty. Default
-- value is True.
-- HISTORY
-- 8.6.0 - Added
-- EXAMPLE
-- -- Set the selection in My_Entry widget to the all characters
-- Selection_Range(My_Entry, 0, LASTCHARACTER);
-- SEE ALSO
-- TtkEntry.Selection_Range_(numerical_indexes),
-- TtkEntry.Selection_Range_(entry_index_type),
-- TtkEntry.Selection_Range_(entry_index_type_numerical)
-- COMMANDS
-- Entry_Widget selection range Start_Index End_Index
-- SOURCE
procedure Selection_Range
(Entry_Widget: Ttk_Entry; Start_Index: Natural;
End_Index: Entry_Index_Type; Is_Start_Index: Boolean := True) with
Pre => Entry_Widget /= Null_Widget,
Test_Case => (Name => "Test_Selection_Range3", Mode => Nominal);
-- ****
-- ****f* TtkEntry/TtkEntry.Selection_Range_(entry_index_type_numerical)
-- FUNCTION
-- Set the selection in the selected Ttk_Entry
-- PARAMETERS
-- Entry_Widget - The Ttk_Entry in which the selection will be set
-- Start_Index - The index of the first character in the selection
-- End_Index - The index or X coordinate of the last character in
-- the selection
-- Is_End_Index - If True, the End_Index index is numerical index,
-- otherwise it is X coordinate. Can be empty. Default
-- value is True.
-- HISTORY
-- 8.6.0 - Added
-- EXAMPLE
-- -- Set the selection in My_Entry widget from insertion cursor to 10th character
-- Selection_Range(My_Entry, INSERT, 9);
-- SEE ALSO
-- TtkEntry.Selection_Range_(numerical_indexes),
-- TtkEntry.Selection_Range_(entry_index_type),
-- TtkEntry.Selection_Range_(numerical_entry_index_type),
-- COMMANDS
-- Entry_Widget selection range Start_Index End_Index
-- SOURCE
procedure Selection_Range
(Entry_Widget: Ttk_Entry; Start_Index: Entry_Index_Type;
End_Index: Natural; Is_End_Index: Boolean := True) with
Pre => Entry_Widget /= Null_Widget,
Test_Case => (Name => "Test_Selection_Range4", Mode => Nominal);
-- ****
-- ****f* TtkEntry/TtkEntry.Validate
-- FUNCTION
-- Revalidate the content of the selected Ttk_Entry
-- PARAMETERS
-- Entry_Widget - The Ttk_Entry which content will be validated
-- RESULT
-- If content is valid, return True, otherwise False
-- HISTORY
-- 8.6.0 - Added
-- EXAMPLE
-- -- Validate the content of My_Entry widget
-- Is_Valid: constant Boolean := Validate(My_Entry);
-- COMMANDS
-- Entry_Widget validate
-- SOURCE
function Validate(Entry_Widget: Ttk_Entry) return Boolean with
Pre => Entry_Widget /= Null_Widget,
Test_Case => (Name => "Test_Validate", Mode => Nominal);
-- ****
-- ****f* TtkEntry/TtkEntry.X_View
-- FUNCTION
-- Get the fraction of currently visible part of the selected Ttk_Entry
-- PARAMETERS
-- Entry_Widget - The Ttk_Entry which visible part coordinates will be
-- get
-- RESULT
-- Factions_Array, where the first element is start point of visible part,
-- the second is the end point of visible part of Entry_Widget
-- HISTORY
-- 8.6.0 - Added
-- EXAMPLE
-- -- Get the visible coordinates of My_Entry widget
-- Visible_Part: constant Fractions_Array := X_View(My_Entry);
-- COMMANDS
-- Entry_Widget xview
-- SOURCE
function X_View(Entry_Widget: Ttk_Entry) return Fractions_Array with
Pre => Entry_Widget /= Null_Widget,
Test_Case => (Name => "Test_X_View", Mode => Nominal);
-- ****
-- ****f* TtkEntry/TtkEntry.X_View_Adjust_(numerical_index)
-- FUNCTION
-- Adjust the view of the Ttk_Entry so the selected character will be
-- displayed at the left edge of the widget
-- PARAMETERS
-- Entry_Widget - The Ttk_Entry which view will be adjusted
-- Index - The index or X coordinate of the character to which
-- the Ttk_Entry view will be adjusted
-- Is_Index - If True, Index is numerical index of the character. If
-- False, Index is X coordinate of the character. Can be
-- empty. Default value is True.
-- HISTORY
-- 8.6.0 - Added
-- EXAMPLE
-- -- Adjust My_Entry so it will show the content from the first character
-- X_View_Adjust(My_Entry, 0);
-- SEE ALSO
-- X_View_Adjust_(entry_index_type)
-- COMMANDS
-- Entry_Widget xview adjust Index
-- SOURCE
procedure X_View_Adjust
(Entry_Widget: Ttk_Entry; Index: Natural; Is_Index: Boolean := True) with
Pre => Entry_Widget /= Null_Widget,
Test_Case => (Name => "Test_X_View_Adjust", Mode => Nominal);
-- ****
-- ****f* TtkEntry/TtkEntry.X_View_Adjust_(entry_index_type)
-- FUNCTION
-- Adjust the view of the Ttk_Entry so the selected character will be
-- displayed at the left edge of the widget
-- PARAMETERS
-- Entry_Widget - The Ttk_Entry which view will be adjusted
-- Index - The index of the character to which the Ttk_Entry
-- view will be adjusted
-- HISTORY
-- 8.6.0 - Added
-- EXAMPLE
-- -- Adjust My_Entry so it will show the content from the insertion cursor
-- X_View_Adjust(My_Entry, INSERT);
-- SEE ALSO
-- X_View_Adjust_(numeric_index)
-- COMMANDS
-- Entry_Widget xview adjust Index
procedure X_View_Adjust
(Entry_Widget: Ttk_Entry; Index: Entry_Index_Type) with
Pre => Entry_Widget /= Null_Widget,
Test_Case => (Name => "Test_X_View_Adjust2", Mode => Nominal);
-- ****
-- ****f* TtkEntry/TtkEntry.X_View_Move_To
-- FUNCTION
-- Move Ttk_Entry view by the selected fraction. The selected fraction
-- will be displayed at the left edge of the widget.
-- PARAMETERS
-- Entry_Widget - The Ttk_Entry which view will be moved
-- Fraction - The fraction about which the view will be moved
-- HISTORY
-- 8.6.0 - Added
-- EXAMPLE
-- -- Move view of My_Entry by half
-- X_View_Move_To(My_Entry, 0.5);
-- COMMANDS
-- Entry_Widget xview moveto Fraction
-- SOURCE
procedure X_View_Move_To
(Entry_Widget: Ttk_Entry; Fraction: Fraction_Type) with
Pre => Entry_Widget /= Null_Widget,
Test_Case => (Name => "Test_X_View_Move_To", Mode => Nominal);
-- ****
-- ****f* TtkEntry/Ttk_Entry.X_View_Scroll
-- FUNCTION
-- Shift the view in the Ttk_Entry on the left or right.
-- PARAMETERS
-- Entry_Widget - The Ttk_Entry which will be shifted
-- Number - The amount of units. If it is positive then move to
-- the right, if negative, move to the left
-- What - If UNITS then move by selected amount of characters,
-- when PAGES then amount of screens
-- HISTORY
-- 8.6.0 - Added
-- EXAMPLE
-- -- Scroll My_Entry by two screens
-- X_View_Scroll(My_Entry, 2, PAGES);
-- SOURCE
procedure X_View_Scroll
(Entry_Widget: Ttk_Entry; Number: Integer; What: Scroll_Unit_Type) with
Pre => Entry_Widget /= Null_Widget,
Test_Case => (Name => "Test_X_View_Scroll", Mode => Nominal);
-- ****
--## rule on REDUCEABLE_SCOPE
end Tk.TtkEntry;
|
------------------------------------------------------------------------------
-- --
-- Copyright (C) 2015-2016, AdaCore --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions are --
-- met: --
-- 1. Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- 2. Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in --
-- the documentation and/or other materials provided with the --
-- distribution. --
-- 3. Neither the name of the copyright holder nor the names of its --
-- contributors may be used to endorse or promote products derived --
-- from this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT --
-- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, --
-- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY --
-- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT --
-- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE --
-- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
with Last_Chance_Handler; pragma Unreferenced (Last_Chance_Handler);
-- The "last chance handler" is the user-defined routine that is called when
-- an exception is propagated. We need it in the executable, therefore it
-- must be somewhere in the closure of the context clauses.
with STM32.Board; use STM32.Board;
with STM32.DMA2D; use STM32.DMA2D;
with STM32.DMA2D_Bitmap; use STM32.DMA2D_Bitmap;
with HAL; use HAL;
with HAL.Bitmap; use HAL.Bitmap;
procedure Dma2d
is
function Bitmap_Buffer return not null Any_Bitmap_Buffer;
function Buffer return DMA2D_Buffer;
-------------------
-- Bitmap_Buffer --
-------------------
function Bitmap_Buffer return not null Any_Bitmap_Buffer is
begin
if Display.Hidden_Buffer (1).all not in DMA2D_Bitmap_Buffer then
raise Program_Error with "We expect a DM2D buffer here";
end if;
return Display.Hidden_Buffer (1);
end Bitmap_Buffer;
------------
-- Buffer --
------------
function Buffer return DMA2D_Buffer is
begin
return To_DMA2D_Buffer (Display.Hidden_Buffer (1).all);
end Buffer;
Width : Natural;
Height : Natural;
X, Y : Natural;
L4_CLUT : array (UInt4) of DMA2D_Color;
L8_CLUT : array (UInt8) of DMA2D_Color;
type L4_Bitmap is array (UInt4) of UInt4 with Pack;
type L8_Bitmap is array (UInt8) of UInt8 with Pack;
L4_Data : L4_Bitmap with Size => 16 * 4;
L8_Data : L8_Bitmap with Size => 256 * 8;
L4_Buffer : constant DMA2D_Buffer :=
(Color_Mode => L4,
Addr => L4_Data (0)'Address,
Width => 4,
Height => 4,
CLUT_Color_Mode => ARGB8888,
CLUT_Addr => L4_CLUT (0)'Address);
L8_Buffer : constant DMA2D_Buffer :=
(Color_Mode => L8,
Addr => L8_Data (0)'Address,
Width => 16,
Height => 16,
CLUT_Color_Mode => ARGB8888,
CLUT_Addr => L8_CLUT (0)'Address);
begin
-- Initialize LCD
Display.Initialize;
Display.Initialize_Layer (1, HAL.Bitmap.ARGB_8888);
Width := Display.Hidden_Buffer (1).Width;
Height := Display.Hidden_Buffer (1).Height;
loop
Bitmap_Buffer.Set_Source (HAL.Bitmap.Dark_Green);
Bitmap_Buffer.Fill;
-- Draw blue filled rectangle in the upper left corner
Bitmap_Buffer.Set_Source (HAL.Bitmap.Blue);
Bitmap_Buffer.Fill_Rect ((Position => (0, 0),
Width => Width / 2,
Height => Height / 2));
-- Drawn yellow rectangle outline in the lower left corner
Bitmap_Buffer.Set_Source (HAL.Bitmap.Yellow);
Bitmap_Buffer.Draw_Rect ((Position => (0, Height / 2),
Width => Width / 2,
Height => Height / 2));
-- Draw 10 red lines in the blue rectangle
X := 0;
Y := 0;
while X < Width / 2 and then Y < ((Height / 2) - 10) loop
for Cnt in 0 .. 10 loop
Bitmap_Buffer.Set_Pixel ((X, Y + Cnt), HAL.Bitmap.Red);
end loop;
X := X + 1;
Y := Y + 1;
end loop;
-- Draw 10 red blended lines in the yellow rectangle
X := 0;
Y := Height / 2;
while X < Width / 2 and then Y < Height - 10 loop
for Cnt in 0 .. 10 loop
Bitmap_Buffer.Set_Source ((100, 255, 0, 0));
Bitmap_Buffer.Set_Pixel_Blend ((X, Y + Cnt));
end loop;
X := X + 1;
Y := Y + 1;
end loop;
-- Copy half of the screen to the other half
Copy_Rect (Src_Buffer => Bitmap_Buffer.all,
Src_Pt => (0, 0),
Dst_Buffer => Bitmap_Buffer.all,
Dst_Pt => (Width / 2, 0),
Bg_Buffer => STM32.DMA2D_Bitmap.Null_Buffer,
Bg_Pt => (0, 0),
Width => Width / 2,
Height => Height,
Synchronous => True);
-- Fill L4 CLUT
for Index in UInt4 loop
L4_CLUT (Index) := (255, 0, 0, UInt8 (Index) * 16);
end loop;
-- Fill L4 bitmap
for Index in L4_Data'Range loop
L4_Data (Index) := Index;
end loop;
-- Fill L8 CLUT
for Index in UInt8 loop
L8_CLUT (Index) := (255, 0, Index, 0);
end loop;
-- Fill L8 bitmap
for Index in L8_Data'Range loop
L8_Data (Index) := Index;
end loop;
for X in 0 .. 4 loop
for Y in 0 .. 4 loop
STM32.DMA2D.DMA2D_Copy_Rect
(Src_Buffer => L4_Buffer,
X_Src => 0,
Y_Src => 0,
Dst_Buffer => Buffer,
X_Dst => L4_Buffer.Width * X,
Y_Dst => (L4_Buffer.Height * Y),
Bg_Buffer => STM32.DMA2D.Null_Buffer,
X_Bg => 0,
Y_Bg => 0,
Width => L4_Buffer.Width,
Height => L4_Buffer.Height,
Synchronous => True);
STM32.DMA2D.DMA2D_Copy_Rect
(Src_Buffer => L8_Buffer,
X_Src => 0,
Y_Src => 0,
Dst_Buffer => Buffer,
X_Dst => L8_Buffer.Width * X,
Y_Dst => (L8_Buffer.Height * Y) + Height / 2,
Bg_Buffer => STM32.DMA2D.Null_Buffer,
X_Bg => 0,
Y_Bg => 0,
Width => L8_Buffer.Width,
Height => L8_Buffer.Height,
Synchronous => True);
end loop;
end loop;
Display.Update_Layers;
end loop;
end Dma2d;
|
with Ada.Colors;
with Ada.Text_IO.Terminal.Colors.Names;
procedure tty_color is
use type Ada.Text_IO.Terminal.Colors.Color_Parameter;
package CN
renames Ada.Text_IO.Terminal.Colors.Names;
System_Colors : constant array (0 .. 15) of Ada.Text_IO.Terminal.Colors.Color := (
CN.Black,
CN.Dark_Blue,
CN.Dark_Green,
CN.Dark_Cyan,
CN.Dark_Red,
CN.Dark_Magenta,
CN.Dark_Yellow,
CN.Gray,
CN.Dark_Gray,
CN.Blue,
CN.Green,
CN.Cyan,
CN.Red,
CN.Magenta,
CN.Yellow,
CN.White);
Fullwidth_A : constant String := (
Character'Val (16#EF#),
Character'Val (16#BC#),
Character'Val (16#A1#));
Output : Ada.Text_IO.File_Type
renames Ada.Text_IO.Standard_Output.all;
begin
for I in System_Colors'Range loop
Ada.Text_IO.Terminal.Colors.Set_Color (Output,
Foreground => +System_Colors (System_Colors'Last - I),
Background => +System_Colors (I));
Ada.Text_IO.Put (Output, Fullwidth_A);
end loop;
Ada.Text_IO.Terminal.Colors.Reset_Color (Output);
Ada.Text_IO.New_Line (Output, Spacing => 2);
for R1 in 0 .. 1 loop -- large Y block
for G in 0 .. 7 loop -- Y
for R2 in 0 .. 3 loop -- large X block
for B in 0 .. 7 loop -- X
declare
C : constant Ada.Text_IO.Terminal.Colors.Color :=
Ada.Text_IO.Terminal.Colors.To_Color (
Ada.Colors.RGB'(
Red => Float (R1 * 4 + R2) / 7.0,
Blue => Float (B) / 7.0,
Green => Float (G) / 7.0));
begin
Ada.Text_IO.Terminal.Colors.Set_Color (Output, Background => +C);
Ada.Text_IO.Put (Output, " ");
end;
end loop;
Ada.Text_IO.Terminal.Colors.Reset_Color (Output);
if R2 < 3 then
Ada.Text_IO.Put (Output, " ");
end if;
end loop;
Ada.Text_IO.New_Line (Output);
end loop;
Ada.Text_IO.New_Line (Output);
end loop;
for L in 0 .. 25 loop -- grayscale
declare
C : constant Ada.Text_IO.Terminal.Colors.Color :=
Ada.Text_IO.Terminal.Colors.To_Grayscale_Color (Float (L) / 25.0);
begin
Ada.Text_IO.Terminal.Colors.Set_Color (Output, Background => +C);
Ada.Text_IO.Put (Output, " ");
end;
end loop;
Ada.Text_IO.Terminal.Colors.Reset_Color (Output);
Ada.Text_IO.New_Line;
end tty_color;
|
with Ada.Text_IO;
with Orka.Features.Atmosphere.KTX;
with Orka.Transforms.Doubles.Matrices;
package body Demo.Atmospheres is
package Matrices renames Orka.Transforms.Doubles.Matrices;
function Create
(Planet_Model : aliased Orka.Features.Atmosphere.Model_Data;
Planet_Data : Planets.Planet_Characteristics;
Location_Shaders : Orka.Resources.Locations.Location_Ptr;
Location_Precomputed : Orka.Resources.Locations.Writable_Location_Ptr) return Atmosphere
is
use Orka.Features.Atmosphere;
begin
if not Location_Precomputed.Exists ("irradiance.ktx") or
not Location_Precomputed.Exists ("scattering.ktx") or
not Location_Precomputed.Exists ("transmittance.ktx")
then
Ada.Text_IO.Put_Line ("Precomputing atmosphere. Stay a while and listen...");
declare
Atmosphere_Model : constant Model :=
Create_Model (Planet_Model'Access, Location_Shaders);
Textures : constant Precomputed_Textures := Atmosphere_Model.Compute_Textures;
begin
Ada.Text_IO.Put_Line ("Precomputed textures for atmosphere");
KTX.Save_Textures (Textures, Location_Precomputed);
Ada.Text_IO.Put_Line ("Saved textures for atmosphere");
end;
end if;
return
(Program => Rendering.Create_Atmosphere
(Planet_Model, Location_Shaders,
Parameters => (Semi_Major_Axis => Planet_Data.Semi_Major_Axis,
Flattening => Planet_Data.Flattening,
Axial_Tilt => Matrices.Vectors.To_Radians
(Planet_Data.Axial_Tilt_Deg),
Star_Radius => <>)),
Textures =>
Orka.Features.Atmosphere.KTX.Load_Textures
(Planet_Model, Orka.Resources.Locations.Location_Ptr (Location_Precomputed)));
end Create;
function Shader_Module (Object : Atmosphere)
return Orka.Rendering.Programs.Modules.Module
is (Object.Program.Shader_Module);
procedure Render
(Object : in out Atmosphere;
Camera : Orka.Cameras.Camera_Ptr;
Planet, Star : Orka.Behaviors.Behavior_Ptr) is
begin
Orka.Features.Atmosphere.Bind_Textures (Object.Textures);
Object.Program.Render (Camera, Planet, Star);
end Render;
end Demo.Atmospheres;
|
-- Copyright (C)2021,2022 Steve Merrony
-- Permission is hereby granted, free of charge, to any person obtaining a copy
-- of this software and associated documentation files (the "Software"), to deal
-- in the Software without restriction, including without limitation the rights
-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-- copies of the Software, and to permit persons to whom the Software is
-- furnished to do so, subject to the following conditions:
-- The above copyright notice and this permission notice shall be included in
-- all copies or substantial portions of the Software.
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-- THE SOFTWARE.
with Ada.Command_Line; use Ada.Command_Line;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
with Ada.Text_IO;
with GNAT.OS_Lib;
-- with Gtk.Builder;
-- with Gtkada.Builder;
-- with Gtk.Application;
with Gdk.Threads;
with Gtk.Main;
with Gtk.Window; use Gtk.Window;
with GUI;
with Logging; use Logging;
procedure Dashera is
-- Glade_Filename : constant String := "resources/dashera.glade";
-- GUI stuff
Main_Window : Gtk_Window;
-- program args etc.
Arg_Ix : Natural := 1;
Host_Arg : Unbounded_String := Null_Unbounded_String;
Trace_Xmodem : Boolean := false;
-- Builder : Gtkada.Builder.Gtkada_Builder;
-- Error : aliased GError;
procedure Print_Help is
begin
Ada.Text_IO.Put_Line ("Usage of dashera:");
Ada.Text_IO.Put_Line (" -host <host:port> Host to connect with via Telnet");
Ada.Text_IO.Put_Line (" -debug Print debugging information on STDOUT");
Ada.Text_IO.Put_Line (" -tracescript Print trace of Mini-Expect script on STDOUT");
Ada.Text_IO.Put_Line (" -tracexmodem Show details of XMODEM file transfers on STDOUT");
Ada.Text_IO.Put_Line (" -version show the version number of dashera and exit");
end Print_Help;
begin
while Arg_Ix <= Argument_Count loop
if Argument (Arg_Ix) = "-version" then
Ada.Text_IO.Put_Line ("dashera version " & GUI.App_SemVer);
return;
elsif Argument (Arg_Ix) = "-host" then
Host_Arg := To_Unbounded_String (Argument (Arg_Ix + 1));
Arg_Ix := Arg_Ix + 1;
elsif Argument (Arg_Ix) = "-debug" then
Set_Level (DEBUG);
elsif Argument (Arg_Ix) = "-tracescript" then
Set_Level (TRACE);
elsif Argument (Arg_Ix) = "-tracexmodem" then
Trace_Xmodem := true;
elsif Argument (Arg_Ix) = "-h" or Argument (Arg_Ix) = "-help" then
Print_Help;
GNAT.OS_Lib.OS_Exit (0);
end if;
Arg_Ix := Arg_Ix + 1;
end loop;
Gdk.Threads.G_Init;
Gdk.Threads.Init;
Gtk.Main.Init;
Log (DEBUG, "Preparing to enter Main GTK event loop...");
Gdk.Threads.Enter;
Main_Window := Gui.Create_Window (Host_Arg, Trace_Xmodem);
Main_Window.Show_All;
Gtk.Main.Main;
Gdk.Threads.Leave;
end Dashera;
|
------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- S E M _ C H 1 3 --
-- --
-- B o d y --
-- --
-- Copyright (C) 1992-2006, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 2, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
-- for more details. You should have received a copy of the GNU General --
-- Public License distributed with GNAT; see file COPYING. If not, write --
-- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
-- Boston, MA 02110-1301, USA. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
with Atree; use Atree;
with Checks; use Checks;
with Einfo; use Einfo;
with Errout; use Errout;
with Exp_Tss; use Exp_Tss;
with Exp_Util; use Exp_Util;
with Lib; use Lib;
with Nlists; use Nlists;
with Nmake; use Nmake;
with Opt; use Opt;
with Restrict; use Restrict;
with Rident; use Rident;
with Rtsfind; use Rtsfind;
with Sem; use Sem;
with Sem_Ch8; use Sem_Ch8;
with Sem_Eval; use Sem_Eval;
with Sem_Res; use Sem_Res;
with Sem_Type; use Sem_Type;
with Sem_Util; use Sem_Util;
with Snames; use Snames;
with Stand; use Stand;
with Sinfo; use Sinfo;
with Table;
with Targparm; use Targparm;
with Ttypes; use Ttypes;
with Tbuild; use Tbuild;
with Urealp; use Urealp;
with GNAT.Heap_Sort_A; use GNAT.Heap_Sort_A;
package body Sem_Ch13 is
SSU : constant Pos := System_Storage_Unit;
-- Convenient short hand for commonly used constant
-----------------------
-- Local Subprograms --
-----------------------
procedure Alignment_Check_For_Esize_Change (Typ : Entity_Id);
-- This routine is called after setting the Esize of type entity Typ.
-- The purpose is to deal with the situation where an aligment has been
-- inherited from a derived type that is no longer appropriate for the
-- new Esize value. In this case, we reset the Alignment to unknown.
procedure Check_Component_Overlap (C1_Ent, C2_Ent : Entity_Id);
-- Given two entities for record components or discriminants, checks
-- if they hav overlapping component clauses and issues errors if so.
function Get_Alignment_Value (Expr : Node_Id) return Uint;
-- Given the expression for an alignment value, returns the corresponding
-- Uint value. If the value is inappropriate, then error messages are
-- posted as required, and a value of No_Uint is returned.
function Is_Operational_Item (N : Node_Id) return Boolean;
-- A specification for a stream attribute is allowed before the full
-- type is declared, as explained in AI-00137 and the corrigendum.
-- Attributes that do not specify a representation characteristic are
-- operational attributes.
function Address_Aliased_Entity (N : Node_Id) return Entity_Id;
-- If expression N is of the form E'Address, return E
procedure Mark_Aliased_Address_As_Volatile (N : Node_Id);
-- This is used for processing of an address representation clause. If
-- the expression N is of the form of K'Address, then the entity that
-- is associated with K is marked as volatile.
procedure New_Stream_Function
(N : Node_Id;
Ent : Entity_Id;
Subp : Entity_Id;
Nam : TSS_Name_Type);
-- Create a function renaming of a given stream attribute to the
-- designated subprogram and then in the tagged case, provide this as
-- a primitive operation, or in the non-tagged case make an appropriate
-- TSS entry. Used for Input. This is more properly an expansion activity
-- than just semantics, but the presence of user-defined stream functions
-- for limited types is a legality check, which is why this takes place
-- here rather than in exp_ch13, where it was previously. Nam indicates
-- the name of the TSS function to be generated.
--
-- To avoid elaboration anomalies with freeze nodes, for untagged types
-- we generate both a subprogram declaration and a subprogram renaming
-- declaration, so that the attribute specification is handled as a
-- renaming_as_body. For tagged types, the specification is one of the
-- primitive specs.
procedure New_Stream_Procedure
(N : Node_Id;
Ent : Entity_Id;
Subp : Entity_Id;
Nam : TSS_Name_Type;
Out_P : Boolean := False);
-- Create a procedure renaming of a given stream attribute to the
-- designated subprogram and then in the tagged case, provide this as
-- a primitive operation, or in the non-tagged case make an appropriate
-- TSS entry. Used for Read, Output, Write. Nam indicates the name of
-- the TSS procedure to be generated.
----------------------------------------------
-- Table for Validate_Unchecked_Conversions --
----------------------------------------------
-- The following table collects unchecked conversions for validation.
-- Entries are made by Validate_Unchecked_Conversion and then the
-- call to Validate_Unchecked_Conversions does the actual error
-- checking and posting of warnings. The reason for this delayed
-- processing is to take advantage of back-annotations of size and
-- alignment values peformed by the back end.
type UC_Entry is record
Enode : Node_Id; -- node used for posting warnings
Source : Entity_Id; -- source type for unchecked conversion
Target : Entity_Id; -- target type for unchecked conversion
end record;
package Unchecked_Conversions is new Table.Table (
Table_Component_Type => UC_Entry,
Table_Index_Type => Int,
Table_Low_Bound => 1,
Table_Initial => 50,
Table_Increment => 200,
Table_Name => "Unchecked_Conversions");
----------------------------
-- Address_Aliased_Entity --
----------------------------
function Address_Aliased_Entity (N : Node_Id) return Entity_Id is
begin
if Nkind (N) = N_Attribute_Reference
and then Attribute_Name (N) = Name_Address
then
declare
Nam : Node_Id := Prefix (N);
begin
while False
or else Nkind (Nam) = N_Selected_Component
or else Nkind (Nam) = N_Indexed_Component
loop
Nam := Prefix (Nam);
end loop;
if Is_Entity_Name (Nam) then
return Entity (Nam);
end if;
end;
end if;
return Empty;
end Address_Aliased_Entity;
--------------------------------------
-- Alignment_Check_For_Esize_Change --
--------------------------------------
procedure Alignment_Check_For_Esize_Change (Typ : Entity_Id) is
begin
-- If the alignment is known, and not set by a rep clause, and is
-- inconsistent with the size being set, then reset it to unknown,
-- we assume in this case that the size overrides the inherited
-- alignment, and that the alignment must be recomputed.
if Known_Alignment (Typ)
and then not Has_Alignment_Clause (Typ)
and then Esize (Typ) mod (Alignment (Typ) * SSU) /= 0
then
Init_Alignment (Typ);
end if;
end Alignment_Check_For_Esize_Change;
-----------------------
-- Analyze_At_Clause --
-----------------------
-- An at clause is replaced by the corresponding Address attribute
-- definition clause that is the preferred approach in Ada 95.
procedure Analyze_At_Clause (N : Node_Id) is
begin
Check_Restriction (No_Obsolescent_Features, N);
if Warn_On_Obsolescent_Feature then
Error_Msg_N
("at clause is an obsolescent feature ('R'M 'J.7(2))?", N);
Error_Msg_N
("\use address attribute definition clause instead?", N);
end if;
Rewrite (N,
Make_Attribute_Definition_Clause (Sloc (N),
Name => Identifier (N),
Chars => Name_Address,
Expression => Expression (N)));
Analyze_Attribute_Definition_Clause (N);
end Analyze_At_Clause;
-----------------------------------------
-- Analyze_Attribute_Definition_Clause --
-----------------------------------------
procedure Analyze_Attribute_Definition_Clause (N : Node_Id) is
Loc : constant Source_Ptr := Sloc (N);
Nam : constant Node_Id := Name (N);
Attr : constant Name_Id := Chars (N);
Expr : constant Node_Id := Expression (N);
Id : constant Attribute_Id := Get_Attribute_Id (Attr);
Ent : Entity_Id;
U_Ent : Entity_Id;
FOnly : Boolean := False;
-- Reset to True for subtype specific attribute (Alignment, Size)
-- and for stream attributes, i.e. those cases where in the call
-- to Rep_Item_Too_Late, FOnly is set True so that only the freezing
-- rules are checked. Note that the case of stream attributes is not
-- clear from the RM, but see AI95-00137. Also, the RM seems to
-- disallow Storage_Size for derived task types, but that is also
-- clearly unintentional.
procedure Analyze_Stream_TSS_Definition (TSS_Nam : TSS_Name_Type);
-- Common processing for 'Read, 'Write, 'Input and 'Output attribute
-- definition clauses.
procedure Analyze_Stream_TSS_Definition (TSS_Nam : TSS_Name_Type) is
Subp : Entity_Id := Empty;
I : Interp_Index;
It : Interp;
Pnam : Entity_Id;
Is_Read : constant Boolean := (TSS_Nam = TSS_Stream_Read);
function Has_Good_Profile (Subp : Entity_Id) return Boolean;
-- Return true if the entity is a subprogram with an appropriate
-- profile for the attribute being defined.
----------------------
-- Has_Good_Profile --
----------------------
function Has_Good_Profile (Subp : Entity_Id) return Boolean is
F : Entity_Id;
Is_Function : constant Boolean := (TSS_Nam = TSS_Stream_Input);
Expected_Ekind : constant array (Boolean) of Entity_Kind :=
(False => E_Procedure, True => E_Function);
Typ : Entity_Id;
begin
if Ekind (Subp) /= Expected_Ekind (Is_Function) then
return False;
end if;
F := First_Formal (Subp);
if No (F)
or else Ekind (Etype (F)) /= E_Anonymous_Access_Type
or else Designated_Type (Etype (F)) /=
Class_Wide_Type (RTE (RE_Root_Stream_Type))
then
return False;
end if;
if not Is_Function then
Next_Formal (F);
declare
Expected_Mode : constant array (Boolean) of Entity_Kind :=
(False => E_In_Parameter,
True => E_Out_Parameter);
begin
if Parameter_Mode (F) /= Expected_Mode (Is_Read) then
return False;
end if;
end;
Typ := Etype (F);
else
Typ := Etype (Subp);
end if;
return Base_Type (Typ) = Base_Type (Ent)
and then No (Next_Formal (F));
end Has_Good_Profile;
-- Start of processing for Analyze_Stream_TSS_Definition
begin
FOnly := True;
if not Is_Type (U_Ent) then
Error_Msg_N ("local name must be a subtype", Nam);
return;
end if;
Pnam := TSS (Base_Type (U_Ent), TSS_Nam);
if Present (Pnam) and then Has_Good_Profile (Pnam) then
Error_Msg_Sloc := Sloc (Pnam);
Error_Msg_Name_1 := Attr;
Error_Msg_N ("% attribute already defined #", Nam);
return;
end if;
Analyze (Expr);
if Is_Entity_Name (Expr) then
if not Is_Overloaded (Expr) then
if Has_Good_Profile (Entity (Expr)) then
Subp := Entity (Expr);
end if;
else
Get_First_Interp (Expr, I, It);
while Present (It.Nam) loop
if Has_Good_Profile (It.Nam) then
Subp := It.Nam;
exit;
end if;
Get_Next_Interp (I, It);
end loop;
end if;
end if;
if Present (Subp) then
if Is_Abstract (Subp) then
Error_Msg_N ("stream subprogram must not be abstract", Expr);
return;
end if;
Set_Entity (Expr, Subp);
Set_Etype (Expr, Etype (Subp));
if TSS_Nam = TSS_Stream_Input then
New_Stream_Function (N, U_Ent, Subp, TSS_Nam);
else
New_Stream_Procedure (N, U_Ent, Subp, TSS_Nam,
Out_P => Is_Read);
end if;
else
Error_Msg_Name_1 := Attr;
Error_Msg_N ("incorrect expression for% attribute", Expr);
end if;
end Analyze_Stream_TSS_Definition;
-- Start of processing for Analyze_Attribute_Definition_Clause
begin
Analyze (Nam);
Ent := Entity (Nam);
if Rep_Item_Too_Early (Ent, N) then
return;
end if;
-- Rep clause applies to full view of incomplete type or private type if
-- we have one (if not, this is a premature use of the type). However,
-- certain semantic checks need to be done on the specified entity (i.e.
-- the private view), so we save it in Ent.
if Is_Private_Type (Ent)
and then Is_Derived_Type (Ent)
and then not Is_Tagged_Type (Ent)
and then No (Full_View (Ent))
then
-- If this is a private type whose completion is a derivation from
-- another private type, there is no full view, and the attribute
-- belongs to the type itself, not its underlying parent.
U_Ent := Ent;
elsif Ekind (Ent) = E_Incomplete_Type then
-- The attribute applies to the full view, set the entity of the
-- attribute definition accordingly.
Ent := Underlying_Type (Ent);
U_Ent := Ent;
Set_Entity (Nam, Ent);
else
U_Ent := Underlying_Type (Ent);
end if;
-- Complete other routine error checks
if Etype (Nam) = Any_Type then
return;
elsif Scope (Ent) /= Current_Scope then
Error_Msg_N ("entity must be declared in this scope", Nam);
return;
elsif No (U_Ent) then
U_Ent := Ent;
elsif Is_Type (U_Ent)
and then not Is_First_Subtype (U_Ent)
and then Id /= Attribute_Object_Size
and then Id /= Attribute_Value_Size
and then not From_At_Mod (N)
then
Error_Msg_N ("cannot specify attribute for subtype", Nam);
return;
end if;
-- Switch on particular attribute
case Id is
-------------
-- Address --
-------------
-- Address attribute definition clause
when Attribute_Address => Address : begin
Analyze_And_Resolve (Expr, RTE (RE_Address));
if Present (Address_Clause (U_Ent)) then
Error_Msg_N ("address already given for &", Nam);
-- Case of address clause for subprogram
elsif Is_Subprogram (U_Ent) then
if Has_Homonym (U_Ent) then
Error_Msg_N
("address clause cannot be given " &
"for overloaded subprogram",
Nam);
end if;
-- For subprograms, all address clauses are permitted,
-- and we mark the subprogram as having a deferred freeze
-- so that Gigi will not elaborate it too soon.
-- Above needs more comments, what is too soon about???
Set_Has_Delayed_Freeze (U_Ent);
-- Case of address clause for entry
elsif Ekind (U_Ent) = E_Entry then
if Nkind (Parent (N)) = N_Task_Body then
Error_Msg_N
("entry address must be specified in task spec", Nam);
end if;
-- For entries, we require a constant address
Check_Constant_Address_Clause (Expr, U_Ent);
if Is_Task_Type (Scope (U_Ent))
and then Comes_From_Source (Scope (U_Ent))
then
Error_Msg_N
("?entry address declared for entry in task type", N);
Error_Msg_N
("\?only one task can be declared of this type", N);
end if;
Check_Restriction (No_Obsolescent_Features, N);
if Warn_On_Obsolescent_Feature then
Error_Msg_N
("attaching interrupt to task entry is an " &
"obsolescent feature ('R'M 'J.7.1)?", N);
Error_Msg_N
("\use interrupt procedure instead?", N);
end if;
-- Case of an address clause for a controlled object:
-- erroneous execution.
elsif Is_Controlled (Etype (U_Ent)) then
Error_Msg_NE
("?controlled object& must not be overlaid", Nam, U_Ent);
Error_Msg_N
("\?Program_Error will be raised at run time", Nam);
Insert_Action (Declaration_Node (U_Ent),
Make_Raise_Program_Error (Loc,
Reason => PE_Overlaid_Controlled_Object));
-- Case of address clause for a (non-controlled) object
elsif
Ekind (U_Ent) = E_Variable
or else
Ekind (U_Ent) = E_Constant
then
declare
Expr : constant Node_Id := Expression (N);
Aent : constant Entity_Id := Address_Aliased_Entity (Expr);
begin
-- Exported variables cannot have an address clause,
-- because this cancels the effect of the pragma Export
if Is_Exported (U_Ent) then
Error_Msg_N
("cannot export object with address clause", Nam);
-- Overlaying controlled objects is erroneous
elsif Present (Aent)
and then Is_Controlled (Etype (Aent))
then
Error_Msg_N
("?controlled object must not be overlaid", Expr);
Error_Msg_N
("\?Program_Error will be raised at run time", Expr);
Insert_Action (Declaration_Node (U_Ent),
Make_Raise_Program_Error (Loc,
Reason => PE_Overlaid_Controlled_Object));
elsif Present (Aent)
and then Ekind (U_Ent) = E_Constant
and then Ekind (Aent) /= E_Constant
then
Error_Msg_N ("constant overlays a variable?", Expr);
elsif Present (Renamed_Object (U_Ent)) then
Error_Msg_N
("address clause not allowed"
& " for a renaming declaration ('R'M 13.1(6))", Nam);
-- Imported variables can have an address clause, but then
-- the import is pretty meaningless except to suppress
-- initializations, so we do not need such variables to
-- be statically allocated (and in fact it causes trouble
-- if the address clause is a local value).
elsif Is_Imported (U_Ent) then
Set_Is_Statically_Allocated (U_Ent, False);
end if;
-- We mark a possible modification of a variable with an
-- address clause, since it is likely aliasing is occurring.
Note_Possible_Modification (Nam);
-- Here we are checking for explicit overlap of one
-- variable by another, and if we find this, then we
-- mark the overlapped variable as also being aliased.
-- First case is where we have an explicit
-- for J'Address use K'Address;
-- In this case, we mark K as volatile
Mark_Aliased_Address_As_Volatile (Expr);
-- Second case is where we have a constant whose
-- definition is of the form of an address as in:
-- A : constant Address := K'Address;
-- ...
-- for B'Address use A;
-- In this case we also mark K as volatile
if Is_Entity_Name (Expr) then
declare
Ent : constant Entity_Id := Entity (Expr);
Decl : constant Node_Id := Declaration_Node (Ent);
begin
if Ekind (Ent) = E_Constant
and then Nkind (Decl) = N_Object_Declaration
and then Present (Expression (Decl))
then
Mark_Aliased_Address_As_Volatile
(Expression (Decl));
end if;
end;
end if;
-- Legality checks on the address clause for initialized
-- objects is deferred until the freeze point, because
-- a subsequent pragma might indicate that the object is
-- imported and thus not initialized.
Set_Has_Delayed_Freeze (U_Ent);
if Is_Exported (U_Ent) then
Error_Msg_N
("& cannot be exported if an address clause is given",
Nam);
Error_Msg_N
("\define and export a variable " &
"that holds its address instead",
Nam);
end if;
-- Entity has delayed freeze, so we will generate
-- an alignment check at the freeze point.
Set_Check_Address_Alignment
(N, not Range_Checks_Suppressed (U_Ent));
-- Kill the size check code, since we are not allocating
-- the variable, it is somewhere else.
Kill_Size_Check_Code (U_Ent);
end;
-- Not a valid entity for an address clause
else
Error_Msg_N ("address cannot be given for &", Nam);
end if;
end Address;
---------------
-- Alignment --
---------------
-- Alignment attribute definition clause
when Attribute_Alignment => Alignment_Block : declare
Align : constant Uint := Get_Alignment_Value (Expr);
begin
FOnly := True;
if not Is_Type (U_Ent)
and then Ekind (U_Ent) /= E_Variable
and then Ekind (U_Ent) /= E_Constant
then
Error_Msg_N ("alignment cannot be given for &", Nam);
elsif Has_Alignment_Clause (U_Ent) then
Error_Msg_Sloc := Sloc (Alignment_Clause (U_Ent));
Error_Msg_N ("alignment clause previously given#", N);
elsif Align /= No_Uint then
Set_Has_Alignment_Clause (U_Ent);
Set_Alignment (U_Ent, Align);
end if;
end Alignment_Block;
---------------
-- Bit_Order --
---------------
-- Bit_Order attribute definition clause
when Attribute_Bit_Order => Bit_Order : declare
begin
if not Is_Record_Type (U_Ent) then
Error_Msg_N
("Bit_Order can only be defined for record type", Nam);
else
Analyze_And_Resolve (Expr, RTE (RE_Bit_Order));
if Etype (Expr) = Any_Type then
return;
elsif not Is_Static_Expression (Expr) then
Flag_Non_Static_Expr
("Bit_Order requires static expression!", Expr);
else
if (Expr_Value (Expr) = 0) /= Bytes_Big_Endian then
Set_Reverse_Bit_Order (U_Ent, True);
end if;
end if;
end if;
end Bit_Order;
--------------------
-- Component_Size --
--------------------
-- Component_Size attribute definition clause
when Attribute_Component_Size => Component_Size_Case : declare
Csize : constant Uint := Static_Integer (Expr);
Btype : Entity_Id;
Biased : Boolean;
New_Ctyp : Entity_Id;
Decl : Node_Id;
begin
if not Is_Array_Type (U_Ent) then
Error_Msg_N ("component size requires array type", Nam);
return;
end if;
Btype := Base_Type (U_Ent);
if Has_Component_Size_Clause (Btype) then
Error_Msg_N
("component size clase for& previously given", Nam);
elsif Csize /= No_Uint then
Check_Size (Expr, Component_Type (Btype), Csize, Biased);
if Has_Aliased_Components (Btype)
and then Csize < 32
and then Csize /= 8
and then Csize /= 16
then
Error_Msg_N
("component size incorrect for aliased components", N);
return;
end if;
-- For the biased case, build a declaration for a subtype
-- that will be used to represent the biased subtype that
-- reflects the biased representation of components. We need
-- this subtype to get proper conversions on referencing
-- elements of the array.
if Biased then
New_Ctyp :=
Make_Defining_Identifier (Loc,
Chars => New_External_Name (Chars (U_Ent), 'C', 0, 'T'));
Decl :=
Make_Subtype_Declaration (Loc,
Defining_Identifier => New_Ctyp,
Subtype_Indication =>
New_Occurrence_Of (Component_Type (Btype), Loc));
Set_Parent (Decl, N);
Analyze (Decl, Suppress => All_Checks);
Set_Has_Delayed_Freeze (New_Ctyp, False);
Set_Esize (New_Ctyp, Csize);
Set_RM_Size (New_Ctyp, Csize);
Init_Alignment (New_Ctyp);
Set_Has_Biased_Representation (New_Ctyp, True);
Set_Is_Itype (New_Ctyp, True);
Set_Associated_Node_For_Itype (New_Ctyp, U_Ent);
Set_Component_Type (Btype, New_Ctyp);
end if;
Set_Component_Size (Btype, Csize);
Set_Has_Component_Size_Clause (Btype, True);
Set_Has_Non_Standard_Rep (Btype, True);
end if;
end Component_Size_Case;
------------------
-- External_Tag --
------------------
when Attribute_External_Tag => External_Tag :
begin
if not Is_Tagged_Type (U_Ent) then
Error_Msg_N ("should be a tagged type", Nam);
end if;
Analyze_And_Resolve (Expr, Standard_String);
if not Is_Static_Expression (Expr) then
Flag_Non_Static_Expr
("static string required for tag name!", Nam);
end if;
Set_Has_External_Tag_Rep_Clause (U_Ent);
end External_Tag;
-----------
-- Input --
-----------
when Attribute_Input =>
Analyze_Stream_TSS_Definition (TSS_Stream_Input);
Set_Has_Specified_Stream_Input (Ent);
-------------------
-- Machine_Radix --
-------------------
-- Machine radix attribute definition clause
when Attribute_Machine_Radix => Machine_Radix : declare
Radix : constant Uint := Static_Integer (Expr);
begin
if not Is_Decimal_Fixed_Point_Type (U_Ent) then
Error_Msg_N ("decimal fixed-point type expected for &", Nam);
elsif Has_Machine_Radix_Clause (U_Ent) then
Error_Msg_Sloc := Sloc (Alignment_Clause (U_Ent));
Error_Msg_N ("machine radix clause previously given#", N);
elsif Radix /= No_Uint then
Set_Has_Machine_Radix_Clause (U_Ent);
Set_Has_Non_Standard_Rep (Base_Type (U_Ent));
if Radix = 2 then
null;
elsif Radix = 10 then
Set_Machine_Radix_10 (U_Ent);
else
Error_Msg_N ("machine radix value must be 2 or 10", Expr);
end if;
end if;
end Machine_Radix;
-----------------
-- Object_Size --
-----------------
-- Object_Size attribute definition clause
when Attribute_Object_Size => Object_Size : declare
Size : constant Uint := Static_Integer (Expr);
Biased : Boolean;
begin
if not Is_Type (U_Ent) then
Error_Msg_N ("Object_Size cannot be given for &", Nam);
elsif Has_Object_Size_Clause (U_Ent) then
Error_Msg_N ("Object_Size already given for &", Nam);
else
Check_Size (Expr, U_Ent, Size, Biased);
if Size /= 8
and then
Size /= 16
and then
Size /= 32
and then
UI_Mod (Size, 64) /= 0
then
Error_Msg_N
("Object_Size must be 8, 16, 32, or multiple of 64",
Expr);
end if;
Set_Esize (U_Ent, Size);
Set_Has_Object_Size_Clause (U_Ent);
Alignment_Check_For_Esize_Change (U_Ent);
end if;
end Object_Size;
------------
-- Output --
------------
when Attribute_Output =>
Analyze_Stream_TSS_Definition (TSS_Stream_Output);
Set_Has_Specified_Stream_Output (Ent);
----------
-- Read --
----------
when Attribute_Read =>
Analyze_Stream_TSS_Definition (TSS_Stream_Read);
Set_Has_Specified_Stream_Read (Ent);
----------
-- Size --
----------
-- Size attribute definition clause
when Attribute_Size => Size : declare
Size : constant Uint := Static_Integer (Expr);
Etyp : Entity_Id;
Biased : Boolean;
begin
FOnly := True;
if Has_Size_Clause (U_Ent) then
Error_Msg_N ("size already given for &", Nam);
elsif not Is_Type (U_Ent)
and then Ekind (U_Ent) /= E_Variable
and then Ekind (U_Ent) /= E_Constant
then
Error_Msg_N ("size cannot be given for &", Nam);
elsif Is_Array_Type (U_Ent)
and then not Is_Constrained (U_Ent)
then
Error_Msg_N
("size cannot be given for unconstrained array", Nam);
elsif Size /= No_Uint then
if Is_Type (U_Ent) then
Etyp := U_Ent;
else
Etyp := Etype (U_Ent);
end if;
-- Check size, note that Gigi is in charge of checking
-- that the size of an array or record type is OK. Also
-- we do not check the size in the ordinary fixed-point
-- case, since it is too early to do so (there may be a
-- subsequent small clause that affects the size). We can
-- check the size if a small clause has already been given.
if not Is_Ordinary_Fixed_Point_Type (U_Ent)
or else Has_Small_Clause (U_Ent)
then
Check_Size (Expr, Etyp, Size, Biased);
Set_Has_Biased_Representation (U_Ent, Biased);
end if;
-- For types set RM_Size and Esize if possible
if Is_Type (U_Ent) then
Set_RM_Size (U_Ent, Size);
-- For scalar types, increase Object_Size to power of 2,
-- but not less than a storage unit in any case (i.e.,
-- normally this means it will be byte addressable).
if Is_Scalar_Type (U_Ent) then
if Size <= System_Storage_Unit then
Init_Esize (U_Ent, System_Storage_Unit);
elsif Size <= 16 then
Init_Esize (U_Ent, 16);
elsif Size <= 32 then
Init_Esize (U_Ent, 32);
else
Set_Esize (U_Ent, (Size + 63) / 64 * 64);
end if;
-- For all other types, object size = value size. The
-- backend will adjust as needed.
else
Set_Esize (U_Ent, Size);
end if;
Alignment_Check_For_Esize_Change (U_Ent);
-- For objects, set Esize only
else
if Is_Elementary_Type (Etyp) then
if Size /= System_Storage_Unit
and then
Size /= System_Storage_Unit * 2
and then
Size /= System_Storage_Unit * 4
and then
Size /= System_Storage_Unit * 8
then
Error_Msg_Uint_1 := UI_From_Int (System_Storage_Unit);
Error_Msg_Uint_2 := Error_Msg_Uint_1 * 8;
Error_Msg_N
("size for primitive object must be a power of 2"
& " in the range ^-^", N);
end if;
end if;
Set_Esize (U_Ent, Size);
end if;
Set_Has_Size_Clause (U_Ent);
end if;
end Size;
-----------
-- Small --
-----------
-- Small attribute definition clause
when Attribute_Small => Small : declare
Implicit_Base : constant Entity_Id := Base_Type (U_Ent);
Small : Ureal;
begin
Analyze_And_Resolve (Expr, Any_Real);
if Etype (Expr) = Any_Type then
return;
elsif not Is_Static_Expression (Expr) then
Flag_Non_Static_Expr
("small requires static expression!", Expr);
return;
else
Small := Expr_Value_R (Expr);
if Small <= Ureal_0 then
Error_Msg_N ("small value must be greater than zero", Expr);
return;
end if;
end if;
if not Is_Ordinary_Fixed_Point_Type (U_Ent) then
Error_Msg_N
("small requires an ordinary fixed point type", Nam);
elsif Has_Small_Clause (U_Ent) then
Error_Msg_N ("small already given for &", Nam);
elsif Small > Delta_Value (U_Ent) then
Error_Msg_N
("small value must not be greater then delta value", Nam);
else
Set_Small_Value (U_Ent, Small);
Set_Small_Value (Implicit_Base, Small);
Set_Has_Small_Clause (U_Ent);
Set_Has_Small_Clause (Implicit_Base);
Set_Has_Non_Standard_Rep (Implicit_Base);
end if;
end Small;
------------------
-- Storage_Size --
------------------
-- Storage_Size attribute definition clause
when Attribute_Storage_Size => Storage_Size : declare
Btype : constant Entity_Id := Base_Type (U_Ent);
Sprag : Node_Id;
begin
if Is_Task_Type (U_Ent) then
Check_Restriction (No_Obsolescent_Features, N);
if Warn_On_Obsolescent_Feature then
Error_Msg_N
("storage size clause for task is an " &
"obsolescent feature ('R'M 'J.9)?", N);
Error_Msg_N
("\use Storage_Size pragma instead?", N);
end if;
FOnly := True;
end if;
if not Is_Access_Type (U_Ent)
and then Ekind (U_Ent) /= E_Task_Type
then
Error_Msg_N ("storage size cannot be given for &", Nam);
elsif Is_Access_Type (U_Ent) and Is_Derived_Type (U_Ent) then
Error_Msg_N
("storage size cannot be given for a derived access type",
Nam);
elsif Has_Storage_Size_Clause (Btype) then
Error_Msg_N ("storage size already given for &", Nam);
else
Analyze_And_Resolve (Expr, Any_Integer);
if Is_Access_Type (U_Ent) then
if Present (Associated_Storage_Pool (U_Ent)) then
Error_Msg_N ("storage pool already given for &", Nam);
return;
end if;
if Compile_Time_Known_Value (Expr)
and then Expr_Value (Expr) = 0
then
Set_No_Pool_Assigned (Btype);
end if;
else -- Is_Task_Type (U_Ent)
Sprag := Get_Rep_Pragma (Btype, Name_Storage_Size);
if Present (Sprag) then
Error_Msg_Sloc := Sloc (Sprag);
Error_Msg_N
("Storage_Size already specified#", Nam);
return;
end if;
end if;
Set_Has_Storage_Size_Clause (Btype);
end if;
end Storage_Size;
------------------
-- Storage_Pool --
------------------
-- Storage_Pool attribute definition clause
when Attribute_Storage_Pool => Storage_Pool : declare
Pool : Entity_Id;
T : Entity_Id;
begin
if Ekind (U_Ent) /= E_Access_Type
and then Ekind (U_Ent) /= E_General_Access_Type
then
Error_Msg_N (
"storage pool can only be given for access types", Nam);
return;
elsif Is_Derived_Type (U_Ent) then
Error_Msg_N
("storage pool cannot be given for a derived access type",
Nam);
elsif Has_Storage_Size_Clause (U_Ent) then
Error_Msg_N ("storage size already given for &", Nam);
return;
elsif Present (Associated_Storage_Pool (U_Ent)) then
Error_Msg_N ("storage pool already given for &", Nam);
return;
end if;
Analyze_And_Resolve
(Expr, Class_Wide_Type (RTE (RE_Root_Storage_Pool)));
if Nkind (Expr) = N_Type_Conversion then
T := Etype (Expression (Expr));
else
T := Etype (Expr);
end if;
-- The Stack_Bounded_Pool is used internally for implementing
-- access types with a Storage_Size. Since it only work
-- properly when used on one specific type, we need to check
-- that it is not highjacked improperly:
-- type T is access Integer;
-- for T'Storage_Size use n;
-- type Q is access Float;
-- for Q'Storage_Size use T'Storage_Size; -- incorrect
if Base_Type (T) = RTE (RE_Stack_Bounded_Pool) then
Error_Msg_N ("non-sharable internal Pool", Expr);
return;
end if;
-- If the argument is a name that is not an entity name, then
-- we construct a renaming operation to define an entity of
-- type storage pool.
if not Is_Entity_Name (Expr)
and then Is_Object_Reference (Expr)
then
Pool :=
Make_Defining_Identifier (Loc,
Chars => New_Internal_Name ('P'));
declare
Rnode : constant Node_Id :=
Make_Object_Renaming_Declaration (Loc,
Defining_Identifier => Pool,
Subtype_Mark =>
New_Occurrence_Of (Etype (Expr), Loc),
Name => Expr);
begin
Insert_Before (N, Rnode);
Analyze (Rnode);
Set_Associated_Storage_Pool (U_Ent, Pool);
end;
elsif Is_Entity_Name (Expr) then
Pool := Entity (Expr);
-- If pool is a renamed object, get original one. This can
-- happen with an explicit renaming, and within instances.
while Present (Renamed_Object (Pool))
and then Is_Entity_Name (Renamed_Object (Pool))
loop
Pool := Entity (Renamed_Object (Pool));
end loop;
if Present (Renamed_Object (Pool))
and then Nkind (Renamed_Object (Pool)) = N_Type_Conversion
and then Is_Entity_Name (Expression (Renamed_Object (Pool)))
then
Pool := Entity (Expression (Renamed_Object (Pool)));
end if;
Set_Associated_Storage_Pool (U_Ent, Pool);
elsif Nkind (Expr) = N_Type_Conversion
and then Is_Entity_Name (Expression (Expr))
and then Nkind (Original_Node (Expr)) = N_Attribute_Reference
then
Pool := Entity (Expression (Expr));
Set_Associated_Storage_Pool (U_Ent, Pool);
else
Error_Msg_N ("incorrect reference to a Storage Pool", Expr);
return;
end if;
end Storage_Pool;
-----------------
-- Stream_Size --
-----------------
when Attribute_Stream_Size => Stream_Size : declare
Size : constant Uint := Static_Integer (Expr);
begin
if Has_Stream_Size_Clause (U_Ent) then
Error_Msg_N ("Stream_Size already given for &", Nam);
elsif Is_Elementary_Type (U_Ent) then
if Size /= System_Storage_Unit
and then
Size /= System_Storage_Unit * 2
and then
Size /= System_Storage_Unit * 4
and then
Size /= System_Storage_Unit * 8
then
Error_Msg_Uint_1 := UI_From_Int (System_Storage_Unit);
Error_Msg_N
("stream size for elementary type must be a"
& " power of 2 and at least ^", N);
elsif RM_Size (U_Ent) > Size then
Error_Msg_Uint_1 := RM_Size (U_Ent);
Error_Msg_N
("stream size for elementary type must be a"
& " power of 2 and at least ^", N);
end if;
Set_Has_Stream_Size_Clause (U_Ent);
else
Error_Msg_N ("Stream_Size cannot be given for &", Nam);
end if;
end Stream_Size;
----------------
-- Value_Size --
----------------
-- Value_Size attribute definition clause
when Attribute_Value_Size => Value_Size : declare
Size : constant Uint := Static_Integer (Expr);
Biased : Boolean;
begin
if not Is_Type (U_Ent) then
Error_Msg_N ("Value_Size cannot be given for &", Nam);
elsif Present
(Get_Attribute_Definition_Clause
(U_Ent, Attribute_Value_Size))
then
Error_Msg_N ("Value_Size already given for &", Nam);
else
if Is_Elementary_Type (U_Ent) then
Check_Size (Expr, U_Ent, Size, Biased);
Set_Has_Biased_Representation (U_Ent, Biased);
end if;
Set_RM_Size (U_Ent, Size);
end if;
end Value_Size;
-----------
-- Write --
-----------
when Attribute_Write =>
Analyze_Stream_TSS_Definition (TSS_Stream_Write);
Set_Has_Specified_Stream_Write (Ent);
-- All other attributes cannot be set
when others =>
Error_Msg_N
("attribute& cannot be set with definition clause", N);
end case;
-- The test for the type being frozen must be performed after
-- any expression the clause has been analyzed since the expression
-- itself might cause freezing that makes the clause illegal.
if Rep_Item_Too_Late (U_Ent, N, FOnly) then
return;
end if;
end Analyze_Attribute_Definition_Clause;
----------------------------
-- Analyze_Code_Statement --
----------------------------
procedure Analyze_Code_Statement (N : Node_Id) is
HSS : constant Node_Id := Parent (N);
SBody : constant Node_Id := Parent (HSS);
Subp : constant Entity_Id := Current_Scope;
Stmt : Node_Id;
Decl : Node_Id;
StmtO : Node_Id;
DeclO : Node_Id;
begin
-- Analyze and check we get right type, note that this implements the
-- requirement (RM 13.8(1)) that Machine_Code be with'ed, since that
-- is the only way that Asm_Insn could possibly be visible.
Analyze_And_Resolve (Expression (N));
if Etype (Expression (N)) = Any_Type then
return;
elsif Etype (Expression (N)) /= RTE (RE_Asm_Insn) then
Error_Msg_N ("incorrect type for code statement", N);
return;
end if;
-- Make sure we appear in the handled statement sequence of a
-- subprogram (RM 13.8(3)).
if Nkind (HSS) /= N_Handled_Sequence_Of_Statements
or else Nkind (SBody) /= N_Subprogram_Body
then
Error_Msg_N
("code statement can only appear in body of subprogram", N);
return;
end if;
-- Do remaining checks (RM 13.8(3)) if not already done
if not Is_Machine_Code_Subprogram (Subp) then
Set_Is_Machine_Code_Subprogram (Subp);
-- No exception handlers allowed
if Present (Exception_Handlers (HSS)) then
Error_Msg_N
("exception handlers not permitted in machine code subprogram",
First (Exception_Handlers (HSS)));
end if;
-- No declarations other than use clauses and pragmas (we allow
-- certain internally generated declarations as well).
Decl := First (Declarations (SBody));
while Present (Decl) loop
DeclO := Original_Node (Decl);
if Comes_From_Source (DeclO)
and then Nkind (DeclO) /= N_Pragma
and then Nkind (DeclO) /= N_Use_Package_Clause
and then Nkind (DeclO) /= N_Use_Type_Clause
and then Nkind (DeclO) /= N_Implicit_Label_Declaration
then
Error_Msg_N
("this declaration not allowed in machine code subprogram",
DeclO);
end if;
Next (Decl);
end loop;
-- No statements other than code statements, pragmas, and labels.
-- Again we allow certain internally generated statements.
Stmt := First (Statements (HSS));
while Present (Stmt) loop
StmtO := Original_Node (Stmt);
if Comes_From_Source (StmtO)
and then Nkind (StmtO) /= N_Pragma
and then Nkind (StmtO) /= N_Label
and then Nkind (StmtO) /= N_Code_Statement
then
Error_Msg_N
("this statement is not allowed in machine code subprogram",
StmtO);
end if;
Next (Stmt);
end loop;
end if;
end Analyze_Code_Statement;
-----------------------------------------------
-- Analyze_Enumeration_Representation_Clause --
-----------------------------------------------
procedure Analyze_Enumeration_Representation_Clause (N : Node_Id) is
Ident : constant Node_Id := Identifier (N);
Aggr : constant Node_Id := Array_Aggregate (N);
Enumtype : Entity_Id;
Elit : Entity_Id;
Expr : Node_Id;
Assoc : Node_Id;
Choice : Node_Id;
Val : Uint;
Err : Boolean := False;
Lo : constant Uint := Expr_Value (Type_Low_Bound (Universal_Integer));
Hi : constant Uint := Expr_Value (Type_High_Bound (Universal_Integer));
Min : Uint;
Max : Uint;
begin
-- First some basic error checks
Find_Type (Ident);
Enumtype := Entity (Ident);
if Enumtype = Any_Type
or else Rep_Item_Too_Early (Enumtype, N)
then
return;
else
Enumtype := Underlying_Type (Enumtype);
end if;
if not Is_Enumeration_Type (Enumtype) then
Error_Msg_NE
("enumeration type required, found}",
Ident, First_Subtype (Enumtype));
return;
end if;
-- Ignore rep clause on generic actual type. This will already have
-- been flagged on the template as an error, and this is the safest
-- way to ensure we don't get a junk cascaded message in the instance.
if Is_Generic_Actual_Type (Enumtype) then
return;
-- Type must be in current scope
elsif Scope (Enumtype) /= Current_Scope then
Error_Msg_N ("type must be declared in this scope", Ident);
return;
-- Type must be a first subtype
elsif not Is_First_Subtype (Enumtype) then
Error_Msg_N ("cannot give enumeration rep clause for subtype", N);
return;
-- Ignore duplicate rep clause
elsif Has_Enumeration_Rep_Clause (Enumtype) then
Error_Msg_N ("duplicate enumeration rep clause ignored", N);
return;
-- Don't allow rep clause for standard [wide_[wide_]]character
elsif Root_Type (Enumtype) = Standard_Character
or else Root_Type (Enumtype) = Standard_Wide_Character
or else Root_Type (Enumtype) = Standard_Wide_Wide_Character
then
Error_Msg_N ("enumeration rep clause not allowed for this type", N);
return;
-- Check that the expression is a proper aggregate (no parentheses)
elsif Paren_Count (Aggr) /= 0 then
Error_Msg
("extra parentheses surrounding aggregate not allowed",
First_Sloc (Aggr));
return;
-- All tests passed, so set rep clause in place
else
Set_Has_Enumeration_Rep_Clause (Enumtype);
Set_Has_Enumeration_Rep_Clause (Base_Type (Enumtype));
end if;
-- Now we process the aggregate. Note that we don't use the normal
-- aggregate code for this purpose, because we don't want any of the
-- normal expansion activities, and a number of special semantic
-- rules apply (including the component type being any integer type)
Elit := First_Literal (Enumtype);
-- First the positional entries if any
if Present (Expressions (Aggr)) then
Expr := First (Expressions (Aggr));
while Present (Expr) loop
if No (Elit) then
Error_Msg_N ("too many entries in aggregate", Expr);
return;
end if;
Val := Static_Integer (Expr);
-- Err signals that we found some incorrect entries processing
-- the list. The final checks for completeness and ordering are
-- skipped in this case.
if Val = No_Uint then
Err := True;
elsif Val < Lo or else Hi < Val then
Error_Msg_N ("value outside permitted range", Expr);
Err := True;
end if;
Set_Enumeration_Rep (Elit, Val);
Set_Enumeration_Rep_Expr (Elit, Expr);
Next (Expr);
Next (Elit);
end loop;
end if;
-- Now process the named entries if present
if Present (Component_Associations (Aggr)) then
Assoc := First (Component_Associations (Aggr));
while Present (Assoc) loop
Choice := First (Choices (Assoc));
if Present (Next (Choice)) then
Error_Msg_N
("multiple choice not allowed here", Next (Choice));
Err := True;
end if;
if Nkind (Choice) = N_Others_Choice then
Error_Msg_N ("others choice not allowed here", Choice);
Err := True;
elsif Nkind (Choice) = N_Range then
-- ??? should allow zero/one element range here
Error_Msg_N ("range not allowed here", Choice);
Err := True;
else
Analyze_And_Resolve (Choice, Enumtype);
if Is_Entity_Name (Choice)
and then Is_Type (Entity (Choice))
then
Error_Msg_N ("subtype name not allowed here", Choice);
Err := True;
-- ??? should allow static subtype with zero/one entry
elsif Etype (Choice) = Base_Type (Enumtype) then
if not Is_Static_Expression (Choice) then
Flag_Non_Static_Expr
("non-static expression used for choice!", Choice);
Err := True;
else
Elit := Expr_Value_E (Choice);
if Present (Enumeration_Rep_Expr (Elit)) then
Error_Msg_Sloc := Sloc (Enumeration_Rep_Expr (Elit));
Error_Msg_NE
("representation for& previously given#",
Choice, Elit);
Err := True;
end if;
Set_Enumeration_Rep_Expr (Elit, Choice);
Expr := Expression (Assoc);
Val := Static_Integer (Expr);
if Val = No_Uint then
Err := True;
elsif Val < Lo or else Hi < Val then
Error_Msg_N ("value outside permitted range", Expr);
Err := True;
end if;
Set_Enumeration_Rep (Elit, Val);
end if;
end if;
end if;
Next (Assoc);
end loop;
end if;
-- Aggregate is fully processed. Now we check that a full set of
-- representations was given, and that they are in range and in order.
-- These checks are only done if no other errors occurred.
if not Err then
Min := No_Uint;
Max := No_Uint;
Elit := First_Literal (Enumtype);
while Present (Elit) loop
if No (Enumeration_Rep_Expr (Elit)) then
Error_Msg_NE ("missing representation for&!", N, Elit);
else
Val := Enumeration_Rep (Elit);
if Min = No_Uint then
Min := Val;
end if;
if Val /= No_Uint then
if Max /= No_Uint and then Val <= Max then
Error_Msg_NE
("enumeration value for& not ordered!",
Enumeration_Rep_Expr (Elit), Elit);
end if;
Max := Val;
end if;
-- If there is at least one literal whose representation
-- is not equal to the Pos value, then note that this
-- enumeration type has a non-standard representation.
if Val /= Enumeration_Pos (Elit) then
Set_Has_Non_Standard_Rep (Base_Type (Enumtype));
end if;
end if;
Next (Elit);
end loop;
-- Now set proper size information
declare
Minsize : Uint := UI_From_Int (Minimum_Size (Enumtype));
begin
if Has_Size_Clause (Enumtype) then
if Esize (Enumtype) >= Minsize then
null;
else
Minsize :=
UI_From_Int (Minimum_Size (Enumtype, Biased => True));
if Esize (Enumtype) < Minsize then
Error_Msg_N ("previously given size is too small", N);
else
Set_Has_Biased_Representation (Enumtype);
end if;
end if;
else
Set_RM_Size (Enumtype, Minsize);
Set_Enum_Esize (Enumtype);
end if;
Set_RM_Size (Base_Type (Enumtype), RM_Size (Enumtype));
Set_Esize (Base_Type (Enumtype), Esize (Enumtype));
Set_Alignment (Base_Type (Enumtype), Alignment (Enumtype));
end;
end if;
-- We repeat the too late test in case it froze itself!
if Rep_Item_Too_Late (Enumtype, N) then
null;
end if;
end Analyze_Enumeration_Representation_Clause;
----------------------------
-- Analyze_Free_Statement --
----------------------------
procedure Analyze_Free_Statement (N : Node_Id) is
begin
Analyze (Expression (N));
end Analyze_Free_Statement;
------------------------------------------
-- Analyze_Record_Representation_Clause --
------------------------------------------
procedure Analyze_Record_Representation_Clause (N : Node_Id) is
Loc : constant Source_Ptr := Sloc (N);
Ident : constant Node_Id := Identifier (N);
Rectype : Entity_Id;
Fent : Entity_Id;
CC : Node_Id;
Posit : Uint;
Fbit : Uint;
Lbit : Uint;
Hbit : Uint := Uint_0;
Comp : Entity_Id;
Ocomp : Entity_Id;
Biased : Boolean;
Max_Bit_So_Far : Uint;
-- Records the maximum bit position so far. If all field positions
-- are monotonically increasing, then we can skip the circuit for
-- checking for overlap, since no overlap is possible.
Overlap_Check_Required : Boolean;
-- Used to keep track of whether or not an overlap check is required
Ccount : Natural := 0;
-- Number of component clauses in record rep clause
CR_Pragma : Node_Id := Empty;
-- Points to N_Pragma node if Complete_Representation pragma present
begin
Find_Type (Ident);
Rectype := Entity (Ident);
if Rectype = Any_Type
or else Rep_Item_Too_Early (Rectype, N)
then
return;
else
Rectype := Underlying_Type (Rectype);
end if;
-- First some basic error checks
if not Is_Record_Type (Rectype) then
Error_Msg_NE
("record type required, found}", Ident, First_Subtype (Rectype));
return;
elsif Is_Unchecked_Union (Rectype) then
Error_Msg_N
("record rep clause not allowed for Unchecked_Union", N);
elsif Scope (Rectype) /= Current_Scope then
Error_Msg_N ("type must be declared in this scope", N);
return;
elsif not Is_First_Subtype (Rectype) then
Error_Msg_N ("cannot give record rep clause for subtype", N);
return;
elsif Has_Record_Rep_Clause (Rectype) then
Error_Msg_N ("duplicate record rep clause ignored", N);
return;
elsif Rep_Item_Too_Late (Rectype, N) then
return;
end if;
if Present (Mod_Clause (N)) then
declare
Loc : constant Source_Ptr := Sloc (N);
M : constant Node_Id := Mod_Clause (N);
P : constant List_Id := Pragmas_Before (M);
AtM_Nod : Node_Id;
Mod_Val : Uint;
pragma Warnings (Off, Mod_Val);
begin
Check_Restriction (No_Obsolescent_Features, Mod_Clause (N));
if Warn_On_Obsolescent_Feature then
Error_Msg_N
("mod clause is an obsolescent feature ('R'M 'J.8)?", N);
Error_Msg_N
("\use alignment attribute definition clause instead?", N);
end if;
if Present (P) then
Analyze_List (P);
end if;
-- In ASIS_Mode mode, expansion is disabled, but we must
-- convert the Mod clause into an alignment clause anyway, so
-- that the back-end can compute and back-annotate properly the
-- size and alignment of types that may include this record.
if Operating_Mode = Check_Semantics
and then ASIS_Mode
then
AtM_Nod :=
Make_Attribute_Definition_Clause (Loc,
Name => New_Reference_To (Base_Type (Rectype), Loc),
Chars => Name_Alignment,
Expression => Relocate_Node (Expression (M)));
Set_From_At_Mod (AtM_Nod);
Insert_After (N, AtM_Nod);
Mod_Val := Get_Alignment_Value (Expression (AtM_Nod));
Set_Mod_Clause (N, Empty);
else
-- Get the alignment value to perform error checking
Mod_Val := Get_Alignment_Value (Expression (M));
end if;
end;
end if;
-- Clear any existing component clauses for the type (this happens
-- with derived types, where we are now overriding the original)
Fent := First_Entity (Rectype);
Comp := Fent;
while Present (Comp) loop
if Ekind (Comp) = E_Component
or else Ekind (Comp) = E_Discriminant
then
Set_Component_Clause (Comp, Empty);
end if;
Next_Entity (Comp);
end loop;
-- All done if no component clauses
CC := First (Component_Clauses (N));
if No (CC) then
return;
end if;
-- If a tag is present, then create a component clause that places
-- it at the start of the record (otherwise gigi may place it after
-- other fields that have rep clauses).
if Nkind (Fent) = N_Defining_Identifier
and then Chars (Fent) = Name_uTag
then
Set_Component_Bit_Offset (Fent, Uint_0);
Set_Normalized_Position (Fent, Uint_0);
Set_Normalized_First_Bit (Fent, Uint_0);
Set_Normalized_Position_Max (Fent, Uint_0);
Init_Esize (Fent, System_Address_Size);
Set_Component_Clause (Fent,
Make_Component_Clause (Loc,
Component_Name =>
Make_Identifier (Loc,
Chars => Name_uTag),
Position =>
Make_Integer_Literal (Loc,
Intval => Uint_0),
First_Bit =>
Make_Integer_Literal (Loc,
Intval => Uint_0),
Last_Bit =>
Make_Integer_Literal (Loc,
UI_From_Int (System_Address_Size))));
Ccount := Ccount + 1;
end if;
-- A representation like this applies to the base type
Set_Has_Record_Rep_Clause (Base_Type (Rectype));
Set_Has_Non_Standard_Rep (Base_Type (Rectype));
Set_Has_Specified_Layout (Base_Type (Rectype));
Max_Bit_So_Far := Uint_Minus_1;
Overlap_Check_Required := False;
-- Process the component clauses
while Present (CC) loop
-- Pragma
if Nkind (CC) = N_Pragma then
Analyze (CC);
-- The only pragma of interest is Complete_Representation
if Chars (CC) = Name_Complete_Representation then
CR_Pragma := CC;
end if;
-- Processing for real component clause
else
Ccount := Ccount + 1;
Posit := Static_Integer (Position (CC));
Fbit := Static_Integer (First_Bit (CC));
Lbit := Static_Integer (Last_Bit (CC));
if Posit /= No_Uint
and then Fbit /= No_Uint
and then Lbit /= No_Uint
then
if Posit < 0 then
Error_Msg_N
("position cannot be negative", Position (CC));
elsif Fbit < 0 then
Error_Msg_N
("first bit cannot be negative", First_Bit (CC));
-- Values look OK, so find the corresponding record component
-- Even though the syntax allows an attribute reference for
-- implementation-defined components, GNAT does not allow the
-- tag to get an explicit position.
elsif Nkind (Component_Name (CC)) = N_Attribute_Reference then
if Attribute_Name (Component_Name (CC)) = Name_Tag then
Error_Msg_N ("position of tag cannot be specified", CC);
else
Error_Msg_N ("illegal component name", CC);
end if;
else
Comp := First_Entity (Rectype);
while Present (Comp) loop
exit when Chars (Comp) = Chars (Component_Name (CC));
Next_Entity (Comp);
end loop;
if No (Comp) then
-- Maybe component of base type that is absent from
-- statically constrained first subtype.
Comp := First_Entity (Base_Type (Rectype));
while Present (Comp) loop
exit when Chars (Comp) = Chars (Component_Name (CC));
Next_Entity (Comp);
end loop;
end if;
if No (Comp) then
Error_Msg_N
("component clause is for non-existent field", CC);
elsif Present (Component_Clause (Comp)) then
Error_Msg_Sloc := Sloc (Component_Clause (Comp));
Error_Msg_N
("component clause previously given#", CC);
else
-- Update Fbit and Lbit to the actual bit number
Fbit := Fbit + UI_From_Int (SSU) * Posit;
Lbit := Lbit + UI_From_Int (SSU) * Posit;
if Fbit <= Max_Bit_So_Far then
Overlap_Check_Required := True;
else
Max_Bit_So_Far := Lbit;
end if;
if Has_Size_Clause (Rectype)
and then Esize (Rectype) <= Lbit
then
Error_Msg_N
("bit number out of range of specified size",
Last_Bit (CC));
else
Set_Component_Clause (Comp, CC);
Set_Component_Bit_Offset (Comp, Fbit);
Set_Esize (Comp, 1 + (Lbit - Fbit));
Set_Normalized_First_Bit (Comp, Fbit mod SSU);
Set_Normalized_Position (Comp, Fbit / SSU);
Set_Normalized_Position_Max
(Fent, Normalized_Position (Fent));
if Is_Tagged_Type (Rectype)
and then Fbit < System_Address_Size
then
Error_Msg_NE
("component overlaps tag field of&",
CC, Rectype);
end if;
-- This information is also set in the corresponding
-- component of the base type, found by accessing the
-- Original_Record_Component link if it is present.
Ocomp := Original_Record_Component (Comp);
if Hbit < Lbit then
Hbit := Lbit;
end if;
Check_Size
(Component_Name (CC),
Etype (Comp),
Esize (Comp),
Biased);
Set_Has_Biased_Representation (Comp, Biased);
if Present (Ocomp) then
Set_Component_Clause (Ocomp, CC);
Set_Component_Bit_Offset (Ocomp, Fbit);
Set_Normalized_First_Bit (Ocomp, Fbit mod SSU);
Set_Normalized_Position (Ocomp, Fbit / SSU);
Set_Esize (Ocomp, 1 + (Lbit - Fbit));
Set_Normalized_Position_Max
(Ocomp, Normalized_Position (Ocomp));
Set_Has_Biased_Representation
(Ocomp, Has_Biased_Representation (Comp));
end if;
if Esize (Comp) < 0 then
Error_Msg_N ("component size is negative", CC);
end if;
end if;
end if;
end if;
end if;
end if;
Next (CC);
end loop;
-- Now that we have processed all the component clauses, check for
-- overlap. We have to leave this till last, since the components
-- can appear in any arbitrary order in the representation clause.
-- We do not need this check if all specified ranges were monotonic,
-- as recorded by Overlap_Check_Required being False at this stage.
-- This first section checks if there are any overlapping entries
-- at all. It does this by sorting all entries and then seeing if
-- there are any overlaps. If there are none, then that is decisive,
-- but if there are overlaps, they may still be OK (they may result
-- from fields in different variants).
if Overlap_Check_Required then
Overlap_Check1 : declare
OC_Fbit : array (0 .. Ccount) of Uint;
-- First-bit values for component clauses, the value is the
-- offset of the first bit of the field from start of record.
-- The zero entry is for use in sorting.
OC_Lbit : array (0 .. Ccount) of Uint;
-- Last-bit values for component clauses, the value is the
-- offset of the last bit of the field from start of record.
-- The zero entry is for use in sorting.
OC_Count : Natural := 0;
-- Count of entries in OC_Fbit and OC_Lbit
function OC_Lt (Op1, Op2 : Natural) return Boolean;
-- Compare routine for Sort (See GNAT.Heap_Sort_A)
procedure OC_Move (From : Natural; To : Natural);
-- Move routine for Sort (see GNAT.Heap_Sort_A)
function OC_Lt (Op1, Op2 : Natural) return Boolean is
begin
return OC_Fbit (Op1) < OC_Fbit (Op2);
end OC_Lt;
procedure OC_Move (From : Natural; To : Natural) is
begin
OC_Fbit (To) := OC_Fbit (From);
OC_Lbit (To) := OC_Lbit (From);
end OC_Move;
begin
CC := First (Component_Clauses (N));
while Present (CC) loop
if Nkind (CC) /= N_Pragma then
Posit := Static_Integer (Position (CC));
Fbit := Static_Integer (First_Bit (CC));
Lbit := Static_Integer (Last_Bit (CC));
if Posit /= No_Uint
and then Fbit /= No_Uint
and then Lbit /= No_Uint
then
OC_Count := OC_Count + 1;
Posit := Posit * SSU;
OC_Fbit (OC_Count) := Fbit + Posit;
OC_Lbit (OC_Count) := Lbit + Posit;
end if;
end if;
Next (CC);
end loop;
Sort
(OC_Count,
OC_Move'Unrestricted_Access,
OC_Lt'Unrestricted_Access);
Overlap_Check_Required := False;
for J in 1 .. OC_Count - 1 loop
if OC_Lbit (J) >= OC_Fbit (J + 1) then
Overlap_Check_Required := True;
exit;
end if;
end loop;
end Overlap_Check1;
end if;
-- If Overlap_Check_Required is still True, then we have to do
-- the full scale overlap check, since we have at least two fields
-- that do overlap, and we need to know if that is OK since they
-- are in the same variant, or whether we have a definite problem
if Overlap_Check_Required then
Overlap_Check2 : declare
C1_Ent, C2_Ent : Entity_Id;
-- Entities of components being checked for overlap
Clist : Node_Id;
-- Component_List node whose Component_Items are being checked
Citem : Node_Id;
-- Component declaration for component being checked
begin
C1_Ent := First_Entity (Base_Type (Rectype));
-- Loop through all components in record. For each component check
-- for overlap with any of the preceding elements on the component
-- list containing the component, and also, if the component is in
-- a variant, check against components outside the case structure.
-- This latter test is repeated recursively up the variant tree.
Main_Component_Loop : while Present (C1_Ent) loop
if Ekind (C1_Ent) /= E_Component
and then Ekind (C1_Ent) /= E_Discriminant
then
goto Continue_Main_Component_Loop;
end if;
-- Skip overlap check if entity has no declaration node. This
-- happens with discriminants in constrained derived types.
-- Probably we are missing some checks as a result, but that
-- does not seem terribly serious ???
if No (Declaration_Node (C1_Ent)) then
goto Continue_Main_Component_Loop;
end if;
Clist := Parent (List_Containing (Declaration_Node (C1_Ent)));
-- Loop through component lists that need checking. Check the
-- current component list and all lists in variants above us.
Component_List_Loop : loop
-- If derived type definition, go to full declaration
-- If at outer level, check discriminants if there are any
if Nkind (Clist) = N_Derived_Type_Definition then
Clist := Parent (Clist);
end if;
-- Outer level of record definition, check discriminants
if Nkind (Clist) = N_Full_Type_Declaration
or else Nkind (Clist) = N_Private_Type_Declaration
then
if Has_Discriminants (Defining_Identifier (Clist)) then
C2_Ent :=
First_Discriminant (Defining_Identifier (Clist));
while Present (C2_Ent) loop
exit when C1_Ent = C2_Ent;
Check_Component_Overlap (C1_Ent, C2_Ent);
Next_Discriminant (C2_Ent);
end loop;
end if;
-- Record extension case
elsif Nkind (Clist) = N_Derived_Type_Definition then
Clist := Empty;
-- Otherwise check one component list
else
Citem := First (Component_Items (Clist));
while Present (Citem) loop
if Nkind (Citem) = N_Component_Declaration then
C2_Ent := Defining_Identifier (Citem);
exit when C1_Ent = C2_Ent;
Check_Component_Overlap (C1_Ent, C2_Ent);
end if;
Next (Citem);
end loop;
end if;
-- Check for variants above us (the parent of the Clist can
-- be a variant, in which case its parent is a variant part,
-- and the parent of the variant part is a component list
-- whose components must all be checked against the current
-- component for overlap.
if Nkind (Parent (Clist)) = N_Variant then
Clist := Parent (Parent (Parent (Clist)));
-- Check for possible discriminant part in record, this is
-- treated essentially as another level in the recursion.
-- For this case we have the parent of the component list
-- is the record definition, and its parent is the full
-- type declaration which contains the discriminant
-- specifications.
elsif Nkind (Parent (Clist)) = N_Record_Definition then
Clist := Parent (Parent ((Clist)));
-- If neither of these two cases, we are at the top of
-- the tree
else
exit Component_List_Loop;
end if;
end loop Component_List_Loop;
<<Continue_Main_Component_Loop>>
Next_Entity (C1_Ent);
end loop Main_Component_Loop;
end Overlap_Check2;
end if;
-- For records that have component clauses for all components, and
-- whose size is less than or equal to 32, we need to know the size
-- in the front end to activate possible packed array processing
-- where the component type is a record.
-- At this stage Hbit + 1 represents the first unused bit from all
-- the component clauses processed, so if the component clauses are
-- complete, then this is the length of the record.
-- For records longer than System.Storage_Unit, and for those where
-- not all components have component clauses, the back end determines
-- the length (it may for example be appopriate to round up the size
-- to some convenient boundary, based on alignment considerations etc).
if Unknown_RM_Size (Rectype)
and then Hbit + 1 <= 32
then
-- Nothing to do if at least one component with no component clause
Comp := First_Entity (Rectype);
while Present (Comp) loop
if Ekind (Comp) = E_Component
or else Ekind (Comp) = E_Discriminant
then
exit when No (Component_Clause (Comp));
end if;
Next_Entity (Comp);
end loop;
-- If we fall out of loop, all components have component clauses
-- and so we can set the size to the maximum value.
if No (Comp) then
Set_RM_Size (Rectype, Hbit + 1);
end if;
end if;
-- Check missing components if Complete_Representation pragma appeared
if Present (CR_Pragma) then
Comp := First_Entity (Rectype);
while Present (Comp) loop
if Ekind (Comp) = E_Component
or else
Ekind (Comp) = E_Discriminant
then
if No (Component_Clause (Comp)) then
Error_Msg_NE
("missing component clause for &", CR_Pragma, Comp);
end if;
end if;
Next_Entity (Comp);
end loop;
end if;
end Analyze_Record_Representation_Clause;
-----------------------------
-- Check_Component_Overlap --
-----------------------------
procedure Check_Component_Overlap (C1_Ent, C2_Ent : Entity_Id) is
begin
if Present (Component_Clause (C1_Ent))
and then Present (Component_Clause (C2_Ent))
then
-- Exclude odd case where we have two tag fields in the same
-- record, both at location zero. This seems a bit strange,
-- but it seems to happen in some circumstances ???
if Chars (C1_Ent) = Name_uTag
and then Chars (C2_Ent) = Name_uTag
then
return;
end if;
-- Here we check if the two fields overlap
declare
S1 : constant Uint := Component_Bit_Offset (C1_Ent);
S2 : constant Uint := Component_Bit_Offset (C2_Ent);
E1 : constant Uint := S1 + Esize (C1_Ent);
E2 : constant Uint := S2 + Esize (C2_Ent);
begin
if E2 <= S1 or else E1 <= S2 then
null;
else
Error_Msg_Node_2 :=
Component_Name (Component_Clause (C2_Ent));
Error_Msg_Sloc := Sloc (Error_Msg_Node_2);
Error_Msg_Node_1 :=
Component_Name (Component_Clause (C1_Ent));
Error_Msg_N
("component& overlaps & #",
Component_Name (Component_Clause (C1_Ent)));
end if;
end;
end if;
end Check_Component_Overlap;
-----------------------------------
-- Check_Constant_Address_Clause --
-----------------------------------
procedure Check_Constant_Address_Clause
(Expr : Node_Id;
U_Ent : Entity_Id)
is
procedure Check_At_Constant_Address (Nod : Node_Id);
-- Checks that the given node N represents a name whose 'Address
-- is constant (in the same sense as OK_Constant_Address_Clause,
-- i.e. the address value is the same at the point of declaration
-- of U_Ent and at the time of elaboration of the address clause.
procedure Check_Expr_Constants (Nod : Node_Id);
-- Checks that Nod meets the requirements for a constant address
-- clause in the sense of the enclosing procedure.
procedure Check_List_Constants (Lst : List_Id);
-- Check that all elements of list Lst meet the requirements for a
-- constant address clause in the sense of the enclosing procedure.
-------------------------------
-- Check_At_Constant_Address --
-------------------------------
procedure Check_At_Constant_Address (Nod : Node_Id) is
begin
if Is_Entity_Name (Nod) then
if Present (Address_Clause (Entity ((Nod)))) then
Error_Msg_NE
("invalid address clause for initialized object &!",
Nod, U_Ent);
Error_Msg_NE
("address for& cannot" &
" depend on another address clause! ('R'M 13.1(22))!",
Nod, U_Ent);
elsif In_Same_Source_Unit (Entity (Nod), U_Ent)
and then Sloc (U_Ent) < Sloc (Entity (Nod))
then
Error_Msg_NE
("invalid address clause for initialized object &!",
Nod, U_Ent);
Error_Msg_Name_1 := Chars (Entity (Nod));
Error_Msg_Name_2 := Chars (U_Ent);
Error_Msg_N
("\% must be defined before % ('R'M 13.1(22))!",
Nod);
end if;
elsif Nkind (Nod) = N_Selected_Component then
declare
T : constant Entity_Id := Etype (Prefix (Nod));
begin
if (Is_Record_Type (T)
and then Has_Discriminants (T))
or else
(Is_Access_Type (T)
and then Is_Record_Type (Designated_Type (T))
and then Has_Discriminants (Designated_Type (T)))
then
Error_Msg_NE
("invalid address clause for initialized object &!",
Nod, U_Ent);
Error_Msg_N
("\address cannot depend on component" &
" of discriminated record ('R'M 13.1(22))!",
Nod);
else
Check_At_Constant_Address (Prefix (Nod));
end if;
end;
elsif Nkind (Nod) = N_Indexed_Component then
Check_At_Constant_Address (Prefix (Nod));
Check_List_Constants (Expressions (Nod));
else
Check_Expr_Constants (Nod);
end if;
end Check_At_Constant_Address;
--------------------------
-- Check_Expr_Constants --
--------------------------
procedure Check_Expr_Constants (Nod : Node_Id) is
Loc_U_Ent : constant Source_Ptr := Sloc (U_Ent);
Ent : Entity_Id := Empty;
begin
if Nkind (Nod) in N_Has_Etype
and then Etype (Nod) = Any_Type
then
return;
end if;
case Nkind (Nod) is
when N_Empty | N_Error =>
return;
when N_Identifier | N_Expanded_Name =>
Ent := Entity (Nod);
-- We need to look at the original node if it is different
-- from the node, since we may have rewritten things and
-- substituted an identifier representing the rewrite.
if Original_Node (Nod) /= Nod then
Check_Expr_Constants (Original_Node (Nod));
-- If the node is an object declaration without initial
-- value, some code has been expanded, and the expression
-- is not constant, even if the constituents might be
-- acceptable, as in A'Address + offset.
if Ekind (Ent) = E_Variable
and then Nkind (Declaration_Node (Ent))
= N_Object_Declaration
and then
No (Expression (Declaration_Node (Ent)))
then
Error_Msg_NE
("invalid address clause for initialized object &!",
Nod, U_Ent);
-- If entity is constant, it may be the result of expanding
-- a check. We must verify that its declaration appears
-- before the object in question, else we also reject the
-- address clause.
elsif Ekind (Ent) = E_Constant
and then In_Same_Source_Unit (Ent, U_Ent)
and then Sloc (Ent) > Loc_U_Ent
then
Error_Msg_NE
("invalid address clause for initialized object &!",
Nod, U_Ent);
end if;
return;
end if;
-- Otherwise look at the identifier and see if it is OK
if Ekind (Ent) = E_Named_Integer
or else
Ekind (Ent) = E_Named_Real
or else
Is_Type (Ent)
then
return;
elsif
Ekind (Ent) = E_Constant
or else
Ekind (Ent) = E_In_Parameter
then
-- This is the case where we must have Ent defined
-- before U_Ent. Clearly if they are in different
-- units this requirement is met since the unit
-- containing Ent is already processed.
if not In_Same_Source_Unit (Ent, U_Ent) then
return;
-- Otherwise location of Ent must be before the
-- location of U_Ent, that's what prior defined means.
elsif Sloc (Ent) < Loc_U_Ent then
return;
else
Error_Msg_NE
("invalid address clause for initialized object &!",
Nod, U_Ent);
Error_Msg_Name_1 := Chars (Ent);
Error_Msg_Name_2 := Chars (U_Ent);
Error_Msg_N
("\% must be defined before % ('R'M 13.1(22))!",
Nod);
end if;
elsif Nkind (Original_Node (Nod)) = N_Function_Call then
Check_Expr_Constants (Original_Node (Nod));
else
Error_Msg_NE
("invalid address clause for initialized object &!",
Nod, U_Ent);
if Comes_From_Source (Ent) then
Error_Msg_Name_1 := Chars (Ent);
Error_Msg_N
("\reference to variable% not allowed"
& " ('R'M 13.1(22))!", Nod);
else
Error_Msg_N
("non-static expression not allowed"
& " ('R'M 13.1(22))!", Nod);
end if;
end if;
when N_Integer_Literal =>
-- If this is a rewritten unchecked conversion, in a system
-- where Address is an integer type, always use the base type
-- for a literal value. This is user-friendly and prevents
-- order-of-elaboration issues with instances of unchecked
-- conversion.
if Nkind (Original_Node (Nod)) = N_Function_Call then
Set_Etype (Nod, Base_Type (Etype (Nod)));
end if;
when N_Real_Literal |
N_String_Literal |
N_Character_Literal =>
return;
when N_Range =>
Check_Expr_Constants (Low_Bound (Nod));
Check_Expr_Constants (High_Bound (Nod));
when N_Explicit_Dereference =>
Check_Expr_Constants (Prefix (Nod));
when N_Indexed_Component =>
Check_Expr_Constants (Prefix (Nod));
Check_List_Constants (Expressions (Nod));
when N_Slice =>
Check_Expr_Constants (Prefix (Nod));
Check_Expr_Constants (Discrete_Range (Nod));
when N_Selected_Component =>
Check_Expr_Constants (Prefix (Nod));
when N_Attribute_Reference =>
if Attribute_Name (Nod) = Name_Address
or else
Attribute_Name (Nod) = Name_Access
or else
Attribute_Name (Nod) = Name_Unchecked_Access
or else
Attribute_Name (Nod) = Name_Unrestricted_Access
then
Check_At_Constant_Address (Prefix (Nod));
else
Check_Expr_Constants (Prefix (Nod));
Check_List_Constants (Expressions (Nod));
end if;
when N_Aggregate =>
Check_List_Constants (Component_Associations (Nod));
Check_List_Constants (Expressions (Nod));
when N_Component_Association =>
Check_Expr_Constants (Expression (Nod));
when N_Extension_Aggregate =>
Check_Expr_Constants (Ancestor_Part (Nod));
Check_List_Constants (Component_Associations (Nod));
Check_List_Constants (Expressions (Nod));
when N_Null =>
return;
when N_Binary_Op | N_And_Then | N_Or_Else | N_In | N_Not_In =>
Check_Expr_Constants (Left_Opnd (Nod));
Check_Expr_Constants (Right_Opnd (Nod));
when N_Unary_Op =>
Check_Expr_Constants (Right_Opnd (Nod));
when N_Type_Conversion |
N_Qualified_Expression |
N_Allocator =>
Check_Expr_Constants (Expression (Nod));
when N_Unchecked_Type_Conversion =>
Check_Expr_Constants (Expression (Nod));
-- If this is a rewritten unchecked conversion, subtypes
-- in this node are those created within the instance.
-- To avoid order of elaboration issues, replace them
-- with their base types. Note that address clauses can
-- cause order of elaboration problems because they are
-- elaborated by the back-end at the point of definition,
-- and may mention entities declared in between (as long
-- as everything is static). It is user-friendly to allow
-- unchecked conversions in this context.
if Nkind (Original_Node (Nod)) = N_Function_Call then
Set_Etype (Expression (Nod),
Base_Type (Etype (Expression (Nod))));
Set_Etype (Nod, Base_Type (Etype (Nod)));
end if;
when N_Function_Call =>
if not Is_Pure (Entity (Name (Nod))) then
Error_Msg_NE
("invalid address clause for initialized object &!",
Nod, U_Ent);
Error_Msg_NE
("\function & is not pure ('R'M 13.1(22))!",
Nod, Entity (Name (Nod)));
else
Check_List_Constants (Parameter_Associations (Nod));
end if;
when N_Parameter_Association =>
Check_Expr_Constants (Explicit_Actual_Parameter (Nod));
when others =>
Error_Msg_NE
("invalid address clause for initialized object &!",
Nod, U_Ent);
Error_Msg_NE
("\must be constant defined before& ('R'M 13.1(22))!",
Nod, U_Ent);
end case;
end Check_Expr_Constants;
--------------------------
-- Check_List_Constants --
--------------------------
procedure Check_List_Constants (Lst : List_Id) is
Nod1 : Node_Id;
begin
if Present (Lst) then
Nod1 := First (Lst);
while Present (Nod1) loop
Check_Expr_Constants (Nod1);
Next (Nod1);
end loop;
end if;
end Check_List_Constants;
-- Start of processing for Check_Constant_Address_Clause
begin
Check_Expr_Constants (Expr);
end Check_Constant_Address_Clause;
----------------
-- Check_Size --
----------------
procedure Check_Size
(N : Node_Id;
T : Entity_Id;
Siz : Uint;
Biased : out Boolean)
is
UT : constant Entity_Id := Underlying_Type (T);
M : Uint;
begin
Biased := False;
-- Dismiss cases for generic types or types with previous errors
if No (UT)
or else UT = Any_Type
or else Is_Generic_Type (UT)
or else Is_Generic_Type (Root_Type (UT))
then
return;
-- Check case of bit packed array
elsif Is_Array_Type (UT)
and then Known_Static_Component_Size (UT)
and then Is_Bit_Packed_Array (UT)
then
declare
Asiz : Uint;
Indx : Node_Id;
Ityp : Entity_Id;
begin
Asiz := Component_Size (UT);
Indx := First_Index (UT);
loop
Ityp := Etype (Indx);
-- If non-static bound, then we are not in the business of
-- trying to check the length, and indeed an error will be
-- issued elsewhere, since sizes of non-static array types
-- cannot be set implicitly or explicitly.
if not Is_Static_Subtype (Ityp) then
return;
end if;
-- Otherwise accumulate next dimension
Asiz := Asiz * (Expr_Value (Type_High_Bound (Ityp)) -
Expr_Value (Type_Low_Bound (Ityp)) +
Uint_1);
Next_Index (Indx);
exit when No (Indx);
end loop;
if Asiz <= Siz then
return;
else
Error_Msg_Uint_1 := Asiz;
Error_Msg_NE
("size for& too small, minimum allowed is ^", N, T);
Set_Esize (T, Asiz);
Set_RM_Size (T, Asiz);
end if;
end;
-- All other composite types are ignored
elsif Is_Composite_Type (UT) then
return;
-- For fixed-point types, don't check minimum if type is not frozen,
-- since we don't know all the characteristics of the type that can
-- affect the size (e.g. a specified small) till freeze time.
elsif Is_Fixed_Point_Type (UT)
and then not Is_Frozen (UT)
then
null;
-- Cases for which a minimum check is required
else
-- Ignore if specified size is correct for the type
if Known_Esize (UT) and then Siz = Esize (UT) then
return;
end if;
-- Otherwise get minimum size
M := UI_From_Int (Minimum_Size (UT));
if Siz < M then
-- Size is less than minimum size, but one possibility remains
-- that we can manage with the new size if we bias the type
M := UI_From_Int (Minimum_Size (UT, Biased => True));
if Siz < M then
Error_Msg_Uint_1 := M;
Error_Msg_NE
("size for& too small, minimum allowed is ^", N, T);
Set_Esize (T, M);
Set_RM_Size (T, M);
else
Biased := True;
end if;
end if;
end if;
end Check_Size;
-------------------------
-- Get_Alignment_Value --
-------------------------
function Get_Alignment_Value (Expr : Node_Id) return Uint is
Align : constant Uint := Static_Integer (Expr);
begin
if Align = No_Uint then
return No_Uint;
elsif Align <= 0 then
Error_Msg_N ("alignment value must be positive", Expr);
return No_Uint;
else
for J in Int range 0 .. 64 loop
declare
M : constant Uint := Uint_2 ** J;
begin
exit when M = Align;
if M > Align then
Error_Msg_N
("alignment value must be power of 2", Expr);
return No_Uint;
end if;
end;
end loop;
return Align;
end if;
end Get_Alignment_Value;
----------------
-- Initialize --
----------------
procedure Initialize is
begin
Unchecked_Conversions.Init;
end Initialize;
-------------------------
-- Is_Operational_Item --
-------------------------
function Is_Operational_Item (N : Node_Id) return Boolean is
begin
if Nkind (N) /= N_Attribute_Definition_Clause then
return False;
else
declare
Id : constant Attribute_Id := Get_Attribute_Id (Chars (N));
begin
return Id = Attribute_Input
or else Id = Attribute_Output
or else Id = Attribute_Read
or else Id = Attribute_Write
or else Id = Attribute_External_Tag;
end;
end if;
end Is_Operational_Item;
--------------------------------------
-- Mark_Aliased_Address_As_Volatile --
--------------------------------------
procedure Mark_Aliased_Address_As_Volatile (N : Node_Id) is
Ent : constant Entity_Id := Address_Aliased_Entity (N);
begin
if Present (Ent) then
Set_Treat_As_Volatile (Ent);
end if;
end Mark_Aliased_Address_As_Volatile;
------------------
-- Minimum_Size --
------------------
function Minimum_Size
(T : Entity_Id;
Biased : Boolean := False) return Nat
is
Lo : Uint := No_Uint;
Hi : Uint := No_Uint;
LoR : Ureal := No_Ureal;
HiR : Ureal := No_Ureal;
LoSet : Boolean := False;
HiSet : Boolean := False;
B : Uint;
S : Nat;
Ancest : Entity_Id;
R_Typ : constant Entity_Id := Root_Type (T);
begin
-- If bad type, return 0
if T = Any_Type then
return 0;
-- For generic types, just return zero. There cannot be any legitimate
-- need to know such a size, but this routine may be called with a
-- generic type as part of normal processing.
elsif Is_Generic_Type (R_Typ)
or else R_Typ = Any_Type
then
return 0;
-- Access types. Normally an access type cannot have a size smaller
-- than the size of System.Address. The exception is on VMS, where
-- we have short and long addresses, and it is possible for an access
-- type to have a short address size (and thus be less than the size
-- of System.Address itself). We simply skip the check for VMS, and
-- leave the back end to do the check.
elsif Is_Access_Type (T) then
if OpenVMS_On_Target then
return 0;
else
return System_Address_Size;
end if;
-- Floating-point types
elsif Is_Floating_Point_Type (T) then
return UI_To_Int (Esize (R_Typ));
-- Discrete types
elsif Is_Discrete_Type (T) then
-- The following loop is looking for the nearest compile time
-- known bounds following the ancestor subtype chain. The idea
-- is to find the most restrictive known bounds information.
Ancest := T;
loop
if Ancest = Any_Type or else Etype (Ancest) = Any_Type then
return 0;
end if;
if not LoSet then
if Compile_Time_Known_Value (Type_Low_Bound (Ancest)) then
Lo := Expr_Rep_Value (Type_Low_Bound (Ancest));
LoSet := True;
exit when HiSet;
end if;
end if;
if not HiSet then
if Compile_Time_Known_Value (Type_High_Bound (Ancest)) then
Hi := Expr_Rep_Value (Type_High_Bound (Ancest));
HiSet := True;
exit when LoSet;
end if;
end if;
Ancest := Ancestor_Subtype (Ancest);
if No (Ancest) then
Ancest := Base_Type (T);
if Is_Generic_Type (Ancest) then
return 0;
end if;
end if;
end loop;
-- Fixed-point types. We can't simply use Expr_Value to get the
-- Corresponding_Integer_Value values of the bounds, since these
-- do not get set till the type is frozen, and this routine can
-- be called before the type is frozen. Similarly the test for
-- bounds being static needs to include the case where we have
-- unanalyzed real literals for the same reason.
elsif Is_Fixed_Point_Type (T) then
-- The following loop is looking for the nearest compile time
-- known bounds following the ancestor subtype chain. The idea
-- is to find the most restrictive known bounds information.
Ancest := T;
loop
if Ancest = Any_Type or else Etype (Ancest) = Any_Type then
return 0;
end if;
if not LoSet then
if Nkind (Type_Low_Bound (Ancest)) = N_Real_Literal
or else Compile_Time_Known_Value (Type_Low_Bound (Ancest))
then
LoR := Expr_Value_R (Type_Low_Bound (Ancest));
LoSet := True;
exit when HiSet;
end if;
end if;
if not HiSet then
if Nkind (Type_High_Bound (Ancest)) = N_Real_Literal
or else Compile_Time_Known_Value (Type_High_Bound (Ancest))
then
HiR := Expr_Value_R (Type_High_Bound (Ancest));
HiSet := True;
exit when LoSet;
end if;
end if;
Ancest := Ancestor_Subtype (Ancest);
if No (Ancest) then
Ancest := Base_Type (T);
if Is_Generic_Type (Ancest) then
return 0;
end if;
end if;
end loop;
Lo := UR_To_Uint (LoR / Small_Value (T));
Hi := UR_To_Uint (HiR / Small_Value (T));
-- No other types allowed
else
raise Program_Error;
end if;
-- Fall through with Hi and Lo set. Deal with biased case
if (Biased and then not Is_Fixed_Point_Type (T))
or else Has_Biased_Representation (T)
then
Hi := Hi - Lo;
Lo := Uint_0;
end if;
-- Signed case. Note that we consider types like range 1 .. -1 to be
-- signed for the purpose of computing the size, since the bounds
-- have to be accomodated in the base type.
if Lo < 0 or else Hi < 0 then
S := 1;
B := Uint_1;
-- S = size, B = 2 ** (size - 1) (can accommodate -B .. +(B - 1))
-- Note that we accommodate the case where the bounds cross. This
-- can happen either because of the way the bounds are declared
-- or because of the algorithm in Freeze_Fixed_Point_Type.
while Lo < -B
or else Hi < -B
or else Lo >= B
or else Hi >= B
loop
B := Uint_2 ** S;
S := S + 1;
end loop;
-- Unsigned case
else
-- If both bounds are positive, make sure that both are represen-
-- table in the case where the bounds are crossed. This can happen
-- either because of the way the bounds are declared, or because of
-- the algorithm in Freeze_Fixed_Point_Type.
if Lo > Hi then
Hi := Lo;
end if;
-- S = size, (can accommodate 0 .. (2**size - 1))
S := 0;
while Hi >= Uint_2 ** S loop
S := S + 1;
end loop;
end if;
return S;
end Minimum_Size;
-------------------------
-- New_Stream_Function --
-------------------------
procedure New_Stream_Function
(N : Node_Id;
Ent : Entity_Id;
Subp : Entity_Id;
Nam : TSS_Name_Type)
is
Loc : constant Source_Ptr := Sloc (N);
Sname : constant Name_Id := Make_TSS_Name (Base_Type (Ent), Nam);
Subp_Id : Entity_Id;
Subp_Decl : Node_Id;
F : Entity_Id;
Etyp : Entity_Id;
function Build_Spec return Node_Id;
-- Used for declaration and renaming declaration, so that this is
-- treated as a renaming_as_body.
----------------
-- Build_Spec --
----------------
function Build_Spec return Node_Id is
begin
Subp_Id := Make_Defining_Identifier (Loc, Sname);
return
Make_Function_Specification (Loc,
Defining_Unit_Name => Subp_Id,
Parameter_Specifications =>
New_List (
Make_Parameter_Specification (Loc,
Defining_Identifier =>
Make_Defining_Identifier (Loc, Name_S),
Parameter_Type =>
Make_Access_Definition (Loc,
Subtype_Mark =>
New_Reference_To (
Designated_Type (Etype (F)), Loc)))),
Result_Definition =>
New_Reference_To (Etyp, Loc));
end Build_Spec;
-- Start of processing for New_Stream_Function
begin
F := First_Formal (Subp);
Etyp := Etype (Subp);
if not Is_Tagged_Type (Ent) then
Subp_Decl :=
Make_Subprogram_Declaration (Loc,
Specification => Build_Spec);
Insert_Action (N, Subp_Decl);
end if;
Subp_Decl :=
Make_Subprogram_Renaming_Declaration (Loc,
Specification => Build_Spec,
Name => New_Reference_To (Subp, Loc));
if Is_Tagged_Type (Ent) then
Set_TSS (Base_Type (Ent), Subp_Id);
else
Insert_Action (N, Subp_Decl);
Copy_TSS (Subp_Id, Base_Type (Ent));
end if;
end New_Stream_Function;
--------------------------
-- New_Stream_Procedure --
--------------------------
procedure New_Stream_Procedure
(N : Node_Id;
Ent : Entity_Id;
Subp : Entity_Id;
Nam : TSS_Name_Type;
Out_P : Boolean := False)
is
Loc : constant Source_Ptr := Sloc (N);
Sname : constant Name_Id := Make_TSS_Name (Base_Type (Ent), Nam);
Subp_Id : Entity_Id;
Subp_Decl : Node_Id;
F : Entity_Id;
Etyp : Entity_Id;
function Build_Spec return Node_Id;
-- Used for declaration and renaming declaration, so that this is
-- treated as a renaming_as_body.
----------------
-- Build_Spec --
----------------
function Build_Spec return Node_Id is
begin
Subp_Id := Make_Defining_Identifier (Loc, Sname);
return
Make_Procedure_Specification (Loc,
Defining_Unit_Name => Subp_Id,
Parameter_Specifications =>
New_List (
Make_Parameter_Specification (Loc,
Defining_Identifier =>
Make_Defining_Identifier (Loc, Name_S),
Parameter_Type =>
Make_Access_Definition (Loc,
Subtype_Mark =>
New_Reference_To (
Designated_Type (Etype (F)), Loc))),
Make_Parameter_Specification (Loc,
Defining_Identifier =>
Make_Defining_Identifier (Loc, Name_V),
Out_Present => Out_P,
Parameter_Type =>
New_Reference_To (Etyp, Loc))));
end Build_Spec;
-- Start of processing for New_Stream_Procedure
begin
F := First_Formal (Subp);
Etyp := Etype (Next_Formal (F));
if not Is_Tagged_Type (Ent) then
Subp_Decl :=
Make_Subprogram_Declaration (Loc,
Specification => Build_Spec);
Insert_Action (N, Subp_Decl);
end if;
Subp_Decl :=
Make_Subprogram_Renaming_Declaration (Loc,
Specification => Build_Spec,
Name => New_Reference_To (Subp, Loc));
if Is_Tagged_Type (Ent) then
Set_TSS (Base_Type (Ent), Subp_Id);
else
Insert_Action (N, Subp_Decl);
Copy_TSS (Subp_Id, Base_Type (Ent));
end if;
end New_Stream_Procedure;
------------------------
-- Rep_Item_Too_Early --
------------------------
function Rep_Item_Too_Early (T : Entity_Id; N : Node_Id) return Boolean is
begin
-- Cannot apply rep items that are not operational items
-- to generic types
if Is_Operational_Item (N) then
return False;
elsif Is_Type (T)
and then Is_Generic_Type (Root_Type (T))
then
Error_Msg_N
("representation item not allowed for generic type", N);
return True;
end if;
-- Otherwise check for incompleted type
if Is_Incomplete_Or_Private_Type (T)
and then No (Underlying_Type (T))
then
Error_Msg_N
("representation item must be after full type declaration", N);
return True;
-- If the type has incompleted components, a representation clause is
-- illegal but stream attributes and Convention pragmas are correct.
elsif Has_Private_Component (T) then
if Nkind (N) = N_Pragma then
return False;
else
Error_Msg_N
("representation item must appear after type is fully defined",
N);
return True;
end if;
else
return False;
end if;
end Rep_Item_Too_Early;
-----------------------
-- Rep_Item_Too_Late --
-----------------------
function Rep_Item_Too_Late
(T : Entity_Id;
N : Node_Id;
FOnly : Boolean := False) return Boolean
is
S : Entity_Id;
Parent_Type : Entity_Id;
procedure Too_Late;
-- Output the too late message. Note that this is not considered a
-- serious error, since the effect is simply that we ignore the
-- representation clause in this case.
--------------
-- Too_Late --
--------------
procedure Too_Late is
begin
Error_Msg_N ("|representation item appears too late!", N);
end Too_Late;
-- Start of processing for Rep_Item_Too_Late
begin
-- First make sure entity is not frozen (RM 13.1(9)). Exclude imported
-- types, which may be frozen if they appear in a representation clause
-- for a local type.
if Is_Frozen (T)
and then not From_With_Type (T)
then
Too_Late;
S := First_Subtype (T);
if Present (Freeze_Node (S)) then
Error_Msg_NE
("?no more representation items for }", Freeze_Node (S), S);
end if;
return True;
-- Check for case of non-tagged derived type whose parent either has
-- primitive operations, or is a by reference type (RM 13.1(10)).
elsif Is_Type (T)
and then not FOnly
and then Is_Derived_Type (T)
and then not Is_Tagged_Type (T)
then
Parent_Type := Etype (Base_Type (T));
if Has_Primitive_Operations (Parent_Type) then
Too_Late;
Error_Msg_NE
("primitive operations already defined for&!", N, Parent_Type);
return True;
elsif Is_By_Reference_Type (Parent_Type) then
Too_Late;
Error_Msg_NE
("parent type & is a by reference type!", N, Parent_Type);
return True;
end if;
end if;
-- No error, link item into head of chain of rep items for the entity
Record_Rep_Item (T, N);
return False;
end Rep_Item_Too_Late;
-------------------------
-- Same_Representation --
-------------------------
function Same_Representation (Typ1, Typ2 : Entity_Id) return Boolean is
T1 : constant Entity_Id := Underlying_Type (Typ1);
T2 : constant Entity_Id := Underlying_Type (Typ2);
begin
-- A quick check, if base types are the same, then we definitely have
-- the same representation, because the subtype specific representation
-- attributes (Size and Alignment) do not affect representation from
-- the point of view of this test.
if Base_Type (T1) = Base_Type (T2) then
return True;
elsif Is_Private_Type (Base_Type (T2))
and then Base_Type (T1) = Full_View (Base_Type (T2))
then
return True;
end if;
-- Tagged types never have differing representations
if Is_Tagged_Type (T1) then
return True;
end if;
-- Representations are definitely different if conventions differ
if Convention (T1) /= Convention (T2) then
return False;
end if;
-- Representations are different if component alignments differ
if (Is_Record_Type (T1) or else Is_Array_Type (T1))
and then
(Is_Record_Type (T2) or else Is_Array_Type (T2))
and then Component_Alignment (T1) /= Component_Alignment (T2)
then
return False;
end if;
-- For arrays, the only real issue is component size. If we know the
-- component size for both arrays, and it is the same, then that's
-- good enough to know we don't have a change of representation.
if Is_Array_Type (T1) then
if Known_Component_Size (T1)
and then Known_Component_Size (T2)
and then Component_Size (T1) = Component_Size (T2)
then
return True;
end if;
end if;
-- Types definitely have same representation if neither has non-standard
-- representation since default representations are always consistent.
-- If only one has non-standard representation, and the other does not,
-- then we consider that they do not have the same representation. They
-- might, but there is no way of telling early enough.
if Has_Non_Standard_Rep (T1) then
if not Has_Non_Standard_Rep (T2) then
return False;
end if;
else
return not Has_Non_Standard_Rep (T2);
end if;
-- Here the two types both have non-standard representation, and we
-- need to determine if they have the same non-standard representation
-- For arrays, we simply need to test if the component sizes are the
-- same. Pragma Pack is reflected in modified component sizes, so this
-- check also deals with pragma Pack.
if Is_Array_Type (T1) then
return Component_Size (T1) = Component_Size (T2);
-- Tagged types always have the same representation, because it is not
-- possible to specify different representations for common fields.
elsif Is_Tagged_Type (T1) then
return True;
-- Case of record types
elsif Is_Record_Type (T1) then
-- Packed status must conform
if Is_Packed (T1) /= Is_Packed (T2) then
return False;
-- Otherwise we must check components. Typ2 maybe a constrained
-- subtype with fewer components, so we compare the components
-- of the base types.
else
Record_Case : declare
CD1, CD2 : Entity_Id;
function Same_Rep return Boolean;
-- CD1 and CD2 are either components or discriminants. This
-- function tests whether the two have the same representation
--------------
-- Same_Rep --
--------------
function Same_Rep return Boolean is
begin
if No (Component_Clause (CD1)) then
return No (Component_Clause (CD2));
else
return
Present (Component_Clause (CD2))
and then
Component_Bit_Offset (CD1) = Component_Bit_Offset (CD2)
and then
Esize (CD1) = Esize (CD2);
end if;
end Same_Rep;
-- Start processing for Record_Case
begin
if Has_Discriminants (T1) then
CD1 := First_Discriminant (T1);
CD2 := First_Discriminant (T2);
-- The number of discriminants may be different if the
-- derived type has fewer (constrained by values). The
-- invisible discriminants retain the representation of
-- the original, so the discrepancy does not per se
-- indicate a different representation.
while Present (CD1)
and then Present (CD2)
loop
if not Same_Rep then
return False;
else
Next_Discriminant (CD1);
Next_Discriminant (CD2);
end if;
end loop;
end if;
CD1 := First_Component (Underlying_Type (Base_Type (T1)));
CD2 := First_Component (Underlying_Type (Base_Type (T2)));
while Present (CD1) loop
if not Same_Rep then
return False;
else
Next_Component (CD1);
Next_Component (CD2);
end if;
end loop;
return True;
end Record_Case;
end if;
-- For enumeration types, we must check each literal to see if the
-- representation is the same. Note that we do not permit enumeration
-- reprsentation clauses for Character and Wide_Character, so these
-- cases were already dealt with.
elsif Is_Enumeration_Type (T1) then
Enumeration_Case : declare
L1, L2 : Entity_Id;
begin
L1 := First_Literal (T1);
L2 := First_Literal (T2);
while Present (L1) loop
if Enumeration_Rep (L1) /= Enumeration_Rep (L2) then
return False;
else
Next_Literal (L1);
Next_Literal (L2);
end if;
end loop;
return True;
end Enumeration_Case;
-- Any other types have the same representation for these purposes
else
return True;
end if;
end Same_Representation;
--------------------
-- Set_Enum_Esize --
--------------------
procedure Set_Enum_Esize (T : Entity_Id) is
Lo : Uint;
Hi : Uint;
Sz : Nat;
begin
Init_Alignment (T);
-- Find the minimum standard size (8,16,32,64) that fits
Lo := Enumeration_Rep (Entity (Type_Low_Bound (T)));
Hi := Enumeration_Rep (Entity (Type_High_Bound (T)));
if Lo < 0 then
if Lo >= -Uint_2**07 and then Hi < Uint_2**07 then
Sz := Standard_Character_Size; -- May be > 8 on some targets
elsif Lo >= -Uint_2**15 and then Hi < Uint_2**15 then
Sz := 16;
elsif Lo >= -Uint_2**31 and then Hi < Uint_2**31 then
Sz := 32;
else pragma Assert (Lo >= -Uint_2**63 and then Hi < Uint_2**63);
Sz := 64;
end if;
else
if Hi < Uint_2**08 then
Sz := Standard_Character_Size; -- May be > 8 on some targets
elsif Hi < Uint_2**16 then
Sz := 16;
elsif Hi < Uint_2**32 then
Sz := 32;
else pragma Assert (Hi < Uint_2**63);
Sz := 64;
end if;
end if;
-- That minimum is the proper size unless we have a foreign convention
-- and the size required is 32 or less, in which case we bump the size
-- up to 32. This is required for C and C++ and seems reasonable for
-- all other foreign conventions.
if Has_Foreign_Convention (T)
and then Esize (T) < Standard_Integer_Size
then
Init_Esize (T, Standard_Integer_Size);
else
Init_Esize (T, Sz);
end if;
end Set_Enum_Esize;
-----------------------------------
-- Validate_Unchecked_Conversion --
-----------------------------------
procedure Validate_Unchecked_Conversion
(N : Node_Id;
Act_Unit : Entity_Id)
is
Source : Entity_Id;
Target : Entity_Id;
Vnode : Node_Id;
begin
-- Obtain source and target types. Note that we call Ancestor_Subtype
-- here because the processing for generic instantiation always makes
-- subtypes, and we want the original frozen actual types.
-- If we are dealing with private types, then do the check on their
-- fully declared counterparts if the full declarations have been
-- encountered (they don't have to be visible, but they must exist!)
Source := Ancestor_Subtype (Etype (First_Formal (Act_Unit)));
if Is_Private_Type (Source)
and then Present (Underlying_Type (Source))
then
Source := Underlying_Type (Source);
end if;
Target := Ancestor_Subtype (Etype (Act_Unit));
-- If either type is generic, the instantiation happens within a
-- generic unit, and there is nothing to check. The proper check
-- will happen when the enclosing generic is instantiated.
if Is_Generic_Type (Source) or else Is_Generic_Type (Target) then
return;
end if;
if Is_Private_Type (Target)
and then Present (Underlying_Type (Target))
then
Target := Underlying_Type (Target);
end if;
-- Source may be unconstrained array, but not target
if Is_Array_Type (Target)
and then not Is_Constrained (Target)
then
Error_Msg_N
("unchecked conversion to unconstrained array not allowed", N);
return;
end if;
-- Make entry in unchecked conversion table for later processing
-- by Validate_Unchecked_Conversions, which will check sizes and
-- alignments (using values set by the back-end where possible).
-- This is only done if the appropriate warning is active
if Warn_On_Unchecked_Conversion then
Unchecked_Conversions.Append
(New_Val => UC_Entry'
(Enode => N,
Source => Source,
Target => Target));
-- If both sizes are known statically now, then back end annotation
-- is not required to do a proper check but if either size is not
-- known statically, then we need the annotation.
if Known_Static_RM_Size (Source)
and then Known_Static_RM_Size (Target)
then
null;
else
Back_Annotate_Rep_Info := True;
end if;
end if;
-- If unchecked conversion to access type, and access type is
-- declared in the same unit as the unchecked conversion, then
-- set the No_Strict_Aliasing flag (no strict aliasing is
-- implicit in this situation).
if Is_Access_Type (Target) and then
In_Same_Source_Unit (Target, N)
then
Set_No_Strict_Aliasing (Implementation_Base_Type (Target));
end if;
-- Generate N_Validate_Unchecked_Conversion node for back end in
-- case the back end needs to perform special validation checks.
-- Shouldn't this be in exp_ch13, since the check only gets done
-- if we have full expansion and the back end is called ???
Vnode :=
Make_Validate_Unchecked_Conversion (Sloc (N));
Set_Source_Type (Vnode, Source);
Set_Target_Type (Vnode, Target);
-- If the unchecked conversion node is in a list, just insert before
-- it. If not we have some strange case, not worth bothering about.
if Is_List_Member (N) then
Insert_After (N, Vnode);
end if;
end Validate_Unchecked_Conversion;
------------------------------------
-- Validate_Unchecked_Conversions --
------------------------------------
procedure Validate_Unchecked_Conversions is
begin
for N in Unchecked_Conversions.First .. Unchecked_Conversions.Last loop
declare
T : UC_Entry renames Unchecked_Conversions.Table (N);
Enode : constant Node_Id := T.Enode;
Source : constant Entity_Id := T.Source;
Target : constant Entity_Id := T.Target;
Source_Siz : Uint;
Target_Siz : Uint;
begin
-- This validation check, which warns if we have unequal sizes
-- for unchecked conversion, and thus potentially implementation
-- dependent semantics, is one of the few occasions on which we
-- use the official RM size instead of Esize. See description
-- in Einfo "Handling of Type'Size Values" for details.
if Serious_Errors_Detected = 0
and then Known_Static_RM_Size (Source)
and then Known_Static_RM_Size (Target)
then
Source_Siz := RM_Size (Source);
Target_Siz := RM_Size (Target);
if Source_Siz /= Target_Siz then
Error_Msg_N
("types for unchecked conversion have different sizes?",
Enode);
if All_Errors_Mode then
Error_Msg_Name_1 := Chars (Source);
Error_Msg_Uint_1 := Source_Siz;
Error_Msg_Name_2 := Chars (Target);
Error_Msg_Uint_2 := Target_Siz;
Error_Msg_N
("\size of % is ^, size of % is ^?", Enode);
Error_Msg_Uint_1 := UI_Abs (Source_Siz - Target_Siz);
if Is_Discrete_Type (Source)
and then Is_Discrete_Type (Target)
then
if Source_Siz > Target_Siz then
Error_Msg_N
("\^ high order bits of source will be ignored?",
Enode);
elsif Is_Unsigned_Type (Source) then
Error_Msg_N
("\source will be extended with ^ high order " &
"zero bits?", Enode);
else
Error_Msg_N
("\source will be extended with ^ high order " &
"sign bits?",
Enode);
end if;
elsif Source_Siz < Target_Siz then
if Is_Discrete_Type (Target) then
if Bytes_Big_Endian then
Error_Msg_N
("\target value will include ^ undefined " &
"low order bits?",
Enode);
else
Error_Msg_N
("\target value will include ^ undefined " &
"high order bits?",
Enode);
end if;
else
Error_Msg_N
("\^ trailing bits of target value will be " &
"undefined?", Enode);
end if;
else pragma Assert (Source_Siz > Target_Siz);
Error_Msg_N
("\^ trailing bits of source will be ignored?",
Enode);
end if;
end if;
end if;
end if;
-- If both types are access types, we need to check the alignment.
-- If the alignment of both is specified, we can do it here.
if Serious_Errors_Detected = 0
and then Ekind (Source) in Access_Kind
and then Ekind (Target) in Access_Kind
and then Target_Strict_Alignment
and then Present (Designated_Type (Source))
and then Present (Designated_Type (Target))
then
declare
D_Source : constant Entity_Id := Designated_Type (Source);
D_Target : constant Entity_Id := Designated_Type (Target);
begin
if Known_Alignment (D_Source)
and then Known_Alignment (D_Target)
then
declare
Source_Align : constant Uint := Alignment (D_Source);
Target_Align : constant Uint := Alignment (D_Target);
begin
if Source_Align < Target_Align
and then not Is_Tagged_Type (D_Source)
then
Error_Msg_Uint_1 := Target_Align;
Error_Msg_Uint_2 := Source_Align;
Error_Msg_Node_2 := D_Source;
Error_Msg_NE
("alignment of & (^) is stricter than " &
"alignment of & (^)?", Enode, D_Target);
if All_Errors_Mode then
Error_Msg_N
("\resulting access value may have invalid " &
"alignment?", Enode);
end if;
end if;
end;
end if;
end;
end if;
end;
end loop;
end Validate_Unchecked_Conversions;
end Sem_Ch13;
|
-- This spec has been automatically generated from STM32F411xx.svd
pragma Restrictions (No_Elaboration_Code);
pragma Ada_2012;
pragma Style_Checks (Off);
with System;
package STM32_SVD.DMA is
pragma Preelaborate;
---------------
-- Registers --
---------------
subtype LISR_FEIF0_Field is STM32_SVD.Bit;
subtype LISR_DMEIF0_Field is STM32_SVD.Bit;
subtype LISR_TEIF0_Field is STM32_SVD.Bit;
subtype LISR_HTIF0_Field is STM32_SVD.Bit;
subtype LISR_TCIF0_Field is STM32_SVD.Bit;
subtype LISR_FEIF1_Field is STM32_SVD.Bit;
subtype LISR_DMEIF1_Field is STM32_SVD.Bit;
subtype LISR_TEIF1_Field is STM32_SVD.Bit;
subtype LISR_HTIF1_Field is STM32_SVD.Bit;
subtype LISR_TCIF1_Field is STM32_SVD.Bit;
subtype LISR_FEIF2_Field is STM32_SVD.Bit;
subtype LISR_DMEIF2_Field is STM32_SVD.Bit;
subtype LISR_TEIF2_Field is STM32_SVD.Bit;
subtype LISR_HTIF2_Field is STM32_SVD.Bit;
subtype LISR_TCIF2_Field is STM32_SVD.Bit;
subtype LISR_FEIF3_Field is STM32_SVD.Bit;
subtype LISR_DMEIF3_Field is STM32_SVD.Bit;
subtype LISR_TEIF3_Field is STM32_SVD.Bit;
subtype LISR_HTIF3_Field is STM32_SVD.Bit;
subtype LISR_TCIF3_Field is STM32_SVD.Bit;
-- low interrupt status register
type LISR_Register is record
-- Read-only. Stream x FIFO error interrupt flag (x=3..0)
FEIF0 : LISR_FEIF0_Field;
-- unspecified
Reserved_1_1 : STM32_SVD.Bit;
-- Read-only. Stream x direct mode error interrupt flag (x=3..0)
DMEIF0 : LISR_DMEIF0_Field;
-- Read-only. Stream x transfer error interrupt flag (x=3..0)
TEIF0 : LISR_TEIF0_Field;
-- Read-only. Stream x half transfer interrupt flag (x=3..0)
HTIF0 : LISR_HTIF0_Field;
-- Read-only. Stream x transfer complete interrupt flag (x = 3..0)
TCIF0 : LISR_TCIF0_Field;
-- Read-only. Stream x FIFO error interrupt flag (x=3..0)
FEIF1 : LISR_FEIF1_Field;
-- unspecified
Reserved_7_7 : STM32_SVD.Bit;
-- Read-only. Stream x direct mode error interrupt flag (x=3..0)
DMEIF1 : LISR_DMEIF1_Field;
-- Read-only. Stream x transfer error interrupt flag (x=3..0)
TEIF1 : LISR_TEIF1_Field;
-- Read-only. Stream x half transfer interrupt flag (x=3..0)
HTIF1 : LISR_HTIF1_Field;
-- Read-only. Stream x transfer complete interrupt flag (x = 3..0)
TCIF1 : LISR_TCIF1_Field;
-- unspecified
Reserved_12_15 : STM32_SVD.UInt4;
-- Read-only. Stream x FIFO error interrupt flag (x=3..0)
FEIF2 : LISR_FEIF2_Field;
-- unspecified
Reserved_17_17 : STM32_SVD.Bit;
-- Read-only. Stream x direct mode error interrupt flag (x=3..0)
DMEIF2 : LISR_DMEIF2_Field;
-- Read-only. Stream x transfer error interrupt flag (x=3..0)
TEIF2 : LISR_TEIF2_Field;
-- Read-only. Stream x half transfer interrupt flag (x=3..0)
HTIF2 : LISR_HTIF2_Field;
-- Read-only. Stream x transfer complete interrupt flag (x = 3..0)
TCIF2 : LISR_TCIF2_Field;
-- Read-only. Stream x FIFO error interrupt flag (x=3..0)
FEIF3 : LISR_FEIF3_Field;
-- unspecified
Reserved_23_23 : STM32_SVD.Bit;
-- Read-only. Stream x direct mode error interrupt flag (x=3..0)
DMEIF3 : LISR_DMEIF3_Field;
-- Read-only. Stream x transfer error interrupt flag (x=3..0)
TEIF3 : LISR_TEIF3_Field;
-- Read-only. Stream x half transfer interrupt flag (x=3..0)
HTIF3 : LISR_HTIF3_Field;
-- Read-only. Stream x transfer complete interrupt flag (x = 3..0)
TCIF3 : LISR_TCIF3_Field;
-- unspecified
Reserved_28_31 : STM32_SVD.UInt4;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for LISR_Register use record
FEIF0 at 0 range 0 .. 0;
Reserved_1_1 at 0 range 1 .. 1;
DMEIF0 at 0 range 2 .. 2;
TEIF0 at 0 range 3 .. 3;
HTIF0 at 0 range 4 .. 4;
TCIF0 at 0 range 5 .. 5;
FEIF1 at 0 range 6 .. 6;
Reserved_7_7 at 0 range 7 .. 7;
DMEIF1 at 0 range 8 .. 8;
TEIF1 at 0 range 9 .. 9;
HTIF1 at 0 range 10 .. 10;
TCIF1 at 0 range 11 .. 11;
Reserved_12_15 at 0 range 12 .. 15;
FEIF2 at 0 range 16 .. 16;
Reserved_17_17 at 0 range 17 .. 17;
DMEIF2 at 0 range 18 .. 18;
TEIF2 at 0 range 19 .. 19;
HTIF2 at 0 range 20 .. 20;
TCIF2 at 0 range 21 .. 21;
FEIF3 at 0 range 22 .. 22;
Reserved_23_23 at 0 range 23 .. 23;
DMEIF3 at 0 range 24 .. 24;
TEIF3 at 0 range 25 .. 25;
HTIF3 at 0 range 26 .. 26;
TCIF3 at 0 range 27 .. 27;
Reserved_28_31 at 0 range 28 .. 31;
end record;
subtype HISR_FEIF4_Field is STM32_SVD.Bit;
subtype HISR_DMEIF4_Field is STM32_SVD.Bit;
subtype HISR_TEIF4_Field is STM32_SVD.Bit;
subtype HISR_HTIF4_Field is STM32_SVD.Bit;
subtype HISR_TCIF4_Field is STM32_SVD.Bit;
subtype HISR_FEIF5_Field is STM32_SVD.Bit;
subtype HISR_DMEIF5_Field is STM32_SVD.Bit;
subtype HISR_TEIF5_Field is STM32_SVD.Bit;
subtype HISR_HTIF5_Field is STM32_SVD.Bit;
subtype HISR_TCIF5_Field is STM32_SVD.Bit;
subtype HISR_FEIF6_Field is STM32_SVD.Bit;
subtype HISR_DMEIF6_Field is STM32_SVD.Bit;
subtype HISR_TEIF6_Field is STM32_SVD.Bit;
subtype HISR_HTIF6_Field is STM32_SVD.Bit;
subtype HISR_TCIF6_Field is STM32_SVD.Bit;
subtype HISR_FEIF7_Field is STM32_SVD.Bit;
subtype HISR_DMEIF7_Field is STM32_SVD.Bit;
subtype HISR_TEIF7_Field is STM32_SVD.Bit;
subtype HISR_HTIF7_Field is STM32_SVD.Bit;
subtype HISR_TCIF7_Field is STM32_SVD.Bit;
-- high interrupt status register
type HISR_Register is record
-- Read-only. Stream x FIFO error interrupt flag (x=7..4)
FEIF4 : HISR_FEIF4_Field;
-- unspecified
Reserved_1_1 : STM32_SVD.Bit;
-- Read-only. Stream x direct mode error interrupt flag (x=7..4)
DMEIF4 : HISR_DMEIF4_Field;
-- Read-only. Stream x transfer error interrupt flag (x=7..4)
TEIF4 : HISR_TEIF4_Field;
-- Read-only. Stream x half transfer interrupt flag (x=7..4)
HTIF4 : HISR_HTIF4_Field;
-- Read-only. Stream x transfer complete interrupt flag (x=7..4)
TCIF4 : HISR_TCIF4_Field;
-- Read-only. Stream x FIFO error interrupt flag (x=7..4)
FEIF5 : HISR_FEIF5_Field;
-- unspecified
Reserved_7_7 : STM32_SVD.Bit;
-- Read-only. Stream x direct mode error interrupt flag (x=7..4)
DMEIF5 : HISR_DMEIF5_Field;
-- Read-only. Stream x transfer error interrupt flag (x=7..4)
TEIF5 : HISR_TEIF5_Field;
-- Read-only. Stream x half transfer interrupt flag (x=7..4)
HTIF5 : HISR_HTIF5_Field;
-- Read-only. Stream x transfer complete interrupt flag (x=7..4)
TCIF5 : HISR_TCIF5_Field;
-- unspecified
Reserved_12_15 : STM32_SVD.UInt4;
-- Read-only. Stream x FIFO error interrupt flag (x=7..4)
FEIF6 : HISR_FEIF6_Field;
-- unspecified
Reserved_17_17 : STM32_SVD.Bit;
-- Read-only. Stream x direct mode error interrupt flag (x=7..4)
DMEIF6 : HISR_DMEIF6_Field;
-- Read-only. Stream x transfer error interrupt flag (x=7..4)
TEIF6 : HISR_TEIF6_Field;
-- Read-only. Stream x half transfer interrupt flag (x=7..4)
HTIF6 : HISR_HTIF6_Field;
-- Read-only. Stream x transfer complete interrupt flag (x=7..4)
TCIF6 : HISR_TCIF6_Field;
-- Read-only. Stream x FIFO error interrupt flag (x=7..4)
FEIF7 : HISR_FEIF7_Field;
-- unspecified
Reserved_23_23 : STM32_SVD.Bit;
-- Read-only. Stream x direct mode error interrupt flag (x=7..4)
DMEIF7 : HISR_DMEIF7_Field;
-- Read-only. Stream x transfer error interrupt flag (x=7..4)
TEIF7 : HISR_TEIF7_Field;
-- Read-only. Stream x half transfer interrupt flag (x=7..4)
HTIF7 : HISR_HTIF7_Field;
-- Read-only. Stream x transfer complete interrupt flag (x=7..4)
TCIF7 : HISR_TCIF7_Field;
-- unspecified
Reserved_28_31 : STM32_SVD.UInt4;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for HISR_Register use record
FEIF4 at 0 range 0 .. 0;
Reserved_1_1 at 0 range 1 .. 1;
DMEIF4 at 0 range 2 .. 2;
TEIF4 at 0 range 3 .. 3;
HTIF4 at 0 range 4 .. 4;
TCIF4 at 0 range 5 .. 5;
FEIF5 at 0 range 6 .. 6;
Reserved_7_7 at 0 range 7 .. 7;
DMEIF5 at 0 range 8 .. 8;
TEIF5 at 0 range 9 .. 9;
HTIF5 at 0 range 10 .. 10;
TCIF5 at 0 range 11 .. 11;
Reserved_12_15 at 0 range 12 .. 15;
FEIF6 at 0 range 16 .. 16;
Reserved_17_17 at 0 range 17 .. 17;
DMEIF6 at 0 range 18 .. 18;
TEIF6 at 0 range 19 .. 19;
HTIF6 at 0 range 20 .. 20;
TCIF6 at 0 range 21 .. 21;
FEIF7 at 0 range 22 .. 22;
Reserved_23_23 at 0 range 23 .. 23;
DMEIF7 at 0 range 24 .. 24;
TEIF7 at 0 range 25 .. 25;
HTIF7 at 0 range 26 .. 26;
TCIF7 at 0 range 27 .. 27;
Reserved_28_31 at 0 range 28 .. 31;
end record;
subtype LIFCR_CFEIF0_Field is STM32_SVD.Bit;
subtype LIFCR_CDMEIF0_Field is STM32_SVD.Bit;
subtype LIFCR_CTEIF0_Field is STM32_SVD.Bit;
subtype LIFCR_CHTIF0_Field is STM32_SVD.Bit;
subtype LIFCR_CTCIF0_Field is STM32_SVD.Bit;
subtype LIFCR_CFEIF1_Field is STM32_SVD.Bit;
subtype LIFCR_CDMEIF1_Field is STM32_SVD.Bit;
subtype LIFCR_CTEIF1_Field is STM32_SVD.Bit;
subtype LIFCR_CHTIF1_Field is STM32_SVD.Bit;
subtype LIFCR_CTCIF1_Field is STM32_SVD.Bit;
subtype LIFCR_CFEIF2_Field is STM32_SVD.Bit;
subtype LIFCR_CDMEIF2_Field is STM32_SVD.Bit;
subtype LIFCR_CTEIF2_Field is STM32_SVD.Bit;
subtype LIFCR_CHTIF2_Field is STM32_SVD.Bit;
subtype LIFCR_CTCIF2_Field is STM32_SVD.Bit;
subtype LIFCR_CFEIF3_Field is STM32_SVD.Bit;
subtype LIFCR_CDMEIF3_Field is STM32_SVD.Bit;
subtype LIFCR_CTEIF3_Field is STM32_SVD.Bit;
subtype LIFCR_CHTIF3_Field is STM32_SVD.Bit;
subtype LIFCR_CTCIF3_Field is STM32_SVD.Bit;
-- low interrupt flag clear register
type LIFCR_Register is record
-- Write-only. Stream x clear FIFO error interrupt flag (x = 3..0)
CFEIF0 : LIFCR_CFEIF0_Field := 16#0#;
-- unspecified
Reserved_1_1 : STM32_SVD.Bit := 16#0#;
-- Write-only. Stream x clear direct mode error interrupt flag (x =
-- 3..0)
CDMEIF0 : LIFCR_CDMEIF0_Field := 16#0#;
-- Write-only. Stream x clear transfer error interrupt flag (x = 3..0)
CTEIF0 : LIFCR_CTEIF0_Field := 16#0#;
-- Write-only. Stream x clear half transfer interrupt flag (x = 3..0)
CHTIF0 : LIFCR_CHTIF0_Field := 16#0#;
-- Write-only. Stream x clear transfer complete interrupt flag (x =
-- 3..0)
CTCIF0 : LIFCR_CTCIF0_Field := 16#0#;
-- Write-only. Stream x clear FIFO error interrupt flag (x = 3..0)
CFEIF1 : LIFCR_CFEIF1_Field := 16#0#;
-- unspecified
Reserved_7_7 : STM32_SVD.Bit := 16#0#;
-- Write-only. Stream x clear direct mode error interrupt flag (x =
-- 3..0)
CDMEIF1 : LIFCR_CDMEIF1_Field := 16#0#;
-- Write-only. Stream x clear transfer error interrupt flag (x = 3..0)
CTEIF1 : LIFCR_CTEIF1_Field := 16#0#;
-- Write-only. Stream x clear half transfer interrupt flag (x = 3..0)
CHTIF1 : LIFCR_CHTIF1_Field := 16#0#;
-- Write-only. Stream x clear transfer complete interrupt flag (x =
-- 3..0)
CTCIF1 : LIFCR_CTCIF1_Field := 16#0#;
-- unspecified
Reserved_12_15 : STM32_SVD.UInt4 := 16#0#;
-- Write-only. Stream x clear FIFO error interrupt flag (x = 3..0)
CFEIF2 : LIFCR_CFEIF2_Field := 16#0#;
-- unspecified
Reserved_17_17 : STM32_SVD.Bit := 16#0#;
-- Write-only. Stream x clear direct mode error interrupt flag (x =
-- 3..0)
CDMEIF2 : LIFCR_CDMEIF2_Field := 16#0#;
-- Write-only. Stream x clear transfer error interrupt flag (x = 3..0)
CTEIF2 : LIFCR_CTEIF2_Field := 16#0#;
-- Write-only. Stream x clear half transfer interrupt flag (x = 3..0)
CHTIF2 : LIFCR_CHTIF2_Field := 16#0#;
-- Write-only. Stream x clear transfer complete interrupt flag (x =
-- 3..0)
CTCIF2 : LIFCR_CTCIF2_Field := 16#0#;
-- Write-only. Stream x clear FIFO error interrupt flag (x = 3..0)
CFEIF3 : LIFCR_CFEIF3_Field := 16#0#;
-- unspecified
Reserved_23_23 : STM32_SVD.Bit := 16#0#;
-- Write-only. Stream x clear direct mode error interrupt flag (x =
-- 3..0)
CDMEIF3 : LIFCR_CDMEIF3_Field := 16#0#;
-- Write-only. Stream x clear transfer error interrupt flag (x = 3..0)
CTEIF3 : LIFCR_CTEIF3_Field := 16#0#;
-- Write-only. Stream x clear half transfer interrupt flag (x = 3..0)
CHTIF3 : LIFCR_CHTIF3_Field := 16#0#;
-- Write-only. Stream x clear transfer complete interrupt flag (x =
-- 3..0)
CTCIF3 : LIFCR_CTCIF3_Field := 16#0#;
-- unspecified
Reserved_28_31 : STM32_SVD.UInt4 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for LIFCR_Register use record
CFEIF0 at 0 range 0 .. 0;
Reserved_1_1 at 0 range 1 .. 1;
CDMEIF0 at 0 range 2 .. 2;
CTEIF0 at 0 range 3 .. 3;
CHTIF0 at 0 range 4 .. 4;
CTCIF0 at 0 range 5 .. 5;
CFEIF1 at 0 range 6 .. 6;
Reserved_7_7 at 0 range 7 .. 7;
CDMEIF1 at 0 range 8 .. 8;
CTEIF1 at 0 range 9 .. 9;
CHTIF1 at 0 range 10 .. 10;
CTCIF1 at 0 range 11 .. 11;
Reserved_12_15 at 0 range 12 .. 15;
CFEIF2 at 0 range 16 .. 16;
Reserved_17_17 at 0 range 17 .. 17;
CDMEIF2 at 0 range 18 .. 18;
CTEIF2 at 0 range 19 .. 19;
CHTIF2 at 0 range 20 .. 20;
CTCIF2 at 0 range 21 .. 21;
CFEIF3 at 0 range 22 .. 22;
Reserved_23_23 at 0 range 23 .. 23;
CDMEIF3 at 0 range 24 .. 24;
CTEIF3 at 0 range 25 .. 25;
CHTIF3 at 0 range 26 .. 26;
CTCIF3 at 0 range 27 .. 27;
Reserved_28_31 at 0 range 28 .. 31;
end record;
subtype HIFCR_CFEIF4_Field is STM32_SVD.Bit;
subtype HIFCR_CDMEIF4_Field is STM32_SVD.Bit;
subtype HIFCR_CTEIF4_Field is STM32_SVD.Bit;
subtype HIFCR_CHTIF4_Field is STM32_SVD.Bit;
subtype HIFCR_CTCIF4_Field is STM32_SVD.Bit;
subtype HIFCR_CFEIF5_Field is STM32_SVD.Bit;
subtype HIFCR_CDMEIF5_Field is STM32_SVD.Bit;
subtype HIFCR_CTEIF5_Field is STM32_SVD.Bit;
subtype HIFCR_CHTIF5_Field is STM32_SVD.Bit;
subtype HIFCR_CTCIF5_Field is STM32_SVD.Bit;
subtype HIFCR_CFEIF6_Field is STM32_SVD.Bit;
subtype HIFCR_CDMEIF6_Field is STM32_SVD.Bit;
subtype HIFCR_CTEIF6_Field is STM32_SVD.Bit;
subtype HIFCR_CHTIF6_Field is STM32_SVD.Bit;
subtype HIFCR_CTCIF6_Field is STM32_SVD.Bit;
subtype HIFCR_CFEIF7_Field is STM32_SVD.Bit;
subtype HIFCR_CDMEIF7_Field is STM32_SVD.Bit;
subtype HIFCR_CTEIF7_Field is STM32_SVD.Bit;
subtype HIFCR_CHTIF7_Field is STM32_SVD.Bit;
subtype HIFCR_CTCIF7_Field is STM32_SVD.Bit;
-- high interrupt flag clear register
type HIFCR_Register is record
-- Write-only. Stream x clear FIFO error interrupt flag (x = 7..4)
CFEIF4 : HIFCR_CFEIF4_Field := 16#0#;
-- unspecified
Reserved_1_1 : STM32_SVD.Bit := 16#0#;
-- Write-only. Stream x clear direct mode error interrupt flag (x =
-- 7..4)
CDMEIF4 : HIFCR_CDMEIF4_Field := 16#0#;
-- Write-only. Stream x clear transfer error interrupt flag (x = 7..4)
CTEIF4 : HIFCR_CTEIF4_Field := 16#0#;
-- Write-only. Stream x clear half transfer interrupt flag (x = 7..4)
CHTIF4 : HIFCR_CHTIF4_Field := 16#0#;
-- Write-only. Stream x clear transfer complete interrupt flag (x =
-- 7..4)
CTCIF4 : HIFCR_CTCIF4_Field := 16#0#;
-- Write-only. Stream x clear FIFO error interrupt flag (x = 7..4)
CFEIF5 : HIFCR_CFEIF5_Field := 16#0#;
-- unspecified
Reserved_7_7 : STM32_SVD.Bit := 16#0#;
-- Write-only. Stream x clear direct mode error interrupt flag (x =
-- 7..4)
CDMEIF5 : HIFCR_CDMEIF5_Field := 16#0#;
-- Write-only. Stream x clear transfer error interrupt flag (x = 7..4)
CTEIF5 : HIFCR_CTEIF5_Field := 16#0#;
-- Write-only. Stream x clear half transfer interrupt flag (x = 7..4)
CHTIF5 : HIFCR_CHTIF5_Field := 16#0#;
-- Write-only. Stream x clear transfer complete interrupt flag (x =
-- 7..4)
CTCIF5 : HIFCR_CTCIF5_Field := 16#0#;
-- unspecified
Reserved_12_15 : STM32_SVD.UInt4 := 16#0#;
-- Write-only. Stream x clear FIFO error interrupt flag (x = 7..4)
CFEIF6 : HIFCR_CFEIF6_Field := 16#0#;
-- unspecified
Reserved_17_17 : STM32_SVD.Bit := 16#0#;
-- Write-only. Stream x clear direct mode error interrupt flag (x =
-- 7..4)
CDMEIF6 : HIFCR_CDMEIF6_Field := 16#0#;
-- Write-only. Stream x clear transfer error interrupt flag (x = 7..4)
CTEIF6 : HIFCR_CTEIF6_Field := 16#0#;
-- Write-only. Stream x clear half transfer interrupt flag (x = 7..4)
CHTIF6 : HIFCR_CHTIF6_Field := 16#0#;
-- Write-only. Stream x clear transfer complete interrupt flag (x =
-- 7..4)
CTCIF6 : HIFCR_CTCIF6_Field := 16#0#;
-- Write-only. Stream x clear FIFO error interrupt flag (x = 7..4)
CFEIF7 : HIFCR_CFEIF7_Field := 16#0#;
-- unspecified
Reserved_23_23 : STM32_SVD.Bit := 16#0#;
-- Write-only. Stream x clear direct mode error interrupt flag (x =
-- 7..4)
CDMEIF7 : HIFCR_CDMEIF7_Field := 16#0#;
-- Write-only. Stream x clear transfer error interrupt flag (x = 7..4)
CTEIF7 : HIFCR_CTEIF7_Field := 16#0#;
-- Write-only. Stream x clear half transfer interrupt flag (x = 7..4)
CHTIF7 : HIFCR_CHTIF7_Field := 16#0#;
-- Write-only. Stream x clear transfer complete interrupt flag (x =
-- 7..4)
CTCIF7 : HIFCR_CTCIF7_Field := 16#0#;
-- unspecified
Reserved_28_31 : STM32_SVD.UInt4 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for HIFCR_Register use record
CFEIF4 at 0 range 0 .. 0;
Reserved_1_1 at 0 range 1 .. 1;
CDMEIF4 at 0 range 2 .. 2;
CTEIF4 at 0 range 3 .. 3;
CHTIF4 at 0 range 4 .. 4;
CTCIF4 at 0 range 5 .. 5;
CFEIF5 at 0 range 6 .. 6;
Reserved_7_7 at 0 range 7 .. 7;
CDMEIF5 at 0 range 8 .. 8;
CTEIF5 at 0 range 9 .. 9;
CHTIF5 at 0 range 10 .. 10;
CTCIF5 at 0 range 11 .. 11;
Reserved_12_15 at 0 range 12 .. 15;
CFEIF6 at 0 range 16 .. 16;
Reserved_17_17 at 0 range 17 .. 17;
CDMEIF6 at 0 range 18 .. 18;
CTEIF6 at 0 range 19 .. 19;
CHTIF6 at 0 range 20 .. 20;
CTCIF6 at 0 range 21 .. 21;
CFEIF7 at 0 range 22 .. 22;
Reserved_23_23 at 0 range 23 .. 23;
CDMEIF7 at 0 range 24 .. 24;
CTEIF7 at 0 range 25 .. 25;
CHTIF7 at 0 range 26 .. 26;
CTCIF7 at 0 range 27 .. 27;
Reserved_28_31 at 0 range 28 .. 31;
end record;
subtype S0CR_EN_Field is STM32_SVD.Bit;
subtype S0CR_DMEIE_Field is STM32_SVD.Bit;
subtype S0CR_TEIE_Field is STM32_SVD.Bit;
subtype S0CR_HTIE_Field is STM32_SVD.Bit;
subtype S0CR_TCIE_Field is STM32_SVD.Bit;
subtype S0CR_PFCTRL_Field is STM32_SVD.Bit;
subtype S0CR_DIR_Field is STM32_SVD.UInt2;
subtype S0CR_CIRC_Field is STM32_SVD.Bit;
subtype S0CR_PINC_Field is STM32_SVD.Bit;
subtype S0CR_MINC_Field is STM32_SVD.Bit;
subtype S0CR_PSIZE_Field is STM32_SVD.UInt2;
subtype S0CR_MSIZE_Field is STM32_SVD.UInt2;
subtype S0CR_PINCOS_Field is STM32_SVD.Bit;
subtype S0CR_PL_Field is STM32_SVD.UInt2;
subtype S0CR_DBM_Field is STM32_SVD.Bit;
subtype S0CR_CT_Field is STM32_SVD.Bit;
subtype S0CR_PBURST_Field is STM32_SVD.UInt2;
subtype S0CR_MBURST_Field is STM32_SVD.UInt2;
subtype S0CR_CHSEL_Field is STM32_SVD.UInt3;
-- stream x configuration register
type S0CR_Register is record
-- Stream enable / flag stream ready when read low
EN : S0CR_EN_Field := 16#0#;
-- Direct mode error interrupt enable
DMEIE : S0CR_DMEIE_Field := 16#0#;
-- Transfer error interrupt enable
TEIE : S0CR_TEIE_Field := 16#0#;
-- Half transfer interrupt enable
HTIE : S0CR_HTIE_Field := 16#0#;
-- Transfer complete interrupt enable
TCIE : S0CR_TCIE_Field := 16#0#;
-- Peripheral flow controller
PFCTRL : S0CR_PFCTRL_Field := 16#0#;
-- Data transfer direction
DIR : S0CR_DIR_Field := 16#0#;
-- Circular mode
CIRC : S0CR_CIRC_Field := 16#0#;
-- Peripheral increment mode
PINC : S0CR_PINC_Field := 16#0#;
-- Memory increment mode
MINC : S0CR_MINC_Field := 16#0#;
-- Peripheral data size
PSIZE : S0CR_PSIZE_Field := 16#0#;
-- Memory data size
MSIZE : S0CR_MSIZE_Field := 16#0#;
-- Peripheral increment offset size
PINCOS : S0CR_PINCOS_Field := 16#0#;
-- Priority level
PL : S0CR_PL_Field := 16#0#;
-- Double buffer mode
DBM : S0CR_DBM_Field := 16#0#;
-- Current target (only in double buffer mode)
CT : S0CR_CT_Field := 16#0#;
-- unspecified
Reserved_20_20 : STM32_SVD.Bit := 16#0#;
-- Peripheral burst transfer configuration
PBURST : S0CR_PBURST_Field := 16#0#;
-- Memory burst transfer configuration
MBURST : S0CR_MBURST_Field := 16#0#;
-- Channel selection
CHSEL : S0CR_CHSEL_Field := 16#0#;
-- unspecified
Reserved_28_31 : STM32_SVD.UInt4 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for S0CR_Register use record
EN at 0 range 0 .. 0;
DMEIE at 0 range 1 .. 1;
TEIE at 0 range 2 .. 2;
HTIE at 0 range 3 .. 3;
TCIE at 0 range 4 .. 4;
PFCTRL at 0 range 5 .. 5;
DIR at 0 range 6 .. 7;
CIRC at 0 range 8 .. 8;
PINC at 0 range 9 .. 9;
MINC at 0 range 10 .. 10;
PSIZE at 0 range 11 .. 12;
MSIZE at 0 range 13 .. 14;
PINCOS at 0 range 15 .. 15;
PL at 0 range 16 .. 17;
DBM at 0 range 18 .. 18;
CT at 0 range 19 .. 19;
Reserved_20_20 at 0 range 20 .. 20;
PBURST at 0 range 21 .. 22;
MBURST at 0 range 23 .. 24;
CHSEL at 0 range 25 .. 27;
Reserved_28_31 at 0 range 28 .. 31;
end record;
subtype S0NDTR_NDT_Field is STM32_SVD.UInt16;
-- stream x number of data register
type S0NDTR_Register is record
-- Number of data items to transfer
NDT : S0NDTR_NDT_Field := 16#0#;
-- unspecified
Reserved_16_31 : STM32_SVD.UInt16 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for S0NDTR_Register use record
NDT at 0 range 0 .. 15;
Reserved_16_31 at 0 range 16 .. 31;
end record;
subtype S0FCR_FTH_Field is STM32_SVD.UInt2;
subtype S0FCR_DMDIS_Field is STM32_SVD.Bit;
subtype S0FCR_FS_Field is STM32_SVD.UInt3;
subtype S0FCR_FEIE_Field is STM32_SVD.Bit;
-- stream x FIFO control register
type S0FCR_Register is record
-- FIFO threshold selection
FTH : S0FCR_FTH_Field := 16#1#;
-- Direct mode disable
DMDIS : S0FCR_DMDIS_Field := 16#0#;
-- Read-only. FIFO status
FS : S0FCR_FS_Field := 16#4#;
-- unspecified
Reserved_6_6 : STM32_SVD.Bit := 16#0#;
-- FIFO error interrupt enable
FEIE : S0FCR_FEIE_Field := 16#0#;
-- unspecified
Reserved_8_31 : STM32_SVD.UInt24 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for S0FCR_Register use record
FTH at 0 range 0 .. 1;
DMDIS at 0 range 2 .. 2;
FS at 0 range 3 .. 5;
Reserved_6_6 at 0 range 6 .. 6;
FEIE at 0 range 7 .. 7;
Reserved_8_31 at 0 range 8 .. 31;
end record;
subtype S1CR_EN_Field is STM32_SVD.Bit;
subtype S1CR_DMEIE_Field is STM32_SVD.Bit;
subtype S1CR_TEIE_Field is STM32_SVD.Bit;
subtype S1CR_HTIE_Field is STM32_SVD.Bit;
subtype S1CR_TCIE_Field is STM32_SVD.Bit;
subtype S1CR_PFCTRL_Field is STM32_SVD.Bit;
subtype S1CR_DIR_Field is STM32_SVD.UInt2;
subtype S1CR_CIRC_Field is STM32_SVD.Bit;
subtype S1CR_PINC_Field is STM32_SVD.Bit;
subtype S1CR_MINC_Field is STM32_SVD.Bit;
subtype S1CR_PSIZE_Field is STM32_SVD.UInt2;
subtype S1CR_MSIZE_Field is STM32_SVD.UInt2;
subtype S1CR_PINCOS_Field is STM32_SVD.Bit;
subtype S1CR_PL_Field is STM32_SVD.UInt2;
subtype S1CR_DBM_Field is STM32_SVD.Bit;
subtype S1CR_CT_Field is STM32_SVD.Bit;
subtype S1CR_ACK_Field is STM32_SVD.Bit;
subtype S1CR_PBURST_Field is STM32_SVD.UInt2;
subtype S1CR_MBURST_Field is STM32_SVD.UInt2;
subtype S1CR_CHSEL_Field is STM32_SVD.UInt3;
-- stream x configuration register
type S1CR_Register is record
-- Stream enable / flag stream ready when read low
EN : S1CR_EN_Field := 16#0#;
-- Direct mode error interrupt enable
DMEIE : S1CR_DMEIE_Field := 16#0#;
-- Transfer error interrupt enable
TEIE : S1CR_TEIE_Field := 16#0#;
-- Half transfer interrupt enable
HTIE : S1CR_HTIE_Field := 16#0#;
-- Transfer complete interrupt enable
TCIE : S1CR_TCIE_Field := 16#0#;
-- Peripheral flow controller
PFCTRL : S1CR_PFCTRL_Field := 16#0#;
-- Data transfer direction
DIR : S1CR_DIR_Field := 16#0#;
-- Circular mode
CIRC : S1CR_CIRC_Field := 16#0#;
-- Peripheral increment mode
PINC : S1CR_PINC_Field := 16#0#;
-- Memory increment mode
MINC : S1CR_MINC_Field := 16#0#;
-- Peripheral data size
PSIZE : S1CR_PSIZE_Field := 16#0#;
-- Memory data size
MSIZE : S1CR_MSIZE_Field := 16#0#;
-- Peripheral increment offset size
PINCOS : S1CR_PINCOS_Field := 16#0#;
-- Priority level
PL : S1CR_PL_Field := 16#0#;
-- Double buffer mode
DBM : S1CR_DBM_Field := 16#0#;
-- Current target (only in double buffer mode)
CT : S1CR_CT_Field := 16#0#;
-- ACK
ACK : S1CR_ACK_Field := 16#0#;
-- Peripheral burst transfer configuration
PBURST : S1CR_PBURST_Field := 16#0#;
-- Memory burst transfer configuration
MBURST : S1CR_MBURST_Field := 16#0#;
-- Channel selection
CHSEL : S1CR_CHSEL_Field := 16#0#;
-- unspecified
Reserved_28_31 : STM32_SVD.UInt4 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for S1CR_Register use record
EN at 0 range 0 .. 0;
DMEIE at 0 range 1 .. 1;
TEIE at 0 range 2 .. 2;
HTIE at 0 range 3 .. 3;
TCIE at 0 range 4 .. 4;
PFCTRL at 0 range 5 .. 5;
DIR at 0 range 6 .. 7;
CIRC at 0 range 8 .. 8;
PINC at 0 range 9 .. 9;
MINC at 0 range 10 .. 10;
PSIZE at 0 range 11 .. 12;
MSIZE at 0 range 13 .. 14;
PINCOS at 0 range 15 .. 15;
PL at 0 range 16 .. 17;
DBM at 0 range 18 .. 18;
CT at 0 range 19 .. 19;
ACK at 0 range 20 .. 20;
PBURST at 0 range 21 .. 22;
MBURST at 0 range 23 .. 24;
CHSEL at 0 range 25 .. 27;
Reserved_28_31 at 0 range 28 .. 31;
end record;
subtype S1NDTR_NDT_Field is STM32_SVD.UInt16;
-- stream x number of data register
type S1NDTR_Register is record
-- Number of data items to transfer
NDT : S1NDTR_NDT_Field := 16#0#;
-- unspecified
Reserved_16_31 : STM32_SVD.UInt16 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for S1NDTR_Register use record
NDT at 0 range 0 .. 15;
Reserved_16_31 at 0 range 16 .. 31;
end record;
subtype S1FCR_FTH_Field is STM32_SVD.UInt2;
subtype S1FCR_DMDIS_Field is STM32_SVD.Bit;
subtype S1FCR_FS_Field is STM32_SVD.UInt3;
subtype S1FCR_FEIE_Field is STM32_SVD.Bit;
-- stream x FIFO control register
type S1FCR_Register is record
-- FIFO threshold selection
FTH : S1FCR_FTH_Field := 16#1#;
-- Direct mode disable
DMDIS : S1FCR_DMDIS_Field := 16#0#;
-- Read-only. FIFO status
FS : S1FCR_FS_Field := 16#4#;
-- unspecified
Reserved_6_6 : STM32_SVD.Bit := 16#0#;
-- FIFO error interrupt enable
FEIE : S1FCR_FEIE_Field := 16#0#;
-- unspecified
Reserved_8_31 : STM32_SVD.UInt24 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for S1FCR_Register use record
FTH at 0 range 0 .. 1;
DMDIS at 0 range 2 .. 2;
FS at 0 range 3 .. 5;
Reserved_6_6 at 0 range 6 .. 6;
FEIE at 0 range 7 .. 7;
Reserved_8_31 at 0 range 8 .. 31;
end record;
subtype S2CR_EN_Field is STM32_SVD.Bit;
subtype S2CR_DMEIE_Field is STM32_SVD.Bit;
subtype S2CR_TEIE_Field is STM32_SVD.Bit;
subtype S2CR_HTIE_Field is STM32_SVD.Bit;
subtype S2CR_TCIE_Field is STM32_SVD.Bit;
subtype S2CR_PFCTRL_Field is STM32_SVD.Bit;
subtype S2CR_DIR_Field is STM32_SVD.UInt2;
subtype S2CR_CIRC_Field is STM32_SVD.Bit;
subtype S2CR_PINC_Field is STM32_SVD.Bit;
subtype S2CR_MINC_Field is STM32_SVD.Bit;
subtype S2CR_PSIZE_Field is STM32_SVD.UInt2;
subtype S2CR_MSIZE_Field is STM32_SVD.UInt2;
subtype S2CR_PINCOS_Field is STM32_SVD.Bit;
subtype S2CR_PL_Field is STM32_SVD.UInt2;
subtype S2CR_DBM_Field is STM32_SVD.Bit;
subtype S2CR_CT_Field is STM32_SVD.Bit;
subtype S2CR_ACK_Field is STM32_SVD.Bit;
subtype S2CR_PBURST_Field is STM32_SVD.UInt2;
subtype S2CR_MBURST_Field is STM32_SVD.UInt2;
subtype S2CR_CHSEL_Field is STM32_SVD.UInt3;
-- stream x configuration register
type S2CR_Register is record
-- Stream enable / flag stream ready when read low
EN : S2CR_EN_Field := 16#0#;
-- Direct mode error interrupt enable
DMEIE : S2CR_DMEIE_Field := 16#0#;
-- Transfer error interrupt enable
TEIE : S2CR_TEIE_Field := 16#0#;
-- Half transfer interrupt enable
HTIE : S2CR_HTIE_Field := 16#0#;
-- Transfer complete interrupt enable
TCIE : S2CR_TCIE_Field := 16#0#;
-- Peripheral flow controller
PFCTRL : S2CR_PFCTRL_Field := 16#0#;
-- Data transfer direction
DIR : S2CR_DIR_Field := 16#0#;
-- Circular mode
CIRC : S2CR_CIRC_Field := 16#0#;
-- Peripheral increment mode
PINC : S2CR_PINC_Field := 16#0#;
-- Memory increment mode
MINC : S2CR_MINC_Field := 16#0#;
-- Peripheral data size
PSIZE : S2CR_PSIZE_Field := 16#0#;
-- Memory data size
MSIZE : S2CR_MSIZE_Field := 16#0#;
-- Peripheral increment offset size
PINCOS : S2CR_PINCOS_Field := 16#0#;
-- Priority level
PL : S2CR_PL_Field := 16#0#;
-- Double buffer mode
DBM : S2CR_DBM_Field := 16#0#;
-- Current target (only in double buffer mode)
CT : S2CR_CT_Field := 16#0#;
-- ACK
ACK : S2CR_ACK_Field := 16#0#;
-- Peripheral burst transfer configuration
PBURST : S2CR_PBURST_Field := 16#0#;
-- Memory burst transfer configuration
MBURST : S2CR_MBURST_Field := 16#0#;
-- Channel selection
CHSEL : S2CR_CHSEL_Field := 16#0#;
-- unspecified
Reserved_28_31 : STM32_SVD.UInt4 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for S2CR_Register use record
EN at 0 range 0 .. 0;
DMEIE at 0 range 1 .. 1;
TEIE at 0 range 2 .. 2;
HTIE at 0 range 3 .. 3;
TCIE at 0 range 4 .. 4;
PFCTRL at 0 range 5 .. 5;
DIR at 0 range 6 .. 7;
CIRC at 0 range 8 .. 8;
PINC at 0 range 9 .. 9;
MINC at 0 range 10 .. 10;
PSIZE at 0 range 11 .. 12;
MSIZE at 0 range 13 .. 14;
PINCOS at 0 range 15 .. 15;
PL at 0 range 16 .. 17;
DBM at 0 range 18 .. 18;
CT at 0 range 19 .. 19;
ACK at 0 range 20 .. 20;
PBURST at 0 range 21 .. 22;
MBURST at 0 range 23 .. 24;
CHSEL at 0 range 25 .. 27;
Reserved_28_31 at 0 range 28 .. 31;
end record;
subtype S2NDTR_NDT_Field is STM32_SVD.UInt16;
-- stream x number of data register
type S2NDTR_Register is record
-- Number of data items to transfer
NDT : S2NDTR_NDT_Field := 16#0#;
-- unspecified
Reserved_16_31 : STM32_SVD.UInt16 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for S2NDTR_Register use record
NDT at 0 range 0 .. 15;
Reserved_16_31 at 0 range 16 .. 31;
end record;
subtype S2FCR_FTH_Field is STM32_SVD.UInt2;
subtype S2FCR_DMDIS_Field is STM32_SVD.Bit;
subtype S2FCR_FS_Field is STM32_SVD.UInt3;
subtype S2FCR_FEIE_Field is STM32_SVD.Bit;
-- stream x FIFO control register
type S2FCR_Register is record
-- FIFO threshold selection
FTH : S2FCR_FTH_Field := 16#1#;
-- Direct mode disable
DMDIS : S2FCR_DMDIS_Field := 16#0#;
-- Read-only. FIFO status
FS : S2FCR_FS_Field := 16#4#;
-- unspecified
Reserved_6_6 : STM32_SVD.Bit := 16#0#;
-- FIFO error interrupt enable
FEIE : S2FCR_FEIE_Field := 16#0#;
-- unspecified
Reserved_8_31 : STM32_SVD.UInt24 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for S2FCR_Register use record
FTH at 0 range 0 .. 1;
DMDIS at 0 range 2 .. 2;
FS at 0 range 3 .. 5;
Reserved_6_6 at 0 range 6 .. 6;
FEIE at 0 range 7 .. 7;
Reserved_8_31 at 0 range 8 .. 31;
end record;
subtype S3CR_EN_Field is STM32_SVD.Bit;
subtype S3CR_DMEIE_Field is STM32_SVD.Bit;
subtype S3CR_TEIE_Field is STM32_SVD.Bit;
subtype S3CR_HTIE_Field is STM32_SVD.Bit;
subtype S3CR_TCIE_Field is STM32_SVD.Bit;
subtype S3CR_PFCTRL_Field is STM32_SVD.Bit;
subtype S3CR_DIR_Field is STM32_SVD.UInt2;
subtype S3CR_CIRC_Field is STM32_SVD.Bit;
subtype S3CR_PINC_Field is STM32_SVD.Bit;
subtype S3CR_MINC_Field is STM32_SVD.Bit;
subtype S3CR_PSIZE_Field is STM32_SVD.UInt2;
subtype S3CR_MSIZE_Field is STM32_SVD.UInt2;
subtype S3CR_PINCOS_Field is STM32_SVD.Bit;
subtype S3CR_PL_Field is STM32_SVD.UInt2;
subtype S3CR_DBM_Field is STM32_SVD.Bit;
subtype S3CR_CT_Field is STM32_SVD.Bit;
subtype S3CR_ACK_Field is STM32_SVD.Bit;
subtype S3CR_PBURST_Field is STM32_SVD.UInt2;
subtype S3CR_MBURST_Field is STM32_SVD.UInt2;
subtype S3CR_CHSEL_Field is STM32_SVD.UInt3;
-- stream x configuration register
type S3CR_Register is record
-- Stream enable / flag stream ready when read low
EN : S3CR_EN_Field := 16#0#;
-- Direct mode error interrupt enable
DMEIE : S3CR_DMEIE_Field := 16#0#;
-- Transfer error interrupt enable
TEIE : S3CR_TEIE_Field := 16#0#;
-- Half transfer interrupt enable
HTIE : S3CR_HTIE_Field := 16#0#;
-- Transfer complete interrupt enable
TCIE : S3CR_TCIE_Field := 16#0#;
-- Peripheral flow controller
PFCTRL : S3CR_PFCTRL_Field := 16#0#;
-- Data transfer direction
DIR : S3CR_DIR_Field := 16#0#;
-- Circular mode
CIRC : S3CR_CIRC_Field := 16#0#;
-- Peripheral increment mode
PINC : S3CR_PINC_Field := 16#0#;
-- Memory increment mode
MINC : S3CR_MINC_Field := 16#0#;
-- Peripheral data size
PSIZE : S3CR_PSIZE_Field := 16#0#;
-- Memory data size
MSIZE : S3CR_MSIZE_Field := 16#0#;
-- Peripheral increment offset size
PINCOS : S3CR_PINCOS_Field := 16#0#;
-- Priority level
PL : S3CR_PL_Field := 16#0#;
-- Double buffer mode
DBM : S3CR_DBM_Field := 16#0#;
-- Current target (only in double buffer mode)
CT : S3CR_CT_Field := 16#0#;
-- ACK
ACK : S3CR_ACK_Field := 16#0#;
-- Peripheral burst transfer configuration
PBURST : S3CR_PBURST_Field := 16#0#;
-- Memory burst transfer configuration
MBURST : S3CR_MBURST_Field := 16#0#;
-- Channel selection
CHSEL : S3CR_CHSEL_Field := 16#0#;
-- unspecified
Reserved_28_31 : STM32_SVD.UInt4 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for S3CR_Register use record
EN at 0 range 0 .. 0;
DMEIE at 0 range 1 .. 1;
TEIE at 0 range 2 .. 2;
HTIE at 0 range 3 .. 3;
TCIE at 0 range 4 .. 4;
PFCTRL at 0 range 5 .. 5;
DIR at 0 range 6 .. 7;
CIRC at 0 range 8 .. 8;
PINC at 0 range 9 .. 9;
MINC at 0 range 10 .. 10;
PSIZE at 0 range 11 .. 12;
MSIZE at 0 range 13 .. 14;
PINCOS at 0 range 15 .. 15;
PL at 0 range 16 .. 17;
DBM at 0 range 18 .. 18;
CT at 0 range 19 .. 19;
ACK at 0 range 20 .. 20;
PBURST at 0 range 21 .. 22;
MBURST at 0 range 23 .. 24;
CHSEL at 0 range 25 .. 27;
Reserved_28_31 at 0 range 28 .. 31;
end record;
subtype S3NDTR_NDT_Field is STM32_SVD.UInt16;
-- stream x number of data register
type S3NDTR_Register is record
-- Number of data items to transfer
NDT : S3NDTR_NDT_Field := 16#0#;
-- unspecified
Reserved_16_31 : STM32_SVD.UInt16 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for S3NDTR_Register use record
NDT at 0 range 0 .. 15;
Reserved_16_31 at 0 range 16 .. 31;
end record;
subtype S3FCR_FTH_Field is STM32_SVD.UInt2;
subtype S3FCR_DMDIS_Field is STM32_SVD.Bit;
subtype S3FCR_FS_Field is STM32_SVD.UInt3;
subtype S3FCR_FEIE_Field is STM32_SVD.Bit;
-- stream x FIFO control register
type S3FCR_Register is record
-- FIFO threshold selection
FTH : S3FCR_FTH_Field := 16#1#;
-- Direct mode disable
DMDIS : S3FCR_DMDIS_Field := 16#0#;
-- Read-only. FIFO status
FS : S3FCR_FS_Field := 16#4#;
-- unspecified
Reserved_6_6 : STM32_SVD.Bit := 16#0#;
-- FIFO error interrupt enable
FEIE : S3FCR_FEIE_Field := 16#0#;
-- unspecified
Reserved_8_31 : STM32_SVD.UInt24 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for S3FCR_Register use record
FTH at 0 range 0 .. 1;
DMDIS at 0 range 2 .. 2;
FS at 0 range 3 .. 5;
Reserved_6_6 at 0 range 6 .. 6;
FEIE at 0 range 7 .. 7;
Reserved_8_31 at 0 range 8 .. 31;
end record;
subtype S4CR_EN_Field is STM32_SVD.Bit;
subtype S4CR_DMEIE_Field is STM32_SVD.Bit;
subtype S4CR_TEIE_Field is STM32_SVD.Bit;
subtype S4CR_HTIE_Field is STM32_SVD.Bit;
subtype S4CR_TCIE_Field is STM32_SVD.Bit;
subtype S4CR_PFCTRL_Field is STM32_SVD.Bit;
subtype S4CR_DIR_Field is STM32_SVD.UInt2;
subtype S4CR_CIRC_Field is STM32_SVD.Bit;
subtype S4CR_PINC_Field is STM32_SVD.Bit;
subtype S4CR_MINC_Field is STM32_SVD.Bit;
subtype S4CR_PSIZE_Field is STM32_SVD.UInt2;
subtype S4CR_MSIZE_Field is STM32_SVD.UInt2;
subtype S4CR_PINCOS_Field is STM32_SVD.Bit;
subtype S4CR_PL_Field is STM32_SVD.UInt2;
subtype S4CR_DBM_Field is STM32_SVD.Bit;
subtype S4CR_CT_Field is STM32_SVD.Bit;
subtype S4CR_ACK_Field is STM32_SVD.Bit;
subtype S4CR_PBURST_Field is STM32_SVD.UInt2;
subtype S4CR_MBURST_Field is STM32_SVD.UInt2;
subtype S4CR_CHSEL_Field is STM32_SVD.UInt3;
-- stream x configuration register
type S4CR_Register is record
-- Stream enable / flag stream ready when read low
EN : S4CR_EN_Field := 16#0#;
-- Direct mode error interrupt enable
DMEIE : S4CR_DMEIE_Field := 16#0#;
-- Transfer error interrupt enable
TEIE : S4CR_TEIE_Field := 16#0#;
-- Half transfer interrupt enable
HTIE : S4CR_HTIE_Field := 16#0#;
-- Transfer complete interrupt enable
TCIE : S4CR_TCIE_Field := 16#0#;
-- Peripheral flow controller
PFCTRL : S4CR_PFCTRL_Field := 16#0#;
-- Data transfer direction
DIR : S4CR_DIR_Field := 16#0#;
-- Circular mode
CIRC : S4CR_CIRC_Field := 16#0#;
-- Peripheral increment mode
PINC : S4CR_PINC_Field := 16#0#;
-- Memory increment mode
MINC : S4CR_MINC_Field := 16#0#;
-- Peripheral data size
PSIZE : S4CR_PSIZE_Field := 16#0#;
-- Memory data size
MSIZE : S4CR_MSIZE_Field := 16#0#;
-- Peripheral increment offset size
PINCOS : S4CR_PINCOS_Field := 16#0#;
-- Priority level
PL : S4CR_PL_Field := 16#0#;
-- Double buffer mode
DBM : S4CR_DBM_Field := 16#0#;
-- Current target (only in double buffer mode)
CT : S4CR_CT_Field := 16#0#;
-- ACK
ACK : S4CR_ACK_Field := 16#0#;
-- Peripheral burst transfer configuration
PBURST : S4CR_PBURST_Field := 16#0#;
-- Memory burst transfer configuration
MBURST : S4CR_MBURST_Field := 16#0#;
-- Channel selection
CHSEL : S4CR_CHSEL_Field := 16#0#;
-- unspecified
Reserved_28_31 : STM32_SVD.UInt4 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for S4CR_Register use record
EN at 0 range 0 .. 0;
DMEIE at 0 range 1 .. 1;
TEIE at 0 range 2 .. 2;
HTIE at 0 range 3 .. 3;
TCIE at 0 range 4 .. 4;
PFCTRL at 0 range 5 .. 5;
DIR at 0 range 6 .. 7;
CIRC at 0 range 8 .. 8;
PINC at 0 range 9 .. 9;
MINC at 0 range 10 .. 10;
PSIZE at 0 range 11 .. 12;
MSIZE at 0 range 13 .. 14;
PINCOS at 0 range 15 .. 15;
PL at 0 range 16 .. 17;
DBM at 0 range 18 .. 18;
CT at 0 range 19 .. 19;
ACK at 0 range 20 .. 20;
PBURST at 0 range 21 .. 22;
MBURST at 0 range 23 .. 24;
CHSEL at 0 range 25 .. 27;
Reserved_28_31 at 0 range 28 .. 31;
end record;
subtype S4NDTR_NDT_Field is STM32_SVD.UInt16;
-- stream x number of data register
type S4NDTR_Register is record
-- Number of data items to transfer
NDT : S4NDTR_NDT_Field := 16#0#;
-- unspecified
Reserved_16_31 : STM32_SVD.UInt16 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for S4NDTR_Register use record
NDT at 0 range 0 .. 15;
Reserved_16_31 at 0 range 16 .. 31;
end record;
subtype S4FCR_FTH_Field is STM32_SVD.UInt2;
subtype S4FCR_DMDIS_Field is STM32_SVD.Bit;
subtype S4FCR_FS_Field is STM32_SVD.UInt3;
subtype S4FCR_FEIE_Field is STM32_SVD.Bit;
-- stream x FIFO control register
type S4FCR_Register is record
-- FIFO threshold selection
FTH : S4FCR_FTH_Field := 16#1#;
-- Direct mode disable
DMDIS : S4FCR_DMDIS_Field := 16#0#;
-- Read-only. FIFO status
FS : S4FCR_FS_Field := 16#4#;
-- unspecified
Reserved_6_6 : STM32_SVD.Bit := 16#0#;
-- FIFO error interrupt enable
FEIE : S4FCR_FEIE_Field := 16#0#;
-- unspecified
Reserved_8_31 : STM32_SVD.UInt24 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for S4FCR_Register use record
FTH at 0 range 0 .. 1;
DMDIS at 0 range 2 .. 2;
FS at 0 range 3 .. 5;
Reserved_6_6 at 0 range 6 .. 6;
FEIE at 0 range 7 .. 7;
Reserved_8_31 at 0 range 8 .. 31;
end record;
subtype S5CR_EN_Field is STM32_SVD.Bit;
subtype S5CR_DMEIE_Field is STM32_SVD.Bit;
subtype S5CR_TEIE_Field is STM32_SVD.Bit;
subtype S5CR_HTIE_Field is STM32_SVD.Bit;
subtype S5CR_TCIE_Field is STM32_SVD.Bit;
subtype S5CR_PFCTRL_Field is STM32_SVD.Bit;
subtype S5CR_DIR_Field is STM32_SVD.UInt2;
subtype S5CR_CIRC_Field is STM32_SVD.Bit;
subtype S5CR_PINC_Field is STM32_SVD.Bit;
subtype S5CR_MINC_Field is STM32_SVD.Bit;
subtype S5CR_PSIZE_Field is STM32_SVD.UInt2;
subtype S5CR_MSIZE_Field is STM32_SVD.UInt2;
subtype S5CR_PINCOS_Field is STM32_SVD.Bit;
subtype S5CR_PL_Field is STM32_SVD.UInt2;
subtype S5CR_DBM_Field is STM32_SVD.Bit;
subtype S5CR_CT_Field is STM32_SVD.Bit;
subtype S5CR_ACK_Field is STM32_SVD.Bit;
subtype S5CR_PBURST_Field is STM32_SVD.UInt2;
subtype S5CR_MBURST_Field is STM32_SVD.UInt2;
subtype S5CR_CHSEL_Field is STM32_SVD.UInt3;
-- stream x configuration register
type S5CR_Register is record
-- Stream enable / flag stream ready when read low
EN : S5CR_EN_Field := 16#0#;
-- Direct mode error interrupt enable
DMEIE : S5CR_DMEIE_Field := 16#0#;
-- Transfer error interrupt enable
TEIE : S5CR_TEIE_Field := 16#0#;
-- Half transfer interrupt enable
HTIE : S5CR_HTIE_Field := 16#0#;
-- Transfer complete interrupt enable
TCIE : S5CR_TCIE_Field := 16#0#;
-- Peripheral flow controller
PFCTRL : S5CR_PFCTRL_Field := 16#0#;
-- Data transfer direction
DIR : S5CR_DIR_Field := 16#0#;
-- Circular mode
CIRC : S5CR_CIRC_Field := 16#0#;
-- Peripheral increment mode
PINC : S5CR_PINC_Field := 16#0#;
-- Memory increment mode
MINC : S5CR_MINC_Field := 16#0#;
-- Peripheral data size
PSIZE : S5CR_PSIZE_Field := 16#0#;
-- Memory data size
MSIZE : S5CR_MSIZE_Field := 16#0#;
-- Peripheral increment offset size
PINCOS : S5CR_PINCOS_Field := 16#0#;
-- Priority level
PL : S5CR_PL_Field := 16#0#;
-- Double buffer mode
DBM : S5CR_DBM_Field := 16#0#;
-- Current target (only in double buffer mode)
CT : S5CR_CT_Field := 16#0#;
-- ACK
ACK : S5CR_ACK_Field := 16#0#;
-- Peripheral burst transfer configuration
PBURST : S5CR_PBURST_Field := 16#0#;
-- Memory burst transfer configuration
MBURST : S5CR_MBURST_Field := 16#0#;
-- Channel selection
CHSEL : S5CR_CHSEL_Field := 16#0#;
-- unspecified
Reserved_28_31 : STM32_SVD.UInt4 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for S5CR_Register use record
EN at 0 range 0 .. 0;
DMEIE at 0 range 1 .. 1;
TEIE at 0 range 2 .. 2;
HTIE at 0 range 3 .. 3;
TCIE at 0 range 4 .. 4;
PFCTRL at 0 range 5 .. 5;
DIR at 0 range 6 .. 7;
CIRC at 0 range 8 .. 8;
PINC at 0 range 9 .. 9;
MINC at 0 range 10 .. 10;
PSIZE at 0 range 11 .. 12;
MSIZE at 0 range 13 .. 14;
PINCOS at 0 range 15 .. 15;
PL at 0 range 16 .. 17;
DBM at 0 range 18 .. 18;
CT at 0 range 19 .. 19;
ACK at 0 range 20 .. 20;
PBURST at 0 range 21 .. 22;
MBURST at 0 range 23 .. 24;
CHSEL at 0 range 25 .. 27;
Reserved_28_31 at 0 range 28 .. 31;
end record;
subtype S5NDTR_NDT_Field is STM32_SVD.UInt16;
-- stream x number of data register
type S5NDTR_Register is record
-- Number of data items to transfer
NDT : S5NDTR_NDT_Field := 16#0#;
-- unspecified
Reserved_16_31 : STM32_SVD.UInt16 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for S5NDTR_Register use record
NDT at 0 range 0 .. 15;
Reserved_16_31 at 0 range 16 .. 31;
end record;
subtype S5FCR_FTH_Field is STM32_SVD.UInt2;
subtype S5FCR_DMDIS_Field is STM32_SVD.Bit;
subtype S5FCR_FS_Field is STM32_SVD.UInt3;
subtype S5FCR_FEIE_Field is STM32_SVD.Bit;
-- stream x FIFO control register
type S5FCR_Register is record
-- FIFO threshold selection
FTH : S5FCR_FTH_Field := 16#1#;
-- Direct mode disable
DMDIS : S5FCR_DMDIS_Field := 16#0#;
-- Read-only. FIFO status
FS : S5FCR_FS_Field := 16#4#;
-- unspecified
Reserved_6_6 : STM32_SVD.Bit := 16#0#;
-- FIFO error interrupt enable
FEIE : S5FCR_FEIE_Field := 16#0#;
-- unspecified
Reserved_8_31 : STM32_SVD.UInt24 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for S5FCR_Register use record
FTH at 0 range 0 .. 1;
DMDIS at 0 range 2 .. 2;
FS at 0 range 3 .. 5;
Reserved_6_6 at 0 range 6 .. 6;
FEIE at 0 range 7 .. 7;
Reserved_8_31 at 0 range 8 .. 31;
end record;
subtype S6CR_EN_Field is STM32_SVD.Bit;
subtype S6CR_DMEIE_Field is STM32_SVD.Bit;
subtype S6CR_TEIE_Field is STM32_SVD.Bit;
subtype S6CR_HTIE_Field is STM32_SVD.Bit;
subtype S6CR_TCIE_Field is STM32_SVD.Bit;
subtype S6CR_PFCTRL_Field is STM32_SVD.Bit;
subtype S6CR_DIR_Field is STM32_SVD.UInt2;
subtype S6CR_CIRC_Field is STM32_SVD.Bit;
subtype S6CR_PINC_Field is STM32_SVD.Bit;
subtype S6CR_MINC_Field is STM32_SVD.Bit;
subtype S6CR_PSIZE_Field is STM32_SVD.UInt2;
subtype S6CR_MSIZE_Field is STM32_SVD.UInt2;
subtype S6CR_PINCOS_Field is STM32_SVD.Bit;
subtype S6CR_PL_Field is STM32_SVD.UInt2;
subtype S6CR_DBM_Field is STM32_SVD.Bit;
subtype S6CR_CT_Field is STM32_SVD.Bit;
subtype S6CR_ACK_Field is STM32_SVD.Bit;
subtype S6CR_PBURST_Field is STM32_SVD.UInt2;
subtype S6CR_MBURST_Field is STM32_SVD.UInt2;
subtype S6CR_CHSEL_Field is STM32_SVD.UInt3;
-- stream x configuration register
type S6CR_Register is record
-- Stream enable / flag stream ready when read low
EN : S6CR_EN_Field := 16#0#;
-- Direct mode error interrupt enable
DMEIE : S6CR_DMEIE_Field := 16#0#;
-- Transfer error interrupt enable
TEIE : S6CR_TEIE_Field := 16#0#;
-- Half transfer interrupt enable
HTIE : S6CR_HTIE_Field := 16#0#;
-- Transfer complete interrupt enable
TCIE : S6CR_TCIE_Field := 16#0#;
-- Peripheral flow controller
PFCTRL : S6CR_PFCTRL_Field := 16#0#;
-- Data transfer direction
DIR : S6CR_DIR_Field := 16#0#;
-- Circular mode
CIRC : S6CR_CIRC_Field := 16#0#;
-- Peripheral increment mode
PINC : S6CR_PINC_Field := 16#0#;
-- Memory increment mode
MINC : S6CR_MINC_Field := 16#0#;
-- Peripheral data size
PSIZE : S6CR_PSIZE_Field := 16#0#;
-- Memory data size
MSIZE : S6CR_MSIZE_Field := 16#0#;
-- Peripheral increment offset size
PINCOS : S6CR_PINCOS_Field := 16#0#;
-- Priority level
PL : S6CR_PL_Field := 16#0#;
-- Double buffer mode
DBM : S6CR_DBM_Field := 16#0#;
-- Current target (only in double buffer mode)
CT : S6CR_CT_Field := 16#0#;
-- ACK
ACK : S6CR_ACK_Field := 16#0#;
-- Peripheral burst transfer configuration
PBURST : S6CR_PBURST_Field := 16#0#;
-- Memory burst transfer configuration
MBURST : S6CR_MBURST_Field := 16#0#;
-- Channel selection
CHSEL : S6CR_CHSEL_Field := 16#0#;
-- unspecified
Reserved_28_31 : STM32_SVD.UInt4 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for S6CR_Register use record
EN at 0 range 0 .. 0;
DMEIE at 0 range 1 .. 1;
TEIE at 0 range 2 .. 2;
HTIE at 0 range 3 .. 3;
TCIE at 0 range 4 .. 4;
PFCTRL at 0 range 5 .. 5;
DIR at 0 range 6 .. 7;
CIRC at 0 range 8 .. 8;
PINC at 0 range 9 .. 9;
MINC at 0 range 10 .. 10;
PSIZE at 0 range 11 .. 12;
MSIZE at 0 range 13 .. 14;
PINCOS at 0 range 15 .. 15;
PL at 0 range 16 .. 17;
DBM at 0 range 18 .. 18;
CT at 0 range 19 .. 19;
ACK at 0 range 20 .. 20;
PBURST at 0 range 21 .. 22;
MBURST at 0 range 23 .. 24;
CHSEL at 0 range 25 .. 27;
Reserved_28_31 at 0 range 28 .. 31;
end record;
subtype S6NDTR_NDT_Field is STM32_SVD.UInt16;
-- stream x number of data register
type S6NDTR_Register is record
-- Number of data items to transfer
NDT : S6NDTR_NDT_Field := 16#0#;
-- unspecified
Reserved_16_31 : STM32_SVD.UInt16 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for S6NDTR_Register use record
NDT at 0 range 0 .. 15;
Reserved_16_31 at 0 range 16 .. 31;
end record;
subtype S6FCR_FTH_Field is STM32_SVD.UInt2;
subtype S6FCR_DMDIS_Field is STM32_SVD.Bit;
subtype S6FCR_FS_Field is STM32_SVD.UInt3;
subtype S6FCR_FEIE_Field is STM32_SVD.Bit;
-- stream x FIFO control register
type S6FCR_Register is record
-- FIFO threshold selection
FTH : S6FCR_FTH_Field := 16#1#;
-- Direct mode disable
DMDIS : S6FCR_DMDIS_Field := 16#0#;
-- Read-only. FIFO status
FS : S6FCR_FS_Field := 16#4#;
-- unspecified
Reserved_6_6 : STM32_SVD.Bit := 16#0#;
-- FIFO error interrupt enable
FEIE : S6FCR_FEIE_Field := 16#0#;
-- unspecified
Reserved_8_31 : STM32_SVD.UInt24 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for S6FCR_Register use record
FTH at 0 range 0 .. 1;
DMDIS at 0 range 2 .. 2;
FS at 0 range 3 .. 5;
Reserved_6_6 at 0 range 6 .. 6;
FEIE at 0 range 7 .. 7;
Reserved_8_31 at 0 range 8 .. 31;
end record;
subtype S7CR_EN_Field is STM32_SVD.Bit;
subtype S7CR_DMEIE_Field is STM32_SVD.Bit;
subtype S7CR_TEIE_Field is STM32_SVD.Bit;
subtype S7CR_HTIE_Field is STM32_SVD.Bit;
subtype S7CR_TCIE_Field is STM32_SVD.Bit;
subtype S7CR_PFCTRL_Field is STM32_SVD.Bit;
subtype S7CR_DIR_Field is STM32_SVD.UInt2;
subtype S7CR_CIRC_Field is STM32_SVD.Bit;
subtype S7CR_PINC_Field is STM32_SVD.Bit;
subtype S7CR_MINC_Field is STM32_SVD.Bit;
subtype S7CR_PSIZE_Field is STM32_SVD.UInt2;
subtype S7CR_MSIZE_Field is STM32_SVD.UInt2;
subtype S7CR_PINCOS_Field is STM32_SVD.Bit;
subtype S7CR_PL_Field is STM32_SVD.UInt2;
subtype S7CR_DBM_Field is STM32_SVD.Bit;
subtype S7CR_CT_Field is STM32_SVD.Bit;
subtype S7CR_ACK_Field is STM32_SVD.Bit;
subtype S7CR_PBURST_Field is STM32_SVD.UInt2;
subtype S7CR_MBURST_Field is STM32_SVD.UInt2;
subtype S7CR_CHSEL_Field is STM32_SVD.UInt3;
-- stream x configuration register
type S7CR_Register is record
-- Stream enable / flag stream ready when read low
EN : S7CR_EN_Field := 16#0#;
-- Direct mode error interrupt enable
DMEIE : S7CR_DMEIE_Field := 16#0#;
-- Transfer error interrupt enable
TEIE : S7CR_TEIE_Field := 16#0#;
-- Half transfer interrupt enable
HTIE : S7CR_HTIE_Field := 16#0#;
-- Transfer complete interrupt enable
TCIE : S7CR_TCIE_Field := 16#0#;
-- Peripheral flow controller
PFCTRL : S7CR_PFCTRL_Field := 16#0#;
-- Data transfer direction
DIR : S7CR_DIR_Field := 16#0#;
-- Circular mode
CIRC : S7CR_CIRC_Field := 16#0#;
-- Peripheral increment mode
PINC : S7CR_PINC_Field := 16#0#;
-- Memory increment mode
MINC : S7CR_MINC_Field := 16#0#;
-- Peripheral data size
PSIZE : S7CR_PSIZE_Field := 16#0#;
-- Memory data size
MSIZE : S7CR_MSIZE_Field := 16#0#;
-- Peripheral increment offset size
PINCOS : S7CR_PINCOS_Field := 16#0#;
-- Priority level
PL : S7CR_PL_Field := 16#0#;
-- Double buffer mode
DBM : S7CR_DBM_Field := 16#0#;
-- Current target (only in double buffer mode)
CT : S7CR_CT_Field := 16#0#;
-- ACK
ACK : S7CR_ACK_Field := 16#0#;
-- Peripheral burst transfer configuration
PBURST : S7CR_PBURST_Field := 16#0#;
-- Memory burst transfer configuration
MBURST : S7CR_MBURST_Field := 16#0#;
-- Channel selection
CHSEL : S7CR_CHSEL_Field := 16#0#;
-- unspecified
Reserved_28_31 : STM32_SVD.UInt4 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for S7CR_Register use record
EN at 0 range 0 .. 0;
DMEIE at 0 range 1 .. 1;
TEIE at 0 range 2 .. 2;
HTIE at 0 range 3 .. 3;
TCIE at 0 range 4 .. 4;
PFCTRL at 0 range 5 .. 5;
DIR at 0 range 6 .. 7;
CIRC at 0 range 8 .. 8;
PINC at 0 range 9 .. 9;
MINC at 0 range 10 .. 10;
PSIZE at 0 range 11 .. 12;
MSIZE at 0 range 13 .. 14;
PINCOS at 0 range 15 .. 15;
PL at 0 range 16 .. 17;
DBM at 0 range 18 .. 18;
CT at 0 range 19 .. 19;
ACK at 0 range 20 .. 20;
PBURST at 0 range 21 .. 22;
MBURST at 0 range 23 .. 24;
CHSEL at 0 range 25 .. 27;
Reserved_28_31 at 0 range 28 .. 31;
end record;
subtype S7NDTR_NDT_Field is STM32_SVD.UInt16;
-- stream x number of data register
type S7NDTR_Register is record
-- Number of data items to transfer
NDT : S7NDTR_NDT_Field := 16#0#;
-- unspecified
Reserved_16_31 : STM32_SVD.UInt16 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for S7NDTR_Register use record
NDT at 0 range 0 .. 15;
Reserved_16_31 at 0 range 16 .. 31;
end record;
subtype S7FCR_FTH_Field is STM32_SVD.UInt2;
subtype S7FCR_DMDIS_Field is STM32_SVD.Bit;
subtype S7FCR_FS_Field is STM32_SVD.UInt3;
subtype S7FCR_FEIE_Field is STM32_SVD.Bit;
-- stream x FIFO control register
type S7FCR_Register is record
-- FIFO threshold selection
FTH : S7FCR_FTH_Field := 16#1#;
-- Direct mode disable
DMDIS : S7FCR_DMDIS_Field := 16#0#;
-- Read-only. FIFO status
FS : S7FCR_FS_Field := 16#4#;
-- unspecified
Reserved_6_6 : STM32_SVD.Bit := 16#0#;
-- FIFO error interrupt enable
FEIE : S7FCR_FEIE_Field := 16#0#;
-- unspecified
Reserved_8_31 : STM32_SVD.UInt24 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for S7FCR_Register use record
FTH at 0 range 0 .. 1;
DMDIS at 0 range 2 .. 2;
FS at 0 range 3 .. 5;
Reserved_6_6 at 0 range 6 .. 6;
FEIE at 0 range 7 .. 7;
Reserved_8_31 at 0 range 8 .. 31;
end record;
-----------------
-- Peripherals --
-----------------
-- DMA controller
type DMA_Peripheral is record
-- low interrupt status register
LISR : aliased LISR_Register;
-- high interrupt status register
HISR : aliased HISR_Register;
-- low interrupt flag clear register
LIFCR : aliased LIFCR_Register;
-- high interrupt flag clear register
HIFCR : aliased HIFCR_Register;
-- stream x configuration register
S0CR : aliased S0CR_Register;
-- stream x number of data register
S0NDTR : aliased S0NDTR_Register;
-- stream x peripheral address register
S0PAR : aliased STM32_SVD.UInt32;
-- stream x memory 0 address register
S0M0AR : aliased STM32_SVD.UInt32;
-- stream x memory 1 address register
S0M1AR : aliased STM32_SVD.UInt32;
-- stream x FIFO control register
S0FCR : aliased S0FCR_Register;
-- stream x configuration register
S1CR : aliased S1CR_Register;
-- stream x number of data register
S1NDTR : aliased S1NDTR_Register;
-- stream x peripheral address register
S1PAR : aliased STM32_SVD.UInt32;
-- stream x memory 0 address register
S1M0AR : aliased STM32_SVD.UInt32;
-- stream x memory 1 address register
S1M1AR : aliased STM32_SVD.UInt32;
-- stream x FIFO control register
S1FCR : aliased S1FCR_Register;
-- stream x configuration register
S2CR : aliased S2CR_Register;
-- stream x number of data register
S2NDTR : aliased S2NDTR_Register;
-- stream x peripheral address register
S2PAR : aliased STM32_SVD.UInt32;
-- stream x memory 0 address register
S2M0AR : aliased STM32_SVD.UInt32;
-- stream x memory 1 address register
S2M1AR : aliased STM32_SVD.UInt32;
-- stream x FIFO control register
S2FCR : aliased S2FCR_Register;
-- stream x configuration register
S3CR : aliased S3CR_Register;
-- stream x number of data register
S3NDTR : aliased S3NDTR_Register;
-- stream x peripheral address register
S3PAR : aliased STM32_SVD.UInt32;
-- stream x memory 0 address register
S3M0AR : aliased STM32_SVD.UInt32;
-- stream x memory 1 address register
S3M1AR : aliased STM32_SVD.UInt32;
-- stream x FIFO control register
S3FCR : aliased S3FCR_Register;
-- stream x configuration register
S4CR : aliased S4CR_Register;
-- stream x number of data register
S4NDTR : aliased S4NDTR_Register;
-- stream x peripheral address register
S4PAR : aliased STM32_SVD.UInt32;
-- stream x memory 0 address register
S4M0AR : aliased STM32_SVD.UInt32;
-- stream x memory 1 address register
S4M1AR : aliased STM32_SVD.UInt32;
-- stream x FIFO control register
S4FCR : aliased S4FCR_Register;
-- stream x configuration register
S5CR : aliased S5CR_Register;
-- stream x number of data register
S5NDTR : aliased S5NDTR_Register;
-- stream x peripheral address register
S5PAR : aliased STM32_SVD.UInt32;
-- stream x memory 0 address register
S5M0AR : aliased STM32_SVD.UInt32;
-- stream x memory 1 address register
S5M1AR : aliased STM32_SVD.UInt32;
-- stream x FIFO control register
S5FCR : aliased S5FCR_Register;
-- stream x configuration register
S6CR : aliased S6CR_Register;
-- stream x number of data register
S6NDTR : aliased S6NDTR_Register;
-- stream x peripheral address register
S6PAR : aliased STM32_SVD.UInt32;
-- stream x memory 0 address register
S6M0AR : aliased STM32_SVD.UInt32;
-- stream x memory 1 address register
S6M1AR : aliased STM32_SVD.UInt32;
-- stream x FIFO control register
S6FCR : aliased S6FCR_Register;
-- stream x configuration register
S7CR : aliased S7CR_Register;
-- stream x number of data register
S7NDTR : aliased S7NDTR_Register;
-- stream x peripheral address register
S7PAR : aliased STM32_SVD.UInt32;
-- stream x memory 0 address register
S7M0AR : aliased STM32_SVD.UInt32;
-- stream x memory 1 address register
S7M1AR : aliased STM32_SVD.UInt32;
-- stream x FIFO control register
S7FCR : aliased S7FCR_Register;
end record
with Volatile;
for DMA_Peripheral use record
LISR at 16#0# range 0 .. 31;
HISR at 16#4# range 0 .. 31;
LIFCR at 16#8# range 0 .. 31;
HIFCR at 16#C# range 0 .. 31;
S0CR at 16#10# range 0 .. 31;
S0NDTR at 16#14# range 0 .. 31;
S0PAR at 16#18# range 0 .. 31;
S0M0AR at 16#1C# range 0 .. 31;
S0M1AR at 16#20# range 0 .. 31;
S0FCR at 16#24# range 0 .. 31;
S1CR at 16#28# range 0 .. 31;
S1NDTR at 16#2C# range 0 .. 31;
S1PAR at 16#30# range 0 .. 31;
S1M0AR at 16#34# range 0 .. 31;
S1M1AR at 16#38# range 0 .. 31;
S1FCR at 16#3C# range 0 .. 31;
S2CR at 16#40# range 0 .. 31;
S2NDTR at 16#44# range 0 .. 31;
S2PAR at 16#48# range 0 .. 31;
S2M0AR at 16#4C# range 0 .. 31;
S2M1AR at 16#50# range 0 .. 31;
S2FCR at 16#54# range 0 .. 31;
S3CR at 16#58# range 0 .. 31;
S3NDTR at 16#5C# range 0 .. 31;
S3PAR at 16#60# range 0 .. 31;
S3M0AR at 16#64# range 0 .. 31;
S3M1AR at 16#68# range 0 .. 31;
S3FCR at 16#6C# range 0 .. 31;
S4CR at 16#70# range 0 .. 31;
S4NDTR at 16#74# range 0 .. 31;
S4PAR at 16#78# range 0 .. 31;
S4M0AR at 16#7C# range 0 .. 31;
S4M1AR at 16#80# range 0 .. 31;
S4FCR at 16#84# range 0 .. 31;
S5CR at 16#88# range 0 .. 31;
S5NDTR at 16#8C# range 0 .. 31;
S5PAR at 16#90# range 0 .. 31;
S5M0AR at 16#94# range 0 .. 31;
S5M1AR at 16#98# range 0 .. 31;
S5FCR at 16#9C# range 0 .. 31;
S6CR at 16#A0# range 0 .. 31;
S6NDTR at 16#A4# range 0 .. 31;
S6PAR at 16#A8# range 0 .. 31;
S6M0AR at 16#AC# range 0 .. 31;
S6M1AR at 16#B0# range 0 .. 31;
S6FCR at 16#B4# range 0 .. 31;
S7CR at 16#B8# range 0 .. 31;
S7NDTR at 16#BC# range 0 .. 31;
S7PAR at 16#C0# range 0 .. 31;
S7M0AR at 16#C4# range 0 .. 31;
S7M1AR at 16#C8# range 0 .. 31;
S7FCR at 16#CC# range 0 .. 31;
end record;
-- DMA controller
DMA1_Periph : aliased DMA_Peripheral
with Import, Address => System'To_Address (16#40026000#);
-- DMA controller
DMA2_Periph : aliased DMA_Peripheral
with Import, Address => System'To_Address (16#40026400#);
end STM32_SVD.DMA;
|
------------------------------------------------------------------------------
-- --
-- GNAT RUN-TIME COMPONENTS --
-- --
-- ADA.NUMERICS.BIG_NUMBERS.BIG_INTEGERS --
-- --
-- B o d y --
-- --
-- Copyright (C) 2019-2020, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. --
-- --
-- As a special exception under Section 7 of GPL version 3, you are granted --
-- additional permissions described in the GCC Runtime Library Exception, --
-- version 3.1, as published by the Free Software Foundation. --
-- --
-- You should have received a copy of the GNU General Public License and --
-- a copy of the GCC Runtime Library Exception along with this program; --
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
-- <http://www.gnu.org/licenses/>. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
-- This is the GMP version of this package
with Ada.Unchecked_Conversion;
with Ada.Unchecked_Deallocation;
with Interfaces.C; use Interfaces.C;
with Interfaces.C.Strings; use Interfaces.C.Strings;
with Ada.Strings.Text_Output.Utils;
with Ada.Characters.Handling; use Ada.Characters.Handling;
package body Ada.Numerics.Big_Numbers.Big_Integers is
use System;
pragma Linker_Options ("-lgmp");
type mpz_t is record
mp_alloc : Integer;
mp_size : Integer;
mp_d : System.Address;
end record;
pragma Convention (C, mpz_t);
type mpz_t_ptr is access all mpz_t;
function To_Mpz is new Ada.Unchecked_Conversion (System.Address, mpz_t_ptr);
function To_Address is new
Ada.Unchecked_Conversion (mpz_t_ptr, System.Address);
function Get_Mpz (Arg : Big_Integer) return mpz_t_ptr is
(To_Mpz (Arg.Value.C));
-- Return the mpz_t value stored in Arg
procedure Set_Mpz (Arg : in out Big_Integer; Value : mpz_t_ptr)
with Inline;
-- Set the mpz_t value stored in Arg to Value
procedure Allocate (This : in out Big_Integer) with Inline;
-- Allocate a Big_Integer, including the underlying mpz
procedure mpz_init_set (ROP : access mpz_t; OP : access constant mpz_t);
pragma Import (C, mpz_init_set, "__gmpz_init_set");
procedure mpz_set (ROP : access mpz_t; OP : access constant mpz_t);
pragma Import (C, mpz_set, "__gmpz_set");
function mpz_cmp (OP1, OP2 : access constant mpz_t) return Integer;
pragma Import (C, mpz_cmp, "__gmpz_cmp");
function mpz_cmp_ui
(OP1 : access constant mpz_t; OP2 : unsigned_long) return Integer;
pragma Import (C, mpz_cmp_ui, "__gmpz_cmp_ui");
procedure mpz_set_si (ROP : access mpz_t; OP : long);
pragma Import (C, mpz_set_si, "__gmpz_set_si");
procedure mpz_set_ui (ROP : access mpz_t; OP : unsigned_long);
pragma Import (C, mpz_set_ui, "__gmpz_set_ui");
function mpz_get_si (OP : access constant mpz_t) return long;
pragma Import (C, mpz_get_si, "__gmpz_get_si");
function mpz_get_ui (OP : access constant mpz_t) return unsigned_long;
pragma Import (C, mpz_get_ui, "__gmpz_get_ui");
procedure mpz_neg (ROP : access mpz_t; OP : access constant mpz_t);
pragma Import (C, mpz_neg, "__gmpz_neg");
procedure mpz_sub (ROP : access mpz_t; OP1, OP2 : access constant mpz_t);
pragma Import (C, mpz_sub, "__gmpz_sub");
-------------
-- Set_Mpz --
-------------
procedure Set_Mpz (Arg : in out Big_Integer; Value : mpz_t_ptr) is
begin
Arg.Value.C := To_Address (Value);
end Set_Mpz;
--------------
-- Is_Valid --
--------------
function Is_Valid (Arg : Big_Integer) return Boolean is
(Arg.Value.C /= System.Null_Address);
---------
-- "=" --
---------
function "=" (L, R : Valid_Big_Integer) return Boolean is
begin
return mpz_cmp (Get_Mpz (L), Get_Mpz (R)) = 0;
end "=";
---------
-- "<" --
---------
function "<" (L, R : Valid_Big_Integer) return Boolean is
begin
return mpz_cmp (Get_Mpz (L), Get_Mpz (R)) < 0;
end "<";
----------
-- "<=" --
----------
function "<=" (L, R : Valid_Big_Integer) return Boolean is
begin
return mpz_cmp (Get_Mpz (L), Get_Mpz (R)) <= 0;
end "<=";
---------
-- ">" --
---------
function ">" (L, R : Valid_Big_Integer) return Boolean is
begin
return mpz_cmp (Get_Mpz (L), Get_Mpz (R)) > 0;
end ">";
----------
-- ">=" --
----------
function ">=" (L, R : Valid_Big_Integer) return Boolean is
begin
return mpz_cmp (Get_Mpz (L), Get_Mpz (R)) >= 0;
end ">=";
--------------------
-- To_Big_Integer --
--------------------
function To_Big_Integer (Arg : Integer) return Valid_Big_Integer is
Result : Big_Integer;
begin
Allocate (Result);
mpz_set_si (Get_Mpz (Result), long (Arg));
return Result;
end To_Big_Integer;
----------------
-- To_Integer --
----------------
function To_Integer (Arg : Valid_Big_Integer) return Integer is
begin
return Integer (mpz_get_si (Get_Mpz (Arg)));
end To_Integer;
------------------------
-- Signed_Conversions --
------------------------
package body Signed_Conversions is
--------------------
-- To_Big_Integer --
--------------------
function To_Big_Integer (Arg : Int) return Valid_Big_Integer is
Result : Big_Integer;
begin
Allocate (Result);
mpz_set_si (Get_Mpz (Result), long (Arg));
return Result;
end To_Big_Integer;
----------------------
-- From_Big_Integer --
----------------------
function From_Big_Integer (Arg : Valid_Big_Integer) return Int is
begin
return Int (mpz_get_si (Get_Mpz (Arg)));
end From_Big_Integer;
end Signed_Conversions;
--------------------------
-- Unsigned_Conversions --
--------------------------
package body Unsigned_Conversions is
--------------------
-- To_Big_Integer --
--------------------
function To_Big_Integer (Arg : Int) return Valid_Big_Integer is
Result : Big_Integer;
begin
Allocate (Result);
mpz_set_ui (Get_Mpz (Result), unsigned_long (Arg));
return Result;
end To_Big_Integer;
----------------------
-- From_Big_Integer --
----------------------
function From_Big_Integer (Arg : Valid_Big_Integer) return Int is
begin
return Int (mpz_get_ui (Get_Mpz (Arg)));
end From_Big_Integer;
end Unsigned_Conversions;
---------------
-- To_String --
---------------
function To_String
(Arg : Valid_Big_Integer; Width : Field := 0; Base : Number_Base := 10)
return String
is
function mpz_get_str
(STR : System.Address;
BASE : Integer;
OP : access constant mpz_t) return chars_ptr;
pragma Import (C, mpz_get_str, "__gmpz_get_str");
function mpz_sizeinbase
(this : access constant mpz_t; base : Integer) return size_t;
pragma Import (C, mpz_sizeinbase, "__gmpz_sizeinbase");
function Add_Base (S : String) return String;
-- Add base information if Base /= 10
function Leading_Padding
(Str : String;
Min_Length : Field;
Char : Character := ' ') return String;
-- Return padding of Char concatenated with Str so that the resulting
-- string is at least Min_Length long.
function Image (N : Natural) return String;
-- Return image of N, with no leading space.
--------------
-- Add_Base --
--------------
function Add_Base (S : String) return String is
begin
if Base = 10 then
return S;
else
return Image (Base) & "#" & To_Upper (S) & "#";
end if;
end Add_Base;
-----------
-- Image --
-----------
function Image (N : Natural) return String is
S : constant String := Natural'Image (N);
begin
return S (2 .. S'Last);
end Image;
---------------------
-- Leading_Padding --
---------------------
function Leading_Padding
(Str : String;
Min_Length : Field;
Char : Character := ' ') return String is
begin
return (1 .. Integer'Max (Integer (Min_Length) - Str'Length, 0)
=> Char) & Str;
end Leading_Padding;
Number_Digits : constant Integer :=
Integer (mpz_sizeinbase (Get_Mpz (Arg), Integer (abs Base)));
Buffer : aliased String (1 .. Number_Digits + 2);
-- The correct number to allocate is 2 more than Number_Digits in order
-- to handle a possible minus sign and the null-terminator.
Result : constant chars_ptr :=
mpz_get_str (Buffer'Address, Integer (Base), Get_Mpz (Arg));
S : constant String := Value (Result);
begin
if S (1) = '-' then
return Leading_Padding ("-" & Add_Base (S (2 .. S'Last)), Width);
else
return Leading_Padding (" " & Add_Base (S), Width);
end if;
end To_String;
-----------------
-- From_String --
-----------------
function From_String (Arg : String) return Big_Integer is
function mpz_set_str
(this : access mpz_t;
str : System.Address;
base : Integer := 10) return Integer;
pragma Import (C, mpz_set_str, "__gmpz_set_str");
Result : Big_Integer;
First : Natural;
Last : Natural;
Base : Natural;
begin
Allocate (Result);
if Arg (Arg'Last) /= '#' then
-- Base 10 number
First := Arg'First;
Last := Arg'Last;
Base := 10;
else
-- Compute the xx base in a xx#yyyyy# number
if Arg'Length < 4 then
raise Constraint_Error;
end if;
First := 0;
Last := Arg'Last - 1;
for J in Arg'First + 1 .. Last loop
if Arg (J) = '#' then
First := J;
exit;
end if;
end loop;
if First = 0 then
raise Constraint_Error;
end if;
Base := Natural'Value (Arg (Arg'First .. First - 1));
First := First + 1;
end if;
declare
Str : aliased String (1 .. Last - First + 2);
Index : Natural := 0;
begin
-- Strip underscores
for J in First .. Last loop
if Arg (J) /= '_' then
Index := Index + 1;
Str (Index) := Arg (J);
end if;
end loop;
Index := Index + 1;
Str (Index) := ASCII.NUL;
if mpz_set_str (Get_Mpz (Result), Str'Address, Base) /= 0 then
raise Constraint_Error;
end if;
end;
return Result;
end From_String;
---------------
-- Put_Image --
---------------
procedure Put_Image (S : in out Sink'Class; V : Big_Integer) is
-- This is implemented in terms of To_String. It might be more elegant
-- and more efficient to do it the other way around, but this is the
-- most expedient implementation for now.
begin
Strings.Text_Output.Utils.Put_UTF_8 (S, To_String (V));
end Put_Image;
---------
-- "+" --
---------
function "+" (L : Valid_Big_Integer) return Valid_Big_Integer is
Result : Big_Integer;
begin
Set_Mpz (Result, new mpz_t);
mpz_init_set (Get_Mpz (Result), Get_Mpz (L));
return Result;
end "+";
---------
-- "-" --
---------
function "-" (L : Valid_Big_Integer) return Valid_Big_Integer is
Result : Big_Integer;
begin
Allocate (Result);
mpz_neg (Get_Mpz (Result), Get_Mpz (L));
return Result;
end "-";
-----------
-- "abs" --
-----------
function "abs" (L : Valid_Big_Integer) return Valid_Big_Integer is
procedure mpz_abs (ROP : access mpz_t; OP : access constant mpz_t);
pragma Import (C, mpz_abs, "__gmpz_abs");
Result : Big_Integer;
begin
Allocate (Result);
mpz_abs (Get_Mpz (Result), Get_Mpz (L));
return Result;
end "abs";
---------
-- "+" --
---------
function "+" (L, R : Valid_Big_Integer) return Valid_Big_Integer is
procedure mpz_add
(ROP : access mpz_t; OP1, OP2 : access constant mpz_t);
pragma Import (C, mpz_add, "__gmpz_add");
Result : Big_Integer;
begin
Allocate (Result);
mpz_add (Get_Mpz (Result), Get_Mpz (L), Get_Mpz (R));
return Result;
end "+";
---------
-- "-" --
---------
function "-" (L, R : Valid_Big_Integer) return Valid_Big_Integer is
Result : Big_Integer;
begin
Allocate (Result);
mpz_sub (Get_Mpz (Result), Get_Mpz (L), Get_Mpz (R));
return Result;
end "-";
---------
-- "*" --
---------
function "*" (L, R : Valid_Big_Integer) return Valid_Big_Integer is
procedure mpz_mul
(ROP : access mpz_t; OP1, OP2 : access constant mpz_t);
pragma Import (C, mpz_mul, "__gmpz_mul");
Result : Big_Integer;
begin
Allocate (Result);
mpz_mul (Get_Mpz (Result), Get_Mpz (L), Get_Mpz (R));
return Result;
end "*";
---------
-- "/" --
---------
function "/" (L, R : Valid_Big_Integer) return Valid_Big_Integer is
procedure mpz_tdiv_q (Q : access mpz_t; N, D : access constant mpz_t);
pragma Import (C, mpz_tdiv_q, "__gmpz_tdiv_q");
begin
if mpz_cmp_ui (Get_Mpz (R), 0) = 0 then
raise Constraint_Error;
end if;
declare
Result : Big_Integer;
begin
Allocate (Result);
mpz_tdiv_q (Get_Mpz (Result), Get_Mpz (L), Get_Mpz (R));
return Result;
end;
end "/";
-----------
-- "mod" --
-----------
function "mod" (L, R : Valid_Big_Integer) return Valid_Big_Integer is
procedure mpz_mod (R : access mpz_t; N, D : access constant mpz_t);
pragma Import (C, mpz_mod, "__gmpz_mod");
-- result is always non-negative
L_Negative, R_Negative : Boolean;
begin
if mpz_cmp_ui (Get_Mpz (R), 0) = 0 then
raise Constraint_Error;
end if;
declare
Result : Big_Integer;
begin
Allocate (Result);
L_Negative := mpz_cmp_ui (Get_Mpz (L), 0) < 0;
R_Negative := mpz_cmp_ui (Get_Mpz (R), 0) < 0;
if not (L_Negative or R_Negative) then
mpz_mod (Get_Mpz (Result), Get_Mpz (L), Get_Mpz (R));
else
-- The GMP library provides operators defined by C semantics, but
-- the semantics of Ada's mod operator are not the same as C's
-- when negative values are involved. We do the following to
-- implement the required Ada semantics.
declare
Temp_Left : Big_Integer;
Temp_Right : Big_Integer;
Temp_Result : Big_Integer;
begin
Allocate (Temp_Result);
Set_Mpz (Temp_Left, new mpz_t);
Set_Mpz (Temp_Right, new mpz_t);
mpz_init_set (Get_Mpz (Temp_Left), Get_Mpz (L));
mpz_init_set (Get_Mpz (Temp_Right), Get_Mpz (R));
if L_Negative then
mpz_neg (Get_Mpz (Temp_Left), Get_Mpz (Temp_Left));
end if;
if R_Negative then
mpz_neg (Get_Mpz (Temp_Right), Get_Mpz (Temp_Right));
end if;
-- now both Temp_Left and Temp_Right are nonnegative
mpz_mod (Get_Mpz (Temp_Result),
Get_Mpz (Temp_Left),
Get_Mpz (Temp_Right));
if mpz_cmp_ui (Get_Mpz (Temp_Result), 0) = 0 then
-- if Temp_Result is zero we are done
mpz_set (Get_Mpz (Result), Get_Mpz (Temp_Result));
elsif L_Negative then
if R_Negative then
mpz_neg (Get_Mpz (Result), Get_Mpz (Temp_Result));
else -- L is negative but R is not
mpz_sub (Get_Mpz (Result),
Get_Mpz (Temp_Right),
Get_Mpz (Temp_Result));
end if;
else
pragma Assert (R_Negative);
mpz_sub (Get_Mpz (Result),
Get_Mpz (Temp_Result),
Get_Mpz (Temp_Right));
end if;
end;
end if;
return Result;
end;
end "mod";
-----------
-- "rem" --
-----------
function "rem" (L, R : Valid_Big_Integer) return Valid_Big_Integer is
procedure mpz_tdiv_r (R : access mpz_t; N, D : access constant mpz_t);
pragma Import (C, mpz_tdiv_r, "__gmpz_tdiv_r");
-- R will have the same sign as N.
begin
if mpz_cmp_ui (Get_Mpz (R), 0) = 0 then
raise Constraint_Error;
end if;
declare
Result : Big_Integer;
begin
Allocate (Result);
mpz_tdiv_r (R => Get_Mpz (Result),
N => Get_Mpz (L),
D => Get_Mpz (R));
-- the result takes the sign of N, as required by the RM
return Result;
end;
end "rem";
----------
-- "**" --
----------
function "**"
(L : Valid_Big_Integer; R : Natural) return Valid_Big_Integer
is
procedure mpz_pow_ui (ROP : access mpz_t;
BASE : access constant mpz_t;
EXP : unsigned_long);
pragma Import (C, mpz_pow_ui, "__gmpz_pow_ui");
Result : Big_Integer;
begin
Allocate (Result);
mpz_pow_ui (Get_Mpz (Result), Get_Mpz (L), unsigned_long (R));
return Result;
end "**";
---------
-- Min --
---------
function Min (L, R : Valid_Big_Integer) return Valid_Big_Integer is
(if L < R then L else R);
---------
-- Max --
---------
function Max (L, R : Valid_Big_Integer) return Valid_Big_Integer is
(if L > R then L else R);
-----------------------------
-- Greatest_Common_Divisor --
-----------------------------
function Greatest_Common_Divisor
(L, R : Valid_Big_Integer) return Big_Positive
is
procedure mpz_gcd
(ROP : access mpz_t; Op1, Op2 : access constant mpz_t);
pragma Import (C, mpz_gcd, "__gmpz_gcd");
Result : Big_Integer;
begin
Allocate (Result);
mpz_gcd (Get_Mpz (Result), Get_Mpz (L), Get_Mpz (R));
return Result;
end Greatest_Common_Divisor;
--------------
-- Allocate --
--------------
procedure Allocate (This : in out Big_Integer) is
procedure mpz_init (this : access mpz_t);
pragma Import (C, mpz_init, "__gmpz_init");
begin
Set_Mpz (This, new mpz_t);
mpz_init (Get_Mpz (This));
end Allocate;
------------
-- Adjust --
------------
procedure Adjust (This : in out Controlled_Bignum) is
Value : constant mpz_t_ptr := To_Mpz (This.C);
begin
if Value /= null then
This.C := To_Address (new mpz_t);
mpz_init_set (To_Mpz (This.C), Value);
end if;
end Adjust;
--------------
-- Finalize --
--------------
procedure Finalize (This : in out Controlled_Bignum) is
procedure Free is new Ada.Unchecked_Deallocation (mpz_t, mpz_t_ptr);
procedure mpz_clear (this : access mpz_t);
pragma Import (C, mpz_clear, "__gmpz_clear");
Mpz : mpz_t_ptr;
begin
if This.C /= System.Null_Address then
Mpz := To_Mpz (This.C);
mpz_clear (Mpz);
Free (Mpz);
This.C := System.Null_Address;
end if;
end Finalize;
end Ada.Numerics.Big_Numbers.Big_Integers;
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.