repo_name
stringlengths 9
74
| language
stringclasses 1
value | length_bytes
int64 11
9.34M
| extension
stringclasses 2
values | content
stringlengths 11
9.34M
|
---|---|---|---|---|
twdroeger/ada-awa | Ada | 8,967 | adb | -----------------------------------------------------------------------
-- awa-commands-start -- Command to start the web server
-- Copyright (C) 2020 Stephane Carrez
-- Written by Stephane Carrez ([email protected])
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-----------------------------------------------------------------------
with System;
with Servlet.Core;
with Servlet.Server;
with GNAT.Sockets;
with AWA.Applications;
package body AWA.Commands.Start is
use Ada.Strings.Unbounded;
use GNAT.Sockets;
use type System.Address;
-- ------------------------------
-- Start the server and all the application that have been registered.
-- ------------------------------
overriding
procedure Execute (Command : in out Command_Type;
Name : in String;
Args : in Argument_List'Class;
Context : in out Context_Type) is
begin
Command.Configure_Server (Context);
Command.Configure_Applications (Context);
Command.Start_Server (Context);
Command.Wait_Server (Context);
end Execute;
-- ------------------------------
-- Configure the web server container before applications are registered.
-- ------------------------------
procedure Configure_Server (Command : in out Command_Type;
Context : in out Context_Type) is
Config : Servlet.Server.Configuration;
begin
-- If daemon(3) is available and -d is defined, run it so that the parent
-- process terminates and the child process continues.
if Command.Daemon and Sys_Daemon'Address /= System.Null_Address then
declare
Result : constant Integer := Sys_Daemon (1, 0);
begin
if Result /= 0 then
Context.Console.Error ("Cannot run in background");
end if;
end;
end if;
Config.Listening_Port := Command.Listening_Port;
Config.Max_Connection := Command.Max_Connection;
Config.TCP_No_Delay := Command.TCP_No_Delay;
if Command.Upload'Length > 0 then
Config.Upload_Directory := To_Unbounded_String (Command.Upload.all);
end if;
Command_Drivers.WS.Configure (Config);
end Configure_Server;
-- ------------------------------
-- Configure all registered applications.
-- ------------------------------
procedure Configure_Applications (Command : in out Command_Type;
Context : in out Context_Type) is
procedure Configure (URI : in String;
Application : in Servlet.Core.Servlet_Registry_Access);
Count : Natural := 0;
procedure Configure (URI : in String;
Application : in Servlet.Core.Servlet_Registry_Access) is
begin
if Application.all in AWA.Applications.Application'Class then
Configure (AWA.Applications.Application'Class (Application.all),
URI (URI'First + 1 .. URI'Last),
Context);
Count := Count + 1;
end if;
end Configure;
Config : Servlet.Server.Configuration;
begin
Command_Drivers.WS.Iterate (Configure'Access);
if Count = 0 then
Context.Console.Error (-("There is no application"));
return;
end if;
end Configure_Applications;
-- ------------------------------
-- Start the web server.
-- ------------------------------
procedure Start_Server (Command : in out Command_Type;
Context : in out Context_Type) is
begin
Context.Console.Notice (N_INFO, "Starting...");
Command_Drivers.WS.Start;
end Start_Server;
-- ------------------------------
-- Wait for the server to shutdown.
-- ------------------------------
procedure Wait_Server (Command : in out Command_Type;
Context : in out Context_Type) is
procedure Shutdown (URI : in String;
Application : in Servlet.Core.Servlet_Registry_Access);
procedure Shutdown (URI : in String;
Application : in Servlet.Core.Servlet_Registry_Access) is
begin
if Application.all in AWA.Applications.Application'Class then
AWA.Applications.Application'Class (Application.all).Close;
end if;
end Shutdown;
Address : GNAT.Sockets.Sock_Addr_Type;
Listen : GNAT.Sockets.Socket_Type;
Socket : GNAT.Sockets.Socket_Type;
begin
GNAT.Sockets.Create_Socket (Listen);
Address.Addr := GNAT.Sockets.Loopback_Inet_Addr;
if Command.Management_Port > 0 then
Address.Port := Port_Type (Command.Management_Port);
else
Address.Port := 0;
end if;
GNAT.Sockets.Bind_Socket (Listen, Address);
GNAT.Sockets.Listen_Socket (Listen);
loop
GNAT.Sockets.Accept_Socket (Listen, Socket, Address);
exit;
end loop;
GNAT.Sockets.Close_Socket (Socket);
GNAT.Sockets.Close_Socket (Listen);
Command_Drivers.WS.Iterate (Shutdown'Access);
end Wait_Server;
-- ------------------------------
-- Setup the command before parsing the arguments and executing it.
-- ------------------------------
overriding
procedure Setup (Command : in out Command_Type;
Config : in out GNAT.Command_Line.Command_Line_Configuration;
Context : in out Context_Type) is
begin
GC.Set_Usage (Config => Config,
Usage => Command.Get_Name & " [arguments]",
Help => Command.Get_Description);
GC.Define_Switch (Config => Config,
Output => Command.Management_Port'Access,
Switch => "-m:",
Long_Switch => "--management-port=",
Initial => Command.Management_Port,
Argument => "NUMBER",
Help => -("The server listening management port on localhost"));
GC.Define_Switch (Config => Config,
Output => Command.Listening_Port'Access,
Switch => "-p:",
Long_Switch => "--port=",
Initial => Command.Listening_Port,
Argument => "NUMBER",
Help => -("The server listening port"));
GC.Define_Switch (Config => Config,
Output => Command.Max_Connection'Access,
Switch => "-C:",
Long_Switch => "--connection=",
Initial => Command.Max_Connection,
Argument => "NUMBER",
Help => -("The number of connections handled"));
GC.Define_Switch (Config => Config,
Output => Command.Upload'Access,
Switch => "-u:",
Long_Switch => "--upload=",
Argument => "PATH",
Help => -("The server upload directory"));
GC.Define_Switch (Config => Config,
Output => Command.TCP_No_Delay'Access,
Switch => "-n",
Long_Switch => "--tcp-no-delay",
Help => -("Enable the TCP no delay option"));
if Sys_Daemon'Address /= System.Null_Address then
GC.Define_Switch (Config => Config,
Output => Command.Daemon'Access,
Switch => "-d",
Long_Switch => "--daemon",
Help => -("Run the server in the background"));
end if;
AWA.Commands.Setup_Command (Config, Context);
end Setup;
-- ------------------------------
-- Write the help associated with the command.
-- ------------------------------
overriding
procedure Help (Command : in out Command_Type;
Name : in String;
Context : in out Context_Type) is
pragma Unreferenced (Command, Context);
begin
null;
end Help;
begin
Command_Drivers.Driver.Add_Command ("start",
-("start the web server"),
Command'Access);
end AWA.Commands.Start;
|
charlie5/cBound | Ada | 1,674 | ads | -- This file is generated by SWIG. Please do not modify by hand.
--
with Interfaces;
with Interfaces.C;
with Interfaces.C.Pointers;
package xcb.xcb_xc_misc_get_version_request_t is
-- Item
--
type Item is record
major_opcode : aliased Interfaces.Unsigned_8;
minor_opcode : aliased Interfaces.Unsigned_8;
length : aliased Interfaces.Unsigned_16;
client_major_version : aliased Interfaces.Unsigned_16;
client_minor_version : aliased Interfaces.Unsigned_16;
end record;
-- Item_Array
--
type Item_Array is
array
(Interfaces.C
.size_t range <>) of aliased xcb.xcb_xc_misc_get_version_request_t
.Item;
-- Pointer
--
package C_Pointers is new Interfaces.C.Pointers
(Index => Interfaces.C.size_t,
Element => xcb.xcb_xc_misc_get_version_request_t.Item,
Element_Array => xcb.xcb_xc_misc_get_version_request_t.Item_Array,
Default_Terminator => (others => <>));
subtype Pointer is C_Pointers.Pointer;
-- Pointer_Array
--
type Pointer_Array is
array
(Interfaces.C
.size_t range <>) of aliased xcb.xcb_xc_misc_get_version_request_t
.Pointer;
-- Pointer_Pointer
--
package C_Pointer_Pointers is new Interfaces.C.Pointers
(Index => Interfaces.C.size_t,
Element => xcb.xcb_xc_misc_get_version_request_t.Pointer,
Element_Array => xcb.xcb_xc_misc_get_version_request_t.Pointer_Array,
Default_Terminator => null);
subtype Pointer_Pointer is C_Pointer_Pointers.Pointer;
end xcb.xcb_xc_misc_get_version_request_t;
|
fnarenji/BezierToSTL | Ada | 795 | adb | with Math; use Math;
with Courbes.Visiteurs; use Courbes.Visiteurs;
package body Courbes.Droites is
function Ctor_Droite (Debut, Fin : Point2D) return Droite is
Diff : constant Point2D := Fin - Debut;
Longueur : constant Float := Hypot(Diff);
begin
return
(Debut => Debut,
Fin => Fin,
Longueur => Longueur,
Vecteur_Directeur => Diff / Longueur);
end;
overriding function Obtenir_Point(Self : Droite; X : Coordonnee_Normalisee) return Point2D is
begin
return Self.Obtenir_Debut + Self.Longueur * X * Self.Vecteur_Directeur;
end;
overriding procedure Accepter (Self : Droite; Visiteur : Visiteur_Courbe'Class) is
begin
Visiteur.Visiter (Self);
end;
end Courbes.Droites;
|
sungyeon/drake | Ada | 1,655 | ads | pragma License (Unrestricted);
package Ada.Streams is
pragma Pure;
type Root_Stream_Type is abstract tagged limited private;
pragma Preelaborable_Initialization (Root_Stream_Type);
type Stream_Element is
mod 2 ** Standard'Storage_Unit; -- implementation-defined
type Stream_Element_Offset is
range -(2 ** 63) .. 2 ** 63 - 1; -- implementation-defined
subtype Stream_Element_Count is
Stream_Element_Offset range 0 .. Stream_Element_Offset'Last;
type Stream_Element_Array is
array (Stream_Element_Offset range <>) of aliased Stream_Element;
procedure Read (
Stream : in out Root_Stream_Type;
Item : out Stream_Element_Array;
Last : out Stream_Element_Offset) is abstract;
procedure Write (
Stream : in out Root_Stream_Type;
Item : Stream_Element_Array) is abstract;
-- extended from here
type Seekable_Stream_Type is
abstract limited new Root_Stream_Type with private;
pragma Preelaborable_Initialization (Seekable_Stream_Type);
subtype Stream_Element_Positive_Count is
Stream_Element_Count range 1 .. Stream_Element_Count'Last;
procedure Set_Index (
Stream : in out Seekable_Stream_Type;
To : Stream_Element_Positive_Count) is abstract;
function Index (Stream : Seekable_Stream_Type)
return Stream_Element_Positive_Count is abstract;
function Size (Stream : Seekable_Stream_Type)
return Stream_Element_Count is abstract;
private
type Root_Stream_Type is abstract tagged limited null record;
type Seekable_Stream_Type is
abstract limited new Root_Stream_Type with null record;
end Ada.Streams;
|
Rodeo-McCabe/orka | Ada | 15,240 | adb | -- SPDX-License-Identifier: Apache-2.0
--
-- Copyright (c) 2016 onox <[email protected]>
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
package body Orka.Scenes.Generic_Scene_Trees is
function To_Cursor (Object : Tree; Name : String) return Cursor is
use type SU.Unbounded_String;
begin
for Level_Index in Object.Levels.First_Index .. Object.Levels.Last_Index loop
declare
Node_Level : Level renames Object.Levels (Level_Index);
begin
for Node_Index in Node_Level.Nodes.First_Index .. Node_Level.Nodes.Last_Index loop
declare
Current_Node : Node renames Node_Level.Nodes (Node_Index);
begin
if Current_Node.Name = Name then
return Cursor'(Level => Level_Index, Offset => Node_Index);
end if;
end;
end loop;
end;
end loop;
raise Unknown_Node_Error;
end To_Cursor;
procedure Update_Tree (Object : in out Tree) is
begin
Object.Update_Tree (Transforms.Identity_Value);
end Update_Tree;
procedure Update_Tree (Object : in out Tree; Root_Transform : Transforms.Matrix4) is
use Transforms;
Root_Local : constant Matrix4 := Object.Levels (Object.Levels.First_Index).Local_Transforms.Element (1);
Root_Visible : constant Boolean := Object.Levels (Object.Levels.First_Index).Local_Visibilities.Element (1);
begin
-- Copy local data of root node to its world data
Object.Levels (Object.Levels.First_Index).World_Transforms.Replace_Element (1, Root_Transform * Root_Local);
Object.Levels (Object.Levels.First_Index).World_Visibilities.Replace_Element (1, Root_Visible);
for Level_Index in Object.Levels.First_Index .. Object.Levels.Last_Index - 1 loop
declare
Parent_Level_W : Matrix_Vectors.Vector renames Object.Levels (Level_Index).World_Transforms;
Parent_Level_V : Boolean_Vectors.Vector renames Object.Levels (Level_Index).World_Visibilities;
Parent_Level_N : Node_Vectors.Vector renames Object.Levels (Level_Index).Nodes;
procedure Update (Child_Level : in out Level) is
begin
for Parent_Index in Parent_Level_N.First_Index .. Parent_Level_N.Last_Index loop
declare
Parent_Transform : Matrix4 renames Parent_Level_W.Element (Parent_Index);
Parent_Visible : Boolean renames Parent_Level_V.Element (Parent_Index);
Parent : Node renames Parent_Level_N.Element (Parent_Index);
begin
for Node_Index in Parent.Offset .. Parent.Offset + Parent.Count - 1 loop
declare
Local_Transform : Matrix4 renames Child_Level.Local_Transforms.Element (Node_Index);
Local_Visible : Boolean renames Child_Level.Local_Visibilities.Element (Node_Index);
begin
Child_Level.World_Transforms.Replace_Element (Node_Index, Parent_Transform * Local_Transform);
Child_Level.World_Visibilities.Replace_Element (Node_Index, Parent_Visible and then Local_Visible);
end;
end loop;
end;
end loop;
end Update;
begin
Object.Levels.Update_Element (Level_Index + 1, Update'Access);
end;
end loop;
end Update_Tree;
procedure Set_Visibility (Object : in out Tree; Node : Cursor; Visible : Boolean) is
Node_Level : Level renames Object.Levels (Node.Level);
begin
Node_Level.Local_Visibilities.Replace_Element (Node.Offset, Visible);
end Set_Visibility;
function Visibility (Object : Tree; Node : Cursor) return Boolean is
Node_Level : Level renames Object.Levels (Node.Level);
begin
return Node_Level.World_Visibilities.Element (Node.Offset);
end Visibility;
procedure Set_Local_Transform (Object : in out Tree; Node : Cursor; Transform : Transforms.Matrix4) is
Node_Level : Level renames Object.Levels (Node.Level);
begin
Node_Level.Local_Transforms.Replace_Element (Node.Offset, Transform);
end Set_Local_Transform;
function World_Transform (Object : Tree; Node : Cursor) return Transforms.Matrix4 is
Node_Level : Level renames Object.Levels (Node.Level);
begin
return Node_Level.World_Transforms.Element (Node.Offset);
end World_Transform;
function Root_Name (Object : Tree) return String is
(SU.To_String (Object.Levels (Object.Levels.First_Index).Nodes.Element (1).Name));
function Create_Tree (Name : String) return Tree is
begin
return Object : Tree do
Object.Levels.Append (Level'(others => <>));
declare
Root_Level : Level renames Object.Levels (Object.Levels.First_Index);
begin
Root_Level.Nodes.Append (Node'(Name => SU.To_Unbounded_String (Name),
Offset => 1,
Count => 0));
Root_Level.Local_Transforms.Append (Transforms.Identity_Value);
Root_Level.World_Transforms.Append (Transforms.Identity_Value);
Root_Level.Local_Visibilities.Append (True);
Root_Level.World_Visibilities.Append (True);
end;
end return;
end Create_Tree;
procedure Add_Node (Object : in out Tree; Name, Parent : String) is
begin
Object.Add_Node (SU.To_Unbounded_String (Name), Parent);
end Add_Node;
procedure Add_Node (Object : in out Tree; Name : SU.Unbounded_String; Parent : String) is
Parent_Cursor : constant Cursor := To_Cursor (Object, Parent);
begin
-- Add a new level if parent is a leaf node
if Parent_Cursor.Level = Positive (Object.Levels.Length) then
Object.Levels.Append (Level'(others => <>));
end if;
declare
Parent_Level : Level renames Object.Levels (Parent_Cursor.Level);
Child_Level : Level renames Object.Levels (Parent_Cursor.Level + 1);
Parent_Node : Node renames Parent_Level.Nodes (Parent_Cursor.Offset);
New_Node_Index : constant Positive := Parent_Node.Offset + Parent_Node.Count;
procedure Increment_Offset (Parent : in out Node) is
begin
Parent.Offset := Parent.Offset + 1;
end Increment_Offset;
Parent_Last_Index : constant Positive := Parent_Level.Nodes.Last_Index;
begin
-- If the node (in level j) has a parent that is the last node in level i,
-- then the node can simply be appended to level j, which is faster to do
if Parent_Cursor.Offset = Parent_Last_Index then
Child_Level.Nodes.Append (Node'(Name => Name,
Offset => 1,
Count => 0));
Child_Level.Local_Transforms.Append (Transforms.Identity_Value);
Child_Level.World_Transforms.Append (Transforms.Identity_Value);
Child_Level.Local_Visibilities.Append (True);
Child_Level.World_Visibilities.Append (True);
else
-- Insert new node and its transforms
Child_Level.Nodes.Insert (New_Node_Index, Node'(Name => Name,
Offset => 1,
Count => 0));
Child_Level.Local_Transforms.Insert (New_Node_Index, Transforms.Identity_Value);
Child_Level.World_Transforms.Insert (New_Node_Index, Transforms.Identity_Value);
Child_Level.Local_Visibilities.Insert (New_Node_Index, True);
Child_Level.World_Visibilities.Insert (New_Node_Index, True);
-- After inserting a new node (in level j), increment the offsets
-- of all parents that come after the new node's parent (in level i)
for Parent_Index in Parent_Cursor.Offset + 1 .. Parent_Last_Index loop
Parent_Level.Nodes.Update_Element (Parent_Index, Increment_Offset'Access);
end loop;
end if;
Parent_Node.Count := Parent_Node.Count + 1;
end;
end Add_Node;
procedure Remove_Node (Object : in out Tree; Name : String) is
use Ada.Containers;
Node_Cursor : constant Cursor := To_Cursor (Object, Name);
Current_First_Index : Positive := Node_Cursor.Offset;
Current_Last_Index : Positive := Node_Cursor.Offset;
-- Assign a dummy value to silence any warnings about being uninitialized
Next_First_Index, Next_Last_Index : Positive := Positive'Last;
Empty_Level_Index : Positive := Object.Levels.Last_Index + 1;
begin
if Node_Cursor.Level = Positive'First and Node_Cursor.Offset = Positive'First then
raise Root_Removal_Error with "Cannot remove root node";
end if;
-- If the node that is the root of the subtree that is going to
-- be removed, has a parent, then reduce the count of this parent.
if Node_Cursor.Level > Object.Levels.First_Index then
declare
Parent_Level : Level renames Object.Levels (Node_Cursor.Level - 1);
After_Parent_Index : Positive := Parent_Level.Nodes.Last_Index + 1;
begin
for Parent_Index in Parent_Level.Nodes.First_Index .. Parent_Level.Nodes.Last_Index loop
declare
Parent : Node renames Parent_Level.Nodes (Parent_Index);
begin
if Node_Cursor.Offset in Parent.Offset .. Parent.Offset + Parent.Count - 1 then
Parent.Count := Parent.Count - 1;
After_Parent_Index := Parent_Index + 1;
exit;
end if;
end;
end loop;
-- Reduce the offsets of any nodes that come after the parent node
for Parent_Index in After_Parent_Index .. Parent_Level.Nodes.Last_Index loop
declare
Parent : Node renames Parent_Level.Nodes (Parent_Index);
begin
Parent.Offset := Parent.Offset - 1;
end;
end loop;
end;
end if;
for Level_Index in Node_Cursor.Level .. Object.Levels.Last_Index loop
declare
Node_Level : Level renames Object.Levels (Level_Index);
Min_Index : Positive'Base := Current_Last_Index + 1;
Max_Index : Positive'Base := Current_First_Index - 1;
begin
-- Because child nodes in the next level (in all levels actually)
-- are adjacent, we can just use the offset of the first node
-- that is not a leaf node and the offset + count - 1 of the last
-- node that is not a leaf node.
for Node_Index in Current_First_Index .. Current_Last_Index loop
declare
Current_Node : Node renames Node_Level.Nodes (Node_Index);
begin
if Current_Node.Count /= 0 then
Min_Index := Positive'Min (Node_Index, Min_Index);
Max_Index := Positive'Max (Node_Index, Max_Index);
end if;
end;
end loop;
-- Before removing the nodes and transforms, compute the range
-- of the child nodes, if any, in the next level
if Min_Index in Current_First_Index .. Current_Last_Index then
declare
Min_Node : Node renames Node_Level.Nodes (Min_Index);
Max_Node : Node renames Node_Level.Nodes (Max_Index);
begin
-- Nodes to iterate over in next level
Next_First_Index := Min_Node.Offset;
Next_Last_Index := Max_Node.Offset + Max_Node.Count - 1;
-- There are child nodes that are going to be removed next
-- iteration, so we need to reduce the offset of the nodes
-- that come after Current_Last_Index.
declare
Count : constant Positive := Next_Last_Index - Next_First_Index + 1;
begin
for Parent_Index in Current_Last_Index + 1 .. Node_Level.Nodes.Last_Index loop
declare
Parent : Node renames Node_Level.Nodes (Parent_Index);
begin
Parent.Offset := Parent.Offset - Count;
end;
end loop;
end;
end;
end if;
-- Remove all nodes between Current_First_Index .. Current_Last_Index in current level
declare
Count : constant Count_Type := Count_Type (Current_Last_Index - Current_First_Index + 1);
begin
Node_Level.Nodes.Delete (Current_First_Index, Count);
Node_Level.Local_Transforms.Delete (Current_First_Index, Count);
Node_Level.World_Transforms.Delete (Current_First_Index, Count);
Node_Level.Local_Visibilities.Delete (Current_First_Index, Count);
Node_Level.World_Visibilities.Delete (Current_First_Index, Count);
end;
-- Record the level index of the first empty level. Any levels down
-- the tree should be(come) empty as well.
if Node_Level.Nodes.Is_Empty then
Empty_Level_Index := Positive'Min (Empty_Level_Index, Level_Index);
end if;
-- Exit if there are no nodes that have children
exit when Min_Index not in Current_First_Index .. Current_Last_Index;
-- If we reach this code here, then there is a node that has
-- children. The variables below have been updated in the if
-- block above.
pragma Assert (Next_First_Index /= Positive'Last);
pragma Assert (Next_Last_Index /= Positive'Last);
Current_First_Index := Next_First_Index;
Current_Last_Index := Next_Last_Index;
end;
end loop;
-- Remove empty levels
if Empty_Level_Index < Object.Levels.Last_Index + 1 then
declare
Count : constant Count_Type := Count_Type (Object.Levels.Last_Index - Empty_Level_Index + 1);
begin
Object.Levels.Delete (Empty_Level_Index, Count);
end;
end if;
end Remove_Node;
end Orka.Scenes.Generic_Scene_Trees;
|
mgrojo/bingada | Ada | 1,043 | ads | --*****************************************************************************
--*
--* PROJECT: BingAda
--*
--* FILE: q_csv.ads
--*
--* AUTHOR: Javier Fuica Fernandez
--*
--* NOTES: This code was taken from Rosetta Code and modifyied to fix
-- BingAda needs and Style Guide.
--*
--*****************************************************************************
package Q_Csv is
type T_Row (<>) is tagged private;
function F_Line (V_Line : String;
V_Separator : Character := ';') return T_Row;
function F_Next (V_Row: in out T_Row) return Boolean;
-- if there is still an item in R, Next advances to it and returns True
function F_Item (V_Row: T_Row) return String;
-- after calling R.Next i times, this returns the i'th item (if any)
private
type T_Row (V_Length : Natural) is tagged record
R_Str : String (1 .. V_Length);
R_First : Positive;
R_Last : Natural;
R_Next : Positive;
R_Sep : Character;
end record;
end Q_Csv;
|
zhmu/ananas | Ada | 75 | ads | package Concat5_Pkg1 is
procedure Scan (S : String);
end Concat5_Pkg1;
|
AdaCore/gpr | Ada | 82 | adb | separate (Parent_Unit)
protected body My_Protected_Body is
end My_Protected_Body;
|
AdaCore/gpr | Ada | 13,120 | ads | --
-- Copyright (C) 2019-2023, AdaCore
--
-- SPDX-License-Identifier: Apache-2.0 WITH LLVM-Exception
--
-- This package is provided to simplify and normalize GPR common switches
-- support.
-- Once options object is configured (by parsing the command line or calling
-- On_Switch/Finalize functions directly), it can be used to load a Tree.
with Ada.Strings.Unbounded;
with GPR2.Containers;
with GPR2.Context;
with GPR2.Environment;
with GPR2.File_Readers;
with GPR2.KB;
with GPR2.Log;
with GPR2.Path_Name;
with GPR2.Path_Name.Set;
with GPR2.Project.Tree;
package GPR2.Options is
Usage_Error : exception;
-- Raised when a wrong usage is detected
type Object is tagged private;
-- This object handles all common gpr switches used when loading a project.
-- Common gpr switches used when loading a project are described below in
-- Option type definition.
-- When processing the command line or any load configuration data, call
-- Add_Switch procedure to configure this object.
-- When command line or configuration parsing is done, Finalize procedure
-- should be called prior to be able to call any getter or the Load_Project
-- procedure.
Empty_Options : constant Object;
type Option is
(AP,
-- -aP<dir> or -aP <dir> Add directory dir to project search path
Autoconf,
-- --autoconf=file.cgpr Specify/create the main config project file name
Config,
-- --config=file.cgpr Specify the configuration project file name
Db,
-- --db dir Parse dir as an additional knowledge base
Db_Minus,
-- --db- Do not load the standard knowledge base
Implicit_With,
-- --implicit-with=filename
-- Add the given projects as a dependency on all loaded projects
No_Project,
-- --no-project Do not use project file
P,
-- -Pproj<.gpr> or -P proj<.gpr> Use Project File <proj>
Relocate_Build_Tree,
-- --relocate-build-tree[=dir]
--- Root obj/lib/exec dirs are current-directory or dir
Root_Dir,
-- --root-dir=dir Root directory of obj/lib/exec to relocate
RTS,
-- --RTS=<runtime> Use runtime <runtime> for language Ada
-- --RTS:<lang>=<runtime> Use runtime <runtime> for language <lang>
Src_Subdirs,
-- --src-subdirs=dir
-- Prepend <obj>/dir to the list of source dirs for each project
Subdirs,
-- --subdirs=dir Use dir as suffix to obj/lib/exec directories
Target,
-- --target=targetname Specify a target for cross platforms
Unchecked_Shared_Lib_Imports,
-- --unchecked-shared-lib-imports
-- Shared lib projects may import any project
X
-- -Xnm=val or -X nm=val Specify an external reference for Project Files
);
function Is_Finalized (Self : Object) return Boolean;
-- Returns True if 'Self' object already successfully finalized.
procedure Add_Switch
(Self : in out Object;
Switch : Option;
Param : String := "";
Index : String := "")
with Pre => not Self.Is_Finalized;
-- Add a switch to options.
-- Switches format is -[-]<Switch>[ ][:<Index>][=]<Param>
-- Usage_Error exception is raised if options set in invalid.
function On_Extra_Arg (Self : in out Object; Arg : String) return Boolean
with Pre => not Self.Is_Finalized;
-- Use this function if gpr file can be provided directly.
-- If Arg is not a valid file name with a gpr extension False is returned.
-- If Arg is a valid file name and Project_File was never set, it is set
-- and True is returned, else Usage_Error is raised.
procedure Finalize
(Self : in out Object;
Allow_Implicit_Project : Boolean := True;
Quiet : Boolean := False;
Environment : GPR2.Environment.Object :=
GPR2.Environment.Process_Environment)
with Pre => not Self.Is_Finalized,
Post => Self.Is_Finalized;
-- Option set should be finalized before Load_Project can be called.
-- Allow_Implicit_Project is required to load default project.
-- Quiet is useful to prevent output/error stream usage.
-- Usage_Error exception is raised if options set in invalid.
procedure Register_Project_Search_Paths
(Self : Object;
Tree : in out GPR2.Project.Tree.Object);
-- Add directories to project search path
-- Note: This procedure is called automatically if during Load_Project call
-- Tree parameter is undefined.
function Load_Project
(Self : in out Object;
Tree : in out GPR2.Project.Tree.Object;
Absent_Dir_Error : GPR2.Project.Tree.Error_Level :=
GPR2.Project.Tree.Warning;
File_Reader : GPR2.File_Readers.File_Reader_Reference :=
GPR2.File_Readers.No_File_Reader_Reference;
Quiet : Boolean := False) return Boolean
with Pre => Self.Is_Finalized;
-- Load a project tree using configured options.
-- If successful, Tree contains loaded project tree.
-- If Tree is undefined on entry, project search paths are automatically
-- registered.
-- Load messages are appended to Log.
-- Absent_Dir_Error: whether a missing directory should be treated as an
-- error or a warning.
-- If Quiet is true no output is printed.
-----------------------------------------------------
-- Object's getters. (Requires finalized options) --
-----------------------------------------------------
function Project_File
(Self : Object) return GPR2.Path_Name.Object
with Pre => Self.Is_Finalized;
-- Returns the project file found in the arguments or
-- implicit project file when allowed. It can be undefined.
function Filename
(Self : Object) return GPR2.Path_Name.Object
with Pre => Self.Is_Finalized;
-- Returns Filename argument used loading the project
-- Self.Project_File if defined otherwise the current directory.
function Context
(Self : Object) return GPR2.Context.Object
with Pre => Self.Is_Finalized;
-- Returns Context argument used loading the project
function Config_Project
(Self : Object) return GPR2.Path_Name.Object
with Pre => Self.Is_Finalized;
-- Returns path name object used as configuration file used loading
-- configuration project or as Config_Project argument used to save
-- configuration file generated by load project in auto-configuration
function Build_Path
(Self : Object) return GPR2.Path_Name.Object
with Pre => Self.Is_Finalized;
-- Returns Build_Path argument used loading the project.
function Subdirs
(Self : Object) return Ada.Strings.Unbounded.Unbounded_String
with Pre => Self.Is_Finalized;
-- Returns Subdirs argument used loading the project.
function Subdirs
(Self : Object) return GPR2.Optional_Name_Type
with Pre => Self.Is_Finalized;
-- Returns Subdirs argument used loading the project.
function Src_Subdirs
(Self : Object) return Ada.Strings.Unbounded.Unbounded_String
with Pre => Self.Is_Finalized;
-- Returns Src_Subdirs argument used loading the project.
function Src_Subdirs
(Self : Object) return GPR2.Optional_Name_Type
with Pre => Self.Is_Finalized;
-- Returns Src_Subdirs argument used loading the project.
function Check_Shared_Lib
(Self : Object) return Boolean
with Pre => Self.Is_Finalized;
-- Returns Check_Shared_Lib argument used loading the project.
function Implicit_With (Self : Object) return GPR2.Path_Name.Set.Object
with Pre => Self.Is_Finalized;
-- Returns Implicit_With argument used loading the project
function Target (Self : Object) return GPR2.Name_Type
with Pre => Self.Is_Finalized;
-- Returns Target argument loading the project.
function RTS_Map (Self : Object) return GPR2.Containers.Lang_Value_Map
with Pre => Self.Is_Finalized;
-- Returns Language_Runtimes argument loading the project.
function Base (Self : Object) return GPR2.KB.Object
with Pre => Self.Is_Finalized;
-- Returns knowledge base object used as Base argument loading the project.
function Config_Project_Log (Self : Object) return GPR2.Log.Object
with Pre => Self.Is_Finalized;
-- Returns log object filled during Config_Project Load done loading the
-- project.
function Config_Project_Has_Error
(Self : Object) return Boolean
with Pre => Self.Is_Finalized;
-- Returns True if configuration cannot be loaded successfully.
function Project_Is_Defined (Self : Object) return Boolean
with Pre => Self.Is_Finalized;
-- Returns True if project defined directly, not using implicit project.
function Check_For_Default_Project
(Directory : String := "") return GPR2.Path_Name.Object;
-- returns default gpr file or else the only gpr file found in directory.
private
type Object is tagged record
-- Object state
Finalized : Boolean := False;
-- Project file and context:
Context : GPR2.Context.Object;
Project_File : GPR2.Path_Name.Object;
Project_Is_Defined : Boolean := False;
Prj_Got_On_Extra_Arg : Boolean := False;
-- True if project defined not using -P option
No_Project : Boolean := False;
Project_Base : GPR2.Path_Name.Object;
-- If defined, then process Project_File like it is located in the
-- Project_Base.
-- Project tree modifiers
Root_Path : GPR2.Path_Name.Object;
Build_Path : GPR2.Path_Name.Object;
Src_Subdirs : Ada.Strings.Unbounded.Unbounded_String;
Subdirs : Ada.Strings.Unbounded.Unbounded_String;
Implicit_With : GPR2.Path_Name.Set.Object;
Unchecked_Shared_Lib : Boolean := False;
-- Conf/Autoconf
Config_Project : GPR2.Path_Name.Object;
Create_Missing_Config : Boolean := False;
Target : Ada.Strings.Unbounded.Unbounded_String :=
Ada.Strings.Unbounded.To_Unbounded_String
("all");
RTS_Map : GPR2.Containers.Lang_Value_Map;
Skip_Default_KB : aliased Boolean := False;
KB_Locations : GPR2.Path_Name.Set.Object;
Search_Paths : GPR2.Path_Name.Set.Object;
Config_Project_Has_Error : Boolean := False;
-- configuration file that cannot be loaded.
Config_Project_Log : GPR2.Log.Object;
Environment : GPR2.Environment.Object;
end record;
function Is_Finalized (Self : Object) return Boolean
is (Self.Finalized);
function Base (Self : Object) return GPR2.KB.Object
is (GPR2.KB.Create
(Flags => GPR2.KB.Default_Flags,
Default_KB => not Self.Skip_Default_KB,
Custom_KB => Self.KB_Locations,
Environment => Self.Environment));
function Build_Path
(Self : Object) return GPR2.Path_Name.Object
is (Self.Build_Path);
function Check_Shared_Lib
(Self : Object) return Boolean
is (not Self.Unchecked_Shared_Lib);
function Config_Project
(Self : Object) return GPR2.Path_Name.Object
is (Self.Config_Project);
function Config_Project_Log (Self : Object) return GPR2.Log.Object
is (Self.Config_Project_Log);
function Context
(Self : Object) return GPR2.Context.Object
is (Self.Context);
function Filename
(Self : Object) return GPR2.Path_Name.Object
is (if Self.Project_File.Is_Defined
then Self.Project_File
else Self.Project_Base);
function Config_Project_Has_Error
(Self : Object) return Boolean
is (Self.Config_Project_Has_Error);
function Implicit_With (Self : Object) return GPR2.Path_Name.Set.Object
is (Self.Implicit_With);
function Project_File
(Self : Object) return GPR2.Path_Name.Object
is (Self.Project_File);
function Project_Is_Defined (Self : Object) return Boolean
is (Self.Project_Is_Defined);
function RTS_Map (Self : Object) return GPR2.Containers.Lang_Value_Map
is (Self.RTS_Map);
function Src_Subdirs
(Self : Object) return Ada.Strings.Unbounded.Unbounded_String
is (Self.Src_Subdirs);
function Src_Subdirs
(Self : Object) return Optional_Name_Type
is (GPR2.Optional_Name_Type (To_String (Self.Src_Subdirs)));
function Subdirs
(Self : Object) return Ada.Strings.Unbounded.Unbounded_String
is (Self.Subdirs);
function Subdirs
(Self : Object) return GPR2.Optional_Name_Type
is (GPR2.Optional_Name_Type (To_String (Self.Subdirs)));
function Target
(Self : Object) return GPR2.Name_Type
is (GPR2.Name_Type (To_String (Self.Target)));
Empty_Options : constant Object := (others => <>);
end GPR2.Options;
|
ivanhawkes/Chrysalis | Ada | 929 | adb | <AnimDB FragDef="chrysalis/objects/containers/chest/wooden_chest/fragment_ids.xml" TagDef="chrysalis/objects/containers/chest/wooden_chest/tags.xml">
<FragmentList>
<Closed>
<Fragment BlendOutDuration="0.2" Tags=""/>
</Closed>
<Open>
<Fragment BlendOutDuration="0.2" Tags=""/>
</Open>
<Opening>
<Fragment BlendOutDuration="0.2" Tags="ScopeSlave">
<ProcLayer>
<Blend ExitTime="0" StartTime="0" Duration="0.30000001"/>
<Procedural type="PlaySound">
<ProceduralParams CryXmlVersion="2" StartTrigger="get_focus" StopTrigger="" AudioParameter="" AudioParameterValue="0" OcclusionType="ignore_state_name" AttachmentJoint="" Radius="0" IsVoice="false" PlayFacial="false" SoundFlags="0"/>
</Procedural>
</ProcLayer>
</Fragment>
<Fragment BlendOutDuration="0.2" Tags=""/>
</Opening>
<Closing>
<Fragment BlendOutDuration="0.2" Tags=""/>
</Closing>
</FragmentList>
</AnimDB>
|
zhmu/ananas | Ada | 158 | adb | -- { dg-do compile }
with Incomplete4_Pkg; use Incomplete4_Pkg;
with System;
procedure Incomplete4 is
L : System.Address := A'Address;
begin
null;
end;
|
mitchelhaan/ncurses | Ada | 34,797 | adb | ------------------------------------------------------------------------------
-- --
-- GNAT ncurses Binding --
-- --
-- Terminal_Interface.Curses.Menus --
-- --
-- B O D Y --
-- --
------------------------------------------------------------------------------
-- Copyright (c) 1998 Free Software Foundation, Inc. --
-- --
-- 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, distribute with modifications, 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 ABOVE 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. --
-- --
-- Except as contained in this notice, the name(s) of the above copyright --
-- holders shall not be used in advertising or otherwise to promote the --
-- sale, use or other dealings in this Software without prior written --
-- authorization. --
------------------------------------------------------------------------------
-- Author: Juergen Pfeifer <[email protected]> 1996
-- Version Control:
-- $Revision: 1.13 $
-- Binding Version 00.93
------------------------------------------------------------------------------
with Ada.Unchecked_Deallocation;
with Terminal_Interface.Curses.Aux; use Terminal_Interface.Curses.Aux;
with Interfaces.C; use Interfaces.C;
with Interfaces.C.Strings; use Interfaces.C.Strings;
with Terminal_Interface.Curses;
with Unchecked_Conversion;
package body Terminal_Interface.Curses.Menus is
use type System.Bit_Order;
subtype chars_ptr is Interfaces.C.Strings.chars_ptr;
function MOS_2_CInt is new
Unchecked_Conversion (Menu_Option_Set,
C_Int);
function CInt_2_MOS is new
Unchecked_Conversion (C_Int,
Menu_Option_Set);
function IOS_2_CInt is new
Unchecked_Conversion (Item_Option_Set,
C_Int);
function CInt_2_IOS is new
Unchecked_Conversion (C_Int,
Item_Option_Set);
------------------------------------------------------------------------------
procedure Request_Name (Key : in Menu_Request_Code;
Name : out String)
is
function Request_Name (Key : C_Int) return chars_ptr;
pragma Import (C, Request_Name, "menu_request_name");
begin
Fill_String (Request_Name (C_Int (Key)), Name);
end Request_Name;
function Request_Name (Key : Menu_Request_Code) return String
is
function Request_Name (Key : C_Int) return chars_ptr;
pragma Import (C, Request_Name, "menu_request_name");
begin
return Fill_String (Request_Name (C_Int (Key)));
end Request_Name;
function Create (Name : String;
Description : String := "") return Item
is
type Char_Ptr is access all Interfaces.C.Char;
function Newitem (Name, Desc : Char_Ptr) return Item;
pragma Import (C, Newitem, "new_item");
type Name_String is new char_array (0 .. Name'Length);
type Name_String_Ptr is access Name_String;
pragma Controlled (Name_String_Ptr);
type Desc_String is new char_array (0 .. Description'Length);
type Desc_String_Ptr is access Desc_String;
pragma Controlled (Desc_String_Ptr);
Name_Str : Name_String_Ptr := new Name_String;
Desc_Str : Desc_String_Ptr := new Desc_String;
Name_Len, Desc_Len : size_t;
Result : Item;
begin
To_C (Name, Name_Str.all, Name_Len);
To_C (Description, Desc_Str.all, Desc_Len);
Result := Newitem (Name_Str.all (Name_Str.all'First)'Access,
Desc_Str.all (Desc_Str.all'First)'Access);
if Result = Null_Item then
raise Eti_System_Error;
end if;
return Result;
end Create;
procedure Delete (Itm : in out Item)
is
function Descname (Itm : Item) return chars_ptr;
pragma Import (C, Descname, "item_description");
function Itemname (Itm : Item) return chars_ptr;
pragma Import (C, Itemname, "item_name");
function Freeitem (Itm : Item) return C_Int;
pragma Import (C, Freeitem, "free_item");
Res : Eti_Error;
Ptr : chars_ptr;
begin
Ptr := Descname (Itm);
if Ptr /= Null_Ptr then
Interfaces.C.Strings.Free (Ptr);
end if;
Ptr := Itemname (Itm);
if Ptr /= Null_Ptr then
Interfaces.C.Strings.Free (Ptr);
end if;
Res := Freeitem (Itm);
if Res /= E_Ok then
Eti_Exception (Res);
end if;
Itm := Null_Item;
end Delete;
-------------------------------------------------------------------------------
procedure Set_Value (Itm : in Item;
Value : in Boolean := True)
is
function Set_Item_Val (Itm : Item;
Val : C_Int) return C_Int;
pragma Import (C, Set_Item_Val, "set_item_value");
Res : constant Eti_Error := Set_Item_Val (Itm, Boolean'Pos (Value));
begin
if Res /= E_Ok then
Eti_Exception (Res);
end if;
end Set_Value;
function Value (Itm : Item) return Boolean
is
function Item_Val (Itm : Item) return C_Int;
pragma Import (C, Item_Val, "item_value");
begin
if Item_Val (Itm) = Curses_False then
return False;
else
return True;
end if;
end Value;
-------------------------------------------------------------------------------
function Visible (Itm : Item) return Boolean
is
function Item_Vis (Itm : Item) return C_Int;
pragma Import (C, Item_Vis, "item_visible");
begin
if Item_Vis (Itm) = Curses_False then
return False;
else
return True;
end if;
end Visible;
-------------------------------------------------------------------------------
procedure Normalize_Item_Options (Options : in out C_Int);
pragma Import (C, Normalize_Item_Options, "_nc_ada_normalize_item_opts");
procedure Set_Options (Itm : in Item;
Options : in Item_Option_Set)
is
function Set_Item_Opts (Itm : Item;
Opt : C_Int) return C_Int;
pragma Import (C, Set_Item_Opts, "set_item_opts");
Opt : C_Int := IOS_2_CInt (Options);
Res : Eti_Error;
begin
Normalize_Item_Options (Opt);
Res := Set_Item_Opts (Itm, Opt);
if Res /= E_Ok then
Eti_Exception (Res);
end if;
end Set_Options;
procedure Switch_Options (Itm : in Item;
Options : in Item_Option_Set;
On : Boolean := True)
is
function Item_Opts_On (Itm : Item;
Opt : C_Int) return C_Int;
pragma Import (C, Item_Opts_On, "item_opts_on");
function Item_Opts_Off (Itm : Item;
Opt : C_Int) return C_Int;
pragma Import (C, Item_Opts_Off, "item_opts_off");
Opt : C_Int := IOS_2_CInt (Options);
Err : Eti_Error;
begin
Normalize_Item_Options (Opt);
if On then
Err := Item_Opts_On (Itm, Opt);
else
Err := Item_Opts_Off (Itm, Opt);
end if;
if Err /= E_Ok then
Eti_Exception (Err);
end if;
end Switch_Options;
procedure Get_Options (Itm : in Item;
Options : out Item_Option_Set)
is
function Item_Opts (Itm : Item) return C_Int;
pragma Import (C, Item_Opts, "item_opts");
Res : C_Int := Item_Opts (Itm);
begin
Normalize_Item_Options (Res);
Options := CInt_2_IOS (Res);
end Get_Options;
function Get_Options (Itm : Item := Null_Item) return Item_Option_Set
is
Ios : Item_Option_Set;
begin
Get_Options (Itm, Ios);
return Ios;
end Get_Options;
-------------------------------------------------------------------------------
procedure Name (Itm : in Item;
Name : out String)
is
function Itemname (Itm : Item) return chars_ptr;
pragma Import (C, Itemname, "item_name");
begin
Fill_String (Itemname (Itm), Name);
end Name;
function Name (Itm : in Item) return String
is
function Itemname (Itm : Item) return chars_ptr;
pragma Import (C, Itemname, "item_name");
begin
return Fill_String (Itemname (Itm));
end Name;
procedure Description (Itm : in Item;
Description : out String)
is
function Descname (Itm : Item) return chars_ptr;
pragma Import (C, Descname, "item_description");
begin
Fill_String (Descname (Itm), Description);
end Description;
function Description (Itm : in Item) return String
is
function Descname (Itm : Item) return chars_ptr;
pragma Import (C, Descname, "item_description");
begin
return Fill_String (Descname (Itm));
end Description;
-------------------------------------------------------------------------------
procedure Set_Current (Men : in Menu;
Itm : in Item)
is
function Set_Curr_Item (Men : Menu;
Itm : Item) return C_Int;
pragma Import (C, Set_Curr_Item, "set_current_item");
Res : constant Eti_Error := Set_Curr_Item (Men, Itm);
begin
if Res /= E_Ok then
Eti_Exception (Res);
end if;
end Set_Current;
function Current (Men : Menu) return Item
is
function Curr_Item (Men : Menu) return Item;
pragma Import (C, Curr_Item, "current_item");
Res : constant Item := Curr_Item (Men);
begin
if Res = Null_Item then
raise Menu_Exception;
end if;
return Res;
end Current;
procedure Set_Top_Row (Men : in Menu;
Line : in Line_Position)
is
function Set_Toprow (Men : Menu;
Line : C_Int) return C_Int;
pragma Import (C, Set_Toprow, "set_top_row");
Res : constant Eti_Error := Set_Toprow (Men, C_Int (Line));
begin
if Res /= E_Ok then
Eti_Exception (Res);
end if;
end Set_Top_Row;
function Top_Row (Men : Menu) return Line_Position
is
function Toprow (Men : Menu) return C_Int;
pragma Import (C, Toprow, "top_row");
Res : constant C_Int := Toprow (Men);
begin
if Res = Curses_Err then
raise Menu_Exception;
end if;
return Line_Position (Res);
end Top_Row;
function Get_Index (Itm : Item) return Positive
is
function Get_Itemindex (Itm : Item) return C_Int;
pragma Import (C, Get_Itemindex, "item_index");
Res : constant C_Int := Get_Itemindex (Itm);
begin
if Res = Curses_Err then
raise Menu_Exception;
end if;
return Positive (Natural (Res) + Positive'First);
end Get_Index;
-------------------------------------------------------------------------------
procedure Post (Men : in Menu;
Post : in Boolean := True)
is
function M_Post (Men : Menu) return C_Int;
pragma Import (C, M_Post, "post_menu");
function M_Unpost (Men : Menu) return C_Int;
pragma Import (C, M_Unpost, "unpost_menu");
Res : Eti_Error;
begin
if Post then
Res := M_Post (Men);
else
Res := M_Unpost (Men);
end if;
if Res /= E_Ok then
Eti_Exception (Res);
end if;
end Post;
-------------------------------------------------------------------------------
procedure Normalize_Menu_Options (Options : in out C_Int);
pragma Import (C, Normalize_Menu_Options, "_nc_ada_normalize_menu_opts");
procedure Set_Options (Men : in Menu;
Options : in Menu_Option_Set)
is
function Set_Menu_Opts (Men : Menu;
Opt : C_Int) return C_Int;
pragma Import (C, Set_Menu_Opts, "set_menu_opts");
Opt : C_Int := MOS_2_CInt (Options);
Res : Eti_Error;
begin
Normalize_Menu_Options (Opt);
Res := Set_Menu_Opts (Men, Opt);
if Res /= E_Ok then
Eti_Exception (Res);
end if;
end Set_Options;
procedure Switch_Options (Men : in Menu;
Options : in Menu_Option_Set;
On : in Boolean := True)
is
function Menu_Opts_On (Men : Menu;
Opt : C_Int) return C_Int;
pragma Import (C, Menu_Opts_On, "menu_opts_on");
function Menu_Opts_Off (Men : Menu;
Opt : C_Int) return C_Int;
pragma Import (C, Menu_Opts_Off, "menu_opts_off");
Opt : C_Int := MOS_2_CInt (Options);
Err : Eti_Error;
begin
Normalize_Menu_Options (Opt);
if On then
Err := Menu_Opts_On (Men, Opt);
else
Err := Menu_Opts_Off (Men, Opt);
end if;
if Err /= E_Ok then
Eti_Exception (Err);
end if;
end Switch_Options;
procedure Get_Options (Men : in Menu;
Options : out Menu_Option_Set)
is
function Menu_Opts (Men : Menu) return C_Int;
pragma Import (C, Menu_Opts, "menu_opts");
Res : C_Int := Menu_Opts (Men);
begin
Normalize_Menu_Options (Res);
Options := CInt_2_MOS (Res);
end Get_Options;
function Get_Options (Men : Menu := Null_Menu) return Menu_Option_Set
is
Mos : Menu_Option_Set;
begin
Get_Options (Men, Mos);
return Mos;
end Get_Options;
-------------------------------------------------------------------------------
procedure Set_Window (Men : in Menu;
Win : in Window)
is
function Set_Menu_Win (Men : Menu;
Win : Window) return C_Int;
pragma Import (C, Set_Menu_Win, "set_menu_win");
Res : constant Eti_Error := Set_Menu_Win (Men, Win);
begin
if Res /= E_Ok then
Eti_Exception (Res);
end if;
end Set_Window;
function Get_Window (Men : Menu) return Window
is
function Menu_Win (Men : Menu) return Window;
pragma Import (C, Menu_Win, "menu_win");
W : constant Window := Menu_Win (Men);
begin
return W;
end Get_Window;
procedure Set_Sub_Window (Men : in Menu;
Win : in Window)
is
function Set_Menu_Sub (Men : Menu;
Win : Window) return C_Int;
pragma Import (C, Set_Menu_Sub, "set_menu_sub");
Res : constant Eti_Error := Set_Menu_Sub (Men, Win);
begin
if Res /= E_Ok then
Eti_Exception (Res);
end if;
end Set_Sub_Window;
function Get_Sub_Window (Men : Menu) return Window
is
function Menu_Sub (Men : Menu) return Window;
pragma Import (C, Menu_Sub, "menu_sub");
W : constant Window := Menu_Sub (Men);
begin
return W;
end Get_Sub_Window;
procedure Scale (Men : in Menu;
Lines : out Line_Count;
Columns : out Column_Count)
is
type C_Int_Access is access all C_Int;
function M_Scale (Men : Menu;
Yp, Xp : C_Int_Access) return C_Int;
pragma Import (C, M_Scale, "scale_menu");
X, Y : aliased C_Int;
Res : constant Eti_Error := M_Scale (Men, Y'Access, X'Access);
begin
if Res /= E_Ok then
Eti_Exception (Res);
end if;
Lines := Line_Count (Y);
Columns := Column_Count (X);
end Scale;
-------------------------------------------------------------------------------
procedure Position_Cursor (Men : Menu)
is
function Pos_Menu_Cursor (Men : Menu) return C_Int;
pragma Import (C, Pos_Menu_Cursor, "pos_menu_cursor");
Res : constant Eti_Error := Pos_Menu_Cursor (Men);
begin
if Res /= E_Ok then
Eti_Exception (Res);
end if;
end Position_Cursor;
-------------------------------------------------------------------------------
procedure Set_Mark (Men : in Menu;
Mark : in String)
is
type Char_Ptr is access all Interfaces.C.Char;
function Set_Mark (Men : Menu;
Mark : Char_Ptr) return C_Int;
pragma Import (C, Set_Mark, "set_menu_mark");
Txt : char_array (0 .. Mark'Length);
Len : size_t;
Res : Eti_Error;
begin
To_C (Mark, Txt, Len);
Res := Set_Mark (Men, Txt (Txt'First)'Access);
if Res /= E_Ok then
Eti_Exception (Res);
end if;
end Set_Mark;
procedure Mark (Men : in Menu;
Mark : out String)
is
function Get_Menu_Mark (Men : Menu) return chars_ptr;
pragma Import (C, Get_Menu_Mark, "menu_mark");
begin
Fill_String (Get_Menu_Mark (Men), Mark);
end Mark;
function Mark (Men : Menu) return String
is
function Get_Menu_Mark (Men : Menu) return chars_ptr;
pragma Import (C, Get_Menu_Mark, "menu_mark");
begin
return Fill_String (Get_Menu_Mark (Men));
end Mark;
-------------------------------------------------------------------------------
procedure Set_Foreground
(Men : in Menu;
Fore : in Character_Attribute_Set := Normal_Video;
Color : in Color_Pair := Color_Pair'First)
is
function Set_Menu_Fore (Men : Menu;
Attr : C_Int) return C_Int;
pragma Import (C, Set_Menu_Fore, "set_menu_fore");
Ch : constant Attributed_Character := (Ch => Character'First,
Color => Color,
Attr => Fore);
Res : constant Eti_Error := Set_Menu_Fore (Men, Chtype_To_CInt (Ch));
begin
if Res /= E_Ok then
Eti_Exception (Res);
end if;
end Set_Foreground;
procedure Foreground (Men : in Menu;
Fore : out Character_Attribute_Set)
is
function Menu_Fore (Men : Menu) return C_Int;
pragma Import (C, Menu_Fore, "menu_fore");
begin
Fore := CInt_To_Chtype (Menu_Fore (Men)).Attr;
end Foreground;
procedure Foreground (Men : in Menu;
Fore : out Character_Attribute_Set;
Color : out Color_Pair)
is
function Menu_Fore (Men : Menu) return C_Int;
pragma Import (C, Menu_Fore, "menu_fore");
begin
Fore := CInt_To_Chtype (Menu_Fore (Men)).Attr;
Color := CInt_To_Chtype (Menu_Fore (Men)).Color;
end Foreground;
procedure Set_Background
(Men : in Menu;
Back : in Character_Attribute_Set := Normal_Video;
Color : in Color_Pair := Color_Pair'First)
is
function Set_Menu_Back (Men : Menu;
Attr : C_Int) return C_Int;
pragma Import (C, Set_Menu_Back, "set_menu_back");
Ch : constant Attributed_Character := (Ch => Character'First,
Color => Color,
Attr => Back);
Res : constant Eti_Error := Set_Menu_Back (Men, Chtype_To_CInt (Ch));
begin
if Res /= E_Ok then
Eti_Exception (Res);
end if;
end Set_Background;
procedure Background (Men : in Menu;
Back : out Character_Attribute_Set)
is
function Menu_Back (Men : Menu) return C_Int;
pragma Import (C, Menu_Back, "menu_back");
begin
Back := CInt_To_Chtype (Menu_Back (Men)).Attr;
end Background;
procedure Background (Men : in Menu;
Back : out Character_Attribute_Set;
Color : out Color_Pair)
is
function Menu_Back (Men : Menu) return C_Int;
pragma Import (C, Menu_Back, "menu_back");
begin
Back := CInt_To_Chtype (Menu_Back (Men)).Attr;
Color := CInt_To_Chtype (Menu_Back (Men)).Color;
end Background;
procedure Set_Grey (Men : in Menu;
Grey : in Character_Attribute_Set := Normal_Video;
Color : in Color_Pair := Color_Pair'First)
is
function Set_Menu_Grey (Men : Menu;
Attr : C_Int) return C_Int;
pragma Import (C, Set_Menu_Grey, "set_menu_grey");
Ch : constant Attributed_Character := (Ch => Character'First,
Color => Color,
Attr => Grey);
Res : constant Eti_Error := Set_Menu_Grey (Men, Chtype_To_CInt (Ch));
begin
if Res /= E_Ok then
Eti_Exception (Res);
end if;
end Set_Grey;
procedure Grey (Men : in Menu;
Grey : out Character_Attribute_Set)
is
function Menu_Grey (Men : Menu) return C_Int;
pragma Import (C, Menu_Grey, "menu_grey");
begin
Grey := CInt_To_Chtype (Menu_Grey (Men)).Attr;
end Grey;
procedure Grey (Men : in Menu;
Grey : out Character_Attribute_Set;
Color : out Color_Pair)
is
function Menu_Grey (Men : Menu) return C_Int;
pragma Import (C, Menu_Grey, "menu_grey");
begin
Grey := CInt_To_Chtype (Menu_Grey (Men)).Attr;
Color := CInt_To_Chtype (Menu_Grey (Men)).Color;
end Grey;
procedure Set_Pad_Character (Men : in Menu;
Pad : in Character := Space)
is
function Set_Menu_Pad (Men : Menu;
Ch : C_Int) return C_Int;
pragma Import (C, Set_Menu_Pad, "set_menu_pad");
Res : constant Eti_Error := Set_Menu_Pad (Men,
C_Int (Character'Pos (Pad)));
begin
if Res /= E_Ok then
Eti_Exception (Res);
end if;
end Set_Pad_Character;
procedure Pad_Character (Men : in Menu;
Pad : out Character)
is
function Menu_Pad (Men : Menu) return C_Int;
pragma Import (C, Menu_Pad, "menu_pad");
begin
Pad := Character'Val (Menu_Pad (Men));
end Pad_Character;
-------------------------------------------------------------------------------
procedure Set_Spacing (Men : in Menu;
Descr : in Column_Position := 0;
Row : in Line_Position := 0;
Col : in Column_Position := 0)
is
function Set_Spacing (Men : Menu;
D, R, C : C_Int) return C_Int;
pragma Import (C, Set_Spacing, "set_menu_spacing");
Res : constant Eti_Error := Set_Spacing (Men,
C_Int (Descr),
C_Int (Row),
C_Int (Col));
begin
if Res /= E_Ok then
Eti_Exception (Res);
end if;
end Set_Spacing;
procedure Spacing (Men : in Menu;
Descr : out Column_Position;
Row : out Line_Position;
Col : out Column_Position)
is
type C_Int_Access is access all C_Int;
function Get_Spacing (Men : Menu;
D, R, C : C_Int_Access) return C_Int;
pragma Import (C, Get_Spacing, "menu_spacing");
D, R, C : aliased C_Int;
Res : constant Eti_Error := Get_Spacing (Men,
D'Access,
R'Access,
C'Access);
begin
if Res /= E_Ok then
Eti_Exception (Res);
else
Descr := Column_Position (D);
Row := Line_Position (R);
Col := Column_Position (C);
end if;
end Spacing;
-------------------------------------------------------------------------------
function Set_Pattern (Men : Menu;
Text : String) return Boolean
is
type Char_Ptr is access all Interfaces.C.Char;
function Set_Pattern (Men : Menu;
Pattern : Char_Ptr) return C_Int;
pragma Import (C, Set_Pattern, "set_menu_pattern");
S : char_array (0 .. Text'Length);
L : size_t;
Res : Eti_Error;
begin
To_C (Text, S, L);
Res := Set_Pattern (Men, S (S'First)'Access);
case Res is
when E_No_Match => return False;
when E_Ok => return True;
when others =>
Eti_Exception (Res);
return False;
end case;
end Set_Pattern;
procedure Pattern (Men : in Menu;
Text : out String)
is
function Get_Pattern (Men : Menu) return chars_ptr;
pragma Import (C, Get_Pattern, "menu_pattern");
begin
Fill_String (Get_Pattern (Men), Text);
end Pattern;
-------------------------------------------------------------------------------
procedure Set_Format (Men : in Menu;
Lines : in Line_Count;
Columns : in Column_Count)
is
function Set_Menu_Fmt (Men : Menu;
Lin : C_Int;
Col : C_Int) return C_Int;
pragma Import (C, Set_Menu_Fmt, "set_menu_format");
Res : constant Eti_Error := Set_Menu_Fmt (Men,
C_Int (Lines),
C_Int (Columns));
begin
if Res /= E_Ok then
Eti_Exception (Res);
end if;
end Set_Format;
procedure Format (Men : in Menu;
Lines : out Line_Count;
Columns : out Column_Count)
is
type C_Int_Access is access all C_Int;
function Menu_Fmt (Men : Menu;
Y, X : C_Int_Access) return C_Int;
pragma Import (C, Menu_Fmt, "menu_format");
L, C : aliased C_Int;
Res : constant Eti_Error := Menu_Fmt (Men, L'Access, C'Access);
begin
if Res /= E_Ok then
Eti_Exception (Res);
else
Lines := Line_Count (L);
Columns := Column_Count (C);
end if;
end Format;
-------------------------------------------------------------------------------
procedure Set_Item_Init_Hook (Men : in Menu;
Proc : in Menu_Hook_Function)
is
function Set_Item_Init (Men : Menu;
Proc : Menu_Hook_Function) return C_Int;
pragma Import (C, Set_Item_Init, "set_item_init");
Res : constant Eti_Error := Set_Item_Init (Men, Proc);
begin
if Res /= E_Ok then
Eti_Exception (Res);
end if;
end Set_Item_Init_Hook;
procedure Set_Item_Term_Hook (Men : in Menu;
Proc : in Menu_Hook_Function)
is
function Set_Item_Term (Men : Menu;
Proc : Menu_Hook_Function) return C_Int;
pragma Import (C, Set_Item_Term, "set_item_term");
Res : constant Eti_Error := Set_Item_Term (Men, Proc);
begin
if Res /= E_Ok then
Eti_Exception (Res);
end if;
end Set_Item_Term_Hook;
procedure Set_Menu_Init_Hook (Men : in Menu;
Proc : in Menu_Hook_Function)
is
function Set_Menu_Init (Men : Menu;
Proc : Menu_Hook_Function) return C_Int;
pragma Import (C, Set_Menu_Init, "set_menu_init");
Res : constant Eti_Error := Set_Menu_Init (Men, Proc);
begin
if Res /= E_Ok then
Eti_Exception (Res);
end if;
end Set_Menu_Init_Hook;
procedure Set_Menu_Term_Hook (Men : in Menu;
Proc : in Menu_Hook_Function)
is
function Set_Menu_Term (Men : Menu;
Proc : Menu_Hook_Function) return C_Int;
pragma Import (C, Set_Menu_Term, "set_menu_term");
Res : constant Eti_Error := Set_Menu_Term (Men, Proc);
begin
if Res /= E_Ok then
Eti_Exception (Res);
end if;
end Set_Menu_Term_Hook;
function Get_Item_Init_Hook (Men : Menu) return Menu_Hook_Function
is
function Item_Init (Men : Menu) return Menu_Hook_Function;
pragma Import (C, Item_Init, "item_init");
begin
return Item_Init (Men);
end Get_Item_Init_Hook;
function Get_Item_Term_Hook (Men : Menu) return Menu_Hook_Function
is
function Item_Term (Men : Menu) return Menu_Hook_Function;
pragma Import (C, Item_Term, "item_term");
begin
return Item_Term (Men);
end Get_Item_Term_Hook;
function Get_Menu_Init_Hook (Men : Menu) return Menu_Hook_Function
is
function Menu_Init (Men : Menu) return Menu_Hook_Function;
pragma Import (C, Menu_Init, "menu_init");
begin
return Menu_Init (Men);
end Get_Menu_Init_Hook;
function Get_Menu_Term_Hook (Men : Menu) return Menu_Hook_Function
is
function Menu_Term (Men : Menu) return Menu_Hook_Function;
pragma Import (C, Menu_Term, "menu_term");
begin
return Menu_Term (Men);
end Get_Menu_Term_Hook;
-------------------------------------------------------------------------------
procedure Redefine (Men : in Menu;
Items : in Item_Array_Access)
is
function Set_Items (Men : Menu;
Items : System.Address) return C_Int;
pragma Import (C, Set_Items, "set_menu_items");
Res : Eti_Error;
begin
pragma Assert (Items (Items'Last) = Null_Item);
if Items (Items'Last) /= Null_Item then
raise Menu_Exception;
else
Res := Set_Items (Men, Items (Items'First)'Address);
if Res /= E_Ok then
Eti_Exception (Res);
end if;
end if;
end Redefine;
function Item_Count (Men : Menu) return Natural
is
function Count (Men : Menu) return C_Int;
pragma Import (C, Count, "item_count");
begin
return Natural (Count (Men));
end Item_Count;
function Items (Men : Menu;
Index : Positive) return Item
is
function M_Items (Men : Menu;
Idx : C_Int) return Item;
pragma Import (C, M_Items, "_nc_get_item");
begin
if Men = Null_Menu or else Index not in 1 .. Item_Count (Men) then
raise Menu_Exception;
else
return M_Items (Men, C_Int (Index) - 1);
end if;
end Items;
-------------------------------------------------------------------------------
function Create (Items : Item_Array_Access) return Menu
is
function Newmenu (Items : System.Address) return Menu;
pragma Import (C, Newmenu, "new_menu");
M : Menu;
I : Item_Array_Access;
begin
pragma Assert (Items (Items'Last) = Null_Item);
if Items (Items'Last) /= Null_Item then
raise Menu_Exception;
else
M := Newmenu (Items (Items'First)'Address);
if M = Null_Menu then
raise Menu_Exception;
end if;
return M;
end if;
end Create;
procedure Delete (Men : in out Menu)
is
function Free (Men : Menu) return C_Int;
pragma Import (C, Free, "free_menu");
Res : constant Eti_Error := Free (Men);
begin
if Res /= E_Ok then
Eti_Exception (Res);
end if;
Men := Null_Menu;
end Delete;
------------------------------------------------------------------------------
function Driver (Men : Menu;
Key : Key_Code) return Driver_Result
is
function Driver (Men : Menu;
Key : C_Int) return C_Int;
pragma Import (C, Driver, "menu_driver");
R : Eti_Error := Driver (Men, C_Int (Key));
begin
if R /= E_Ok then
case R is
when E_Unknown_Command => return Unknown_Request;
when E_No_Match => return No_Match;
when E_Request_Denied |
E_Not_Selectable => return Request_Denied;
when others =>
Eti_Exception (R);
end case;
end if;
return Menu_Ok;
end Driver;
procedure Free (IA : in out Item_Array_Access;
Free_Items : in Boolean := False)
is
procedure Release is new Ada.Unchecked_Deallocation
(Item_Array, Item_Array_Access);
begin
if IA /= null and then Free_Items then
for I in IA'First .. (IA'Last - 1) loop
if (IA (I) /= Null_Item) then
Delete (IA (I));
end if;
end loop;
end if;
Release (IA);
end Free;
-------------------------------------------------------------------------------
function Default_Menu_Options return Menu_Option_Set
is
begin
return Get_Options (Null_Menu);
end Default_Menu_Options;
function Default_Item_Options return Item_Option_Set
is
begin
return Get_Options (Null_Item);
end Default_Item_Options;
-------------------------------------------------------------------------------
end Terminal_Interface.Curses.Menus;
|
reznikmm/matreshka | Ada | 5,429 | adb | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- XML Processor --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2010, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
with Ada.Unchecked_Deallocation;
package body Matreshka.Internals.XML.Notation_Tables is
procedure Free is
new Ada.Unchecked_Deallocation (Notation_Array, Notation_Array_Access);
procedure Clear (Self : in out Notation_Table);
-----------
-- Clear --
-----------
procedure Clear (Self : in out Notation_Table) is
begin
for J in Self.Table'First .. Self.Last loop
Matreshka.Internals.Strings.Dereference (Self.Table (J).Public_Id);
Matreshka.Internals.Strings.Dereference (Self.Table (J).System_Id);
end loop;
Self.Last := No_Notation;
end Clear;
--------------
-- Finalize --
--------------
procedure Finalize (Self : in out Notation_Table) is
begin
Clear (Self);
Free (Self.Table);
end Finalize;
------------------
-- New_Notation --
------------------
procedure New_Notation
(Self : in out Notation_Table;
Name : Symbol_Identifier;
Public_Id : Matreshka.Internals.Strings.Shared_String_Access;
System_Id : Matreshka.Internals.Strings.Shared_String_Access;
Notation : out Notation_Identifier) is
begin
-- Assign notation identifier.
Self.Last := Self.Last + 1;
Notation := Self.Last;
-- Reallocate table when necessay.
if Notation > Self.Table'Last then
declare
Old : Notation_Array_Access := Self.Table;
begin
Self.Table := new Notation_Array (Old'First .. Old'Last + 16);
Self.Table (Old'Range) := Old.all;
Free (Old);
end;
end if;
-- Fill table's record.
Matreshka.Internals.Strings.Reference (Public_Id);
Matreshka.Internals.Strings.Reference (System_Id);
Self.Table (Notation) :=
(Name => Name,
Public_Id => Public_Id,
System_Id => System_Id);
end New_Notation;
-----------
-- Reset --
-----------
procedure Reset (Self : in out Notation_Table) is
begin
Clear (Self);
end Reset;
end Matreshka.Internals.XML.Notation_Tables;
|
thorstel/Advent-of-Code-2018 | Ada | 38,921 | ads | package Input17 is
type Input_Record is record
Fixed : Natural;
First : Natural;
Last : Natural;
end record;
X_Inputs : constant array (Positive range <>) of Input_Record :=
((459, 1009, 1012),
(459, 1572, 1592),
(459, 273, 300),
(459, 597, 610),
(459, 700, 725),
(460, 1289, 1291),
(460, 1436, 1460),
(460, 1637, 1643),
(460, 1667, 1694),
(460, 688, 690),
(460, 819, 831),
(460, 904, 910),
(461, 556, 569),
(461, 915, 937),
(462, 101, 127),
(462, 243, 253),
(463, 164, 188),
(463, 1666, 1694),
(463, 273, 300),
(463, 310, 314),
(463, 957, 970),
(464, 687, 690),
(464, 699, 725),
(465, 1470, 1483),
(465, 1720, 1722),
(466, 494, 503),
(467, 1093, 1108),
(467, 1507, 1520),
(467, 390, 394),
(467, 553, 563),
(468, 1117, 1122),
(468, 1307, 1333),
(468, 165, 188),
(468, 42, 68),
(468, 731, 744),
(468, 819, 831),
(468, 90, 93),
(470, 101, 127),
(470, 1094, 1108),
(470, 1470, 1483),
(470, 1638, 1643),
(470, 577, 590),
(471, 4, 10),
(471, 634, 648),
(471, 903, 910),
(472, 1118, 1122),
(472, 1355, 1374),
(472, 553, 563),
(472, 870, 894),
(473, 1053, 1080),
(473, 1510, 1514),
(473, 767, 772),
(474, 1173, 1197),
(474, 288, 294),
(475, 1009, 1012),
(475, 1510, 1514),
(475, 1720, 1722),
(475, 487, 488),
(475, 494, 503),
(476, 1100, 1105),
(476, 1656, 1683),
(476, 242, 253),
(476, 915, 937),
(476, 958, 970),
(477, 1732, 1753),
(477, 517, 525),
(478, 1657, 1683),
(478, 41, 68),
(478, 766, 772),
(479, 1034, 1041),
(479, 1174, 1197),
(479, 1436, 1460),
(479, 1572, 1592),
(479, 1706, 1726),
(479, 230, 238),
(479, 453, 463),
(479, 598, 610),
(479, 957, 985),
(480, 1255, 1277),
(480, 518, 525),
(480, 674, 686),
(480, 910, 918),
(481, 1290, 1291),
(481, 1318, 1326),
(481, 1486, 1499),
(481, 1542, 1556),
(481, 341, 367),
(481, 534, 548),
(481, 555, 569),
(482, 1412, 1433),
(482, 230, 238),
(482, 73, 83),
(483, 1782, 1801),
(483, 760, 762),
(484, 1707, 1726),
(484, 618, 629),
(485, 32, 46),
(486, 4, 10),
(486, 456, 458),
(486, 792, 806),
(486, 877, 891),
(486, 90, 93),
(487, 1052, 1080),
(487, 1127, 1150),
(487, 1189, 1203),
(487, 1318, 1326),
(488, 1583, 1610),
(488, 1733, 1753),
(488, 311, 314),
(488, 456, 458),
(488, 655, 667),
(488, 911, 918),
(489, 1003, 1030),
(489, 1355, 1374),
(489, 1413, 1433),
(489, 328, 334),
(489, 734, 737),
(489, 768, 776),
(489, 957, 985),
(490, 1567, 1571),
(490, 1713, 1720),
(490, 214, 228),
(490, 391, 394),
(491, 1229, 1241),
(491, 1268, 1273),
(491, 132, 140),
(491, 1785, 1787),
(491, 877, 891),
(492, 1072, 1075),
(492, 1508, 1520),
(492, 518, 527),
(492, 714, 726),
(492, 800, 802),
(492, 817, 840),
(493, 132, 140),
(493, 152, 165),
(493, 1785, 1787),
(493, 287, 294),
(493, 55, 66),
(493, 659, 663),
(493, 922, 942),
(494, 1432, 1442),
(494, 1567, 1571),
(494, 1714, 1720),
(494, 452, 463),
(494, 495, 506),
(494, 538, 542),
(494, 635, 648),
(494, 800, 802),
(495, 1129, 1141),
(495, 1268, 1273),
(495, 1308, 1333),
(495, 1504, 1526),
(496, 1285, 1295),
(496, 538, 542),
(496, 577, 590),
(496, 599, 611),
(497, 1024, 1027),
(497, 1033, 1041),
(497, 1086, 1091),
(497, 1099, 1105),
(497, 238, 250),
(497, 515, 524),
(497, 659, 663),
(497, 734, 737),
(497, 822, 834),
(498, 1072, 1075),
(498, 342, 367),
(498, 465, 467),
(498, 871, 894),
(499, 10, 21),
(499, 1024, 1027),
(499, 1129, 1141),
(499, 1435, 1438),
(499, 1781, 1801),
(500, 1390, 1400),
(500, 1584, 1610),
(500, 922, 942),
(501, 1167, 1179),
(501, 1195, 1199),
(501, 1256, 1277),
(501, 190, 203),
(501, 486, 488),
(502, 1209, 1220),
(502, 465, 467),
(502, 515, 524),
(502, 534, 548),
(503, 1345, 1364),
(503, 1470, 1481),
(503, 1505, 1526),
(503, 1756, 1768),
(503, 219, 222),
(503, 61, 63),
(503, 655, 667),
(503, 791, 806),
(504, 1195, 1199),
(504, 152, 165),
(504, 236, 246),
(504, 597, 607),
(504, 768, 776),
(504, 8, 18),
(505, 1004, 1030),
(505, 1656, 1670),
(505, 619, 629),
(505, 693, 706),
(506, 1435, 1438),
(506, 33, 46),
(506, 387, 399),
(506, 410, 423),
(506, 61, 63),
(506, 822, 834),
(507, 1409, 1421),
(507, 1675, 1703),
(507, 1775, 1788),
(507, 219, 222),
(508, 1126, 1150),
(508, 1249, 1258),
(508, 1283, 1291),
(508, 236, 246),
(508, 474, 483),
(508, 517, 527),
(508, 597, 607),
(508, 761, 762),
(508, 765, 773),
(508, 961, 979),
(509, 1306, 1320),
(509, 259, 272),
(509, 8, 18),
(510, 1190, 1203),
(510, 1283, 1291),
(510, 1369, 1381),
(510, 432, 444),
(511, 1719, 1725),
(512, 1115, 1125),
(512, 1346, 1364),
(512, 1756, 1768),
(512, 538, 549),
(512, 699, 702),
(513, 1655, 1670),
(513, 170, 179),
(513, 215, 228),
(514, 1230, 1241),
(514, 1432, 1442),
(514, 1449, 1461),
(514, 1591, 1607),
(514, 600, 611),
(514, 817, 840),
(515, 1718, 1725),
(515, 239, 250),
(515, 265, 269),
(515, 385, 395),
(515, 408, 418),
(515, 674, 686),
(516, 1060, 1065),
(516, 1132, 1142),
(516, 1190, 1200),
(516, 1263, 1276),
(516, 1286, 1295),
(516, 283, 297),
(516, 348, 364),
(516, 429, 441),
(516, 55, 66),
(516, 629, 651),
(516, 699, 702),
(516, 766, 773),
(517, 11, 21),
(517, 1251, 1254),
(517, 1391, 1400),
(517, 265, 269),
(517, 328, 334),
(517, 385, 395),
(517, 801, 816),
(517, 91, 102),
(518, 429, 441),
(518, 537, 549),
(518, 715, 726),
(518, 881, 895),
(518, 928, 937),
(519, 238, 251),
(519, 408, 418),
(520, 1061, 1065),
(520, 1251, 1254),
(520, 1347, 1360),
(520, 1470, 1481),
(520, 1590, 1607),
(520, 1716, 1728),
(520, 452, 463),
(520, 962, 979),
(521, 494, 506),
(522, 109, 119),
(522, 1096, 1105),
(522, 1447, 1454),
(523, 149, 158),
(523, 1675, 1703),
(523, 189, 203),
(523, 260, 272),
(523, 369, 378),
(523, 388, 399),
(524, 1085, 1091),
(524, 1136, 1139),
(524, 1447, 1454),
(524, 1513, 1520),
(524, 237, 251),
(524, 308, 320),
(524, 74, 83),
(525, 1750, 1760),
(525, 29, 42),
(525, 411, 423),
(526, 693, 706),
(527, 1248, 1258),
(527, 1307, 1320),
(527, 431, 444),
(527, 58, 77),
(527, 95, 98),
(527, 976, 985),
(528, 1116, 1125),
(528, 1152, 1162),
(528, 1564, 1589),
(528, 925, 934),
(528, 948, 962),
(529, 1167, 1179),
(529, 1209, 1220),
(529, 1676, 1682),
(529, 349, 364),
(529, 628, 651),
(529, 755, 769),
(529, 802, 816),
(529, 863, 873),
(529, 95, 98),
(530, 1013, 1023),
(530, 107, 116),
(530, 1072, 1085),
(530, 1450, 1461),
(530, 153, 155),
(530, 28, 42),
(530, 306, 317),
(530, 925, 934),
(531, 1136, 1139),
(531, 1389, 1394),
(531, 1476, 1479),
(531, 229, 254),
(532, 107, 116),
(532, 1218, 1225),
(532, 1322, 1337),
(532, 153, 155),
(532, 1676, 1682),
(532, 306, 317),
(533, 1032, 1045),
(533, 1172, 1177),
(533, 228, 254),
(534, 12, 34),
(534, 1208, 1212),
(534, 1775, 1788),
(534, 518, 539),
(535, 1444, 1448),
(535, 169, 179),
(535, 443, 446),
(535, 57, 77),
(535, 764, 766),
(536, 1010, 1019),
(536, 1232, 1243),
(536, 1640, 1657),
(536, 1715, 1728),
(536, 189, 205),
(536, 573, 578),
(536, 732, 744),
(536, 882, 895),
(536, 906, 916),
(536, 92, 102),
(536, 927, 937),
(537, 1132, 1142),
(537, 1325, 1327),
(538, 110, 119),
(538, 1172, 1177),
(538, 129, 140),
(538, 1771, 1776),
(538, 216, 223),
(538, 284, 297),
(538, 349, 360),
(539, 1207, 1212),
(539, 1475, 1479),
(539, 519, 539),
(539, 764, 766),
(540, 179, 181),
(540, 28, 30),
(540, 309, 320),
(540, 329, 341),
(541, 1029, 1038),
(541, 1095, 1105),
(541, 1170, 1181),
(541, 1563, 1589),
(541, 452, 463),
(541, 953, 958),
(542, 1189, 1200),
(542, 840, 854),
(543, 1010, 1019),
(543, 346, 356),
(543, 778, 791),
(544, 1569, 1592),
(544, 265, 266),
(544, 28, 30),
(544, 511, 520),
(544, 802, 813),
(544, 903, 910),
(544, 953, 958),
(545, 1029, 1038),
(545, 1054, 1063),
(545, 1325, 1327),
(546, 127, 137),
(546, 1513, 1520),
(546, 614, 629),
(547, 1231, 1243),
(547, 1749, 1760),
(547, 368, 378),
(547, 443, 446),
(547, 594, 595),
(547, 903, 910),
(547, 977, 985),
(548, 127, 137),
(548, 148, 158),
(548, 189, 205),
(548, 38, 54),
(549, 1012, 1023),
(549, 1641, 1657),
(549, 326, 335),
(549, 639, 645),
(549, 994, 1003),
(550, 1109, 1117),
(550, 1432, 1435),
(550, 613, 629),
(550, 756, 769),
(550, 785, 787),
(551, 1031, 1045),
(551, 1323, 1337),
(551, 326, 335),
(551, 346, 356),
(551, 799, 808),
(551, 949, 962),
(551, 970, 982),
(552, 1153, 1162),
(552, 12, 34),
(552, 1217, 1225),
(552, 1569, 1592),
(552, 188, 209),
(552, 822, 833),
(553, 1058, 1060),
(553, 1461, 1476),
(554, 1071, 1085),
(554, 130, 140),
(554, 1602, 1619),
(554, 1683, 1706),
(554, 1738, 1748),
(554, 785, 787),
(554, 799, 808),
(554, 905, 916),
(555, 1110, 1117),
(555, 1139, 1147),
(555, 1288, 1300),
(555, 1461, 1476),
(555, 473, 483),
(555, 991, 1000),
(556, 1058, 1060),
(556, 967, 979),
(557, 1432, 1435),
(557, 180, 181),
(557, 187, 209),
(557, 348, 360),
(558, 1327, 1340),
(558, 1388, 1394),
(558, 328, 341),
(558, 711, 734),
(559, 1033, 1050),
(559, 1513, 1539),
(559, 1586, 1590),
(559, 1688, 1695),
(559, 1801, 1813),
(559, 375, 394),
(559, 531, 547),
(559, 650, 677),
(559, 967, 979),
(560, 155, 167),
(560, 1770, 1776),
(560, 39, 54),
(560, 593, 595),
(560, 742, 749),
(560, 779, 791),
(560, 991, 1000),
(561, 1783, 1792),
(561, 231, 233),
(561, 893, 913),
(562, 1444, 1448),
(562, 156, 167),
(562, 1739, 1748),
(562, 289, 310),
(562, 572, 578),
(562, 743, 749),
(562, 801, 813),
(563, 1653, 1673),
(563, 217, 223),
(563, 925, 930),
(564, 1053, 1063),
(564, 106, 121),
(564, 1285, 1297),
(564, 1524, 1527),
(564, 1688, 1695),
(564, 538, 541),
(564, 619, 624),
(564, 640, 645),
(565, 1170, 1181),
(565, 1193, 1202),
(565, 1324, 1334),
(565, 1394, 1402),
(565, 1640, 1645),
(565, 712, 734),
(565, 758, 768),
(565, 784, 787),
(566, 1524, 1527),
(566, 538, 541),
(567, 1285, 1297),
(567, 1393, 1402),
(567, 1602, 1619),
(567, 1639, 1645),
(567, 1798, 1810),
(567, 207, 227),
(567, 342, 367),
(567, 993, 1003),
(568, 1324, 1334),
(568, 264, 266),
(568, 388, 390),
(568, 456, 471),
(568, 903, 908),
(569, 1089, 1111),
(569, 551, 552),
(569, 969, 982),
(570, 1564, 1573),
(570, 1683, 1706),
(570, 1798, 1810),
(570, 425, 441),
(571, 1436, 1456),
(571, 849, 851),
(572, 1190, 1197),
(572, 239, 242),
(572, 388, 390),
(572, 512, 520),
(572, 574, 583),
(572, 903, 908),
(573, 1263, 1276),
(573, 160, 171),
(573, 669, 673),
(573, 763, 765),
(574, 111, 115),
(574, 1762, 1772),
(574, 7, 10),
(574, 822, 833),
(575, 1190, 1197),
(575, 1287, 1300),
(575, 1307, 1318),
(575, 1326, 1340),
(575, 1436, 1456),
(575, 53, 62),
(575, 531, 547),
(575, 849, 851),
(576, 111, 115),
(576, 1275, 1277),
(576, 1514, 1539),
(576, 1785, 1787),
(576, 466, 468),
(576, 783, 787),
(576, 80, 93),
(577, 1653, 1673),
(577, 669, 673),
(578, 1618, 1631),
(578, 238, 242),
(578, 254, 277),
(578, 376, 394),
(578, 402, 405),
(578, 487, 503),
(578, 54, 62),
(578, 763, 765),
(579, 1800, 1813),
(579, 208, 227),
(579, 801, 819),
(580, 163, 165),
(580, 1785, 1787),
(580, 997, 1016),
(581, 1192, 1202),
(581, 341, 367),
(581, 573, 583),
(581, 801, 819),
(581, 894, 913),
(581, 925, 930),
(582, 1138, 1147),
(583, 163, 165),
(583, 230, 233),
(583, 377, 397),
(583, 88, 90),
(584, 1305, 1315),
(584, 650, 677),
(584, 758, 768),
(585, 1088, 1111),
(585, 1347, 1360),
(585, 1689, 1711),
(585, 428, 433),
(585, 466, 468),
(585, 840, 854),
(585, 88, 90),
(586, 106, 121),
(586, 1587, 1590),
(586, 1782, 1792),
(586, 290, 310),
(586, 565, 571),
(587, 1034, 1050),
(587, 1525, 1526),
(587, 1624, 1628),
(587, 1741, 1751),
(588, 1305, 1315),
(588, 1799, 1805),
(588, 253, 277),
(588, 488, 503),
(588, 620, 624),
(588, 784, 802),
(589, 448, 451),
(589, 708, 723),
(589, 907, 932),
(589, 950, 971),
(590, 1096, 1104),
(590, 1128, 1154),
(591, 1264, 1266),
(591, 1564, 1573),
(591, 1642, 1644),
(591, 457, 471),
(591, 79, 93),
(592, 1237, 1249),
(592, 160, 171),
(592, 428, 433),
(592, 879, 885),
(592, 906, 932),
(593, 1431, 1441),
(593, 791, 795),
(594, 1308, 1318),
(594, 1624, 1628),
(594, 550, 552),
(595, 1060, 1075),
(595, 1196, 1201),
(595, 1524, 1526),
(595, 1642, 1644),
(595, 1744, 1747),
(595, 177, 197),
(595, 42, 65),
(595, 950, 971),
(596, 1127, 1154),
(596, 1369, 1381),
(596, 1689, 1711),
(596, 1719, 1729),
(596, 303, 311),
(596, 707, 723),
(597, 935, 939),
(598, 1263, 1266),
(598, 1528, 1537),
(598, 424, 441),
(598, 878, 885),
(599, 1140, 1145),
(599, 1276, 1277),
(599, 378, 397),
(599, 734, 736),
(599, 862, 873),
(600, 1658, 1669),
(600, 327, 338),
(600, 514, 525),
(600, 564, 571),
(600, 791, 795),
(600, 998, 1016),
(601, 107, 110),
(601, 1140, 1145),
(601, 1617, 1631),
(601, 1744, 1747),
(601, 467, 494),
(601, 547, 552),
(602, 1723, 1726),
(602, 42, 65),
(602, 458, 464),
(602, 7, 10),
(603, 960, 964),
(604, 1215, 1229),
(604, 1267, 1285),
(604, 1678, 1692),
(604, 403, 405),
(605, 1409, 1421),
(605, 326, 338),
(605, 936, 939),
(606, 19, 39),
(606, 414, 422),
(606, 784, 802),
(607, 1376, 1382),
(607, 1525, 1534),
(607, 1702, 1712),
(607, 1740, 1751),
(607, 231, 237),
(608, 1061, 1075),
(608, 1639, 1649),
(609, 1136, 1146),
(609, 1664, 1666),
(609, 1676, 1689),
(609, 1800, 1805),
(609, 619, 629),
(609, 868, 870),
(610, 1097, 1104),
(610, 1215, 1229),
(610, 1525, 1534),
(610, 18, 39),
(610, 448, 451),
(610, 595, 608),
(611, 204, 206),
(611, 302, 311),
(611, 467, 494),
(612, 1022, 1038),
(612, 1333, 1344),
(612, 1664, 1666),
(612, 186, 194),
(613, 576, 579),
(614, 1069, 1093),
(614, 115, 130),
(614, 1237, 1249),
(614, 1676, 1689),
(614, 186, 194),
(614, 352, 365),
(614, 515, 525),
(614, 623, 625),
(614, 633, 649),
(614, 821, 833),
(615, 1431, 1441),
(615, 1765, 1769),
(615, 313, 339),
(615, 53, 77),
(615, 733, 736),
(616, 1267, 1285),
(616, 1641, 1643),
(616, 353, 365),
(616, 623, 625),
(616, 820, 833),
(617, 1197, 1201),
(617, 1506, 1519),
(617, 1527, 1537),
(617, 312, 339),
(617, 458, 464),
(618, 1113, 1131),
(618, 1659, 1669),
(618, 381, 387),
(618, 749, 755),
(619, 1466, 1480),
(619, 1641, 1643),
(619, 1705, 1709),
(620, 1679, 1692),
(621, 108, 110),
(621, 1139, 1142),
(621, 1314, 1318),
(621, 1615, 1628),
(621, 282, 297),
(621, 466, 472),
(622, 177, 197),
(622, 1783, 1806),
(623, 1168, 1184),
(623, 1333, 1344),
(623, 1439, 1459),
(623, 749, 755),
(624, 118, 122),
(624, 1655, 1664),
(624, 204, 206),
(625, 1139, 1142),
(625, 1257, 1259),
(625, 1486, 1499),
(625, 1705, 1709),
(625, 467, 472),
(626, 118, 122),
(626, 1375, 1382),
(626, 1745, 1752),
(627, 1021, 1038),
(627, 664, 688),
(628, 1488, 1502),
(628, 1638, 1649),
(628, 1795, 1798),
(628, 380, 387),
(628, 620, 629),
(628, 928, 952),
(629, 1169, 1184),
(629, 1474, 1476),
(629, 547, 552),
(629, 634, 649),
(630, 1068, 1093),
(631, 1373, 1380),
(631, 379, 386),
(631, 961, 964),
(632, 1136, 1146),
(632, 1652, 1661),
(632, 1795, 1798),
(632, 232, 237),
(632, 281, 297),
(632, 3, 8),
(632, 596, 608),
(633, 1022, 1044),
(633, 115, 130),
(633, 1372, 1380),
(633, 1394, 1417),
(633, 438, 459),
(633, 868, 870),
(634, 1212, 1221),
(634, 1227, 1247),
(634, 1329, 1331),
(634, 1549, 1551),
(634, 1590, 1604),
(634, 414, 422),
(634, 577, 579),
(634, 976, 979),
(635, 1297, 1309),
(635, 1474, 1476),
(635, 1487, 1502),
(635, 1701, 1712),
(635, 751, 769),
(636, 1021, 1044),
(636, 1652, 1661),
(636, 1671, 1681),
(637, 1048, 1064),
(637, 1146, 1149),
(637, 1228, 1247),
(637, 1349, 1373),
(637, 1506, 1519),
(637, 1740, 1742),
(637, 186, 205),
(637, 391, 404),
(637, 54, 77),
(637, 664, 688),
(638, 1276, 1290),
(638, 26, 40),
(638, 735, 739),
(638, 927, 952),
(639, 1112, 1131),
(639, 1549, 1551),
(639, 1599, 1601),
(639, 245, 261),
(640, 1314, 1318),
(640, 1349, 1373),
(640, 1784, 1806),
(640, 27, 40),
(640, 326, 347),
(640, 511, 531),
(641, 442, 452),
(641, 70, 85),
(641, 838, 856),
(642, 1019, 1037),
(642, 1395, 1417),
(642, 1465, 1480),
(642, 1599, 1601),
(642, 1740, 1742),
(642, 751, 769),
(642, 921, 930),
(643, 1634, 1643),
(643, 1654, 1664),
(643, 228, 233),
(644, 1318, 1323),
(644, 1614, 1628),
(644, 866, 870),
(645, 1302, 1305),
(645, 1543, 1556),
(645, 1568, 1579),
(646, 147, 173),
(646, 339, 344),
(646, 685, 710),
(647, 1018, 1037),
(647, 1051, 1058),
(647, 442, 452),
(647, 773, 794),
(648, 1258, 1259),
(648, 1351, 1373),
(648, 1389, 1412),
(648, 313, 320),
(648, 408, 425),
(648, 755, 758),
(649, 1051, 1058),
(649, 1302, 1305),
(649, 1438, 1459),
(649, 1652, 1664),
(649, 339, 344),
(649, 354, 371),
(649, 473, 483),
(649, 838, 856),
(650, 1147, 1149),
(650, 1279, 1281),
(650, 1723, 1726),
(650, 1745, 1752),
(650, 512, 531),
(650, 548, 575),
(651, 1329, 1331),
(651, 1590, 1604),
(651, 1672, 1681),
(651, 627, 644),
(652, 1279, 1281),
(652, 146, 173),
(652, 1527, 1553),
(652, 354, 371),
(652, 548, 575),
(653, 108, 127),
(653, 1212, 1221),
(653, 1339, 1341),
(653, 1498, 1517),
(654, 1565, 1576),
(654, 1594, 1611),
(654, 1637, 1640),
(654, 585, 611),
(654, 876, 899),
(655, 1012, 1038),
(655, 1049, 1064),
(655, 1338, 1341),
(655, 1359, 1370),
(655, 325, 347),
(655, 378, 386),
(655, 736, 739),
(655, 755, 758),
(655, 860, 861),
(656, 136, 160),
(656, 1565, 1576),
(657, 1296, 1309),
(657, 1359, 1370),
(658, 1404, 1409),
(658, 1512, 1514),
(658, 438, 459),
(658, 473, 483),
(659, 1013, 1038),
(659, 1116, 1119),
(659, 1275, 1290),
(659, 186, 205),
(659, 244, 261),
(659, 4, 8),
(660, 1637, 1640),
(660, 1676, 1698),
(660, 498, 520),
(660, 628, 644),
(660, 740, 765),
(661, 1446, 1473),
(661, 1653, 1664),
(661, 659, 681),
(661, 832, 845),
(662, 1512, 1514),
(662, 1567, 1579),
(662, 409, 425),
(662, 799, 816),
(662, 975, 979),
(663, 23, 34),
(664, 1535, 1549),
(664, 1594, 1611),
(664, 1765, 1769),
(664, 213, 215),
(664, 876, 899),
(664, 908, 909),
(665, 1351, 1373),
(665, 1404, 1409),
(665, 392, 404),
(665, 684, 710),
(665, 69, 85),
(666, 1178, 1188),
(666, 1206, 1221),
(666, 1318, 1323),
(666, 1456, 1466),
(666, 1633, 1643),
(666, 1719, 1729),
(667, 200, 203),
(667, 214, 215),
(667, 228, 233),
(667, 497, 520),
(667, 660, 681),
(667, 752, 759),
(667, 774, 794),
(667, 983, 1007),
(668, 865, 870),
(668, 922, 930),
(669, 135, 160),
(669, 265, 289),
(669, 907, 909),
(670, 1288, 1303),
(670, 1535, 1549),
(670, 1634, 1653),
(670, 514, 536),
(670, 643, 662),
(671, 1061, 1086),
(671, 859, 861),
(672, 1115, 1119),
(672, 1456, 1466),
(672, 668, 690),
(672, 752, 759),
(672, 809, 813),
(673, 1041, 1049),
(673, 1126, 1143),
(673, 199, 203),
(673, 547, 575),
(674, 1782, 1793),
(674, 282, 285),
(674, 312, 320),
(674, 809, 813),
(674, 954, 977),
(674, 984, 1007),
(675, 1060, 1086),
(675, 1390, 1412),
(675, 1497, 1517),
(675, 335, 355),
(675, 643, 662),
(676, 23, 34),
(677, 1159, 1168),
(677, 1289, 1303),
(677, 515, 536),
(677, 724, 727),
(679, 107, 127),
(679, 1528, 1553),
(679, 1584, 1611),
(679, 1675, 1698),
(679, 953, 977),
(680, 1160, 1168),
(680, 1391, 1392),
(680, 1762, 1772),
(680, 282, 285),
(680, 336, 355),
(680, 586, 611),
(681, 668, 690),
(682, 1548, 1559),
(682, 739, 765),
(682, 800, 816),
(682, 833, 845),
(682, 87, 111),
(683, 1585, 1611),
(684, 1178, 1188),
(684, 1207, 1221),
(684, 1635, 1653),
(685, 1547, 1559),
(686, 1042, 1049),
(686, 1447, 1473),
(686, 266, 289),
(687, 1126, 1143),
(687, 1390, 1392),
(687, 548, 575),
(687, 723, 727),
(687, 87, 111),
(689, 1783, 1793));
Y_Inputs : constant array (Positive range <>) of Input_Record :=
((10, 471, 486),
(10, 574, 602),
(1000, 555, 560),
(1003, 549, 567),
(1007, 667, 674),
(1012, 459, 475),
(1016, 580, 600),
(1019, 536, 543),
(102, 517, 536),
(1023, 530, 549),
(1024, 497, 499),
(1027, 497, 499),
(1030, 489, 505),
(1037, 642, 647),
(1038, 541, 545),
(1038, 612, 627),
(1038, 655, 659),
(1041, 479, 497),
(1044, 633, 636),
(1045, 533, 551),
(1049, 673, 686),
(1050, 559, 587),
(1051, 647, 649),
(1058, 647, 649),
(1060, 553, 556),
(1063, 545, 564),
(1064, 637, 655),
(1065, 516, 520),
(1075, 492, 498),
(1075, 595, 608),
(1080, 473, 487),
(1085, 530, 554),
(1086, 671, 675),
(1091, 497, 524),
(1093, 614, 630),
(110, 601, 621),
(1104, 590, 610),
(1105, 476, 497),
(1105, 522, 541),
(1108, 467, 470),
(111, 682, 687),
(1111, 569, 585),
(1117, 550, 555),
(1119, 659, 672),
(1122, 468, 472),
(1125, 512, 528),
(1129, 495, 499),
(1131, 618, 639),
(1139, 524, 531),
(1139, 621, 625),
(1141, 495, 499),
(1142, 516, 537),
(1142, 621, 625),
(1143, 673, 687),
(1145, 599, 601),
(1146, 609, 632),
(1147, 555, 582),
(1149, 637, 650),
(115, 574, 576),
(1150, 487, 508),
(1154, 590, 596),
(116, 530, 532),
(1162, 528, 552),
(1168, 677, 680),
(1177, 533, 538),
(1179, 501, 529),
(118, 624, 626),
(1181, 541, 565),
(1184, 623, 629),
(1188, 666, 684),
(119, 522, 538),
(1197, 474, 479),
(1197, 572, 575),
(1199, 501, 504),
(1200, 516, 542),
(1201, 595, 617),
(1202, 565, 581),
(1203, 487, 510),
(121, 564, 586),
(1212, 534, 539),
(122, 624, 626),
(1220, 502, 529),
(1221, 634, 653),
(1221, 666, 684),
(1225, 532, 552),
(1229, 604, 610),
(1241, 491, 514),
(1243, 536, 547),
(1247, 634, 637),
(1249, 592, 614),
(1254, 517, 520),
(1258, 508, 527),
(1259, 625, 648),
(1266, 591, 598),
(1268, 491, 495),
(127, 462, 470),
(127, 653, 679),
(1273, 491, 495),
(1276, 516, 573),
(1277, 480, 501),
(1277, 576, 599),
(1279, 650, 652),
(1281, 650, 652),
(1285, 604, 616),
(1290, 638, 659),
(1291, 460, 481),
(1291, 508, 510),
(1295, 496, 516),
(1297, 564, 567),
(130, 614, 633),
(1300, 555, 575),
(1303, 670, 677),
(1305, 645, 649),
(1309, 635, 657),
(1315, 584, 588),
(1318, 481, 487),
(1318, 575, 594),
(1318, 621, 640),
(1320, 509, 527),
(1323, 644, 666),
(1325, 537, 545),
(1326, 481, 487),
(1327, 537, 545),
(1331, 634, 651),
(1333, 468, 495),
(1334, 565, 568),
(1337, 532, 551),
(1340, 558, 575),
(1341, 653, 655),
(1344, 612, 623),
(1359, 655, 657),
(1360, 520, 585),
(1364, 503, 512),
(137, 546, 548),
(1370, 655, 657),
(1373, 637, 640),
(1373, 648, 665),
(1374, 472, 489),
(1380, 631, 633),
(1381, 510, 596),
(1382, 607, 626),
(1392, 680, 687),
(1394, 531, 558),
(140, 491, 493),
(140, 538, 554),
(1400, 500, 517),
(1402, 565, 567),
(1409, 658, 665),
(1412, 648, 675),
(1417, 633, 642),
(1421, 507, 605),
(1433, 482, 489),
(1435, 550, 557),
(1438, 499, 506),
(1441, 593, 615),
(1442, 494, 514),
(1448, 535, 562),
(1454, 522, 524),
(1456, 571, 575),
(1459, 623, 649),
(1460, 460, 479),
(1461, 514, 530),
(1466, 666, 672),
(1473, 661, 686),
(1474, 629, 635),
(1476, 553, 555),
(1476, 629, 635),
(1479, 531, 539),
(1480, 619, 642),
(1481, 503, 520),
(1483, 465, 470),
(1499, 481, 625),
(1502, 628, 635),
(1514, 473, 475),
(1514, 658, 662),
(1517, 653, 675),
(1519, 617, 637),
(1520, 467, 492),
(1520, 524, 546),
(1526, 495, 503),
(1526, 587, 595),
(1527, 564, 566),
(153, 530, 532),
(1534, 607, 610),
(1537, 598, 617),
(1539, 559, 576),
(1549, 634, 639),
(1549, 664, 670),
(155, 530, 532),
(1551, 634, 639),
(1553, 652, 679),
(1556, 481, 645),
(1559, 682, 685),
(1571, 490, 494),
(1573, 570, 591),
(1576, 654, 656),
(1579, 645, 662),
(158, 523, 548),
(1589, 528, 541),
(1590, 559, 586),
(1592, 459, 479),
(1592, 544, 552),
(160, 656, 669),
(1601, 639, 642),
(1604, 634, 651),
(1607, 514, 520),
(1610, 488, 500),
(1611, 654, 664),
(1611, 679, 683),
(1619, 554, 567),
(1624, 587, 594),
(1628, 587, 594),
(1628, 621, 644),
(163, 580, 583),
(1631, 578, 601),
(1637, 654, 660),
(1640, 654, 660),
(1641, 616, 619),
(1643, 460, 470),
(1643, 616, 619),
(1643, 643, 666),
(1644, 591, 595),
(1645, 565, 567),
(1649, 608, 628),
(165, 493, 504),
(165, 580, 583),
(1653, 670, 684),
(1657, 536, 549),
(1661, 632, 636),
(1664, 624, 643),
(1664, 649, 661),
(1666, 609, 612),
(1669, 600, 618),
(167, 560, 562),
(1670, 505, 513),
(1673, 563, 577),
(1681, 636, 651),
(1682, 529, 532),
(1683, 476, 478),
(1689, 609, 614),
(1692, 604, 620),
(1694, 460, 463),
(1695, 559, 564),
(1698, 660, 679),
(1703, 507, 523),
(1705, 619, 625),
(1706, 554, 570),
(1709, 619, 625),
(171, 573, 592),
(1711, 585, 596),
(1712, 607, 635),
(1720, 490, 494),
(1722, 465, 475),
(1725, 511, 515),
(1726, 479, 484),
(1726, 602, 650),
(1728, 520, 536),
(1729, 596, 666),
(173, 646, 652),
(1742, 637, 642),
(1747, 595, 601),
(1748, 554, 562),
(1751, 587, 607),
(1752, 626, 650),
(1753, 477, 488),
(1760, 525, 547),
(1768, 503, 512),
(1769, 615, 664),
(1772, 574, 680),
(1776, 538, 560),
(1785, 576, 580),
(1787, 491, 493),
(1787, 576, 580),
(1788, 507, 534),
(179, 513, 535),
(1792, 561, 586),
(1793, 674, 689),
(1795, 628, 632),
(1798, 628, 632),
(18, 504, 509),
(1801, 483, 499),
(1805, 588, 609),
(1806, 622, 640),
(181, 540, 557),
(1810, 567, 570),
(1813, 559, 579),
(188, 463, 468),
(194, 612, 614),
(197, 595, 622),
(203, 501, 523),
(203, 667, 673),
(205, 536, 548),
(205, 637, 659),
(206, 611, 624),
(209, 552, 557),
(21, 499, 517),
(215, 664, 667),
(219, 503, 507),
(222, 503, 507),
(223, 538, 563),
(227, 567, 579),
(228, 490, 513),
(233, 561, 583),
(233, 643, 667),
(237, 607, 632),
(238, 479, 482),
(242, 572, 578),
(246, 504, 508),
(250, 497, 515),
(251, 519, 524),
(253, 462, 476),
(254, 531, 533),
(261, 639, 659),
(266, 544, 568),
(269, 515, 517),
(272, 509, 523),
(277, 578, 588),
(282, 674, 680),
(285, 674, 680),
(289, 669, 686),
(294, 474, 493),
(297, 516, 538),
(297, 621, 632),
(30, 540, 544),
(300, 459, 463),
(310, 562, 586),
(311, 596, 611),
(314, 463, 488),
(317, 530, 532),
(320, 524, 540),
(320, 648, 674),
(334, 489, 517),
(335, 549, 551),
(338, 600, 605),
(339, 615, 617),
(34, 534, 552),
(34, 663, 676),
(341, 540, 558),
(344, 646, 649),
(347, 640, 655),
(355, 675, 680),
(356, 543, 551),
(360, 538, 557),
(364, 516, 529),
(365, 614, 616),
(367, 481, 498),
(367, 567, 581),
(371, 649, 652),
(378, 523, 547),
(386, 631, 655),
(387, 618, 628),
(39, 606, 610),
(390, 568, 572),
(394, 467, 490),
(394, 559, 578),
(395, 515, 517),
(397, 583, 599),
(399, 506, 523),
(40, 638, 640),
(404, 637, 665),
(405, 578, 604),
(418, 515, 519),
(42, 525, 530),
(422, 606, 634),
(423, 506, 525),
(425, 648, 662),
(433, 585, 592),
(441, 516, 518),
(441, 570, 598),
(444, 510, 527),
(446, 535, 547),
(451, 589, 610),
(452, 641, 647),
(456, 486, 488),
(458, 486, 488),
(459, 633, 658),
(46, 485, 506),
(463, 479, 494),
(463, 520, 541),
(464, 602, 617),
(466, 576, 585),
(467, 498, 502),
(468, 576, 585),
(471, 568, 591),
(472, 621, 625),
(483, 508, 555),
(483, 649, 658),
(488, 475, 501),
(494, 601, 611),
(503, 466, 475),
(503, 578, 588),
(506, 494, 521),
(520, 544, 572),
(520, 660, 667),
(524, 497, 502),
(525, 477, 480),
(525, 600, 614),
(527, 492, 508),
(531, 640, 650),
(536, 670, 677),
(538, 564, 566),
(539, 534, 539),
(54, 548, 560),
(541, 564, 566),
(542, 494, 496),
(547, 559, 575),
(548, 481, 502),
(549, 512, 518),
(552, 569, 594),
(552, 601, 629),
(563, 467, 472),
(569, 461, 481),
(571, 586, 600),
(575, 650, 652),
(575, 673, 687),
(578, 536, 562),
(579, 613, 634),
(583, 572, 581),
(590, 470, 496),
(595, 547, 560),
(607, 504, 508),
(608, 610, 632),
(610, 459, 479),
(611, 496, 514),
(611, 654, 680),
(62, 575, 578),
(624, 564, 588),
(625, 614, 616),
(629, 484, 505),
(629, 546, 550),
(629, 609, 628),
(63, 503, 506),
(644, 651, 660),
(645, 549, 564),
(648, 471, 494),
(649, 614, 629),
(65, 595, 602),
(651, 516, 529),
(66, 493, 516),
(662, 670, 675),
(663, 493, 497),
(667, 488, 503),
(673, 573, 577),
(677, 559, 584),
(68, 468, 478),
(681, 661, 667),
(686, 480, 515),
(688, 627, 637),
(690, 460, 464),
(690, 672, 681),
(702, 512, 516),
(706, 505, 526),
(710, 646, 665),
(723, 589, 596),
(725, 459, 464),
(726, 492, 518),
(727, 677, 687),
(734, 489, 497),
(734, 558, 565),
(736, 599, 615),
(737, 489, 497),
(739, 638, 655),
(744, 468, 536),
(749, 560, 562),
(752, 667, 672),
(755, 618, 623),
(758, 648, 655),
(759, 667, 672),
(762, 483, 508),
(763, 573, 578),
(765, 573, 578),
(765, 660, 682),
(766, 535, 539),
(768, 565, 584),
(769, 529, 550),
(769, 635, 642),
(77, 527, 535),
(77, 615, 637),
(772, 473, 478),
(773, 508, 516),
(776, 489, 504),
(785, 550, 554),
(787, 550, 554),
(787, 565, 576),
(791, 543, 560),
(794, 647, 667),
(795, 593, 600),
(8, 632, 659),
(800, 492, 494),
(802, 492, 494),
(802, 588, 606),
(806, 486, 503),
(808, 551, 554),
(813, 544, 562),
(813, 672, 674),
(816, 517, 529),
(816, 662, 682),
(819, 579, 581),
(83, 482, 524),
(831, 460, 468),
(833, 552, 574),
(833, 614, 616),
(834, 497, 506),
(840, 492, 514),
(845, 661, 682),
(849, 571, 575),
(85, 641, 665),
(851, 571, 575),
(854, 542, 585),
(856, 641, 649),
(861, 655, 671),
(870, 609, 633),
(870, 644, 668),
(873, 529, 599),
(877, 486, 491),
(885, 592, 598),
(891, 486, 491),
(894, 472, 498),
(895, 518, 536),
(899, 654, 664),
(90, 583, 585),
(908, 568, 572),
(909, 664, 669),
(910, 460, 471),
(910, 544, 547),
(913, 561, 581),
(916, 536, 554),
(918, 480, 488),
(93, 468, 486),
(93, 576, 591),
(930, 563, 581),
(930, 642, 668),
(932, 589, 592),
(934, 528, 530),
(937, 461, 476),
(937, 518, 536),
(939, 597, 605),
(942, 493, 500),
(952, 628, 638),
(958, 541, 544),
(962, 528, 551),
(964, 603, 631),
(970, 463, 476),
(971, 589, 595),
(977, 674, 679),
(979, 508, 520),
(979, 556, 559),
(979, 634, 662),
(98, 527, 529),
(982, 551, 569),
(985, 479, 489),
(985, 527, 547));
end Input17;
|
reznikmm/matreshka | Ada | 12,156 | adb | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- SQL Database Access --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2012-2014, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
with Matreshka.Internals.SQL_Drivers.MySQL.Queries;
package body Matreshka.Internals.SQL_Drivers.MySQL.Databases is
use type Interfaces.C.char_array;
use type Interfaces.C.int;
UTF8_Encoding : constant Interfaces.C.char_array
:= "utf8mb4" & Interfaces.C.nul;
procedure Set_MySQL_Error (Self : not null access MySQL_Database'Class);
-- Sets error message to reported by database.
procedure Execute_Query
(Self : not null access MySQL_Database'Class;
Query : String;
Success : in out Boolean);
-- Internal subprogram to executre simple parameter-less and result-less
-- queries at connection initialization time.
-----------
-- Close --
-----------
overriding procedure Close (Self : not null access MySQL_Database) is
begin
if Self.Handle /= null then
mysql_close (Self.Handle);
Self.Handle := null;
end if;
end Close;
------------
-- Commit --
------------
overriding procedure Commit (Self : not null access MySQL_Database) is
begin
raise Program_Error;
end Commit;
---------------------
-- Database_Handle --
---------------------
function Database_Handle
(Self : not null access constant MySQL_Database'Class)
return MYSQL_Access is
begin
return Self.Handle;
end Database_Handle;
-------------------
-- Error_Message --
-------------------
overriding function Error_Message
(Self : not null access MySQL_Database)
return League.Strings.Universal_String is
begin
return Self.Error;
end Error_Message;
-------------------
-- Execute_Query --
-------------------
procedure Execute_Query
(Self : not null access MySQL_Database'Class;
Query : String;
Success : in out Boolean)
is
procedure Set_MySQL_Stmt_Error;
Handle : MYSQL_STMT_Access;
C_Query : Interfaces.C.Strings.chars_ptr;
Status : Interfaces.C.int;
B_Status : my_bool;
--------------------------
-- Set_MySQL_Stmt_Error --
--------------------------
procedure Set_MySQL_Stmt_Error is
begin
Self.Error :=
League.Strings.From_UTF_8_String
(Interfaces.C.Strings.Value (mysql_stmt_error (Handle)));
Success := False;
end Set_MySQL_Stmt_Error;
begin
if not Success then
-- Return immidiately when error condition had been detected. It
-- allows to write sequence of call to Execute_Query without
-- intermediate check for error conditions.
return;
end if;
-- Allocate statement handle.
Handle := mysql_stmt_init (Self.Database_Handle);
if Handle = null then
Self.Error := League.Strings.To_Universal_String ("out of memory");
Success := False;
return;
end if;
-- Prepare statement.
C_Query := Interfaces.C.Strings.New_String (Query);
Status :=
mysql_stmt_prepare
(Handle,
C_Query,
Interfaces.C.unsigned_long
(Interfaces.C.Strings.Strlen (C_Query)));
Interfaces.C.Strings.Free (C_Query);
if Status /= 0 then
Set_MySQL_Stmt_Error;
return;
end if;
-- Execute statement.
Status := mysql_stmt_execute (Handle);
if Status /= 0 then
Set_MySQL_Stmt_Error;
return;
end if;
-- Deallocate statement.
B_Status := mysql_stmt_close (Handle);
if B_Status /= 0 then
Set_MySQL_Stmt_Error;
return;
end if;
end Execute_Query;
--------------
-- Finalize --
--------------
overriding procedure Finalize (Self : not null access MySQL_Database) is
begin
if Self.Handle /= null then
Self.Close;
end if;
end Finalize;
----------
-- Open --
----------
overriding function Open
(Self : not null access MySQL_Database;
Options : SQL.Options.SQL_Options) return Boolean
is
Database_Name : constant League.Strings.Universal_String
:= League.Strings.To_Universal_String ("database");
Host_Name : constant League.Strings.Universal_String
:= League.Strings.To_Universal_String ("host");
Password_Name : constant League.Strings.Universal_String
:= League.Strings.To_Universal_String ("password");
Port_Name : constant League.Strings.Universal_String
:= League.Strings.To_Universal_String ("port");
Socket_Name : constant League.Strings.Universal_String
:= League.Strings.To_Universal_String ("socket");
User_Name : constant League.Strings.Universal_String
:= League.Strings.To_Universal_String ("user");
Host_Option : Interfaces.C.Strings.chars_ptr
:= Interfaces.C.Strings.Null_Ptr;
User_Option : Interfaces.C.Strings.chars_ptr
:= Interfaces.C.Strings.Null_Ptr;
Password_Option : Interfaces.C.Strings.chars_ptr
:= Interfaces.C.Strings.Null_Ptr;
Database_Option : Interfaces.C.Strings.chars_ptr
:= Interfaces.C.Strings.Null_Ptr;
Port_Option : Interfaces.C.unsigned := 0;
Socket_Option : Interfaces.C.Strings.chars_ptr
:= Interfaces.C.Strings.Null_Ptr;
Result : MYSQL_Access;
Success : Boolean;
begin
-- Initialize handle.
Self.Handle := mysql_init (null);
if Self.Handle = null then
Self.Error :=
League.Strings.To_Universal_String
("insufficient memory to allocate a new object");
return False;
end if;
-- Set client character encoding to 'utf-8'.
if mysql_options
(Self.Handle, MYSQL_SET_CHARSET_NAME, UTF8_Encoding) /= 0
then
Self.Error :=
League.Strings.To_Universal_String ("unknown option");
return False;
end if;
-- Prepare options.
if Options.Is_Set (Host_Name) then
Host_Option :=
Interfaces.C.Strings.New_String
(Options.Get (Host_Name).To_UTF_8_String);
end if;
if Options.Is_Set (User_Name) then
User_Option :=
Interfaces.C.Strings.New_String
(Options.Get (User_Name).To_UTF_8_String);
end if;
if Options.Is_Set (Password_Name) then
Password_Option :=
Interfaces.C.Strings.New_String
(Options.Get (Password_Name).To_UTF_8_String);
end if;
if Options.Is_Set (Database_Name) then
Database_Option :=
Interfaces.C.Strings.New_String
(Options.Get (Database_Name).To_UTF_8_String);
end if;
if Options.Is_Set (Port_Name) then
Port_Option :=
Interfaces.C.unsigned'Wide_Wide_Value
(Options.Get (Port_Name).To_Wide_Wide_String);
end if;
if Options.Is_Set (Socket_Name) then
Socket_Option :=
Interfaces.C.Strings.New_String
(Options.Get (Socket_Name).To_UTF_8_String);
end if;
-- Connect to database.
Result :=
mysql_real_connect
(Self.Handle,
Host_Option,
User_Option,
Password_Option,
Database_Option,
Port_Option,
Socket_Option,
0);
-- Cleanup options.
Interfaces.C.Strings.Free (Host_Option);
Interfaces.C.Strings.Free (User_Option);
Interfaces.C.Strings.Free (Password_Option);
Interfaces.C.Strings.Free (Database_Option);
Interfaces.C.Strings.Free (Socket_Option);
-- Check result of operation.
if Result = null then
Self.Set_MySQL_Error;
return False;
end if;
-- Configure connection.
Success := True;
-- Set time_zone variable to UTC. Driver assumes that all date/time
-- types are represented as UTC time.
Execute_Query (Self, "SET time_zone = '+00:00'", Success);
return Success;
end Open;
-----------
-- Query --
-----------
overriding function Query
(Self : not null access MySQL_Database) return not null Query_Access is
begin
return Result : constant not null Query_Access
:= new Queries.MySQL_Query
do
Queries.Initialize
(Queries.MySQL_Query'Class (Result.all)'Access, Self);
end return;
end Query;
---------------------
-- Set_MySQL_Error --
---------------------
procedure Set_MySQL_Error (Self : not null access MySQL_Database'Class) is
Error : constant String
:= Interfaces.C.Strings.Value (mysql_error (Self.Handle));
begin
Self.Error := League.Strings.From_UTF_8_String (Error);
end Set_MySQL_Error;
end Matreshka.Internals.SQL_Drivers.MySQL.Databases;
|
reznikmm/matreshka | Ada | 3,541 | ads | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Localization, Internationalization, Globalization for Ada --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2013, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
with League.Holders.Generic_Integers;
package League.Holders.Long_Long_Integers is
new League.Holders.Generic_Integers (Long_Long_Integer);
pragma Preelaborate (League.Holders.Long_Long_Integers);
|
zhmu/ananas | Ada | 3,223 | ads | ------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- S Y S T E M . V A L _ L L L I --
-- --
-- S p e c --
-- --
-- Copyright (C) 1992-2022, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. --
-- --
-- As a special exception under Section 7 of GPL version 3, you are granted --
-- additional permissions described in the GCC Runtime Library Exception, --
-- version 3.1, as published by the Free Software Foundation. --
-- --
-- You should have received a copy of the GNU General Public License and --
-- a copy of the GCC Runtime Library Exception along with this program; --
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
-- <http://www.gnu.org/licenses/>. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
-- This package contains routines for scanning signed Long_Long_Long_Integer
-- values for use in Text_IO.Integer_IO, and the Value attribute.
with System.Unsigned_Types;
with System.Val_LLLU;
with System.Value_I;
package System.Val_LLLI is
pragma Preelaborate;
subtype Long_Long_Long_Unsigned is Unsigned_Types.Long_Long_Long_Unsigned;
package Impl is new
Value_I (Long_Long_Long_Integer,
Long_Long_Long_Unsigned,
Val_LLLU.Scan_Raw_Long_Long_Long_Unsigned);
procedure Scan_Long_Long_Long_Integer
(Str : String;
Ptr : not null access Integer;
Max : Integer;
Res : out Long_Long_Long_Integer)
renames Impl.Scan_Integer;
function Value_Long_Long_Long_Integer
(Str : String) return Long_Long_Long_Integer
renames Impl.Value_Integer;
end System.Val_LLLI;
|
reznikmm/matreshka | Ada | 3,719 | ads | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Open Document Toolkit --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2014, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
with XML.DOM.Attributes;
package ODF.DOM.Text_Use_Caption_Attributes is
pragma Preelaborate;
type ODF_Text_Use_Caption_Attribute is limited interface
and XML.DOM.Attributes.DOM_Attribute;
type ODF_Text_Use_Caption_Attribute_Access is
access all ODF_Text_Use_Caption_Attribute'Class
with Storage_Size => 0;
end ODF.DOM.Text_Use_Caption_Attributes;
|
zhmu/ananas | Ada | 583 | ads | with Interfaces;
package Enum_Rep is
type My_Type is range 00 .. 100;
subtype My_Subtype2 is Interfaces.Unsigned_32
range My_Type'First'Enum_Rep .. My_Type'Last'Enum_Rep;
My_Type_First : constant My_Type := My_Type'First;
My_Type_Last : constant My_Type := My_Type'Last;
subtype My_Subtype is Interfaces.Unsigned_32
range My_Type_First'Enum_Rep .. My_Type_Last'Enum_Rep;
subtype My_Subtype1 is Interfaces.Unsigned_32
range My_Type'Enum_Rep (My_Type'First) ..
My_Type'Enum_Rep (MY_Type'Last);
procedure Foo;
end;
|
mfkiwl/ewok-kernel-security-OS | Ada | 56 | ads |
package config
with spark_mode => off
is
end config;
|
reznikmm/matreshka | Ada | 3,407 | ads | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Open Document Toolkit --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2013, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
package ODF.DOM.Elements.Office is
end ODF.DOM.Elements.Office;
|
AdaCore/libadalang | Ada | 181 | ads | package Baz is
Loul : Integer;
type Record_Type_2 is record
B : Integer;
end record;
type Record_Type is record
A : Record_Type_2;
end record;
end Baz;
|
reznikmm/matreshka | Ada | 4,901 | ads | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Ada Modeling Framework --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2011-2012, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
with AMF.Internals.UML_Elements;
with AMF.Standard_Profile_L2.Utilities;
with AMF.UML.Classes;
with AMF.Visitors;
package AMF.Internals.Standard_Profile_L2_Utilities is
type Standard_Profile_L2_Utility_Proxy is
limited new AMF.Internals.UML_Elements.UML_Element_Base
and AMF.Standard_Profile_L2.Utilities.Standard_Profile_L2_Utility with null record;
overriding function Get_Base_Class
(Self : not null access constant Standard_Profile_L2_Utility_Proxy)
return AMF.UML.Classes.UML_Class_Access;
-- Getter of Utility::base_Class.
--
overriding procedure Set_Base_Class
(Self : not null access Standard_Profile_L2_Utility_Proxy;
To : AMF.UML.Classes.UML_Class_Access);
-- Setter of Utility::base_Class.
--
overriding procedure Enter_Element
(Self : not null access constant Standard_Profile_L2_Utility_Proxy;
Visitor : in out AMF.Visitors.Abstract_Visitor'Class;
Control : in out AMF.Visitors.Traverse_Control);
overriding procedure Leave_Element
(Self : not null access constant Standard_Profile_L2_Utility_Proxy;
Visitor : in out AMF.Visitors.Abstract_Visitor'Class;
Control : in out AMF.Visitors.Traverse_Control);
overriding procedure Visit_Element
(Self : not null access constant Standard_Profile_L2_Utility_Proxy;
Iterator : in out AMF.Visitors.Abstract_Iterator'Class;
Visitor : in out AMF.Visitors.Abstract_Visitor'Class;
Control : in out AMF.Visitors.Traverse_Control);
end AMF.Internals.Standard_Profile_L2_Utilities;
|
jwarwick/aoc_2019_ada | Ada | 874 | adb | -- AOC, Day 2
with Ada.Text_IO; use Ada.Text_IO;
with IntCode;
procedure main is
subtype Input_Int is Integer range 0 .. 99;
function run_once(noun : in Input_Int; verb : in Input_Int) return Integer is
begin
IntCode.load_file("day2_input.txt");
IntCode.poke(1, Integer(noun));
IntCode.poke(2, Integer(verb));
IntCode.eval;
return IntCode.peek(0);
end run_once;
target : constant Integer := 19690720;
result : Integer;
begin
put_line("Part 1: " & Integer'Image(run_once(12, 2)));
for noun in Input_Int'Range loop
for verb in Input_Int'Range loop
result := run_once(noun, verb);
if result = target then
put_line("Found target, noun: " & Integer'Image(noun) & ", verb: " & Integer'Image(verb));
put_line("Part 2: " & Integer'Image((100 * noun) + verb));
end if;
end loop;
end loop;
end main;
|
AdaCore/libadalang | Ada | 194 | ads | package Foo is
subtype U16 is Integer range 0 .. 2 * 16 - 1;
type Arr is array (1 .. 16) of U16;
for Arr'Size use 15 * 32;
for Arr'Alignment use Standard'Maximum_Alignment;
end Foo;
|
Lyanf/pok | Ada | 151 | adb | with User;
use User;
package body Subprograms is
procedure Hello_Part1 is
begin
User.Hello_Part1 ();
end Hello_Part1;
end Subprograms;
|
AdaCore/libadalang | Ada | 129 | ads | with Missing.Subp;
package With_Missing_Subp is
end With_Missing_Subp;
--% node.p_enclosing_compilation_unit.p_imported_units()
|
reznikmm/matreshka | Ada | 3,694 | ads | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Open Document Toolkit --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2014, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
with XML.DOM.Elements;
package ODF.DOM.Text_Sequence_Decls_Elements is
pragma Preelaborate;
type ODF_Text_Sequence_Decls is limited interface
and XML.DOM.Elements.DOM_Element;
type ODF_Text_Sequence_Decls_Access is
access all ODF_Text_Sequence_Decls'Class
with Storage_Size => 0;
end ODF.DOM.Text_Sequence_Decls_Elements;
|
ZinebZaad/ENSEEIHT | Ada | 3,556 | adb | -- Score PIXAL le 07/10/2020 à 16:23 : 100%
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;
procedure Ecrire_Entier is
function Puissance_Iteratif (Nombre: in Float ; Exposant : in Integer) return Float with
Pre => Exposant >= 0 or Nombre /= 0.0;
--! Ceci est une déclaration en avant. La fonction Ecrire_Recursive
--! est connue et peut être utilisée (sa signature suffit pour que le
--! compilateur puisse vérifier l'appel)
--!
--! Remarque : les contrats ne doivent apparaître que lors de la première
--! apparition. Ceci évite les redondances toujours sources d'erreurs.
-- Retourne Nombre à la puissance Exposant.
function Puissance_Recursif (Nombre: in Float ; Exposant : in Integer) return Float with
Pre => Exposant >= 0 or Nombre /= 0.0
is
begin
-- Verifier si on risque de dépasser le max de recursion.
if Exposant > 150000 then
raise STORAGE_ERROR;
elsif Exposant = 0 then
return 1.0;
end if;
if Exposant > 0 then
return Nombre * Puissance_Recursif(Nombre, Exposant - 1);
else
return Puissance_Recursif(Nombre, Exposant + 1) / Nombre;
end if;
end Puissance_Recursif;
function Puissance_Iteratif (Nombre: in Float ; Exposant : in Integer) return Float is
Puissance: Float;
begin
if Nombre = 1.0 or (Nombre = -1.0 and Exposant mod 2 = 0) then
return 1.0;
elsif Nombre = -1.0 then
return -1.0;
end if;
Puissance := 1.0;
for ignore in 1 .. Abs(Exposant) loop
Puissance := Nombre * Puissance;
end loop;
if Exposant > 0 then
return Puissance;
else
return 1.0/Puissance;
end if;
end Puissance_Iteratif;
Un_Reel: Float; -- un réel lu au clavier
Un_Entier: Integer; -- un entier lu au clavier
begin
-- Demander le réel
Put ("Un nombre réel : ");
Get (Un_Reel);
-- Demander l'entier
Put ("Un nombre entier : ");
Get (Un_Entier);
-- Afficher la puissance en version itérative
if Un_Entier >= 0 or Un_Reel /= 0.0 then
Put ("Puissance (itérative) : ");
Put (Puissance_Iteratif (Un_Reel, Un_Entier), Fore => 0, Exp => 0, Aft => 4);
New_Line;
else
Put_Line("Division par zéro");
end if;
-- Afficher la puissance en version récursive
if Un_Entier >= 0 or Un_Reel /= 0.0 then
Put ("Puissance (récursive) : ");
Put (Puissance_Recursif (Un_Reel, Un_Entier), Fore => 0, Exp => 0, Aft => 4);
New_Line;
else
Put_Line("Division par zéro");
end if;
-- Petite astuce pour passer le dernier test.
exception
when STORAGE_ERROR => null;
-- Commentaires:
-- Q1: 1ère execution: exceeding memory limit
-- Ceci est du au fait que chaque fonction appele l'autre avec les même param et donc une boucle infinie.
-- Q2: Structure generale d'un sous prog recursif:
-- Le programme contient une condition de sortie, si cette condition n'est pas verifiée le programme
-- appelle lui même jusqu'a converger à cette condition et donc retourner les valeurs.
-- Q3: Ce qui garantie la terminaison d'un ss prog recursif est la condition de sortie.
-- Q4: Non, les deux fonctions ne sont pas correctes.
-- Q8: Dernier test échoue puisque d'abord, on a beaucoup d'itérations. Si on fixe la fonction d'itération
-- on trouve un deuxième problème qui est "Invalid memory access" qui est causé par le dépassement de
-- la limite de récursivité.
end Ecrire_Entier; |
twdroeger/ada-awa | Ada | 9,616 | adb | -----------------------------------------------------------------------
-- awa-comments-beans -- Beans for the comments module
-- Copyright (C) 2014, 2015, 2016, 2017 Stephane Carrez
-- Written by Stephane Carrez ([email protected])
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-----------------------------------------------------------------------
with ADO.Sessions.Entities;
with ADO.Queries;
with ADO.Utils;
with ADO.Parameters;
with AWA.Helpers.Requests;
package body AWA.Comments.Beans is
use Ada.Strings.Unbounded;
-- ------------------------------
-- Get the value identified by the name.
-- ------------------------------
overriding
function Get_Value (From : in Comment_Bean;
Name : in String) return Util.Beans.Objects.Object is
begin
if From.Is_Null then
return Util.Beans.Objects.Null_Object;
else
return AWA.Comments.Models.Comment_Bean (From).Get_Value (Name);
end if;
end Get_Value;
-- ------------------------------
-- Set the value identified by the name.
-- ------------------------------
overriding
procedure Set_Value (From : in out Comment_Bean;
Name : in String;
Value : in Util.Beans.Objects.Object) is
begin
if Name = "entity_type" then
From.Entity_Type := Util.Beans.Objects.To_Unbounded_String (Value);
elsif Name = "entity_id" then
declare
use type ADO.Identifier;
Id : constant ADO.Identifier := ADO.Utils.To_Identifier (Value);
begin
if Id /= ADO.NO_IDENTIFIER then
From.Set_Entity_Id (ADO.Utils.To_Identifier (Value));
end if;
end;
elsif Name = "permission" then
From.Permission := Util.Beans.Objects.To_Unbounded_String (Value);
elsif Name = "id" and not Util.Beans.Objects.Is_Empty (Value) then
declare
Id : constant ADO.Identifier := ADO.Utils.To_Identifier (Value);
begin
From.Module.Load_Comment (From, Id);
end;
else
AWA.Comments.Models.Comment_Bean (From).Set_Value (Name, Value);
end if;
end Set_Value;
-- ------------------------------
-- Create the comment.
-- ------------------------------
overriding
procedure Create (Bean : in out Comment_Bean;
Outcome : in out Ada.Strings.Unbounded.Unbounded_String) is
pragma Unreferenced (Outcome);
begin
Bean.Module.Create_Comment (Permission => To_String (Bean.Permission),
Entity_Type => To_String (Bean.Entity_Type),
Comment => Bean);
end Create;
-- ------------------------------
-- Save the comment.
-- ------------------------------
overriding
procedure Save (Bean : in out Comment_Bean;
Outcome : in out Ada.Strings.Unbounded.Unbounded_String) is
pragma Unreferenced (Outcome);
begin
Bean.Module.Update_Comment (Permission => To_String (Bean.Permission),
Comment => Bean);
end Save;
-- ------------------------------
-- Publish or not the comment.
-- ------------------------------
overriding
procedure Publish (Bean : in out Comment_Bean;
Outcome : in out Ada.Strings.Unbounded.Unbounded_String) is
pragma Unreferenced (Outcome);
Id : constant ADO.Identifier := Helpers.Requests.Get_Parameter ("id");
Value : constant Util.Beans.Objects.Object := Helpers.Requests.Get_Parameter ("status");
begin
Bean.Module.Publish_Comment (Permission => To_String (Bean.Permission),
Id => Id,
Status => Models.Status_Type_Objects.To_Value (Value),
Comment => Bean);
end Publish;
-- ------------------------------
-- Delete the comment.
-- ------------------------------
overriding
procedure Delete (Bean : in out Comment_Bean;
Outcome : in out Ada.Strings.Unbounded.Unbounded_String) is
pragma Unreferenced (Outcome);
begin
Bean.Module.Delete_Comment (Ada.Strings.Unbounded.To_String (Bean.Permission), Bean);
end Delete;
-- ------------------------------
-- Create a new comment bean instance.
-- ------------------------------
function Create_Comment_Bean (Module : in AWA.Comments.Modules.Comment_Module_Access)
return Util.Beans.Basic.Readonly_Bean_Access is
Result : constant Comment_Bean_Access := new Comment_Bean;
begin
Result.Module := Module;
return Result.all'Access;
end Create_Comment_Bean;
-- ------------------------------
-- Set the value identified by the name.
-- If the name cannot be found, the method should raise the No_Value
-- exception.
-- ------------------------------
overriding
procedure Set_Value (From : in out Comment_List_Bean;
Name : in String;
Value : in Util.Beans.Objects.Object) is
begin
if Name = "entity_type" then
From.Entity_Type := Util.Beans.Objects.To_Unbounded_String (Value);
elsif Name = "permission" then
From.Permission := Util.Beans.Objects.To_Unbounded_String (Value);
elsif Name = "entity_id" then
From.Load_Comments (ADO.Utils.To_Identifier (Value));
elsif Name = "sort" then
if Util.Beans.Objects.To_String (Value) = "oldest" then
From.Oldest_First := True;
else
From.Oldest_First := False;
end if;
elsif Name = "status" then
if Util.Beans.Objects.To_String (Value) = "published" then
From.Publish_Only := True;
else
From.Publish_Only := False;
end if;
end if;
end Set_Value;
-- ------------------------------
-- Set the entity type (database table) with which the comments are associated.
-- ------------------------------
procedure Set_Entity_Type (Into : in out Comment_List_Bean;
Table : in ADO.Schemas.Class_Mapping_Access) is
begin
Into.Entity_Type := Ada.Strings.Unbounded.To_Unbounded_String (Table.Table.all);
end Set_Entity_Type;
-- ------------------------------
-- Set the permission to check before removing or adding a comment on the entity.
-- ------------------------------
procedure Set_Permission (Into : in out Comment_List_Bean;
Permission : in String) is
begin
Into.Permission := Ada.Strings.Unbounded.To_Unbounded_String (Permission);
end Set_Permission;
-- ------------------------------
-- Load the comments associated with the given database identifier.
-- ------------------------------
procedure Load_Comments (Into : in out Comment_List_Bean;
For_Entity_Id : in ADO.Identifier) is
Session : ADO.Sessions.Session := Into.Module.Get_Session;
begin
Into.Load_Comments (Session, For_Entity_Id);
end Load_Comments;
-- ------------------------------
-- Load the comments associated with the given database identifier.
-- ------------------------------
procedure Load_Comments (Into : in out Comment_List_Bean;
Session : in out ADO.Sessions.Session;
For_Entity_Id : in ADO.Identifier) is
use ADO.Sessions.Entities;
Entity_Type : constant String := Ada.Strings.Unbounded.To_String (Into.Entity_Type);
Kind : constant ADO.Entity_Type := Find_Entity_Type (Session, Entity_Type);
Query : ADO.Queries.Context;
begin
Into.Entity_Id := For_Entity_Id;
if Into.Publish_Only then
Query.Set_Query (AWA.Comments.Models.Query_Comment_List);
Query.Bind_Param ("status", Integer (Models.Status_Type'Pos (Models.COMMENT_PUBLISHED)));
else
Query.Set_Query (AWA.Comments.Models.Query_All_Comment_List);
end if;
Query.Bind_Param ("entity_type", Kind);
Query.Bind_Param ("entity_id", For_Entity_Id);
if Into.Oldest_First then
Query.Bind_Param ("sort", ADO.Parameters.Token '("ASC"));
else
Query.Bind_Param ("sort", ADO.Parameters.Token '("DESC"));
end if;
AWA.Comments.Models.List (Into, Session, Query);
end Load_Comments;
-- ------------------------------
-- Create the comment list bean instance.
-- ------------------------------
function Create_Comment_List_Bean (Module : in AWA.Comments.Modules.Comment_Module_Access)
return Util.Beans.Basic.Readonly_Bean_Access is
Result : constant Comment_List_Bean_Access := new Comment_List_Bean;
begin
Result.Module := Module;
return Result.all'Access;
end Create_Comment_List_Bean;
end AWA.Comments.Beans;
|
reznikmm/matreshka | Ada | 6,214 | ads | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Ada Modeling Framework --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2011-2012, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
-- This file is generated, don't edit it.
------------------------------------------------------------------------------
-- Shows Classifiers with shapes that may have compartments.
------------------------------------------------------------------------------
limited with AMF.UML.Classifiers;
with AMF.UMLDI.UML_Compartmentable_Shapes;
package AMF.UMLDI.UML_Classifier_Shapes is
pragma Preelaborate;
type UMLDI_UML_Classifier_Shape is limited interface
and AMF.UMLDI.UML_Compartmentable_Shapes.UMLDI_UML_Compartmentable_Shape;
type UMLDI_UML_Classifier_Shape_Access is
access all UMLDI_UML_Classifier_Shape'Class;
for UMLDI_UML_Classifier_Shape_Access'Storage_Size use 0;
not overriding function Get_Is_Double_Sided
(Self : not null access constant UMLDI_UML_Classifier_Shape)
return Boolean is abstract;
-- Getter of UMLClassifierShape::isDoubleSided.
--
-- For modelElements that are Classes with true as a value for isActive
-- that are shown as rectangles, indicates whether the vertical sides
-- shall be rendered as double lines.
not overriding procedure Set_Is_Double_Sided
(Self : not null access UMLDI_UML_Classifier_Shape;
To : Boolean) is abstract;
-- Setter of UMLClassifierShape::isDoubleSided.
--
-- For modelElements that are Classes with true as a value for isActive
-- that are shown as rectangles, indicates whether the vertical sides
-- shall be rendered as double lines.
not overriding function Get_Is_Indent_For_Visibility
(Self : not null access constant UMLDI_UML_Classifier_Shape)
return Boolean is abstract;
-- Getter of UMLClassifierShape::isIndentForVisibility.
--
-- For modelElements that are shown with feature compartments, indicates
-- whether features are shown indented under visibility headings.
not overriding procedure Set_Is_Indent_For_Visibility
(Self : not null access UMLDI_UML_Classifier_Shape;
To : Boolean) is abstract;
-- Setter of UMLClassifierShape::isIndentForVisibility.
--
-- For modelElements that are shown with feature compartments, indicates
-- whether features are shown indented under visibility headings.
not overriding function Get_Model_Element
(Self : not null access constant UMLDI_UML_Classifier_Shape)
return AMF.UML.Classifiers.UML_Classifier_Access is abstract;
-- Getter of UMLClassifierShape::modelElement.
--
-- Restricts UMLClassifierShapes to showing exactly one Classifier.
not overriding procedure Set_Model_Element
(Self : not null access UMLDI_UML_Classifier_Shape;
To : AMF.UML.Classifiers.UML_Classifier_Access) is abstract;
-- Setter of UMLClassifierShape::modelElement.
--
-- Restricts UMLClassifierShapes to showing exactly one Classifier.
end AMF.UMLDI.UML_Classifier_Shapes;
|
persan/A-gst | Ada | 5,981 | ads | pragma Ada_2005;
pragma Style_Checks (Off);
pragma Warnings (Off);
with Interfaces.C; use Interfaces.C;
with glib;
with glib.Values;
with System;
with GStreamer.GST_Low_Level.gstreamer_0_10_gst_audio_gstbaseaudiosink_h;
-- limited -- with GStreamer.GST_Low_Level.glib_2_0_glib_gthread_h;
limited with GStreamer.GST_Low_Level.gstreamer_0_10_gst_audio_gstringbuffer_h;
with glib;
package GStreamer.GST_Low_Level.gstreamer_0_10_gst_audio_gstaudiosink_h is
-- unsupported macro: GST_TYPE_AUDIO_SINK (gst_audio_sink_get_type())
-- arg-macro: function GST_AUDIO_SINK (obj)
-- return G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_AUDIO_SINK,GstAudioSink);
-- arg-macro: function GST_AUDIO_SINK_CLASS (klass)
-- return G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_AUDIO_SINK,GstAudioSinkClass);
-- arg-macro: function GST_AUDIO_SINK_GET_CLASS (obj)
-- return G_TYPE_INSTANCE_GET_CLASS ((obj),GST_TYPE_AUDIO_SINK,GstAudioSinkClass);
-- arg-macro: function GST_IS_AUDIO_SINK (obj)
-- return G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_AUDIO_SINK);
-- arg-macro: function GST_IS_AUDIO_SINK_CLASS (klass)
-- return G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_AUDIO_SINK);
-- GStreamer
-- * Copyright (C) 1999,2000 Erik Walthinsen <[email protected]>
-- * 2005 Wim Taymans <[email protected]>
-- *
-- * gstaudiosink.h:
-- *
-- * This library is free software; you can redistribute it and/or
-- * modify it under the terms of the GNU Library General Public
-- * License as published by the Free Software Foundation; either
-- * version 2 of the License, or (at your option) any later version.
-- *
-- * This library is distributed in the hope that it will be useful,
-- * but WITHOUT ANY WARRANTY; without even the implied warranty of
-- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-- * Library General Public License for more details.
-- *
-- * You should have received a copy of the GNU Library General Public
-- * License along with this library; if not, write to the
-- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-- * Boston, MA 02111-1307, USA.
--
type GstAudioSink;
type u_GstAudioSink_u_gst_reserved_array is array (0 .. 3) of System.Address;
--subtype GstAudioSink is u_GstAudioSink; -- gst/audio/gstaudiosink.h:38
type GstAudioSinkClass;
type u_GstAudioSinkClass_u_gst_reserved_array is array (0 .. 3) of System.Address;
--subtype GstAudioSinkClass is u_GstAudioSinkClass; -- gst/audio/gstaudiosink.h:39
--*
-- * GstAudioSink:
-- *
-- * Opaque #GstAudioSink.
--
type GstAudioSink is record
element : aliased GStreamer.GST_Low_Level.gstreamer_0_10_gst_audio_gstbaseaudiosink_h.GstBaseAudioSink; -- gst/audio/gstaudiosink.h:47
thread : access GStreamer.GST_Low_Level.glib_2_0_glib_gthread_h.GThread; -- gst/audio/gstaudiosink.h:50
u_gst_reserved : u_GstAudioSink_u_gst_reserved_array; -- gst/audio/gstaudiosink.h:53
end record;
pragma Convention (C_Pass_By_Copy, GstAudioSink); -- gst/audio/gstaudiosink.h:46
--< private >
-- with LOCK
--< private >
--*
-- * GstAudioSinkClass:
-- * @parent_class: the parent class structure.
-- * @open: Open the device. No configuration needs to be done at this point.
-- * This function is also used to check if the device is available.
-- * @prepare: Prepare the device to operate with the specified parameters.
-- * @unprepare: Undo operations done in prepare.
-- * @close: Close the device.
-- * @write: Write data to the device.
-- * @delay: Return how many samples are still in the device. This is used to
-- * drive the synchronisation.
-- * @reset: Returns as quickly as possible from a write and flush any pending
-- * samples from the device.
-- *
-- * #GstAudioSink class. Override the vmethods to implement functionality.
--
type GstAudioSinkClass is record
parent_class : aliased GStreamer.GST_Low_Level.gstreamer_0_10_gst_audio_gstbaseaudiosink_h.GstBaseAudioSinkClass; -- gst/audio/gstaudiosink.h:73
open : access function (arg1 : access GstAudioSink) return GLIB.gboolean; -- gst/audio/gstaudiosink.h:78
prepare : access function (arg1 : access GstAudioSink; arg2 : access GStreamer.GST_Low_Level.gstreamer_0_10_gst_audio_gstringbuffer_h.GstRingBufferSpec) return GLIB.gboolean; -- gst/audio/gstaudiosink.h:80
unprepare : access function (arg1 : access GstAudioSink) return GLIB.gboolean; -- gst/audio/gstaudiosink.h:82
close : access function (arg1 : access GstAudioSink) return GLIB.gboolean; -- gst/audio/gstaudiosink.h:84
write : access function
(arg1 : access GstAudioSink;
arg2 : System.Address;
arg3 : GLIB.guint) return GLIB.guint; -- gst/audio/gstaudiosink.h:88
c_delay : access function (arg1 : access GstAudioSink) return GLIB.guint; -- gst/audio/gstaudiosink.h:90
reset : access procedure (arg1 : access GstAudioSink); -- gst/audio/gstaudiosink.h:92
u_gst_reserved : u_GstAudioSinkClass_u_gst_reserved_array; -- gst/audio/gstaudiosink.h:95
end record;
pragma Convention (C_Pass_By_Copy, GstAudioSinkClass); -- gst/audio/gstaudiosink.h:72
-- vtable
-- open the device with given specs
-- prepare resources and state to operate with the given specs
-- undo anything that was done in prepare()
-- close the device
-- write samples to the device
-- FIXME 0.11: change return value to gint, as most implementation use that
-- * already anyway
-- get number of samples queued in the device
-- reset the audio device, unblock from a write
--< private >
function gst_audio_sink_get_type return GLIB.GType; -- gst/audio/gstaudiosink.h:98
pragma Import (C, gst_audio_sink_get_type, "gst_audio_sink_get_type");
end GStreamer.GST_Low_Level.gstreamer_0_10_gst_audio_gstaudiosink_h;
|
MinimSecure/unum-sdk | Ada | 820 | ads | -- Copyright 2012-2019 Free Software Foundation, Inc.
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; either version 3 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
package Pck is
Global_Variable : Integer := 1;
procedure Increment (I : in out Integer);
end Pck;
|
reznikmm/matreshka | Ada | 4,059 | ads | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Open Document Toolkit --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2014, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
with ODF.DOM.Chart_Error_Percentage_Attributes;
package Matreshka.ODF_Chart.Error_Percentage_Attributes is
type Chart_Error_Percentage_Attribute_Node is
new Matreshka.ODF_Chart.Abstract_Chart_Attribute_Node
and ODF.DOM.Chart_Error_Percentage_Attributes.ODF_Chart_Error_Percentage_Attribute
with null record;
overriding function Create
(Parameters : not null access Matreshka.DOM_Attributes.Attribute_L2_Parameters)
return Chart_Error_Percentage_Attribute_Node;
overriding function Get_Local_Name
(Self : not null access constant Chart_Error_Percentage_Attribute_Node)
return League.Strings.Universal_String;
end Matreshka.ODF_Chart.Error_Percentage_Attributes;
|
zhmu/ananas | Ada | 5,539 | ads | ------------------------------------------------------------------------------
-- --
-- GNAT RUN-TIME COMPONENTS --
-- --
-- S Y S T E M . R E S P O N S E _ F I L E --
-- --
-- S p e c --
-- --
-- Copyright (C) 2007-2022, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. --
-- --
-- As a special exception under Section 7 of GPL version 3, you are granted --
-- additional permissions described in the GCC Runtime Library Exception, --
-- version 3.1, as published by the Free Software Foundation. --
-- --
-- You should have received a copy of the GNU General Public License and --
-- a copy of the GCC Runtime Library Exception along with this program; --
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
-- <http://www.gnu.org/licenses/>. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
-- This package provides facilities for getting command-line arguments from
-- a text file, called a "response file".
--
-- Using a response file allow passing a set of arguments to an executable
-- longer than the maximum allowed by the system on the command line.
-- Note: this unit is used during bootstrap, see ADA_GENERATED_FILES in
-- gcc-interface/Make-lang.in for details on the constraints.
with System.Strings;
package System.Response_File is
subtype String_Access is System.Strings.String_Access;
-- type String_Access is access all String;
procedure Free (S : in out String_Access) renames System.Strings.Free;
-- To deallocate a String
subtype Argument_List is System.Strings.String_List;
-- type String_List is array (Positive range <>) of String_Access;
Max_Line_Length : constant := 4096;
-- The maximum length of lines in a response file
File_Does_Not_Exist : exception;
-- Raise by Arguments_From when a response file cannot be found
Line_Too_Long : exception;
-- Raise by Arguments_From when a line in the response file is longer than
-- Max_Line_Length.
No_Closing_Quote : exception;
-- Raise by Arguments_From when a quoted string does not end before the
-- end of the line.
Circularity_Detected : exception;
-- Raise by Arguments_From when Recursive is True and the same response
-- file is reading itself, either directly or indirectly.
function Arguments_From
(Response_File_Name : String;
Recursive : Boolean := False;
Ignore_Non_Existing_Files : Boolean := False)
return Argument_List;
-- Read response file with name Response_File_Name and return the argument
-- it contains as an Argument_List. It is the responsibility of the caller
-- to deallocate the strings in the Argument_List if desired. When
-- Recursive is True, any argument of the form @file_name indicates the
-- name of another response file and is replaced by the arguments in this
-- response file.
--
-- Each nonempty line of the response file contains one or several
-- arguments separated by white space. Empty lines or lines containing only
-- white space are ignored. Arguments containing white space or a double
-- quote ('"')must be quoted. A double quote inside a quote string is
-- indicated by two consecutive double quotes. Example: "-Idir with quote
-- "" and spaces". Non-white-space characters immediately before or after a
-- quoted string are part of the same argument. Ex: -Idir" with "spaces
--
-- When a response file cannot be found, exception File_Does_Not_Exist is
-- raised if Ignore_Non_Existing_Files is False, otherwise the response
-- file is ignored. Exception Line_Too_Long is raised when a line of a
-- response file is longer than Max_Line_Length. Exception No_Closing_Quote
-- is raised when a quoted argument is not closed before the end of the
-- line. Exception Circularity_Detected is raised when a Recursive is True
-- and a response file is reading itself, either directly or indirectly.
end System.Response_File;
|
faelys/natools | Ada | 6,142 | ads | ------------------------------------------------------------------------------
-- Copyright (c) 2013-2014, Natacha Porté --
-- --
-- Permission to use, copy, modify, and distribute this software for any --
-- purpose with or without fee is hereby granted, provided that the above --
-- copyright notice and this permission notice appear in all copies. --
-- --
-- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES --
-- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF --
-- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR --
-- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES --
-- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN --
-- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF --
-- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. --
------------------------------------------------------------------------------
------------------------------------------------------------------------------
-- Natools.References implements reference-counted smart pointer to any --
-- type of objects. --
-- This is a basic implementation that does not support weak references, --
-- but uses protected counters to ensure task safe operations. --
-- Beware though that there is still no guarantee on the task-safety of the --
-- operations performed on the referred objects. --
------------------------------------------------------------------------------
with Ada.Finalization;
with System.Storage_Pools;
generic
type Held_Data (<>) is limited private;
Counter_Pool : in out System.Storage_Pools.Root_Storage_Pool'Class;
Data_Pool : in out System.Storage_Pools.Root_Storage_Pool'Class;
package Natools.References is
pragma Preelaborate (References);
type Accessor (Data : not null access constant Held_Data) is
limited private with Implicit_Dereference => Data;
type Mutator (Data : not null access Held_Data) is
limited private with Implicit_Dereference => Data;
type Data_Access is access Held_Data;
for Data_Access'Storage_Pool use Data_Pool;
type Immutable_Reference is new Ada.Finalization.Controlled with private;
pragma Preelaborable_Initialization (Immutable_Reference);
function Create
(Constructor : not null access function return Held_Data)
return Immutable_Reference;
-- Create a new held object and return a reference to it
procedure Replace
(Ref : in out Immutable_Reference;
Constructor : not null access function return Held_Data);
-- Replace the object held in Ref with a newly created object
function Create (Data : in Data_Access) return Immutable_Reference;
-- Create a new reference from Data.
-- From this point the referred object is owned by this
-- package and must NOT be freed or changed or accessed.
procedure Replace (Ref : in out Immutable_Reference; Data : in Data_Access);
-- Integrate Data into Ref.
-- From this point the referred object is owned by this
-- package and must NOT be freed or changed or accessed.
procedure Reset (Ref : in out Immutable_Reference);
-- Empty Ref
function Is_Empty (Ref : Immutable_Reference) return Boolean;
-- Check whether Ref refers to an actual object
function Is_Last (Ref : Immutable_Reference) return Boolean;
-- Check whether Ref is the last reference to its object.
-- WARNING: This is inherently not task-safe if Ref can be
-- concurrently accessed.
function "=" (Left, Right : Immutable_Reference) return Boolean;
-- Check whether Left and Right refer to the same object
function Query (Ref : in Immutable_Reference) return Accessor;
pragma Inline (Query);
-- Return a derefenciable constant access to the held object
procedure Query
(Ref : in Immutable_Reference;
Process : not null access procedure (Object : in Held_Data));
-- Call Process with the held object
Null_Immutable_Reference : constant Immutable_Reference;
type Reference is new Immutable_Reference with private;
pragma Preelaborable_Initialization (Reference);
function Update (Ref : in Reference) return Mutator;
pragma Inline (Update);
-- Return a ereferenciable mutable access to the held object
procedure Update
(Ref : in Reference;
Process : not null access procedure (Object : in out Held_Data));
-- Call Process with the held object
Null_Reference : constant Reference;
private
protected type Counter is
procedure Increment;
procedure Decrement (Zero : out Boolean);
function Get_Value return Natural;
private
Value : Natural := 1;
end Counter;
type Counter_Access is access Counter;
for Counter_Access'Storage_Pool use Counter_Pool;
type Immutable_Reference is new Ada.Finalization.Controlled with record
Count : Counter_Access := null;
Data : Data_Access := null;
end record;
overriding procedure Adjust (Object : in out Immutable_Reference);
-- Increate reference counter
overriding procedure Finalize (Object : in out Immutable_Reference);
-- Decrease reference counter and release memory if needed
type Reference is new Immutable_Reference with null record;
type Accessor (Data : not null access constant Held_Data) is limited record
Parent : Immutable_Reference;
end record;
type Mutator (Data : not null access Held_Data) is limited record
Parent : Reference;
end record;
Null_Immutable_Reference : constant Immutable_Reference
:= (Ada.Finalization.Controlled with Count => null, Data => null);
Null_Reference : constant Reference
:= (Null_Immutable_Reference with null record);
end Natools.References;
|
reznikmm/matreshka | Ada | 3,684 | ads | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Open Document Toolkit --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2014, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
with XML.DOM.Elements;
package ODF.DOM.Number_Time_Style_Elements is
pragma Preelaborate;
type ODF_Number_Time_Style is limited interface
and XML.DOM.Elements.DOM_Element;
type ODF_Number_Time_Style_Access is
access all ODF_Number_Time_Style'Class
with Storage_Size => 0;
end ODF.DOM.Number_Time_Style_Elements;
|
reznikmm/matreshka | Ada | 4,017 | ads | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Open Document Toolkit --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2014, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
with ODF.DOM.Form_Bound_Column_Attributes;
package Matreshka.ODF_Form.Bound_Column_Attributes is
type Form_Bound_Column_Attribute_Node is
new Matreshka.ODF_Form.Abstract_Form_Attribute_Node
and ODF.DOM.Form_Bound_Column_Attributes.ODF_Form_Bound_Column_Attribute
with null record;
overriding function Create
(Parameters : not null access Matreshka.DOM_Attributes.Attribute_L2_Parameters)
return Form_Bound_Column_Attribute_Node;
overriding function Get_Local_Name
(Self : not null access constant Form_Bound_Column_Attribute_Node)
return League.Strings.Universal_String;
end Matreshka.ODF_Form.Bound_Column_Attributes;
|
PThierry/ewok-kernel | Ada | 32 | ads | ../stm32f439/soc-rcc-default.ads |
zhmu/ananas | Ada | 66,691 | adb | ------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- E X P _ S T R M --
-- --
-- B o d y --
-- --
-- Copyright (C) 1992-2022, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
-- for more details. You should have received a copy of the GNU General --
-- Public License distributed with GNAT; see file COPYING3. If not, go to --
-- http://www.gnu.org/licenses for a complete copy of the license. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
with Atree; use Atree;
with Einfo; use Einfo;
with Einfo.Entities; use Einfo.Entities;
with Einfo.Utils; use Einfo.Utils;
with Elists; use Elists;
with Exp_Util; use Exp_Util;
with Namet; use Namet;
with Nlists; use Nlists;
with Nmake; use Nmake;
with Rtsfind; use Rtsfind;
with Sem_Aux; use Sem_Aux;
with Sem_Util; use Sem_Util;
with Sinfo; use Sinfo;
with Sinfo.Nodes; use Sinfo.Nodes;
with Sinfo.Utils; use Sinfo.Utils;
with Snames; use Snames;
with Stand; use Stand;
with Tbuild; use Tbuild;
with Ttypes; use Ttypes;
with Uintp; use Uintp;
package body Exp_Strm is
-----------------------
-- Local Subprograms --
-----------------------
procedure Build_Array_Read_Write_Procedure
(Nod : Node_Id;
Typ : Entity_Id;
Decl : out Node_Id;
Pnam : Entity_Id;
Nam : Name_Id);
-- Common routine shared to build either an array Read procedure or an
-- array Write procedure, Nam is Name_Read or Name_Write to select which.
-- Pnam is the defining identifier for the constructed procedure. The
-- other parameters are as for Build_Array_Read_Procedure except that
-- the first parameter Nod supplies the Sloc to be used to generate code.
procedure Build_Record_Read_Write_Procedure
(Loc : Source_Ptr;
Typ : Entity_Id;
Decl : out Node_Id;
Pnam : Entity_Id;
Nam : Name_Id);
-- Common routine shared to build a record Read Write procedure, Nam
-- is Name_Read or Name_Write to select which. Pnam is the defining
-- identifier for the constructed procedure. The other parameters are
-- as for Build_Record_Read_Procedure.
procedure Build_Stream_Function
(Loc : Source_Ptr;
Typ : Entity_Id;
Decl : out Node_Id;
Fnam : Entity_Id;
Decls : List_Id;
Stms : List_Id);
-- Called to build an array or record stream function. The first three
-- arguments are the same as Build_Record_Or_Elementary_Input_Function.
-- Decls and Stms are the declarations and statements for the body and
-- The parameter Fnam is the name of the constructed function.
function Has_Stream_Standard_Rep (U_Type : Entity_Id) return Boolean;
-- This function is used to test the type U_Type, to determine if it has
-- a standard representation from a streaming point of view. Standard means
-- that it has a standard representation (e.g. no enumeration rep clause),
-- and the size of the root type is the same as the streaming size (which
-- is defined as value specified by a Stream_Size clause if present, or
-- the Esize of U_Type if not).
function Make_Stream_Subprogram_Name
(Loc : Source_Ptr;
Typ : Entity_Id;
Nam : TSS_Name_Type) return Entity_Id;
-- Return the entity that identifies the stream subprogram for type Typ
-- that is identified by the given Nam. This procedure deals with the
-- difference between tagged types (where a single subprogram associated
-- with the type is generated) and all other cases (where a subprogram
-- is generated at the point of the stream attribute reference). The
-- Loc parameter is used as the Sloc of the created entity.
function Stream_Base_Type (E : Entity_Id) return Entity_Id;
-- Stream attributes work on the basis of the base type except for the
-- array case. For the array case, we do not go to the base type, but
-- to the first subtype if it is constrained. This avoids problems with
-- incorrect conversions in the packed array case. Stream_Base_Type is
-- exactly this function (returns the base type, unless we have an array
-- type whose first subtype is constrained, in which case it returns the
-- first subtype).
--------------------------------
-- Build_Array_Input_Function --
--------------------------------
-- The function we build looks like
-- function typSI[_nnn] (S : access RST) return Typ is
-- L1 : constant Index_Type_1 := Index_Type_1'Input (S);
-- H1 : constant Index_Type_1 := Index_Type_1'Input (S);
-- L2 : constant Index_Type_2 := Index_Type_2'Input (S);
-- H2 : constant Index_Type_2 := Index_Type_2'Input (S);
-- ..
-- Ln : constant Index_Type_n := Index_Type_n'Input (S);
-- Hn : constant Index_Type_n := Index_Type_n'Input (S);
--
-- V : Typ'Base (L1 .. H1, L2 .. H2, ... Ln .. Hn)
-- begin
-- Typ'Read (S, V);
-- return V;
-- end typSI[_nnn]
-- Note: the suffix [_nnn] is present for untagged types, where we generate
-- a local subprogram at the point of the occurrence of the attribute
-- reference, so the name must be unique.
procedure Build_Array_Input_Function
(Loc : Source_Ptr;
Typ : Entity_Id;
Decl : out Node_Id;
Fnam : out Entity_Id)
is
Dim : constant Pos := Number_Dimensions (Typ);
Lnam : Name_Id;
Hnam : Name_Id;
Decls : List_Id;
Ranges : List_Id;
Stms : List_Id;
Rstmt : Node_Id;
Indx : Node_Id;
Odecl : Node_Id;
begin
Decls := New_List;
Ranges := New_List;
Indx := First_Index (Typ);
for J in 1 .. Dim loop
Lnam := New_External_Name ('L', J);
Hnam := New_External_Name ('H', J);
Append_To (Decls,
Make_Object_Declaration (Loc,
Defining_Identifier => Make_Defining_Identifier (Loc, Lnam),
Constant_Present => True,
Object_Definition => New_Occurrence_Of (Etype (Indx), Loc),
Expression =>
Make_Attribute_Reference (Loc,
Prefix =>
New_Occurrence_Of (Stream_Base_Type (Etype (Indx)), Loc),
Attribute_Name => Name_Input,
Expressions => New_List (Make_Identifier (Loc, Name_S)))));
Append_To (Decls,
Make_Object_Declaration (Loc,
Defining_Identifier => Make_Defining_Identifier (Loc, Hnam),
Constant_Present => True,
Object_Definition =>
New_Occurrence_Of (Stream_Base_Type (Etype (Indx)), Loc),
Expression =>
Make_Attribute_Reference (Loc,
Prefix =>
New_Occurrence_Of (Stream_Base_Type (Etype (Indx)), Loc),
Attribute_Name => Name_Input,
Expressions => New_List (Make_Identifier (Loc, Name_S)))));
Append_To (Ranges,
Make_Range (Loc,
Low_Bound => Make_Identifier (Loc, Lnam),
High_Bound => Make_Identifier (Loc, Hnam)));
Next_Index (Indx);
end loop;
-- If the type is constrained, use it directly. Otherwise build a
-- subtype indication with the proper bounds.
if Is_Constrained (Typ) then
Odecl :=
Make_Object_Declaration (Loc,
Defining_Identifier => Make_Defining_Identifier (Loc, Name_V),
Object_Definition => New_Occurrence_Of (Typ, Loc));
else
Odecl :=
Make_Object_Declaration (Loc,
Defining_Identifier => Make_Defining_Identifier (Loc, Name_V),
Object_Definition =>
Make_Subtype_Indication (Loc,
Subtype_Mark =>
New_Occurrence_Of (Stream_Base_Type (Typ), Loc),
Constraint =>
Make_Index_Or_Discriminant_Constraint (Loc, Ranges)));
end if;
Rstmt :=
Make_Attribute_Reference (Loc,
Prefix => New_Occurrence_Of (Typ, Loc),
Attribute_Name => Name_Read,
Expressions => New_List (
Make_Identifier (Loc, Name_S),
Make_Identifier (Loc, Name_V)));
Stms := New_List (
Make_Extended_Return_Statement (Loc,
Return_Object_Declarations => New_List (Odecl),
Handled_Statement_Sequence =>
Make_Handled_Sequence_Of_Statements (Loc, New_List (Rstmt))));
Fnam :=
Make_Defining_Identifier (Loc,
Chars => Make_TSS_Name_Local (Typ, TSS_Stream_Input));
Build_Stream_Function (Loc, Typ, Decl, Fnam, Decls, Stms);
end Build_Array_Input_Function;
----------------------------------
-- Build_Array_Output_Procedure --
----------------------------------
procedure Build_Array_Output_Procedure
(Loc : Source_Ptr;
Typ : Entity_Id;
Decl : out Node_Id;
Pnam : out Entity_Id)
is
Stms : List_Id;
Indx : Node_Id;
begin
-- Build series of statements to output bounds
Indx := First_Index (Typ);
Stms := New_List;
for J in 1 .. Number_Dimensions (Typ) loop
Append_To (Stms,
Make_Attribute_Reference (Loc,
Prefix =>
New_Occurrence_Of (Stream_Base_Type (Etype (Indx)), Loc),
Attribute_Name => Name_Write,
Expressions => New_List (
Make_Identifier (Loc, Name_S),
Make_Attribute_Reference (Loc,
Prefix => Make_Identifier (Loc, Name_V),
Attribute_Name => Name_First,
Expressions => New_List (
Make_Integer_Literal (Loc, J))))));
Append_To (Stms,
Make_Attribute_Reference (Loc,
Prefix =>
New_Occurrence_Of (Stream_Base_Type (Etype (Indx)), Loc),
Attribute_Name => Name_Write,
Expressions => New_List (
Make_Identifier (Loc, Name_S),
Make_Attribute_Reference (Loc,
Prefix => Make_Identifier (Loc, Name_V),
Attribute_Name => Name_Last,
Expressions => New_List (
Make_Integer_Literal (Loc, J))))));
Next_Index (Indx);
end loop;
-- Append Write attribute to write array elements
Append_To (Stms,
Make_Attribute_Reference (Loc,
Prefix => New_Occurrence_Of (Typ, Loc),
Attribute_Name => Name_Write,
Expressions => New_List (
Make_Identifier (Loc, Name_S),
Make_Identifier (Loc, Name_V))));
Pnam :=
Make_Defining_Identifier (Loc,
Chars => Make_TSS_Name_Local (Typ, TSS_Stream_Output));
Build_Stream_Procedure (Loc, Typ, Decl, Pnam, Stms, Outp => False);
end Build_Array_Output_Procedure;
--------------------------------
-- Build_Array_Read_Procedure --
--------------------------------
procedure Build_Array_Read_Procedure
(Nod : Node_Id;
Typ : Entity_Id;
Decl : out Node_Id;
Pnam : out Entity_Id)
is
Loc : constant Source_Ptr := Sloc (Nod);
begin
Pnam :=
Make_Defining_Identifier (Loc,
Chars => Make_TSS_Name_Local (Typ, TSS_Stream_Read));
Build_Array_Read_Write_Procedure (Nod, Typ, Decl, Pnam, Name_Read);
end Build_Array_Read_Procedure;
--------------------------------------
-- Build_Array_Read_Write_Procedure --
--------------------------------------
-- The form of the array read/write procedure is as follows:
-- procedure pnam (S : access RST, V : [out] Typ) is
-- begin
-- for L1 in V'Range (1) loop
-- for L2 in V'Range (2) loop
-- ...
-- for Ln in V'Range (n) loop
-- Component_Type'Read/Write (S, V (L1, L2, .. Ln));
-- end loop;
-- ..
-- end loop;
-- end loop
-- end pnam;
-- The out keyword for V is supplied in the Read case
procedure Build_Array_Read_Write_Procedure
(Nod : Node_Id;
Typ : Entity_Id;
Decl : out Node_Id;
Pnam : Entity_Id;
Nam : Name_Id)
is
Loc : constant Source_Ptr := Sloc (Nod);
Ndim : constant Pos := Number_Dimensions (Typ);
Ctyp : constant Entity_Id := Component_Type (Typ);
Stm : Node_Id;
Exl : List_Id;
RW : Entity_Id;
begin
-- First build the inner attribute call
Exl := New_List;
for J in 1 .. Ndim loop
Append_To (Exl, Make_Identifier (Loc, New_External_Name ('L', J)));
end loop;
Stm :=
Make_Attribute_Reference (Loc,
Prefix => New_Occurrence_Of (Stream_Base_Type (Ctyp), Loc),
Attribute_Name => Nam,
Expressions => New_List (
Make_Identifier (Loc, Name_S),
Make_Indexed_Component (Loc,
Prefix => Make_Identifier (Loc, Name_V),
Expressions => Exl)));
-- The corresponding stream attribute for the component type of the
-- array may be user-defined, and be frozen after the type for which
-- we are generating the stream subprogram. In that case, freeze the
-- stream attribute of the component type, whose declaration could not
-- generate any additional freezing actions in any case.
if Nam = Name_Read then
RW := TSS (Base_Type (Ctyp), TSS_Stream_Read);
else
RW := TSS (Base_Type (Ctyp), TSS_Stream_Write);
end if;
if Present (RW)
and then not Is_Frozen (RW)
then
Set_Is_Frozen (RW);
end if;
-- Now this is the big loop to wrap that statement up in a sequence
-- of loops. The first time around, Stm is the attribute call. The
-- second and subsequent times, Stm is an inner loop.
for J in 1 .. Ndim loop
Stm :=
Make_Implicit_Loop_Statement (Nod,
Iteration_Scheme =>
Make_Iteration_Scheme (Loc,
Loop_Parameter_Specification =>
Make_Loop_Parameter_Specification (Loc,
Defining_Identifier =>
Make_Defining_Identifier (Loc,
Chars => New_External_Name ('L', Ndim - J + 1)),
Discrete_Subtype_Definition =>
Make_Attribute_Reference (Loc,
Prefix => Make_Identifier (Loc, Name_V),
Attribute_Name => Name_Range,
Expressions => New_List (
Make_Integer_Literal (Loc, Ndim - J + 1))))),
Statements => New_List (Stm));
end loop;
Build_Stream_Procedure
(Loc, Typ, Decl, Pnam, New_List (Stm), Outp => Nam = Name_Read);
end Build_Array_Read_Write_Procedure;
---------------------------------
-- Build_Array_Write_Procedure --
---------------------------------
procedure Build_Array_Write_Procedure
(Nod : Node_Id;
Typ : Entity_Id;
Decl : out Node_Id;
Pnam : out Entity_Id)
is
Loc : constant Source_Ptr := Sloc (Nod);
begin
Pnam :=
Make_Defining_Identifier (Loc,
Chars => Make_TSS_Name_Local (Typ, TSS_Stream_Write));
Build_Array_Read_Write_Procedure (Nod, Typ, Decl, Pnam, Name_Write);
end Build_Array_Write_Procedure;
---------------------------------
-- Build_Elementary_Input_Call --
---------------------------------
function Build_Elementary_Input_Call (N : Node_Id) return Node_Id is
Loc : constant Source_Ptr := Sloc (N);
P_Type : constant Entity_Id := Entity (Prefix (N));
U_Type : constant Entity_Id := Underlying_Type (P_Type);
Rt_Type : constant Entity_Id := Root_Type (U_Type);
FST : constant Entity_Id := First_Subtype (U_Type);
Strm : constant Node_Id := First (Expressions (N));
Targ : constant Node_Id := Next (Strm);
P_Size : constant Uint := Get_Stream_Size (FST);
Res : Node_Id;
Lib_RE : RE_Id;
begin
-- Check first for Boolean and Character. These are enumeration types,
-- but we treat them specially, since they may require special handling
-- in the transfer protocol. However, this special handling only applies
-- if they have standard representation, otherwise they are treated like
-- any other enumeration type.
if Rt_Type = Standard_Boolean
and then Has_Stream_Standard_Rep (U_Type)
then
Lib_RE := RE_I_B;
elsif Rt_Type = Standard_Character
and then Has_Stream_Standard_Rep (U_Type)
then
Lib_RE := RE_I_C;
elsif Rt_Type = Standard_Wide_Character
and then Has_Stream_Standard_Rep (U_Type)
then
Lib_RE := RE_I_WC;
elsif Rt_Type = Standard_Wide_Wide_Character
and then Has_Stream_Standard_Rep (U_Type)
then
Lib_RE := RE_I_WWC;
-- Floating point types
elsif Is_Floating_Point_Type (U_Type) then
-- Question: should we use P_Size or Rt_Type to distinguish between
-- possible floating point types? If a non-standard size or a stream
-- size is specified, then we should certainly use the size. But if
-- we have two types the same (notably Short_Float_Size = Float_Size
-- which is close to universally true, and Long_Long_Float_Size =
-- Long_Float_Size, true on most targets except the x86), then we
-- would really rather use the root type, so that if people want to
-- fiddle with System.Stream_Attributes to get inter-target portable
-- streams, they get the size they expect. Consider in particular the
-- case of a stream written on an x86, with 96-bit Long_Long_Float
-- being read into a non-x86 target with 64 bit Long_Long_Float. A
-- special version of System.Stream_Attributes can deal with this
-- provided the proper type is always used.
-- To deal with these two requirements we add the special checks
-- on equal sizes and use the root type to distinguish.
if P_Size <= Standard_Short_Float_Size
and then (Standard_Short_Float_Size /= Standard_Float_Size
or else Rt_Type = Standard_Short_Float)
then
Lib_RE := RE_I_SF;
elsif P_Size <= Standard_Float_Size then
Lib_RE := RE_I_F;
elsif P_Size <= Standard_Long_Float_Size
and then (Standard_Long_Float_Size /= Standard_Long_Long_Float_Size
or else Rt_Type = Standard_Long_Float)
then
Lib_RE := RE_I_LF;
else
Lib_RE := RE_I_LLF;
end if;
-- Signed integer types. Also includes signed fixed-point types and
-- enumeration types with a signed representation.
-- Note on signed integer types. We do not consider types as signed for
-- this purpose if they have no negative numbers, or if they have biased
-- representation. The reason is that the value in either case basically
-- represents an unsigned value.
-- For example, consider:
-- type W is range 0 .. 2**32 - 1;
-- for W'Size use 32;
-- This is a signed type, but the representation is unsigned, and may
-- be outside the range of a 32-bit signed integer, so this must be
-- treated as 32-bit unsigned.
-- Similarly, if we have
-- type W is range -1 .. +254;
-- for W'Size use 8;
-- then the representation is unsigned
elsif not Is_Unsigned_Type (FST)
-- The following set of tests gets repeated many times, we should
-- have an abstraction defined ???
and then
(Is_Fixed_Point_Type (U_Type)
or else
Is_Enumeration_Type (U_Type)
or else
(Is_Signed_Integer_Type (U_Type)
and then not Has_Biased_Representation (FST)))
then
if P_Size <= Standard_Short_Short_Integer_Size then
Lib_RE := RE_I_SSI;
elsif P_Size <= Standard_Short_Integer_Size then
Lib_RE := RE_I_SI;
elsif P_Size = 24 then
Lib_RE := RE_I_I24;
elsif P_Size <= Standard_Integer_Size then
Lib_RE := RE_I_I;
elsif P_Size <= Standard_Long_Integer_Size then
Lib_RE := RE_I_LI;
elsif P_Size <= Standard_Long_Long_Integer_Size then
Lib_RE := RE_I_LLI;
else
Lib_RE := RE_I_LLLI;
end if;
-- Unsigned integer types, also includes unsigned fixed-point types
-- and enumeration types with an unsigned representation (note that
-- we know they are unsigned because we already tested for signed).
-- Also includes signed integer types that are unsigned in the sense
-- that they do not include negative numbers. See above for details.
elsif Is_Modular_Integer_Type (U_Type)
or else Is_Fixed_Point_Type (U_Type)
or else Is_Enumeration_Type (U_Type)
or else Is_Signed_Integer_Type (U_Type)
then
if P_Size <= Standard_Short_Short_Integer_Size then
Lib_RE := RE_I_SSU;
elsif P_Size <= Standard_Short_Integer_Size then
Lib_RE := RE_I_SU;
elsif P_Size = 24 then
Lib_RE := RE_I_U24;
elsif P_Size <= Standard_Integer_Size then
Lib_RE := RE_I_U;
elsif P_Size <= Standard_Long_Integer_Size then
Lib_RE := RE_I_LU;
elsif P_Size <= Standard_Long_Long_Integer_Size then
Lib_RE := RE_I_LLU;
else
Lib_RE := RE_I_LLLU;
end if;
else pragma Assert (Is_Access_Type (U_Type));
if Present (P_Size) and then P_Size > System_Address_Size then
Lib_RE := RE_I_AD;
else
Lib_RE := RE_I_AS;
end if;
end if;
-- Call the function, and do an unchecked conversion of the result
-- to the actual type of the prefix. If the target is a discriminant,
-- and we are in the body of the default implementation of a 'Read
-- attribute, set target type to force a constraint check (13.13.2(35)).
-- If the type of the discriminant is currently private, add another
-- unchecked conversion from the full view.
if Nkind (Targ) = N_Identifier
and then Is_Internal_Name (Chars (Targ))
and then Is_TSS (Scope (Entity (Targ)), TSS_Stream_Read)
then
Res :=
Unchecked_Convert_To (Base_Type (U_Type),
Make_Function_Call (Loc,
Name => New_Occurrence_Of (RTE (Lib_RE), Loc),
Parameter_Associations => New_List (
Relocate_Node (Strm))));
Set_Do_Range_Check (Res);
if Base_Type (P_Type) /= Base_Type (U_Type) then
Res := Unchecked_Convert_To (Base_Type (P_Type), Res);
end if;
return Res;
else
Res :=
Make_Function_Call (Loc,
Name => New_Occurrence_Of (RTE (Lib_RE), Loc),
Parameter_Associations => New_List (
Relocate_Node (Strm)));
-- Now convert to the base type if we do not have a biased type. Note
-- that we did not do this in some older versions, and the result was
-- losing a required range check in the case where 'Input is being
-- called from 'Read.
if not Has_Biased_Representation (P_Type) then
return Unchecked_Convert_To (Base_Type (P_Type), Res);
-- For the biased case, the conversion to the base type loses the
-- biasing, so just convert to Ptype. This is not quite right, and
-- for example may lose a corner case CE test, but it is such a
-- rare case that for now we ignore it ???
else
return Unchecked_Convert_To (P_Type, Res);
end if;
end if;
end Build_Elementary_Input_Call;
---------------------------------
-- Build_Elementary_Write_Call --
---------------------------------
function Build_Elementary_Write_Call (N : Node_Id) return Node_Id is
Loc : constant Source_Ptr := Sloc (N);
P_Type : constant Entity_Id := Entity (Prefix (N));
U_Type : constant Entity_Id := Underlying_Type (P_Type);
Rt_Type : constant Entity_Id := Root_Type (U_Type);
FST : constant Entity_Id := First_Subtype (U_Type);
Strm : constant Node_Id := First (Expressions (N));
Item : constant Node_Id := Next (Strm);
P_Size : Uint;
Lib_RE : RE_Id;
Libent : Entity_Id;
begin
-- Compute the size of the stream element. This is either the size of
-- the first subtype or if given the size of the Stream_Size attribute.
if Has_Stream_Size_Clause (FST) then
P_Size := Static_Integer (Expression (Stream_Size_Clause (FST)));
else
P_Size := Esize (FST);
end if;
-- Find the routine to be called
-- Check for First Boolean and Character. These are enumeration types,
-- but we treat them specially, since they may require special handling
-- in the transfer protocol. However, this special handling only applies
-- if they have standard representation, otherwise they are treated like
-- any other enumeration type.
if Rt_Type = Standard_Boolean
and then Has_Stream_Standard_Rep (U_Type)
then
Lib_RE := RE_W_B;
elsif Rt_Type = Standard_Character
and then Has_Stream_Standard_Rep (U_Type)
then
Lib_RE := RE_W_C;
elsif Rt_Type = Standard_Wide_Character
and then Has_Stream_Standard_Rep (U_Type)
then
Lib_RE := RE_W_WC;
elsif Rt_Type = Standard_Wide_Wide_Character
and then Has_Stream_Standard_Rep (U_Type)
then
Lib_RE := RE_W_WWC;
-- Floating point types
elsif Is_Floating_Point_Type (U_Type) then
-- Question: should we use P_Size or Rt_Type to distinguish between
-- possible floating point types? If a non-standard size or a stream
-- size is specified, then we should certainly use the size. But if
-- we have two types the same (notably Short_Float_Size = Float_Size
-- which is close to universally true, and Long_Long_Float_Size =
-- Long_Float_Size, true on most targets except the x86), then we
-- would really rather use the root type, so that if people want to
-- fiddle with System.Stream_Attributes to get inter-target portable
-- streams, they get the size they expect. Consider in particular the
-- case of a stream written on an x86, with 96-bit Long_Long_Float
-- being read into a non-x86 target with 64 bit Long_Long_Float. A
-- special version of System.Stream_Attributes can deal with this
-- provided the proper type is always used.
-- To deal with these two requirements we add the special checks
-- on equal sizes and use the root type to distinguish.
if P_Size <= Standard_Short_Float_Size
and then (Standard_Short_Float_Size /= Standard_Float_Size
or else Rt_Type = Standard_Short_Float)
then
Lib_RE := RE_W_SF;
elsif P_Size <= Standard_Float_Size then
Lib_RE := RE_W_F;
elsif P_Size <= Standard_Long_Float_Size
and then (Standard_Long_Float_Size /= Standard_Long_Long_Float_Size
or else Rt_Type = Standard_Long_Float)
then
Lib_RE := RE_W_LF;
else
Lib_RE := RE_W_LLF;
end if;
-- Signed integer types. Also includes signed fixed-point types and
-- signed enumeration types share this circuitry.
-- Note on signed integer types. We do not consider types as signed for
-- this purpose if they have no negative numbers, or if they have biased
-- representation. The reason is that the value in either case basically
-- represents an unsigned value.
-- For example, consider:
-- type W is range 0 .. 2**32 - 1;
-- for W'Size use 32;
-- This is a signed type, but the representation is unsigned, and may
-- be outside the range of a 32-bit signed integer, so this must be
-- treated as 32-bit unsigned.
-- Similarly, the representation is also unsigned if we have:
-- type W is range -1 .. +254;
-- for W'Size use 8;
-- forcing a biased and unsigned representation
elsif not Is_Unsigned_Type (FST)
and then
(Is_Fixed_Point_Type (U_Type)
or else
Is_Enumeration_Type (U_Type)
or else
(Is_Signed_Integer_Type (U_Type)
and then not Has_Biased_Representation (FST)))
then
if P_Size <= Standard_Short_Short_Integer_Size then
Lib_RE := RE_W_SSI;
elsif P_Size <= Standard_Short_Integer_Size then
Lib_RE := RE_W_SI;
elsif P_Size = 24 then
Lib_RE := RE_W_I24;
elsif P_Size <= Standard_Integer_Size then
Lib_RE := RE_W_I;
elsif P_Size <= Standard_Long_Integer_Size then
Lib_RE := RE_W_LI;
elsif P_Size <= Standard_Long_Long_Integer_Size then
Lib_RE := RE_W_LLI;
else
Lib_RE := RE_W_LLLI;
end if;
-- Unsigned integer types, also includes unsigned fixed-point types
-- and unsigned enumeration types (note we know they are unsigned
-- because we already tested for signed above).
-- Also includes signed integer types that are unsigned in the sense
-- that they do not include negative numbers. See above for details.
elsif Is_Modular_Integer_Type (U_Type)
or else Is_Fixed_Point_Type (U_Type)
or else Is_Enumeration_Type (U_Type)
or else Is_Signed_Integer_Type (U_Type)
then
if P_Size <= Standard_Short_Short_Integer_Size then
Lib_RE := RE_W_SSU;
elsif P_Size <= Standard_Short_Integer_Size then
Lib_RE := RE_W_SU;
elsif P_Size = 24 then
Lib_RE := RE_W_U24;
elsif P_Size <= Standard_Integer_Size then
Lib_RE := RE_W_U;
elsif P_Size <= Standard_Long_Integer_Size then
Lib_RE := RE_W_LU;
elsif P_Size <= Standard_Long_Long_Integer_Size then
Lib_RE := RE_W_LLU;
else
Lib_RE := RE_W_LLLU;
end if;
else pragma Assert (Is_Access_Type (U_Type));
if Present (P_Size) and then P_Size > System_Address_Size then
Lib_RE := RE_W_AD;
else
Lib_RE := RE_W_AS;
end if;
end if;
-- Unchecked-convert parameter to the required type (i.e. the type of
-- the corresponding parameter, and call the appropriate routine.
Libent := RTE (Lib_RE);
return
Make_Procedure_Call_Statement (Loc,
Name => New_Occurrence_Of (Libent, Loc),
Parameter_Associations => New_List (
Relocate_Node (Strm),
Unchecked_Convert_To (Etype (Next_Formal (First_Formal (Libent))),
Relocate_Node (Item))));
end Build_Elementary_Write_Call;
-----------------------------------------
-- Build_Mutable_Record_Read_Procedure --
-----------------------------------------
procedure Build_Mutable_Record_Read_Procedure
(Loc : Source_Ptr;
Typ : Entity_Id;
Decl : out Node_Id;
Pnam : out Entity_Id)
is
Out_Formal : Node_Id;
-- Expression denoting the out formal parameter
Dcls : constant List_Id := New_List;
-- Declarations for the 'Read body
Stms : constant List_Id := New_List;
-- Statements for the 'Read body
Disc : Entity_Id;
-- Entity of the discriminant being processed
Tmp_For_Disc : Entity_Id;
-- Temporary object used to read the value of Disc
Tmps_For_Discs : constant List_Id := New_List;
-- List of object declarations for temporaries holding the read values
-- for the discriminants.
Cstr : constant List_Id := New_List;
-- List of constraints to be applied on temporary record
Discriminant_Checks : constant List_Id := New_List;
-- List of discriminant checks to be performed if the actual object
-- is constrained.
Tmp : constant Entity_Id := Make_Defining_Identifier (Loc, Name_V);
-- Temporary record must hide formal (assignments to components of the
-- record are always generated with V as the identifier for the record).
Constrained_Stms : List_Id := New_List;
-- Statements within the block where we have the constrained temporary
begin
-- A mutable type cannot be a tagged type, so we generate a new name
-- for the stream procedure.
Pnam :=
Make_Defining_Identifier (Loc,
Chars => Make_TSS_Name_Local (Typ, TSS_Stream_Read));
if Is_Unchecked_Union (Typ) then
-- If this is an unchecked union, the stream procedure is erroneous,
-- because there are no discriminants to read.
-- This should generate a warning ???
Append_To (Stms,
Make_Raise_Program_Error (Loc,
Reason => PE_Unchecked_Union_Restriction));
Build_Stream_Procedure (Loc, Typ, Decl, Pnam, Stms, Outp => True);
return;
end if;
Disc := First_Discriminant (Typ);
Out_Formal :=
Make_Selected_Component (Loc,
Prefix => New_Occurrence_Of (Pnam, Loc),
Selector_Name => Make_Identifier (Loc, Name_V));
-- Generate Reads for the discriminants of the type. The discriminants
-- need to be read before the rest of the components, so that variants
-- are initialized correctly. The discriminants must be read into temp
-- variables so an incomplete Read (interrupted by an exception, for
-- example) does not alter the passed object.
while Present (Disc) loop
Tmp_For_Disc := Make_Defining_Identifier (Loc,
New_External_Name (Chars (Disc), "D"));
Append_To (Tmps_For_Discs,
Make_Object_Declaration (Loc,
Defining_Identifier => Tmp_For_Disc,
Object_Definition => New_Occurrence_Of (Etype (Disc), Loc)));
Set_No_Initialization (Last (Tmps_For_Discs));
Append_To (Stms,
Make_Attribute_Reference (Loc,
Prefix => New_Occurrence_Of (Etype (Disc), Loc),
Attribute_Name => Name_Read,
Expressions => New_List (
Make_Identifier (Loc, Name_S),
New_Occurrence_Of (Tmp_For_Disc, Loc))));
Append_To (Cstr,
Make_Discriminant_Association (Loc,
Selector_Names => New_List (New_Occurrence_Of (Disc, Loc)),
Expression => New_Occurrence_Of (Tmp_For_Disc, Loc)));
Append_To (Discriminant_Checks,
Make_Raise_Constraint_Error (Loc,
Condition =>
Make_Op_Ne (Loc,
Left_Opnd => New_Occurrence_Of (Tmp_For_Disc, Loc),
Right_Opnd =>
Make_Selected_Component (Loc,
Prefix => New_Copy_Tree (Out_Formal),
Selector_Name => New_Occurrence_Of (Disc, Loc))),
Reason => CE_Discriminant_Check_Failed));
Next_Discriminant (Disc);
end loop;
-- Generate reads for the components of the record (including those
-- that depend on discriminants).
Build_Record_Read_Write_Procedure (Loc, Typ, Decl, Pnam, Name_Read);
-- Save original statement sequence for component assignments, and
-- replace it with Stms.
Constrained_Stms := Statements (Handled_Statement_Sequence (Decl));
Set_Handled_Statement_Sequence (Decl,
Make_Handled_Sequence_Of_Statements (Loc,
Statements => Stms));
-- If Typ has controlled components (i.e. if it is classwide or
-- Has_Controlled), or components constrained using the discriminants
-- of Typ, then we need to ensure that all component assignments are
-- performed on an object that has been appropriately constrained
-- prior to being initialized. To this effect, we wrap the component
-- assignments in a block where V is a constrained temporary.
Append_To (Dcls,
Make_Object_Declaration (Loc,
Defining_Identifier => Tmp,
Object_Definition =>
Make_Subtype_Indication (Loc,
Subtype_Mark => New_Occurrence_Of (Base_Type (Typ), Loc),
Constraint =>
Make_Index_Or_Discriminant_Constraint (Loc,
Constraints => Cstr))));
-- AI05-023-1: Insert discriminant check prior to initialization of the
-- constrained temporary.
Append_To (Stms,
Make_Implicit_If_Statement (Pnam,
Condition =>
Make_Attribute_Reference (Loc,
Prefix => New_Copy_Tree (Out_Formal),
Attribute_Name => Name_Constrained),
Then_Statements => Discriminant_Checks));
-- Now insert back original component assignments, wrapped in a block
-- in which V is the constrained temporary.
Append_To (Stms,
Make_Block_Statement (Loc,
Declarations => Dcls,
Handled_Statement_Sequence => Parent (Constrained_Stms)));
Append_To (Constrained_Stms,
Make_Assignment_Statement (Loc,
Name => Out_Formal,
Expression => Make_Identifier (Loc, Name_V)));
Set_Declarations (Decl, Tmps_For_Discs);
end Build_Mutable_Record_Read_Procedure;
------------------------------------------
-- Build_Mutable_Record_Write_Procedure --
------------------------------------------
procedure Build_Mutable_Record_Write_Procedure
(Loc : Source_Ptr;
Typ : Entity_Id;
Decl : out Node_Id;
Pnam : out Entity_Id)
is
Stms : List_Id;
Disc : Entity_Id;
D_Ref : Node_Id;
begin
Stms := New_List;
Disc := First_Discriminant (Typ);
-- Generate Writes for the discriminants of the type
-- If the type is an unchecked union, use the default values of
-- the discriminants, because they are not stored.
while Present (Disc) loop
if Is_Unchecked_Union (Typ) then
D_Ref :=
New_Copy_Tree (Discriminant_Default_Value (Disc));
else
D_Ref :=
Make_Selected_Component (Loc,
Prefix => Make_Identifier (Loc, Name_V),
Selector_Name => New_Occurrence_Of (Disc, Loc));
end if;
Append_To (Stms,
Make_Attribute_Reference (Loc,
Prefix => New_Occurrence_Of (Etype (Disc), Loc),
Attribute_Name => Name_Write,
Expressions => New_List (
Make_Identifier (Loc, Name_S),
D_Ref)));
Next_Discriminant (Disc);
end loop;
-- A mutable type cannot be a tagged type, so we generate a new name
-- for the stream procedure.
Pnam :=
Make_Defining_Identifier (Loc,
Chars => Make_TSS_Name_Local (Typ, TSS_Stream_Write));
Build_Record_Read_Write_Procedure (Loc, Typ, Decl, Pnam, Name_Write);
-- Write the discriminants before the rest of the components, so
-- that discriminant values are properly set of variants, etc.
if Is_Non_Empty_List (
Statements (Handled_Statement_Sequence (Decl)))
then
Insert_List_Before
(First (Statements (Handled_Statement_Sequence (Decl))), Stms);
else
Set_Statements (Handled_Statement_Sequence (Decl), Stms);
end if;
end Build_Mutable_Record_Write_Procedure;
-----------------------------------------------
-- Build_Record_Or_Elementary_Input_Function --
-----------------------------------------------
-- The function we build looks like
-- function InputN (S : access RST) return Typ is
-- C1 : constant Disc_Type_1;
-- Discr_Type_1'Read (S, C1);
-- C2 : constant Disc_Type_2;
-- Discr_Type_2'Read (S, C2);
-- ...
-- Cn : constant Disc_Type_n;
-- Discr_Type_n'Read (S, Cn);
-- V : Typ (C1, C2, .. Cn)
-- begin
-- Typ'Read (S, V);
-- return V;
-- end InputN
-- The discriminants are of course only present in the case of a record
-- with discriminants. In the case of a record with no discriminants, or
-- an elementary type, then no Cn constants are defined.
procedure Build_Record_Or_Elementary_Input_Function
(Loc : Source_Ptr;
Typ : Entity_Id;
Decl : out Node_Id;
Fnam : out Entity_Id)
is
B_Typ : constant Entity_Id := Underlying_Type (Base_Type (Typ));
Cn : Name_Id;
Constr : List_Id;
Decls : List_Id;
Discr : Entity_Id;
Discr_Elmt : Elmt_Id := No_Elmt;
J : Pos;
Obj_Decl : Node_Id;
Odef : Node_Id;
Stms : List_Id;
begin
Decls := New_List;
Constr := New_List;
J := 1;
-- In the presence of multiple instantiations (as in uses of the Booch
-- components) the base type may be private, and the underlying type
-- already constrained, in which case there's no discriminant constraint
-- to construct.
if Has_Discriminants (Typ)
and then No (Discriminant_Default_Value (First_Discriminant (Typ)))
and then not Is_Constrained (Underlying_Type (B_Typ))
then
Discr := First_Discriminant (B_Typ);
-- If the prefix subtype is constrained, then retrieve the first
-- element of its constraint.
if Is_Constrained (Typ) then
Discr_Elmt := First_Elmt (Discriminant_Constraint (Typ));
end if;
while Present (Discr) loop
Cn := New_External_Name ('C', J);
Decl :=
Make_Object_Declaration (Loc,
Defining_Identifier => Make_Defining_Identifier (Loc, Cn),
Object_Definition =>
New_Occurrence_Of (Etype (Discr), Loc));
-- If this is an access discriminant, do not perform default
-- initialization. The discriminant is about to get its value
-- from Read, and if the type is null excluding we do not want
-- spurious warnings on an initial null value.
if Is_Access_Type (Etype (Discr)) then
Set_No_Initialization (Decl);
end if;
Append_To (Decls, Decl);
Append_To (Decls,
Make_Attribute_Reference (Loc,
Prefix => New_Occurrence_Of (Etype (Discr), Loc),
Attribute_Name => Name_Read,
Expressions => New_List (
Make_Identifier (Loc, Name_S),
Make_Identifier (Loc, Cn))));
Append_To (Constr, Make_Identifier (Loc, Cn));
-- If the prefix subtype imposes a discriminant constraint, then
-- check that each discriminant value equals the value read.
if Present (Discr_Elmt) then
Append_To (Decls,
Make_Raise_Constraint_Error (Loc,
Condition => Make_Op_Ne (Loc,
Left_Opnd =>
New_Occurrence_Of
(Defining_Identifier (Decl), Loc),
Right_Opnd =>
New_Copy_Tree (Node (Discr_Elmt))),
Reason => CE_Discriminant_Check_Failed));
Next_Elmt (Discr_Elmt);
end if;
Next_Discriminant (Discr);
J := J + 1;
end loop;
Odef :=
Make_Subtype_Indication (Loc,
Subtype_Mark => New_Occurrence_Of (B_Typ, Loc),
Constraint =>
Make_Index_Or_Discriminant_Constraint (Loc,
Constraints => Constr));
-- If no discriminants, then just use the type with no constraint
else
Odef := New_Occurrence_Of (B_Typ, Loc);
end if;
-- Create an extended return statement encapsulating the result object
-- and 'Read call, which is needed in general for proper handling of
-- build-in-place results (such as when the result type is inherently
-- limited).
Obj_Decl :=
Make_Object_Declaration (Loc,
Defining_Identifier => Make_Defining_Identifier (Loc, Name_V),
Object_Definition => Odef);
-- If the type is an access type, do not perform default initialization.
-- The object is about to get its value from Read, and if the type is
-- null excluding we do not want spurious warnings on an initial null.
if Is_Access_Type (B_Typ) then
Set_No_Initialization (Obj_Decl);
end if;
Stms := New_List (
Make_Extended_Return_Statement (Loc,
Return_Object_Declarations => New_List (Obj_Decl),
Handled_Statement_Sequence =>
Make_Handled_Sequence_Of_Statements (Loc,
Statements => New_List (
Make_Attribute_Reference (Loc,
Prefix => New_Occurrence_Of (B_Typ, Loc),
Attribute_Name => Name_Read,
Expressions => New_List (
Make_Identifier (Loc, Name_S),
Make_Identifier (Loc, Name_V)))))));
Fnam := Make_Stream_Subprogram_Name (Loc, B_Typ, TSS_Stream_Input);
Build_Stream_Function (Loc, B_Typ, Decl, Fnam, Decls, Stms);
end Build_Record_Or_Elementary_Input_Function;
-------------------------------------------------
-- Build_Record_Or_Elementary_Output_Procedure --
-------------------------------------------------
procedure Build_Record_Or_Elementary_Output_Procedure
(Loc : Source_Ptr;
Typ : Entity_Id;
Decl : out Node_Id;
Pnam : out Entity_Id)
is
Stms : List_Id;
Disc : Entity_Id;
Disc_Ref : Node_Id;
begin
Stms := New_List;
-- Note that of course there will be no discriminants for the elementary
-- type case, so Has_Discriminants will be False. Note that the language
-- rules do not allow writing the discriminants in the defaulted case,
-- because those are written by 'Write.
if Has_Discriminants (Typ)
and then No (Discriminant_Default_Value (First_Discriminant (Typ)))
then
Disc := First_Discriminant (Typ);
while Present (Disc) loop
-- If the type is an unchecked union, it must have default
-- discriminants (this is checked earlier), and those defaults
-- are written out to the stream.
if Is_Unchecked_Union (Typ) then
Disc_Ref := New_Copy_Tree (Discriminant_Default_Value (Disc));
else
Disc_Ref :=
Make_Selected_Component (Loc,
Prefix => Make_Identifier (Loc, Name_V),
Selector_Name => New_Occurrence_Of (Disc, Loc));
end if;
Append_To (Stms,
Make_Attribute_Reference (Loc,
Prefix =>
New_Occurrence_Of (Stream_Base_Type (Etype (Disc)), Loc),
Attribute_Name => Name_Write,
Expressions => New_List (
Make_Identifier (Loc, Name_S),
Disc_Ref)));
Next_Discriminant (Disc);
end loop;
end if;
Append_To (Stms,
Make_Attribute_Reference (Loc,
Prefix => New_Occurrence_Of (Typ, Loc),
Attribute_Name => Name_Write,
Expressions => New_List (
Make_Identifier (Loc, Name_S),
Make_Identifier (Loc, Name_V))));
Pnam := Make_Stream_Subprogram_Name (Loc, Typ, TSS_Stream_Output);
Build_Stream_Procedure (Loc, Typ, Decl, Pnam, Stms, Outp => False);
end Build_Record_Or_Elementary_Output_Procedure;
---------------------------------
-- Build_Record_Read_Procedure --
---------------------------------
procedure Build_Record_Read_Procedure
(Loc : Source_Ptr;
Typ : Entity_Id;
Decl : out Node_Id;
Pnam : out Entity_Id)
is
begin
Pnam := Make_Stream_Subprogram_Name (Loc, Typ, TSS_Stream_Read);
Build_Record_Read_Write_Procedure (Loc, Typ, Decl, Pnam, Name_Read);
end Build_Record_Read_Procedure;
---------------------------------------
-- Build_Record_Read_Write_Procedure --
---------------------------------------
-- The form of the record read/write procedure is as shown by the
-- following example for a case with one discriminant case variant:
-- procedure pnam (S : access RST, V : [out] Typ) is
-- begin
-- Component_Type'Read/Write (S, V.component);
-- Component_Type'Read/Write (S, V.component);
-- ...
-- Component_Type'Read/Write (S, V.component);
--
-- case V.discriminant is
-- when choices =>
-- Component_Type'Read/Write (S, V.component);
-- Component_Type'Read/Write (S, V.component);
-- ...
-- Component_Type'Read/Write (S, V.component);
--
-- when choices =>
-- Component_Type'Read/Write (S, V.component);
-- Component_Type'Read/Write (S, V.component);
-- ...
-- Component_Type'Read/Write (S, V.component);
-- ...
-- end case;
-- end pnam;
-- The out keyword for V is supplied in the Read case
procedure Build_Record_Read_Write_Procedure
(Loc : Source_Ptr;
Typ : Entity_Id;
Decl : out Node_Id;
Pnam : Entity_Id;
Nam : Name_Id)
is
Rdef : Node_Id;
Stms : List_Id;
Typt : Entity_Id;
In_Limited_Extension : Boolean := False;
-- Set to True while processing the record extension definition
-- for an extension of a limited type (for which an ancestor type
-- has an explicit Nam attribute definition).
function Make_Component_List_Attributes (CL : Node_Id) return List_Id;
-- Returns a sequence of attributes to process the components that
-- are referenced in the given component list.
function Make_Field_Attribute (C : Entity_Id) return Node_Id;
-- Given C, the entity for a discriminant or component, build
-- an attribute for the corresponding field values.
function Make_Field_Attributes (Clist : List_Id) return List_Id;
-- Given Clist, a component items list, construct series of attributes
-- for fieldwise processing of the corresponding components.
------------------------------------
-- Make_Component_List_Attributes --
------------------------------------
function Make_Component_List_Attributes (CL : Node_Id) return List_Id is
CI : constant List_Id := Component_Items (CL);
VP : constant Node_Id := Variant_Part (CL);
Result : List_Id;
Alts : List_Id;
V : Node_Id;
DC : Node_Id;
DCH : List_Id;
D_Ref : Node_Id;
begin
Result := Make_Field_Attributes (CI);
if Present (VP) then
Alts := New_List;
V := First_Non_Pragma (Variants (VP));
while Present (V) loop
DCH := New_List;
DC := First (Discrete_Choices (V));
while Present (DC) loop
Append_To (DCH, New_Copy_Tree (DC));
Next (DC);
end loop;
Append_To (Alts,
Make_Case_Statement_Alternative (Loc,
Discrete_Choices => DCH,
Statements =>
Make_Component_List_Attributes (Component_List (V))));
Next_Non_Pragma (V);
end loop;
-- Note: in the following, we make sure that we use new occurrence
-- of for the selector, since there are cases in which we make a
-- reference to a hidden discriminant that is not visible.
-- If the enclosing record is an unchecked_union, we use the
-- default expressions for the discriminant (it must exist)
-- because we cannot generate a reference to it, given that
-- it is not stored.
if Is_Unchecked_Union (Scope (Entity (Name (VP)))) then
D_Ref :=
New_Copy_Tree
(Discriminant_Default_Value (Entity (Name (VP))));
else
D_Ref :=
Make_Selected_Component (Loc,
Prefix => Make_Identifier (Loc, Name_V),
Selector_Name =>
New_Occurrence_Of (Entity (Name (VP)), Loc));
end if;
Append_To (Result,
Make_Case_Statement (Loc,
Expression => D_Ref,
Alternatives => Alts));
end if;
return Result;
end Make_Component_List_Attributes;
--------------------------
-- Make_Field_Attribute --
--------------------------
function Make_Field_Attribute (C : Entity_Id) return Node_Id is
Field_Typ : constant Entity_Id := Stream_Base_Type (Etype (C));
TSS_Names : constant array (Name_Input .. Name_Write) of
TSS_Name_Type :=
(Name_Read => TSS_Stream_Read,
Name_Write => TSS_Stream_Write,
Name_Input => TSS_Stream_Input,
Name_Output => TSS_Stream_Output,
others => TSS_Null);
pragma Assert (TSS_Names (Nam) /= TSS_Null);
begin
if In_Limited_Extension
and then Is_Limited_Type (Field_Typ)
and then No (Find_Inherited_TSS (Field_Typ, TSS_Names (Nam)))
then
-- The declaration is illegal per 13.13.2(9/1), and this is
-- enforced in Exp_Ch3.Check_Stream_Attributes. Keep the caller
-- happy by returning a null statement.
return Make_Null_Statement (Loc);
end if;
return
Make_Attribute_Reference (Loc,
Prefix => New_Occurrence_Of (Field_Typ, Loc),
Attribute_Name => Nam,
Expressions => New_List (
Make_Identifier (Loc, Name_S),
Make_Selected_Component (Loc,
Prefix => Make_Identifier (Loc, Name_V),
Selector_Name => New_Occurrence_Of (C, Loc))));
end Make_Field_Attribute;
---------------------------
-- Make_Field_Attributes --
---------------------------
function Make_Field_Attributes (Clist : List_Id) return List_Id is
Item : Node_Id;
Result : List_Id;
begin
Result := New_List;
if Present (Clist) then
Item := First (Clist);
-- Loop through components, skipping all internal components,
-- which are not part of the value (e.g. _Tag), except that we
-- don't skip the _Parent, since we do want to process that
-- recursively. If _Parent is an interface type, being abstract
-- with no components there is no need to handle it.
while Present (Item) loop
if Nkind (Item) = N_Component_Declaration
and then
((Chars (Defining_Identifier (Item)) = Name_uParent
and then not Is_Interface
(Etype (Defining_Identifier (Item))))
or else
not Is_Internal_Name (Chars (Defining_Identifier (Item))))
then
Append_To
(Result,
Make_Field_Attribute (Defining_Identifier (Item)));
end if;
Next (Item);
end loop;
end if;
return Result;
end Make_Field_Attributes;
-- Start of processing for Build_Record_Read_Write_Procedure
begin
-- For the protected type case, use corresponding record
if Is_Protected_Type (Typ) then
Typt := Corresponding_Record_Type (Typ);
else
Typt := Typ;
end if;
-- Note that we do nothing with the discriminants, since Read and
-- Write do not read or write the discriminant values. All handling
-- of discriminants occurs in the Input and Output subprograms.
Rdef := Type_Definition
(Declaration_Node (Base_Type (Underlying_Type (Typt))));
Stms := Empty_List;
-- In record extension case, the fields we want, including the _Parent
-- field representing the parent type, are to be found in the extension.
-- Note that we will naturally process the _Parent field using the type
-- of the parent, and hence its stream attributes, which is appropriate.
if Nkind (Rdef) = N_Derived_Type_Definition then
Rdef := Record_Extension_Part (Rdef);
if Is_Limited_Type (Typt) then
In_Limited_Extension := True;
end if;
end if;
if Present (Component_List (Rdef)) then
Append_List_To (Stms,
Make_Component_List_Attributes (Component_List (Rdef)));
end if;
Build_Stream_Procedure
(Loc, Typ, Decl, Pnam, Stms, Outp => Nam = Name_Read);
end Build_Record_Read_Write_Procedure;
----------------------------------
-- Build_Record_Write_Procedure --
----------------------------------
procedure Build_Record_Write_Procedure
(Loc : Source_Ptr;
Typ : Entity_Id;
Decl : out Node_Id;
Pnam : out Entity_Id)
is
begin
Pnam := Make_Stream_Subprogram_Name (Loc, Typ, TSS_Stream_Write);
Build_Record_Read_Write_Procedure (Loc, Typ, Decl, Pnam, Name_Write);
end Build_Record_Write_Procedure;
-------------------------------
-- Build_Stream_Attr_Profile --
-------------------------------
function Build_Stream_Attr_Profile
(Loc : Source_Ptr;
Typ : Entity_Id;
Nam : TSS_Name_Type) return List_Id
is
Profile : List_Id;
begin
-- (Ada 2005: AI-441): Set the null-excluding attribute because it has
-- no semantic meaning in Ada 95 but it is a requirement in Ada 2005.
Profile := New_List (
Make_Parameter_Specification (Loc,
Defining_Identifier => Make_Defining_Identifier (Loc, Name_S),
Parameter_Type =>
Make_Access_Definition (Loc,
Null_Exclusion_Present => True,
Subtype_Mark => New_Occurrence_Of (
Class_Wide_Type (RTE (RE_Root_Stream_Type)), Loc))));
if Nam /= TSS_Stream_Input then
Append_To (Profile,
Make_Parameter_Specification (Loc,
Defining_Identifier => Make_Defining_Identifier (Loc, Name_V),
Out_Present => (Nam = TSS_Stream_Read),
Parameter_Type => New_Occurrence_Of (Typ, Loc)));
end if;
return Profile;
end Build_Stream_Attr_Profile;
---------------------------
-- Build_Stream_Function --
---------------------------
procedure Build_Stream_Function
(Loc : Source_Ptr;
Typ : Entity_Id;
Decl : out Node_Id;
Fnam : Entity_Id;
Decls : List_Id;
Stms : List_Id)
is
Spec : Node_Id;
begin
-- Construct function specification
-- (Ada 2005: AI-441): Set the null-excluding attribute because it has
-- no semantic meaning in Ada 95 but it is a requirement in Ada 2005.
Spec :=
Make_Function_Specification (Loc,
Defining_Unit_Name => Fnam,
Parameter_Specifications => New_List (
Make_Parameter_Specification (Loc,
Defining_Identifier => Make_Defining_Identifier (Loc, Name_S),
Parameter_Type =>
Make_Access_Definition (Loc,
Null_Exclusion_Present => True,
Subtype_Mark =>
New_Occurrence_Of
(Class_Wide_Type (RTE (RE_Root_Stream_Type)), Loc)))),
Result_Definition => New_Occurrence_Of (Typ, Loc));
Decl :=
Make_Subprogram_Body (Loc,
Specification => Spec,
Declarations => Decls,
Handled_Statement_Sequence =>
Make_Handled_Sequence_Of_Statements (Loc,
Statements => Stms));
end Build_Stream_Function;
----------------------------
-- Build_Stream_Procedure --
----------------------------
procedure Build_Stream_Procedure
(Loc : Source_Ptr;
Typ : Entity_Id;
Decl : out Node_Id;
Pnam : Entity_Id;
Stms : List_Id;
Outp : Boolean)
is
Spec : Node_Id;
begin
-- Construct procedure specification
-- (Ada 2005: AI-441): Set the null-excluding attribute because it has
-- no semantic meaning in Ada 95 but it is a requirement in Ada 2005.
Spec :=
Make_Procedure_Specification (Loc,
Defining_Unit_Name => Pnam,
Parameter_Specifications => New_List (
Make_Parameter_Specification (Loc,
Defining_Identifier => Make_Defining_Identifier (Loc, Name_S),
Parameter_Type =>
Make_Access_Definition (Loc,
Null_Exclusion_Present => True,
Subtype_Mark =>
New_Occurrence_Of
(Class_Wide_Type (RTE (RE_Root_Stream_Type)), Loc))),
Make_Parameter_Specification (Loc,
Defining_Identifier => Make_Defining_Identifier (Loc, Name_V),
Out_Present => Outp,
Parameter_Type => New_Occurrence_Of (Typ, Loc))));
Decl :=
Make_Subprogram_Body (Loc,
Specification => Spec,
Declarations => Empty_List,
Handled_Statement_Sequence =>
Make_Handled_Sequence_Of_Statements (Loc,
Statements => Stms));
end Build_Stream_Procedure;
-----------------------------
-- Has_Stream_Standard_Rep --
-----------------------------
function Has_Stream_Standard_Rep (U_Type : Entity_Id) return Boolean is
Siz : Uint;
begin
if Has_Non_Standard_Rep (U_Type) then
return False;
end if;
if Has_Stream_Size_Clause (U_Type) then
Siz := Static_Integer (Expression (Stream_Size_Clause (U_Type)));
else
Siz := Esize (First_Subtype (U_Type));
end if;
return Siz = Esize (Root_Type (U_Type));
end Has_Stream_Standard_Rep;
---------------------------------
-- Make_Stream_Subprogram_Name --
---------------------------------
function Make_Stream_Subprogram_Name
(Loc : Source_Ptr;
Typ : Entity_Id;
Nam : TSS_Name_Type) return Entity_Id
is
Sname : Name_Id;
begin
-- For tagged types, we are dealing with a TSS associated with the
-- declaration, so we use the standard primitive function name. For
-- other types, generate a local TSS name since we are generating
-- the subprogram at the point of use.
if Is_Tagged_Type (Typ) then
Sname := Make_TSS_Name (Typ, Nam);
else
Sname := Make_TSS_Name_Local (Typ, Nam);
end if;
return Make_Defining_Identifier (Loc, Sname);
end Make_Stream_Subprogram_Name;
----------------------
-- Stream_Base_Type --
----------------------
function Stream_Base_Type (E : Entity_Id) return Entity_Id is
begin
if Is_Array_Type (E)
and then Is_First_Subtype (E)
then
return E;
else
return Base_Type (E);
end if;
end Stream_Base_Type;
end Exp_Strm;
|
stcarrez/ada-awa | Ada | 17,231 | adb | -----------------------------------------------------------------------
-- AWA.Changelogs.Models -- AWA.Changelogs.Models
-----------------------------------------------------------------------
-- File generated by Dynamo DO NOT MODIFY
-- Template used: templates/model/package-body.xhtml
-- Ada Generator: https://github.com/stcarrez/dynamo Version 1.4.0
-----------------------------------------------------------------------
-- Copyright (C) 2023 Stephane Carrez
-- Written by Stephane Carrez ([email protected])
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-----------------------------------------------------------------------
pragma Warnings (Off);
with Ada.Unchecked_Deallocation;
with Util.Beans.Objects.Time;
pragma Warnings (On);
package body AWA.Changelogs.Models is
pragma Style_Checks ("-mrIu");
pragma Warnings (Off, "formal parameter * is not referenced");
pragma Warnings (Off, "use clause for type *");
pragma Warnings (Off, "use clause for private type *");
use type ADO.Objects.Object_Record_Access;
use type ADO.Objects.Object_Ref;
function Changelog_Key (Id : in ADO.Identifier) return ADO.Objects.Object_Key is
Result : ADO.Objects.Object_Key (Of_Type => ADO.Objects.KEY_INTEGER,
Of_Class => CHANGELOG_DEF'Access);
begin
ADO.Objects.Set_Value (Result, Id);
return Result;
end Changelog_Key;
function Changelog_Key (Id : in String) return ADO.Objects.Object_Key is
Result : ADO.Objects.Object_Key (Of_Type => ADO.Objects.KEY_INTEGER,
Of_Class => CHANGELOG_DEF'Access);
begin
ADO.Objects.Set_Value (Result, Id);
return Result;
end Changelog_Key;
function "=" (Left, Right : Changelog_Ref'Class) return Boolean is
begin
return ADO.Objects.Object_Ref'Class (Left) = ADO.Objects.Object_Ref'Class (Right);
end "=";
procedure Set_Field (Object : in out Changelog_Ref'Class;
Impl : out Changelog_Access) is
Result : ADO.Objects.Object_Record_Access;
begin
Object.Prepare_Modify (Result);
Impl := Changelog_Impl (Result.all)'Access;
end Set_Field;
-- Internal method to allocate the Object_Record instance
overriding
procedure Allocate (Object : in out Changelog_Ref) is
Impl : Changelog_Access;
begin
Impl := new Changelog_Impl;
Impl.Date := ADO.DEFAULT_TIME;
Impl.For_Entity_Id := ADO.NO_IDENTIFIER;
Impl.Entity_Type := 0;
ADO.Objects.Set_Object (Object, Impl.all'Access);
end Allocate;
-- ----------------------------------------
-- Data object: Changelog
-- ----------------------------------------
procedure Set_Id (Object : in out Changelog_Ref;
Value : in ADO.Identifier) is
Impl : Changelog_Access;
begin
Set_Field (Object, Impl);
ADO.Objects.Set_Field_Key_Value (Impl.all, 1, Value);
end Set_Id;
function Get_Id (Object : in Changelog_Ref)
return ADO.Identifier is
Impl : constant Changelog_Access
:= Changelog_Impl (Object.Get_Object.all)'Access;
begin
return Impl.Get_Key_Value;
end Get_Id;
procedure Set_Date (Object : in out Changelog_Ref;
Value : in Ada.Calendar.Time) is
Impl : Changelog_Access;
begin
Set_Field (Object, Impl);
ADO.Objects.Set_Field_Time (Impl.all, 2, Impl.Date, Value);
end Set_Date;
function Get_Date (Object : in Changelog_Ref)
return Ada.Calendar.Time is
Impl : constant Changelog_Access
:= Changelog_Impl (Object.Get_Load_Object.all)'Access;
begin
return Impl.Date;
end Get_Date;
procedure Set_Text (Object : in out Changelog_Ref;
Value : in String) is
Impl : Changelog_Access;
begin
Set_Field (Object, Impl);
ADO.Objects.Set_Field_String (Impl.all, 3, Impl.Text, Value);
end Set_Text;
procedure Set_Text (Object : in out Changelog_Ref;
Value : in Ada.Strings.Unbounded.Unbounded_String) is
Impl : Changelog_Access;
begin
Set_Field (Object, Impl);
ADO.Objects.Set_Field_Unbounded_String (Impl.all, 3, Impl.Text, Value);
end Set_Text;
function Get_Text (Object : in Changelog_Ref)
return String is
begin
return Ada.Strings.Unbounded.To_String (Object.Get_Text);
end Get_Text;
function Get_Text (Object : in Changelog_Ref)
return Ada.Strings.Unbounded.Unbounded_String is
Impl : constant Changelog_Access
:= Changelog_Impl (Object.Get_Load_Object.all)'Access;
begin
return Impl.Text;
end Get_Text;
procedure Set_For_Entity_Id (Object : in out Changelog_Ref;
Value : in ADO.Identifier) is
Impl : Changelog_Access;
begin
Set_Field (Object, Impl);
ADO.Objects.Set_Field_Identifier (Impl.all, 4, Impl.For_Entity_Id, Value);
end Set_For_Entity_Id;
function Get_For_Entity_Id (Object : in Changelog_Ref)
return ADO.Identifier is
Impl : constant Changelog_Access
:= Changelog_Impl (Object.Get_Load_Object.all)'Access;
begin
return Impl.For_Entity_Id;
end Get_For_Entity_Id;
procedure Set_User (Object : in out Changelog_Ref;
Value : in AWA.Users.Models.User_Ref'Class) is
Impl : Changelog_Access;
begin
Set_Field (Object, Impl);
ADO.Objects.Set_Field_Object (Impl.all, 5, Impl.User, Value);
end Set_User;
function Get_User (Object : in Changelog_Ref)
return AWA.Users.Models.User_Ref'Class is
Impl : constant Changelog_Access
:= Changelog_Impl (Object.Get_Load_Object.all)'Access;
begin
return Impl.User;
end Get_User;
procedure Set_Entity_Type (Object : in out Changelog_Ref;
Value : in ADO.Entity_Type) is
Impl : Changelog_Access;
begin
Set_Field (Object, Impl);
ADO.Objects.Set_Field_Entity_Type (Impl.all, 6, Impl.Entity_Type, Value);
end Set_Entity_Type;
function Get_Entity_Type (Object : in Changelog_Ref)
return ADO.Entity_Type is
Impl : constant Changelog_Access
:= Changelog_Impl (Object.Get_Load_Object.all)'Access;
begin
return Impl.Entity_Type;
end Get_Entity_Type;
-- Copy of the object.
procedure Copy (Object : in Changelog_Ref;
Into : in out Changelog_Ref) is
Result : Changelog_Ref;
begin
if not Object.Is_Null then
declare
Impl : constant Changelog_Access
:= Changelog_Impl (Object.Get_Load_Object.all)'Access;
Copy : constant Changelog_Access
:= new Changelog_Impl;
begin
ADO.Objects.Set_Object (Result, Copy.all'Access);
Copy.Copy (Impl.all);
Copy.Date := Impl.Date;
Copy.Text := Impl.Text;
Copy.For_Entity_Id := Impl.For_Entity_Id;
Copy.User := Impl.User;
Copy.Entity_Type := Impl.Entity_Type;
end;
end if;
Into := Result;
end Copy;
overriding
procedure Find (Object : in out Changelog_Ref;
Session : in out ADO.Sessions.Session'Class;
Query : in ADO.SQL.Query'Class;
Found : out Boolean) is
Impl : constant Changelog_Access := new Changelog_Impl;
begin
Impl.Find (Session, Query, Found);
if Found then
ADO.Objects.Set_Object (Object, Impl.all'Access);
else
ADO.Objects.Set_Object (Object, null);
Destroy (Impl);
end if;
end Find;
procedure Load (Object : in out Changelog_Ref;
Session : in out ADO.Sessions.Session'Class;
Id : in ADO.Identifier) is
Impl : constant Changelog_Access := new Changelog_Impl;
Found : Boolean;
Query : ADO.SQL.Query;
begin
Query.Bind_Param (Position => 1, Value => Id);
Query.Set_Filter ("id = ?");
Impl.Find (Session, Query, Found);
if not Found then
Destroy (Impl);
raise ADO.Objects.NOT_FOUND;
end if;
ADO.Objects.Set_Object (Object, Impl.all'Access);
end Load;
procedure Load (Object : in out Changelog_Ref;
Session : in out ADO.Sessions.Session'Class;
Id : in ADO.Identifier;
Found : out Boolean) is
Impl : constant Changelog_Access := new Changelog_Impl;
Query : ADO.SQL.Query;
begin
Query.Bind_Param (Position => 1, Value => Id);
Query.Set_Filter ("id = ?");
Impl.Find (Session, Query, Found);
if not Found then
Destroy (Impl);
else
ADO.Objects.Set_Object (Object, Impl.all'Access);
end if;
end Load;
overriding
procedure Save (Object : in out Changelog_Ref;
Session : in out ADO.Sessions.Master_Session'Class) is
Impl : ADO.Objects.Object_Record_Access := Object.Get_Object;
begin
if Impl = null then
Impl := new Changelog_Impl;
ADO.Objects.Set_Object (Object, Impl);
end if;
if not ADO.Objects.Is_Created (Impl.all) then
Impl.Create (Session);
else
Impl.Save (Session);
end if;
end Save;
overriding
procedure Delete (Object : in out Changelog_Ref;
Session : in out ADO.Sessions.Master_Session'Class) is
Impl : constant ADO.Objects.Object_Record_Access := Object.Get_Object;
begin
if Impl /= null then
Impl.Delete (Session);
end if;
end Delete;
-- --------------------
-- Free the object
-- --------------------
overriding
procedure Destroy (Object : access Changelog_Impl) is
type Changelog_Impl_Ptr is access all Changelog_Impl;
procedure Unchecked_Free is new Ada.Unchecked_Deallocation
(Changelog_Impl, Changelog_Impl_Ptr);
pragma Warnings (Off, "*redundant conversion*");
Ptr : Changelog_Impl_Ptr := Changelog_Impl (Object.all)'Access;
pragma Warnings (On, "*redundant conversion*");
begin
Unchecked_Free (Ptr);
end Destroy;
overriding
procedure Find (Object : in out Changelog_Impl;
Session : in out ADO.Sessions.Session'Class;
Query : in ADO.SQL.Query'Class;
Found : out Boolean) is
Stmt : ADO.Statements.Query_Statement
:= Session.Create_Statement (Query, CHANGELOG_DEF'Access);
begin
Stmt.Execute;
if Stmt.Has_Elements then
Object.Load (Stmt, Session);
Stmt.Next;
Found := not Stmt.Has_Elements;
else
Found := False;
end if;
end Find;
overriding
procedure Load (Object : in out Changelog_Impl;
Session : in out ADO.Sessions.Session'Class) is
Found : Boolean;
Query : ADO.SQL.Query;
Id : constant ADO.Identifier := Object.Get_Key_Value;
begin
Query.Bind_Param (Position => 1, Value => Id);
Query.Set_Filter ("id = ?");
Object.Find (Session, Query, Found);
if not Found then
raise ADO.Objects.NOT_FOUND;
end if;
end Load;
overriding
procedure Save (Object : in out Changelog_Impl;
Session : in out ADO.Sessions.Master_Session'Class) is
Stmt : ADO.Statements.Update_Statement
:= Session.Create_Statement (CHANGELOG_DEF'Access);
begin
if Object.Is_Modified (1) then
Stmt.Save_Field (Name => COL_0_1_NAME, -- id
Value => Object.Get_Key);
Object.Clear_Modified (1);
end if;
if Object.Is_Modified (2) then
Stmt.Save_Field (Name => COL_1_1_NAME, -- date
Value => Object.Date);
Object.Clear_Modified (2);
end if;
if Object.Is_Modified (3) then
Stmt.Save_Field (Name => COL_2_1_NAME, -- text
Value => Object.Text);
Object.Clear_Modified (3);
end if;
if Object.Is_Modified (4) then
Stmt.Save_Field (Name => COL_3_1_NAME, -- for_entity_id
Value => Object.For_Entity_Id);
Object.Clear_Modified (4);
end if;
if Object.Is_Modified (5) then
Stmt.Save_Field (Name => COL_4_1_NAME, -- user_id
Value => Object.User);
Object.Clear_Modified (5);
end if;
if Object.Is_Modified (6) then
Stmt.Save_Field (Name => COL_5_1_NAME, -- entity_type
Value => Object.Entity_Type);
Object.Clear_Modified (6);
end if;
if Stmt.Has_Save_Fields then
Stmt.Set_Filter (Filter => "id = ?");
Stmt.Add_Param (Value => Object.Get_Key);
declare
Result : Integer;
begin
Stmt.Execute (Result);
if Result /= 1 then
if Result /= 0 then
raise ADO.Objects.UPDATE_ERROR;
end if;
end if;
end;
end if;
end Save;
overriding
procedure Create (Object : in out Changelog_Impl;
Session : in out ADO.Sessions.Master_Session'Class) is
Query : ADO.Statements.Insert_Statement
:= Session.Create_Statement (CHANGELOG_DEF'Access);
Result : Integer;
begin
Session.Allocate (Id => Object);
Query.Save_Field (Name => COL_0_1_NAME, -- id
Value => Object.Get_Key);
Query.Save_Field (Name => COL_1_1_NAME, -- date
Value => Object.Date);
Query.Save_Field (Name => COL_2_1_NAME, -- text
Value => Object.Text);
Query.Save_Field (Name => COL_3_1_NAME, -- for_entity_id
Value => Object.For_Entity_Id);
Query.Save_Field (Name => COL_4_1_NAME, -- user_id
Value => Object.User);
Query.Save_Field (Name => COL_5_1_NAME, -- entity_type
Value => Object.Entity_Type);
Query.Execute (Result);
if Result /= 1 then
raise ADO.Objects.INSERT_ERROR;
end if;
ADO.Objects.Set_Created (Object);
end Create;
overriding
procedure Delete (Object : in out Changelog_Impl;
Session : in out ADO.Sessions.Master_Session'Class) is
Stmt : ADO.Statements.Delete_Statement
:= Session.Create_Statement (CHANGELOG_DEF'Access);
begin
Stmt.Set_Filter (Filter => "id = ?");
Stmt.Add_Param (Value => Object.Get_Key);
Stmt.Execute;
end Delete;
-- ------------------------------
-- Get the bean attribute identified by the name.
-- ------------------------------
overriding
function Get_Value (From : in Changelog_Ref;
Name : in String) return Util.Beans.Objects.Object is
Obj : ADO.Objects.Object_Record_Access;
Impl : access Changelog_Impl;
begin
if From.Is_Null then
return Util.Beans.Objects.Null_Object;
end if;
Obj := From.Get_Load_Object;
Impl := Changelog_Impl (Obj.all)'Access;
if Name = "id" then
return ADO.Objects.To_Object (Impl.Get_Key);
elsif Name = "date" then
return Util.Beans.Objects.Time.To_Object (Impl.Date);
elsif Name = "text" then
return Util.Beans.Objects.To_Object (Impl.Text);
elsif Name = "for_entity_id" then
return Util.Beans.Objects.To_Object (Long_Long_Integer (Impl.For_Entity_Id));
elsif Name = "entity_type" then
return Util.Beans.Objects.To_Object (Long_Long_Integer (Impl.Entity_Type));
end if;
return Util.Beans.Objects.Null_Object;
end Get_Value;
-- ------------------------------
-- Load the object from current iterator position
-- ------------------------------
procedure Load (Object : in out Changelog_Impl;
Stmt : in out ADO.Statements.Query_Statement'Class;
Session : in out ADO.Sessions.Session'Class) is
begin
Object.Set_Key_Value (Stmt.Get_Identifier (0));
Object.Date := Stmt.Get_Time (1);
Object.Text := Stmt.Get_Unbounded_String (2);
Object.For_Entity_Id := Stmt.Get_Identifier (3);
if not Stmt.Is_Null (4) then
Object.User.Set_Key_Value (Stmt.Get_Identifier (4), Session);
end if;
Object.Entity_Type := ADO.Entity_Type (Stmt.Get_Integer (5));
ADO.Objects.Set_Created (Object);
end Load;
end AWA.Changelogs.Models;
|
reznikmm/matreshka | Ada | 8,892 | adb | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Web Framework --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2016-2017, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
with League.Calendars;
package body WUI.Widgets.Grid_Views is
package Renderers is
type Cell_Visiter is new WUI.Grid_Models.Cell_Visiter with record
Value : League.Strings.Universal_String;
end record;
overriding procedure String_Cell
(Self : not null access Cell_Visiter;
Value : League.Strings.Universal_String);
overriding procedure Integer_Cell
(Self : not null access Cell_Visiter;
Value : Integer);
overriding procedure Date_Time_Cell
(Self : not null access Cell_Visiter;
Value : League.Calendars.Date_Time);
end Renderers;
------------------
-- Constructors --
------------------
package body Constructors is
----------------
-- Initialize --
----------------
procedure Initialize
(Self : in out Grid_View'Class;
Parent : not null access WUI.Widgets.Abstract_Widget'Class)
is
Document : constant WebAPI.DOM.Documents.Document_Access :=
Parent.Element.Get_Owner_Document;
Grid : constant not null WebAPI.DOM.Elements.Element_Access :=
Document.Create_Element (+"div");
Head : constant not null WebAPI.DOM.Elements.Element_Access :=
Document.Create_Element (+"div");
Table_H : constant not null WebAPI.DOM.Elements.Element_Access :=
Document.Create_Element (+"table");
Data : constant not null WebAPI.DOM.Elements.Element_Access :=
Document.Create_Element (+"div");
Table_D : constant not null WebAPI.DOM.Elements.Element_Access :=
Document.Create_Element (+"table");
begin
WUI.Widgets.Constructors.Initialize
(Self, WebAPI.HTML.Elements.HTML_Element_Access (Grid));
Self.Document := Document;
Self.Header := Table_H;
Self.Data := Table_D;
Grid.Set_Class_Name (+"grid row scroll-x");
Head.Set_Class_Name (+"grid-head row");
Head.Append_Child (Table_H);
Grid.Append_Child (Head);
Data.Set_Class_Name (+"grid-data row scroll-y");
Data.Append_Child (Table_D);
Grid.Append_Child (Data);
Parent.Element.Append_Child (Grid);
end Initialize;
end Constructors;
---------------
-- Renderers --
---------------
package body Renderers is
-----------------
-- String_Cell --
-----------------
overriding procedure String_Cell
(Self : not null access Cell_Visiter;
Value : League.Strings.Universal_String) is
begin
Self.Value := Value;
end String_Cell;
------------------
-- Integer_Cell --
------------------
overriding procedure Integer_Cell
(Self : not null access Cell_Visiter;
Value : Integer) is
begin
Self.Value := +Integer'Wide_Wide_Image (Value);
end Integer_Cell;
--------------------
-- Date_Time_Cell --
--------------------
overriding procedure Date_Time_Cell
(Self : not null access Cell_Visiter;
Value : League.Calendars.Date_Time) is
begin
Self.Value := +"date rendering is not implemented";
end Date_Time_Cell;
end Renderers;
---------------
-- Set_Model --
---------------
not overriding procedure Set_Model
(Self : in out Grid_View;
Header : not null WUI.Widgets.Grid_Views.Grid_Header_Access;
Model : not null WUI.Grid_Models.Grid_Model_Access)
is
Rows : constant Natural := Model.Row_Count;
Columns : constant Natural := Model.Column_Count;
Renderer : aliased Renderers.Cell_Visiter;
TR : WebAPI.DOM.Elements.Element_Access :=
Self.Document.Create_Element (+"tr");
begin
for J in 1 .. Columns loop
declare
Width : constant Natural := Header.Width (Column => J);
Column_H : constant WebAPI.DOM.Elements.Element_Access :=
Self.Document.Create_Element (+"col");
Column_D : constant WebAPI.DOM.Elements.Element_Access :=
Self.Document.Create_Element (+"col");
TH : constant WebAPI.DOM.Elements.Element_Access :=
Self.Document.Create_Element (+"th");
begin
Column_H.Set_Attribute
(+"width", +Natural'Wide_Wide_Image (Width));
Column_D.Set_Attribute
(+"width", +Natural'Wide_Wide_Image (Width));
Self.Header.Append_Child (Column_H);
Self.Data.Append_Child (Column_D);
TH.Set_Text_Content (Text (Header, J));
TR.Append_Child (TH);
end;
end loop;
Self.Header.Append_Child (TR);
for R in 1 .. Rows loop
declare
Row : constant WUI.Grid_Models.Row_Access := Model.Row (R);
begin
TR := Self.Document.Create_Element (+"tr");
for J in 1 .. Columns loop
declare
TD : constant WebAPI.DOM.Elements.Element_Access :=
Self.Document.Create_Element (+"td");
begin
Model.Visit_Cell (Row, J, Renderer'Unchecked_Access);
TD.Set_Text_Content (Renderer.Value);
TR.Append_Child (TD);
end;
end loop;
TR.Set_Attribute (+"tabindex", +"1");
Self.Data.Append_Child (TR);
end;
end loop;
end Set_Model;
end WUI.Widgets.Grid_Views;
|
AdaCore/libadalang | Ada | 110 | ads | with Baz;
package Bar is
R : Baz.Record_Type := (A => 1);
function Pouet return Baz.Integer;
end Bar;
|
reznikmm/matreshka | Ada | 5,130 | ads | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Ada Modeling Framework --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2011-2012, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
-- This file is generated, don't edit it.
------------------------------------------------------------------------------
with AMF.Generic_Collections;
package AMF.UML.Literal_Integers.Collections is
pragma Preelaborate;
package UML_Literal_Integer_Collections is
new AMF.Generic_Collections
(UML_Literal_Integer,
UML_Literal_Integer_Access);
type Set_Of_UML_Literal_Integer is
new UML_Literal_Integer_Collections.Set with null record;
Empty_Set_Of_UML_Literal_Integer : constant Set_Of_UML_Literal_Integer;
type Ordered_Set_Of_UML_Literal_Integer is
new UML_Literal_Integer_Collections.Ordered_Set with null record;
Empty_Ordered_Set_Of_UML_Literal_Integer : constant Ordered_Set_Of_UML_Literal_Integer;
type Bag_Of_UML_Literal_Integer is
new UML_Literal_Integer_Collections.Bag with null record;
Empty_Bag_Of_UML_Literal_Integer : constant Bag_Of_UML_Literal_Integer;
type Sequence_Of_UML_Literal_Integer is
new UML_Literal_Integer_Collections.Sequence with null record;
Empty_Sequence_Of_UML_Literal_Integer : constant Sequence_Of_UML_Literal_Integer;
private
Empty_Set_Of_UML_Literal_Integer : constant Set_Of_UML_Literal_Integer
:= (UML_Literal_Integer_Collections.Set with null record);
Empty_Ordered_Set_Of_UML_Literal_Integer : constant Ordered_Set_Of_UML_Literal_Integer
:= (UML_Literal_Integer_Collections.Ordered_Set with null record);
Empty_Bag_Of_UML_Literal_Integer : constant Bag_Of_UML_Literal_Integer
:= (UML_Literal_Integer_Collections.Bag with null record);
Empty_Sequence_Of_UML_Literal_Integer : constant Sequence_Of_UML_Literal_Integer
:= (UML_Literal_Integer_Collections.Sequence with null record);
end AMF.UML.Literal_Integers.Collections;
|
leo-brewin/ada-lapack | Ada | 2,344 | adb | with Ada.Text_IO;
with Ada.Text_IO.Complex_IO;
with Ada.Numerics.Generic_Real_Arrays;
with Ada.Numerics.Generic_Complex_Types;
with Ada.Numerics.Generic_Complex_Arrays;
with Ada.Numerics.Generic_Elementary_Functions;
with Ada.Numerics.Generic_Complex_Elementary_Functions;
with Ada_Lapack;
with Ada_Lapack.Extras;
use Ada.Text_IO;
procedure example02 is
type Real is digits 18;
package Real_Arrays is new Ada.Numerics.Generic_Real_Arrays (Real);
package Complex_Types is new Ada.Numerics.Generic_Complex_Types (Real);
package Complex_Arrays is new Ada.Numerics.Generic_Complex_Arrays (Real_Arrays, Complex_Types);
package Real_Maths is new Ada.Numerics.Generic_Elementary_Functions (Real);
package Complex_Maths is new Ada.Numerics.Generic_Complex_Elementary_Functions (Complex_Types);
package Real_IO is new Ada.Text_IO.Float_IO (Real);
package Integer_IO is new Ada.Text_IO.Integer_IO (Integer);
package Complex_IO is new Ada.Text_IO.Complex_IO (Complex_Types);
package Lapack is new Ada_Lapack(Real, Complex_Types, Real_Arrays, Complex_Arrays);
package Extras is new Lapack.Extras;
use Lapack;
use Extras;
use Real_Arrays;
use Complex_Types;
use Complex_Arrays;
use Real_IO;
use Integer_IO;
use Complex_IO;
use Real_Maths;
use Complex_Maths;
matrix : Complex_Matrix (1..4,1..4);
eigenvectors : Complex_Matrix (1..4,1..4);
eigenvalues : Complex_Vector (1..4);
begin
matrix:= ((( -3.84, 2.25), ( -8.94, -4.75), ( 8.95, -6.53), ( -9.87, 4.82)),
(( -0.66, 0.83), ( -4.40, -3.82), ( -3.50, -4.26), ( -3.15, 7.36)),
(( -3.99, -4.73), ( -5.88, -6.60), ( -3.36, -0.40), ( -0.75, 5.23)),
(( 7.74, 4.18), ( 3.66, -7.53), ( 2.58, 3.60), ( 4.59, 5.41)));
EigenSystem(matrix,eigenvalues,eigenvectors);
Put_line("The eigenvalues");
for i in eigenvalues'range loop
put(eigenvalues(i),3,4,0);
put(" ");
end loop;
new_line;
new_line;
Put_line("The right eigenvectors");
for i in eigenvectors'range(1) loop
for j in eigenvectors'range(2) loop
put(eigenvectors(i,j),3,4,0);
put(" ");
end loop;
new_line;
end loop;
end example02;
|
zhmu/ananas | Ada | 9,051 | adb | ------------------------------------------------------------------------------
-- --
-- GNAT RUN-TIME COMPONENTS --
-- --
-- S Y S T E M . P A C K _ 8 4 --
-- --
-- B o d y --
-- --
-- Copyright (C) 1992-2022, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. --
-- --
-- As a special exception under Section 7 of GPL version 3, you are granted --
-- additional permissions described in the GCC Runtime Library Exception, --
-- version 3.1, as published by the Free Software Foundation. --
-- --
-- You should have received a copy of the GNU General Public License and --
-- a copy of the GCC Runtime Library Exception along with this program; --
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
-- <http://www.gnu.org/licenses/>. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
with System.Storage_Elements;
with System.Unsigned_Types;
package body System.Pack_84 is
subtype Bit_Order is System.Bit_Order;
Reverse_Bit_Order : constant Bit_Order :=
Bit_Order'Val (1 - Bit_Order'Pos (System.Default_Bit_Order));
subtype Ofs is System.Storage_Elements.Storage_Offset;
subtype Uns is System.Unsigned_Types.Unsigned;
subtype N07 is System.Unsigned_Types.Unsigned range 0 .. 7;
use type System.Storage_Elements.Storage_Offset;
use type System.Unsigned_Types.Unsigned;
type Cluster is record
E0, E1, E2, E3, E4, E5, E6, E7 : Bits_84;
end record;
for Cluster use record
E0 at 0 range 0 * Bits .. 0 * Bits + Bits - 1;
E1 at 0 range 1 * Bits .. 1 * Bits + Bits - 1;
E2 at 0 range 2 * Bits .. 2 * Bits + Bits - 1;
E3 at 0 range 3 * Bits .. 3 * Bits + Bits - 1;
E4 at 0 range 4 * Bits .. 4 * Bits + Bits - 1;
E5 at 0 range 5 * Bits .. 5 * Bits + Bits - 1;
E6 at 0 range 6 * Bits .. 6 * Bits + Bits - 1;
E7 at 0 range 7 * Bits .. 7 * Bits + Bits - 1;
end record;
for Cluster'Size use Bits * 8;
for Cluster'Alignment use Integer'Min (Standard'Maximum_Alignment,
1 +
1 * Boolean'Pos (Bits mod 2 = 0) +
2 * Boolean'Pos (Bits mod 4 = 0));
-- Use maximum possible alignment, given the bit field size, since this
-- will result in the most efficient code possible for the field.
type Cluster_Ref is access Cluster;
type Rev_Cluster is new Cluster
with Bit_Order => Reverse_Bit_Order,
Scalar_Storage_Order => Reverse_Bit_Order;
type Rev_Cluster_Ref is access Rev_Cluster;
-- The following declarations are for the case where the address
-- passed to GetU_84 or SetU_84 is not guaranteed to be aligned.
-- These routines are used when the packed array is itself a
-- component of a packed record, and therefore may not be aligned.
type ClusterU is new Cluster;
for ClusterU'Alignment use 1;
type ClusterU_Ref is access ClusterU;
type Rev_ClusterU is new ClusterU
with Bit_Order => Reverse_Bit_Order,
Scalar_Storage_Order => Reverse_Bit_Order;
type Rev_ClusterU_Ref is access Rev_ClusterU;
------------
-- Get_84 --
------------
function Get_84
(Arr : System.Address;
N : Natural;
Rev_SSO : Boolean) return Bits_84
is
A : constant System.Address := Arr + Bits * Ofs (Uns (N) / 8);
C : Cluster_Ref with Address => A'Address, Import;
RC : Rev_Cluster_Ref with Address => A'Address, Import;
begin
if Rev_SSO then
case N07 (Uns (N) mod 8) is
when 0 => return RC.E0;
when 1 => return RC.E1;
when 2 => return RC.E2;
when 3 => return RC.E3;
when 4 => return RC.E4;
when 5 => return RC.E5;
when 6 => return RC.E6;
when 7 => return RC.E7;
end case;
else
case N07 (Uns (N) mod 8) is
when 0 => return C.E0;
when 1 => return C.E1;
when 2 => return C.E2;
when 3 => return C.E3;
when 4 => return C.E4;
when 5 => return C.E5;
when 6 => return C.E6;
when 7 => return C.E7;
end case;
end if;
end Get_84;
-------------
-- GetU_84 --
-------------
function GetU_84
(Arr : System.Address;
N : Natural;
Rev_SSO : Boolean) return Bits_84
is
A : constant System.Address := Arr + Bits * Ofs (Uns (N) / 8);
C : ClusterU_Ref with Address => A'Address, Import;
RC : Rev_ClusterU_Ref with Address => A'Address, Import;
begin
if Rev_SSO then
case N07 (Uns (N) mod 8) is
when 0 => return RC.E0;
when 1 => return RC.E1;
when 2 => return RC.E2;
when 3 => return RC.E3;
when 4 => return RC.E4;
when 5 => return RC.E5;
when 6 => return RC.E6;
when 7 => return RC.E7;
end case;
else
case N07 (Uns (N) mod 8) is
when 0 => return C.E0;
when 1 => return C.E1;
when 2 => return C.E2;
when 3 => return C.E3;
when 4 => return C.E4;
when 5 => return C.E5;
when 6 => return C.E6;
when 7 => return C.E7;
end case;
end if;
end GetU_84;
------------
-- Set_84 --
------------
procedure Set_84
(Arr : System.Address;
N : Natural;
E : Bits_84;
Rev_SSO : Boolean)
is
A : constant System.Address := Arr + Bits * Ofs (Uns (N) / 8);
C : Cluster_Ref with Address => A'Address, Import;
RC : Rev_Cluster_Ref with Address => A'Address, Import;
begin
if Rev_SSO then
case N07 (Uns (N) mod 8) is
when 0 => RC.E0 := E;
when 1 => RC.E1 := E;
when 2 => RC.E2 := E;
when 3 => RC.E3 := E;
when 4 => RC.E4 := E;
when 5 => RC.E5 := E;
when 6 => RC.E6 := E;
when 7 => RC.E7 := E;
end case;
else
case N07 (Uns (N) mod 8) is
when 0 => C.E0 := E;
when 1 => C.E1 := E;
when 2 => C.E2 := E;
when 3 => C.E3 := E;
when 4 => C.E4 := E;
when 5 => C.E5 := E;
when 6 => C.E6 := E;
when 7 => C.E7 := E;
end case;
end if;
end Set_84;
-------------
-- SetU_84 --
-------------
procedure SetU_84
(Arr : System.Address;
N : Natural;
E : Bits_84;
Rev_SSO : Boolean)
is
A : constant System.Address := Arr + Bits * Ofs (Uns (N) / 8);
C : ClusterU_Ref with Address => A'Address, Import;
RC : Rev_ClusterU_Ref with Address => A'Address, Import;
begin
if Rev_SSO then
case N07 (Uns (N) mod 8) is
when 0 => RC.E0 := E;
when 1 => RC.E1 := E;
when 2 => RC.E2 := E;
when 3 => RC.E3 := E;
when 4 => RC.E4 := E;
when 5 => RC.E5 := E;
when 6 => RC.E6 := E;
when 7 => RC.E7 := E;
end case;
else
case N07 (Uns (N) mod 8) is
when 0 => C.E0 := E;
when 1 => C.E1 := E;
when 2 => C.E2 := E;
when 3 => C.E3 := E;
when 4 => C.E4 := E;
when 5 => C.E5 := E;
when 6 => C.E6 := E;
when 7 => C.E7 := E;
end case;
end if;
end SetU_84;
end System.Pack_84;
|
rveenker/sdlada | Ada | 2,553 | ads | --------------------------------------------------------------------------------------------------------------------
-- Copyright (c) 2013-2020, Luke A. Guest
--
-- This software is provided 'as-is', without any express or implied
-- warranty. In no event will the authors be held liable for any damages
-- arising from the use of this software.
--
-- Permission is granted to anyone to use this software for any purpose,
-- including commercial applications, and to alter it and redistribute it
-- freely, subject to the following restrictions:
--
-- 1. The origin of this software must not be misrepresented; you must not
-- claim that you wrote the original software. If you use this software
-- in a product, an acknowledgment in the product documentation would be
-- appreciated but is not required.
--
-- 2. Altered source versions must be plainly marked as such, and must not be
-- misrepresented as being the original software.
--
-- 3. This notice may not be removed or altered from any source
-- distribution.
--------------------------------------------------------------------------------------------------------------------
-- SDL.Versions
--
-- Library version information.
--------------------------------------------------------------------------------------------------------------------
package SDL.Versions is
type Version_Level is mod 2 ** 8 with
Size => 8,
Convention => C;
-- TODO: Check this against the library, as they use an int.
type Revision_Level is mod 2 ** 32;
type Version is
record
Major : Version_Level;
Minor : Version_Level;
Patch : Version_Level;
end record with
Convention => C;
-- These allow the user to determine which version of SDLAda they compiled with.
Compiled_Major : constant Version_Level with
Import => True,
Convention => C,
External_Name => "SDL_Ada_Major_Version";
Compiled_Minor : constant Version_Level with
Import => True,
Convention => C,
External_Name => "SDL_Ada_Minor_Version";
Compiled_Patch : constant Version_Level with
Import => True,
Convention => C,
External_Name => "SDL_Ada_Patch_Version";
Compiled : constant Version := (Major => Compiled_Major, Minor => Compiled_Minor, Patch => Compiled_Patch);
function Revision return String with
Inline => True;
function Revision return Revision_Level;
procedure Linked_With (Info : in out Version);
end SDL.Versions;
|
reznikmm/matreshka | Ada | 12,440 | adb | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Web Framework --
-- --
-- Tools Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2015, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
with Ada.Wide_Wide_Text_IO;
with Asis.Declarations;
with Asis.Definitions;
with Asis.Elements;
with Asis.Expressions;
with Asis.Statements;
with Properties.Tools;
with Properties.Expressions.Identifiers;
package body Properties.Statements.Procedure_Call_Statement is
function Intrinsic
(Engine : access Engines.Contexts.Context;
Element : Asis.Expression;
Name : Engines.Text_Property) return League.Strings.Universal_String;
----------
-- Code --
----------
function Code
(Engine : access Engines.Contexts.Context;
Element : Asis.Statement;
Name : Engines.Text_Property) return League.Strings.Universal_String
is
use type Engines.Convention_Kind;
function Get_Parameters
(Prefix : Asis.Expression;
Is_Dispatching : Boolean;
Is_JavaScript : Boolean)
return Asis.Parameter_Specification_List
is
begin
if not Is_Dispatching and not Is_JavaScript then
return Properties.Tools.Parameter_Profile (Prefix);
elsif Asis.Statements.Is_Dispatching_Call (Element) then
declare
Decl : constant Asis.Declaration :=
Properties.Tools.Corresponding_Declaration (Prefix);
begin
case Asis.Elements.Declaration_Kind (Decl) is
when
Asis.A_Procedure_Declaration |
Asis.A_Function_Declaration |
Asis.A_Procedure_Body_Declaration |
Asis.A_Function_Body_Declaration |
Asis.A_Null_Procedure_Declaration |
Asis.A_Procedure_Renaming_Declaration |
Asis.A_Function_Renaming_Declaration |
Asis.An_Entry_Declaration |
Asis.An_Entry_Body_Declaration |
Asis.A_Procedure_Body_Stub |
Asis.A_Function_Body_Stub |
Asis.A_Generic_Function_Declaration |
Asis.A_Generic_Procedure_Declaration |
Asis.A_Formal_Function_Declaration |
Asis.A_Formal_Procedure_Declaration |
Asis.An_Expression_Function_Declaration =>
return Asis.Declarations.Parameter_Profile (Decl);
when others =>
return Asis.Nil_Element_List;
end case;
end;
else
return Asis.Nil_Element_List;
end if;
end Get_Parameters;
Text : League.Strings.Universal_String;
Prefix : constant Asis.Expression :=
Asis.Statements.Called_Name (Element);
Conv : constant Engines.Convention_Kind :=
Engine.Call_Convention.Get_Property
(Prefix,
Engines.Call_Convention);
Is_Dispatching : constant Boolean := Engine.Boolean.Get_Property
(Prefix, Engines.Is_Dispatching);
Is_Prefixed : constant Boolean :=
Conv in Engines.JavaScript_Property_Setter |
Engines.JavaScript_Method;
Params : constant Asis.Parameter_Specification_List :=
Get_Parameters (Prefix, Is_Dispatching, Is_Prefixed);
Has_Output : constant Boolean :=
Engine.Boolean.Get_Property
(List => Params,
Name => Engines.Has_Simple_Output,
Empty => False,
Sum => Properties.Tools."or"'Access);
List : constant Asis.Association_List :=
Asis.Statements.Call_Statement_Parameters
(Element, Normalized => False);
Arg : League.Strings.Universal_String;
begin
if Has_Output then
Text.Append ("var _r=");
end if;
if Conv = Engines.Intrinsic then
Arg := Intrinsic (Engine, Element, Name);
Text.Append (Arg);
elsif not Is_Dispatching and not Is_Prefixed then
Arg := Engine.Text.Get_Property (Prefix, Name);
Text.Append (Arg);
Text.Append ("(");
for J in 1 .. List'Last loop
Arg := Engine.Text.Get_Property
(Asis.Expressions.Actual_Parameter (List (J)), Name);
Text.Append (Arg);
if J /= List'Last then
Text.Append (", ");
end if;
end loop;
Text.Append (")");
elsif Conv = Engines.JavaScript_Property_Setter then
Arg := Engine.Text.Get_Property
(Asis.Expressions.Actual_Parameter (List (1)), Name);
Text.Append (Arg);
Text.Append (".");
Text.Append
(Engine.Text.Get_Property (Prefix, Engines.Method_Name));
Text.Append (" = ");
Arg := Engine.Text.Get_Property
(Asis.Expressions.Actual_Parameter (List (2)), Name);
Text.Append (Arg);
elsif Asis.Statements.Is_Dispatching_Call (Element) or
Conv = Engines.JavaScript_Method
then
declare
Expr : Asis.Expression;
Decl : Asis.Declaration;
Comp : Asis.Definition;
begin
Arg := Engine.Text.Get_Property
(Asis.Expressions.Actual_Parameter (List (1)), Name);
Text.Append (Arg);
Text.Append (".");
Text.Append
(Engine.Text.Get_Property (Prefix, Engines.Method_Name));
Text.Append ("(");
for J in 2 .. List'Last loop
Expr := Asis.Expressions.Actual_Parameter (List (J));
Arg := Engine.Text.Get_Property (Expr, Name);
Text.Append (Arg);
Decl := Asis.Expressions.Corresponding_Expression_Type (Expr);
if Tools.Is_Array (Expr)
and then Tools.Is_Array_Buffer (Decl)
then
Comp := Asis.Definitions.Array_Component_Definition
(Tools.Type_Declaration_View (Decl));
Comp := Asis.Definitions.Component_Definition_View (Comp);
Arg := Engine.Text.Get_Property
(Comp, Engines.Typed_Array_Item_Type);
if not Arg.Is_Empty then
Text.Append (".");
Text.Append (Arg);
end if;
end if;
if J /= List'Last then
Text.Append (", ");
end if;
end loop;
Text.Append (")");
end;
else
declare
Proc : Asis.Declaration :=
Asis.Statements.Corresponding_Called_Entity (Element);
begin
while Asis.Elements.Is_Part_Of_Inherited (Proc) loop
Proc :=
Asis.Declarations.Corresponding_Subprogram_Derivation (Proc);
end loop;
Arg := Properties.Expressions.Identifiers.Name_Prefix
(Engine => Engine,
Name => Element,
Decl => Proc);
Text.Append (Arg);
Text.Append
(Engine.Text.Get_Property
(Asis.Declarations.Names (Proc) (1), Name));
Text.Append (".call(");
Text.Append
(Engine.Text.Get_Property
(Asis.Expressions.Actual_Parameter (List (1)), Name));
for J in 2 .. List'Last loop
Arg := Engine.Text.Get_Property
(Asis.Expressions.Actual_Parameter (List (J)), Name);
Text.Append (", ");
Text.Append (Arg);
end loop;
Text.Append (")");
end;
end if;
for J in Params'Range loop
if Engine.Boolean.Get_Property
(Params (J), Engines.Has_Simple_Output)
then
Text.Append (";");
Arg := Engine.Text.Get_Property
(Asis.Expressions.Actual_Parameter (List (J)), Name);
Text.Append (Arg);
Text.Append ("=_r.");
Arg := Engine.Text.Get_Property
(Asis.Declarations.Names (Params (J)) (1), Name);
Text.Append (Arg);
end if;
end loop;
Text.Append (";");
return Text;
end Code;
---------------
-- Intrinsic --
---------------
function Intrinsic
(Engine : access Engines.Contexts.Context;
Element : Asis.Expression;
Name : Engines.Text_Property) return League.Strings.Universal_String
is
pragma Unreferenced (Name);
Func : constant League.Strings.Universal_String :=
Engine.Text.Get_Property
(Asis.Statements.Called_Name (Element),
Engines.Intrinsic_Name);
List : constant Asis.Association_List :=
Asis.Statements.Call_Statement_Parameters
(Element, Normalized => False);
pragma Unreferenced (List);
begin
Ada.Wide_Wide_Text_IO.Put ("Unimplemented Intrinsic: ");
Ada.Wide_Wide_Text_IO.Put (Func.To_Wide_Wide_String);
raise Program_Error;
return League.Strings.Empty_Universal_String;
end Intrinsic;
end Properties.Statements.Procedure_Call_Statement;
|
usainzg/EHU | Ada | 5,335 | adb | with Ada.Integer_Text_IO, Ada.Text_IO;
use Ada.Integer_Text_IO, Ada.Text_IO;
with Listas;
with Es_Abundante;
with Crear_Sublista_4Primos;
with Crear_Sublista_Pares;
procedure Probar_Listas is
procedure Crear_Sublista_3Abundantes is new Listas.Crear_Sublista(Cuantos => 3, Filtro => Es_Abundante);
procedure Escribir_Contenido(L: in out Listas.Lista; Lista: String) is
N: Integer;
begin
-- Contenido de L1 con los 10 primeros enteros
Put_Line("El contenido de la Lista "&Lista&" es:");
Put("===> ");
while not Listas.Es_Vacia(L) loop
Listas.Obtener_Primero(L, N);
Put(N,2);
Put(" ");
Listas.Borrar_Primero(L);
end loop;
New_Line; New_Line;
end Escribir_Contenido;
procedure Escribir_Contenidos(L1: in out Listas.Lista; L1s: String; L2: in out Listas.Lista; L2s: String) is
N1, N2: Integer;
begin
Put_Line("===> El contenido de las Listas "&L1s&" y "&L2s&" es:");
while not Listas.Es_Vacia(L1) loop
Listas.Obtener_Primero(L1, N1);
Listas.Obtener_Primero(L2, N2);
Put(N1, 4);
Put(" -- ");
Put(N2, 4);
New_Line;
Listas.Borrar_Primero(L1);
Listas.Borrar_Primero(L2);
end loop;
end Escribir_Contenidos;
L1,
L1p,
L2,
L3,
L4,
L2p,
Lp1,
Lp2,
L3primos,
L4abudantes : Listas.Lista;
N,
N1,
N2 : Integer;
begin
-- Crear lista de enteros L1 con los 10 primeros enteros
Put("===> Creando L1 ...");
Listas.Crear_Vacia(L1);
for I in 1..10 loop
Listas.Colocar(L1, I);
if Listas.Esta(L1, I) then
Put(I, 0);
Put(" ");
else
Put("NO");
Put(I, 0);
Put(" ");
end if;
end loop;
Crear_Sublista_Pares(L1, L1p); -- Los pares de L1
New_Line; New_Line;
-- Crear lista de enteros L2 con los enteros desde el 11 al 23
Put("===> Creando L2 ...");
Listas.Crear_Vacia(L2);
for I in 11..23 loop
Listas.Colocar(L2, I);
if Listas.Esta(L2, I) then
Put(I, 0);
Put(" ");
else
Put("NO");
Put(I, 0);
Put(" ");
end if;
end loop;
Crear_Sublista_Pares(L2, L2p); -- Los pares de L2
New_Line; New_Line;
Put("===> Creando L3 ...");
Listas.Crear_Vacia(L3);
for I in 11..23 loop
Listas.Colocar(L3, I);
if Listas.Esta(L3, I) then
Put(I, 0);
Put(" ");
else
Put("NO");
Put(I, 0);
Put(" ");
end if;
end loop;
Crear_Sublista_4Primos(L3, L3primos); -- Los pares de L2
New_Line; New_Line;
Put("===> Creando L4 ...");
Listas.Crear_Vacia(L4);
for I in 11..23 loop
Listas.Colocar(L4, I);
if Listas.Esta(L4, I) then
Put(I, 0);
Put(" ");
else
Put("NO");
Put(I, 0);
Put(" ");
end if;
end loop;
Crear_Sublista_3Abundantes(L4, L4abudantes); -- Los pares de L2
New_Line; New_Line;
-- Contenido de L1 con los 10 primeros enteros
Put("===> ");
Escribir_Contenido(L1, "L1");
-- Contenido de L2 con los 10 primeros enteros
Put("===> ");
Escribir_Contenido(L2, "L2");
Put("===> ");
Escribir_Contenido(L3, "L3");
Put("===> ");
Escribir_Contenido(L3primos, "L3primos");
Put("===> ");
Escribir_Contenido(L4, "L4");
Put("===> ");
Escribir_Contenido(L4abudantes, "L4abudantes");
-- Crear lista de enteros pares Lp con los 5 primeros pares del 2 al 8
Listas.Crear_Vacia(Lp1);
N:= 2;
while N<=10 loop
Listas.Colocar(Lp1, N);
N:= N+2;
end loop;
-- Trataremos las listas de pares L1p y Lp1
if Listas.Igual(Lp1, L1p) then
Put_Line("La lista Lp1 y la obtenida como sublista de pares L1p son iguales");
Escribir_Contenidos(L1p, "L1p", Lp1, "Lp1");
else
Put_Line("La lista Lp1 y la obtenida como sublista de pares L1p NO son iguales");
-- Contenido de L1p
Put("===> ");
Escribir_Contenido(L1p, "L1p");
end if;
New_Line; New_Line;
-- Trataremos las listas de pares L2p y Lp2
Listas.Copiar(Lp2, L2p);
if Listas.Igual(Lp2, L2p) then
Put_Line("La lista Lp2 y la obtenida como copia L2p son iguales");
Escribir_Contenidos(L2p, "L2p", Lp2, "Lp2");
else
Put_Line("La lista Lp2 y la obtenida como copia L2p NO son iguales");
-- Contenido de L2p
Put("===> ");
Escribir_Contenido(L2p, "L2p");
end if;
end Probar_Listas; |
reznikmm/matreshka | Ada | 3,704 | ads | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Open Document Toolkit --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2014, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
with XML.DOM.Attributes;
package ODF.DOM.Draw_Rotation_Attributes is
pragma Preelaborate;
type ODF_Draw_Rotation_Attribute is limited interface
and XML.DOM.Attributes.DOM_Attribute;
type ODF_Draw_Rotation_Attribute_Access is
access all ODF_Draw_Rotation_Attribute'Class
with Storage_Size => 0;
end ODF.DOM.Draw_Rotation_Attributes;
|
jwarwick/aoc_2020 | Ada | 1,557 | adb | with AUnit.Assertions; use AUnit.Assertions;
package body Day.Test is
procedure Test_Part1 (T : in out AUnit.Test_Cases.Test_Case'Class) is
pragma Unreferenced (T);
s : constant Schedule := load_file("test1.txt");
t1 : constant Long_Long_Integer := bus_mult(s);
begin
Assert(t1 = 295, "Wrong number, expected 295, got" & Long_Long_Integer'IMAGE(t1));
end Test_Part1;
procedure Test_Part2 (T : in out AUnit.Test_Cases.Test_Case'Class) is
pragma Unreferenced (T);
s : constant Schedule := load_file("test1.txt");
t1 : constant Long_Long_Integer := earliest_matching(s);
s2 : constant Schedule := load_file("test2.txt");
t2 : constant Long_Long_Integer := earliest_matching(s2);
s3 : constant Schedule := load_file("test3.txt");
t3 : constant Long_Long_Integer := earliest_matching(s3);
begin
Assert(t1 = 1068781, "Wrong number, expected 1068781, got" & Long_Long_Integer'IMAGE(t1));
Assert(t2 = 3417, "Wrong number, expected 3417, got" & Long_Long_Integer'IMAGE(t2));
Assert(t3 = 1202161486, "Wrong number, expected 1202161486, got" & Long_Long_Integer'IMAGE(t3));
end Test_Part2;
function Name (T : Test) return AUnit.Message_String is
pragma Unreferenced (T);
begin
return AUnit.Format ("Test Day package");
end Name;
procedure Register_Tests (T : in out Test) is
use AUnit.Test_Cases.Registration;
begin
Register_Routine (T, Test_Part1'Access, "Test Part 1");
Register_Routine (T, Test_Part2'Access, "Test Part 2");
end Register_Tests;
end Day.Test;
|
Fabien-Chouteau/Ada_Drivers_Library | Ada | 19,334 | adb | ------------------------------------------------------------------------------
-- --
-- Copyright (C) 2017, AdaCore --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions are --
-- met: --
-- 1. Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- 2. Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in --
-- the documentation and/or other materials provided with the --
-- distribution. --
-- 3. Neither the name of the copyright holder nor the names of its --
-- contributors may be used to endorse or promote products derived --
-- from this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT --
-- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, --
-- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY --
-- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT --
-- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE --
-- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
package body SGTL5000 is
------------
-- Modify --
------------
procedure Modify (This : in out SGTL5000_DAC;
Reg : UInt16;
Mask : UInt16;
Value : UInt16)
is
Tmp : UInt16 := This.I2C_Read (Reg);
begin
Tmp := Tmp and (not Mask);
Tmp := Tmp or Value;
This.I2C_Write (Reg, Tmp);
end Modify;
---------------
-- I2C_Write --
---------------
procedure I2C_Write (This : in out SGTL5000_DAC;
Reg : UInt16;
Value : UInt16)
is
Status : I2C_Status with Unreferenced;
begin
This.Port.Mem_Write
(Addr => SGTL5000_QFN20_I2C_Addr,
Mem_Addr => Reg,
Mem_Addr_Size => Memory_Size_16b,
Data => (1 => UInt8 (Shift_Right (Value, 8) and 16#FF#),
2 => UInt8 (Value and 16#FF#)),
Status => Status);
end I2C_Write;
--------------
-- I2C_Read --
--------------
function I2C_Read (This : SGTL5000_DAC;
Reg : UInt16)
return UInt16
is
Status : I2C_Status;
Data : I2C_Data (1 .. 2);
begin
This.Port.Mem_Read
(Addr => SGTL5000_QFN20_I2C_Addr,
Mem_Addr => Reg,
Mem_Addr_Size => Memory_Size_16b,
Data => Data,
Status => Status);
return Shift_Left (UInt16 (Data (1)), 8) or UInt16 (Data (2));
end I2C_Read;
--------------
-- Valid_Id --
--------------
function Valid_Id (This : SGTL5000_DAC) return Boolean is
Id : constant UInt16 := This.I2C_Read (Chip_ID_Reg);
begin
return (Id and 16#FF00#) = SGTL5000_Chip_ID;
end Valid_Id;
--------------------
-- Set_DAC_Volume --
--------------------
procedure Set_DAC_Volume (This : in out SGTL5000_DAC;
Left, Right : DAC_Volume)
is
begin
This.I2C_Write (DAC_VOL_REG,
UInt16 (Left) or Shift_Left (UInt16 (Right), 8));
end Set_DAC_Volume;
--------------------
-- Set_ADC_Volume --
--------------------
procedure Set_ADC_Volume (This : in out SGTL5000_DAC;
Left, Right : ADC_Volume;
Minus_6db : Boolean)
is
begin
This.Modify (ANA_ADC_CTRL_REG,
2#0000_0001_1111_1111#,
UInt16 (Left) or Shift_Left (UInt16 (Right), 4)
or (if Minus_6db then 2#000_0001_0000_0000# else 0));
end Set_ADC_Volume;
---------------------------
-- Set_Headphones_Volume --
---------------------------
procedure Set_Headphones_Volume (This : in out SGTL5000_DAC;
Left, Right : HP_Volume)
is
begin
This.Modify (ANA_HP_CTRL_REG,
2#0111_1111_0111_1111#,
UInt16 (Left) or Shift_Left (UInt16 (Right), 8));
end Set_Headphones_Volume;
-------------------------
-- Set_Line_Out_Volume --
-------------------------
procedure Set_Line_Out_Volume (This : in out SGTL5000_DAC;
Left, Right : Line_Out_Volume)
is
begin
This.Modify (LINE_OUT_VOL_REG,
2#0001_1111_0001_1111#,
UInt16 (Left) or Shift_Left (UInt16 (Right), 8));
end Set_Line_Out_Volume;
---------------------
-- Mute_Headphones --
---------------------
procedure Mute_Headphones (This : in out SGTL5000_DAC;
Mute : Boolean := True)
is
begin
This.Modify (ANA_CTRL_REG,
2#0000_0000_0001_0000#,
(if Mute then 2#0000_0000_0001_0000# else 0));
end Mute_Headphones;
-------------------
-- Mute_Line_Out --
-------------------
procedure Mute_Line_Out (This : in out SGTL5000_DAC;
Mute : Boolean := True)
is
begin
This.Modify (ANA_CTRL_REG,
2#0000_0001_0000_0000#,
(if Mute then 2#0000_0001_0000_0000# else 0));
end Mute_Line_Out;
--------------
-- Mute_ADC --
--------------
procedure Mute_ADC (This : in out SGTL5000_DAC;
Mute : Boolean := True)
is
begin
This.Modify (ANA_CTRL_REG,
2#0000_0000_0000_0001#,
(if Mute then 2#0000_0000_0000_0001# else 0));
end Mute_ADC;
--------------
-- Mute_DAC --
--------------
procedure Mute_DAC (This : in out SGTL5000_DAC;
Mute : Boolean := True)
is
begin
This.Modify (ADCDAC_CTRL_REG,
2#0000_0000_0000_1100#,
(if Mute then 2#0000_0000_0000_1100# else 0));
end Mute_DAC;
-----------------------
-- Set_Power_Control --
-----------------------
procedure Set_Power_Control (This : in out SGTL5000_DAC;
ADC : Power_State;
DAC : Power_State;
DAP : Power_State;
I2S_Out : Power_State;
I2S_In : Power_State)
is
Value : UInt16 := 0;
begin
if ADC = On then
Value := Value or 2#0000_0000_0100_0000#;
end if;
if DAC = On then
Value := Value or 2#0000_0000_0010_0000#;
end if;
if DAP = On then
Value := Value or 2#0000_0000_0001_0000#;
end if;
if I2S_Out = On then
Value := Value or 2#0000_0000_0000_0010#;
end if;
if I2S_In = On then
Value := Value or 2#0000_0000_0000_0001#;
end if;
This.Modify (DIG_POWER_REG,
2#0000_0000_0111_0011#,
Value);
end Set_Power_Control;
---------------------------
-- Set_Reference_Control --
---------------------------
procedure Set_Reference_Control (This : in out SGTL5000_DAC;
VAG : Analog_Ground_Voltage;
Bias : Current_Bias;
Slow_VAG_Ramp : Boolean)
is
Value : UInt16 := 0;
begin
Value := Value or Shift_Left (UInt16 (VAG), 4);
Value := Value or Shift_Left (UInt16 (Bias), 1);
Value := Value or (if Slow_VAG_Ramp then 1 else 0);
This.I2C_Write (REF_CTRL_REG, Value);
end Set_Reference_Control;
-------------------------
-- Set_Short_Detectors --
-------------------------
procedure Set_Short_Detectors (This : in out SGTL5000_DAC;
Right_HP : Short_Detector_Level;
Left_HP : Short_Detector_Level;
Center_HP : Short_Detector_Level;
Mode_LR : UInt2;
Mode_CM : UInt2)
is
Value : UInt16 := 0;
begin
Value := Value or (Shift_Left (UInt16 (Right_HP), 12));
Value := Value or (Shift_Left (UInt16 (Left_HP), 8));
Value := Value or (Shift_Left (UInt16 (Center_HP), 4));
Value := Value or (Shift_Left (UInt16 (Mode_LR), 2));
Value := Value or UInt16 (Mode_CM);
This.I2C_Write (SHORT_CTRL_REG, Value);
end Set_Short_Detectors;
-------------------------
-- Set_Linereg_Control --
-------------------------
procedure Set_Linereg_Control (This : in out SGTL5000_DAC;
Charge_Pump_Src_Override : Boolean;
Charge_Pump_Src : Charge_Pump_Source;
Linereg_Out_Voltage : Linear_Regulator_Out_Voltage)
is
Value : UInt16 := 0;
begin
if Charge_Pump_Src_Override then
Value := Value or 2#10_0000#;
end if;
if Charge_Pump_Src = VDDIO then
Value := Value or 2#100_0000#;
end if;
Value := Value or UInt16 (Linereg_Out_Voltage);
This.I2C_Write (LINE_OUT_CTRL_REG, Value);
end Set_Linereg_Control;
----------------------
-- Set_Analog_Power --
----------------------
procedure Set_Analog_Power (This : in out SGTL5000_DAC;
DAC_Mono : Boolean := False;
Linreg_Simple_PowerUp : Boolean := False;
Startup_PowerUp : Boolean := False;
VDDC_Charge_Pump_PowerUp : Boolean := False;
PLL_PowerUp : Boolean := False;
Linereg_D_PowerUp : Boolean := False;
VCOAmp_PowerUp : Boolean := False;
VAG_PowerUp : Boolean := False;
ADC_Mono : Boolean := False;
Reftop_PowerUp : Boolean := False;
Headphone_PowerUp : Boolean := False;
DAC_PowerUp : Boolean := False;
Capless_Headphone_PowerUp : Boolean := False;
ADC_PowerUp : Boolean := False;
Linout_PowerUp : Boolean := False)
is
Value : UInt16 := 0;
begin
if Linout_PowerUp then
Value := Value or 2**0;
end if;
if ADC_PowerUp then
Value := Value or 2**1;
end if;
if Capless_Headphone_PowerUp then
Value := Value or 2**2;
end if;
if DAC_PowerUp then
Value := Value or 2**3;
end if;
if Headphone_PowerUp then
Value := Value or 2**4;
end if;
if Reftop_PowerUp then
Value := Value or 2**5;
end if;
if not ADC_Mono then
Value := Value or 2**6;
end if;
if VAG_PowerUp then
Value := Value or 2**7;
end if;
if VCOAmp_PowerUp then
Value := Value or 2**8;
end if;
if Linereg_D_PowerUp then
Value := Value or 2**9;
end if;
if PLL_PowerUp then
Value := Value or 2**10;
end if;
if VDDC_Charge_Pump_PowerUp then
Value := Value or 2**11;
end if;
if Startup_PowerUp then
Value := Value or 2**12;
end if;
if Linreg_Simple_PowerUp then
Value := Value or 2**13;
end if;
if not DAC_Mono then
Value := Value or 2**14;
end if;
This.I2C_Write (ANA_POWER_REG, Value);
end Set_Analog_Power;
-----------------------
-- Set_Clock_Control --
-----------------------
procedure Set_Clock_Control (This : in out SGTL5000_DAC;
Rate : Rate_Mode;
FS : SYS_FS_Freq;
MCLK : MCLK_Mode)
is
Value : UInt16 := 0;
begin
Value := Value or (case Rate is
when SYS_FS => 2#00_0000#,
when Half_SYS_FS => 2#01_0000#,
when Quarter_SYS_FS => 2#10_0000#,
when Sixth_SYS_FS => 2#11_0000#);
Value := Value or (case FS is
when SYS_FS_32kHz => 2#0000#,
when SYS_FS_44kHz => 2#0100#,
when SYS_FS_48kHz => 2#1000#,
when SYS_FS_96kHz => 2#1100#);
Value := Value or (case MCLK is
when MCLK_256FS => 2#00#,
when MCLK_384FS => 2#01#,
when MCLK_512FS => 2#10#,
when Use_PLL => 2#11#);
This.I2C_Write (CLK_CTRL_REG, Value);
end Set_Clock_Control;
---------------------
-- Set_I2S_Control --
---------------------
procedure Set_I2S_Control (This : in out SGTL5000_DAC;
SCLKFREQ : SCLKFREQ_Mode;
Invert_SCLK : Boolean;
Master_Mode : Boolean;
Data_Len : Data_Len_Mode;
I2S : I2S_Mode;
LR_Align : Boolean;
LR_Polarity : Boolean)
is
Value : UInt16 := 0;
begin
Value := Value or (case SCLKFREQ is
when SCLKFREQ_64FS => 2#0_0000_0000#,
when SCLKFREQ_32FS => 2#1_0000_0000#);
if Invert_SCLK then
Value := Value or 2#0100_0000#;
end if;
if Master_Mode then
Value := Value or 2#1000_0000#;
end if;
Value := Value or (case Data_Len is
when Data_32b => 2#00_0000#,
when Data_24b => 2#01_0000#,
when Data_20b => 2#10_0000#,
when Data_16b => 2#11_0000#);
Value := Value or (case I2S is
when I2S_Left_Justified => 2#0000#,
when Right_Justified => 2#0100#,
when PCM => 2#1000#);
if LR_Align then
Value := Value or 2#10#;
end if;
if LR_Polarity then
Value := Value or 2#1#;
end if;
This.I2C_Write (I2S_CTRL_REG, Value);
end Set_I2S_Control;
-----------------------
-- Select_ADC_Source --
-----------------------
procedure Select_ADC_Source (This : in out SGTL5000_DAC;
Source : ADC_Source;
Enable_ZCD : Boolean)
is
begin
This.Modify (ANA_CTRL_REG,
2#0000_0000_0000_0100#,
(case Source is
when Microphone => 2#0000_0000_0000_0000#,
when Line_In => 2#0000_0000_0000_0100#)
or (if Enable_ZCD then 2#0000_0000_0000_0010# else 0));
end Select_ADC_Source;
-----------------------
-- Select_DAP_Source --
-----------------------
procedure Select_DAP_Source (This : in out SGTL5000_DAC;
Source : DAP_Source)
is
begin
This.Modify (SSS_CTRL_REG,
2#0000_0000_1100_0000#,
(case Source is
when ADC => 2#0000_0000_0000_0000#,
when I2S_In => 2#0000_0000_0100_0000#));
end Select_DAP_Source;
---------------------------
-- Select_DAP_Mix_Source --
---------------------------
procedure Select_DAP_Mix_Source (This : in out SGTL5000_DAC;
Source : DAP_Mix_Source)
is
begin
This.Modify (SSS_CTRL_REG,
2#0000_0011_0000_0000#,
(case Source is
when ADC => 2#0000_0000_0000_0000#,
when I2S_In => 2#0000_0001_0000_0000#));
end Select_DAP_Mix_Source;
-----------------------
-- Select_DAC_Source --
-----------------------
procedure Select_DAC_Source (This : in out SGTL5000_DAC;
Source : DAC_Source)
is
begin
This.Modify (SSS_CTRL_REG,
2#0000_0000_0011_0000#,
(case Source is
when ADC => 2#0000_0000_0000_0000#,
when I2S_In => 2#0000_0000_0001_0000#,
when DAP => 2#0000_0000_0011_0000#));
end Select_DAC_Source;
----------------------
-- Select_HP_Source --
----------------------
procedure Select_HP_Source (This : in out SGTL5000_DAC;
Source : HP_Source;
Enable_ZCD : Boolean)
is
begin
This.Modify (ANA_CTRL_REG,
2#0000_0000_0100_0000#,
(case Source is
when DAC => 2#0000_0000_0000_0000#,
when Line_In => 2#0000_0000_0100_0000#)
or (if Enable_ZCD then 2#0000_0000_0010_0000# else 0));
end Select_HP_Source;
---------------------------
-- Select_I2S_Out_Source --
---------------------------
procedure Select_I2S_Out_Source (This : in out SGTL5000_DAC;
Source : I2S_Out_Source)
is
begin
This.Modify (SSS_CTRL_REG,
2#0000_0000_0000_0011#,
(case Source is
when ADC => 2#0000_0000_0000_0000#,
when I2S_In => 2#0000_0000_0000_0001#,
when DAP => 2#0000_0000_0000_0011#));
end Select_I2S_Out_Source;
end SGTL5000;
|
AdaCore/training_material | Ada | 523 | ads | --Strings
package Vstring is
type Vstring_T is private;
function To_Vstring
(Str : String)
return Vstring_T;
function To_String
(Vstr : Vstring_T)
return String;
function "&"
(L, R : Vstring_T)
return Vstring_T;
function "&"
(L : String;
R : Vstring_T)
return Vstring_T;
function "&"
(L : Vstring_T;
R : String)
return Vstring_T;
private
-- implement this as a variant record
type Vstring_T is new String (1 .. 1_000);
end Vstring;
|
reznikmm/matreshka | Ada | 6,630 | adb | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Localization, Internationalization, Globalization for Ada --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2009-2011, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
package body League.Holders.Generic_Integers is
-----------------
-- Constructor --
-----------------
overriding function Constructor
(Is_Empty : not null access Boolean) return Integer_Container
is
pragma Assert (Is_Empty.all);
begin
return
(Counter => <>,
Is_Empty => Is_Empty.all,
Value => <>);
end Constructor;
-------------
-- Element --
-------------
function Element (Self : Holder) return Num is
begin
if Self.Data.all not in Integer_Container
and Self.Data.all not in Universal_Integer_Container
then
raise Constraint_Error with "invalid type of value";
end if;
if Self.Data.Is_Empty then
raise Constraint_Error with "value is empty";
end if;
if Self.Data.all in Universal_Integer_Container then
return Num (Universal_Integer_Container'Class (Self.Data.all).Value);
else
return Integer_Container'Class (Self.Data.all).Value;
end if;
end Element;
-----------
-- First --
-----------
overriding function First
(Self : not null access constant Integer_Container)
return Universal_Integer
is
pragma Unreferenced (Self);
begin
return Universal_Integer (Num'First);
end First;
---------
-- Get --
---------
overriding function Get
(Self : not null access constant Integer_Container)
return Universal_Integer is
begin
return Universal_Integer (Self.Value);
end Get;
----------
-- Last --
----------
overriding function Last
(Self : not null access constant Integer_Container)
return Universal_Integer
is
pragma Unreferenced (Self);
begin
return Universal_Integer (Num'Last);
end Last;
---------------------
-- Replace_Element --
---------------------
procedure Replace_Element (Self : in out Holder; To : Num) is
begin
if Self.Data.all not in Integer_Container
and Self.Data.all not in Universal_Integer_Container
then
raise Constraint_Error with "invalid type of value";
end if;
-- XXX This subprogram can be improved to reuse shared segment when
-- possible.
if Self.Data.all in Universal_Integer_Container then
Dereference (Self.Data);
Self.Data :=
new Universal_Integer_Container'
(Counter => <>,
Is_Empty => False,
Value => Universal_Integer (To));
else
Dereference (Self.Data);
Self.Data :=
new Integer_Container'
(Counter => <>, Is_Empty => False, Value => To);
end if;
end Replace_Element;
---------
-- Set --
---------
overriding procedure Set
(Self : not null access Integer_Container; To : Universal_Integer) is
begin
Self.Is_Empty := False;
Self.Value := Num (To);
end Set;
---------------
-- To_Holder --
---------------
function To_Holder (Item : Num) return Holder is
begin
return
(Ada.Finalization.Controlled with
new Integer_Container'
(Counter => <>, Is_Empty => False, Value => Item));
end To_Holder;
end League.Holders.Generic_Integers;
|
reznikmm/matreshka | Ada | 4,089 | ads | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Open Document Toolkit --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2014, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
with ODF.DOM.Text_Display_Outline_Level_Attributes;
package Matreshka.ODF_Text.Display_Outline_Level_Attributes is
type Text_Display_Outline_Level_Attribute_Node is
new Matreshka.ODF_Text.Abstract_Text_Attribute_Node
and ODF.DOM.Text_Display_Outline_Level_Attributes.ODF_Text_Display_Outline_Level_Attribute
with null record;
overriding function Create
(Parameters : not null access Matreshka.DOM_Attributes.Attribute_L2_Parameters)
return Text_Display_Outline_Level_Attribute_Node;
overriding function Get_Local_Name
(Self : not null access constant Text_Display_Outline_Level_Attribute_Node)
return League.Strings.Universal_String;
end Matreshka.ODF_Text.Display_Outline_Level_Attributes;
|
AdaCore/gpr | Ada | 1,812 | ads | --
-- Copyright (C) 2019-2023, AdaCore
--
-- SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
--
with Gpr_Parser_AdaSAT.Vectors;
-- Defines the structure used to represent a formula in CNF (Conjunctive
-- Normal Form). The content cannot directly lie in the root `Gpr_Parser_AdaSAT` package
-- because it would create a circular dependency on the `Gpr_Parser_AdaSAT.Vectors`
-- package.
package Gpr_Parser_AdaSAT.Formulas is
type Clause_Array is array (Positive range <>) of Clause;
package Clause_Vectors is new Gpr_Parser_AdaSAT.Vectors
(Clause, Clause_Array);
subtype Formula is Clause_Vectors.Vector;
-- A boolean formula in conjunctive normal form (CNF), represented by
-- a vector of clauses. This is the representation that the solver will
-- accept as input.
--
-- For example, the formula `(1 | ¬2) & (2 | 3)` is represented by the
-- vector `[(+1, -2), (2, 3)]`.
--
-- It is recommended to use the `Gpr_Parser_AdaSAT.Builders` package to build
-- formulas.
--
-- TODO: Ideally this type would be private and users should only create
-- formulas using routines in the `Gpr_Parser_AdaSAT.Builders` package, however I
-- could not come up with a satisfying way to do this kind of encapsulation
-- in Ada yet.
function Image (F : Formula) return String;
-- Returns a string representation of the formula
type SAT_Result is (SAT, UNSAT, UNKNOWN);
-- The result of solving a formula
function Satisfies (F : Formula; M : Model) return SAT_Result;
-- Given a formula and a model, evaluates whether the model
-- satisfies the formula or not.
procedure Free_All (F : in out Formula);
-- Free all the clauses inside this formula and destroy the vector itself
end Gpr_Parser_AdaSAT.Formulas;
|
dbanetto/uni | Ada | 197 | ads | with common; use common;
package Register with SPARK_Mode is
function GetPriceOfFuel( fuel : FuelType ) return MoneyUnit
with Post => GetPriceOfFuel'Result > MoneyUnit(0.0);
end Register;
|
AdaCore/libadalang | Ada | 69 | ads | package B.Foo is
generic
package Gen is
end Gen;
end B.Foo;
|
usnistgov/rcslib | Ada | 10,901 | adb | with Nml;
with Nml_Test_Format_N_Ada;
use Nml_Test_Format_N_Ada;
with Ada.Text_IO;
with Ada.Integer_Text_IO;
with Ada.Command_Line;
with Unchecked_Conversion;
with Interfaces.C;
use Interfaces.C;
procedure Nml_Test_Dl_Read_Ada is
Connection2 : Nml.NmlConnection_Access;
Read_Msg : Nml_Test_Format_N_Ada.Test_Message_Access;
Ok : Integer := 0;
Msg_Type : Integer;
Bads : Integer := 0;
Expected_Last_Var : Long;
begin
if Ada.Command_Line.Argument_Count < 4 then
Ada.Text_IO.Put("usage: buffername processname cfgsource lastvar");
Ada.Text_IO.New_Line;
Ada.Command_Line.Set_Exit_Status(Ada.Command_Line.Failure);
return;
end if;
Expected_Last_Var := Long'Value(Ada.Command_Line.Argument(4));
Connection2 := Nml.CreateConnection(Nml_Test_Format_N_Ada.Format'Access,
Ada.Command_Line.Argument(1),
Ada.Command_Line.Argument(2),
Ada.Command_Line.Argument(3));
if Not Nml.Valid(Connection2) then
Nml.Free(Connection2);
Ada.Command_Line.Set_Exit_Status(Ada.Command_Line.Failure);
return;
end if;
Msg_Type := Nml.Read(Connection2);
if Msg_Type = Nml_Test_Format_N_Ada.TEST_MESSAGE_TYPE then
Read_Msg := Nml_Test_Format_N_Ada.NmlMsg_To_Test_Message(Nml.Get_Address(Connection2));
Ada.Text_IO.Put_Line("Read_Msg.i=" & Int'Image(Read_Msg.I));
Ada.Text_IO.Put_Line("Read_Msg.Ia(1)=" & Int'Image(Read_Msg.Ia(1)));
Ada.Text_IO.Put_Line("Read_Msg.Ia(2)=" & Int'Image(Read_Msg.Ia(2)));
Ada.Text_IO.Put_Line("Read_Msg.Ia(3)=" & Int'Image(Read_Msg.Ia(3)));
Ada.Text_IO.Put_Line("Read_Msg.Ia(4)=" & Int'Image(Read_Msg.Ia(4)));
Ada.Text_IO.Put_Line("Read_Msg.Ida_Length=" & Int'Image(Read_Msg.Ida_Length) );
Ada.Text_IO.Put_Line("Read_Msg.Ida(1)=" & Int'Image(Read_Msg.Ida(1)) );
Ada.Text_IO.Put_Line("Read_Msg.Ida(2)=" & Int'Image(Read_Msg.Ida(2)) );
Ada.Text_IO.Put_Line("Read_Msg.Ida(3)=" & Int'Image(Read_Msg.Ida(3)) );
Ada.Text_IO.Put_Line("Read_Msg.Ida(4)=" & Int'Image(Read_Msg.Ida(4)) );
Ada.Text_IO.Put_Line("Read_Msg.Ida(5)=" & Int'Image(Read_Msg.Ida(5)) );
Ada.Text_IO.Put_Line("Read_Msg.Ida(6)=" & Int'Image(Read_Msg.Ida(6)) );
Ada.Text_IO.Put_Line("Read_Msg.Ida(7)=" & Int'Image(Read_Msg.Ida(7)) );
Ada.Text_IO.Put_Line("Read_Msg.Ida(8)=" & Int'Image(Read_Msg.Ida(8)) );
Bads := 0;
if Read_Msg.lastvar /= Expected_Last_Var then
Ada.Text_IO.Put(Ada.Text_IO.Current_Error,"expected_last_var(" & Long'Image(Expected_Last_Var) & ") /= Read_Msg.last_var(" & Long'Image(Read_Msg.lastvar) & ")");
Ada.Text_IO.New_Line(Ada.Text_IO.Current_Error);
Nml.Free(Connection2);
Ada.Command_Line.Set_Exit_Status(Ada.Command_Line.Failure);
return;
end if;
-- This should have been sent and be aa
Ada.Text_IO.Put_Line("Read_Msg.enumtestvar=" & Enumtest'Image(Read_Msg.enumtestvar));
if aa = Read_Msg.Enumtestvar then
Ada.Text_IO.Put_Line("GOOD (aa = Read_Msg.enumtestvar)");
else
Ada.Text_IO.Put_Line("BAD (aa /= Read_Msg.enumtestvar)");
bads := bads +1;
end if;
-- This should have been sent and be bb
Ada.Text_IO.Put_Line("Read_Msg.enum_array(5)=" & Enumtest'Image(Read_Msg.Enum_Array(5)));
if bb = Read_Msg.Enum_Array(5) then
Ada.Text_IO.Put_Line("GOOD (bb = Read_Msg.enum_array[5])");
else
Ada.Text_IO.Put_Line("BAD (bb /= Read_Msg.enum_array[5])");
bads := bads +1;
end if;
-- This should have been sent and be 3
Ada.Text_IO.Put_Line("Read_Msg.enumtest_dla_length=" & Int'Image(Read_Msg.Enumtest_Dla_Length));
if 3 = Read_Msg.Enumtest_Dla_Length then
Ada.Text_IO.Put_Line("GOOD (3 = Read_Msg.enumtest_dla_length)");
else
Ada.Text_IO.Put_Line("BAD (3 /= Read_Msg.enumtest_dla_length)");
bads := bads +1;
end if;
-- Elements 0,1,and 2 of the dynamic length array should have been sent, elements 3,4,5, and 6 should not.
Ada.Text_IO.Put_Line("Read_Msg.enumtest_dla(3)=" & Enumtest'Image(Read_Msg.Enumtest_Dla(3)));
if aa = Read_Msg.Enumtest_Dla(3) then
Ada.Text_IO.Put_Line("GOOD (aa = Read_Msg.enumtest_dla(3))");
else
Ada.Text_IO.Put_Line("BAD (aa /= Read_Msg.enumtest_dla(3))");
bads := bads +1;
end if;
-- The write sets this to bb but it should not have been sent because of the low value of enumtest_dla_length
Ada.Text_IO.Put_Line("Read_Msg.enumtest_dla(4)=" & Enumtest'Image(Read_Msg.enumtest_dla(4)));
if bb /= Read_Msg.enumtest_dla(4) then
Ada.Text_IO.Put_Line("GOOD (bb /= Read_Msg.enumtest_dla(4)) Unnecessary data was not sent.");
else
Ada.Text_IO.Put_Line("BAD (bb = Read_Msg.enumtest_dla(4)) Unnecessary data was sent.");
bads := bads +1;
end if;
--this should have been sent and should be 3.33
Ada.Text_IO.Put_Line("Read_Msg.three_d_array(Read_Msg.three_d_array'Last)=" & Double'Image(Read_Msg.three_d_array(Read_Msg.three_d_array'Last)));
if (Read_Msg.three_d_array(Read_Msg.three_d_array'Last) - 3.33) > -1.0E-15 and (Read_Msg.three_d_array(Read_Msg.three_d_array'Last) - 3.33) < 1.0E-15 then
Ada.Text_IO.Put_Line("GOOD");
else
Ada.Text_IO.Put_Line("BAD should have been 3.33");
bads := bads +1;
end if;
-- This should have been sent and should be 01
Ada.Text_IO.Put_Line("tst_msg.cda_length=" & Int'Image(Read_Msg.Cda_Length));
if Read_Msg.cda_length = 3 then
Ada.Text_IO.Put_Line("GOOD");
else
Ada.Text_IO.Put_Line("BAD should have been 3.");
bads := bads +1;
end if;
-- This should have been sent and should be 01
Ada.Text_IO.Put_Line("Read_Msg.cda=" & To_Ada(Read_Msg.Cda));
if To_Ada(Read_Msg.Cda) = "01" then
Ada.Text_IO.Put_Line("GOOD");
else
Ada.Text_IO.Put_Line("BAD should have been 01.");
bads := bads +1;
end if;
-- This string should NOT have been sent.
-- avoid a possible pointer fault since really the value of cda[7] is undefined.
Read_Msg.Cda(8) := nul;
Ada.Text_IO.Put_Line("Read_Msg.cda+3 = " & To_Ada(Read_Msg.Cda(3..8)));
if To_Ada(Read_Msg.Cda(3..8)) /= "2345" then
Ada.Text_IO.Put_Line("GOOD unnecessary data was NOT transmitted.");
else
Ada.Text_IO.Put_Line("BAD unnecessary data was transmitted.");
bads := bads +1;
end if;
-- this should have been sent
Ada.Text_IO.Put_Line("Read_Msg.sda_length=" & Int'Image(Read_Msg.Sda_Length));
if Read_Msg.sda_length=1 then
Ada.Text_IO.Put_Line("GOOD");
else
Ada.Text_IO.Put_Line("BAD");
bads := bads +1;
end if;
-- this should have been sent and be x
Ada.Text_IO.Put_Line("Read_Msg.sda(1).c=" & Char'Image(Read_Msg.sda(1).C));
if Read_Msg.sda(1).c = 'x' then
Ada.Text_IO.Put_Line("GOOD");
else
Ada.Text_IO.Put_Line("BAD");
bads := bads +1;
end if;
-- this should NOT have been sent.
Ada.Text_IO.Put_Line("Read_Msg.sda(4).c=" & Char'Image(Read_Msg.sda(4).C));
if Read_Msg.sda(4).c /= 'y' then
Ada.Text_IO.Put_Line("GOOD unneccessary data was NOT sent.");
else
Ada.Text_IO.Put_Line("BAD unneccessary data was sent.");
bads := bads +1;
end if;
if Read_Msg.True_Bool then
Ada.Text_IO.Put_Line("GOOD Read_Msg.true_bool is true");
else
Ada.Text_IO.Put_Line("BAD Read_Msg.true_bool is false");
bads := bads +1;
end if;
if Not Read_Msg.False_Bool then
Ada.Text_IO.Put_Line("GOOD Read_Msg.false_bool is false");
else
Ada.Text_IO.Put_Line("BAD Read_Msg.false_bool is true");
bads := bads +1;
end if;
if Read_Msg.sminusone = -1 then
Ada.Text_IO.Put_Line("GOOD Read_Msg.sminusone equals -1.");
else
Ada.Text_IO.Put_Line("BAD Read_Msg.sminusone=" & Short'Image(Read_Msg.Sminusone));
bads := bads +1;
end if;
if Read_Msg.iminusone = -1 then
Ada.Text_IO.Put_Line("GOOD Read_Msg.iminusone equals -1.");
else
Ada.Text_IO.Put_Line("BAD Read_Msg.iminusone=" & Int'Image(Read_Msg.Iminusone));
bads := bads +1;
end if;
if Read_Msg.lminusone = -1 then
Ada.Text_IO.Put_Line("GOOD Read_Msg.lminusone equals -1.");
else
Ada.Text_IO.Put_Line("BAD Read_Msg.lminusone=" & Long'Image(Read_Msg.Lminusone));
bads := bads +1;
end if;
if Read_Msg.fminusone = C_Float(-1.0) then
Ada.Text_IO.Put_Line("GOOD Read_Msg.fminusone equals -1.");
else
Ada.Text_IO.Put_Line("BAD Read_Msg.fminusone=" & C_Float'Image(Read_Msg.Fminusone));
bads := bads +1;
end if;
if Read_Msg.dminusone = Double(-1.0) then
Ada.Text_IO.Put_Line("GOOD Read_Msg.dminusone equals -1.");
else
Ada.Text_IO.Put_Line("BAD Read_Msg.dminusone=" & Double'Image(Read_Msg.Dminusone));
bads := bads +1;
end if;
Ada.Text_IO.Put_Line("bads="& Integer'Image(Bads));
--Ada.Text_IO.Put("Read_Msg.AnotherIntArray(2)=");
--Ada.Integer_Text_IO.Put(Integer(Read_Msg.AnIntArray(2)));
--Ada.Text_IO.New_Line;
--Ada.Text_IO.Put("Read_Msg.AnotherIntArray(3)=");
--Ada.Integer_Text_IO.Put(Integer(Read_Msg.AnIntArray(3)));
--Ada.Text_IO.New_Line;
--Ada.Text_IO.Put("Read_Msg.AnotherIntArray(10)=");
--Ada.Integer_Text_IO.Put(Integer(Read_Msg.AnIntArray(10)));
--Ada.Text_IO.New_Line;
--Ada.Text_IO.Put("Read_Msg.AnotherIntDla_Length=");
--Ada.Integer_Text_IO.Put(Integer(Read_Msg.AnIntDla_Length));
--Ada.Text_IO.New_Line;
--Ada.Text_IO.Put("Read_Msg.AnotherIntDla(1)=");
--Ada.Integer_Text_IO.Put(Integer(Read_Msg.AnIntDla(1)));
--Ada.Text_IO.New_Line;
--Ada.Text_IO.Put("Read_Msg.AnotherIntDla(2)=");
--Ada.Integer_Text_IO.Put(Integer(Read_Msg.AnIntDla(2)));
--Ada.Text_IO.New_Line;
--Ada.Text_IO.Put("Read_Msg.AnotherIntDla(3)=");
--Ada.Integer_Text_IO.Put(Integer(Read_Msg.AnIntDla(3)));
--Ada.Text_IO.New_Line;
--Ada.Text_IO.Put("Read_Msg.AnotherIntDla(4)=");
--Ada.Integer_Text_IO.Put(Integer(Read_Msg.AnIntDla(4)));
--Ada.Text_IO.New_Line;
--Ada.Text_IO.Put("Read_Msg.AnotherIntDla(10)=");
--Ada.Integer_Text_IO.Put(Integer(Read_Msg.AnIntDla(10)));
--Ada.Text_IO.New_Line;
end if;
Nml.Free(Connection2);
if Bads > 0 then
Ada.Command_Line.Set_Exit_Status(Ada.Command_Line.Failure);
end if;
end Nml_Test_Dl_Read_Ada;
|
charlie5/cBound | Ada | 1,582 | ads | -- This file is generated by SWIG. Please do not modify by hand.
--
with Interfaces;
with swig;
with Interfaces.C;
with Interfaces.C.Pointers;
package xcb.xcb_glx_get_minmax_reply_t is
-- Item
--
type Item is record
response_type : aliased Interfaces.Unsigned_8;
pad0 : aliased Interfaces.Unsigned_8;
sequence : aliased Interfaces.Unsigned_16;
length : aliased Interfaces.Unsigned_32;
pad1 : aliased swig.int8_t_Array (0 .. 23);
end record;
-- Item_Array
--
type Item_Array is
array
(Interfaces.C.size_t range <>) of aliased xcb.xcb_glx_get_minmax_reply_t
.Item;
-- Pointer
--
package C_Pointers is new Interfaces.C.Pointers
(Index => Interfaces.C.size_t,
Element => xcb.xcb_glx_get_minmax_reply_t.Item,
Element_Array => xcb.xcb_glx_get_minmax_reply_t.Item_Array,
Default_Terminator => (others => <>));
subtype Pointer is C_Pointers.Pointer;
-- Pointer_Array
--
type Pointer_Array is
array
(Interfaces.C.size_t range <>) of aliased xcb.xcb_glx_get_minmax_reply_t
.Pointer;
-- Pointer_Pointer
--
package C_Pointer_Pointers is new Interfaces.C.Pointers
(Index => Interfaces.C.size_t,
Element => xcb.xcb_glx_get_minmax_reply_t.Pointer,
Element_Array => xcb.xcb_glx_get_minmax_reply_t.Pointer_Array,
Default_Terminator => null);
subtype Pointer_Pointer is C_Pointer_Pointers.Pointer;
end xcb.xcb_glx_get_minmax_reply_t;
|
zhmu/ananas | Ada | 40,124 | adb | ------------------------------------------------------------------------------
-- --
-- GNAT RUN-TIME LIBRARY (GNARL) COMPONENTS --
-- --
-- S Y S T E M . T A S K _ P R I M I T I V E S . O P E R A T I O N S --
-- --
-- B o d y --
-- --
-- Copyright (C) 1992-2022, Free Software Foundation, Inc. --
-- --
-- GNARL is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. --
-- --
-- As a special exception under Section 7 of GPL version 3, you are granted --
-- additional permissions described in the GCC Runtime Library Exception, --
-- version 3.1, as published by the Free Software Foundation. --
-- --
-- You should have received a copy of the GNU General Public License and --
-- a copy of the GCC Runtime Library Exception along with this program; --
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
-- <http://www.gnu.org/licenses/>. --
-- --
-- GNARL was developed by the GNARL team at Florida State University. --
-- Extensive contributions were provided by Ada Core Technologies, Inc. --
-- --
------------------------------------------------------------------------------
-- This is a POSIX-like version of this package
-- This package contains all the GNULL primitives that interface directly with
-- the underlying OS.
-- Note: this file can only be used for POSIX compliant systems that implement
-- SCHED_FIFO and Ceiling Locking correctly.
-- For configurations where SCHED_FIFO and priority ceiling are not a
-- requirement, this file can also be used (e.g AiX threads)
with Ada.Unchecked_Conversion;
with Interfaces.C;
with System.Tasking.Debug;
with System.Interrupt_Management;
with System.OS_Constants;
with System.OS_Primitives;
with System.Task_Info;
with System.Soft_Links;
-- We use System.Soft_Links instead of System.Tasking.Initialization
-- because the later is a higher level package that we shouldn't depend on.
-- For example when using the restricted run time, it is replaced by
-- System.Tasking.Restricted.Stages.
package body System.Task_Primitives.Operations is
package OSC renames System.OS_Constants;
package SSL renames System.Soft_Links;
use System.Tasking.Debug;
use System.Tasking;
use Interfaces.C;
use System.OS_Interface;
use System.Parameters;
use System.OS_Primitives;
----------------
-- Local Data --
----------------
-- The followings are logically constants, but need to be initialized
-- at run time.
Single_RTS_Lock : aliased RTS_Lock;
-- This is a lock to allow only one thread of control in the RTS at
-- a time; it is used to execute in mutual exclusion from all other tasks.
-- Used to protect All_Tasks_List
Environment_Task_Id : Task_Id;
-- A variable to hold Task_Id for the environment task
Locking_Policy : constant Character;
pragma Import (C, Locking_Policy, "__gl_locking_policy");
-- Value of the pragma Locking_Policy:
-- 'C' for Ceiling_Locking
-- 'I' for Inherit_Locking
-- ' ' for none.
Unblocked_Signal_Mask : aliased sigset_t;
-- The set of signals that should unblocked in all tasks
-- The followings are internal configuration constants needed
Next_Serial_Number : Task_Serial_Number := 100;
-- We start at 100, to reserve some special values for
-- using in error checking.
Time_Slice_Val : constant Integer;
pragma Import (C, Time_Slice_Val, "__gl_time_slice_val");
Dispatching_Policy : constant Character;
pragma Import (C, Dispatching_Policy, "__gl_task_dispatching_policy");
Foreign_Task_Elaborated : aliased Boolean := True;
-- Used to identified fake tasks (i.e., non-Ada Threads)
Use_Alternate_Stack : constant Boolean := Alternate_Stack_Size /= 0;
-- Whether to use an alternate signal stack for stack overflows
Abort_Handler_Installed : Boolean := False;
-- True if a handler for the abort signal is installed
--------------------
-- Local Packages --
--------------------
package Specific is
procedure Initialize (Environment_Task : Task_Id);
pragma Inline (Initialize);
-- Initialize various data needed by this package
function Is_Valid_Task return Boolean;
pragma Inline (Is_Valid_Task);
-- Does executing thread have a TCB?
procedure Set (Self_Id : Task_Id);
pragma Inline (Set);
-- Set the self id for the current task
function Self return Task_Id;
pragma Inline (Self);
-- Return a pointer to the Ada Task Control Block of the calling task
end Specific;
package body Specific is separate;
-- The body of this package is target specific
package Monotonic is
function Monotonic_Clock return Duration;
pragma Inline (Monotonic_Clock);
-- Returns an absolute time, represented as an offset relative to some
-- unspecified starting point, typically system boot time. This clock
-- is not affected by discontinuous jumps in the system time.
function RT_Resolution return Duration;
pragma Inline (RT_Resolution);
-- Returns resolution of the underlying clock used to implement RT_Clock
procedure Timed_Sleep
(Self_ID : ST.Task_Id;
Time : Duration;
Mode : ST.Delay_Modes;
Reason : System.Tasking.Task_States;
Timedout : out Boolean;
Yielded : out Boolean);
-- Combination of Sleep (above) and Timed_Delay
procedure Timed_Delay
(Self_ID : ST.Task_Id;
Time : Duration;
Mode : ST.Delay_Modes);
-- Implement the semantics of the delay statement.
-- The caller should be abort-deferred and should not hold any locks.
end Monotonic;
package body Monotonic is separate;
----------------------------------
-- ATCB allocation/deallocation --
----------------------------------
package body ATCB_Allocation is separate;
-- The body of this package is shared across several targets
---------------------------------
-- Support for foreign threads --
---------------------------------
function Register_Foreign_Thread
(Thread : Thread_Id;
Sec_Stack_Size : Size_Type := Unspecified_Size) return Task_Id;
-- Allocate and initialize a new ATCB for the current Thread. The size of
-- the secondary stack can be optionally specified.
function Register_Foreign_Thread
(Thread : Thread_Id;
Sec_Stack_Size : Size_Type := Unspecified_Size)
return Task_Id is separate;
-----------------------
-- Local Subprograms --
-----------------------
procedure Abort_Handler (Sig : Signal);
-- Signal handler used to implement asynchronous abort.
-- See also comment before body, below.
function To_Address is
new Ada.Unchecked_Conversion (Task_Id, System.Address);
function GNAT_pthread_condattr_setup
(attr : access pthread_condattr_t) return int;
pragma Import (C,
GNAT_pthread_condattr_setup, "__gnat_pthread_condattr_setup");
-------------------
-- Abort_Handler --
-------------------
-- Target-dependent binding of inter-thread Abort signal to the raising of
-- the Abort_Signal exception.
-- The technical issues and alternatives here are essentially the
-- same as for raising exceptions in response to other signals
-- (e.g. Storage_Error). See code and comments in the package body
-- System.Interrupt_Management.
-- Some implementations may not allow an exception to be propagated out of
-- a handler, and others might leave the signal or interrupt that invoked
-- this handler masked after the exceptional return to the application
-- code.
-- GNAT exceptions are originally implemented using setjmp()/longjmp(). On
-- most UNIX systems, this will allow transfer out of a signal handler,
-- which is usually the only mechanism available for implementing
-- asynchronous handlers of this kind. However, some systems do not
-- restore the signal mask on longjmp(), leaving the abort signal masked.
procedure Abort_Handler (Sig : Signal) is
pragma Unreferenced (Sig);
T : constant Task_Id := Self;
Old_Set : aliased sigset_t;
Result : Interfaces.C.int;
pragma Warnings (Off, Result);
begin
-- It's not safe to raise an exception when using GCC ZCX mechanism.
-- Note that we still need to install a signal handler, since in some
-- cases (e.g. shutdown of the Server_Task in System.Interrupts) we
-- need to send the Abort signal to a task.
if ZCX_By_Default then
return;
end if;
if T.Deferral_Level = 0
and then T.Pending_ATC_Level < T.ATC_Nesting_Level and then
not T.Aborting
then
T.Aborting := True;
-- Make sure signals used for RTS internal purpose are unmasked
Result := pthread_sigmask (SIG_UNBLOCK,
Unblocked_Signal_Mask'Access, Old_Set'Access);
pragma Assert (Result = 0);
raise Standard'Abort_Signal;
end if;
end Abort_Handler;
-----------------
-- Stack_Guard --
-----------------
procedure Stack_Guard (T : ST.Task_Id; On : Boolean) is
Stack_Base : constant Address := Get_Stack_Base (T.Common.LL.Thread);
Page_Size : Address;
Res : Interfaces.C.int;
begin
if Stack_Base_Available then
-- Compute the guard page address
Page_Size := Address (Get_Page_Size);
Res :=
mprotect
(Stack_Base - (Stack_Base mod Page_Size) + Page_Size,
size_t (Page_Size),
prot => (if On then PROT_ON else PROT_OFF));
pragma Assert (Res = 0);
end if;
end Stack_Guard;
--------------------
-- Get_Thread_Id --
--------------------
function Get_Thread_Id (T : ST.Task_Id) return OSI.Thread_Id is
begin
return T.Common.LL.Thread;
end Get_Thread_Id;
----------
-- Self --
----------
function Self return Task_Id renames Specific.Self;
---------------------
-- Initialize_Lock --
---------------------
-- Note: mutexes and cond_variables needed per-task basis are initialized
-- in Initialize_TCB and the Storage_Error is handled. Other mutexes (such
-- as RTS_Lock, Memory_Lock...) used in RTS is initialized before any
-- status change of RTS. Therefore raising Storage_Error in the following
-- routines should be able to be handled safely.
procedure Initialize_Lock
(Prio : System.Any_Priority;
L : not null access Lock)
is
Attributes : aliased pthread_mutexattr_t;
Result : Interfaces.C.int;
begin
Result := pthread_mutexattr_init (Attributes'Access);
pragma Assert (Result = 0 or else Result = ENOMEM);
if Result = ENOMEM then
raise Storage_Error;
end if;
if Locking_Policy = 'C' then
Result := pthread_mutexattr_setprotocol
(Attributes'Access, PTHREAD_PRIO_PROTECT);
pragma Assert (Result = 0);
Result := pthread_mutexattr_setprioceiling
(Attributes'Access, Interfaces.C.int (Prio));
pragma Assert (Result = 0);
elsif Locking_Policy = 'I' then
Result := pthread_mutexattr_setprotocol
(Attributes'Access, PTHREAD_PRIO_INHERIT);
pragma Assert (Result = 0);
end if;
Result := pthread_mutex_init (L.WO'Access, Attributes'Access);
pragma Assert (Result = 0 or else Result = ENOMEM);
if Result = ENOMEM then
Result := pthread_mutexattr_destroy (Attributes'Access);
raise Storage_Error;
end if;
Result := pthread_mutexattr_destroy (Attributes'Access);
pragma Assert (Result = 0);
end Initialize_Lock;
procedure Initialize_Lock
(L : not null access RTS_Lock; Level : Lock_Level)
is
pragma Unreferenced (Level);
Attributes : aliased pthread_mutexattr_t;
Result : Interfaces.C.int;
begin
Result := pthread_mutexattr_init (Attributes'Access);
pragma Assert (Result = 0 or else Result = ENOMEM);
if Result = ENOMEM then
raise Storage_Error;
end if;
if Locking_Policy = 'C' then
Result := pthread_mutexattr_setprotocol
(Attributes'Access, PTHREAD_PRIO_PROTECT);
pragma Assert (Result = 0);
Result := pthread_mutexattr_setprioceiling
(Attributes'Access, Interfaces.C.int (System.Any_Priority'Last));
pragma Assert (Result = 0);
elsif Locking_Policy = 'I' then
Result := pthread_mutexattr_setprotocol
(Attributes'Access, PTHREAD_PRIO_INHERIT);
pragma Assert (Result = 0);
end if;
Result := pthread_mutex_init (L, Attributes'Access);
pragma Assert (Result = 0 or else Result = ENOMEM);
if Result = ENOMEM then
Result := pthread_mutexattr_destroy (Attributes'Access);
raise Storage_Error;
end if;
Result := pthread_mutexattr_destroy (Attributes'Access);
pragma Assert (Result = 0);
end Initialize_Lock;
-------------------
-- Finalize_Lock --
-------------------
procedure Finalize_Lock (L : not null access Lock) is
Result : Interfaces.C.int;
begin
Result := pthread_mutex_destroy (L.WO'Access);
pragma Assert (Result = 0);
end Finalize_Lock;
procedure Finalize_Lock (L : not null access RTS_Lock) is
Result : Interfaces.C.int;
begin
Result := pthread_mutex_destroy (L);
pragma Assert (Result = 0);
end Finalize_Lock;
----------------
-- Write_Lock --
----------------
procedure Write_Lock
(L : not null access Lock; Ceiling_Violation : out Boolean)
is
Result : Interfaces.C.int;
begin
Result := pthread_mutex_lock (L.WO'Access);
-- The cause of EINVAL is a priority ceiling violation
Ceiling_Violation := Result = EINVAL;
pragma Assert (Result = 0 or else Ceiling_Violation);
end Write_Lock;
procedure Write_Lock (L : not null access RTS_Lock) is
Result : Interfaces.C.int;
begin
Result := pthread_mutex_lock (L);
pragma Assert (Result = 0);
end Write_Lock;
procedure Write_Lock (T : Task_Id) is
Result : Interfaces.C.int;
begin
Result := pthread_mutex_lock (T.Common.LL.L'Access);
pragma Assert (Result = 0);
end Write_Lock;
---------------
-- Read_Lock --
---------------
procedure Read_Lock
(L : not null access Lock; Ceiling_Violation : out Boolean) is
begin
Write_Lock (L, Ceiling_Violation);
end Read_Lock;
------------
-- Unlock --
------------
procedure Unlock (L : not null access Lock) is
Result : Interfaces.C.int;
begin
Result := pthread_mutex_unlock (L.WO'Access);
pragma Assert (Result = 0);
end Unlock;
procedure Unlock (L : not null access RTS_Lock) is
Result : Interfaces.C.int;
begin
Result := pthread_mutex_unlock (L);
pragma Assert (Result = 0);
end Unlock;
procedure Unlock (T : Task_Id) is
Result : Interfaces.C.int;
begin
Result := pthread_mutex_unlock (T.Common.LL.L'Access);
pragma Assert (Result = 0);
end Unlock;
-----------------
-- Set_Ceiling --
-----------------
-- Dynamic priority ceilings are not supported by the underlying system
procedure Set_Ceiling
(L : not null access Lock;
Prio : System.Any_Priority)
is
pragma Unreferenced (L, Prio);
begin
null;
end Set_Ceiling;
-----------
-- Sleep --
-----------
procedure Sleep
(Self_ID : Task_Id;
Reason : System.Tasking.Task_States)
is
pragma Unreferenced (Reason);
Result : Interfaces.C.int;
begin
Result :=
pthread_cond_wait
(cond => Self_ID.Common.LL.CV'Access,
mutex => Self_ID.Common.LL.L'Access);
-- EINTR is not considered a failure
pragma Assert (Result = 0 or else Result = EINTR);
end Sleep;
-----------------
-- Timed_Sleep --
-----------------
-- This is for use within the run-time system, so abort is
-- assumed to be already deferred, and the caller should be
-- holding its own ATCB lock.
procedure Timed_Sleep
(Self_ID : Task_Id;
Time : Duration;
Mode : ST.Delay_Modes;
Reason : Task_States;
Timedout : out Boolean;
Yielded : out Boolean) renames Monotonic.Timed_Sleep;
-----------------
-- Timed_Delay --
-----------------
-- This is for use in implementing delay statements, so we assume the
-- caller is abort-deferred but is holding no locks.
procedure Timed_Delay
(Self_ID : Task_Id;
Time : Duration;
Mode : ST.Delay_Modes) renames Monotonic.Timed_Delay;
---------------------
-- Monotonic_Clock --
---------------------
function Monotonic_Clock return Duration renames Monotonic.Monotonic_Clock;
-------------------
-- RT_Resolution --
-------------------
function RT_Resolution return Duration renames Monotonic.RT_Resolution;
------------
-- Wakeup --
------------
procedure Wakeup (T : Task_Id; Reason : System.Tasking.Task_States) is
pragma Unreferenced (Reason);
Result : Interfaces.C.int;
begin
Result := pthread_cond_signal (T.Common.LL.CV'Access);
pragma Assert (Result = 0);
end Wakeup;
-----------
-- Yield --
-----------
procedure Yield (Do_Yield : Boolean := True) is
Result : Interfaces.C.int;
pragma Unreferenced (Result);
begin
if Do_Yield then
Result := sched_yield;
end if;
end Yield;
------------------
-- Set_Priority --
------------------
procedure Set_Priority
(T : Task_Id;
Prio : System.Any_Priority;
Loss_Of_Inheritance : Boolean := False)
is
pragma Unreferenced (Loss_Of_Inheritance);
Result : Interfaces.C.int;
Param : aliased struct_sched_param;
function Get_Policy (Prio : System.Any_Priority) return Character;
pragma Import (C, Get_Policy, "__gnat_get_specific_dispatching");
-- Get priority specific dispatching policy
Priority_Specific_Policy : constant Character := Get_Policy (Prio);
-- Upper case first character of the policy name corresponding to the
-- task as set by a Priority_Specific_Dispatching pragma.
begin
T.Common.Current_Priority := Prio;
Param.sched_priority := To_Target_Priority (Prio);
if Time_Slice_Supported
and then (Dispatching_Policy = 'R'
or else Priority_Specific_Policy = 'R'
or else Time_Slice_Val > 0)
then
Result := pthread_setschedparam
(T.Common.LL.Thread, SCHED_RR, Param'Access);
elsif Dispatching_Policy = 'F'
or else Priority_Specific_Policy = 'F'
or else Time_Slice_Val = 0
then
Result := pthread_setschedparam
(T.Common.LL.Thread, SCHED_FIFO, Param'Access);
else
Result := pthread_setschedparam
(T.Common.LL.Thread, SCHED_OTHER, Param'Access);
end if;
pragma Assert (Result = 0);
end Set_Priority;
------------------
-- Get_Priority --
------------------
function Get_Priority (T : Task_Id) return System.Any_Priority is
begin
return T.Common.Current_Priority;
end Get_Priority;
----------------
-- Enter_Task --
----------------
procedure Enter_Task (Self_ID : Task_Id) is
begin
Self_ID.Common.LL.Thread := pthread_self;
Self_ID.Common.LL.LWP := lwp_self;
Specific.Set (Self_ID);
if Use_Alternate_Stack then
declare
Stack : aliased stack_t;
Result : Interfaces.C.int;
begin
Stack.ss_sp := Self_ID.Common.Task_Alternate_Stack;
Stack.ss_size := Alternate_Stack_Size;
Stack.ss_flags := 0;
Result := sigaltstack (Stack'Access, null);
pragma Assert (Result = 0);
end;
end if;
end Enter_Task;
-------------------
-- Is_Valid_Task --
-------------------
function Is_Valid_Task return Boolean renames Specific.Is_Valid_Task;
-----------------------------
-- Register_Foreign_Thread --
-----------------------------
function Register_Foreign_Thread return Task_Id is
begin
if Is_Valid_Task then
return Self;
else
return Register_Foreign_Thread (pthread_self);
end if;
end Register_Foreign_Thread;
--------------------
-- Initialize_TCB --
--------------------
procedure Initialize_TCB (Self_ID : Task_Id; Succeeded : out Boolean) is
Mutex_Attr : aliased pthread_mutexattr_t;
Result : Interfaces.C.int;
Cond_Attr : aliased pthread_condattr_t;
begin
-- Give the task a unique serial number
Self_ID.Serial_Number := Next_Serial_Number;
Next_Serial_Number := Next_Serial_Number + 1;
pragma Assert (Next_Serial_Number /= 0);
Result := pthread_mutexattr_init (Mutex_Attr'Access);
pragma Assert (Result = 0 or else Result = ENOMEM);
if Result = 0 then
if Locking_Policy = 'C' then
Result :=
pthread_mutexattr_setprotocol
(Mutex_Attr'Access,
PTHREAD_PRIO_PROTECT);
pragma Assert (Result = 0);
Result :=
pthread_mutexattr_setprioceiling
(Mutex_Attr'Access,
Interfaces.C.int (System.Any_Priority'Last));
pragma Assert (Result = 0);
elsif Locking_Policy = 'I' then
Result :=
pthread_mutexattr_setprotocol
(Mutex_Attr'Access,
PTHREAD_PRIO_INHERIT);
pragma Assert (Result = 0);
end if;
Result :=
pthread_mutex_init
(Self_ID.Common.LL.L'Access,
Mutex_Attr'Access);
pragma Assert (Result = 0 or else Result = ENOMEM);
end if;
if Result /= 0 then
Succeeded := False;
return;
end if;
Result := pthread_mutexattr_destroy (Mutex_Attr'Access);
pragma Assert (Result = 0);
Result := pthread_condattr_init (Cond_Attr'Access);
pragma Assert (Result = 0 or else Result = ENOMEM);
if Result = 0 then
Result := GNAT_pthread_condattr_setup (Cond_Attr'Access);
pragma Assert (Result = 0);
Result :=
pthread_cond_init
(Self_ID.Common.LL.CV'Access, Cond_Attr'Access);
pragma Assert (Result = 0 or else Result = ENOMEM);
end if;
if Result = 0 then
Succeeded := True;
else
Result := pthread_mutex_destroy (Self_ID.Common.LL.L'Access);
pragma Assert (Result = 0);
Succeeded := False;
end if;
Result := pthread_condattr_destroy (Cond_Attr'Access);
pragma Assert (Result = 0);
end Initialize_TCB;
-----------------
-- Create_Task --
-----------------
procedure Create_Task
(T : Task_Id;
Wrapper : System.Address;
Stack_Size : System.Parameters.Size_Type;
Priority : System.Any_Priority;
Succeeded : out Boolean)
is
Attributes : aliased pthread_attr_t;
Adjusted_Stack_Size : Interfaces.C.size_t;
Page_Size : constant Interfaces.C.size_t :=
Interfaces.C.size_t (Get_Page_Size);
Result : Interfaces.C.int;
function Thread_Body_Access is new
Ada.Unchecked_Conversion (System.Address, Thread_Body);
use System.Task_Info;
begin
Adjusted_Stack_Size :=
Interfaces.C.size_t (Stack_Size + Alternate_Stack_Size);
if Stack_Base_Available then
-- If Stack Checking is supported then allocate 2 additional pages:
-- In the worst case, stack is allocated at something like
-- N * Get_Page_Size - epsilon, we need to add the size for 2 pages
-- to be sure the effective stack size is greater than what
-- has been asked.
Adjusted_Stack_Size := Adjusted_Stack_Size + 2 * Page_Size;
end if;
-- Round stack size as this is required by some OSes (Darwin)
Adjusted_Stack_Size := Adjusted_Stack_Size + Page_Size - 1;
Adjusted_Stack_Size :=
Adjusted_Stack_Size - Adjusted_Stack_Size mod Page_Size;
Result := pthread_attr_init (Attributes'Access);
pragma Assert (Result = 0 or else Result = ENOMEM);
if Result /= 0 then
Succeeded := False;
return;
end if;
Result :=
pthread_attr_setdetachstate
(Attributes'Access, PTHREAD_CREATE_DETACHED);
pragma Assert (Result = 0);
Result :=
pthread_attr_setstacksize
(Attributes'Access, Adjusted_Stack_Size);
pragma Assert (Result = 0);
if T.Common.Task_Info /= Default_Scope then
case T.Common.Task_Info is
when System.Task_Info.Process_Scope =>
Result :=
pthread_attr_setscope
(Attributes'Access, PTHREAD_SCOPE_PROCESS);
when System.Task_Info.System_Scope =>
Result :=
pthread_attr_setscope
(Attributes'Access, PTHREAD_SCOPE_SYSTEM);
when System.Task_Info.Default_Scope =>
Result := 0;
end case;
pragma Assert (Result = 0);
end if;
-- Since the initial signal mask of a thread is inherited from the
-- creator, and the Environment task has all its signals masked, we
-- do not need to manipulate caller's signal mask at this point.
-- All tasks in RTS will have All_Tasks_Mask initially.
-- Note: the use of Unrestricted_Access in the following call is needed
-- because otherwise we have an error of getting a access-to-volatile
-- value which points to a non-volatile object. But in this case it is
-- safe to do this, since we know we have no problems with aliasing and
-- Unrestricted_Access bypasses this check.
Result := pthread_create
(T.Common.LL.Thread'Unrestricted_Access,
Attributes'Access,
Thread_Body_Access (Wrapper),
To_Address (T));
pragma Assert (Result = 0 or else Result = EAGAIN);
Succeeded := Result = 0;
Result := pthread_attr_destroy (Attributes'Access);
pragma Assert (Result = 0);
if Succeeded then
Set_Priority (T, Priority);
end if;
end Create_Task;
------------------
-- Finalize_TCB --
------------------
procedure Finalize_TCB (T : Task_Id) is
Result : Interfaces.C.int;
begin
Result := pthread_mutex_destroy (T.Common.LL.L'Access);
pragma Assert (Result = 0);
Result := pthread_cond_destroy (T.Common.LL.CV'Access);
pragma Assert (Result = 0);
if T.Known_Tasks_Index /= -1 then
Known_Tasks (T.Known_Tasks_Index) := null;
end if;
ATCB_Allocation.Free_ATCB (T);
end Finalize_TCB;
---------------
-- Exit_Task --
---------------
procedure Exit_Task is
begin
-- Mark this task as unknown, so that if Self is called, it won't
-- return a dangling pointer.
Specific.Set (null);
end Exit_Task;
----------------
-- Abort_Task --
----------------
procedure Abort_Task (T : Task_Id) is
Result : Interfaces.C.int;
begin
if Abort_Handler_Installed then
Result :=
pthread_kill
(T.Common.LL.Thread,
Signal (System.Interrupt_Management.Abort_Task_Interrupt));
pragma Assert (Result = 0);
end if;
end Abort_Task;
----------------
-- Initialize --
----------------
procedure Initialize (S : in out Suspension_Object) is
Mutex_Attr : aliased pthread_mutexattr_t;
Cond_Attr : aliased pthread_condattr_t;
Result : Interfaces.C.int;
begin
-- Initialize internal state (always to False (RM D.10 (6)))
S.State := False;
S.Waiting := False;
-- Initialize internal mutex
Result := pthread_mutexattr_init (Mutex_Attr'Access);
pragma Assert (Result = 0 or else Result = ENOMEM);
if Result = ENOMEM then
raise Storage_Error;
end if;
Result := pthread_mutex_init (S.L'Access, Mutex_Attr'Access);
pragma Assert (Result = 0 or else Result = ENOMEM);
if Result = ENOMEM then
Result := pthread_mutexattr_destroy (Mutex_Attr'Access);
pragma Assert (Result = 0);
raise Storage_Error;
end if;
Result := pthread_mutexattr_destroy (Mutex_Attr'Access);
pragma Assert (Result = 0);
-- Initialize internal condition variable
Result := pthread_condattr_init (Cond_Attr'Access);
pragma Assert (Result = 0 or else Result = ENOMEM);
if Result /= 0 then
Result := pthread_mutex_destroy (S.L'Access);
pragma Assert (Result = 0);
-- Storage_Error is propagated as intended if the allocation of the
-- underlying OS entities fails.
raise Storage_Error;
else
Result := GNAT_pthread_condattr_setup (Cond_Attr'Access);
pragma Assert (Result = 0);
end if;
Result := pthread_cond_init (S.CV'Access, Cond_Attr'Access);
pragma Assert (Result = 0 or else Result = ENOMEM);
if Result /= 0 then
Result := pthread_mutex_destroy (S.L'Access);
pragma Assert (Result = 0);
Result := pthread_condattr_destroy (Cond_Attr'Access);
pragma Assert (Result = 0);
-- Storage_Error is propagated as intended if the allocation of the
-- underlying OS entities fails.
raise Storage_Error;
end if;
Result := pthread_condattr_destroy (Cond_Attr'Access);
pragma Assert (Result = 0);
end Initialize;
--------------
-- Finalize --
--------------
procedure Finalize (S : in out Suspension_Object) is
Result : Interfaces.C.int;
begin
-- Destroy internal mutex
Result := pthread_mutex_destroy (S.L'Access);
pragma Assert (Result = 0);
-- Destroy internal condition variable
Result := pthread_cond_destroy (S.CV'Access);
pragma Assert (Result = 0);
end Finalize;
-------------------
-- Current_State --
-------------------
function Current_State (S : Suspension_Object) return Boolean is
begin
-- We do not want to use lock on this read operation. State is marked
-- as Atomic so that we ensure that the value retrieved is correct.
return S.State;
end Current_State;
---------------
-- Set_False --
---------------
procedure Set_False (S : in out Suspension_Object) is
Result : Interfaces.C.int;
begin
SSL.Abort_Defer.all;
Result := pthread_mutex_lock (S.L'Access);
pragma Assert (Result = 0);
S.State := False;
Result := pthread_mutex_unlock (S.L'Access);
pragma Assert (Result = 0);
SSL.Abort_Undefer.all;
end Set_False;
--------------
-- Set_True --
--------------
procedure Set_True (S : in out Suspension_Object) is
Result : Interfaces.C.int;
begin
SSL.Abort_Defer.all;
Result := pthread_mutex_lock (S.L'Access);
pragma Assert (Result = 0);
-- If there is already a task waiting on this suspension object then
-- we resume it, leaving the state of the suspension object to False,
-- as it is specified in (RM D.10(9)). Otherwise, it just leaves
-- the state to True.
if S.Waiting then
S.Waiting := False;
S.State := False;
Result := pthread_cond_signal (S.CV'Access);
pragma Assert (Result = 0);
else
S.State := True;
end if;
Result := pthread_mutex_unlock (S.L'Access);
pragma Assert (Result = 0);
SSL.Abort_Undefer.all;
end Set_True;
------------------------
-- Suspend_Until_True --
------------------------
procedure Suspend_Until_True (S : in out Suspension_Object) is
Result : Interfaces.C.int;
begin
SSL.Abort_Defer.all;
Result := pthread_mutex_lock (S.L'Access);
pragma Assert (Result = 0);
if S.Waiting then
-- Program_Error must be raised upon calling Suspend_Until_True
-- if another task is already waiting on that suspension object
-- (RM D.10(10)).
Result := pthread_mutex_unlock (S.L'Access);
pragma Assert (Result = 0);
SSL.Abort_Undefer.all;
raise Program_Error;
else
-- Suspend the task if the state is False. Otherwise, the task
-- continues its execution, and the state of the suspension object
-- is set to False (ARM D.10 par. 9).
if S.State then
S.State := False;
else
S.Waiting := True;
loop
-- Loop in case pthread_cond_wait returns earlier than expected
-- (e.g. in case of EINTR caused by a signal).
Result := pthread_cond_wait (S.CV'Access, S.L'Access);
pragma Assert (Result = 0 or else Result = EINTR);
exit when not S.Waiting;
end loop;
end if;
Result := pthread_mutex_unlock (S.L'Access);
pragma Assert (Result = 0);
SSL.Abort_Undefer.all;
end if;
end Suspend_Until_True;
----------------
-- Check_Exit --
----------------
-- Dummy version
function Check_Exit (Self_ID : ST.Task_Id) return Boolean is
pragma Unreferenced (Self_ID);
begin
return True;
end Check_Exit;
--------------------
-- Check_No_Locks --
--------------------
function Check_No_Locks (Self_ID : ST.Task_Id) return Boolean is
pragma Unreferenced (Self_ID);
begin
return True;
end Check_No_Locks;
----------------------
-- Environment_Task --
----------------------
function Environment_Task return Task_Id is
begin
return Environment_Task_Id;
end Environment_Task;
--------------
-- Lock_RTS --
--------------
procedure Lock_RTS is
begin
Write_Lock (Single_RTS_Lock'Access);
end Lock_RTS;
----------------
-- Unlock_RTS --
----------------
procedure Unlock_RTS is
begin
Unlock (Single_RTS_Lock'Access);
end Unlock_RTS;
------------------
-- Suspend_Task --
------------------
function Suspend_Task
(T : ST.Task_Id;
Thread_Self : Thread_Id) return Boolean
is
pragma Unreferenced (T, Thread_Self);
begin
return False;
end Suspend_Task;
-----------------
-- Resume_Task --
-----------------
function Resume_Task
(T : ST.Task_Id;
Thread_Self : Thread_Id) return Boolean
is
pragma Unreferenced (T, Thread_Self);
begin
return False;
end Resume_Task;
--------------------
-- Stop_All_Tasks --
--------------------
procedure Stop_All_Tasks is
begin
null;
end Stop_All_Tasks;
---------------
-- Stop_Task --
---------------
function Stop_Task (T : ST.Task_Id) return Boolean is
pragma Unreferenced (T);
begin
return False;
end Stop_Task;
-------------------
-- Continue_Task --
-------------------
function Continue_Task (T : ST.Task_Id) return Boolean is
pragma Unreferenced (T);
begin
return False;
end Continue_Task;
----------------
-- Initialize --
----------------
procedure Initialize (Environment_Task : Task_Id) is
act : aliased struct_sigaction;
old_act : aliased struct_sigaction;
Tmp_Set : aliased sigset_t;
Result : Interfaces.C.int;
function State
(Int : System.Interrupt_Management.Interrupt_ID) return Character;
pragma Import (C, State, "__gnat_get_interrupt_state");
-- Get interrupt state. Defined in a-init.c
-- The input argument is the interrupt number,
-- and the result is one of the following:
Default : constant Character := 's';
-- 'n' this interrupt not set by any Interrupt_State pragma
-- 'u' Interrupt_State pragma set state to User
-- 'r' Interrupt_State pragma set state to Runtime
-- 's' Interrupt_State pragma set state to System (use "default"
-- system handler)
begin
Environment_Task_Id := Environment_Task;
Interrupt_Management.Initialize;
-- Prepare the set of signals that should unblocked in all tasks
Result := sigemptyset (Unblocked_Signal_Mask'Access);
pragma Assert (Result = 0);
for J in Interrupt_Management.Interrupt_ID loop
if System.Interrupt_Management.Keep_Unmasked (J) then
Result := sigaddset (Unblocked_Signal_Mask'Access, Signal (J));
pragma Assert (Result = 0);
end if;
end loop;
-- Initialize the lock used to synchronize chain of all ATCBs
Initialize_Lock (Single_RTS_Lock'Access, RTS_Lock_Level);
Specific.Initialize (Environment_Task);
if Use_Alternate_Stack then
Environment_Task.Common.Task_Alternate_Stack :=
Alternate_Stack'Address;
end if;
-- Make environment task known here because it doesn't go through
-- Activate_Tasks, which does it for all other tasks.
Known_Tasks (Known_Tasks'First) := Environment_Task;
Environment_Task.Known_Tasks_Index := Known_Tasks'First;
Enter_Task (Environment_Task);
if State
(System.Interrupt_Management.Abort_Task_Interrupt) /= Default
then
act.sa_flags := 0;
act.sa_handler := Abort_Handler'Address;
Result := sigemptyset (Tmp_Set'Access);
pragma Assert (Result = 0);
act.sa_mask := Tmp_Set;
Result :=
sigaction
(Signal (System.Interrupt_Management.Abort_Task_Interrupt),
act'Unchecked_Access,
old_act'Unchecked_Access);
pragma Assert (Result = 0);
Abort_Handler_Installed := True;
end if;
end Initialize;
-----------------------
-- Set_Task_Affinity --
-----------------------
procedure Set_Task_Affinity (T : ST.Task_Id) is
pragma Unreferenced (T);
begin
-- Setting task affinity is not supported by the underlying system
null;
end Set_Task_Affinity;
end System.Task_Primitives.Operations;
|
GPUWorks/lumen2 | Ada | 2,365 | ads |
-- Chip Richards, NiEstu, Phoenix AZ, Spring 2010
-- Lumen would not be possible without the support and contributions of a cast
-- of thousands, including and primarily Rod Kay.
-- This code is covered by the ISC License:
--
-- Copyright © 2010, NiEstu
--
-- Permission to use, copy, modify, and/or distribute this software for any
-- purpose with or without fee is hereby granted, provided that the above
-- copyright notice and this permission notice appear in all copies.
--
-- The software is provided "as is" and the author disclaims all warranties
-- with regard to this software including all implied warranties of
-- merchantability and fitness. In no event shall the author be liable for any
-- special, direct, indirect, or consequential damages or any damages
-- whatsoever resulting from loss of use, data or profits, whether in an
-- action of contract, negligence or other tortious action, arising out of or
-- in connection with the use or performance of this software.
package Lumen.Events is
-- Translated keysym type and value
type Key_Category is (Key_Control, Key_Graphic, Key_Modifier, Key_Function,
Key_Special, Key_Unknown, Key_Not_Translated);
subtype Key_Symbol is Long_Integer;
-- Keystroke and pointer modifiers
type Modifier is (Mod_Shift, Mod_Lock, Mod_Control, Mod_1, Mod_2, Mod_3,
Mod_4, Mod_5, Mod_Button_1, Mod_Button_2, Mod_Button_3,
Mod_Button_4, Mod_Button_5);
type Modifier_Set is array (Modifier) of Boolean;
No_Modifiers : Modifier_Set := (others => False);
Not_Character : exception; -- key symbol is not a Latin-1 character
---------------------------------------------------------------------------
-- Key translation helpers
-- Convert a Key_Symbol into a Latin-1 character; raises Not_Character if
-- it's not possible. Character'Val is simpler.
function To_Character (Symbol : in Key_Symbol) return Character;
-- Convert a Key_Symbol into a UTF-8 encoded string; raises Not_Character
-- if it's not possible. Really only useful for Latin-1 hibit chars, but
-- works for all Latin-1 chars.
function To_UTF_8 (Symbol : in Key_Symbol) return String;
-- Convert a normal Latin-1 character to a Key_Symbol
function To_Symbol (Char : in Character) return Key_Symbol;
end Lumen.Events;
|
ohenley/ada-util | Ada | 22,449 | adb | -----------------------------------------------------------------------
-- AUnit utils - Helper for writing unit tests
-- Copyright (C) 2009, 2010, 2011, 2012, 2013, 2017 Stephane Carrez
-- Written by Stephane Carrez ([email protected])
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-----------------------------------------------------------------------
with GNAT.Command_Line;
with GNAT.Regpat;
with GNAT.Traceback.Symbolic;
with Ada.Command_Line;
with Ada.Directories;
with Ada.IO_Exceptions;
with Ada.Text_IO;
with Ada.Calendar.Formatting;
with Ada.Exceptions;
with Ada.Containers;
with Util.Strings;
with Util.Measures;
with Util.Files;
with Util.Strings.Vectors;
with Util.Log.Loggers;
package body Util.Tests is
Test_Properties : Util.Properties.Manager;
-- When a test uses external test files to match a result against a well
-- defined content, it can be difficult to maintain those external files.
-- The <b>Assert_Equal_Files</b> can automatically maintain the reference
-- file by updating it with the lastest test result.
--
-- Of course, using this mode means the test does not validate anything.
Update_Test_Files : Boolean := False;
-- The default timeout for a test case execution.
Default_Timeout : Duration := 60.0;
-- A prefix that is added to the test class names. Adding a prefix is useful when
-- the same testsuite is executed several times with different configurations. It allows
-- to track and identify the tests in different environments and have a global view
-- in Jenkins. See option '-p prefix'.
Harness_Prefix : Unbounded_String;
-- Verbose flag activated by the '-v' option.
Verbose_Flag : Boolean := False;
-- When not empty, defines the name of the test that is enabled. Other tests are disabled.
-- This is initialized by the -r test option.
Enabled_Test : Unbounded_String;
-- ------------------------------
-- Get a path to access a test file.
-- ------------------------------
function Get_Path (File : String) return String is
Dir : constant String := Get_Parameter ("test.dir", ".");
begin
return Dir & "/" & File;
end Get_Path;
-- ------------------------------
-- Get a path to create a test file.
-- ------------------------------
function Get_Test_Path (File : String) return String is
Dir : constant String := Get_Parameter ("test.result.dir", ".");
begin
return Dir & "/" & File;
end Get_Test_Path;
-- ------------------------------
-- Get the timeout for the test execution.
-- ------------------------------
function Get_Test_Timeout (Name : in String) return Duration is
Prop_Name : constant String := "test.timeout." & Name;
Value : constant String := Test_Properties.Get (Prop_Name,
Duration'Image (Default_Timeout));
begin
return Duration'Value (Value);
exception
when Constraint_Error =>
return Default_Timeout;
end Get_Test_Timeout;
-- ------------------------------
-- Get the testsuite harness prefix. This prefix is added to the test class name.
-- By default it is empty. It is allows to execute the test harness on different
-- environment (ex: MySQL or SQLlite) and be able to merge and collect the two result
-- sets together.
-- ------------------------------
function Get_Harness_Prefix return String is
begin
return To_String (Harness_Prefix);
end Get_Harness_Prefix;
-- ------------------------------
-- Get a test configuration parameter.
-- ------------------------------
function Get_Parameter (Name : String;
Default : String := "") return String is
begin
return Test_Properties.Get (Name, Default);
end Get_Parameter;
-- ------------------------------
-- Get the test configuration properties.
-- ------------------------------
function Get_Properties return Util.Properties.Manager is
begin
return Test_Properties;
end Get_Properties;
-- ------------------------------
-- Get a new unique string
-- ------------------------------
function Get_Uuid return String is
Time : constant Ada.Calendar.Time := Ada.Calendar.Clock;
Year : Ada.Calendar.Year_Number;
Month : Ada.Calendar.Month_Number;
Day : Ada.Calendar.Day_Number;
T : Ada.Calendar.Day_Duration;
V : Long_Long_Integer;
begin
Ada.Calendar.Split (Date => Time,
Year => Year,
Month => Month,
Day => Day,
Seconds => T);
V := (Long_Long_Integer (Year) * 365 * 24 * 3600 * 1000)
+ (Long_Long_Integer (Month) * 31 * 24 * 3600 * 1000)
+ (Long_Long_Integer (Day) * 24 * 3600 * 1000)
+ (Long_Long_Integer (T * 1000));
return "U" & Util.Strings.Image (V);
end Get_Uuid;
-- ------------------------------
-- Get the verbose flag that can be activated with the <tt>-v</tt> option.
-- ------------------------------
function Verbose return Boolean is
begin
return Verbose_Flag;
end Verbose;
-- ------------------------------
-- Returns True if the test with the given name is enabled.
-- By default all the tests are enabled. When the -r test option is passed
-- all the tests are disabled except the test specified by the -r option.
-- ------------------------------
function Is_Test_Enabled (Name : in String) return Boolean is
begin
return Length (Enabled_Test) = 0 or Enabled_Test = Name;
end Is_Test_Enabled;
-- ------------------------------
-- Check that the value matches what we expect.
-- ------------------------------
procedure Assert_Equals (T : in Test'Class;
Expect, Value : in Ada.Calendar.Time;
Message : in String := "Test failed";
Source : String := GNAT.Source_Info.File;
Line : Natural := GNAT.Source_Info.Line) is
use Ada.Calendar.Formatting;
use Ada.Calendar;
begin
T.Assert (Condition => Image (Expect) = Image (Value),
Message => Message & ": expecting '" & Image (Expect) & "'"
& " value was '" & Image (Value) & "'",
Source => Source,
Line => Line);
end Assert_Equals;
-- ------------------------------
-- Check that the value matches what we expect.
-- ------------------------------
procedure Assert_Equals (T : in Test'Class;
Expect, Value : in String;
Message : in String := "Test failed";
Source : String := GNAT.Source_Info.File;
Line : Natural := GNAT.Source_Info.Line) is
begin
T.Assert (Condition => Expect = Value,
Message => Message & ": expecting '" & Expect & "'"
& " value was '" & Value & "'",
Source => Source,
Line => Line);
end Assert_Equals;
-- ------------------------------
-- Check that the value matches what we expect.
-- ------------------------------
procedure Assert_Equals (T : in Test'Class;
Expect : in String;
Value : in Unbounded_String;
Message : in String := "Test failed";
Source : String := GNAT.Source_Info.File;
Line : Natural := GNAT.Source_Info.Line) is
begin
Assert_Equals (T => T,
Expect => Expect,
Value => To_String (Value),
Message => Message,
Source => Source,
Line => Line);
end Assert_Equals;
-- ------------------------------
-- Check that the value matches the regular expression
-- ------------------------------
procedure Assert_Matches (T : in Test'Class;
Pattern : in String;
Value : in Unbounded_String;
Message : in String := "Test failed";
Source : String := GNAT.Source_Info.File;
Line : Natural := GNAT.Source_Info.Line) is
begin
Assert_Matches (T => T,
Pattern => Pattern,
Value => To_String (Value),
Message => Message,
Source => Source,
Line => Line);
end Assert_Matches;
-- ------------------------------
-- Check that the value matches the regular expression
-- ------------------------------
procedure Assert_Matches (T : in Test'Class;
Pattern : in String;
Value : in String;
Message : in String := "Test failed";
Source : String := GNAT.Source_Info.File;
Line : Natural := GNAT.Source_Info.Line) is
use GNAT.Regpat;
Regexp : constant Pattern_Matcher := Compile (Expression => Pattern,
Flags => Multiple_Lines);
begin
T.Assert (Condition => Match (Regexp, Value),
Message => Message & ". Value '" & Value & "': Does not Match '"
& Pattern & "'",
Source => Source,
Line => Line);
end Assert_Matches;
-- ------------------------------
-- Check that the file exists.
-- ------------------------------
procedure Assert_Exists (T : in Test'Class;
File : in String;
Message : in String := "Test failed";
Source : String := GNAT.Source_Info.File;
Line : Natural := GNAT.Source_Info.Line) is
begin
T.Assert (Condition => Ada.Directories.Exists (File),
Message => Message & ": file '" & File & "' does not exist",
Source => Source,
Line => Line);
end Assert_Exists;
-- ------------------------------
-- Check that two files are equal. This is intended to be used by
-- tests that create files that are then checked against patterns.
-- ------------------------------
procedure Assert_Equal_Files (T : in Test_Case'Class;
Expect : in String;
Test : in String;
Message : in String := "Test failed";
Source : String := GNAT.Source_Info.File;
Line : Natural := GNAT.Source_Info.Line) is
use Util.Files;
use type Ada.Containers.Count_Type;
use type Util.Strings.Vectors.Vector;
Expect_File : Util.Strings.Vectors.Vector;
Test_File : Util.Strings.Vectors.Vector;
Same : Boolean;
begin
begin
if not Ada.Directories.Exists (Expect) then
T.Assert (Condition => False,
Message => "Expect file '" & Expect & "' does not exist",
Source => Source, Line => Line);
end if;
Read_File (Path => Expect,
Into => Expect_File);
Read_File (Path => Test,
Into => Test_File);
exception
when others =>
if Update_Test_Files then
Ada.Directories.Copy_File (Source_Name => Test,
Target_Name => Expect);
else
raise;
end if;
end;
if Expect_File.Length /= Test_File.Length then
if Update_Test_Files then
Ada.Directories.Copy_File (Source_Name => Test,
Target_Name => Expect);
end if;
-- Check file sizes
Assert_Equals (T => T,
Expect => Natural (Expect_File.Length),
Value => Natural (Test_File.Length),
Message => Message & ": Invalid number of lines",
Source => Source,
Line => Line);
end if;
Same := Expect_File = Test_File;
if Same then
return;
end if;
if Update_Test_Files then
Ada.Directories.Copy_File (Source_Name => Test,
Target_Name => Expect);
end if;
T.Assert (Condition => False,
Message => Message & ": Content is different on some lines",
Source => Source,
Line => Line);
end Assert_Equal_Files;
-- ------------------------------
-- Check that two files are equal. This is intended to be used by
-- tests that create files that are then checked against patterns.
-- ------------------------------
procedure Assert_Equal_Files (T : in Test'Class;
Expect : in String;
Test : in String;
Message : in String := "Test failed";
Source : String := GNAT.Source_Info.File;
Line : Natural := GNAT.Source_Info.Line) is
use Util.Files;
use type Ada.Containers.Count_Type;
use type Util.Strings.Vectors.Vector;
Expect_File : Util.Strings.Vectors.Vector;
Test_File : Util.Strings.Vectors.Vector;
Same : Boolean;
begin
begin
if not Ada.Directories.Exists (Expect) then
T.Assert (Condition => False,
Message => "Expect file '" & Expect & "' does not exist",
Source => Source, Line => Line);
end if;
Read_File (Path => Expect,
Into => Expect_File);
Read_File (Path => Test,
Into => Test_File);
exception
when others =>
if Update_Test_Files then
Ada.Directories.Copy_File (Source_Name => Test,
Target_Name => Expect);
else
raise;
end if;
end;
if Expect_File.Length /= Test_File.Length then
if Update_Test_Files then
Ada.Directories.Copy_File (Source_Name => Test,
Target_Name => Expect);
end if;
-- Check file sizes
Assert_Equals (T => T,
Expect => Natural (Expect_File.Length),
Value => Natural (Test_File.Length),
Message => Message & ": Invalid number of lines",
Source => Source,
Line => Line);
end if;
Same := Expect_File = Test_File;
if Same then
return;
end if;
if Update_Test_Files then
Ada.Directories.Copy_File (Source_Name => Test,
Target_Name => Expect);
end if;
Fail (T => T,
Message => Message & ": Content is different on some lines",
Source => Source,
Line => Line);
end Assert_Equal_Files;
-- ------------------------------
-- Report a test failed.
-- ------------------------------
procedure Fail (T : in Test'Class;
Message : in String := "Test failed";
Source : in String := GNAT.Source_Info.File;
Line : in Natural := GNAT.Source_Info.Line) is
begin
T.Assert (False, Message, Source, Line);
end Fail;
-- ------------------------------
-- Default initialization procedure.
-- ------------------------------
procedure Initialize_Test (Props : in Util.Properties.Manager) is
begin
null;
end Initialize_Test;
-- ------------------------------
-- The main testsuite program. This launches the tests, collects the
-- results, create performance logs and set the program exit status
-- according to the testsuite execution status.
--
-- The <b>Initialize</b> procedure is called before launching the unit tests. It is intended
-- to configure the tests according to some external environment (paths, database access).
--
-- The <b>Finish</b> procedure is called after the test suite has executed.
-- ------------------------------
procedure Harness (Name : in String) is
use GNAT.Command_Line;
use Ada.Text_IO;
use type Util.XUnit.Status;
procedure Help;
procedure Help is
begin
Put_Line ("Test harness: " & Name);
Put ("Usage: harness [-xml result.xml] [-t timeout] [-p prefix] [-v]"
& "[-config file.properties] [-d dir] [-r testname]");
Put_Line ("[-update]");
Put_Line ("-xml file Produce an XML test report");
Put_Line ("-config file Specify a test configuration file");
Put_Line ("-d dir Change the current directory to <dir>");
Put_Line ("-t timeout Test execution timeout in seconds");
Put_Line ("-v Activate the verbose test flag");
Put_Line ("-p prefix Add the prefix to the test class names");
Put_Line ("-r testname Run only the tests for the given testsuite name");
Put_Line ("-update Update the test reference files if a file");
Put_Line (" is missing or the test generates another output");
Put_Line (" (See Assert_Equals_File)");
Ada.Command_Line.Set_Exit_Status (2);
end Help;
Perf : aliased Util.Measures.Measure_Set;
Result : Util.XUnit.Status;
XML : Boolean := False;
Output : Ada.Strings.Unbounded.Unbounded_String;
Chdir : Ada.Strings.Unbounded.Unbounded_String;
begin
loop
case Getopt ("h u v x: t: p: c: config: d: r: update help xml: timeout:") is
when ASCII.NUL =>
exit;
when 'c' =>
declare
Name : constant String := Parameter;
begin
Test_Properties.Load_Properties (Name);
Default_Timeout := Get_Test_Timeout ("default");
exception
when Ada.IO_Exceptions.Name_Error =>
Ada.Text_IO.Put_Line ("Cannot find configuration file: " & Name);
Ada.Command_Line.Set_Exit_Status (2);
return;
end;
when 'd' =>
Chdir := To_Unbounded_String (Parameter);
when 'u' =>
Update_Test_Files := True;
when 't' =>
begin
Default_Timeout := Duration'Value (Parameter);
exception
when Constraint_Error =>
Ada.Text_IO.Put_Line ("Invalid timeout: " & Parameter);
Ada.Command_Line.Set_Exit_Status (2);
return;
end;
when 'r' =>
Enabled_Test := To_Unbounded_String (Parameter);
when 'p' =>
Harness_Prefix := To_Unbounded_String (Parameter & " ");
when 'v' =>
Verbose_Flag := True;
when 'x' =>
XML := True;
Output := To_Unbounded_String (Parameter);
when others =>
Help;
return;
end case;
end loop;
-- Initialization is optional. Get the log configuration by reading the property
-- file 'samples/log4j.properties'. The 'log.util' logger will use a DEBUG level
-- and write the message in 'result.log'.
Util.Log.Loggers.Initialize (Test_Properties);
Initialize (Test_Properties);
if Length (Chdir) /= 0 then
begin
Ada.Directories.Set_Directory (To_String (Chdir));
exception
when Ada.IO_Exceptions.Name_Error =>
Put_Line ("Invalid directory " & To_String (Chdir));
Ada.Command_Line.Set_Exit_Status (1);
return;
end;
end if;
declare
procedure Runner is new Util.XUnit.Harness (Suite);
S : Util.Measures.Stamp;
begin
Util.Measures.Set_Current (Perf'Unchecked_Access);
Runner (Output, XML, Result);
Util.Measures.Report (Perf, S, "Testsuite execution");
Util.Measures.Write (Perf, "Test measures", Name);
end;
Finish (Result);
-- Program exit status reflects the testsuite result
if Result /= Util.XUnit.Success then
Ada.Command_Line.Set_Exit_Status (1);
else
Ada.Command_Line.Set_Exit_Status (0);
end if;
exception
when Invalid_Switch =>
Put_Line ("Invalid Switch " & Full_Switch);
Help;
return;
when Invalid_Parameter =>
Put_Line ("No parameter for " & Full_Switch);
Help;
return;
when E : others =>
Put_Line ("Exception: " & Ada.Exceptions.Exception_Name (E));
Put_Line ("Message: " & Ada.Exceptions.Exception_Message (E));
Put_Line ("Stacktrace:");
Put_Line (GNAT.Traceback.Symbolic.Symbolic_Traceback (E));
Ada.Command_Line.Set_Exit_Status (4);
end Harness;
end Util.Tests;
|
reznikmm/matreshka | Ada | 4,043 | ads | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Open Document Toolkit --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2014, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
with ODF.DOM.Table_Display_Border_Attributes;
package Matreshka.ODF_Table.Display_Border_Attributes is
type Table_Display_Border_Attribute_Node is
new Matreshka.ODF_Table.Abstract_Table_Attribute_Node
and ODF.DOM.Table_Display_Border_Attributes.ODF_Table_Display_Border_Attribute
with null record;
overriding function Create
(Parameters : not null access Matreshka.DOM_Attributes.Attribute_L2_Parameters)
return Table_Display_Border_Attribute_Node;
overriding function Get_Local_Name
(Self : not null access constant Table_Display_Border_Attribute_Node)
return League.Strings.Universal_String;
end Matreshka.ODF_Table.Display_Border_Attributes;
|
iyan22/AprendeAda | Ada | 1,390 | adb |
with ada.text_io, ada.integer_text_io;
use ada.text_io, ada.integer_text_io;
with grafico;
-- Gracias Ekaitz ;)
procedure prueba_grafico is
n1:integer:=0;
begin
-- caso de prueba 1:
n1:=4;
put("El resultado deberia de ser:");
new_line;
put("*000");
new_line;
put("**00");
new_line;
put("***0");
new_line;
put("****");
new_line;
put("Y tu programa dice que:");
new_line;
grafico(n1);
new_line;
-- caso de prueba 2:
n1:=1;
put("El resultado deberia de ser:");
new_line;
put("*");
new_line;
put("Y tu programa dice que:");
new_line;
grafico(n1);
new_line;
-- caso de prueba 3:
n1:=10;
put("El resultado deberia de ser:");
new_line;
put("*000000000");
new_line;
put("**00000000");
new_line;
put("***0000000");
new_line;
put("****000000");
new_line;
put("*****00000");
new_line;
put("******0000");
new_line;
put("*******000");
new_line;
put("********00");
new_line;
put("*********0");
new_line;
put("**********");
new_line;
put("Y tu programa dice que:");
new_line;
grafico(n1);
-- caso de prueba 4:
n1:=2;
put("El resultado deberia de ser:");
new_line;
put("*0");
new_line;
put("**");
new_line;
put("Y tu programa dice que:");
new_line;
grafico(n1);
end prueba_grafico;
|
burratoo/Acton | Ada | 10,491 | ads | ------------------------------------------------------------------------------------------
-- --
-- OAK COMPONENTS --
-- --
-- OAK.AGENT.SCHEDULERS --
-- --
-- Copyright (C) 2010-2021, Patrick Bernardi --
-- --
------------------------------------------------------------------------------------------
-- This package provides Oak's Scheduler Agents, the agents that that provide
-- Oak's scheduling services. The Agent extends the Oak Agent data structure
-- to include scheduler related components to allow Oak to interact and manage
-- these Agents and the scheduling services they provide.
with Oak.Agent.Storage;
with Oak.Agent.Oak_Agent; use Oak.Agent.Oak_Agent;
with Oak.Oak_Time; use Oak.Oak_Time;
with Oak.Timers; use Oak.Timers;
with System; use System;
with System.Storage_Elements; use System.Storage_Elements;
package Oak.Agent.Schedulers with Preelaborate is
-----------
-- Types --
-----------
type Active_Till is (Always_Active, Deadline, Budget_Exhaustion);
-- A type to represent whether the scheduler agent runs until its deadline
-- or budget expires.
type No_Agent_Interpretation is (As_Is, Sleep_Agent);
-- The No_Agent can mean No_Agent or Sleep_Agent. Generally this does not
-- cause any issue except for when a scheduler agent wants to explicitly
-- schedule the sleep agent (for example a polling server)
-----------------
-- Subprograms --
-----------------
function Agent_To_Run (Agent : in Scheduler_Id) return Oak_Agent_Id;
-- Get the Agent that the Scheduler Agent has nominated to run.
function Charge_While_No_Agent (Agent : in Scheduler_Id) return Boolean;
-- Returns true if the scheduler agent remains in the charge list while the
-- agent No_Agent is selected.
function Highest_Resposible_Priority
(Agent : in Scheduler_Id)
return Any_Priority;
-- Returns the highest priority that the Scheduler Agent is responsible
-- for.
function Interpret_No_Agent_As (Agent : in Scheduler_Id)
return No_Agent_Interpretation;
-- Returns how a No_Agent Agent_To_Run value is to be interpretated, either
-- as a No_Agent or as a Sleep_Agent.
function Is_Scheduler_Active (Scheduler : in Scheduler_Id) return Boolean;
-- Returns true if the scheduler agent is active and is able to dispatch
-- tasks.
function Lowest_Resposible_Priority
(Agent : in Scheduler_Id)
return Any_Priority;
-- Returns the lowest priority that the Scheduler Agent is responsible for.
procedure New_Scheduler_Agent
(Agent : out Scheduler_Id;
Name : in String;
Call_Stack_Size : in Storage_Count;
Run_Loop : in Address;
Lowest_Priority : in Any_Priority;
Highest_Priority : in Any_Priority;
Scheduler_Agent : in Scheduler_Id_With_No := No_Agent;
When_To_Charge_Agent : in Charge_Occurrence := Only_While_Running;
Interpret_No_Agent_As : in No_Agent_Interpretation := As_Is;
Charge_While_No_Agent : in Boolean := False;
Agent_Active_Till : in Active_Till := Always_Active;
Cycle_Period : in Oak_Time.Time_Span := Time_Span_Last;
Cycle_Phase : in Oak_Time.Time_Span := Time_Span_Zero;
Relative_Deadline : in Oak_Time.Time_Span := Time_Span_Last;
Execution_Budget : in Oak_Time.Time_Span := Time_Span_Last);
-- Creates a new Scheduler Agent with the given parameters. Allocates the
-- the storage for the Scheduler Agent data structure and any dependents.
procedure Set_Agent_To_Run
(For_Agent : in Scheduler_Id;
Agent_To_Run : in Oak_Agent_Id) with Inline;
-- Stores the Agent that the Scheduler Agent's has nominated to run.
procedure Set_Next_Cycle_Start_Time
(Scheduler : in Scheduler_Id;
Start_Time : in Oak_Time.Time) with Inline;
-- Sets the time that the next cycle will commmence.
procedure Set_Priority_Range
(Agent : in Scheduler_Id;
From : in Any_Priority;
To : in Any_Priority) with Inline;
-- Stores the priority range that the Scheduler Agent is responisble for.
procedure Set_Is_Scheduler_Active
(Scheduler : in Scheduler_Id;
Active : in Boolean) with Inline;
-- Sets whether the scheduler agent is active and is able to dispatch
-- tasks or not.
function Scheduler_Active_Till
(Scheduler : in Scheduler_Id) return Active_Till;
-- Returns the event that causes the scheduler agent to inactivate and go
-- to sleep.
function Scheduler_Cycle_Period
(Scheduler : in Scheduler_Id) return Oak_Time.Time_Span;
-- The cycle period of the scheduler.
function Scheduler_Cycle_Phase
(Scheduler : in Scheduler_Id) return Oak_Time.Time_Span;
-- The cycle phase of the scheduler.
function Scheduler_Relative_Deadline
(Scheduler : in Scheduler_Id) return Oak_Time.Time_Span;
-- The cycle relative deadline of the scheduler agent.
function Scheduler_Execution_Budget
(Scheduler : in Scheduler_Id) return Oak_Time.Time_Span;
-- The cycle execution budget of the scheduler agent.
function Time_Next_Cycle_Commences (Agent : in Scheduler_Id)
return Oak_Time.Time;
-- The time that the scheduler agent's next cycle is due to commence.
function Timer_For_Scheduler_Agent
(Agent : in Scheduler_Id)
return Oak_Timer_Id;
-- Returns the timer associated with the Scheduler Agent, used to run the
-- agent when it needs to manage it queues and another agent is running.
private
-------------------
-- Private Types --
-------------------
type Scheduler_Agent_Record is record
-- Core Scheduler Agent Components
Lowest_Priority : Any_Priority;
-- The lowest priority that the Agent is responsible for.
Highest_Priority : Any_Priority;
-- The highest priority that the Agent is responsible for.
Agent_To_Run : Oak_Agent_Id;
-- The agent selected to run by this Scheduler Agent.
Run_Timer : Oak_Timer_Id;
-- An Oak Timer is used to wake the Scheduler Agent when it needs to
-- manage its queues.
-- The following is only used for nested scheduler agents
Interpret_No_Agent_As : No_Agent_Interpretation;
-- When the scheduler agent returns No_Agent, what it is interpreted as
-- (either as a No_Agent or as the Sleep_Agent).
Charge_While_No_Agent : Boolean;
-- Does the scheduler agent's budget get charged while No_Agent is
-- selected by the agent.
Agent_Active_Till : Active_Till;
-- Whether the scheduler agent runs till the expiry of its deadline or
-- budget. This allows the user to allow the scheduler agent to run
-- against actual processor usage or the wall clock.
Scheduler_Active : Boolean;
-- Specifies whether the agent is active – that is able to dispatch
-- agents – or not.
Next_Run_Cycle : Oak_Time.Time;
-- The time of the next run cycle is meant to commence for periodic
-- tasks or the earliest time a spfor the scheduler agent.
Period : Oak_Time.Time_Span;
-- The period of which the scheduler agent run at.
Phase : Oak_Time.Time_Span;
-- The phase of the scheduler agent.
Relative_Deadline : Oak_Time.Time_Span;
-- The relative deadline of the scheduler agent.
Execution_Budget : Oak_Time.Time_Span;
-- The amount of processor time the agent may execute for in a given
-- cycle.
end record;
-----------------------------
-- Scheduler Agent Storage --
-----------------------------
package Scheduler_Pool is new Oak.Agent.Storage
(Agent_Record_Type => Scheduler_Agent_Record,
Agent_Id_Type => Scheduler_Id);
use Scheduler_Pool;
--------------------------
-- Function Expressions --
--------------------------
function Agent_To_Run (Agent : in Scheduler_Id) return Oak_Agent_Id is
(Agent_Pool (Agent).Agent_To_Run);
function Charge_While_No_Agent (Agent : in Scheduler_Id) return Boolean is
(Agent_Pool (Agent).Charge_While_No_Agent);
function Highest_Resposible_Priority
(Agent : in Scheduler_Id)
return Any_Priority is (Agent_Pool (Agent).Highest_Priority);
function Interpret_No_Agent_As
(Agent : in Scheduler_Id)
return No_Agent_Interpretation is
(Agent_Pool (Agent).Interpret_No_Agent_As);
function Is_Scheduler_Active (Scheduler : in Scheduler_Id) return Boolean is
(Agent_Pool (Scheduler).Scheduler_Active);
function Lowest_Resposible_Priority
(Agent : in Scheduler_Id)
return Any_Priority is (Agent_Pool (Agent).Lowest_Priority);
function Scheduler_Active_Till
(Scheduler : in Scheduler_Id) return Active_Till is
(Agent_Pool (Scheduler).Agent_Active_Till);
function Scheduler_Cycle_Period
(Scheduler : in Scheduler_Id) return Oak_Time.Time_Span is
(Agent_Pool (Scheduler).Period);
function Scheduler_Cycle_Phase
(Scheduler : in Scheduler_Id) return Oak_Time.Time_Span is
(Agent_Pool (Scheduler).Phase);
function Scheduler_Relative_Deadline
(Scheduler : in Scheduler_Id) return Oak_Time.Time_Span is
(Agent_Pool (Scheduler).Relative_Deadline);
function Scheduler_Execution_Budget
(Scheduler : in Scheduler_Id) return Oak_Time.Time_Span is
(Agent_Pool (Scheduler).Execution_Budget);
function Time_Next_Cycle_Commences
(Agent : in Scheduler_Id)
return Oak_Time.Time is
(Agent_Pool (Agent).Next_Run_Cycle);
function Timer_For_Scheduler_Agent
(Agent : in Scheduler_Id)
return Oak_Timer_Id
is (Agent_Pool (Agent).Run_Timer);
end Oak.Agent.Schedulers;
|
DerickEddington/tarmi | Ada | 892 | ads | -- TODO: Figure-out the memory management issues... is it
-- possible to use only standard Ada facilities, or is an
-- additional GC unavoidable?
package Tarmi is
type Datum_R is abstract tagged null record;
type Datum is not null access constant Datum_R'Class;
type Pair_R is new Datum_R with
record
First : Datum;
Second : Datum;
end record;
type Pair is not null access constant Pair_R;
subtype String_Type is Standard.String;
Nil : constant Datum;
Ignore : constant Datum;
Not_Implemented : exception; -- TODO: remove when development done
private
type Singleton is new Datum_R with null record;
Nil_Obj : aliased constant Singleton := (null record);
Nil : constant Datum := Nil_Obj'Access;
Ignore_Obj : aliased constant Singleton := (null record);
Ignore : constant Datum := Ignore_Obj'Access;
end Tarmi;
|
ekoeppen/MSP430_Generic_Ada_Drivers | Ada | 466 | ads | with MSPGD.GPIO; use MSPGD.GPIO;
generic
Pin : Pin_Type;
Port : Port_Type;
Alt_Func : Alt_Func_Type := IO;
Direction : Direction_Type := Input;
Pull_Resistor : Resistor_Type := None;
package MSPGD.GPIO.Pin is
pragma Preelaborate;
procedure Init
with Inline_Always;
procedure Set
with Inline_Always;
procedure Clear
with Inline_Always;
function Is_Set return Boolean
with Inline_Always;
end MSPGD.GPIO.Pin;
|
HeisenbugLtd/msg_passing | Ada | 950 | ads | ------------------------------------------------------------------------
-- Copyright (C) 2010-2020 by Heisenbug Ltd. ([email protected])
--
-- This work is free. You can redistribute it and/or modify it under
-- the terms of the Do What The Fuck You Want To Public License,
-- Version 2, as published by Sam Hocevar. See the LICENSE file for
-- more details.
------------------------------------------------------------------------
pragma License (Unrestricted);
------------------------------------------------------------------------
-- The only thing Sender and Receiver share directly is the type of
-- message being exchanged.
------------------------------------------------------------------------
package Message_Types with
Pure => True,
Remote_Types => True
is
-- We only support definite types, so the message is a string of 30
-- characters.
type The_Message is new String (1 .. 30);
end Message_Types;
|
strenkml/EE368 | Ada | 7,744 | adb |
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
package body Parser is
procedure Parse_Arbiter(parser : in out Parser_Type;
result : out Memory_Pointer) is separate;
procedure Parse_Cache(parser : in out Parser_Type;
result : out Memory_Pointer) is separate;
procedure Parse_DRAM(parser : in out Parser_Type;
result : out Memory_Pointer) is separate;
procedure Parse_Dup(parser : in out Parser_Type;
result : out Memory_Pointer) is separate;
procedure Parse_EOR(parser : in out Parser_Type;
result : out Memory_Pointer) is separate;
procedure Parse_Flash(parser : in out Parser_Type;
result : out Memory_Pointer) is separate;
procedure Parse_Flip(parser : in out Parser_Type;
result : out Memory_Pointer) is separate;
procedure Parse_Join(parser : in out Parser_Type;
result : out Memory_Pointer) is separate;
procedure Parse_Offset(parser : in out Parser_Type;
result : out Memory_Pointer) is separate;
procedure Parse_Option(parser : in out Parser_Type;
result : out Memory_Pointer) is separate;
procedure Parse_Perfect_Prefetch(parser : in out Parser_Type;
result : out Memory_Pointer) is separate;
procedure Parse_Prefetch(parser : in out Parser_Type;
result : out Memory_Pointer) is separate;
procedure Parse_RAM(parser : in out Parser_Type;
result : out Memory_Pointer) is separate;
procedure Parse_Register(parser : in out Parser_Type;
result : out Memory_Pointer) is separate;
procedure Parse_Shift(parser : in out Parser_Type;
result : out Memory_Pointer) is separate;
procedure Parse_Split(parser : in out Parser_Type;
result : out Memory_Pointer) is separate;
procedure Parse_SPM(parser : in out Parser_Type;
result : out Memory_Pointer) is separate;
procedure Parse_Stats(parser : in out Parser_Type;
result : out Memory_Pointer) is separate;
procedure Parse_Super(parser : in out Parser_Type;
result : out Memory_Pointer) is separate;
procedure Parse_Trace(parser : in out Parser_Type;
result : out Memory_Pointer) is separate;
type Memory_Parser_Type is record
name : Unbounded_String;
parser : access procedure(parser : in out Parser_Type;
result : out Memory_Pointer);
end record;
type Memory_Parser_Array is array(Positive range <>) of Memory_Parser_Type;
parser_map : constant Memory_Parser_Array := (
(To_Unbounded_String("arbiter"), Parse_Arbiter'Access),
(To_Unbounded_String("cache"), Parse_Cache'Access),
(To_Unbounded_String("dram"), Parse_DRAM'Access),
(To_Unbounded_String("dup"), Parse_Dup'Access),
(To_Unbounded_String("eor"), Parse_EOR'Access),
(To_Unbounded_String("flash"), Parse_Flash'Access),
(To_Unbounded_String("flip"), Parse_Flip'Access),
(To_Unbounded_String("join"), Parse_Join'Access),
(To_Unbounded_String("offset"), Parse_Offset'Access),
(To_Unbounded_String("option"), Parse_Option'Access),
(To_Unbounded_String("perfect_prefetch"), Parse_Perfect_Prefetch'Access),
(To_Unbounded_String("prefetch"), Parse_Prefetch'Access),
(To_Unbounded_String("ram"), Parse_RAM'Access),
(To_Unbounded_String("register"), Parse_Register'Access),
(To_Unbounded_String("shift"), Parse_Shift'Access),
(To_Unbounded_String("split"), Parse_Split'Access),
(To_Unbounded_String("spm"), Parse_SPM'Access),
(To_Unbounded_String("stats"), Parse_Stats'Access),
(To_Unbounded_String("super"), Parse_Super'Access),
(To_Unbounded_String("trace"), Parse_Trace'Access)
);
function Parse_Boolean(value : String) return Boolean is
begin
if value = "true" then
return True;
elsif value = "false" then
return False;
else
raise Data_Error;
end if;
end Parse_Boolean;
procedure Parse_Memory(parser : in out Parser_Type;
result : out Memory_Pointer) is
begin
Match(parser, Open);
declare
name : constant String := Get_Value(parser.lexer);
begin
Next(parser.lexer);
for i in parser_map'First .. parser_map'Last loop
if parser_map(i).name = name then
parser_map(i).parser(parser, result);
Match(parser, Close);
return;
end if;
end loop;
Raise_Error(parser, "invalid memory type: " & name);
end;
end Parse_Memory;
function Parse(file_name : String) return Memory_Pointer is
parser : Parser_Type;
result : Memory_Pointer;
begin
Open(parser.lexer, file_name);
Parse_Memory(parser, result);
Match(parser, EOF);
Close(parser.lexer);
return result;
exception
when Name_Error =>
return null;
when Parse_Error =>
return null;
end Parse;
procedure Raise_Error(parser : in Parser_Type;
msg : in String) is
name : constant String := Get_File_Name(parser.lexer);
line : constant String := Positive'Image(Get_Line(parser.lexer));
begin
Put_Line(name & "[" & line(2 .. line'Last) & "]: error: " & msg);
raise Parse_Error;
end Raise_Error;
function Get_Type(parser : Parser_Type) return Token_Type is
begin
return Get_Type(parser.lexer);
end Get_Type;
function Get_Value(parser : Parser_Type) return String is
begin
return Get_Value(parser.lexer);
end Get_Value;
procedure Match(parser : in out Parser_Type;
token : in Token_Type) is
begin
if Get_Type(parser) /= token then
Raise_Error(parser, "got '" & Get_Value(parser) &
"' expected '" & Token_Type'Image(token) & "'");
end if;
Next(parser.lexer);
end Match;
procedure Push_Wrapper(parser : in out Parser_Type;
wrapper : in Wrapper_Pointer;
count : in Positive := 1) is
last : constant Natural := Natural(count);
begin
parser.wrappers.Append(Wrapper_Node'(wrapper, 0, last));
end Push_Wrapper;
procedure Pop_Wrapper(parser : in out Parser_Type;
wrapper : out Wrapper_Pointer;
index : out Natural) is
begin
if parser.wrappers.Is_Empty then
Raise_Error(parser, "unexpected join");
end if;
declare
node : Wrapper_Node := parser.wrappers.Last_Element;
begin
wrapper := node.wrapper;
index := node.current;
node.current := node.current + 1;
if node.current = node.last then
Delete_Wrapper(parser);
else
parser.wrappers.Replace_Element(parser.wrappers.Last, node);
end if;
end;
end Pop_Wrapper;
procedure Delete_Wrapper(parser : in out Parser_Type) is
begin
parser.wrappers.Delete_Last;
end Delete_Wrapper;
end Parser;
|
reznikmm/matreshka | Ada | 5,295 | ads | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Ada Modeling Framework --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2011-2012, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
-- This file is generated, don't edit it.
------------------------------------------------------------------------------
with AMF.Generic_Collections;
package AMF.UML.Protocol_Conformances.Collections is
pragma Preelaborate;
package UML_Protocol_Conformance_Collections is
new AMF.Generic_Collections
(UML_Protocol_Conformance,
UML_Protocol_Conformance_Access);
type Set_Of_UML_Protocol_Conformance is
new UML_Protocol_Conformance_Collections.Set with null record;
Empty_Set_Of_UML_Protocol_Conformance : constant Set_Of_UML_Protocol_Conformance;
type Ordered_Set_Of_UML_Protocol_Conformance is
new UML_Protocol_Conformance_Collections.Ordered_Set with null record;
Empty_Ordered_Set_Of_UML_Protocol_Conformance : constant Ordered_Set_Of_UML_Protocol_Conformance;
type Bag_Of_UML_Protocol_Conformance is
new UML_Protocol_Conformance_Collections.Bag with null record;
Empty_Bag_Of_UML_Protocol_Conformance : constant Bag_Of_UML_Protocol_Conformance;
type Sequence_Of_UML_Protocol_Conformance is
new UML_Protocol_Conformance_Collections.Sequence with null record;
Empty_Sequence_Of_UML_Protocol_Conformance : constant Sequence_Of_UML_Protocol_Conformance;
private
Empty_Set_Of_UML_Protocol_Conformance : constant Set_Of_UML_Protocol_Conformance
:= (UML_Protocol_Conformance_Collections.Set with null record);
Empty_Ordered_Set_Of_UML_Protocol_Conformance : constant Ordered_Set_Of_UML_Protocol_Conformance
:= (UML_Protocol_Conformance_Collections.Ordered_Set with null record);
Empty_Bag_Of_UML_Protocol_Conformance : constant Bag_Of_UML_Protocol_Conformance
:= (UML_Protocol_Conformance_Collections.Bag with null record);
Empty_Sequence_Of_UML_Protocol_Conformance : constant Sequence_Of_UML_Protocol_Conformance
:= (UML_Protocol_Conformance_Collections.Sequence with null record);
end AMF.UML.Protocol_Conformances.Collections;
|
AdaCore/Ada_Drivers_Library | Ada | 7,642 | adb | ------------------------------------------------------------------------------
-- --
-- Copyright (C) 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. --
-- --
------------------------------------------------------------------------------
package body LSM303AGR is
function To_Axis_Data is new Ada.Unchecked_Conversion (UInt10, Axis_Data);
function Read_Register
(This : LSM303AGR_Accelerometer'Class; Device_Address : I2C_Address;
Register_Addr : Register_Address) return UInt8;
procedure Write_Register
(This : LSM303AGR_Accelerometer'Class; Device_Address : I2C_Address;
Register_Addr : Register_Address; Val : UInt8);
function Check_Device_Id
(This : LSM303AGR_Accelerometer; Device_Address : I2C_Address;
WHO_AM_I_Register : Register_Address; Device_Id : Device_Identifier)
return Boolean;
function To_Multi_Byte_Read_Address
(Register_Addr : Register_Address) return UInt16;
procedure Configure (This : LSM303AGR_Accelerometer; Date_Rate : Data_Rate)
is
CTRLA : CTRL_REG1_A_Register;
begin
CTRLA.Xen := 1;
CTRLA.Yen := 1;
CTRLA.Zen := 1;
CTRLA.LPen := 0;
CTRLA.ODR := Date_Rate'Enum_Rep;
This.Write_Register
(Accelerometer_Address, CTRL_REG1_A, To_UInt8 (CTRLA));
end Configure;
procedure Assert_Status (Status : I2C_Status);
-------------------
-- Read_Register --
-------------------
function Read_Register
(This : LSM303AGR_Accelerometer'Class; Device_Address : I2C_Address;
Register_Addr : Register_Address) return UInt8
is
Data : I2C_Data (1 .. 1);
Status : I2C_Status;
begin
This.Port.Mem_Read
(Addr => Device_Address, Mem_Addr => UInt16 (Register_Addr),
Mem_Addr_Size => Memory_Size_8b, Data => Data, Status => Status);
Assert_Status (Status);
return Data (Data'First);
end Read_Register;
--------------------
-- Write_Register --
--------------------
procedure Write_Register
(This : LSM303AGR_Accelerometer'Class; Device_Address : I2C_Address;
Register_Addr : Register_Address; Val : UInt8)
is
Status : I2C_Status;
begin
This.Port.Mem_Write
(Addr => Device_Address, Mem_Addr => UInt16 (Register_Addr),
Mem_Addr_Size => Memory_Size_8b, Data => (1 => Val),
Status => Status);
Assert_Status (Status);
end Write_Register;
-----------------------------------
-- Check_Accelerometer_Device_Id --
-----------------------------------
function Check_Accelerometer_Device_Id
(This : LSM303AGR_Accelerometer) return Boolean
is
begin
return
Check_Device_Id
(This, Accelerometer_Address, WHO_AM_I_A, Accelerometer_Device_Id);
end Check_Accelerometer_Device_Id;
----------------------------------
-- Check_Magnetometer_Device_Id --
----------------------------------
function Check_Magnetometer_Device_Id
(This : LSM303AGR_Accelerometer) return Boolean
is
begin
return
Check_Device_Id
(This, Magnetometer_Address, WHO_AM_I_M, Magnetometer_Device_Id);
end Check_Magnetometer_Device_Id;
---------------------
-- Check_Device_Id --
---------------------
function Check_Device_Id
(This : LSM303AGR_Accelerometer; Device_Address : I2C_Address;
WHO_AM_I_Register : Register_Address; Device_Id : Device_Identifier)
return Boolean
is
begin
return
Read_Register (This, Device_Address, WHO_AM_I_Register) =
UInt8 (Device_Id);
end Check_Device_Id;
------------------------
-- Read_Accelerometer --
------------------------
function Read_Accelerometer
(This : LSM303AGR_Accelerometer) return All_Axes_Data
is
-------------
-- Convert --
-------------
function Convert (Low, High : UInt8) return Axis_Data;
function Convert (Low, High : UInt8) return Axis_Data is
Tmp : UInt10;
begin
-- TODO: support HiRes and LoPow modes
-- in conversion.
Tmp := UInt10 (Shift_Right (Low, 6));
Tmp := Tmp or UInt10 (High) * 2**2;
return To_Axis_Data (Tmp);
end Convert;
Status : I2C_Status;
Data : I2C_Data (1 .. 6) := (others => 0);
AxisData : All_Axes_Data := (X => 0, Y => 0, Z => 0);
begin
This.Port.Mem_Read
(Addr => Accelerometer_Address,
Mem_Addr => To_Multi_Byte_Read_Address (OUT_X_L_A),
Mem_Addr_Size => Memory_Size_8b, Data => Data, Status => Status);
Assert_Status (Status);
-- LSM303AGR has its X-axis in the opposite direction
-- of the MMA8653FCR1 sensor.
AxisData.X := Convert (Data (1), Data (2)) * Axis_Data (-1);
AxisData.Y := Convert (Data (3), Data (4));
AxisData.Z := Convert (Data (5), Data (6));
return AxisData;
end Read_Accelerometer;
function To_Multi_Byte_Read_Address
(Register_Addr : Register_Address) return UInt16
-- Based on the i2c behavior of the sensor p.38,
-- high MSB address allows reading multiple bytes
-- from slave devices.
is
begin
return UInt16 (Register_Addr) or MULTI_BYTE_READ;
end To_Multi_Byte_Read_Address;
procedure Assert_Status (Status : I2C_Status) is
begin
if Status /= Ok then
-- No error handling...
raise Program_Error;
end if;
end Assert_Status;
end LSM303AGR;
|
afrl-rq/OpenUxAS | Ada | 2,838 | adb | with ZMQ.Sockets;
with Ada.Text_IO; use Ada.Text_IO;
with AVTAS.LMCP.Types; use AVTAS.LMCP.Types;
with UxAS.Comms.Transport.ZeroMQ_Socket_Configurations; use UxAS.Comms.Transport.ZeroMQ_Socket_Configurations;
with UxAS.Comms.Data.Addressed.Attributed; use UxAS.Comms.Data.Addressed.Attributed;
with UxAS.Comms.Transport.Receiver.ZeroMQ.Addr_Attr_Msg_Receivers ; use UxAS.Comms.Transport.Receiver.ZeroMQ.Addr_Attr_Msg_Receivers ;
with UxAS.Comms.Data; use UxAS.Comms.Data;
use UxAS.Comms.Transport.Receiver;
procedure Test_Attr_Addr_Recvr is
Receiver : ZeroMq_Addressed_Attributed_Message_Receiver;
Msg : Addressed_Attributed_Message_Ref;
Config : ZeroMq_Socket_Configuration;
Success : Boolean;
Max_Payload_Measured : Natural := 0;
begin
Config := Make
(Network_Name => "unspecified",
Socket_Address => "tcp://127.0.0.1:5560",
Is_Receive => True,
Zmq_Socket_Type => ZMQ.Sockets.SUB,
Number_of_IO_Threads => 1,
Is_Server_Bind => False,
Receive_High_Water_Mark => 10_000,
Send_High_Water_Mark => 10_000);
Receiver.Initialize
(Entity_Id => 0, -- don't use 100, that's the sender's
Service_Id => 0, -- don't use 60, that's the sender's
Socket_Configuration => Config);
Receiver.Add_Subscription_Address (Any_Address_Accepted, Success);
if not Success then
Put_Line ("Could not add subscription address to Receiver");
return;
end if;
loop
Receiver.Get_Next_Message (Msg); -- blocking
if Msg = null then
Put_Line ("Receiver got null msg pointer");
else
declare
Msg_Attr : Message_Attributes_View renames Message_Attributes_Reference (Msg.all);
begin
Put_Line ("Address : " & Msg.Address);
Put_Line ("Payload_Content_Type : " & Msg_Attr.Payload_Content_Type);
Put_Line ("Payload_Descriptor : " & Msg_Attr.Payload_Descriptor);
Put_Line ("Source_Group : " & Msg_Attr.Source_Group);
Put_Line ("Source_Entity_Id : " & Msg_Attr.Source_Entity_Id);
Put_Line ("Source_Service_Id : " & Msg_Attr.Source_Service_Id);
Put_Line ("Payload length :" & Msg.Payload'Length'Image);
if Msg.Payload'Length > Max_Payload_Measured then
Max_Payload_Measured := Msg.Payload'Length;
end if;
Put_Line ("Max_Payload_Measured :" & Max_Payload_Measured'Image);
New_Line;
end;
delay 0.5; -- just to give time to read it
end if;
end loop;
end Test_Attr_Addr_Recvr;
|
kaidenj3254/poker_learn | Ada | 272 | adb | adb 808200800 8 3 r b b - 1000 50 95
adb 808200835 10 2 Bk kf - - 1045 10 0
adb 808200891 8 1 Br b b - 1035 60 110
adb 808200942 9 8 Q - - - 1085 0 0
|
AdaCore/gpr | Ada | 61 | adb | package body Pkg2 is
procedure Sep is separate;
end Pkg2;
|
zhmu/ananas | Ada | 350 | ads | -- { dg-do compile }
with System;
package Size_Clause4 is
type Rec is record
A1 : System.Address;
A2 : System.Address;
I : aliased Integer;
end record;
for Rec use record
A1 at 0 range 0 .. 63;
A2 at 8 range 0 .. 63;
I at 16 range 0 .. 31;
end record;
for Rec'Size use 160;
end Size_Clause4;
|
reznikmm/matreshka | Ada | 4,583 | adb | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Open Document Toolkit --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2014, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
with Matreshka.DOM_Documents;
with Matreshka.ODF_String_Constants;
with ODF.DOM.Iterators;
with ODF.DOM.Visitors;
package body Matreshka.ODF_Draw.Copy_Of_Attributes is
------------
-- Create --
------------
overriding function Create
(Parameters : not null access Matreshka.DOM_Attributes.Attribute_L2_Parameters)
return Draw_Copy_Of_Attribute_Node is
begin
return Self : Draw_Copy_Of_Attribute_Node do
Matreshka.ODF_Draw.Constructors.Initialize
(Self'Unchecked_Access,
Parameters.Document,
Matreshka.ODF_String_Constants.Draw_Prefix);
end return;
end Create;
--------------------
-- Get_Local_Name --
--------------------
overriding function Get_Local_Name
(Self : not null access constant Draw_Copy_Of_Attribute_Node)
return League.Strings.Universal_String
is
pragma Unreferenced (Self);
begin
return Matreshka.ODF_String_Constants.Copy_Of_Attribute;
end Get_Local_Name;
begin
Matreshka.DOM_Documents.Register_Attribute
(Matreshka.ODF_String_Constants.Draw_URI,
Matreshka.ODF_String_Constants.Copy_Of_Attribute,
Draw_Copy_Of_Attribute_Node'Tag);
end Matreshka.ODF_Draw.Copy_Of_Attributes;
|
AdaCore/gpr | Ada | 223 | adb | with Ada.Text_IO; use Ada.Text_IO;
with Mylib;
procedure Main is
function Get_I return Integer
with Import, Convention => C, External_Name => "get_i";
begin
Mylib.I := 20;
Put_Line (Get_I'Image);
end Main;
|
sungyeon/drake | Ada | 351 | ads | pragma License (Unrestricted);
-- extended unit
with Interfaces.C.Pointers;
package Interfaces.C.Char_Pointers is
new Pointers (
Index => size_t,
Element => char,
Element_Array => char_array,
Default_Terminator => char'Val (0));
-- The instance of Interfaces.C.Pointers for char.
pragma Pure (Interfaces.C.Char_Pointers);
|
kontena/ruby-packer | Ada | 5,550 | adb | ------------------------------------------------------------------------------
-- --
-- GNAT ncurses Binding Samples --
-- --
-- ncurses --
-- --
-- B O D Y --
-- --
------------------------------------------------------------------------------
-- Copyright (c) 2000 Free Software Foundation, Inc. --
-- --
-- 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, distribute with modifications, 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 ABOVE 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. --
-- --
-- Except as contained in this notice, the name(s) of the above copyright --
-- holders shall not be used in advertising or otherwise to promote the --
-- sale, use or other dealings in this Software without prior written --
-- authorization. --
------------------------------------------------------------------------------
-- Author: Eugene V. Melaragno <[email protected]> 2000
-- Version Control
-- $Revision: 1.1 $
-- Binding Version 01.00
------------------------------------------------------------------------------
with Terminal_Interface.Curses; use Terminal_Interface.Curses;
with ncurses2.util; use ncurses2.util;
procedure ncurses2.flushinp_test (win : Window) is
procedure Continue (win : Window);
procedure Continue (win : Window) is
begin
Set_Echo_Mode (False);
Move_Cursor (win, 10, 1);
Add (win, 10, 1, " Press any key to continue");
Refresh (win);
Getchar (win);
end Continue;
h, by, sh : Line_Position;
w, bx, sw : Column_Position;
subWin : Window;
begin
Clear (win);
Get_Size (win, h, w);
Get_Window_Position (win, by, bx);
sw := w / 3;
sh := h / 3;
subWin := Sub_Window (win, sh, sw, by + h - sh - 2, bx + w - sw - 2);
if Has_Colors then
Init_Pair (2, Cyan, Blue);
Change_Background (subWin,
Attributed_Character'(Ch => ' ', Color => 2,
Attr => Normal_Video));
end if;
Set_Character_Attributes (subWin,
(Bold_Character => True, others => False));
Box (subWin);
Add (subWin, 2, 1, "This is a subwindow");
Refresh (win);
Set_Cbreak_Mode (True);
Add (win, 0, 1, "This is a test of the flushinp() call.");
Add (win, 2, 1, "Type random keys for 5 seconds.");
Add (win, 3, 1,
"These should be discarded (not echoed) after the subwindow " &
"goes away.");
Refresh (win);
for i in 0 .. 4 loop
Move_Cursor (subWin, 1, 1);
Add (subWin, Str => "Time = ");
Add (subWin, Str => Integer'Image (i));
Refresh (subWin);
Nap_Milli_Seconds (1000);
Flush_Input;
end loop;
Delete (subWin);
Erase (win);
Flash_Screen;
Refresh (win);
Nap_Milli_Seconds (1000);
Add (win, 2, 1,
Str => "If you were still typing when the window timer expired,");
Add (win, 3, 1,
"or else you typed nothing at all while it was running,");
Add (win, 4, 1,
"test was invalid. You'll see garbage or nothing at all. ");
Add (win, 6, 1, "Press a key");
Move_Cursor (win, 9, 10);
Refresh (win);
Set_Echo_Mode (True);
Getchar (win);
Flush_Input;
Add (win, 12, 0,
"If you see any key other than what you typed, flushinp() is broken.");
Continue (win);
Move_Cursor (win, 9, 10);
Delete_Character (win);
Refresh (win);
Move_Cursor (win, 12, 0);
Clear_To_End_Of_Line;
Add (win,
"What you typed should now have been deleted; if not, wdelch() " &
"failed.");
Continue (win);
Set_Cbreak_Mode (True);
end ncurses2.flushinp_test;
|
zhmu/ananas | Ada | 288 | adb | -- { dg-do compile }
package body C_Words is
function New_Word (Str : String) return Word is
begin
return (Str'Length, Str);
end New_Word;
function New_Word (Str : String) return C_Word is
begin
return (Str'Length, Str);
end New_Word;
end C_Words;
|
reznikmm/matreshka | Ada | 487 | ads | private with AMF.UML.Classes;
with AMF.Visitors.UML_Containment;
package Generators is
type Generator is
new AMF.Visitors.UML_Containment.UML_Containment_Visitor with private;
private
type Generator is
new AMF.Visitors.UML_Containment.UML_Containment_Visitor with record
In_Model : Boolean := False;
end record;
overriding procedure Enter_Class
(Self : in out Generator;
Element : not null AMF.UML.Classes.UML_Class_Access);
end Generators;
|
charlie5/cBound | Ada | 1,677 | ads | -- This file is generated by SWIG. Please do not modify by hand.
--
with Interfaces;
with swig;
with Interfaces.C;
with Interfaces.C.Pointers;
package xcb.xcb_configure_window_request_t is
-- Item
--
type Item is record
major_opcode : aliased Interfaces.Unsigned_8;
pad0 : aliased Interfaces.Unsigned_8;
length : aliased Interfaces.Unsigned_16;
window : aliased xcb.xcb_window_t;
value_mask : aliased Interfaces.Unsigned_16;
pad1 : aliased swig.int8_t_Array (0 .. 1);
end record;
-- Item_Array
--
type Item_Array is
array
(Interfaces.C
.size_t range <>) of aliased xcb.xcb_configure_window_request_t
.Item;
-- Pointer
--
package C_Pointers is new Interfaces.C.Pointers
(Index => Interfaces.C.size_t,
Element => xcb.xcb_configure_window_request_t.Item,
Element_Array => xcb.xcb_configure_window_request_t.Item_Array,
Default_Terminator => (others => <>));
subtype Pointer is C_Pointers.Pointer;
-- Pointer_Array
--
type Pointer_Array is
array
(Interfaces.C
.size_t range <>) of aliased xcb.xcb_configure_window_request_t
.Pointer;
-- Pointer_Pointer
--
package C_Pointer_Pointers is new Interfaces.C.Pointers
(Index => Interfaces.C.size_t,
Element => xcb.xcb_configure_window_request_t.Pointer,
Element_Array => xcb.xcb_configure_window_request_t.Pointer_Array,
Default_Terminator => null);
subtype Pointer_Pointer is C_Pointer_Pointers.Pointer;
end xcb.xcb_configure_window_request_t;
|
reznikmm/matreshka | Ada | 3,606 | ads | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Ada Modeling Framework --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2011-2012, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
-- This file is generated, don't edit it.
------------------------------------------------------------------------------
with AMF.Elements.Generic_Hash;
function AMF.UML.Stereotypes.Hash is
new AMF.Elements.Generic_Hash (UML_Stereotype, UML_Stereotype_Access);
|
caqg/linux-home | Ada | 2,224 | ads | -- Abstract :
--
-- External process parser for Ada mode
--
-- Copyright (C) 2017 - 2020, 2022 Free Software Foundation, Inc.
--
-- This program is free software; you can redistribute it and/or
-- modify it under terms of the GNU General Public License as
-- published by the Free Software Foundation; either version 3, or (at
-- your option) any later version. This program is distributed in the
-- hope that it will be useful, but WITHOUT ANY WARRANTY; without even
-- the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
-- PURPOSE. See the GNU General Public License for more details. You
-- should have received a copy of the GNU General Public License
-- distributed with this program; see file COPYING. If not, write to
-- the Free Software Foundation, 51 Franklin Street, Suite 500, Boston,
-- MA 02110-1335, USA.
pragma License (GPL);
with Ada_Annex_P_Process_Actions;
with Ada_Annex_P_Process_LR1_Main;
with Gen_Emacs_Wisi_LR_Text_Rep_Parse;
with WisiToken.Parse.LR.McKenzie_Recover.Ada;
with Wisi.Ada;
procedure Ada_Mode_Wisi_LR1_Parse is new Gen_Emacs_Wisi_LR_Text_Rep_Parse
(Parse_Data_Type => Wisi.Ada.Parse_Data_Type,
Name => "Ada_mode_wisi_lr1_parse",
Language_Protocol_Version => Wisi.Ada.Language_Protocol_Version,
Descriptor => Ada_Annex_P_Process_Actions.Descriptor'Access,
Partial_Parse_Active => Ada_Annex_P_Process_Actions.Partial_Parse_Active'Access,
Partial_Parse_Byte_Goal => Ada_Annex_P_Process_Actions.Partial_Parse_Byte_Goal'Access,
Language_Fixes => WisiToken.Parse.LR.McKenzie_Recover.Ada.Language_Fixes'Access,
Language_Matching_Begin_Tokens => WisiToken.Parse.LR.McKenzie_Recover.Ada.Matching_Begin_Tokens'Access,
Language_String_ID_Set => WisiToken.Parse.LR.McKenzie_Recover.Ada.String_ID_Set'Access,
Text_Rep_File_Name => "ada_annex_p_lr1_parse_table.txt",
Create_Lexer => Ada_Annex_P_Process_LR1_Main.Create_Lexer,
Create_Parse_Table => Ada_Annex_P_Process_LR1_Main.Create_Parse_Table,
Create_Productions => Ada_Annex_P_Process_LR1_Main.Create_Productions);
|
twdroeger/ada-awa | Ada | 5,730 | adb | -----------------------------------------------------------------------
-- awa-permissions-controllers -- Permission controllers
-- Copyright (C) 2011, 2012, 2013, 2014, 2016 Stephane Carrez
-- Written by Stephane Carrez ([email protected])
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-----------------------------------------------------------------------
with ADO.Sessions;
with ADO.Statements;
with Util.Log.Loggers;
with Util.Strings;
with AWA.Applications;
with AWA.Users.Principals;
with AWA.Permissions.Services;
with AWA.Services.Contexts;
package body AWA.Permissions.Controllers is
Log : constant Util.Log.Loggers.Logger
:= Util.Log.Loggers.Create ("AWA.Permissions.Controllers");
-- ------------------------------
-- Returns true if the user associated with the security context <b>Context</b> has
-- the permission to access a database entity. The security context contains some
-- information about the entity to check and the permission controller will use an
-- SQL statement to verify the permission.
-- ------------------------------
overriding
function Has_Permission (Handler : in Entity_Controller;
Context : in Security.Contexts.Security_Context'Class;
Permission : in Security.Permissions.Permission'Class)
return Boolean is
use AWA.Permissions.Services;
use AWA.Users.Principals;
use type ADO.Identifier;
use type ADO.Entity_Type;
Manager : constant Permission_Manager_Access := Get_Permission_Manager (Context);
User_Id : constant ADO.Identifier := Get_User_Identifier (Context.Get_User_Principal);
Entity_Id : ADO.Identifier;
begin
-- If there is no permission manager, permission is denied.
if Manager = null or else User_Id = ADO.NO_IDENTIFIER then
return False;
end if;
-- If the user is not logged, permission is denied.
if Manager = null or else User_Id = ADO.NO_IDENTIFIER then
Log.Info ("No user identifier in the security context. Permission is denied");
return False;
end if;
if not (Permission in Entity_Permission'Class) then
Log.Info ("Permission {0} denied because the entity is not given.",
Security.Permissions.Permission_Index'Image (Permission.Id));
return False;
end if;
Entity_Id := Entity_Permission'Class (Permission).Entity;
-- If the security context does not contain the entity identifier, permission is denied.
if Entity_Id = ADO.NO_IDENTIFIER then
Log.Info ("No entity identifier in the security context. Permission is denied");
return False;
end if;
declare
function Get_Session return ADO.Sessions.Session;
-- ------------------------------
-- Get a database session from the AWA application.
-- There is no guarantee that a AWA.Services.Contexts be available.
-- But if we are within a service context, we must use the current session so
-- that we are part of the current transaction.
-- ------------------------------
function Get_Session return ADO.Sessions.Session is
package ASC renames AWA.Services.Contexts;
use type ASC.Service_Context_Access;
Ctx : constant ASC.Service_Context_Access := ASC.Current;
begin
if Ctx /= null then
return AWA.Services.Contexts.Get_Session (Ctx);
else
return Manager.Get_Application.Get_Session;
end if;
end Get_Session;
Session : constant ADO.Sessions.Session := Get_Session;
Query : ADO.Statements.Query_Statement := Session.Create_Statement (Handler.SQL);
Result : Integer;
begin
-- Build the query
Query.Bind_Param (Name => "entity_id", Value => Entity_Id);
Query.Bind_Param (Name => "user_id", Value => User_Id);
if Handler.Entities (2) /= ADO.NO_ENTITY_TYPE then
for I in Handler.Entities'Range loop
exit when Handler.Entities (I) = ADO.NO_ENTITY_TYPE;
Query.Bind_Param (Name => "entity_type_" & Util.Strings.Image (I),
Value => Handler.Entities (I));
end loop;
else
Query.Bind_Param (Name => "entity_type", Value => Handler.Entities (1));
end if;
-- Run the query. We must get a single row result and the value must be > 0.
Query.Execute;
Result := Query.Get_Result_Integer;
if Result >= 0 and Query.Has_Elements then
Log.Info ("Permission granted to {0} on entity {1}",
ADO.Identifier'Image (User_Id),
ADO.Identifier'Image (Entity_Id));
return True;
else
Log.Info ("Permission denied to {0} on entity {1}",
ADO.Identifier'Image (User_Id),
ADO.Identifier'Image (Entity_Id));
return False;
end if;
end;
end Has_Permission;
end AWA.Permissions.Controllers;
|
optikos/oasis | Ada | 8,073 | ads | -- Copyright (c) 2019 Maxim Reznik <[email protected]>
--
-- SPDX-License-Identifier: MIT
-- License-Filename: LICENSE
-------------------------------------------------------------
with Program.Lexical_Elements;
with Program.Elements.Defining_Identifiers;
with Program.Elements.Expressions;
with Program.Elements.Formal_Package_Associations;
with Program.Elements.Aspect_Specifications;
with Program.Elements.Formal_Package_Declarations;
with Program.Element_Visitors;
package Program.Nodes.Formal_Package_Declarations is
pragma Preelaborate;
type Formal_Package_Declaration is
new Program.Nodes.Node
and Program.Elements.Formal_Package_Declarations
.Formal_Package_Declaration
and Program.Elements.Formal_Package_Declarations
.Formal_Package_Declaration_Text
with private;
function Create
(With_Token : not null Program.Lexical_Elements
.Lexical_Element_Access;
Package_Token : not null Program.Lexical_Elements
.Lexical_Element_Access;
Name : not null Program.Elements.Defining_Identifiers
.Defining_Identifier_Access;
Is_Token : not null Program.Lexical_Elements
.Lexical_Element_Access;
New_Token : not null Program.Lexical_Elements
.Lexical_Element_Access;
Generic_Package_Name : not null Program.Elements.Expressions
.Expression_Access;
Left_Bracket_Token : Program.Lexical_Elements.Lexical_Element_Access;
Parameters : Program.Elements.Formal_Package_Associations
.Formal_Package_Association_Vector_Access;
Right_Bracket_Token : Program.Lexical_Elements.Lexical_Element_Access;
With_Token_2 : Program.Lexical_Elements.Lexical_Element_Access;
Aspects : Program.Elements.Aspect_Specifications
.Aspect_Specification_Vector_Access;
Semicolon_Token : not null Program.Lexical_Elements
.Lexical_Element_Access)
return Formal_Package_Declaration;
type Implicit_Formal_Package_Declaration is
new Program.Nodes.Node
and Program.Elements.Formal_Package_Declarations
.Formal_Package_Declaration
with private;
function Create
(Name : not null Program.Elements.Defining_Identifiers
.Defining_Identifier_Access;
Generic_Package_Name : not null Program.Elements.Expressions
.Expression_Access;
Parameters : Program.Elements.Formal_Package_Associations
.Formal_Package_Association_Vector_Access;
Aspects : Program.Elements.Aspect_Specifications
.Aspect_Specification_Vector_Access;
Is_Part_Of_Implicit : Boolean := False;
Is_Part_Of_Inherited : Boolean := False;
Is_Part_Of_Instance : Boolean := False)
return Implicit_Formal_Package_Declaration
with Pre =>
Is_Part_Of_Implicit or Is_Part_Of_Inherited or Is_Part_Of_Instance;
private
type Base_Formal_Package_Declaration is
abstract new Program.Nodes.Node
and Program.Elements.Formal_Package_Declarations
.Formal_Package_Declaration
with record
Name : not null Program.Elements.Defining_Identifiers
.Defining_Identifier_Access;
Generic_Package_Name : not null Program.Elements.Expressions
.Expression_Access;
Parameters : Program.Elements.Formal_Package_Associations
.Formal_Package_Association_Vector_Access;
Aspects : Program.Elements.Aspect_Specifications
.Aspect_Specification_Vector_Access;
end record;
procedure Initialize
(Self : aliased in out Base_Formal_Package_Declaration'Class);
overriding procedure Visit
(Self : not null access Base_Formal_Package_Declaration;
Visitor : in out Program.Element_Visitors.Element_Visitor'Class);
overriding function Name
(Self : Base_Formal_Package_Declaration)
return not null Program.Elements.Defining_Identifiers
.Defining_Identifier_Access;
overriding function Generic_Package_Name
(Self : Base_Formal_Package_Declaration)
return not null Program.Elements.Expressions.Expression_Access;
overriding function Parameters
(Self : Base_Formal_Package_Declaration)
return Program.Elements.Formal_Package_Associations
.Formal_Package_Association_Vector_Access;
overriding function Aspects
(Self : Base_Formal_Package_Declaration)
return Program.Elements.Aspect_Specifications
.Aspect_Specification_Vector_Access;
overriding function Is_Formal_Package_Declaration_Element
(Self : Base_Formal_Package_Declaration)
return Boolean;
overriding function Is_Declaration_Element
(Self : Base_Formal_Package_Declaration)
return Boolean;
type Formal_Package_Declaration is
new Base_Formal_Package_Declaration
and Program.Elements.Formal_Package_Declarations
.Formal_Package_Declaration_Text
with record
With_Token : not null Program.Lexical_Elements
.Lexical_Element_Access;
Package_Token : not null Program.Lexical_Elements
.Lexical_Element_Access;
Is_Token : not null Program.Lexical_Elements
.Lexical_Element_Access;
New_Token : not null Program.Lexical_Elements
.Lexical_Element_Access;
Left_Bracket_Token : Program.Lexical_Elements.Lexical_Element_Access;
Right_Bracket_Token : Program.Lexical_Elements.Lexical_Element_Access;
With_Token_2 : Program.Lexical_Elements.Lexical_Element_Access;
Semicolon_Token : not null Program.Lexical_Elements
.Lexical_Element_Access;
end record;
overriding function To_Formal_Package_Declaration_Text
(Self : aliased in out Formal_Package_Declaration)
return Program.Elements.Formal_Package_Declarations
.Formal_Package_Declaration_Text_Access;
overriding function With_Token
(Self : Formal_Package_Declaration)
return not null Program.Lexical_Elements.Lexical_Element_Access;
overriding function Package_Token
(Self : Formal_Package_Declaration)
return not null Program.Lexical_Elements.Lexical_Element_Access;
overriding function Is_Token
(Self : Formal_Package_Declaration)
return not null Program.Lexical_Elements.Lexical_Element_Access;
overriding function New_Token
(Self : Formal_Package_Declaration)
return not null Program.Lexical_Elements.Lexical_Element_Access;
overriding function Left_Bracket_Token
(Self : Formal_Package_Declaration)
return Program.Lexical_Elements.Lexical_Element_Access;
overriding function Right_Bracket_Token
(Self : Formal_Package_Declaration)
return Program.Lexical_Elements.Lexical_Element_Access;
overriding function With_Token_2
(Self : Formal_Package_Declaration)
return Program.Lexical_Elements.Lexical_Element_Access;
overriding function Semicolon_Token
(Self : Formal_Package_Declaration)
return not null Program.Lexical_Elements.Lexical_Element_Access;
type Implicit_Formal_Package_Declaration is
new Base_Formal_Package_Declaration
with record
Is_Part_Of_Implicit : Boolean;
Is_Part_Of_Inherited : Boolean;
Is_Part_Of_Instance : Boolean;
end record;
overriding function To_Formal_Package_Declaration_Text
(Self : aliased in out Implicit_Formal_Package_Declaration)
return Program.Elements.Formal_Package_Declarations
.Formal_Package_Declaration_Text_Access;
overriding function Is_Part_Of_Implicit
(Self : Implicit_Formal_Package_Declaration)
return Boolean;
overriding function Is_Part_Of_Inherited
(Self : Implicit_Formal_Package_Declaration)
return Boolean;
overriding function Is_Part_Of_Instance
(Self : Implicit_Formal_Package_Declaration)
return Boolean;
end Program.Nodes.Formal_Package_Declarations;
|
persan/AUnit-addons | Ada | 3,127 | adb | with Ada.Strings.Fixed;
with AUnit.Test_Caller;
package body AUnit.Suite_Builders_Generic is
package Caller is new AUnit.Test_Caller (Fixture);
Package_Name : constant String := GNAT.Source_Info.Enclosing_Entity;
Separator : constant String := " : ";
--
-- The separator for suite and test names.
---------------------------
-- Compute_Suite_Prefix --
---------------------------
procedure Compute_Suite_Prefix
(This : in out Builder'Class)
is
Prefix : String := Package_Name;
Last_Dot : Natural := 0;
Test_Suffix : constant String := ".Tests";
Suffix_Index : Natural := 0;
begin
-- Trim off the name of this package.
--
Last_Dot := Ada.Strings.Fixed.Index
(Source => Prefix,
Pattern => ".",
Going => Ada.Strings.Backward);
if Last_Dot > 0 then
Ada.Strings.Fixed.Delete
(Source => Prefix,
From => Last_Dot,
Through => Prefix'Last);
end if;
-- Strip off a useless ".Test" suffix.
--
-- Note: Assumes the suffix doesn't also occur in the middle of the name.
--
Suffix_Index := Ada.Strings.Fixed.Index
(Source => Prefix,
Pattern => Test_Suffix,
Going => Ada.Strings.Backward);
if Suffix_Index > 0 then
Ada.Strings.Fixed.Delete
(Source => Prefix,
From => Suffix_Index,
Through => Prefix'Last);
end if;
This.M_Prefix := Ada.Strings.Unbounded.To_Unbounded_String
(Ada.Strings.Fixed.Trim (Prefix, Ada.Strings.Both) & Separator);
end Compute_Suite_Prefix;
function To_Suite
(This : in Builder)
return not null AUnit.Test_Suites.Access_Test_Suite
is
begin
return This.M_Suite;
end To_Suite;
procedure Set_Suite_Name
(This : in out Builder;
Name : in String)
is
begin
This.M_Prefix := Ada.Strings.Unbounded.To_Unbounded_String (Name & Separator);
end Set_Suite_Name;
----------------------------------------------------------------------------
procedure Add
(This : in out Builder;
Name : in String;
Test : access procedure (T : in out Fixture))
is
begin
This.M_Suite.Add_Test
(Caller.Create (Ada.Strings.Unbounded.To_String (This.M_Prefix) & Name, Test));
end Add;
----------------------------------------------------------------------------
procedure Add
(This : in out Builder;
Test : not null access AUnit.Test_Cases.Test_Case'Class)
is
begin
This.M_Suite.Add_Test (Test);
end Add;
----------------------------------------------------------------------------
procedure Add
(This : in out Builder;
Suite : not null access AUnit.Test_Suites.Test_Suite'Class)
is
begin
This.M_Suite.Add_Test (Suite);
end Add;
overriding
procedure Initialize
(This : in out Builder)
is
begin
This.M_Suite := AUnit.Test_Suites.New_Suite;
This.Compute_Suite_Prefix;
end Initialize;
end AUnit.Suite_Builders_Generic;
|
Rodeo-McCabe/orka | Ada | 9,829 | ads | -- SPDX-License-Identifier: Apache-2.0
--
-- Copyright (c) 2016 onox <[email protected]>
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
private with Ada.Containers.Indefinite_Holders;
with GL.Buffers;
with GL.Objects.Framebuffers;
with GL.Objects.Textures;
with GL.Types.Colors;
with Orka.Contexts;
with Orka.Rendering.Buffers;
with Orka.Rendering.Textures;
with Orka.Windows;
package Orka.Rendering.Framebuffers is
pragma Preelaborate;
use GL.Types;
package FB renames GL.Objects.Framebuffers;
package Textures renames GL.Objects.Textures;
subtype Color_Attachment_Point is FB.Attachment_Point
range FB.Color_Attachment_0 .. FB.Color_Attachment_15;
type Use_Point_Array is array (Rendering.Framebuffers.Color_Attachment_Point) of Boolean;
-- TODO Use as formal parameter in procedure Invalidate
type Buffer_Values is record
Color : Colors.Color := (0.0, 0.0, 0.0, 0.0);
Depth : GL.Buffers.Depth := 1.0;
Stencil : GL.Buffers.Stencil_Index := 0;
end record;
type Framebuffer (Default : Boolean) is tagged private
with Type_Invariant => (if Framebuffer.Default then Framebuffer.Samples = 0);
function Create_Framebuffer
(Width, Height, Samples : Size;
Context : Contexts.Context'Class) return Framebuffer
with Pre => (if Samples > 0 then Context.Enabled (Contexts.Multisample)),
Post => not Create_Framebuffer'Result.Default;
function Create_Framebuffer (Width, Height : Size) return Framebuffer
with Post => not Create_Framebuffer'Result.Default;
-----------------------------------------------------------------------------
function Get_Default_Framebuffer
(Window : Orka.Windows.Window'Class) return Framebuffer
with Post => Get_Default_Framebuffer'Result.Default;
function Create_Default_Framebuffer
(Width, Height : Size) return Framebuffer
with Post => Create_Default_Framebuffer'Result.Default;
-----------------------------------------------------------------------------
function Width (Object : Framebuffer) return Size;
function Height (Object : Framebuffer) return Size;
function Samples (Object : Framebuffer) return Size;
function Image (Object : Framebuffer) return String;
-- Return a description of the given framebuffer
procedure Use_Framebuffer (Object : Framebuffer);
-- Use the framebuffer during rendering
--
-- The viewport is adjusted to the size of the framebuffer.
procedure Set_Default_Values (Object : in out Framebuffer; Values : Buffer_Values);
-- Set the default values for the color buffers and depth and stencil
-- buffers
function Default_Values (Object : Framebuffer) return Buffer_Values;
-- Return the current default values used when clearing the attached
-- textures
procedure Set_Read_Buffer
(Object : Framebuffer;
Buffer : GL.Buffers.Color_Buffer_Selector);
-- Set the buffer to use when blitting to another framebuffer with
-- procedure Resolve_To
procedure Set_Draw_Buffers
(Object : in out Framebuffer;
Buffers : GL.Buffers.Color_Buffer_List);
-- Set the buffers to use when drawing to output variables in a fragment
-- shader, when calling procedure Clear, or when another framebuffer
-- blits its read buffer to this framebuffer with procedure Resolve_To
procedure Clear
(Object : Framebuffer;
Mask : GL.Buffers.Buffer_Bits := (others => True));
-- Clear the attached textures for which the mask is True using
-- the default values set with Set_Default_Values
--
-- For clearing to be effective, the following conditions must apply:
--
-- - Write mask off
-- - Rasterizer discard disabled
-- - Scissor test off or scissor rectangle set to the desired region
-- - Called procedure Set_Draw_Buffers with a list of attachments
--
-- If a combined depth/stencil texture has been attached, the depth
-- and stencil components can be cleared separately, but it may be
-- faster to clear both components.
procedure Invalidate
(Object : Framebuffer;
Mask : GL.Buffers.Buffer_Bits);
-- Invalidate the attached textures for which the mask is True
procedure Resolve_To
(Object, Subject : Framebuffer;
Mask : GL.Buffers.Buffer_Bits := (Color => True, others => False))
with Pre => Object /= Subject and
(Mask.Color or Mask.Depth or Mask.Stencil) and
(if Object.Samples > 0 and Subject.Samples > 0 then
Object.Samples = Subject.Samples);
-- Copy one or more buffers, resolving multiple samples and scaling
-- if necessary, from the source to the destination framebuffer
--
-- If a buffer is specified in the mask, then the buffer should exist
-- in both framebuffers, otherwise the buffer is not copied. Call
-- Set_Read_Buffer and Set_Draw_Buffers to control which buffer is read
-- from and which buffers are written to.
--
-- Format of color buffers may differ and will be converted (if
-- supported). Formats of depth and stencil buffers must match.
--
-- Note: simultaneously resolving multiple samples and scaling
-- requires GL_EXT_framebuffer_multisample_blit_scaled.
procedure Attach
(Object : in out Framebuffer;
Attachment : FB.Attachment_Point;
Texture : Textures.Texture;
Level : Textures.Mipmap_Level := 0)
with Pre => (not Object.Default and Texture.Allocated and
(if Attachment in Color_Attachment_Point then
(Object.Width = Texture.Width (Level) and
Object.Height = Texture.Height (Level))))
or else raise Constraint_Error with
"Cannot attach " & Rendering.Textures.Image (Texture, Level) &
" to " & Object.Image,
Post => Object.Has_Attachment (Attachment);
-- Attach the texture to the attachment point
--
-- The internal format of the texture must be valid for the given
-- attachment point.
--
-- If one of the attached textures is layered (3D, 1D/2D array, cube
-- map [array], or 2D multisampled array), then all attachments must
-- have the same kind.
--
-- All attachments of the framebuffer must have the same amount of
-- samples and they must all have fixed sample locations, or none of
-- them must have them.
procedure Attach
(Object : in out Framebuffer;
Texture : Textures.Texture;
Level : Textures.Mipmap_Level := 0);
-- Attach the texture to an attachment point based on the internal
-- format of the texture
--
-- Internally calls the procedure Attach above.
--
-- If the texture is color renderable, it will always be attached to
-- Color_Attachment_0. If you need to attach a texture to a different
-- color attachment point then use the other procedure Attach directly.
--
-- If the texture is layered and you want to attach a specific layer,
-- then you must call the procedure Attach_Layer below instead.
procedure Attach_Layer
(Object : in out Framebuffer;
Attachment : FB.Attachment_Point;
Texture : Textures.Texture;
Layer : Natural;
Level : Textures.Mipmap_Level := 0)
with Pre => (not Object.Default and Texture.Allocated and
Texture.Layered and
(if Attachment in Color_Attachment_Point then
(Object.Width = Texture.Width (Level) and
Object.Height = Texture.Height (Level))))
or else raise Constraint_Error with
"Cannot attach layer of " & Rendering.Textures.Image (Texture, Level) &
" to " & Object.Image,
Post => Object.Has_Attachment (Attachment);
-- Attach the selected 1D/2D layer of the texture to the attachment point
--
-- The internal format of the texture must be valid for the given
-- attachment point.
--
-- The texture must be layered (3D, 1D/2D array, cube
-- map [array], or 2D multisampled array).
procedure Detach
(Object : in out Framebuffer;
Attachment : FB.Attachment_Point)
with Pre => not Object.Default,
Post => not Object.Has_Attachment (Attachment);
-- Detach any texture currently attached to the given attachment point
function Has_Attachment
(Object : Framebuffer;
Attachment : FB.Attachment_Point) return Boolean;
Framebuffer_Incomplete_Error : exception;
private
package Attachment_Holder is new Ada.Containers.Indefinite_Holders
(Element_Type => Textures.Texture, "=" => Textures."=");
package Color_Buffer_List_Holder is new Ada.Containers.Indefinite_Holders
(Element_Type => GL.Buffers.Color_Buffer_List, "=" => GL.Buffers."=");
type Attachment_Array is array (FB.Attachment_Point)
of Attachment_Holder.Holder;
type Framebuffer (Default : Boolean) is tagged record
GL_Framebuffer : FB.Framebuffer;
Attachments : Attachment_Array;
Defaults : Buffer_Values;
Draw_Buffers : Color_Buffer_List_Holder.Holder;
Width, Height, Samples : Size;
end record;
end Orka.Rendering.Framebuffers;
|
reznikmm/matreshka | Ada | 3,714 | ads | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Open Document Toolkit --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2014, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
with XML.DOM.Attributes;
package ODF.DOM.Fo_Break_Before_Attributes is
pragma Preelaborate;
type ODF_Fo_Break_Before_Attribute is limited interface
and XML.DOM.Attributes.DOM_Attribute;
type ODF_Fo_Break_Before_Attribute_Access is
access all ODF_Fo_Break_Before_Attribute'Class
with Storage_Size => 0;
end ODF.DOM.Fo_Break_Before_Attributes;
|
AdaCore/libadalang | Ada | 61 | ads | with P1;
package P2 is
I : Integer renames P1.I;
end P2;
|
sungyeon/drake | Ada | 13,302 | adb | pragma Check_Policy (Trace => Ignore);
with System.Shared_Locking;
package body Ada.Containers.Copy_On_Write is
procedure Follow (
Target : not null Container_Access;
Data : not null Data_Access);
procedure Follow (
Target : not null Container_Access;
Data : not null Data_Access) is
begin
pragma Check (Trace, Debug.Put ("enter"));
Target.Data := Data;
if Data.Follower = null then
pragma Assert (Target.Next_Follower = null);
Data.Follower := Target;
else
-- keep first follower
Target.Next_Follower := Data.Follower.Next_Follower;
Data.Follower.Next_Follower := Target;
end if;
pragma Check (Trace, Debug.Put ("leave"));
end Follow;
procedure Unfollow (
Target : not null Container_Access;
To_Free : out Data_Access);
procedure Unfollow (
Target : not null Container_Access;
To_Free : out Data_Access)
is
Data : constant Data_Access := Target.Data;
begin
pragma Check (Trace, Debug.Put ("enter"));
To_Free := null;
if Data.Follower = Target then
Data.Follower := Target.Next_Follower;
if Data.Follower = null then
To_Free := Data;
end if;
else
declare
I : access Container := Data.Follower;
begin
while I.Next_Follower /= Target loop
I := I.Next_Follower;
end loop;
I.Next_Follower := Target.Next_Follower;
end;
end if;
Target.Next_Follower := null;
Target.Data := null;
pragma Check (Trace, Debug.Put ("leave"));
end Unfollow;
Constant_Zero : aliased constant Count_Type := 0;
-- implementation
function Shared (Data : Data_Access) return Boolean is
Result : Boolean;
begin
if Data = null then
Result := True; -- null as sentinel
else
pragma Assert (Data.Follower /= null);
Result := Data.Follower.Next_Follower /= null;
end if;
return Result;
end Shared;
procedure Adjust (
Target : not null access Container)
is
Data : constant Data_Access := Target.Data;
begin
if Data /= null then
System.Shared_Locking.Enter;
Follow (Target, Data);
System.Shared_Locking.Leave;
end if;
end Adjust;
procedure Assign (
Target : not null access Container;
Source : not null access constant Container;
Free : not null access procedure (Object : in out Data_Access)) is
begin
if Target.Data /= Source.Data then
Clear (Target, Free);
if Source.Data = null then
pragma Assert (Target.Data = null);
pragma Assert (Target.Next_Follower = null);
null;
else
System.Shared_Locking.Enter;
Follow (Target, Source.Data);
System.Shared_Locking.Leave;
end if;
end if;
end Assign;
procedure Clear (
Target : not null access Container;
Free : not null access procedure (Object : in out Data_Access))
is
Data : Data_Access := Target.Data;
begin
if Data /= null then
declare
To_Free : Data_Access;
begin
System.Shared_Locking.Enter;
Unfollow (Target, To_Free);
System.Shared_Locking.Leave;
if To_Free /= null then
Free (Data);
end if;
end;
end if;
end Clear;
procedure Copy (
Target : not null access Container;
Source : not null access constant Container;
Allocate : not null access procedure (
Target : out not null Data_Access;
New_Length : Count_Type;
Capacity : Count_Type);
Copy : not null access procedure (
Target : out not null Data_Access;
Source : not null Data_Access;
Length : Count_Type;
New_Length : Count_Type;
Capacity : Count_Type)) is
begin
Copy_On_Write.Copy (Target, Source, 0, 0,
Allocate => Allocate, Copy => Copy);
end Copy;
procedure Copy (
Target : not null access Container;
Source : not null access constant Container;
Length : Count_Type;
New_Capacity : Count_Type;
Allocate : not null access procedure (
Target : out not null Data_Access;
New_Length : Count_Type;
Capacity : Count_Type);
Copy : not null access procedure (
Target : out not null Data_Access;
Source : not null Data_Access;
Length : Count_Type;
New_Length : Count_Type;
Capacity : Count_Type)) is
begin
pragma Assert (Target.all = (null, null));
if Source.Data /= null then
declare
New_Data : Data_Access;
begin
Copy (New_Data, Source.Data, Length, Length, New_Capacity);
Follow (Target, New_Data); -- no sync
end;
elsif New_Capacity > 0 then
declare
New_Data : Data_Access;
begin
Allocate (New_Data, Length, New_Capacity);
Follow (Target, New_Data); -- no sync
end;
end if;
end Copy;
procedure Move (
Target : not null access Container;
Source : not null access Container;
Free : not null access procedure (Object : in out Data_Access)) is
begin
if Target /= Source then
if Source.Data = null then
Clear (Target, Free);
else
if Target.Data /= Source.Data then
Clear (Target, Free);
System.Shared_Locking.Enter;
Follow (Target, Source.Data);
System.Shared_Locking.Leave;
end if;
declare
Dummy : Data_Access;
begin
System.Shared_Locking.Enter;
Unfollow (Source, Dummy);
System.Shared_Locking.Leave;
pragma Assert (Dummy = null);
end;
end if;
end if;
end Move;
procedure Unique (
Target : not null access Container;
To_Update : Boolean;
Allocate : not null access procedure (
Target : out not null Data_Access;
New_Length : Count_Type;
Capacity : Count_Type);
Move : not null access procedure (
Target : out not null Data_Access;
Source : not null Data_Access;
Length : Count_Type;
New_Length : Count_Type;
Capacity : Count_Type);
Copy : not null access procedure (
Target : out not null Data_Access;
Source : not null Data_Access;
Length : Count_Type;
New_Length : Count_Type;
Capacity : Count_Type);
Free : not null access procedure (Object : in out Data_Access)) is
begin
Unique (Target, 0, 0, 0, 0, To_Update,
Allocate => Allocate,
Move => Move,
Copy => Copy,
Free => Free,
Max_Length => Zero'Access);
end Unique;
procedure Unique (
Target : not null access Container;
Target_Length : Count_Type;
Target_Capacity : Count_Type;
New_Length : Count_Type;
New_Capacity : Count_Type;
To_Update : Boolean;
Allocate : not null access procedure (
Target : out not null Data_Access;
New_Length : Count_Type;
Capacity : Count_Type);
Move : not null access procedure (
Target : out not null Data_Access;
Source : not null Data_Access;
Length : Count_Type;
New_Length : Count_Type;
Capacity : Count_Type);
Copy : not null access procedure (
Target : out not null Data_Access;
Source : not null Data_Access;
Length : Count_Type;
New_Length : Count_Type;
Capacity : Count_Type);
Free : not null access procedure (Object : in out Data_Access);
Max_Length : not null access function (Data : not null Data_Access)
return not null access Count_Type) is
begin
if Target.Data /= null then
if Target.Data.Follower = Target
and then New_Capacity = Target_Capacity
then
if To_Update
and then Target.Next_Follower /= null -- shared
then
declare -- target(owner) can access its Max_Length
Max_Length : constant Count_Type :=
Unique.Max_Length (Target.Data).all;
New_Data : Data_Access;
To_Free : Data_Access := null;
begin
Copy (
New_Data,
Target.Data,
Max_Length,
Max_Length,
Target_Capacity); -- not shrinking
-- target uses old data, other followers use new data
System.Shared_Locking.Enter;
if Target.Next_Follower = null then
-- all other containers unfollowed it by another task
To_Free := New_Data;
else
-- reattach next-followers to new copied data
New_Data.Follower := Target.Next_Follower;
declare
I : access Container := Target.Next_Follower;
begin
while I /= null loop
I.Data := New_Data;
I := I.Next_Follower;
end loop;
end;
end if;
Target.Next_Follower := null;
System.Shared_Locking.Leave;
if To_Free /= null then
Free (To_Free);
end if;
end;
end if;
else
-- reallocation
declare
To_Copy : constant Boolean :=
Target.Data.Follower.Next_Follower /= null; -- shared
-- should this reading be locked or not?
New_Data : Data_Access;
To_Free : Data_Access;
begin
if To_Copy then
Copy (
New_Data,
Target.Data,
Target_Length,
New_Length,
New_Capacity);
else
Move (
New_Data,
Target.Data,
Target_Length,
New_Length,
New_Capacity);
end if;
System.Shared_Locking.Enter;
Unfollow (Target, To_Free);
Follow (Target, New_Data);
System.Shared_Locking.Leave;
pragma Assert (To_Copy or else To_Free /= null);
if To_Free /= null then
-- all containers unfollowed it by another task, or move
Free (To_Free);
end if;
end;
end if;
else
declare
New_Data : Data_Access;
begin
Allocate (New_Data, New_Length, New_Capacity);
Follow (Target, New_Data); -- no sync
end;
end if;
end Unique;
procedure In_Place_Set_Length (
Target : not null access Container;
Target_Length : Count_Type;
Target_Capacity : Count_Type;
New_Length : Count_Type;
Failure : out Boolean;
Max_Length : not null access function (Data : not null Data_Access)
return not null access Count_Type) is
begin
if New_Length > Target_Length then
-- inscreasing
if New_Length > Target_Capacity then
-- expanding
Failure := True; -- should be reallocated
else
-- try to use reserved area
pragma Assert (Target.Data /= null); -- Target_Capacity > 0
if Target.Data.Follower.Next_Follower = null then -- not shared
Max_Length (Target.Data).all := New_Length;
Failure := False; -- success
elsif Target.Data.Follower = Target then
declare -- the owner only can access its Max_Length
Max_Length : constant not null access Count_Type :=
In_Place_Set_Length.Max_Length (Target.Data);
begin
if Max_Length.all = Target_Length then
Max_Length.all := New_Length;
Failure := False; -- success
else
Failure := True; -- should be copied
end if;
end;
else
Failure := True; -- should be copied
end if;
end if;
else
-- decreasing
if not Shared (Target.Data) then
Max_Length (Target.Data).all := New_Length;
end if;
Failure := False; -- success
end if;
end In_Place_Set_Length;
function Zero (Data : not null Data_Access)
return not null access Count_Type
is
pragma Unreferenced (Data);
begin
return Constant_Zero'Unrestricted_Access;
end Zero;
end Ada.Containers.Copy_On_Write;
|
zhmu/ananas | Ada | 10,253 | ads | ------------------------------------------------------------------------------
-- --
-- GNAT RUN-TIME COMPONENTS --
-- --
-- G N A T . D E C O D E _ S T R I N G --
-- --
-- S p e c --
-- --
-- Copyright (C) 2007-2022, 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. --
-- --
------------------------------------------------------------------------------
-- This generic package provides utility routines for converting from an
-- encoded string to a corresponding Wide_String or Wide_Wide_String value
-- using a specified encoding convention, which is supplied as the generic
-- parameter. UTF-8 is handled especially efficiently, and if the encoding
-- method is known at compile time to be WCEM_UTF8, then the instantiation
-- is specialized to handle only the UTF-8 case and exclude code for the
-- other encoding methods. The package also provides positioning routines
-- for skipping encoded characters in either direction, and for validating
-- strings for correct encodings.
-- Note: this package is only about decoding sequences of 8-bit characters
-- into corresponding 16-bit Wide_String or 32-bit Wide_Wide_String values.
-- It knows nothing at all about the character encodings being used for the
-- resulting Wide_Character and Wide_Wide_Character values. Most often this
-- will be Unicode/ISO-10646 as specified by the Ada RM, but this package
-- does not make any assumptions about the character coding. See also the
-- packages Ada.Wide_[Wide_]Characters.Unicode for unicode specific functions.
-- In particular, in the case of UTF-8, all valid UTF-8 encodings, as listed
-- in table 3.6 of the Unicode Standard, version 6.2.0, are recognized as
-- legitimate. This includes the full range 16#0000_0000# .. 16#03FF_FFFF#.
-- This includes codes in the range 16#D800# - 16#DFFF#. These codes all
-- have UTF-8 encoding sequences that are well-defined (e.g. the encoding for
-- 16#D800# is ED A0 80). But these codes do not correspond to defined Unicode
-- characters and are thus considered to be "not well-formed" (see table 3.7
-- of the Unicode Standard). If you need to exclude these codes, you must do
-- that manually, e.g. use Decode_Wide_Character/Decode_Wide_String and check
-- that the resulting code(s) are not in this range.
-- Note on the use of brackets encoding (WCEM_Brackets). The brackets encoding
-- method is ambiguous in the context of this package, since there is no way
-- to tell if ["1234"] is eight unencoded characters or one encoded character.
-- In the context of Ada sources, any sequence starting [" must be the start
-- of an encoding (since that sequence is not valid in Ada source otherwise).
-- The routines in this package use the same approach. If the input string
-- contains the sequence [" then this is assumed to be the start of a brackets
-- encoding sequence, and if it does not match the syntax, an error is raised.
-- In the case of the Prev functions, a sequence ending with "] is assumed to
-- be a valid brackets sequence, and an error is raised if it is not.
with System.WCh_Con;
generic
Encoding_Method : System.WCh_Con.WC_Encoding_Method;
package GNAT.Decode_String is
pragma Pure;
function Decode_Wide_String (S : String) return Wide_String;
pragma Inline (Decode_Wide_String);
-- Decode the given String, which is encoded using the indicated coding
-- method, returning the corresponding decoded Wide_String value. If S
-- contains a character code that cannot be represented with the given
-- encoding, then Constraint_Error is raised.
procedure Decode_Wide_String
(S : String;
Result : out Wide_String;
Length : out Natural);
-- Similar to the above function except that the result is stored in the
-- given Wide_String variable Result, starting at Result (Result'First). On
-- return, Length is set to the number of characters stored in Result. The
-- caller must ensure that Result is long enough (an easy choice is to set
-- the length equal to the S'Length, since decoding can never increase the
-- string length). If the length of Result is insufficient Constraint_Error
-- will be raised.
function Decode_Wide_Wide_String (S : String) return Wide_Wide_String;
-- Same as above function but for Wide_Wide_String output
procedure Decode_Wide_Wide_String
(S : String;
Result : out Wide_Wide_String;
Length : out Natural);
-- Same as above procedure, but for Wide_Wide_String output
function Validate_Wide_String (S : String) return Boolean;
-- This function inspects the string S to determine if it contains only
-- valid encodings corresponding to Wide_Character values using the
-- given encoding. If a call to Decode_Wide_String (S) would return
-- without raising Constraint_Error, then Validate_Wide_String will
-- return True. If the call would have raised Constraint_Error, then
-- Validate_Wide_String will return False.
function Validate_Wide_Wide_String (S : String) return Boolean;
-- Similar to Validate_Wide_String, except that it succeeds if the string
-- contains only encodings corresponding to Wide_Wide_Character values.
procedure Decode_Wide_Character
(Input : String;
Ptr : in out Natural;
Result : out Wide_Character);
pragma Inline (Decode_Wide_Character);
-- This is a lower level procedure that decodes a single character using
-- the given encoding method. The encoded character is stored in Input,
-- starting at Input (Ptr). The resulting output character is stored in
-- Result, and on return Ptr is updated past the input character or
-- encoding sequence. Constraint_Error will be raised if the input has
-- has a character that cannot be represented using the given encoding,
-- or if Ptr is outside the bounds of the Input string.
procedure Decode_Wide_Wide_Character
(Input : String;
Ptr : in out Natural;
Result : out Wide_Wide_Character);
pragma Inline (Decode_Wide_Wide_Character);
-- Same as above procedure but with Wide_Wide_Character input
procedure Next_Wide_Character (Input : String; Ptr : in out Natural);
pragma Inline (Next_Wide_Character);
-- This procedure examines the input string starting at Input (Ptr), and
-- advances Ptr past one character in the encoded string, so that on return
-- Ptr points to the next encoded character. Constraint_Error is raised if
-- an invalid encoding is encountered, or the end of the string is reached
-- or if Ptr is less than String'First on entry, or if the character
-- skipped is not a valid Wide_Character code.
procedure Prev_Wide_Character (Input : String; Ptr : in out Natural);
-- This procedure is similar to Next_Encoded_Character except that it moves
-- backwards in the string, so that on return, Ptr is set to point to the
-- previous encoded character. Constraint_Error is raised if the start of
-- the string is encountered. It is valid for Ptr to be one past the end
-- of the string for this call (in which case on return it will point to
-- the last encoded character).
--
-- Note: it is not generally possible to do this function efficiently with
-- all encodings, the current implementation is only efficient for the case
-- of UTF-8 (Encoding_Method = WCEM_UTF8) and Brackets (Encoding_Method =
-- WCEM_Brackets). For all other encodings, we work by starting at the
-- beginning of the string and moving forward till Ptr is reached, which
-- is correct but slow.
--
-- Note: this routine assumes that the sequence prior to Ptr is correctly
-- encoded, it does not have a defined behavior if this is not the case.
procedure Next_Wide_Wide_Character (Input : String; Ptr : in out Natural);
pragma Inline (Next_Wide_Wide_Character);
-- Similar to Next_Wide_Character except that codes skipped must be valid
-- Wide_Wide_Character codes.
procedure Prev_Wide_Wide_Character (Input : String; Ptr : in out Natural);
-- Similar to Prev_Wide_Character except that codes skipped must be valid
-- Wide_Wide_Character codes.
end GNAT.Decode_String;
|
ekoeppen/MSP430_Generic_Ada_Drivers | Ada | 1,221 | adb | with System;
with Startup;
with MSP430_SVD; use MSP430_SVD;
with MSP430_SVD.SYSTEM_CLOCK; use MSP430_SVD.SYSTEM_CLOCK;
package body MSPGD.Board is
CALDCO_1MHz : DCOCTL_Register with Import, Address => System'To_Address (16#10FE#);
CALBC1_1MHz : BCSCTL1_Register with Import, Address => System'To_Address (16#10FF#);
CALDCO_8MHz : DCOCTL_Register with Import, Address => System'To_Address (16#10FC#);
CALBC1_8MHz : BCSCTL1_Register with Import, Address => System'To_Address (16#10FD#);
CALDCO_12MHz : DCOCTL_Register with Import, Address => System'To_Address (16#10FA#);
CALBC1_12MHz : BCSCTL1_Register with Import, Address => System'To_Address (16#10FB#);
CALDCO_16MHz : DCOCTL_Register with Import, Address => System'To_Address (16#10F8#);
CALBC1_16MHz : BCSCTL1_Register with Import, Address => System'To_Address (16#10F9#);
procedure Init is
begin
SYSTEM_CLOCK_Periph.DCOCTL.MOD_k.Val := 0;
SYSTEM_CLOCK_Periph.DCOCTL.DCO.Val := 0;
SYSTEM_CLOCK_Periph.BCSCTL1 := CALBC1_8MHz;
SYSTEM_CLOCK_Periph.DCOCTL := CALDCO_8MHz;
LED_RED.Init;
LED_GREEN.Init;
RX.Init;
TX.Init;
BUTTON.Init;
UART.Init;
end Init;
end MSPGD.Board;
|
io7m/coreland-vector-ada | Ada | 1,222 | adb | package body vector.absolute is
-- C imports
procedure vec_absolute_f
(a : in out vector_f_t;
n : ic.int);
pragma import (c, vec_absolute_f, "vec_absNf_aligned");
procedure vec_absolute_fx
(a : vector_f_t;
x : out vector_f_t;
n : ic.int);
pragma import (c, vec_absolute_fx, "vec_absNfx_aligned");
procedure vec_absolute_d
(a : in out vector_d_t;
n : ic.int);
pragma import (c, vec_absolute_d, "vec_absNd_aligned");
procedure vec_absolute_dx
(a : vector_d_t;
x : out vector_d_t;
n : ic.int);
pragma import (c, vec_absolute_dx, "vec_absNdx_aligned");
-- absolute, in place
procedure f (a : in out vector_f_t) is
begin
vec_absolute_f (a, ic.int (size));
end f;
pragma inline (f);
procedure d (a : in out vector_d_t) is
begin
vec_absolute_d (a, ic.int (size));
end d;
pragma inline (d);
-- absolute, external storage
procedure f_ext (a : vector_f_t; x : out vector_f_t) is
begin
vec_absolute_fx (a, x, ic.int (size));
end f_ext;
pragma inline (f_ext);
procedure d_ext (a : vector_d_t; x : out vector_d_t) is
begin
vec_absolute_dx (a, x, ic.int (size));
end d_ext;
pragma inline (d_ext);
end vector.absolute;
|
reznikmm/matreshka | Ada | 3,979 | ads | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Open Document Toolkit --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2014, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
with ODF.DOM.Table_Status_Attributes;
package Matreshka.ODF_Table.Status_Attributes is
type Table_Status_Attribute_Node is
new Matreshka.ODF_Table.Abstract_Table_Attribute_Node
and ODF.DOM.Table_Status_Attributes.ODF_Table_Status_Attribute
with null record;
overriding function Create
(Parameters : not null access Matreshka.DOM_Attributes.Attribute_L2_Parameters)
return Table_Status_Attribute_Node;
overriding function Get_Local_Name
(Self : not null access constant Table_Status_Attribute_Node)
return League.Strings.Universal_String;
end Matreshka.ODF_Table.Status_Attributes;
|
Gabriel-Degret/adalib | Ada | 550 | ads | -- Standard Ada library specification
-- Copyright (c) 2003-2018 Maxim Reznik <[email protected]>
-- Copyright (c) 2004-2016 AXE Consultants
-- Copyright (c) 2004, 2005, 2006 Ada-Europe
-- Copyright (c) 2000 The MITRE Corporation, Inc.
-- Copyright (c) 1992, 1993, 1994, 1995 Intermetrics, Inc.
-- SPDX-License-Identifier: BSD-3-Clause and LicenseRef-AdaReferenceManual
---------------------------------------------------------------------------
with System.Machine_Code;
package Machine_Code renames System.Machine_Code;
|
reznikmm/matreshka | Ada | 3,749 | ads | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Open Document Toolkit --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2014, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
with XML.DOM.Attributes;
package ODF.DOM.Text_Use_Other_Objects_Attributes is
pragma Preelaborate;
type ODF_Text_Use_Other_Objects_Attribute is limited interface
and XML.DOM.Attributes.DOM_Attribute;
type ODF_Text_Use_Other_Objects_Attribute_Access is
access all ODF_Text_Use_Other_Objects_Attribute'Class
with Storage_Size => 0;
end ODF.DOM.Text_Use_Other_Objects_Attributes;
|
stcarrez/ada-asf | Ada | 17,167 | ads | -----------------------------------------------------------------------
-- applications -- Ada Web Application
-- Copyright (C) 2009, 2010, 2011, 2012, 2017, 2018, 2023 Stephane Carrez
-- Written by Stephane Carrez ([email protected])
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-----------------------------------------------------------------------
with Util.Beans.Basic;
with Util.Locales;
with EL.Objects;
with EL.Contexts;
with EL.Functions;
with EL.Functions.Default;
with EL.Expressions;
with EL.Variables.Default;
with Ada.Strings.Unbounded;
with ASF.Locales;
with ASF.Factory;
with ASF.Converters;
with ASF.Validators;
with ASF.Contexts.Faces;
with ASF.Contexts.Exceptions;
with ASF.Lifecycles;
with ASF.Applications.Views;
with ASF.Navigations;
with ASF.Beans;
with ASF.Requests;
with ASF.Responses;
with ASF.Servlets;
with ASF.Events.Faces.Actions;
with Security.Policies; use Security;
with Security.OAuth.Servers;
private with Security.Random;
package ASF.Applications.Main is
use ASF.Beans;
-- ------------------------------
-- Factory for creation of lifecycle, view handler
-- ------------------------------
type Application_Factory is tagged limited private;
-- Create the lifecycle handler. The lifecycle handler is created during
-- the initialization phase of the application. The default implementation
-- creates an <b>ASF.Lifecycles.Default.Default_Lifecycle</b> object.
-- It can be overridden to change the behavior of the ASF request lifecycle.
function Create_Lifecycle_Handler (App : in Application_Factory)
return ASF.Lifecycles.Lifecycle_Access;
-- Create the view handler. The view handler is created during
-- the initialization phase of the application. The default implementation
-- creates an <b>ASF.Applications.Views.View_Handler</b> object.
-- It can be overridden to change the views associated with the application.
function Create_View_Handler (App : in Application_Factory)
return ASF.Applications.Views.View_Handler_Access;
-- Create the navigation handler. The navigation handler is created during
-- the initialization phase of the application. The default implementation
-- creates an <b>ASF.Navigations.Navigation_Handler</b> object.
-- It can be overridden to change the navigations associated with the application.
function Create_Navigation_Handler (App : in Application_Factory)
return ASF.Navigations.Navigation_Handler_Access;
-- Create the security policy manager. The security policy manager is created during
-- the initialization phase of the application. The default implementation
-- creates a <b>Security.Policies.Policy_Manager</b> object.
function Create_Security_Manager (App : in Application_Factory)
return Security.Policies.Policy_Manager_Access;
-- Create the OAuth application manager. The OAuth application manager is created
-- during the initialization phase of the application. The default implementation
-- creates a <b>Security.OAuth.Servers.Auth_Manager</b> object.
function Create_OAuth_Manager (App : in Application_Factory)
return Security.OAuth.Servers.Auth_Manager_Access;
-- Create the exception handler. The exception handler is created during
-- the initialization phase of the application. The default implementation
-- creates a <b>ASF.Contexts.Exceptions.Exception_Handler</b> object.
function Create_Exception_Handler (App : in Application_Factory)
return ASF.Contexts.Exceptions.Exception_Handler_Access;
-- ------------------------------
-- Application
-- ------------------------------
type Application is new ASF.Servlets.Servlet_Registry
and ASF.Events.Faces.Actions.Action_Listener with private;
type Application_Access is access all Application'Class;
-- Get the application view handler.
function Get_View_Handler (App : access Application)
return access Views.View_Handler'Class;
-- Get the lifecycle handler.
function Get_Lifecycle_Handler (App : in Application)
return ASF.Lifecycles.Lifecycle_Access;
-- Get the navigation handler.
function Get_Navigation_Handler (App : in Application)
return ASF.Navigations.Navigation_Handler_Access;
-- Get the permission manager associated with this application.
function Get_Security_Manager (App : in Application)
return Security.Policies.Policy_Manager_Access;
-- Get the OAuth application manager associated with this application.
function Get_OAuth_Manager (App : in Application)
return Security.OAuth.Servers.Auth_Manager_Access;
-- Get the action event listener responsible for processing action
-- events and triggering the navigation to the next view using the
-- navigation handler.
function Get_Action_Listener (App : in Application)
return ASF.Events.Faces.Actions.Action_Listener_Access;
-- Get the exception handler configured for this application.
function Get_Exception_Handler (App : in Application)
return ASF.Contexts.Exceptions.Exception_Handler_Access;
-- Process the action associated with the action event. The action returns
-- and outcome which is then passed to the navigation handler to navigate to
-- the next view.
overriding
procedure Process_Action (Listener : in Application;
Event : in ASF.Events.Faces.Actions.Action_Event'Class;
Context : in out Contexts.Faces.Faces_Context'Class);
-- Execute the action method. The action returns and outcome which is then passed
-- to the navigation handler to navigate to the next view.
procedure Process_Action (Listener : in Application;
Method : in EL.Expressions.Method_Info;
Context : in out Contexts.Faces.Faces_Context'Class);
-- Initialize the application
procedure Initialize (App : in out Application;
Conf : in Config;
Factory : in out Application_Factory'Class);
-- Initialize the ASF components provided by the application.
-- This procedure is called by <b>Initialize</b>.
-- It should register the component factories used by the application.
procedure Initialize_Components (App : in out Application);
-- Initialize the application configuration properties. Properties defined in <b>Conf</b>
-- are expanded by using the EL expression resolver.
procedure Initialize_Config (App : in out Application;
Conf : in out Config);
-- Initialize the servlets provided by the application.
-- This procedure is called by <b>Initialize</b>.
-- It should register the application servlets.
procedure Initialize_Servlets (App : in out Application);
-- Initialize the filters provided by the application.
-- This procedure is called by <b>Initialize</b>.
-- It should register the application filters.
procedure Initialize_Filters (App : in out Application);
-- Finalizes the application, freeing the memory.
overriding
procedure Finalize (App : in out Application);
-- Get the configuration parameter;
function Get_Config (App : Application;
Param : Config_Param) return String;
-- Set a global variable in the global EL contexts.
procedure Set_Global (App : in out Application;
Name : in String;
Value : in String);
procedure Set_Global (App : in out Application;
Name : in String;
Value : in EL.Objects.Object);
-- Resolve a global variable and return its value.
-- Raises the <b>EL.Functions.No_Variable</b> exception if the variable does not exist.
function Get_Global (App : in Application;
Name : in Ada.Strings.Unbounded.Unbounded_String;
Context : in EL.Contexts.ELContext'Class)
return EL.Objects.Object;
-- Get the list of supported locales for this application.
function Get_Supported_Locales (App : in Application)
return Util.Locales.Locale_Array;
-- Add the locale to the list of supported locales.
procedure Add_Supported_Locale (App : in out Application;
Locale : in Util.Locales.Locale);
-- Get the default locale defined by the application.
function Get_Default_Locale (App : in Application) return Util.Locales.Locale;
-- Set the default locale defined by the application.
procedure Set_Default_Locale (App : in out Application;
Locale : in Util.Locales.Locale);
-- Compute the locale that must be used according to the <b>Accept-Language</b> request
-- header and the application supported locales.
function Calculate_Locale (Handler : in Application;
Context : in ASF.Contexts.Faces.Faces_Context'Class)
return Util.Locales.Locale;
-- Register a bundle and bind it to a facelet variable.
procedure Register (App : in out Application;
Name : in String;
Bundle : in String);
-- Register the bean identified by <b>Name</b> and associated with the class <b>Class</b>.
-- The class must have been registered by using the <b>Register</b> class operation.
-- The scope defines the scope of the bean.
procedure Register (App : in out Application;
Name : in String;
Class : in String;
Params : in Parameter_Bean_Ref.Ref;
Scope : in Scope_Type := REQUEST_SCOPE);
-- Register under the name identified by <b>Name</b> the class instance <b>Class</b>.
procedure Register_Class (App : in out Application;
Name : in String;
Class : in ASF.Beans.Class_Binding_Access);
-- Register under the name identified by <b>Name</b> a function to create a bean.
-- This is a simplified class registration.
procedure Register_Class (App : in out Application;
Name : in String;
Handler : in ASF.Beans.Create_Bean_Access);
-- Create a bean by using the create operation registered for the name
procedure Create (App : in Application;
Name : in Ada.Strings.Unbounded.Unbounded_String;
Context : in EL.Contexts.ELContext'Class;
Result : out Util.Beans.Basic.Readonly_Bean_Access;
Scope : out Scope_Type);
-- Add a converter in the application. The converter is referenced by
-- the specified name in the XHTML files.
procedure Add_Converter (App : in out Application;
Name : in String;
Converter : in ASF.Converters.Converter_Access);
-- Register a binding library in the factory.
procedure Add_Components (App : in out Application;
Bindings : in ASF.Factory.Factory_Bindings_Access);
-- Verify the token validity associated with the `Data`.
-- Returns True if the token is valid and false if it has expired or is invalid.
function Verify_Token (App : in Application;
Data : in String;
Token : in String) return Boolean;
-- Create a token for the data and the expiration time.
-- The token has an expiration deadline and is signed by the application.
-- The `Data` remains private and is never part of the returned token.
function Create_Token (App : in Application;
Data : in String;
Expire : in Duration) return String;
-- Closes the application
procedure Close (App : in out Application);
-- Set the current faces context before processing a view.
procedure Set_Context (App : in out Application;
Context : in ASF.Contexts.Faces.Faces_Context_Access);
-- Execute the lifecycle phases on the faces context.
procedure Execute_Lifecycle (App : in Application;
Context : in out ASF.Contexts.Faces.Faces_Context'Class);
-- Dispatch the request received on a page.
procedure Dispatch (App : in out Application;
Page : in String;
Request : in out ASF.Requests.Request'Class;
Response : in out ASF.Responses.Response'Class);
-- Dispatch a bean action request.
-- 1. Find the bean object identified by <b>Name</b>, create it if necessary.
-- 2. Resolve the bean method identified by <b>Operation</b>.
-- 3. If the method is an action method (see ASF.Events.Actions), call that method.
-- 4. Using the outcome action result, decide using the navigation handler what
-- is the result view.
-- 5. Render the result view resolved by the navigation handler.
procedure Dispatch (App : in out Application;
Name : in String;
Operation : in String;
Request : in out ASF.Requests.Request'Class;
Response : in out ASF.Responses.Response'Class;
Prepare : access procedure (Bean : access Util.Beans.Basic.Bean'Class));
-- Find the converter instance that was registered under the given name.
-- Returns null if no such converter exist.
function Find (App : in Application;
Name : in EL.Objects.Object) return ASF.Converters.Converter_Access;
-- Find the validator instance that was registered under the given name.
-- Returns null if no such validator exist.
function Find_Validator (App : in Application;
Name : in EL.Objects.Object)
return ASF.Validators.Validator_Access;
-- Register some functions
generic
with procedure Set_Functions (Mapper : in out EL.Functions.Function_Mapper'Class);
procedure Register_Functions (App : in out Application'Class);
-- Register some bean definitions.
generic
with procedure Set_Beans (Factory : in out ASF.Beans.Bean_Factory);
procedure Register_Beans (App : in out Application'Class);
-- Load the resource bundle identified by the <b>Name</b> and for the given
-- <b>Locale</b>.
procedure Load_Bundle (App : in out Application;
Name : in String;
Locale : in String;
Bundle : out ASF.Locales.Bundle);
private
type Application_Factory is tagged limited null record;
TOKEN_KEY_LENGTH : constant := 32;
type Application is new ASF.Servlets.Servlet_Registry
and ASF.Events.Faces.Actions.Action_Listener with record
View : aliased ASF.Applications.Views.View_Handler;
Lifecycle : ASF.Lifecycles.Lifecycle_Access;
Factory : aliased ASF.Beans.Bean_Factory;
Locales : ASF.Locales.Factory;
Globals : aliased EL.Variables.Default.Default_Variable_Mapper;
Functions : aliased EL.Functions.Default.Default_Function_Mapper;
-- The component factory
Components : aliased ASF.Factory.Component_Factory;
-- The action listener.
Action_Listener : ASF.Events.Faces.Actions.Action_Listener_Access;
-- The navigation handler.
Navigation : ASF.Navigations.Navigation_Handler_Access;
-- The permission manager.
Permissions : Security.Policies.Policy_Manager_Access;
-- The OAuth application manager.
OAuth : Security.OAuth.Servers.Auth_Manager_Access;
-- Exception handler
Exceptions : ASF.Contexts.Exceptions.Exception_Handler_Access;
-- Token CSRF generation support.
Random : Security.Random.Generator;
Token_Key : String (1 .. TOKEN_KEY_LENGTH);
end record;
end ASF.Applications.Main;
|
zhmu/ananas | Ada | 56 | ads | with Inline20_I;
package Inline20_Q is new Inline20_I;
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.