repo_name
stringlengths 9
74
| language
stringclasses 1
value | length_bytes
int64 11
9.34M
| extension
stringclasses 2
values | content
stringlengths 11
9.34M
|
---|---|---|---|---|
charlie5/cBound | Ada | 617 | ads | -- This file is generated by SWIG. Please do *not* modify by hand.
--
with gmp_c.a_a_mpz_struct;
with Interfaces.C;
package gmp_c.mpz_ptr is
-- Item
--
subtype Item is gmp_c.a_a_mpz_struct.Pointer;
-- Items
--
type Items is
array (Interfaces.C.size_t range <>) of aliased gmp_c.mpz_ptr.Item;
-- Pointer
--
type Pointer is access all gmp_c.mpz_ptr.Item;
-- Pointers
--
type Pointers is
array (Interfaces.C.size_t range <>) of aliased gmp_c.mpz_ptr.Pointer;
-- Pointer_Pointer
--
type Pointer_Pointer is access all gmp_c.mpz_ptr.Pointer;
end gmp_c.mpz_ptr;
|
thorstel/Advent-of-Code-2018 | Ada | 1,092 | ads | package Input12 is
subtype String_Pattern is String (1 .. 5);
type Input_Type is record
Pattern : String_Pattern;
Plant : Character;
end record;
Initial_State : constant String :=
"..#..###...#####.#.#...####.#..####..###.##.#.#.##.#....#....#.####...#....###.###..##.#....#######";
Inputs : array (Positive range <>) of Input_Type :=
(("..###", '.'),
(".##.#", '#'),
("#..#.", '.'),
("#.#.#", '#'),
("###..", '#'),
(".#..#", '.'),
("##..#", '#'),
(".###.", '#'),
("..#..", '.'),
(".....", '.'),
("#####", '.'),
(".#...", '#'),
("...#.", '#'),
("#...#", '#'),
("####.", '.'),
(".####", '.'),
("##.##", '#'),
("...##", '.'),
("..##.", '.'),
("#.##.", '.'),
("#....", '.'),
(".#.#.", '.'),
("..#.#", '#'),
("#.#..", '#'),
("##...", '#'),
("##.#.", '.'),
("#..##", '.'),
(".##..", '.'),
("#.###", '.'),
("....#", '.'),
(".#.##", '#'),
("###.#", '#'));
end Input12;
|
optikos/oasis | Ada | 7,976 | ads | -- Copyright (c) 2019 Maxim Reznik <[email protected]>
--
-- SPDX-License-Identifier: MIT
-- License-Filename: LICENSE
-------------------------------------------------------------
with Program.Lexical_Elements;
with Program.Elements.Parameter_Specifications;
with Program.Elements.Function_Access_Types;
with Program.Element_Visitors;
package Program.Nodes.Function_Access_Types is
pragma Preelaborate;
type Function_Access_Type is
new Program.Nodes.Node
and Program.Elements.Function_Access_Types.Function_Access_Type
and Program.Elements.Function_Access_Types.Function_Access_Type_Text
with private;
function Create
(Not_Token : Program.Lexical_Elements.Lexical_Element_Access;
Null_Token : Program.Lexical_Elements.Lexical_Element_Access;
Access_Token : not null Program.Lexical_Elements
.Lexical_Element_Access;
Protected_Token : Program.Lexical_Elements.Lexical_Element_Access;
Function_Token : not null Program.Lexical_Elements
.Lexical_Element_Access;
Left_Bracket_Token : Program.Lexical_Elements.Lexical_Element_Access;
Parameters : Program.Elements.Parameter_Specifications
.Parameter_Specification_Vector_Access;
Right_Bracket_Token : Program.Lexical_Elements.Lexical_Element_Access;
Return_Token : not null Program.Lexical_Elements
.Lexical_Element_Access;
Not_Token_2 : Program.Lexical_Elements.Lexical_Element_Access;
Null_Token_2 : Program.Lexical_Elements.Lexical_Element_Access;
Result_Subtype : not null Program.Elements.Element_Access)
return Function_Access_Type;
type Implicit_Function_Access_Type is
new Program.Nodes.Node
and Program.Elements.Function_Access_Types.Function_Access_Type
with private;
function Create
(Parameters : Program.Elements.Parameter_Specifications
.Parameter_Specification_Vector_Access;
Result_Subtype : not null Program.Elements.Element_Access;
Is_Part_Of_Implicit : Boolean := False;
Is_Part_Of_Inherited : Boolean := False;
Is_Part_Of_Instance : Boolean := False;
Has_Not_Null : Boolean := False;
Has_Protected : Boolean := False;
Has_Not_Null_2 : Boolean := False)
return Implicit_Function_Access_Type
with Pre =>
Is_Part_Of_Implicit or Is_Part_Of_Inherited or Is_Part_Of_Instance;
private
type Base_Function_Access_Type is
abstract new Program.Nodes.Node
and Program.Elements.Function_Access_Types.Function_Access_Type
with record
Parameters : Program.Elements.Parameter_Specifications
.Parameter_Specification_Vector_Access;
Result_Subtype : not null Program.Elements.Element_Access;
end record;
procedure Initialize
(Self : aliased in out Base_Function_Access_Type'Class);
overriding procedure Visit
(Self : not null access Base_Function_Access_Type;
Visitor : in out Program.Element_Visitors.Element_Visitor'Class);
overriding function Parameters
(Self : Base_Function_Access_Type)
return Program.Elements.Parameter_Specifications
.Parameter_Specification_Vector_Access;
overriding function Result_Subtype
(Self : Base_Function_Access_Type)
return not null Program.Elements.Element_Access;
overriding function Is_Function_Access_Type_Element
(Self : Base_Function_Access_Type)
return Boolean;
overriding function Is_Access_Type_Element
(Self : Base_Function_Access_Type)
return Boolean;
overriding function Is_Type_Definition_Element
(Self : Base_Function_Access_Type)
return Boolean;
overriding function Is_Definition_Element
(Self : Base_Function_Access_Type)
return Boolean;
type Function_Access_Type is
new Base_Function_Access_Type
and Program.Elements.Function_Access_Types.Function_Access_Type_Text
with record
Not_Token : Program.Lexical_Elements.Lexical_Element_Access;
Null_Token : Program.Lexical_Elements.Lexical_Element_Access;
Access_Token : not null Program.Lexical_Elements
.Lexical_Element_Access;
Protected_Token : Program.Lexical_Elements.Lexical_Element_Access;
Function_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;
Return_Token : not null Program.Lexical_Elements
.Lexical_Element_Access;
Not_Token_2 : Program.Lexical_Elements.Lexical_Element_Access;
Null_Token_2 : Program.Lexical_Elements.Lexical_Element_Access;
end record;
overriding function To_Function_Access_Type_Text
(Self : aliased in out Function_Access_Type)
return Program.Elements.Function_Access_Types
.Function_Access_Type_Text_Access;
overriding function Not_Token
(Self : Function_Access_Type)
return Program.Lexical_Elements.Lexical_Element_Access;
overriding function Null_Token
(Self : Function_Access_Type)
return Program.Lexical_Elements.Lexical_Element_Access;
overriding function Access_Token
(Self : Function_Access_Type)
return not null Program.Lexical_Elements.Lexical_Element_Access;
overriding function Protected_Token
(Self : Function_Access_Type)
return Program.Lexical_Elements.Lexical_Element_Access;
overriding function Function_Token
(Self : Function_Access_Type)
return not null Program.Lexical_Elements.Lexical_Element_Access;
overriding function Left_Bracket_Token
(Self : Function_Access_Type)
return Program.Lexical_Elements.Lexical_Element_Access;
overriding function Right_Bracket_Token
(Self : Function_Access_Type)
return Program.Lexical_Elements.Lexical_Element_Access;
overriding function Return_Token
(Self : Function_Access_Type)
return not null Program.Lexical_Elements.Lexical_Element_Access;
overriding function Not_Token_2
(Self : Function_Access_Type)
return Program.Lexical_Elements.Lexical_Element_Access;
overriding function Null_Token_2
(Self : Function_Access_Type)
return Program.Lexical_Elements.Lexical_Element_Access;
overriding function Has_Not_Null
(Self : Function_Access_Type)
return Boolean;
overriding function Has_Protected
(Self : Function_Access_Type)
return Boolean;
overriding function Has_Not_Null_2
(Self : Function_Access_Type)
return Boolean;
type Implicit_Function_Access_Type is
new Base_Function_Access_Type
with record
Is_Part_Of_Implicit : Boolean;
Is_Part_Of_Inherited : Boolean;
Is_Part_Of_Instance : Boolean;
Has_Not_Null : Boolean;
Has_Protected : Boolean;
Has_Not_Null_2 : Boolean;
end record;
overriding function To_Function_Access_Type_Text
(Self : aliased in out Implicit_Function_Access_Type)
return Program.Elements.Function_Access_Types
.Function_Access_Type_Text_Access;
overriding function Is_Part_Of_Implicit
(Self : Implicit_Function_Access_Type)
return Boolean;
overriding function Is_Part_Of_Inherited
(Self : Implicit_Function_Access_Type)
return Boolean;
overriding function Is_Part_Of_Instance
(Self : Implicit_Function_Access_Type)
return Boolean;
overriding function Has_Not_Null
(Self : Implicit_Function_Access_Type)
return Boolean;
overriding function Has_Protected
(Self : Implicit_Function_Access_Type)
return Boolean;
overriding function Has_Not_Null_2
(Self : Implicit_Function_Access_Type)
return Boolean;
end Program.Nodes.Function_Access_Types;
|
AdaCore/gpr | Ada | 56 | ads | package G.Foo is
Msg : String := "G.Foo";
end G.Foo;
|
onox/orka | Ada | 874 | ads | -- SPDX-License-Identifier: Apache-2.0
--
-- Copyright (c) 2022 onox <[email protected]>
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
with Orka.Transforms.Singles.Matrices;
with Generic_Test_Transforms_Matrices;
package Test_Transforms_Singles_Matrices is new Generic_Test_Transforms_Matrices
("Singles",
Orka.Transforms.Singles.Matrices);
|
zyron92/banana_tree_generator | Ada | 414 | ads | with Svg_Helpers, Parseur, Ada.Text_Io, Ada.Integer_Text_Io;
use Svg_Helpers, Parseur, Ada.Text_Io, Ada.Integer_Text_Io;
package Traceur_Final is
--Génération du fichier svg du tracé final avec ou sans le tracé intermédiaire
procedure Generer_Trace_Final (Nom_Fichier: in string; Couleur_Trait: in RGB; Epaisseur: in string; G: in Graphe; Avec_Intermediaire,Mode_Min: in Boolean);
end Traceur_Final;
|
AdaCore/gpr | Ada | 1,045 | adb | with Ada.Text_IO;
with GPR2.Context;
with GPR2.Path_Name;
with GPR2.Project.Tree;
use GPR2;
procedure Main is
procedure Test (Gpr : String) is
Tree : Project.Tree.Object;
Ctx : Context.Object;
begin
Project.Tree.Load_Autoconf
(Tree,
Path_Name.Create_File (Filename_Type (Gpr)),
Context => Ctx);
if Tree.Log_Messages.Has_Error then
Tree.Log_Messages.Output_Messages (Information => False);
return;
end if;
for V of Tree.Ordered_Views loop
if V.Kind /= K_Aggregate then
Ada.Text_IO.Put ("Roots for " & String (V.Name));
if V.Is_Extended then
Ada.Text_IO.Put (" extended by " & String (V.Extending.Name));
end if;
Ada.Text_IO.New_Line;
for Root of V.Namespace_Roots loop
Ada.Text_IO.Put_Line (" - " & String (Root.Name));
end loop;
end if;
end loop;
Tree.Unload;
end Test;
begin
Test ("tree/agg.gpr");
end Main;
|
zhmu/ananas | Ada | 312 | adb | -- { dg-do compile }
-- { dg-options "-O3" }
package body Opt56 is
function F (Values : Vector) return Boolean is
Result : Boolean := True;
begin
for I in Values'Range loop
Result := Result and Values (I) >= 0.0;
end loop;
return Result;
end;
end Opt56;
|
leo-brewin/Regge | Ada | 18,709 | adb | -- Copyright (c) 2017, Leo Brewin <[email protected]>
--
-- Permission to use, copy, modify, and/or distribute this software for any
-- purpose with or without fee is hereby granted, provided that the above
-- copyright notice and this permission notice appear in all copies.
--
-- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
-- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
-- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
-- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
-- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
with Ada.Numerics; use Ada.Numerics;
with Ada.Numerics.Generic_Elementary_Functions;
package body regge is
package Maths is new Ada.Numerics.Generic_Elementary_Functions (Real); use Maths;
function "*" (Left : Integer; Right : Real) return Real is
begin
return Real(Left) * Right;
end "*";
function "*" (Left : Real; Right : Integer) return Real is
begin
return Left * Real(Right);
end "*";
function sign (x : Real) return Integer is
begin
if x = 0.0 then
return 0;
else
if x < 0.0
then return -1;
else return +1;
end if;
end if;
end sign;
function inv_angle
(n1_dot_m2 : Real;
m1_dot_m2 : Real;
sig_m1 : Integer) return Real
is
phi : Real;
rho : Real;
begin
case bone_signature is
when timelike =>
phi := arccos (m1_dot_m2);
when spacelike =>
if abs (m1_dot_m2) < abs (n1_dot_m2)
then rho := sign (n1_dot_m2) * m1_dot_m2;
else rho := sign (m1_dot_m2) * n1_dot_m2;
end if;
phi := sig_m1 * arcsinh (rho);
end case;
return phi;
end inv_angle;
procedure gauss_system
(solution : out Array2dReal;
the_matrix : in Array2dReal;
the_rhs : in Array2dReal;
num_row : in Integer;
num_rhs : in Integer;
cond : out Real;
failed : out Boolean)
is
singular_pivot : constant := 1.0e-20;
-- Solves a set of linear equations by Gaussian elimination. ------------
det : Real;
pivoting : Boolean;
size : Integer := num_row;
col, row, pivot_row : Integer;
sum, pivot, factor, maximum, temporary : Real;
min_pivot, max_pivot : Real;
rhs : Array2dReal := the_rhs;
matrix : Array2dReal := the_matrix;
begin
col := 1;
row := 1;
det := 1.0e0;
min_pivot := 1.0e20;
max_pivot := 0.0e0;
failed := False;
pivoting := True;
while pivoting loop
-- search for pivot row
maximum := abs (matrix (col, col));
pivot_row := col;
for row in col + 1 .. size loop
if maximum < abs (matrix (row, col)) then
maximum := abs (matrix (row, col));
pivot_row := row;
end if;
end loop;
-- swap diagonal row with pivot row
if pivot_row /= col then
for i in col .. size loop
temporary := matrix (pivot_row, i);
matrix (pivot_row, i) := matrix (col, i);
matrix (col, i) := temporary;
end loop;
for i in 1 .. num_rhs loop
temporary := rhs (pivot_row, i);
rhs (pivot_row, i) := rhs (col, i);
rhs (col, i) := temporary;
end loop;
det := -det;
end if;
-- set diagonal element to one
pivot := matrix (col, col);
if abs (pivot) < min_pivot then
min_pivot := abs (pivot);
end if;
if abs (pivot) > max_pivot then
max_pivot := abs (pivot);
end if;
if abs (pivot / max_pivot) < singular_pivot then
pivoting := False;
failed := True;
det := 0.0e0;
else
matrix (col, col) := 1.0e0;
for i in col + 1 .. size loop
matrix (col, i) := matrix (col, i) / pivot;
end loop;
for i in 1 .. num_rhs loop
rhs (col, i) := rhs (col, i) / pivot;
end loop;
-- eliminate elements below diagonal
for row in col + 1 .. size loop
factor := matrix (row, col);
for i in col .. size loop
matrix (row, i) := matrix (row, i) - factor * matrix (col, i);
end loop;
for i in 1 .. num_rhs loop
rhs (row, i) := rhs (row, i) - factor * rhs (col, i);
end loop;
end loop;
col := col + 1;
pivoting := (not failed) and (col <= size);
det := det * pivot;
end if;
end loop;
-- form the back-substitution
if not failed then
for i in 1 .. num_rhs loop
solution (size, i) := rhs (size, i);
for row in reverse 1 .. size - 1 loop
sum := 0.0e0;
for col in row + 1 .. size loop
sum := sum + matrix (row, col) * solution (col, i);
end loop;
solution (row, i) := rhs (row, i) - sum;
end loop;
end loop;
else
for i in 1 .. size loop
for j in 1 .. num_rhs loop
solution (i, j) := 0.0e0;
end loop;
end loop;
end if;
if not failed
then cond := min_pivot / max_pivot;
else cond := 0.0e0;
end if;
end gauss_system;
function inverse
(matrix : Array2dReal) return Array2dReal
is
cond : Real;
failed : Boolean;
sol : Array2dReal (matrix'first(1)..matrix'last(1),matrix'first(1)..matrix'last(1));
identity : Array2dReal (matrix'first(1)..matrix'last(1),matrix'first(1)..matrix'last(1));
begin
if matrix'length(1) /= matrix'length (2)
then raise Constraint_Error with " matrix must be square";
else
for i in identity'range(1) loop
identity (i,i) := 1.0;
for j in i+1 .. identity'last(2) loop
identity (i,j) := 0.0;
identity (j,i) := 0.0;
end loop;
end loop;
gauss_system (sol,matrix,identity,matrix'length(1),matrix'length(2),cond,failed);
if not failed
then return sol;
else raise Constraint_Error with " matrix may be singular";
end if;
end if;
end inverse;
procedure set_normal
(n : out Array1dReal;
m : out Array1dReal;
sig_n : out Integer;
sig_m : out Integer;
c : Integer;
d : Integer;
inv_metric : Array2dReal)
is
tmp : Real;
begin
-- compute the outward pointing unit normal, n
if inv_metric (c, c) > 0.0 then
sig_n := +1;
tmp := +Sqrt (abs (inv_metric (c, c)));
for a in 1 .. 4 loop
n (a) := -inv_metric (a, c) / tmp; -- minus sign for outward normal
end loop;
else
sig_n := -1;
tmp := -Sqrt (abs (inv_metric (c, c)));
for a in 1 .. 4 loop
n (a) := -inv_metric (a, c) / tmp; -- minus sign for outward normal
end loop;
end if;
-- compute the unit tangent vector, m
tmp := inv_metric (c, d) / inv_metric (c, c);
for a in 1 .. 4 loop
m (a) := inv_metric (a, d) - tmp * inv_metric (a, c);
end loop;
if m (d) > 0.0 then
sig_m := +1;
tmp := +Sqrt (abs (m (d)));
for a in 1 .. 4 loop
m (a) := m (a) / tmp;
end loop;
else
sig_m := -1;
tmp := -Sqrt (abs (m (d)));
for a in 1 .. 4 loop
m (a) := m (a) / tmp;
end loop;
end if;
end set_normal;
function get_signature
(bone : Integer) return bone_type
is
leg_ij, leg_ik, leg_jk : Integer;
lsq_ij, lsq_ik, lsq_jk : Real;
g11, g22, g12 : Real;
begin
leg_ij := simp12 (bone)(1);
leg_ik := simp12 (bone)(2);
leg_jk := simp12 (bone)(3);
lsq_ij := lsq (leg_ij);
lsq_ik := lsq (leg_ik);
lsq_jk := lsq (leg_jk);
g11 := lsq_ij;
g22 := lsq_ik;
g12 := (g11 + g22 - lsq_jk) / 2.0;
if g11*g22-g12*g12 > 0.0
then return spacelike;
else return timelike;
end if;
end get_signature;
procedure set_metric
(metric : out Array2dReal;
bone : Integer;
index : Integer)
is
offset : Integer;
leg_ab : Integer;
leg_ij, leg_ik, leg_jk : Integer;
leg_ai, leg_aj, leg_ak : Integer;
leg_bi, leg_bj, leg_bk : Integer;
lsq_ab : Real;
lsq_ij, lsq_ik, lsq_jk : Real;
lsq_ia, lsq_ja, lsq_ka : Real;
lsq_ib, lsq_jb, lsq_kb : Real;
begin
offset := 4*index - 4;
leg_ij := simp12 (bone)(1);
leg_ik := simp12 (bone)(2);
leg_jk := simp12 (bone)(3);
leg_ai := simp12 (bone)(offset+4);
leg_aj := simp12 (bone)(offset+5);
leg_ak := simp12 (bone)(offset+6);
leg_ab := simp12 (bone)(offset+7);
leg_bi := simp12 (bone)(offset+8);
leg_bj := simp12 (bone)(offset+9);
leg_bk := simp12 (bone)(offset+10);
lsq_ij := lsq (leg_ij);
lsq_ik := lsq (leg_ik);
lsq_jk := lsq (leg_jk);
lsq_ia := lsq (leg_ai);
lsq_ja := lsq (leg_aj);
lsq_ka := lsq (leg_ak);
lsq_ib := lsq (leg_bi);
lsq_jb := lsq (leg_bj);
lsq_kb := lsq (leg_bk);
lsq_ab := lsq (leg_ab);
metric (1, 1) := lsq_ij;
metric (2, 2) := lsq_ik;
metric (3, 3) := lsq_ia;
metric (4, 4) := lsq_ib;
metric (1, 2) := (metric (1, 1) + metric (2, 2) - lsq_jk) / 2.0;
metric (1, 3) := (metric (1, 1) + metric (3, 3) - lsq_ja) / 2.0;
metric (1, 4) := (metric (1, 1) + metric (4, 4) - lsq_jb) / 2.0;
metric (2, 3) := (metric (2, 2) + metric (3, 3) - lsq_ka) / 2.0;
metric (2, 4) := (metric (2, 2) + metric (4, 4) - lsq_kb) / 2.0;
metric (3, 4) := (metric (3, 3) + metric (4, 4) - lsq_ab) / 2.0;
metric (2, 1) := metric (1, 2);
metric (3, 1) := metric (1, 3);
metric (4, 1) := metric (1, 4);
metric (3, 2) := metric (2, 3);
metric (4, 2) := metric (2, 4);
metric (4, 3) := metric (3, 4);
end set_metric;
procedure get_defect
(defect : out Real;
bone : Integer;
n_vertex : Integer)
is
phi : Real;
procedure take_one_step
(phi : in out Real;
index : Integer)
is
n1_dot_m2 : Real;
m1_dot_m2 : Real;
tmp_a : Real;
tmp_b : Real;
tmp_c : Real;
sig_m1 : Integer;
metric : Array2dReal (1..4,1..4);
inv_metric : Array2dReal (1..4,1..4);
begin
set_metric (metric, bone, index); -- standard metric for (i,j,k,a,b);
inv_metric := inverse (metric);
-- update phi, the defect
tmp_a := inv_metric (3, 3) * inv_metric (4, 4);
tmp_b := inv_metric (3, 4) * inv_metric (3, 4);
tmp_c := 1.0 - (tmp_b / tmp_a);
sig_m1 := sign (tmp_c * inv_metric (3, 3));
n1_dot_m2 := -sign (inv_metric (4, 4)) * Sqrt (abs (tmp_c));
m1_dot_m2 := -sign (tmp_a - tmp_b) * inv_metric (3, 4) / Sqrt (abs (tmp_a));
phi := phi + inv_angle (n1_dot_m2, m1_dot_m2, sig_m1);
end take_one_step;
begin
phi := 0.0;
-- compute the defect
-- take a tour around the bone, visiting each 4-simplex in turn
for a in 1 .. n_vertex loop
take_one_step (phi, a);
end loop;
case bone_signature is
when timelike => defect := 2.0 * Pi - phi;
when spacelike => defect := -phi;
end case;
end get_defect;
procedure get_defect_deriv
(deriv : out Real;
bone : Integer;
n_vertex : Integer;
leg_pq : Integer)
is
rho : Real;
deriv_metric : Array2dReal (1 .. 4, 1 .. 4);
procedure set_metric_deriv
(bone : Integer;
index : Integer)
is
the_delta : Real;
save_lsq : Real;
metric_p : Array2dReal (1 .. 4, 1 .. 4);
metric_m : Array2dReal (1 .. 4, 1 .. 4);
begin
-- compute derivative of the metric
-- since the metric is linear in the lsq, a simple finite difference
-- method will give the exact answer
save_lsq := lsq (leg_pq);
the_delta := save_lsq / 10.0;
lsq (leg_pq) := save_lsq + the_delta; set_metric (metric_p, bone, index);
lsq (leg_pq) := save_lsq - the_delta; set_metric (metric_m, bone, index);
for a in 1 .. 4 loop
for b in 1 .. 4 loop
deriv_metric (a, b) := (metric_p (a, b) - metric_m (a, b)) / (2.0 * the_delta);
end loop;
end loop;
-- reset lsq to its original value
lsq (leg_pq) := save_lsq;
end set_metric_deriv;
procedure take_one_step
(rho : in out Real;
index : Integer)
is
sum : Real;
sig_n1, sig_m1 : Integer;
sig_n2, sig_m2 : Integer;
n1, m1 : Array1dReal (1 .. 4);
n2, m2 : Array1dReal (1 .. 4);
metric : Array2dReal (1..4,1..4);
inv_metric : Array2dReal (1..4,1..4);
begin
set_metric (metric, bone, index); -- standard metric for (i,j,k,a,b);
inv_metric := inverse (metric);
set_normal (n1, m1, sig_n1, sig_m1, 4, 3, inv_metric); -- outward normal & tangent vector to (i,j,k,a)
set_normal (n2, m2, sig_n2, sig_m2, 3, 4, inv_metric); -- outward normal & tangent vector to (i,j,k,b)
set_metric_deriv (bone, index);
-- update rho, the derivative of the defect
sum := 0.0;
for a in 1 .. 4 loop
for b in 1 .. 4 loop
sum := sum + (n1 (a) * m1 (b) + n2 (a) * m2 (b)) * deriv_metric (a, b);
end loop;
end loop;
rho := rho + sum;
end take_one_step;
begin
rho := 0.0;
for a in 1 .. n_vertex loop
take_one_step (rho, a);
end loop;
case bone_signature is
when timelike => deriv := -rho / 2.0;
when spacelike => deriv := rho / 2.0;
end case;
end get_defect_deriv;
procedure get_defect_and_deriv
(defect : out Real;
deriv : out Real;
bone : Integer;
n_vertex : Integer;
leg_pq : Integer)
is
phi : Real;
rho : Real;
deriv_metric : Array2dReal (1 .. 4, 1 .. 4);
procedure set_metric_deriv
(bone : Integer;
index : Integer)
is
the_delta : Real;
save_lsq : Real;
metric_p : Array2dReal (1 .. 4, 1 .. 4);
metric_m : Array2dReal (1 .. 4, 1 .. 4);
begin
-- compute derivative of the metric
-- since the metric is linear in the lsq, a simple finite difference
-- method will give the exact answer
save_lsq := lsq (leg_pq);
the_delta := save_lsq / 10.0;
lsq (leg_pq) := save_lsq + the_delta; set_metric (metric_p, bone, index);
lsq (leg_pq) := save_lsq - the_delta; set_metric (metric_m, bone, index);
for a in 1 .. 4 loop
for b in 1 .. 4 loop
deriv_metric (a, b) := (metric_p (a, b) - metric_m (a, b)) / (2.0 * the_delta);
end loop;
end loop;
-- reset lsq to its original value
lsq (leg_pq) := save_lsq;
end set_metric_deriv;
procedure take_one_step
(phi : in out Real;
rho : in out Real;
index : Integer)
is
sum : Real;
n1_dot_m2 : Real;
m1_dot_m2 : Real;
tmp_a : Real;
tmp_b : Real;
tmp_c : Real;
sig_n1, sig_m1 : Integer;
sig_n2, sig_m2 : Integer;
n1, m1 : Array1dReal (1 .. 4);
n2, m2 : Array1dReal (1 .. 4);
metric : Array2dReal (1..4,1..4);
inv_metric : Array2dReal (1..4,1..4);
begin
set_metric (metric, bone, index); -- standard metric for (i,j,k,a,b);
inv_metric := inverse (metric);
set_normal (n1, m1, sig_n1, sig_m1, 4, 3, inv_metric); -- outward normal & tangent vector to (i,j,k,a)
set_normal (n2, m2, sig_n2, sig_m2, 3, 4, inv_metric); -- outward normal & tangent vector to (i,j,k,b)
set_metric_deriv (bone, index);
-- update phi, the defect
tmp_a := inv_metric (3, 3) * inv_metric (4, 4);
tmp_b := inv_metric (3, 4) * inv_metric (3, 4);
tmp_c := 1.0 - (tmp_b / tmp_a);
sig_m1 := sign (tmp_c * inv_metric (3, 3));
n1_dot_m2 := -sign (inv_metric (4, 4)) * Sqrt (abs (tmp_c));
m1_dot_m2 := -sign (tmp_a - tmp_b) * inv_metric (3, 4) / Sqrt (abs (tmp_a));
phi := phi + inv_angle (n1_dot_m2, m1_dot_m2, sig_m1);
-- update rho, the derivative of the defect
sum := 0.0;
for a in 1 .. 4 loop
for b in 1 .. 4 loop
sum := sum + (n1 (a) * m1 (b) + n2 (a) * m2 (b)) * deriv_metric (a, b);
end loop;
end loop;
rho := rho + sum;
end take_one_step;
begin
phi := 0.0;
rho := 0.0;
for a in 1 .. n_vertex loop
take_one_step (phi, rho, a);
end loop;
case bone_signature is
when timelike => defect := 2.0 * Pi - phi;
when spacelike => defect := -phi;
end case;
case bone_signature is
when timelike => deriv := -rho / 2.0;
when spacelike => deriv := rho / 2.0;
end case;
end get_defect_and_deriv;
end regge;
|
io7m/coreland-openal-ada | Ada | 1,897 | adb | with Test;
with OpenAL.Context;
with OpenAL.Context.Error;
procedure init_003 is
package ALC renames OpenAL.Context;
package ALC_Error renames OpenAL.Context.Error;
Device : ALC.Device_t;
Context : ALC.Context_t;
Current_OK : Boolean;
TC : Test.Context_t;
use type ALC.Device_t;
use type ALC.Context_t;
use type ALC_Error.Error_t;
begin
Test.Initialize
(Test_Context => TC,
Program => "init_003",
Test_DB => "TEST_DB",
Test_Results => "TEST_RESULTS");
Device := ALC.Open_Default_Device;
pragma Assert (Device /= ALC.Invalid_Device);
pragma Assert (ALC_Error.Get_Error (Device) = ALC_Error.No_Error);
Context := ALC.Create_Context (Device);
pragma Assert (Context /= ALC.Invalid_Context);
pragma Assert (ALC_Error.Get_Error (Device) = ALC_Error.No_Error);
Current_OK := ALC.Get_Current_Context = ALC.Null_Context;
Test.Check (TC, 12, Current_OK, "Current_OK");
Test.Check (TC, 13, ALC_Error.Get_Error (Device) = ALC_Error.No_Error,
"ALC_Error.Get_Error (Device) = ALC_Error.No_Error");
Current_OK := ALC.Make_Context_Current (Context);
pragma Assert (Current_OK);
pragma Assert (ALC_Error.Get_Error (Device) = ALC_Error.No_Error);
Current_OK := ALC.Get_Current_Context = Context;
Test.Check (TC, 14, Current_OK, "Current_OK");
Test.Check (TC, 15, ALC_Error.Get_Error (Device) = ALC_Error.No_Error,
"ALC_Error.Get_Error (Device) = ALC_Error.No_Error");
Current_OK := ALC.Get_Context_Device (Context) = Device;
Test.Check (TC, 16, Current_OK, "Current_OK");
Test.Check (TC, 17, ALC_Error.Get_Error (Device) = ALC_Error.No_Error,
"ALC_Error.Get_Error (Device) = ALC_Error.No_Error");
ALC.Destroy_Context (Context);
pragma Assert (ALC_Error.Get_Error (Device) = ALC_Error.No_Error);
ALC.Close_Device (Device);
pragma Assert (Device = ALC.Invalid_Device);
end init_003;
|
reznikmm/matreshka | Ada | 5,871 | adb | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Ada Modeling Framework --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2012, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
with AMF.Elements;
with AMF.Internals.Extents;
with AMF.Internals.Helpers;
with AMF.Internals.Tables.MOFEXT_Element_Table;
with AMF.Internals.Tables.MOFEXT_Reflection;
package body AMF.Internals.MOF_Elements is
------------
-- Extent --
------------
overriding function Extent
(Self : not null access constant MOF_Element_Proxy)
return AMF.Extents.Extent_Access is
begin
return
AMF.Internals.Extents.Proxy
(AMF.Internals.Tables.MOFEXT_Element_Table.Table (Self.Element).Extent);
end Extent;
---------
-- Get --
---------
overriding function Get
(Self : not null access constant MOF_Element_Proxy;
Property : not null AMF.CMOF.Properties.CMOF_Property_Access)
return League.Holders.Holder is
begin
return
AMF.Internals.Tables.MOFEXT_Reflection.Get
(Self.Element,
AMF.Internals.Helpers.To_Element
(AMF.Elements.Element_Access (Property)));
end Get;
--------------------
-- Get_Meta_Class --
--------------------
overriding function Get_Meta_Class
(Self : not null access constant MOF_Element_Proxy)
return AMF.CMOF.Classes.CMOF_Class_Access is
begin
return
AMF.CMOF.Classes.CMOF_Class_Access
(AMF.Internals.Helpers.To_Element
(AMF.Internals.Tables.MOFEXT_Reflection.Get_Meta_Class (Self.Element)));
end Get_Meta_Class;
-- -------------------
-- -- Must_Be_Owned --
-- -------------------
--
-- overriding function Must_Be_Owned
-- (Self : not null access constant UML_Element_Proxy) return Boolean
-- is
-- pragma Unreferenced (Self);
--
-- -- [UML241] 7.3.14 Element (from Kernel)
-- --
-- -- The query mustBeOwned() indicates whether elements of this type must
-- -- have an owner. Subclasses of Element that do not require an owner
-- -- must override this operation.
-- --
-- -- Element::mustBeOwned() : Boolean;
-- -- mustBeOwned = true
--
-- begin
-- return True;
-- end Must_Be_Owned;
---------
-- Set --
---------
overriding procedure Set
(Self : not null access MOF_Element_Proxy;
Property : not null AMF.CMOF.Properties.CMOF_Property_Access;
Value : League.Holders.Holder) is
begin
AMF.Internals.Tables.MOFEXT_Reflection.Set
(Self.Element,
AMF.Internals.Helpers.To_Element
(AMF.Elements.Element_Access (Property)),
Value);
end Set;
end AMF.Internals.MOF_Elements;
|
reznikmm/matreshka | Ada | 3,945 | 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.Smil_End_Attributes;
package Matreshka.ODF_Smil.End_Attributes is
type Smil_End_Attribute_Node is
new Matreshka.ODF_Smil.Abstract_Smil_Attribute_Node
and ODF.DOM.Smil_End_Attributes.ODF_Smil_End_Attribute
with null record;
overriding function Create
(Parameters : not null access Matreshka.DOM_Attributes.Attribute_L2_Parameters)
return Smil_End_Attribute_Node;
overriding function Get_Local_Name
(Self : not null access constant Smil_End_Attribute_Node)
return League.Strings.Universal_String;
end Matreshka.ODF_Smil.End_Attributes;
|
zenharris/ada-bbs | Ada | 3,324 | ads | generic
-- User's instantiation enumeration type
type Enumerated is (<>);
package Formatter is
-- Purpose: Format variable numeric arguments
--
-- F Returns the CONTENTS variant record set to the appropriate type
-- to allow a common data type to be passed to either GET or PUT.
--
-- Put Writes a formatted string given a variable number of data
-- values and a FORMAT string.
--
-- Get Returns a formatted string given a variable number of data
-- values and a FORMAT string.
type DP_Float is digits 15; -- Double precision float type
-- Allowable data types to format
type Data_Type is (Integer_Type,
Float_Type,
DP_Float_Type,
String_Type,
Character_Type,
Unknown_Type);
-- Abstract Data Type (ADT) specification
type Contents(Class : Data_Type := Unknown_type) is private;
-- Unconstrained array of data values to format
type Values is array (positive range <>) of Contents;
-- Specific data type to ADT conversion functions (overloaded)
function F(Data : in Integer) return Contents;
function F(Data : in Float) return Contents;
function F(Data : in DP_Float) return Contents;
function F(Data : in Character) return Contents;
function F(Data : in String) return Contents;
function F(Data : in Enumerated) return Contents;
-- Output formatted values procedures (overloaded)
procedure PutS(retStr : in out String;
Format : in String;
Value : in Values);
function SPut(Format : in String;
Value : in Values) return String;
function SPut(Format : in String;
Value : in Contents) return String;
procedure Put(Format : In String;
Value : In Values); -- Multiple data values
procedure Put(Format : In String;
Value : In Contents); -- Single data value
procedure Put(Format : In String); -- No data values
-- Output formatted values string functions (overloaded)
function Get(Format : In String;
Value : In Values) Return String; -- Multiple data values
function Get(Format : In String;
Value : In Contents) Return String; -- Single data value
function Get(Format : In String) Return String; -- No data values
private
-- Private string type
type String_Pointer is access String;
type String_Record is
record
The_String : String_Pointer;
The_Length : Natural := 0;
end record;
-- Abstract Data Type implementation
type Contents(Class : Data_Type := Unknown_type) is
record
case Class is
when Integer_type => Integer_value : Integer;
when Float_type => Float_value : Float;
when DP_Float_type => DP_Float_value : DP_float;
when Character_Type => Character_Value : Character;
when String_type => String_value : String_Record;
when Unknown_type => null;
end case;
end record;
end Formatter;
|
AdaCore/Ada_Drivers_Library | Ada | 3,568 | ads | ------------------------------------------------------------------------------
-- --
-- Copyright (C) 2015-2016, AdaCore --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions are --
-- met: --
-- 1. Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- 2. Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in --
-- the documentation and/or other materials provided with the --
-- distribution. --
-- 3. Neither the name of the copyright holder nor the names of its --
-- contributors may be used to endorse or promote products derived --
-- from this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT --
-- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, --
-- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY --
-- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT --
-- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE --
-- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
with Interfaces; use Interfaces;
package HAL.Audio is
pragma Preelaborate;
type Audio_Buffer is array (Natural range <>) of Integer_16
with Component_Size => 16, Alignment => 2;
type Audio_Volume is new Natural range 0 .. 100;
type Audio_Frequency is
(Audio_Freq_8kHz,
Audio_Freq_11kHz,
Audio_Freq_16kHz,
Audio_Freq_22kHz,
Audio_Freq_32kHz,
Audio_Freq_44kHz,
Audio_Freq_48kHz,
Audio_Freq_96kHz)
with Size => 32;
for Audio_Frequency use
(Audio_Freq_8kHz => 8_000,
Audio_Freq_11kHz => 11_025,
Audio_Freq_16kHz => 16_000,
Audio_Freq_22kHz => 22_050,
Audio_Freq_32kHz => 32_000,
Audio_Freq_44kHz => 44_100,
Audio_Freq_48kHz => 48_000,
Audio_Freq_96kHz => 96_000);
type Audio_Stream is limited interface;
procedure Set_Frequency (This : in out Audio_Stream;
Frequency : Audio_Frequency) is abstract;
procedure Transmit (This : in out Audio_Stream;
Data : Audio_Buffer) is abstract;
procedure Receive (This : in out Audio_Stream;
Data : out Audio_Buffer) is abstract;
end HAL.Audio;
|
zhmu/ananas | Ada | 2,596 | adb | ------------------------------------------------------------------------------
-- --
-- GNAT RUN-TIME COMPONENTS --
-- --
-- S Y S T E M . I M G _ I N T --
-- --
-- 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. --
-- --
------------------------------------------------------------------------------
-- This package does not require a body, since it is an instantiation. We
-- provide a dummy file containing a No_Body pragma so that previous versions
-- of the body (which did exist) will not interfere.
pragma No_Body;
|
reznikmm/matreshka | Ada | 5,984 | adb | ------------------------------------------------------------------------------
-- --
-- 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.Tables.CMOF_Attributes;
with AMF.Internals.Element_Collections;
with AMF.Visitors.CMOF_Iterators;
with AMF.Visitors.CMOF_Visitors;
package body AMF.Internals.CMOF_Enumerations is
use AMF.Internals.Tables.CMOF_Attributes;
-------------------
-- Enter_Element --
-------------------
overriding procedure Enter_Element
(Self : not null access constant CMOF_Enumeration_Proxy;
Visitor : in out AMF.Visitors.Abstract_Visitor'Class;
Control : in out AMF.Visitors.Traverse_Control) is
begin
if Visitor in AMF.Visitors.CMOF_Visitors.CMOF_Visitor'Class then
AMF.Visitors.CMOF_Visitors.CMOF_Visitor'Class
(Visitor).Enter_Enumeration
(AMF.CMOF.Enumerations.CMOF_Enumeration_Access (Self),
Control);
end if;
end Enter_Element;
-----------------------
-- Get_Owned_Literal --
-----------------------
overriding function Get_Owned_Literal
(Self : not null access constant CMOF_Enumeration_Proxy)
return
AMF.CMOF.Enumeration_Literals.Collections.
Ordered_Set_Of_CMOF_Enumeration_Literal is
begin
return
AMF.CMOF.Enumeration_Literals.Collections.Wrap
(AMF.Internals.Element_Collections.Wrap
(Internal_Get_Owned_Literal (Self.Element)));
end Get_Owned_Literal;
-------------------
-- Leave_Element --
-------------------
overriding procedure Leave_Element
(Self : not null access constant CMOF_Enumeration_Proxy;
Visitor : in out AMF.Visitors.Abstract_Visitor'Class;
Control : in out AMF.Visitors.Traverse_Control) is
begin
if Visitor in AMF.Visitors.CMOF_Visitors.CMOF_Visitor'Class then
AMF.Visitors.CMOF_Visitors.CMOF_Visitor'Class
(Visitor).Leave_Enumeration
(AMF.CMOF.Enumerations.CMOF_Enumeration_Access (Self),
Control);
end if;
end Leave_Element;
-------------------
-- Visit_Element --
-------------------
overriding procedure Visit_Element
(Self : not null access constant CMOF_Enumeration_Proxy;
Iterator : in out AMF.Visitors.Abstract_Iterator'Class;
Visitor : in out AMF.Visitors.Abstract_Visitor'Class;
Control : in out AMF.Visitors.Traverse_Control) is
begin
if Iterator in AMF.Visitors.CMOF_Iterators.CMOF_Iterator'Class then
AMF.Visitors.CMOF_Iterators.CMOF_Iterator'Class
(Iterator).Visit_Enumeration
(Visitor,
AMF.CMOF.Enumerations.CMOF_Enumeration_Access (Self),
Control);
end if;
end Visit_Element;
end AMF.Internals.CMOF_Enumerations;
|
google-code/ada-util | Ada | 1,678 | ads | -----------------------------------------------------------------------
-- util-processes-tests - Test for processes
-- Copyright (C) 2011 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.Tests;
package Util.Processes.Tests is
procedure Add_Tests (Suite : in Util.Tests.Access_Test_Suite);
type Test is new Util.Tests.Test with null record;
-- Tests when the process is not launched
procedure Test_No_Process (T : in out Test);
-- Test executing a process
procedure Test_Spawn (T : in out Test);
-- Test output pipe redirection: read the process standard output
procedure Test_Output_Pipe (T : in out Test);
-- Test input pipe redirection: write the process standard input
procedure Test_Input_Pipe (T : in out Test);
-- Test launching several processes through pipes in several threads.
procedure Test_Multi_Spawn (T : in out Test);
-- Test output file redirection.
procedure Test_Output_Redirect (T : in out Test);
end Util.Processes.Tests;
|
ohenley/ada-util | Ada | 7,755 | adb | -----------------------------------------------------------------------
-- util-dates-iso8601 -- ISO8601 dates
-- Copyright (C) 2011, 2013, 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.
-----------------------------------------------------------------------
package body Util.Dates.ISO8601 is
-- ------------------------------
-- Parses an ISO8601 date and return it as a calendar time.
-- Raises Constraint_Error if the date format is not recognized.
-- ------------------------------
function Value (Date : in String) return Ada.Calendar.Time is
use Ada.Calendar;
use Ada.Calendar.Formatting;
Result : Date_Record;
Pos : Natural;
begin
if Date'Length < 4 then
raise Constraint_Error with "Invalid date";
end if;
Result.Hour := 0;
Result.Minute := 0;
Result.Second := 0;
Result.Sub_Second := 0.0;
Result.Time_Zone := 0;
Result.Year := Year_Number'Value (Date (Date'First .. Date'First + 3));
if Date'Length = 4 then
-- ISO8601 date: YYYY
Result.Month := 1;
Result.Month_Day := 1;
elsif Date'Length = 7 and Date (Date'First + 4) = '-' then
-- ISO8601 date: YYYY-MM
Result.Month := Month_Number'Value (Date (Date'First + 4 .. Date'Last));
Result.Month_Day := 1;
elsif Date'Length = 8 then
-- ISO8601 date: YYYYMMDD
Result.Month := Month_Number'Value (Date (Date'First + 4 .. Date'First + 5));
Result.Month_Day := Day_Number'Value (Date (Date'First + 6 .. Date'First + 7));
elsif Date'Length >= 9 and then Date (Date'First + 4) = '-'
and then Date (Date'First + 7) = '-'
then
-- ISO8601 date: YYYY-MM-DD
Result.Month := Month_Number'Value (Date (Date'First + 5 .. Date'First + 6));
Result.Month_Day := Day_Number'Value (Date (Date'First + 8 .. Date'First + 9));
-- ISO8601 date: YYYY-MM-DDTHH
if Date'Length > 12 then
if Date (Date'First + 10) /= 'T' then
raise Constraint_Error with "invalid date";
end if;
Result.Hour := Hour_Number'Value (Date (Date'First + 11 .. Date'First + 12));
Pos := Date'First + 13;
end if;
if Date'Length > 15 then
if Date (Date'First + 13) /= ':' then
raise Constraint_Error with "invalid date";
end if;
Result.Minute := Minute_Number'Value (Date (Date'First + 14 .. Date'First + 15));
Pos := Date'First + 16;
end if;
if Date'Length > 18 then
if Date (Date'First + 16) /= ':' then
raise Constraint_Error with "invalid date";
end if;
Result.Second := Second_Number'Value (Date (Date'First + 17 .. Date'First + 18));
Pos := Date'First + 19;
end if;
-- ISO8601 timezone: +hh:mm or -hh:mm
-- if Date'Length > Pos + 4 then
-- if Date (Pos) /= '+' and Date (Pos) /= '-' and Date (Pos + 2) /= ':' then
-- raise Constraint_Error with "invalid date";
-- end if;
-- end if;
else
raise Constraint_Error with "invalid date";
end if;
return Ada.Calendar.Formatting.Time_Of (Year => Result.Year,
Month => Result.Month,
Day => Result.Month_Day,
Hour => Result.Hour,
Minute => Result.Minute,
Second => Result.Second,
Sub_Second => Result.Sub_Second,
Time_Zone => Result.Time_Zone);
end Value;
-- ------------------------------
-- Return the ISO8601 date.
-- ------------------------------
function Image (Date : in Ada.Calendar.Time) return String is
D : Date_Record;
begin
Split (D, Date);
return Image (D);
end Image;
function Image (Date : in Date_Record) return String is
To_Char : constant array (0 .. 9) of Character := "0123456789";
Result : String (1 .. 10) := "0000-00-00";
begin
Result (1) := To_Char (Date.Year / 1000);
Result (2) := To_Char (Date.Year / 100 mod 10);
Result (3) := To_Char (Date.Year / 10 mod 10);
Result (4) := To_Char (Date.Year mod 10);
Result (6) := To_Char (Date.Month / 10);
Result (7) := To_Char (Date.Month mod 10);
Result (9) := To_Char (Date.Month_Day / 10);
Result (10) := To_Char (Date.Month_Day mod 10);
return Result;
end Image;
function Image (Date : in Ada.Calendar.Time;
Precision : in Precision_Type) return String is
D : Date_Record;
begin
Split (D, Date);
return Image (D, Precision);
end Image;
function Image (Date : in Date_Record;
Precision : in Precision_Type) return String is
use type Ada.Calendar.Time_Zones.Time_Offset;
To_Char : constant array (0 .. 9) of Character := "0123456789";
Result : String (1 .. 29) := "0000-00-00T00:00:00.000-00:00";
N, Tz : Natural;
begin
Result (1) := To_Char (Date.Year / 1000);
Result (2) := To_Char (Date.Year / 100 mod 10);
Result (3) := To_Char (Date.Year / 10 mod 10);
Result (4) := To_Char (Date.Year mod 10);
if Precision = YEAR then
return Result (1 .. 4);
end if;
Result (6) := To_Char (Date.Month / 10);
Result (7) := To_Char (Date.Month mod 10);
if Precision = MONTH then
return Result (1 .. 7);
end if;
Result (9) := To_Char (Date.Month_Day / 10);
Result (10) := To_Char (Date.Month_Day mod 10);
if Precision = DAY then
return Result (1 .. 10);
end if;
Result (12) := To_Char (Date.Hour / 10);
Result (13) := To_Char (Date.Hour mod 10);
if Precision = HOUR then
return Result (1 .. 13);
end if;
Result (15) := To_Char (Date.Minute / 10);
Result (16) := To_Char (Date.Minute mod 10);
if Precision = MINUTE then
return Result (1 .. 16);
end if;
Result (18) := To_Char (Date.Second / 10);
Result (19) := To_Char (Date.Second mod 10);
if Precision = SECOND then
return Result (1 .. 19);
end if;
N := Natural (Date.Sub_Second * 1000.0);
Result (21) := To_Char (N / 100);
Result (22) := To_Char ((N mod 100) / 10);
Result (23) := To_Char (N mod 10);
if Date.Time_Zone < 0 then
Tz := Natural (-Date.Time_Zone);
else
Result (24) := '+';
Tz := Natural (Date.Time_Zone);
end if;
Result (25) := To_Char (Tz / 600);
Result (26) := To_Char ((Tz / 60) mod 10);
Tz := Tz mod 60;
Result (28) := To_Char (Tz / 10);
Result (29) := To_Char (Tz mod 10);
return Result;
end Image;
end Util.Dates.ISO8601;
|
reznikmm/matreshka | Ada | 6,781 | adb | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Open Document Toolkit --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2014, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
with Matreshka.DOM_Documents;
with Matreshka.ODF_String_Constants;
with ODF.DOM.Iterators;
with ODF.DOM.Visitors;
package body Matreshka.ODF_Table.Table_Elements is
------------
-- Create --
------------
overriding function Create
(Parameters : not null access Matreshka.DOM_Elements.Element_L2_Parameters)
return Table_Table_Element_Node is
begin
return Self : Table_Table_Element_Node do
Matreshka.ODF_Table.Constructors.Initialize
(Self'Unchecked_Access,
Parameters.Document,
Matreshka.ODF_String_Constants.Table_Prefix);
end return;
end Create;
----------------
-- Enter_Node --
----------------
overriding procedure Enter_Node
(Self : not null access Table_Table_Element_Node;
Visitor : in out XML.DOM.Visitors.Abstract_Visitor'Class;
Control : in out XML.DOM.Visitors.Traverse_Control) is
begin
if Visitor in ODF.DOM.Visitors.Abstract_ODF_Visitor'Class then
ODF.DOM.Visitors.Abstract_ODF_Visitor'Class
(Visitor).Enter_Table_Table
(ODF.DOM.Table_Table_Elements.ODF_Table_Table_Access
(Self),
Control);
else
Matreshka.DOM_Elements.Abstract_Element_Node
(Self.all).Enter_Node (Visitor, Control);
end if;
end Enter_Node;
--------------------
-- Get_Local_Name --
--------------------
overriding function Get_Local_Name
(Self : not null access constant Table_Table_Element_Node)
return League.Strings.Universal_String
is
pragma Unreferenced (Self);
begin
return Matreshka.ODF_String_Constants.Table_Element;
end Get_Local_Name;
----------------
-- Leave_Node --
----------------
overriding procedure Leave_Node
(Self : not null access Table_Table_Element_Node;
Visitor : in out XML.DOM.Visitors.Abstract_Visitor'Class;
Control : in out XML.DOM.Visitors.Traverse_Control) is
begin
if Visitor in ODF.DOM.Visitors.Abstract_ODF_Visitor'Class then
ODF.DOM.Visitors.Abstract_ODF_Visitor'Class
(Visitor).Leave_Table_Table
(ODF.DOM.Table_Table_Elements.ODF_Table_Table_Access
(Self),
Control);
else
Matreshka.DOM_Elements.Abstract_Element_Node
(Self.all).Leave_Node (Visitor, Control);
end if;
end Leave_Node;
----------------
-- Visit_Node --
----------------
overriding procedure Visit_Node
(Self : not null access Table_Table_Element_Node;
Iterator : in out XML.DOM.Visitors.Abstract_Iterator'Class;
Visitor : in out XML.DOM.Visitors.Abstract_Visitor'Class;
Control : in out XML.DOM.Visitors.Traverse_Control) is
begin
if Iterator in ODF.DOM.Iterators.Abstract_ODF_Iterator'Class then
ODF.DOM.Iterators.Abstract_ODF_Iterator'Class
(Iterator).Visit_Table_Table
(Visitor,
ODF.DOM.Table_Table_Elements.ODF_Table_Table_Access
(Self),
Control);
else
Matreshka.DOM_Elements.Abstract_Element_Node
(Self.all).Visit_Node (Iterator, Visitor, Control);
end if;
end Visit_Node;
begin
Matreshka.DOM_Documents.Register_Element
(Matreshka.ODF_String_Constants.Table_URI,
Matreshka.ODF_String_Constants.Table_Element,
Table_Table_Element_Node'Tag);
end Matreshka.ODF_Table.Table_Elements;
|
shintakezou/drake | Ada | 14,637 | adb | with System.Address_To_Constant_Access_Conversions;
with System.Address_To_Named_Access_Conversions;
with System.Storage_Elements;
package body Interfaces.C.Generic_Strings is
use type Pointers.Constant_Pointer;
use type Pointers.Pointer;
use type System.Storage_Elements.Storage_Offset;
package libc is
function malloc (size : size_t) return chars_ptr
with Import,
Convention => Intrinsic, External_Name => "__builtin_malloc";
procedure free (ptr : chars_ptr)
with Import,
Convention => Intrinsic, External_Name => "__builtin_free";
end libc;
package chars_ptr_Conv is
new System.Address_To_Named_Access_Conversions (Element, chars_ptr);
package const_chars_ptr_Conv is
new System.Address_To_Constant_Access_Conversions (
Element,
const_chars_ptr);
-- implementation
function To_Chars_Ptr (
Item : access Element_Array;
Nul_Check : Boolean := False)
return chars_ptr is
begin
if Item = null then
return null;
else
if Nul_Check then
-- raise Terminator_Error when Item contains no nul
if Element'Size = char'Size
and then Element_Array'Component_Size =
char_array'Component_Size
-- 'Scalar_Storage_Order is unrelated since searching 0
then
declare
Source : char_array (Item'Range);
for Source'Address use Item.all'Address;
Dummy : size_t;
begin
Dummy := Length (Source);
end;
elsif Element'Size = wchar_t'Size
and then Element_Array'Component_Size =
wchar_array'Component_Size
then
declare
Source : wchar_array (Item'Range);
for Source'Address use Item.all'Address;
Dummy : size_t;
begin
Dummy := Length (Source);
end;
else
declare
I : size_t := Item'First;
begin
if I > Item'Last then
raise Terminator_Error; -- Item'Length = 0
end if;
loop
exit when Item (I) = Element'Val (0);
if I >= Item'Last then
raise Terminator_Error;
end if;
I := I + 1;
end loop;
end;
end if;
end if;
return chars_ptr_Conv.To_Pointer (Item.all'Address);
end if;
end To_Chars_Ptr;
function To_Const_Chars_Ptr (Item : not null access constant Element_Array)
return not null const_chars_ptr is
begin
return const_chars_ptr_Conv.To_Pointer (Item.all'Address);
end To_Const_Chars_Ptr;
function New_Char_Array (Chars : Element_Array)
return not null chars_ptr is
begin
return New_Chars_Ptr (
const_chars_ptr_Conv.To_Pointer (Chars'Address),
Chars'Length); -- CXB3009, accept non-nul terminated
end New_Char_Array;
function New_String (
Str : String_Type;
Substitute : Element_Array :=
(0 => Element'Val (Character'Pos ('?'))))
return not null chars_ptr
is
C : constant Element_Array :=
To_C (Str, Append_Nul => True, Substitute => Substitute);
begin
return New_Chars_Ptr (
const_chars_ptr_Conv.To_Pointer (C'Address),
C'Length - 1);
end New_String;
function New_Chars_Ptr (Length : size_t) return not null chars_ptr is
Size : constant System.Storage_Elements.Storage_Count :=
(System.Storage_Elements.Storage_Offset (Length) + 1) -- appending nul
* (Element_Array'Component_Size / Standard'Storage_Unit);
Result : constant chars_ptr := libc.malloc (C.size_t (Size));
begin
if Result = null then
raise Storage_Error;
end if;
Result.all := Element'Val (0);
return Result;
end New_Chars_Ptr;
function New_Chars_Ptr (
Item : not null access constant Element;
Length : size_t)
return not null chars_ptr
is
Result : constant chars_ptr := New_Chars_Ptr (Length);
begin
Pointers.Copy_Array (
Source => Item,
Target => Result,
Length => ptrdiff_t (Length));
chars_ptr'(Result + ptrdiff_t (Length)).all := Element'Val (0);
return Result;
end New_Chars_Ptr;
function New_Chars_Ptr (Item : not null access constant Element)
return not null chars_ptr is
begin
return New_Chars_Ptr (Item, Strlen (Item));
end New_Chars_Ptr;
function New_Strcat (Items : const_chars_ptr_array)
return not null chars_ptr
is
Lengths : array (Items'Range) of size_t;
Total_Length : size_t;
begin
-- get length
Total_Length := 1; -- appending nul
for I in Items'Range loop
Lengths (I) := Strlen (Items (I));
Total_Length := Total_Length + Lengths (I);
end loop;
declare
-- allocate
Result : constant chars_ptr := New_Chars_Ptr (Total_Length);
P : chars_ptr := Result;
begin
-- copy
for I in Items'Range loop
Pointers.Copy_Array (Items (I), P, ptrdiff_t (Lengths (I)));
P := P + ptrdiff_t (Lengths (I));
end loop;
P.all := Element'Val (0);
return Result;
end;
end New_Strcat;
function New_Strcat (Items : const_chars_ptr_With_Length_array)
return not null chars_ptr
is
Total_Length : size_t;
begin
-- get length
Total_Length := 1; -- appending nul
for I in Items'Range loop
Total_Length := Total_Length + Items (I).Length;
end loop;
declare
-- allocate
Result : constant chars_ptr := New_Chars_Ptr (Total_Length);
P : chars_ptr := Result;
begin
-- copy
for I in Items'Range loop
declare
E : const_chars_ptr_With_Length renames Items (I);
begin
Pointers.Copy_Array (E.ptr, P, ptrdiff_t (E.Length));
P := P + ptrdiff_t (E.Length);
end;
end loop;
P.all := Element'Val (0);
return Result;
end;
end New_Strcat;
procedure Free (Item : in out chars_ptr) is
begin
libc.free (Item);
Item := null;
end Free;
function Value (
Item : access constant Element)
return Element_Array
is
Length : constant size_t := Strlen (Item); -- checking Dereference_Error
begin
return Pointers.Value (
Item,
ptrdiff_t (Length + 1)); -- CXB3009, including nul
end Value;
function Value (
Item : access constant Element;
Length : size_t;
Append_Nul : Boolean := False)
return Element_Array
is
pragma Check (Pre,
Check =>
Standard."/=" (Item, null) -- operator for anonymous access
or else Length = 0
or else raise Dereference_Error); -- CXB3010
Actual_Length : size_t;
begin
if not Append_Nul and then Length = 0 then
raise Constraint_Error; -- CXB3010
end if;
if Standard."=" (Item, null) then -- operator for anonymous access
Actual_Length := 0;
else
Actual_Length := Strlen (Item, Limit => Length) + 1; -- including nul
end if;
if Append_Nul and then Length < Actual_Length then
if Length = 0 then
return (0 => Element'Val (0));
else
declare
Source : Element_Array (0 .. Actual_Length - 1);
for Source'Address use const_chars_ptr_Conv.To_Address (Item);
begin
return Source (0 .. Length - 1) & Element'Val (0);
end;
end if;
else
return Pointers.Value (
Item,
ptrdiff_t (size_t'Min (Actual_Length, Length)));
-- CXB3010, not appending nul
end if;
end Value;
function Value (
Item : access constant Element;
Substitute : String_Type :=
(1 => Character_Type'Val (Character'Pos ('?'))))
return String_Type
is
Actual_Length : constant size_t := Strlen (Item); -- checking
First : size_t;
Last : size_t;
begin
if Actual_Length = 0 then
First := 1;
Last := 0;
else
First := 0;
Last := Actual_Length - 1;
end if;
declare
Source : Element_Array (First .. Last);
for Source'Address use const_chars_ptr_Conv.To_Address (Item);
begin
return To_Ada (Source, Trim_Nul => False, Substitute => Substitute);
end;
end Value;
function Value (
Item : access constant Element;
Length : size_t;
Substitute : String_Type :=
(1 => Character_Type'Val (Character'Pos ('?'))))
return String_Type
is
pragma Check (Dynamic_Predicate,
Check =>
Standard."/=" (Item, null) -- operator for anonymous access
or else raise Dereference_Error); -- CXB3011
Actual_Length : constant size_t := Strlen (Item, Limit => Length);
First : size_t;
Last : size_t;
begin
if Actual_Length = 0 then
First := 1;
Last := 0;
else
First := 0;
Last := Actual_Length - 1;
end if;
declare
Source : Element_Array (First .. Last);
for Source'Address use const_chars_ptr_Conv.To_Address (Item);
begin
return To_Ada (Source, Trim_Nul => False, Substitute => Substitute);
end;
end Value;
function Strlen (
Item : access constant Element)
return size_t
is
pragma Check (Dynamic_Predicate,
Check =>
Standard."/=" (Item, null) -- operator for anonymous access
or else raise Dereference_Error); -- CXB3011
begin
if Element'Size = char'Size
and then Element_Array'Component_Size = char_array'Component_Size
-- 'Scalar_Storage_Order is unrelated since searching 0
then
declare
function strlen (s : not null access constant Element)
return size_t
with Import,
Convention => Intrinsic, External_Name => "__builtin_strlen";
begin
return strlen (Item);
end;
elsif Element'Size = wchar_t'Size
and then Element_Array'Component_Size = wchar_array'Component_Size
then
declare
function wcslen (s : not null access constant Element)
return size_t
with Import, Convention => C;
begin
return wcslen (Item);
end;
else
declare
S : not null const_chars_ptr := Item;
Length : size_t := 0;
begin
while S.all /= Element'Val (0) loop
Length := Length + 1;
S := S + ptrdiff_t'(1);
end loop;
return Length;
end;
end if;
end Strlen;
function Strlen (Item : not null access constant Element; Limit : size_t)
return size_t
is
Result : size_t;
begin
if Element'Size = char'Size
and then Element_Array'Component_Size = char_array'Component_Size
then
declare
function memchr (
s : not null access constant Element;
c : int;
n : size_t)
return const_chars_ptr
with Import,
Convention => Intrinsic, External_Name => "__builtin_memchr";
P : constant const_chars_ptr := memchr (Item, 0, Limit);
begin
if P = null then
Result := Limit;
else
Result := size_t (P - Item);
end if;
end;
elsif Element'Size = wchar_t'Size
and then Element_Array'Component_Size = wchar_array'Component_Size
then
declare
function wmemchr (
ws : not null access constant Element;
wc : int;
n : size_t)
return const_chars_ptr
with Import, Convention => C;
P : constant const_chars_ptr := wmemchr (Item, 0, Limit);
begin
if P = null then
Result := Limit;
else
Result := size_t (P - Item);
end if;
end;
else
declare
Source : Element_Array (0 .. Limit - 1);
for Source'Address use const_chars_ptr_Conv.To_Address (Item);
begin
Result := 0;
while Result < Limit
and then Source (Result) /= Element'Val (0)
loop
Result := Result + 1;
end loop;
end;
end if;
return Result;
end Strlen;
procedure Update (
Item : access Element;
Offset : size_t;
Chars : Element_Array;
Check : Boolean := True)
is
pragma Check (Dynamic_Predicate,
Check =>
Standard."/=" (Item, null) -- operator for anonymous access
or else raise Dereference_Error); -- CXB3011
Chars_Length : constant C.size_t := Chars'Length;
begin
if Check and then Offset + Chars_Length > Strlen (Item) then
raise Update_Error;
end if;
declare
Target : constant not null chars_ptr := Item;
begin
Pointers.Copy_Array (
Source => chars_ptr_Conv.To_Pointer (Chars'Address),
Target => Target + ptrdiff_t (Offset),
Length => ptrdiff_t (Chars_Length));
end;
end Update;
procedure Update (
Item : access Element;
Offset : size_t;
Str : String_Type;
Check : Boolean := True;
Substitute : Element_Array :=
(0 => Element'Val (Character'Pos ('?'))))
is
Chars : constant Element_Array :=
To_C (Str, Append_Nul => True, Substitute => Substitute);
First, Last : C.size_t;
begin
if Chars'First >= Chars'Last then -- Chars'Length <= 1
First := Chars'First + 1;
Last := Chars'First;
else
First := Chars'First;
Last := Chars'Last - 1;
end if;
Update (
Item, -- checking Dereference_Error
Offset,
Chars (First .. Last),
Check);
end Update;
end Interfaces.C.Generic_Strings;
|
reznikmm/gela | Ada | 975 | ads | with Gela.Semantic_Types;
package Gela.Int.Expressions is
pragma Preelaborate;
type Expression is new Interpretation with private;
function Create
(Down : Gela.Interpretations.Interpretation_Index_Array;
Expression_Type : Gela.Semantic_Types.Type_View_Index;
Expression_Kind : Gela.Interpretations.Unknown_Auxiliary_Apply_Kinds)
return Expression;
function Expression_Type
(Self : Expression)
return Gela.Semantic_Types.Type_View_Index;
function Expression_Kind
(Self : Expression)
return Gela.Interpretations.Unknown_Auxiliary_Apply_Kinds;
private
type Expression is new Interpretation with record
Expression_Type : Gela.Semantic_Types.Type_View_Index;
Expression_Kind : Gela.Interpretations.Unknown_Auxiliary_Apply_Kinds;
end record;
overriding procedure Visit
(Self : Expression;
Visiter : access Gela.Int.Visiters.Visiter'Class);
end Gela.Int.Expressions;
|
Tim-Tom/project-euler | Ada | 1,829 | adb | with Ada.Integer_Text_IO;
with Ada.Text_IO;
package body Problem_18 is
package IO renames Ada.Text_IO;
package I_IO renames Ada.Integer_Text_IO;
procedure Solve is
num_rows : constant Positive := 15;
cache : Array (1 .. num_rows) of Natural;
input : IO.File_Type;
begin
for item in cache'Range loop
cache(item) := 0;
end loop;
IO.Open(input, IO.In_File, "input/Problem_18.txt");
for row in 1 .. num_rows loop
declare
current_row : Array (1 .. row) of Natural;
begin
-- Read in line
for column in 1 .. row loop
I_IO.Get(input, current_row(column), 0);
end loop;
-- If we go backwards through the row, it allows us to perform the
-- replacement in memory instead of requiring a backup copy of the
-- cache.
for column in reverse 1 .. row loop
declare
max : Natural := 0;
from_right : constant Natural := cache(column) + current_row(column);
begin
-- coming from left
if column > 1 then
max := cache(column - 1) + current_row(column);
end if;
-- coming from right
if from_right > max then
max := from_right;
end if;
cache(column) := max;
end;
end loop;
end;
end loop;
declare
max : Natural := 0;
begin
for item in cache'Range loop
if cache(item) > max then
max := cache(item);
end if;
end loop;
I_IO.Put(max);
IO.New_Line;
end;
end Solve;
end Problem_18;
|
reznikmm/spawn | Ada | 2,256 | adb | --
-- Copyright (C) 2018-2023, AdaCore
--
-- SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
--
-- Try to spawn a not executable file
with Ada.Command_Line;
with Ada.Text_IO;
with Spawn.Processes.Monitor_Loop;
procedure Spawn_Bad_Exe is
package Listeners is
type Listener is limited new Spawn.Processes.Process_Listener with record
Proc : Spawn.Processes.Process;
Error : Integer := 0;
Wrong : Boolean := False; -- Set in Started/Finished
end record;
overriding procedure Error_Occurred
(Self : in out Listener;
Process_Error : Integer);
overriding procedure Started (Self : in out Listener);
overriding procedure Finished
(Self : in out Listener;
Exit_Status : Spawn.Process_Exit_Status;
Exit_Code : Spawn.Process_Exit_Code);
end Listeners;
package body Listeners is
overriding procedure Error_Occurred
(Self : in out Listener;
Process_Error : Integer) is
begin
Self.Error := Process_Error;
end Error_Occurred;
overriding procedure Started (Self : in out Listener) is
begin
Ada.Text_IO.Put_Line ("Unexpected Started");
Self.Wrong := True;
end Started;
overriding procedure Finished
(Self : in out Listener;
Exit_Status : Spawn.Process_Exit_Status;
Exit_Code : Spawn.Process_Exit_Code) is
begin
Ada.Text_IO.Put_Line ("Unexpected Finished");
Self.Wrong := True;
end Finished;
end Listeners;
use all type Spawn.Process_Status;
Command : constant String :=
(if Ada.Command_Line.Argument_Count > 0
then Ada.Command_Line.Argument (1)
else ".");
List : array (1 .. 5) of aliased Listeners.Listener;
begin
for X of List loop
X.Proc.Set_Program (Command);
X.Proc.Set_Listener (X'Unchecked_Access);
X.Proc.Start;
end loop;
while (for some X of List => X.Proc.Status in Starting | Running) loop
Spawn.Processes.Monitor_Loop (0.001);
end loop;
if (for some X of List => X.Wrong or X.Error /= List (1).Error) then
raise Program_Error;
end if;
end Spawn_Bad_Exe;
|
msrLi/portingSources | Ada | 834 | adb | -- Copyright 2008-2014 Free Software Foundation, Inc.
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; either version 3 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
package body Pck is
procedure Do_Nothing (A : System.Address) is
begin
null;
end Do_Nothing;
end Pck;
|
pat-rogers/LmcpGen | Ada | 300 | adb | package body -<full_series_name_dots>-.Object is
procedure pack (this: in Object_Any; buf: in out ByteBuffer) is
begin
null;
end pack;
procedure unpack (this: in out Object_Any; buf: in out ByteBuffer) is
begin
null;
end unpack;
end -<full_series_name_dots>-.Object;
|
AdaCore/training_material | Ada | 1,159 | adb | with Swaps; use Swaps;
with Ada.Text_IO;
package body Sorts is
procedure Display_List (List : in Integer_List) is
package IO renames Ada.Text_IO;
procedure Put_String(S : String) renames Ada.Text_IO.Put;
begin
IO.Put ("(");
for I in List'First .. List'Last loop
if i /= List'First and then
List (I) < 0 then
Put_String (" ");
end if;
Ada.Text_IO.Put (Integer'Image (List (I)));
if I /= List'Last then
Ada.Text_IO.Put(",");
end if;
end loop;
Ada.Text_IO.Put (")");
Ada.Text_IO.New_Line;
end Display_List;
procedure Sort (List : in out Integer_List) is
Idx_Min : Integer;
begin
for Current_Idx in List'First .. List'Last - 1 loop
Idx_Min := Current_Idx;
for Scan_Idx in Current_Idx + 1 .. List'Last loop
if List (Scan_Idx) < List (Idx_Min) then
Idx_Min := Scan_Idx;
end if;
end loop;
if Current_Idx /= Idx_Min then
Swap (List (Current_Idx), List (Idx_Min));
end if;
end loop;
end Sort;
end Sorts;
|
jwarwick/aoc_2020 | Ada | 690 | ads | -- AOC 2020, Day 17
with Ada.Containers.Hashed_Sets;
use Ada.Containers;
package Day is
type Location is record
x : Integer := 0;
y : Integer := 0;
z : Integer := 0;
w : Integer := 0;
end record;
function location_hash(key : in Location) return Hash_Type;
package Grid_Set is new Ada.Containers.Hashed_Sets
(Element_Type => Location,
Hash => location_hash,
Equivalent_Elements => "=");
use Grid_Set;
function load_file(filename : in String) return Grid_Set.Set;
function active_count(g : in Grid_Set.Set; cycles : in Natural) return Natural;
function active_count_4d(g : in Grid_Set.Set; cycles : in Natural) return Natural;
end Day;
|
AdaCore/gpr | Ada | 5,381 | ads | --
-- Copyright (C) 2019-2023, AdaCore
--
-- SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
--
with Ada.Unchecked_Conversion;
with System;
-- This Vector implementation is taken from Gpr_Parser_Support-Vectors and
-- shares the same desired benefits. However it was also modified so as to
-- be able to extract the underlying array (see function `Internal_Array`),
-- which required changes in the allocation and deallocation routines to
-- account for the potential array bounds we may need to insert.
--
-- TODO: Put this implementation in a separate library? (GNATCOLL?)
generic
type Element_Type is private;
type Elements_Array is array (Positive range <>) of Element_Type;
package Gpr_Parser_AdaSAT.Vectors is
subtype Index_Type is Positive;
subtype Iteration_Index_Type is Natural;
-- Like Index_Type, but also covers zero, which is used to represent a
-- dummy last index value for empty vectors.
type Element_Access is not null access all Element_Type;
type Vector is tagged private
with Iterable =>
(First => First_Index,
Next => Next,
Has_Element => Has_Element,
Element => Get);
Empty_Vector : constant Vector;
function Is_Empty (Self : Vector) return Boolean
with Inline;
-- Return whether Self is an empty vector
procedure Append (Self : in out Vector; Element : Element_Type)
with Inline;
-- Appends Element to Self
procedure Reserve (Self : in out Vector; Capacity : Natural)
with Inline;
-- Make sure that Self has enough room to contain Capacity elements in
-- total.
function Get
(Self : Vector; Index : Iteration_Index_Type) return Element_Type
with Inline;
-- Get the element at Index
function Get_Access
(Self : Vector; Index : Iteration_Index_Type) return Element_Access
with Inline;
-- Get an access on element at Index
procedure Set (Self : in out Vector; Index : Index_Type; E : Element_Type)
with Inline;
-- Set the element at Index to E
procedure Destroy (Self : in out Vector)
with Inline;
-- Destroy this vector
procedure Clear (Self : in out Vector)
with Inline;
-- Remove every element in this vector.
-- NOTICE: this function does not actually free the memory of the vector!
function First_Element (Self : Vector) return Element_Type
with Inline;
-- Return the first element in this vector
function Last_Element (Self : Vector) return Element_Type
with Inline;
-- Return the last element in this vector
function Length (Self : Vector) return Natural
with Inline;
-- Return the Length of the vector, ie. the number of elements it contains
procedure Set_Length (Self : in out Vector; N : Natural)
with Inline;
-- Resize the given vector so that it holes N elements
procedure Swap_And_Remove (Self : in out Vector; I : Positive)
with Inline;
-- Remove the element at the given index. That index will now hold
-- the last element of the vector.
function Pop (Self : in out Vector) return Element_Type
with Inline;
-- Remove the last element and return it
function First_Index (Self : Vector) return Iteration_Index_Type
is (Index_Type'First)
with Inline;
-- Return the first index, only used for the Iterable aspect
function Last_Index (Self : Vector) return Iteration_Index_Type
is (First_Index (Self) + Length (Self) - 1)
with Inline;
-- Return the index of the last element in this vector or
-- First_Index (Self) - 1 if this vector is empty.
function Next
(Self : Vector; N : Iteration_Index_Type) return Iteration_Index_Type
is (N + 1)
with Inline;
-- Given a vector and an index, return the next index. Only used for the
-- iterable aspect.
function Previous
(Self : Vector; N : Iteration_Index_Type) return Iteration_Index_Type
is (N - 1)
with Inline;
-- Given a vector and an index, return the next index. Only used for the
-- iterable aspect.
function Has_Element
(Self : Vector; N : Iteration_Index_Type) return Boolean
is (N in First_Index (Self) .. Last_Index (Self))
with Inline;
-- Given a vector and an index, return True if the index is in the vector
-- range. Only used for the iterable aspect.
procedure Move (Target : in out Vector; Source : in out Vector)
with Inline;
-- Move the internal elements array of vector Source to vector Target.
-- Clear the source vector.
function Copy (Self : Vector) return Vector;
-- Return newly allocated copy of Self
generic
type User_Array_Access is access Elements_Array;
function Internal_Array (Self : Vector) return User_Array_Access
with Inline;
-- Return the internal array that the vector is working on.
private
subtype Internal_Elements_Array is Elements_Array (Index_Type);
type Elements_Array_Access is access all Internal_Elements_Array;
function To_Pointer is
new Ada.Unchecked_Conversion (System.Address, Elements_Array_Access);
type Vector is tagged record
E : Elements_Array_Access := null;
Size : Natural := 0;
Capacity : Natural := 0;
end record;
Empty_Vector : constant Vector := (E => null, Size => 0, Capacity => 0);
end Gpr_Parser_AdaSAT.Vectors;
|
persan/AUnit-addons | Ada | 93 | ads | with AUnit.Run.Generic_Runner;
procedure Suits.Main2 is new AUnit.Run.Generic_Runner (Suit);
|
reznikmm/matreshka | Ada | 4,717 | ads | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Open Document Toolkit --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2014, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
with XML.DOM.Visitors;
with ODF.DOM.Text_Index_Body_Elements;
package Matreshka.ODF_Text.Index_Body_Elements is
type Text_Index_Body_Element_Node is
new Matreshka.ODF_Text.Abstract_Text_Element_Node
and ODF.DOM.Text_Index_Body_Elements.ODF_Text_Index_Body
with null record;
overriding function Create
(Parameters : not null access Matreshka.DOM_Elements.Element_L2_Parameters)
return Text_Index_Body_Element_Node;
overriding function Get_Local_Name
(Self : not null access constant Text_Index_Body_Element_Node)
return League.Strings.Universal_String;
overriding procedure Enter_Node
(Self : not null access Text_Index_Body_Element_Node;
Visitor : in out XML.DOM.Visitors.Abstract_Visitor'Class;
Control : in out XML.DOM.Visitors.Traverse_Control);
overriding procedure Leave_Node
(Self : not null access Text_Index_Body_Element_Node;
Visitor : in out XML.DOM.Visitors.Abstract_Visitor'Class;
Control : in out XML.DOM.Visitors.Traverse_Control);
overriding procedure Visit_Node
(Self : not null access Text_Index_Body_Element_Node;
Iterator : in out XML.DOM.Visitors.Abstract_Iterator'Class;
Visitor : in out XML.DOM.Visitors.Abstract_Visitor'Class;
Control : in out XML.DOM.Visitors.Traverse_Control);
end Matreshka.ODF_Text.Index_Body_Elements;
|
docandrew/troodon | Ada | 17,031 | ads | pragma Ada_2012;
pragma Style_Checks (Off);
with Interfaces.C; use Interfaces.C;
with xcb;
with bits_stdint_uintn_h;
with xproto;
with xcb_xfixes;
with System;
package xcb_composite is
CONST_XCB_COMPOSITE_MAJOR_VERSION : constant := 0; -- /usr/include/xcb/composite.h:23
CONST_XCB_COMPOSITE_MINOR_VERSION : constant := 4; -- /usr/include/xcb/composite.h:24
CONST_XCB_COMPOSITE_QUERY_VERSION : constant := 0; -- /usr/include/xcb/composite.h:41
CONST_XCB_COMPOSITE_REDIRECT_WINDOW : constant := 1; -- /usr/include/xcb/composite.h:68
CONST_XCB_COMPOSITE_REDIRECT_SUBWINDOWS : constant := 2; -- /usr/include/xcb/composite.h:83
CONST_XCB_COMPOSITE_UNREDIRECT_WINDOW : constant := 3; -- /usr/include/xcb/composite.h:98
CONST_XCB_COMPOSITE_UNREDIRECT_SUBWINDOWS : constant := 4; -- /usr/include/xcb/composite.h:113
CONST_XCB_COMPOSITE_CREATE_REGION_FROM_BORDER_CLIP : constant := 5; -- /usr/include/xcb/composite.h:128
CONST_XCB_COMPOSITE_NAME_WINDOW_PIXMAP : constant := 6; -- /usr/include/xcb/composite.h:142
CONST_XCB_COMPOSITE_GET_OVERLAY_WINDOW : constant := 7; -- /usr/include/xcb/composite.h:163
CONST_XCB_COMPOSITE_RELEASE_OVERLAY_WINDOW : constant := 8; -- /usr/include/xcb/composite.h:188
xcb_composite_id : aliased xcb.xcb_extension_t -- /usr/include/xcb/composite.h:26
with Import => True,
Convention => C,
External_Name => "xcb_composite_id";
type xcb_composite_redirect_t is
(XCB_COMPOSITE_REDIRECT_AUTOMATIC,
XCB_COMPOSITE_REDIRECT_MANUAL)
with Convention => C; -- /usr/include/xcb/composite.h:28
type xcb_composite_query_version_cookie_t is record
sequence : aliased unsigned; -- /usr/include/xcb/composite.h:37
end record
with Convention => C_Pass_By_Copy; -- /usr/include/xcb/composite.h:36
type xcb_composite_query_version_request_t is record
major_opcode : aliased bits_stdint_uintn_h.uint8_t; -- /usr/include/xcb/composite.h:47
minor_opcode : aliased bits_stdint_uintn_h.uint8_t; -- /usr/include/xcb/composite.h:48
length : aliased bits_stdint_uintn_h.uint16_t; -- /usr/include/xcb/composite.h:49
client_major_version : aliased bits_stdint_uintn_h.uint32_t; -- /usr/include/xcb/composite.h:50
client_minor_version : aliased bits_stdint_uintn_h.uint32_t; -- /usr/include/xcb/composite.h:51
end record
with Convention => C_Pass_By_Copy; -- /usr/include/xcb/composite.h:46
type xcb_composite_query_version_reply_t_array4353 is array (0 .. 15) of aliased bits_stdint_uintn_h.uint8_t;
type xcb_composite_query_version_reply_t is record
response_type : aliased bits_stdint_uintn_h.uint8_t; -- /usr/include/xcb/composite.h:58
pad0 : aliased bits_stdint_uintn_h.uint8_t; -- /usr/include/xcb/composite.h:59
sequence : aliased bits_stdint_uintn_h.uint16_t; -- /usr/include/xcb/composite.h:60
length : aliased bits_stdint_uintn_h.uint32_t; -- /usr/include/xcb/composite.h:61
major_version : aliased bits_stdint_uintn_h.uint32_t; -- /usr/include/xcb/composite.h:62
minor_version : aliased bits_stdint_uintn_h.uint32_t; -- /usr/include/xcb/composite.h:63
pad1 : aliased xcb_composite_query_version_reply_t_array4353; -- /usr/include/xcb/composite.h:64
end record
with Convention => C_Pass_By_Copy; -- /usr/include/xcb/composite.h:57
type xcb_composite_redirect_window_request_t_array1897 is array (0 .. 2) of aliased bits_stdint_uintn_h.uint8_t;
type xcb_composite_redirect_window_request_t is record
major_opcode : aliased bits_stdint_uintn_h.uint8_t; -- /usr/include/xcb/composite.h:74
minor_opcode : aliased bits_stdint_uintn_h.uint8_t; -- /usr/include/xcb/composite.h:75
length : aliased bits_stdint_uintn_h.uint16_t; -- /usr/include/xcb/composite.h:76
window : aliased xproto.xcb_window_t; -- /usr/include/xcb/composite.h:77
update : aliased bits_stdint_uintn_h.uint8_t; -- /usr/include/xcb/composite.h:78
pad0 : aliased xcb_composite_redirect_window_request_t_array1897; -- /usr/include/xcb/composite.h:79
end record
with Convention => C_Pass_By_Copy; -- /usr/include/xcb/composite.h:73
type xcb_composite_redirect_subwindows_request_t_array1897 is array (0 .. 2) of aliased bits_stdint_uintn_h.uint8_t;
type xcb_composite_redirect_subwindows_request_t is record
major_opcode : aliased bits_stdint_uintn_h.uint8_t; -- /usr/include/xcb/composite.h:89
minor_opcode : aliased bits_stdint_uintn_h.uint8_t; -- /usr/include/xcb/composite.h:90
length : aliased bits_stdint_uintn_h.uint16_t; -- /usr/include/xcb/composite.h:91
window : aliased xproto.xcb_window_t; -- /usr/include/xcb/composite.h:92
update : aliased bits_stdint_uintn_h.uint8_t; -- /usr/include/xcb/composite.h:93
pad0 : aliased xcb_composite_redirect_subwindows_request_t_array1897; -- /usr/include/xcb/composite.h:94
end record
with Convention => C_Pass_By_Copy; -- /usr/include/xcb/composite.h:88
type xcb_composite_unredirect_window_request_t_array1897 is array (0 .. 2) of aliased bits_stdint_uintn_h.uint8_t;
type xcb_composite_unredirect_window_request_t is record
major_opcode : aliased bits_stdint_uintn_h.uint8_t; -- /usr/include/xcb/composite.h:104
minor_opcode : aliased bits_stdint_uintn_h.uint8_t; -- /usr/include/xcb/composite.h:105
length : aliased bits_stdint_uintn_h.uint16_t; -- /usr/include/xcb/composite.h:106
window : aliased xproto.xcb_window_t; -- /usr/include/xcb/composite.h:107
update : aliased bits_stdint_uintn_h.uint8_t; -- /usr/include/xcb/composite.h:108
pad0 : aliased xcb_composite_unredirect_window_request_t_array1897; -- /usr/include/xcb/composite.h:109
end record
with Convention => C_Pass_By_Copy; -- /usr/include/xcb/composite.h:103
type xcb_composite_unredirect_subwindows_request_t_array1897 is array (0 .. 2) of aliased bits_stdint_uintn_h.uint8_t;
type xcb_composite_unredirect_subwindows_request_t is record
major_opcode : aliased bits_stdint_uintn_h.uint8_t; -- /usr/include/xcb/composite.h:119
minor_opcode : aliased bits_stdint_uintn_h.uint8_t; -- /usr/include/xcb/composite.h:120
length : aliased bits_stdint_uintn_h.uint16_t; -- /usr/include/xcb/composite.h:121
window : aliased xproto.xcb_window_t; -- /usr/include/xcb/composite.h:122
update : aliased bits_stdint_uintn_h.uint8_t; -- /usr/include/xcb/composite.h:123
pad0 : aliased xcb_composite_unredirect_subwindows_request_t_array1897; -- /usr/include/xcb/composite.h:124
end record
with Convention => C_Pass_By_Copy; -- /usr/include/xcb/composite.h:118
type xcb_composite_create_region_from_border_clip_request_t is record
major_opcode : aliased bits_stdint_uintn_h.uint8_t; -- /usr/include/xcb/composite.h:134
minor_opcode : aliased bits_stdint_uintn_h.uint8_t; -- /usr/include/xcb/composite.h:135
length : aliased bits_stdint_uintn_h.uint16_t; -- /usr/include/xcb/composite.h:136
region : aliased xcb_xfixes.xcb_xfixes_region_t; -- /usr/include/xcb/composite.h:137
window : aliased xproto.xcb_window_t; -- /usr/include/xcb/composite.h:138
end record
with Convention => C_Pass_By_Copy; -- /usr/include/xcb/composite.h:133
type xcb_composite_name_window_pixmap_request_t is record
major_opcode : aliased bits_stdint_uintn_h.uint8_t; -- /usr/include/xcb/composite.h:148
minor_opcode : aliased bits_stdint_uintn_h.uint8_t; -- /usr/include/xcb/composite.h:149
length : aliased bits_stdint_uintn_h.uint16_t; -- /usr/include/xcb/composite.h:150
window : aliased xproto.xcb_window_t; -- /usr/include/xcb/composite.h:151
pixmap : aliased xproto.xcb_pixmap_t; -- /usr/include/xcb/composite.h:152
end record
with Convention => C_Pass_By_Copy; -- /usr/include/xcb/composite.h:147
type xcb_composite_get_overlay_window_cookie_t is record
sequence : aliased unsigned; -- /usr/include/xcb/composite.h:159
end record
with Convention => C_Pass_By_Copy; -- /usr/include/xcb/composite.h:158
type xcb_composite_get_overlay_window_request_t is record
major_opcode : aliased bits_stdint_uintn_h.uint8_t; -- /usr/include/xcb/composite.h:169
minor_opcode : aliased bits_stdint_uintn_h.uint8_t; -- /usr/include/xcb/composite.h:170
length : aliased bits_stdint_uintn_h.uint16_t; -- /usr/include/xcb/composite.h:171
window : aliased xproto.xcb_window_t; -- /usr/include/xcb/composite.h:172
end record
with Convention => C_Pass_By_Copy; -- /usr/include/xcb/composite.h:168
type xcb_composite_get_overlay_window_reply_t_array1992 is array (0 .. 19) of aliased bits_stdint_uintn_h.uint8_t;
type xcb_composite_get_overlay_window_reply_t is record
response_type : aliased bits_stdint_uintn_h.uint8_t; -- /usr/include/xcb/composite.h:179
pad0 : aliased bits_stdint_uintn_h.uint8_t; -- /usr/include/xcb/composite.h:180
sequence : aliased bits_stdint_uintn_h.uint16_t; -- /usr/include/xcb/composite.h:181
length : aliased bits_stdint_uintn_h.uint32_t; -- /usr/include/xcb/composite.h:182
overlay_win : aliased xproto.xcb_window_t; -- /usr/include/xcb/composite.h:183
pad1 : aliased xcb_composite_get_overlay_window_reply_t_array1992; -- /usr/include/xcb/composite.h:184
end record
with Convention => C_Pass_By_Copy; -- /usr/include/xcb/composite.h:178
type xcb_composite_release_overlay_window_request_t is record
major_opcode : aliased bits_stdint_uintn_h.uint8_t; -- /usr/include/xcb/composite.h:194
minor_opcode : aliased bits_stdint_uintn_h.uint8_t; -- /usr/include/xcb/composite.h:195
length : aliased bits_stdint_uintn_h.uint16_t; -- /usr/include/xcb/composite.h:196
window : aliased xproto.xcb_window_t; -- /usr/include/xcb/composite.h:197
end record
with Convention => C_Pass_By_Copy; -- /usr/include/xcb/composite.h:193
function xcb_composite_query_version
(c : access xcb.xcb_connection_t;
client_major_version : bits_stdint_uintn_h.uint32_t;
client_minor_version : bits_stdint_uintn_h.uint32_t) return xcb_composite_query_version_cookie_t -- /usr/include/xcb/composite.h:209
with Import => True,
Convention => C,
External_Name => "xcb_composite_query_version";
function xcb_composite_query_version_unchecked
(c : access xcb.xcb_connection_t;
client_major_version : bits_stdint_uintn_h.uint32_t;
client_minor_version : bits_stdint_uintn_h.uint32_t) return xcb_composite_query_version_cookie_t -- /usr/include/xcb/composite.h:225
with Import => True,
Convention => C,
External_Name => "xcb_composite_query_version_unchecked";
function xcb_composite_query_version_reply
(c : access xcb.xcb_connection_t;
cookie : xcb_composite_query_version_cookie_t;
e : System.Address) return access xcb_composite_query_version_reply_t -- /usr/include/xcb/composite.h:244
with Import => True,
Convention => C,
External_Name => "xcb_composite_query_version_reply";
function xcb_composite_redirect_window_checked
(c : access xcb.xcb_connection_t;
window : xproto.xcb_window_t;
update : bits_stdint_uintn_h.uint8_t) return xcb.xcb_void_cookie_t -- /usr/include/xcb/composite.h:260
with Import => True,
Convention => C,
External_Name => "xcb_composite_redirect_window_checked";
function xcb_composite_redirect_window
(c : access xcb.xcb_connection_t;
window : xproto.xcb_window_t;
update : bits_stdint_uintn_h.uint8_t) return xcb.xcb_void_cookie_t -- /usr/include/xcb/composite.h:273
with Import => True,
Convention => C,
External_Name => "xcb_composite_redirect_window";
function xcb_composite_redirect_subwindows_checked
(c : access xcb.xcb_connection_t;
window : xproto.xcb_window_t;
update : bits_stdint_uintn_h.uint8_t) return xcb.xcb_void_cookie_t -- /usr/include/xcb/composite.h:289
with Import => True,
Convention => C,
External_Name => "xcb_composite_redirect_subwindows_checked";
function xcb_composite_redirect_subwindows
(c : access xcb.xcb_connection_t;
window : xproto.xcb_window_t;
update : bits_stdint_uintn_h.uint8_t) return xcb.xcb_void_cookie_t -- /usr/include/xcb/composite.h:302
with Import => True,
Convention => C,
External_Name => "xcb_composite_redirect_subwindows";
function xcb_composite_unredirect_window_checked
(c : access xcb.xcb_connection_t;
window : xproto.xcb_window_t;
update : bits_stdint_uintn_h.uint8_t) return xcb.xcb_void_cookie_t -- /usr/include/xcb/composite.h:318
with Import => True,
Convention => C,
External_Name => "xcb_composite_unredirect_window_checked";
function xcb_composite_unredirect_window
(c : access xcb.xcb_connection_t;
window : xproto.xcb_window_t;
update : bits_stdint_uintn_h.uint8_t) return xcb.xcb_void_cookie_t -- /usr/include/xcb/composite.h:331
with Import => True,
Convention => C,
External_Name => "xcb_composite_unredirect_window";
function xcb_composite_unredirect_subwindows_checked
(c : access xcb.xcb_connection_t;
window : xproto.xcb_window_t;
update : bits_stdint_uintn_h.uint8_t) return xcb.xcb_void_cookie_t -- /usr/include/xcb/composite.h:347
with Import => True,
Convention => C,
External_Name => "xcb_composite_unredirect_subwindows_checked";
function xcb_composite_unredirect_subwindows
(c : access xcb.xcb_connection_t;
window : xproto.xcb_window_t;
update : bits_stdint_uintn_h.uint8_t) return xcb.xcb_void_cookie_t -- /usr/include/xcb/composite.h:360
with Import => True,
Convention => C,
External_Name => "xcb_composite_unredirect_subwindows";
function xcb_composite_create_region_from_border_clip_checked
(c : access xcb.xcb_connection_t;
region : xcb_xfixes.xcb_xfixes_region_t;
window : xproto.xcb_window_t) return xcb.xcb_void_cookie_t -- /usr/include/xcb/composite.h:376
with Import => True,
Convention => C,
External_Name => "xcb_composite_create_region_from_border_clip_checked";
function xcb_composite_create_region_from_border_clip
(c : access xcb.xcb_connection_t;
region : xcb_xfixes.xcb_xfixes_region_t;
window : xproto.xcb_window_t) return xcb.xcb_void_cookie_t -- /usr/include/xcb/composite.h:389
with Import => True,
Convention => C,
External_Name => "xcb_composite_create_region_from_border_clip";
function xcb_composite_name_window_pixmap_checked
(c : access xcb.xcb_connection_t;
window : xproto.xcb_window_t;
pixmap : xproto.xcb_pixmap_t) return xcb.xcb_void_cookie_t -- /usr/include/xcb/composite.h:405
with Import => True,
Convention => C,
External_Name => "xcb_composite_name_window_pixmap_checked";
function xcb_composite_name_window_pixmap
(c : access xcb.xcb_connection_t;
window : xproto.xcb_window_t;
pixmap : xproto.xcb_pixmap_t) return xcb.xcb_void_cookie_t -- /usr/include/xcb/composite.h:418
with Import => True,
Convention => C,
External_Name => "xcb_composite_name_window_pixmap";
function xcb_composite_get_overlay_window (c : access xcb.xcb_connection_t; window : xproto.xcb_window_t) return xcb_composite_get_overlay_window_cookie_t -- /usr/include/xcb/composite.h:431
with Import => True,
Convention => C,
External_Name => "xcb_composite_get_overlay_window";
function xcb_composite_get_overlay_window_unchecked (c : access xcb.xcb_connection_t; window : xproto.xcb_window_t) return xcb_composite_get_overlay_window_cookie_t -- /usr/include/xcb/composite.h:446
with Import => True,
Convention => C,
External_Name => "xcb_composite_get_overlay_window_unchecked";
function xcb_composite_get_overlay_window_reply
(c : access xcb.xcb_connection_t;
cookie : xcb_composite_get_overlay_window_cookie_t;
e : System.Address) return access xcb_composite_get_overlay_window_reply_t -- /usr/include/xcb/composite.h:464
with Import => True,
Convention => C,
External_Name => "xcb_composite_get_overlay_window_reply";
function xcb_composite_release_overlay_window_checked (c : access xcb.xcb_connection_t; window : xproto.xcb_window_t) return xcb.xcb_void_cookie_t -- /usr/include/xcb/composite.h:480
with Import => True,
Convention => C,
External_Name => "xcb_composite_release_overlay_window_checked";
function xcb_composite_release_overlay_window (c : access xcb.xcb_connection_t; window : xproto.xcb_window_t) return xcb.xcb_void_cookie_t -- /usr/include/xcb/composite.h:492
with Import => True,
Convention => C,
External_Name => "xcb_composite_release_overlay_window";
end xcb_composite;
|
onox/orka | Ada | 1,364 | 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.
with Orka.OS;
with Orka.Types;
procedure Orka_7_Half is
use Orka;
Numbers : constant Float_32_Array
:= (0.0, 0.5, -0.5, 1.0, -1.0, 0.1, -0.1, 0.0, 0.1234, -0.123456,
10.1234, 20.1234, 50.1234, 100.1234, 1000.1234);
Half_Numbers : Float_16_Array (Numbers'Range);
Single_Numbers : Float_32_Array (Half_Numbers'Range);
begin
Orka.Types.Convert (Numbers, Half_Numbers);
Orka.Types.Convert (Half_Numbers, Single_Numbers);
for Number of Numbers loop
Orka.OS.Put_Line (Float_32'Image (Number));
end loop;
Orka.OS.Put_Line ("------------");
for Number of Single_Numbers loop
Orka.OS.Put_Line (Float_32'Image (Number));
end loop;
end Orka_7_Half;
|
reznikmm/matreshka | Ada | 4,567 | 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.Start_Attributes is
------------
-- Create --
------------
overriding function Create
(Parameters : not null access Matreshka.DOM_Attributes.Attribute_L2_Parameters)
return Draw_Start_Attribute_Node is
begin
return Self : Draw_Start_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_Start_Attribute_Node)
return League.Strings.Universal_String
is
pragma Unreferenced (Self);
begin
return Matreshka.ODF_String_Constants.Start_Attribute;
end Get_Local_Name;
begin
Matreshka.DOM_Documents.Register_Attribute
(Matreshka.ODF_String_Constants.Draw_URI,
Matreshka.ODF_String_Constants.Start_Attribute,
Draw_Start_Attribute_Node'Tag);
end Matreshka.ODF_Draw.Start_Attributes;
|
edin/raytracer | Ada | 2,193 | ads | --
-- Raytracer implementation in Ada
-- by John Perry (github: johnperry-math)
-- 2021
--
-- specification for Colors, both RGB ("Color_Type")
-- and RGBA ("Transparent_Color_Type")
--
-- local packages
with RayTracing_Constants; use RayTracing_Constants;
-- @summary
-- specification for Colors, both RGB ("Color_Type")
-- and RGBA ("Transparent_Color_Type")
package Colors is
type Color_Type is record
Blue, Green, Red: Float15;
end record;
-- RGB channels only; for transparency channel see Color_With_Transparency
White: constant Color_Type := ( 1.0, 1.0, 1.0 );
Grey: constant Color_Type := ( 0.5, 0.5, 0.5 );
Black: constant Color_Type := ( 0.0, 0.0, 0.0 );
Background: constant Color_Type := Black;
Default_Color: constant Color_Type := Black;
type Color_With_Transparency_Type is record
Blue, Green, Red, Alpha: UInt8;
end record;
-- R, G, B, and Alpha (transparency) channels
function Create_Color( Red, Green, Blue: Float15 ) return Color_Type;
function Scale( Color: Color_Type; K: Float15 ) return Color_Type;
-- scales Color by a factor of K, returns result
pragma Inline_Always(Scale);
procedure Scale_Self( Color: in out Color_Type; K: Float15 );
-- scales Color by a factor of K, modifies self
pragma Inline_Always(Scale);
function "*"(First, Second: Color_Type) return Color_Type;
-- componentwise product of First and Second, returns result
pragma Inline_Always("*");
procedure Color_Multiply_Self(First: in out Color_Type; Second: Color_Type);
pragma Inline_Always(Color_Multiply_Self);
function "+"(First, Second: Color_Type) return Color_Type;
-- returns sum of First and Second
pragma Inline_Always("+");
function Legalize(C: Float15) return UInt8;
-- modifies C, expected in the range 0.0 .. 1.0, to the range 0 .. 255,
-- with values less than 0.0 converted to 0, and values greater than 1.0
-- converted to 255
pragma Inline_Always(Legalize);
function To_Drawing_Color(C: Color_Type) return Color_With_Transparency_Type;
-- converts RGB to RGBA with A = 255
pragma Inline_Always(To_Drawing_Color);
end Colors;
|
stcarrez/ada-asf | Ada | 2,709 | ads | -----------------------------------------------------------------------
-- asf-events -- ASF Events
-- Copyright (C) 2010 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.Events;
-- with ASF.Lifecycles;
-- with ASF.Components.Base;
--
-- with Ada.Containers.Vectors;
-- The <b>ASF.Events</b> package defines the application events that an ASF
-- application can receive. Events are queued while processing the JSF phases
-- (See UIComponent.Queue_Event). They are dispatched after each phase
-- (See UIComponent.Broadcast).
--
-- This package is an Ada adaptation for the Java Server Faces Specification
-- JSR 314 - 3.4.2 Application Events.
package ASF.Events is
-- ------------------------------
-- Faces event
-- ------------------------------
-- The <b>Faces_Event</b> represents the root type for ASF events.
-- The event is associated with a component and a lifecycle phase after
-- which it will be processed.
-- type Faces_Event is new Util.Events.Event with private;
-- Get the lifecycle phase where the event must be processed.
-- function Get_Phase (Event : in Faces_Event) return ASF.Lifecycles.Phase_Type;
-- Set the lifecycle phase when this event must be processed.
-- procedure Set_Phase (Event : in out Faces_Event;
-- Phase : in ASF.Lifecycles.Phase_Type);
-- Get the component onto which the event was posted.
-- function Get_Component (Event : in Faces_Event) return Components.Base.UIComponent_Access;
-- private
--
-- type Faces_Event_Access is access all Faces_Event'Class;
--
-- package Event_Vectors is new Ada.Containers.Vectors (Index_Type => Natural,
-- Element_Type => Faces_Event_Access);
--
-- type Faces_Event is new Util.Events.Event with record
-- Phase : ASF.Lifecycles.Phase_Type := ASF.Lifecycles.RESTORE_VIEW;
-- Component : Components.Base.UIComponent_Access := null;
-- end record;
end ASF.Events;
|
luk9400/nsi | Ada | 662 | adb | package body Bubble with SPARK_Mode is
procedure Sort (A : in out Arr) is
Tmp : Integer;
begin
Outer: for I in reverse A'First .. A'Last - 1 loop
Inner: for J in A'First .. I loop
if A(J) > A(J + 1) then
Tmp := A(J);
A(J) := A(J + 1);
A(J + 1) := Tmp;
end if;
pragma Loop_Invariant (for all K1 in A'Range => (for some K2 in A'Range => A(K2) = A'Loop_Entry(Inner)(K1)));
end loop Inner;
pragma Loop_Invariant (for all K1 in A'Range => (for some K2 in A'Range => A(K2) = A'Loop_Entry(Outer)(K1)));
end loop Outer;
end Sort;
end Bubble;
|
stcarrez/ada-keystore | Ada | 1,304 | ads | -----------------------------------------------------------------------
-- akt-commands-list -- List content of keystore
-- Copyright (C) 2019 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 AKT.Commands.Drivers;
private package AKT.Commands.List is
type Command_Type is new AKT.Commands.Drivers.Command_Type with null record;
-- List the value entries of the keystore.
overriding
procedure Execute (Command : in out Command_Type;
Name : in String;
Args : in Argument_List'Class;
Context : in out Context_Type);
end AKT.Commands.List;
|
reznikmm/matreshka | Ada | 3,669 | 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.Xml_Id_Attributes is
pragma Preelaborate;
type ODF_Xml_Id_Attribute is limited interface
and XML.DOM.Attributes.DOM_Attribute;
type ODF_Xml_Id_Attribute_Access is
access all ODF_Xml_Id_Attribute'Class
with Storage_Size => 0;
end ODF.DOM.Xml_Id_Attributes;
|
zhmu/ananas | Ada | 186 | ads | with Inline20_G;
with Inline20_H;
package Inline20_R is
package My_G is new Inline20_G;
package My_H is new Inline20_H (My_G);
procedure Log (I : Integer);
end Inline20_R;
|
reznikmm/matreshka | Ada | 6,305 | adb | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Open Document Toolkit --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2013, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
with ODF.Constants;
with ODF.DOM.Elements.Style.Graphic_Properties.Internals;
with ODF.DOM.Iterators;
with ODF.DOM.Visitors;
package body Matreshka.ODF_Elements.Style.Graphic_Properties is
-------------------
-- Enter_Element --
-------------------
overriding procedure Enter_Element
(Self : not null access Style_Graphic_Properties_Node;
Visitor : in out XML.DOM.Visitors.Abstract_Visitor'Class;
Control : in out XML.DOM.Visitors.Traverse_Control) is
begin
if Visitor in ODF.DOM.Visitors.ODF_Visitor'Class then
ODF.DOM.Visitors.ODF_Visitor'Class
(Visitor).Enter_Style_Graphic_Properties
(ODF.DOM.Elements.Style.Graphic_Properties.Internals.Create
(Style_Graphic_Properties_Access (Self)),
Control);
else
Matreshka.DOM_Nodes.Elements.Abstract_Element
(Self.all).Enter_Element (Visitor, Control);
end if;
end Enter_Element;
--------------------
-- Get_Local_Name --
--------------------
overriding function Get_Local_Name
(Self : not null access constant Style_Graphic_Properties_Node)
return League.Strings.Universal_String is
begin
return ODF.Constants.Graphic_Properties_Name;
end Get_Local_Name;
-------------------
-- Leave_Element --
-------------------
overriding procedure Leave_Element
(Self : not null access Style_Graphic_Properties_Node;
Visitor : in out XML.DOM.Visitors.Abstract_Visitor'Class;
Control : in out XML.DOM.Visitors.Traverse_Control) is
begin
if Visitor in ODF.DOM.Visitors.ODF_Visitor'Class then
ODF.DOM.Visitors.ODF_Visitor'Class
(Visitor).Leave_Style_Graphic_Properties
(ODF.DOM.Elements.Style.Graphic_Properties.Internals.Create
(Style_Graphic_Properties_Access (Self)),
Control);
else
Matreshka.DOM_Nodes.Elements.Abstract_Element
(Self.all).Leave_Element (Visitor, Control);
end if;
end Leave_Element;
-------------------
-- Visit_Element --
-------------------
overriding procedure Visit_Element
(Self : not null access Style_Graphic_Properties_Node;
Iterator : in out XML.DOM.Visitors.Abstract_Iterator'Class;
Visitor : in out XML.DOM.Visitors.Abstract_Visitor'Class;
Control : in out XML.DOM.Visitors.Traverse_Control) is
begin
if Iterator in ODF.DOM.Iterators.ODF_Iterator'Class then
ODF.DOM.Iterators.ODF_Iterator'Class
(Iterator).Visit_Style_Graphic_Properties
(Visitor,
ODF.DOM.Elements.Style.Graphic_Properties.Internals.Create
(Style_Graphic_Properties_Access (Self)),
Control);
else
Matreshka.DOM_Nodes.Elements.Abstract_Element
(Self.all).Visit_Element (Iterator, Visitor, Control);
end if;
end Visit_Element;
end Matreshka.ODF_Elements.Style.Graphic_Properties;
|
reznikmm/gela | Ada | 2,444 | adb | ------------------------------------------------------------------------------
-- G E L A G R A M M A R S --
-- Library for dealing with tests for for Gela project, --
-- a portable Ada compiler --
-- http://gela.ada-ru.org/ --
-- - - - - - - - - - - - - - - - --
-- Read copyright and license in gela.ads file --
------------------------------------------------------------------------------
with Gela.Host;
package body Gela.Test_Cases.Runner is
------------
-- Create --
------------
function Create
(Command : League.Strings.Universal_String;
Arguments : League.String_Vectors.Universal_String_Vector;
Directory : League.Strings.Universal_String :=
League.Strings.Empty_Universal_String;
Info : Base.Base_Information := Base.No_Info)
return Test_Case
is
begin
return Result : Test_Case :=
(Base.Test_Case with
Command => Command,
Arguments => Arguments,
Directory => Directory,
Status => Error,
Output => <>,
Traceback => <>)
do
Result.Set_Information (Info);
end return;
end Create;
-------------
-- Execute --
-------------
overriding procedure Execute (Self : in out Test_Case) is
Code : Integer;
begin
Host.Execute
(Command => Self.Command,
Arguments => Self.Arguments,
Exit_Code => Code,
Output => Self.Output,
Directory => Self.Directory);
Self.Status := (if Code = 0 then Success else Failure);
end Execute;
------------
-- Status --
------------
overriding function Status (Self : Test_Case) return Status_Kind is
begin
return Self.Status;
end Status;
------------
-- Output --
------------
overriding function Output
(Self : Test_Case) return League.Strings.Universal_String is
begin
return Self.Output;
end Output;
---------------
-- Traceback --
---------------
overriding function Traceback
(Self : Test_Case) return League.Strings.Universal_String is
begin
return Self.Traceback;
end Traceback;
end Gela.Test_Cases.Runner;
|
charlie5/cBound | Ada | 1,626 | 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_poly_fill_rectangle_request_t is
-- Item
--
type Item is record
major_opcode : aliased Interfaces.Unsigned_8;
pad0 : aliased Interfaces.Unsigned_8;
length : aliased Interfaces.Unsigned_16;
drawable : aliased xcb.xcb_drawable_t;
gc : aliased xcb.xcb_gcontext_t;
end record;
-- Item_Array
--
type Item_Array is
array
(Interfaces.C
.size_t range <>) of aliased xcb.xcb_poly_fill_rectangle_request_t
.Item;
-- Pointer
--
package C_Pointers is new Interfaces.C.Pointers
(Index => Interfaces.C.size_t,
Element => xcb.xcb_poly_fill_rectangle_request_t.Item,
Element_Array => xcb.xcb_poly_fill_rectangle_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_poly_fill_rectangle_request_t
.Pointer;
-- Pointer_Pointer
--
package C_Pointer_Pointers is new Interfaces.C.Pointers
(Index => Interfaces.C.size_t,
Element => xcb.xcb_poly_fill_rectangle_request_t.Pointer,
Element_Array => xcb.xcb_poly_fill_rectangle_request_t.Pointer_Array,
Default_Terminator => null);
subtype Pointer_Pointer is C_Pointer_Pointers.Pointer;
end xcb.xcb_poly_fill_rectangle_request_t;
|
stcarrez/ada-ado | Ada | 1,581 | ads | -----------------------------------------------------------------------
-- regtests -- Support for unit tests
-- Copyright (C) 2009, 2010, 2017, 2018 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.Audits;
with ADO.Sessions;
with ADO.Sessions.Sources;
package Regtests is
-- Get the database manager to be used for the unit tests
function Get_Controller return ADO.Sessions.Sources.Data_Source'Class;
-- Get the readonly connection database to be used for the unit tests
function Get_Database return ADO.Sessions.Session;
-- Get the writeable connection database to be used for the unit tests
function Get_Master_Database return ADO.Sessions.Master_Session;
-- Set the audit manager on the factory.
procedure Set_Audit_Manager (Manager : in ADO.Audits.Audit_Manager_Access);
-- Initialize the test database
procedure Initialize (Name : in String);
end Regtests;
|
sbksba/Concurrence-LI330 | Ada | 223 | adb | with Ada.Text_IO, Matrice;
use Ada.Text_IO, Matrice;
procedure Test_saisie_affichage is
A : Une_Matrice_Entiere(1..10,1..10);
begin
Initialiser_Une_Matrice(A);
Afficher_Une_Matrice(A);
end Test_saisie_affichage;
|
VitalijBondarenko/Formatted_Output_NG | Ada | 3,757 | ads | ------------------------------------------------------------------------------
-- --
-- Copyright (c) 2016-2022 Vitalii Bondarenko <[email protected]> --
-- --
------------------------------------------------------------------------------
-- --
-- The MIT License (MIT) --
-- --
-- Permission is hereby granted, free of charge, to any person obtaining a --
-- copy of this software and associated documentation files (the --
-- "Software"), to deal in the Software without restriction, including --
-- without limitation the rights to use, copy, modify, merge, publish, --
-- distribute, sublicense, and/or sell copies of the Software, and to --
-- permit persons to whom the Software is furnished to do so, subject to --
-- the following conditions: --
-- --
-- The above copyright notice and this permission notice shall be included --
-- in all copies or substantial portions of the Software. --
-- --
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS --
-- OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF --
-- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. --
-- IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY --
-- CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, --
-- TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE --
-- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. --
------------------------------------------------------------------------------
generic
type Item_Type is delta <> digits <>;
package Formatted_Output.Decimal_Output is
function "&" (Fmt : Format_Type; Value : Item_Type'Base) return Format_Type;
-- Replaces leftmost formatting sequence in Fmt with formatted Value image,
-- then returns Fmt. Raises exception Format_Error when invalid formatting
-- sequence is found or no formatting sequence found at all.
--
-- Format sequences for decimal types:
--
-- %[flags][<width>[.<width_aft>]](f|g)
--
-- Flag characters can be:
-- - The converted value is to be left adjusted on the field boundary.
-- (The default is right justification.)
-- * The converted value is to be center adjusted on the field boundary.
-- (The default is right justification.)
-- + A sign (+ or -) should always be placed before a number produced by a
-- signed conversion. By default, a sign is used only for negative numbers.
-- 0 The value should be zero padded.
-- _ The output is to be grouped with grouping character '_'. Group size is 3.
-- ' The output is to be grouped with thousands' grouping characters if the
-- locale information indicates any.
--
-- <width> is decimal number specifying minimal field width.
--
-- <width_aft> is decimal number specifying number of digits after decimal point.
--
-- Format specifier can be:
-- f Convert to decimal notation in the style [-]ddd.ddd.
-- g Convert to shortest representation without any trailing zeroes.
end Formatted_Output.Decimal_Output;
|
AdaCore/gpr | Ada | 20 | ads | package I is
end I;
|
reznikmm/matreshka | Ada | 4,675 | 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.
------------------------------------------------------------------------------
-- A manifestation is the concrete physical rendering of one or more model
-- elements by an artifact.
------------------------------------------------------------------------------
with AMF.UML.Abstractions;
limited with AMF.UML.Packageable_Elements;
package AMF.UML.Manifestations is
pragma Preelaborate;
type UML_Manifestation is limited interface
and AMF.UML.Abstractions.UML_Abstraction;
type UML_Manifestation_Access is
access all UML_Manifestation'Class;
for UML_Manifestation_Access'Storage_Size use 0;
not overriding function Get_Utilized_Element
(Self : not null access constant UML_Manifestation)
return AMF.UML.Packageable_Elements.UML_Packageable_Element_Access is abstract;
-- Getter of Manifestation::utilizedElement.
--
-- The model element that is utilized in the manifestation in an Artifact.
not overriding procedure Set_Utilized_Element
(Self : not null access UML_Manifestation;
To : AMF.UML.Packageable_Elements.UML_Packageable_Element_Access) is abstract;
-- Setter of Manifestation::utilizedElement.
--
-- The model element that is utilized in the manifestation in an Artifact.
end AMF.UML.Manifestations;
|
reznikmm/matreshka | Ada | 3,764 | ads | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Open Document Toolkit --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2014, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
with XML.DOM.Attributes;
package ODF.DOM.Table_On_Update_Keep_Size_Attributes is
pragma Preelaborate;
type ODF_Table_On_Update_Keep_Size_Attribute is limited interface
and XML.DOM.Attributes.DOM_Attribute;
type ODF_Table_On_Update_Keep_Size_Attribute_Access is
access all ODF_Table_On_Update_Keep_Size_Attribute'Class
with Storage_Size => 0;
end ODF.DOM.Table_On_Update_Keep_Size_Attributes;
|
reznikmm/matreshka | Ada | 3,739 | ads | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Open Document Toolkit --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2014, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
with XML.DOM.Attributes;
package ODF.DOM.Style_Repeat_Content_Attributes is
pragma Preelaborate;
type ODF_Style_Repeat_Content_Attribute is limited interface
and XML.DOM.Attributes.DOM_Attribute;
type ODF_Style_Repeat_Content_Attribute_Access is
access all ODF_Style_Repeat_Content_Attribute'Class
with Storage_Size => 0;
end ODF.DOM.Style_Repeat_Content_Attributes;
|
zhmu/ananas | Ada | 6,232 | adb | ------------------------------------------------------------------------------
-- --
-- GNAT RUN-TIME COMPONENTS --
-- --
-- S Y S T E M . F O R E _ F --
-- --
-- B o d y --
-- --
-- Copyright (C) 2020-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. --
-- --
------------------------------------------------------------------------------
package body System.Fore_F is
Maxdigs : constant Natural := Int'Width - 2;
-- Maximum number of decimal digits that can be represented in an Int.
-- The "-2" accounts for the sign and one extra digit, since we need the
-- maximum number of 9's that can be represented, e.g. for the 64-bit case,
-- Integer_64'Width is 20 since the maximum value is approximately 9.2E+18
-- and has 19 digits, but the maximum number of 9's that can be represented
-- in Integer_64 is only 18.
-- The first prerequisite of the implementation is that the scaled divide
-- does not overflow, which means that the absolute value of the bounds of
-- the subtype must be smaller than 10**Maxdigs * 2**(Int'Size - 1).
-- Otherwise Constraint_Error is raised by the scaled divide operation.
-- The second prerequisite is that the computation of the operands does not
-- overflow, which means that, if the small is larger than 1, it is either
-- an integer or its numerator and denominator must be both smaller than
-- the power 10**(Maxdigs - 1).
----------------
-- Fore_Fixed --
----------------
function Fore_Fixed (Lo, Hi, Num, Den : Int; Scale : Integer) return Natural
is
pragma Assert (Num < 0 and then Den < 0);
-- Accept only negative numbers to allow -2**(Int'Size - 1)
function Negative_Abs (Val : Int) return Int is
(if Val <= 0 then Val else -Val);
-- Return the opposite of the absolute value of Val
T : Int := Int'Min (Negative_Abs (Lo), Negative_Abs (Hi));
F : Natural;
Q, R : Int;
begin
-- Initial value of 2 allows for sign and mandatory single digit
F := 2;
-- The easy case is when Num is not larger than Den in magnitude,
-- i.e. if S = Num / Den, then S <= 1, in which case we can just
-- compute the product Q = T * S.
if Num >= Den then
Scaled_Divide (T, Num, Den, Q, R, Round => False);
T := Q;
-- Otherwise S > 1 and thus Scale <= 0, compute Q and R such that
-- T * Num = Q * (Den * 10**(-D)) + R
-- with
-- D = Integer'Max (-Maxdigs, Scale - 1)
-- then reason on Q if it is non-zero or else on R / Den.
-- This works only if Den * 10**(-D) does not overflow, which is true
-- if Den = 1. Suppose that Num corresponds to the maximum value of -D,
-- i.e. Maxdigs and 10**(-D) = 10**Maxdigs. If you change Den into 10,
-- then S becomes 10 times smaller and, therefore, Scale is incremented
-- by 1, which means that -D is decremented by 1 provided that Scale was
-- initially not smaller than 1 - Maxdigs, so the multiplication still
-- does not overflow. But you need to reach 10 to trigger this effect,
-- which means that a leeway of 10 is required, so let's restrict this
-- to a Num for which 10**(-D) <= 10**(Maxdigs - 1). To sum up, if S is
-- the ratio of two integers with
-- 1 < Den < Num <= B
-- where B is a fixed limit, then the multiplication does not overflow.
-- B can be taken as the largest integer Small such that D = 1 - Maxdigs
-- i.e. such that Scale = 2 - Maxdigs, which is 10**(Maxdigs - 1) - 1.
else
declare
D : constant Integer := Integer'Max (-Maxdigs, Scale - 1);
begin
Scaled_Divide (T, Num, Den * 10**(-D), Q, R, Round => False);
if Q /= 0 then
T := Q;
F := F - D;
else
T := R / Den;
end if;
end;
end if;
-- Loop to increase Fore as needed to include full range of values
while T <= -10 or else T >= 10 loop
T := T / 10;
F := F + 1;
end loop;
return F;
end Fore_Fixed;
end System.Fore_F;
|
charlie5/cBound | Ada | 1,386 | ads | -- This file is generated by SWIG. Please do not modify by hand.
--
with Interfaces.C;
with Interfaces.C;
with Interfaces.C.Pointers;
package xcb.xcb_query_best_size_cookie_t is
-- Item
--
type Item is record
sequence : aliased Interfaces.C.unsigned;
end record;
-- Item_Array
--
type Item_Array is
array
(Interfaces.C
.size_t range <>) of aliased xcb.xcb_query_best_size_cookie_t
.Item;
-- Pointer
--
package C_Pointers is new Interfaces.C.Pointers
(Index => Interfaces.C.size_t,
Element => xcb.xcb_query_best_size_cookie_t.Item,
Element_Array => xcb.xcb_query_best_size_cookie_t.Item_Array,
Default_Terminator => (others => <>));
subtype Pointer is C_Pointers.Pointer;
-- Pointer_Array
--
type Pointer_Array is
array
(Interfaces.C
.size_t range <>) of aliased xcb.xcb_query_best_size_cookie_t
.Pointer;
-- Pointer_Pointer
--
package C_Pointer_Pointers is new Interfaces.C.Pointers
(Index => Interfaces.C.size_t,
Element => xcb.xcb_query_best_size_cookie_t.Pointer,
Element_Array => xcb.xcb_query_best_size_cookie_t.Pointer_Array,
Default_Terminator => null);
subtype Pointer_Pointer is C_Pointer_Pointers.Pointer;
end xcb.xcb_query_best_size_cookie_t;
|
jhumphry/SPARK_SipHash | Ada | 2,675 | adb | -- SipHash.Wide_Discrete
-- Implementing SipHash over a generic discrete type
-- Copyright (c) 2015, James Humphry - see LICENSE file for details
with Interfaces;
use all type Interfaces.Unsigned_64;
function SipHash.Wide_Discrete (m : T_Array) return Hash_Type is
subtype T_Array_4 is T_Array(T_Index'First..T_Index'First+3);
T_Offset : constant Integer := T'Pos(T'First);
function T_Array_4_to_U64_LE (S : in T_Array_4) return U64 with Inline;
function T_Array_Tail_to_U64_LE (S : in T_Array)
return U64
with Inline, Pre => (S'Length <= 3 and then S'Length > 0);
function T_Array_4_to_U64_LE (S : in T_Array_4) return U64 is
(U64(T'Pos(S(S'First)) - T_Offset)
or Shift_Left(U64(T'Pos(S(S'First+1)) - T_Offset), 16)
or Shift_Left(U64(T'Pos(S(S'First+2)) - T_Offset), 32)
or Shift_Left(U64(T'Pos(S(S'First+3)) - T_Offset), 48));
function T_Array_Tail_to_U64_LE (S : in T_Array)
return U64 is
R : U64 := 0;
Shift : Natural := 0;
T_I : T;
begin
for I in 0..S'Length-1 loop
pragma Loop_Invariant (Shift = I * 16);
T_I := S(S'First + T_Index'Base(I));
R := R or Shift_Left(U64(T'Pos(T_I) - T_Offset), Shift);
Shift := Shift + 16;
end loop;
return R;
end T_Array_Tail_to_U64_LE;
m_pos : T_Index'Base := 0;
m_i : U64;
v : SipHash_State := Get_Initial_State;
w : constant Natural := (m'Length / 4) + 1;
begin
-- This compile-time check is useful for GNAT but in GNATprove it currently
-- just generates a warning that it can not yet prove them correct.
pragma Warnings (GNATprove, Off, "Compile_Time_Error");
pragma Compile_Time_Error ((T'Size > 16),
"SipHash.Wide_Discrete only works for discrete " &
"types which fit into two bytes.");
pragma Warnings (GNATprove, On, "Compile_Time_Error");
for I in 1..w-1 loop
pragma Loop_Invariant (m_pos = T_Index'Base(I - 1) * 4);
m_i := T_Array_4_to_U64_LE(m(m'First + m_pos..m'First + m_pos + 3));
v(3) := v(3) xor m_i;
for J in 1..c_rounds loop
Sip_Round(v);
end loop;
v(0) := v(0) xor m_i;
m_pos := m_pos + 4;
end loop;
if m_pos < m'Length then
m_i := T_Array_Tail_to_U64_LE(m(m'First + m_pos .. m'Last));
else
m_i := 0;
end if;
m_i := m_i or Shift_Left(U64(m'Length mod 256), 56);
v(3) := v(3) xor m_i;
for J in 1..c_rounds loop
Sip_Round(v);
end loop;
v(0) := v(0) xor m_i;
return Hash_Type'Mod(Sip_Finalization(v));
end SipHash.Wide_Discrete;
|
reznikmm/matreshka | Ada | 3,699 | 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.Draw_Contour_Polygon_Elements is
pragma Preelaborate;
type ODF_Draw_Contour_Polygon is limited interface
and XML.DOM.Elements.DOM_Element;
type ODF_Draw_Contour_Polygon_Access is
access all ODF_Draw_Contour_Polygon'Class
with Storage_Size => 0;
end ODF.DOM.Draw_Contour_Polygon_Elements;
|
optikos/oasis | Ada | 8,558 | adb | -- Copyright (c) 2019 Maxim Reznik <[email protected]>
--
-- SPDX-License-Identifier: MIT
-- License-Filename: LICENSE
-------------------------------------------------------------
package body Program.Nodes.Parameter_Specifications is
function Create
(Names : not null Program.Elements.Defining_Identifiers
.Defining_Identifier_Vector_Access;
Colon_Token : not null Program.Lexical_Elements
.Lexical_Element_Access;
Aliased_Token : Program.Lexical_Elements.Lexical_Element_Access;
In_Token : Program.Lexical_Elements.Lexical_Element_Access;
Out_Token : Program.Lexical_Elements.Lexical_Element_Access;
Not_Token : Program.Lexical_Elements.Lexical_Element_Access;
Null_Token : Program.Lexical_Elements.Lexical_Element_Access;
Parameter_Subtype : not null Program.Elements.Element_Access;
Assignment_Token : Program.Lexical_Elements.Lexical_Element_Access;
Default_Expression : Program.Elements.Expressions.Expression_Access)
return Parameter_Specification is
begin
return Result : Parameter_Specification :=
(Names => Names, Colon_Token => Colon_Token,
Aliased_Token => Aliased_Token, In_Token => In_Token,
Out_Token => Out_Token, Not_Token => Not_Token,
Null_Token => Null_Token, Parameter_Subtype => Parameter_Subtype,
Assignment_Token => Assignment_Token,
Default_Expression => Default_Expression, Enclosing_Element => null)
do
Initialize (Result);
end return;
end Create;
function Create
(Names : not null Program.Elements.Defining_Identifiers
.Defining_Identifier_Vector_Access;
Parameter_Subtype : not null Program.Elements.Element_Access;
Default_Expression : Program.Elements.Expressions.Expression_Access;
Is_Part_Of_Implicit : Boolean := False;
Is_Part_Of_Inherited : Boolean := False;
Is_Part_Of_Instance : Boolean := False;
Has_Aliased : Boolean := False;
Has_In : Boolean := False;
Has_Out : Boolean := False;
Has_Not_Null : Boolean := False)
return Implicit_Parameter_Specification is
begin
return Result : Implicit_Parameter_Specification :=
(Names => Names, Parameter_Subtype => Parameter_Subtype,
Default_Expression => Default_Expression,
Is_Part_Of_Implicit => Is_Part_Of_Implicit,
Is_Part_Of_Inherited => Is_Part_Of_Inherited,
Is_Part_Of_Instance => Is_Part_Of_Instance,
Has_Aliased => Has_Aliased, Has_In => Has_In, Has_Out => Has_Out,
Has_Not_Null => Has_Not_Null, Enclosing_Element => null)
do
Initialize (Result);
end return;
end Create;
overriding function Names
(Self : Base_Parameter_Specification)
return not null Program.Elements.Defining_Identifiers
.Defining_Identifier_Vector_Access is
begin
return Self.Names;
end Names;
overriding function Parameter_Subtype
(Self : Base_Parameter_Specification)
return not null Program.Elements.Element_Access is
begin
return Self.Parameter_Subtype;
end Parameter_Subtype;
overriding function Default_Expression
(Self : Base_Parameter_Specification)
return Program.Elements.Expressions.Expression_Access is
begin
return Self.Default_Expression;
end Default_Expression;
overriding function Colon_Token
(Self : Parameter_Specification)
return not null Program.Lexical_Elements.Lexical_Element_Access is
begin
return Self.Colon_Token;
end Colon_Token;
overriding function Aliased_Token
(Self : Parameter_Specification)
return Program.Lexical_Elements.Lexical_Element_Access is
begin
return Self.Aliased_Token;
end Aliased_Token;
overriding function In_Token
(Self : Parameter_Specification)
return Program.Lexical_Elements.Lexical_Element_Access is
begin
return Self.In_Token;
end In_Token;
overriding function Out_Token
(Self : Parameter_Specification)
return Program.Lexical_Elements.Lexical_Element_Access is
begin
return Self.Out_Token;
end Out_Token;
overriding function Not_Token
(Self : Parameter_Specification)
return Program.Lexical_Elements.Lexical_Element_Access is
begin
return Self.Not_Token;
end Not_Token;
overriding function Null_Token
(Self : Parameter_Specification)
return Program.Lexical_Elements.Lexical_Element_Access is
begin
return Self.Null_Token;
end Null_Token;
overriding function Assignment_Token
(Self : Parameter_Specification)
return Program.Lexical_Elements.Lexical_Element_Access is
begin
return Self.Assignment_Token;
end Assignment_Token;
overriding function Has_Aliased
(Self : Parameter_Specification)
return Boolean is
begin
return Self.Aliased_Token.Assigned;
end Has_Aliased;
overriding function Has_In
(Self : Parameter_Specification)
return Boolean is
begin
return Self.In_Token.Assigned;
end Has_In;
overriding function Has_Out
(Self : Parameter_Specification)
return Boolean is
begin
return Self.Out_Token.Assigned;
end Has_Out;
overriding function Has_Not_Null
(Self : Parameter_Specification)
return Boolean is
begin
return Self.Null_Token.Assigned;
end Has_Not_Null;
overriding function Is_Part_Of_Implicit
(Self : Implicit_Parameter_Specification)
return Boolean is
begin
return Self.Is_Part_Of_Implicit;
end Is_Part_Of_Implicit;
overriding function Is_Part_Of_Inherited
(Self : Implicit_Parameter_Specification)
return Boolean is
begin
return Self.Is_Part_Of_Inherited;
end Is_Part_Of_Inherited;
overriding function Is_Part_Of_Instance
(Self : Implicit_Parameter_Specification)
return Boolean is
begin
return Self.Is_Part_Of_Instance;
end Is_Part_Of_Instance;
overriding function Has_Aliased
(Self : Implicit_Parameter_Specification)
return Boolean is
begin
return Self.Has_Aliased;
end Has_Aliased;
overriding function Has_In
(Self : Implicit_Parameter_Specification)
return Boolean is
begin
return Self.Has_In;
end Has_In;
overriding function Has_Out
(Self : Implicit_Parameter_Specification)
return Boolean is
begin
return Self.Has_Out;
end Has_Out;
overriding function Has_Not_Null
(Self : Implicit_Parameter_Specification)
return Boolean is
begin
return Self.Has_Not_Null;
end Has_Not_Null;
procedure Initialize
(Self : aliased in out Base_Parameter_Specification'Class) is
begin
for Item in Self.Names.Each_Element loop
Set_Enclosing_Element (Item.Element, Self'Unchecked_Access);
end loop;
Set_Enclosing_Element (Self.Parameter_Subtype, Self'Unchecked_Access);
if Self.Default_Expression.Assigned then
Set_Enclosing_Element
(Self.Default_Expression, Self'Unchecked_Access);
end if;
null;
end Initialize;
overriding function Is_Parameter_Specification_Element
(Self : Base_Parameter_Specification)
return Boolean is
pragma Unreferenced (Self);
begin
return True;
end Is_Parameter_Specification_Element;
overriding function Is_Declaration_Element
(Self : Base_Parameter_Specification)
return Boolean is
pragma Unreferenced (Self);
begin
return True;
end Is_Declaration_Element;
overriding procedure Visit
(Self : not null access Base_Parameter_Specification;
Visitor : in out Program.Element_Visitors.Element_Visitor'Class) is
begin
Visitor.Parameter_Specification (Self);
end Visit;
overriding function To_Parameter_Specification_Text
(Self : aliased in out Parameter_Specification)
return Program.Elements.Parameter_Specifications
.Parameter_Specification_Text_Access is
begin
return Self'Unchecked_Access;
end To_Parameter_Specification_Text;
overriding function To_Parameter_Specification_Text
(Self : aliased in out Implicit_Parameter_Specification)
return Program.Elements.Parameter_Specifications
.Parameter_Specification_Text_Access is
pragma Unreferenced (Self);
begin
return null;
end To_Parameter_Specification_Text;
end Program.Nodes.Parameter_Specifications;
|
aeszter/lox-spark | Ada | 478 | adb | with Ada.Text_IO;
with Ast_Printers;
with Exprs; use Exprs;
with Tokens; use Tokens;
procedure Test_Ast with SPARK_Mode => Off is
Test_Expr, U, N, G, F : Expr_Handle;
begin
Create_Num_Literal (123, N);
Create_Unary (New_Token (T_MINUS, "-", 1), N, U);
Create_Float_Literal (45.67, F);
Create_Grouping (F, G);
Create_Binary (U, New_Token (T_STAR, "*", 1), G, Test_Expr);
Ada.Text_IO.Put_Line (Ast_Printers.Print (Exprs.Retrieve (Test_Expr)));
end Test_Ast;
|
reznikmm/matreshka | Ada | 4,785 | ads | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- SQL Database Access --
-- --
-- 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 package provides base implementation of SQL statement parameter
-- rewriter, which converts :name style parameter placeholders into database
-- specific representation.
------------------------------------------------------------------------------
with League.Strings;
with Matreshka.Internals.SQL_Parameter_Sets;
package Matreshka.Internals.SQL_Parameter_Rewriters is
pragma Preelaborate;
type Abstract_Parameter_Rewriter is abstract tagged limited null record;
procedure Rewrite
(Self : Abstract_Parameter_Rewriter'Class;
Source : League.Strings.Universal_String;
Rewritten : out League.Strings.Universal_String;
Parameters : out SQL_Parameter_Sets.Parameter_Set);
-- Parses SQL statement Source, rewrites parameter placeholders to
-- database specific format and prepare set of parameters object.
not overriding procedure Database_Placeholder
(Self : Abstract_Parameter_Rewriter;
Name : League.Strings.Universal_String;
Number : Positive;
Placeholder : out League.Strings.Universal_String;
Parameters : in out SQL_Parameter_Sets.Parameter_Set) is abstract;
-- Sets Placeholder to database specific placeholder for parameter with
-- Name and number Number. Implementation must modify Parameters
-- accordingly.
--
-- Note: passed parameter's name is casefolded.
end Matreshka.Internals.SQL_Parameter_Rewriters;
|
reznikmm/matreshka | Ada | 4,113 | ads | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Web Framework --
-- --
-- Runtime Library 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 League.Strings;
with League.Holders.Generic_Integers;
package Forum.Posts is
pragma Preelaborate;
-- type Post_Identifier is private;
type Post_Identifier is range 0 .. 2 ** 63 - 1;
function Encode
(Item : Post_Identifier) return League.Strings.Universal_String;
function Decode
(Image : League.Strings.Universal_String;
Value : out Post_Identifier) return Boolean;
-- Functions to 'encode' and 'decode' post identifiers to string
-- representsation. Decode function returns True when category identifier
-- was decoded successfully.
package Post_Identifier_Holders is
new League.Holders.Generic_Integers (Post_Identifier);
-- private
--
--
-- type Post_Identifier is range 0 .. 2 ** 63 - 1;
end Forum.Posts;
|
reznikmm/matreshka | Ada | 12,646 | adb | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Web Framework --
-- --
-- Tools Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2012-2013, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
with League.Strings;
with WSDL.AST.Bindings;
pragma Unreferenced (WSDL.AST.Bindings);
-- GNAT Pro 7.2.0w (20130423): package is needed to access to type's
-- components.
with WSDL.AST.Descriptions;
pragma Unreferenced (WSDL.AST.Descriptions);
-- GNAT Pro 7.2.0w (20130423): package is needed to access to type's
-- components.
with WSDL.AST.Faults;
pragma Unreferenced (WSDL.AST.Faults);
-- GNAT Pro 7.2.0w (20130423): package is needed to access to type's
-- components.
with WSDL.AST.Interfaces;
pragma Unreferenced (WSDL.AST.Interfaces);
-- XXX GNAT 20130108 reports that unit is not referenced.
with WSDL.AST.Operations;
pragma Unreferenced (WSDL.AST.Operations);
-- XXX GNAT 20130108 reports that unit is not referenced.
package body WSDL.Name_Resolvers is
use type League.Strings.Universal_String;
use type WSDL.AST.Interface_Operation_Access;
function Resolve_Binding
(Root : not null WSDL.AST.Description_Access;
Namespace_URI : League.Strings.Universal_String;
Local_Name : League.Strings.Universal_String)
return WSDL.AST.Binding_Access;
-- Resolves binding component by qualified name.
function Resolve_Interface
(Root : not null WSDL.AST.Description_Access;
Namespace_URI : League.Strings.Universal_String;
Local_Name : League.Strings.Universal_String)
return WSDL.AST.Interface_Access;
-- Resolves name of interface component.
function Resolve_Interface_Fault
(Node : not null WSDL.AST.Interface_Access;
Name : WSDL.AST.Qualified_Name)
return WSDL.AST.Interface_Fault_Access;
-- Resolves name of interface operation component.
function Resolve_Interface_Operation
(Node : not null WSDL.AST.Interface_Access;
Local_Name : League.Strings.Universal_String)
return WSDL.AST.Interface_Operation_Access;
-- Resolves name of interface operation component.
procedure Resolve_Interface_Operation
(Node : not null WSDL.AST.Interface_Access;
Local_Name : League.Strings.Universal_String;
Result : out WSDL.AST.Interface_Operation_Access);
-------------------
-- Enter_Binding --
-------------------
overriding procedure Enter_Binding
(Self : in out Name_Resolver;
Node : not null WSDL.AST.Binding_Access;
Control : in out WSDL.Iterators.Traverse_Control)
is
pragma Unreferenced (Control);
begin
-- Resolve interface component when necessary.
if not Node.Interface_Name.Local_Name.Is_Empty then
Node.Interface_Node :=
Resolve_Interface
(Self.Root,
Node.Interface_Name.Namespace_URI,
Node.Interface_Name.Local_Name);
end if;
end Enter_Binding;
-------------------------
-- Enter_Binding_Fault --
-------------------------
overriding procedure Enter_Binding_Fault
(Self : in out Name_Resolver;
Node : not null WSDL.AST.Binding_Fault_Access;
Control : in out WSDL.Iterators.Traverse_Control) is
begin
-- Resolve interface fault component.
Node.Interface_Fault :=
Resolve_Interface_Fault (Node.Parent.Interface_Node, Node.Ref);
end Enter_Binding_Fault;
-----------------------------
-- Enter_Binding_Operation --
-----------------------------
overriding procedure Enter_Binding_Operation
(Self : in out Name_Resolver;
Node : not null WSDL.AST.Binding_Operation_Access;
Control : in out WSDL.Iterators.Traverse_Control)
is
pragma Unreferenced (Self);
pragma Unreferenced (Control);
begin
-- It is unclear from the specification how namespace URI should be
-- used. From the other side, operations are identified uniquely in the
-- interface.
Node.Interface_Operation :=
Resolve_Interface_Operation
(Node.Parent.Interface_Node, Node.Ref.Local_Name);
end Enter_Binding_Operation;
--------------------
-- Enter_Endpoint --
--------------------
overriding procedure Enter_Endpoint
(Self : in out Name_Resolver;
Node : not null WSDL.AST.Endpoints.Endpoint_Access;
Control : in out WSDL.Iterators.Traverse_Control)
is
pragma Unreferenced (Control);
begin
Node.Binding :=
Resolve_Binding
(Self.Root,
Node.Binding_Name.Namespace_URI,
Node.Binding_Name.Local_Name);
end Enter_Endpoint;
---------------------
-- Enter_Interface --
---------------------
overriding procedure Enter_Interface
(Self : in out Name_Resolver;
Node : not null WSDL.AST.Interface_Access;
Control : in out WSDL.Iterators.Traverse_Control)
is
pragma Unreferenced (Control);
begin
for J of Node.Extends loop
Node.Extended_Interfaces.Append
(Resolve_Interface (Self.Root, J.Namespace_URI, J.Local_Name));
end loop;
end Enter_Interface;
-------------------
-- Enter_Service --
-------------------
overriding procedure Enter_Service
(Self : in out Name_Resolver;
Node : not null WSDL.AST.Services.Service_Access;
Control : in out WSDL.Iterators.Traverse_Control)
is
pragma Unreferenced (Control);
begin
-- Resolve interface by qualified name.
Node.Interface_Node :=
Resolve_Interface
(Self.Root,
Node.Interface_Name.Namespace_URI,
Node.Interface_Name.Local_Name);
end Enter_Service;
---------------------
-- Resolve_Binding --
---------------------
function Resolve_Binding
(Root : not null WSDL.AST.Description_Access;
Namespace_URI : League.Strings.Universal_String;
Local_Name : League.Strings.Universal_String)
return WSDL.AST.Binding_Access is
begin
-- QName-resolution-1064: "A Description component MUST NOT have such
-- broken references."
if Root.Target_Namespace /= Namespace_URI then
raise Program_Error;
end if;
if not Root.Bindings.Contains (Local_Name) then
raise Program_Error;
end if;
return Root.Bindings.Element (Local_Name);
end Resolve_Binding;
-----------------------
-- Resolve_Interface --
-----------------------
function Resolve_Interface
(Root : not null WSDL.AST.Description_Access;
Namespace_URI : League.Strings.Universal_String;
Local_Name : League.Strings.Universal_String)
return WSDL.AST.Interface_Access is
begin
-- QName-resolution-1064: "A Description component MUST NOT have such
-- broken references."
if Root.Target_Namespace /= Namespace_URI then
raise Program_Error;
end if;
if not Root.Interfaces.Contains (Local_Name) then
raise Program_Error;
end if;
return Root.Interfaces.Element (Local_Name);
end Resolve_Interface;
-----------------------------
-- Resolve_Interface_Fault --
-----------------------------
function Resolve_Interface_Fault
(Node : not null WSDL.AST.Interface_Access;
Name : WSDL.AST.Qualified_Name)
return WSDL.AST.Interface_Fault_Access
is
use type WSDL.AST.Interface_Fault_Access;
Result : WSDL.AST.Interface_Fault_Access;
begin
if Node.Parent.Target_Namespace = Name.Namespace_URI
and then Node.Interface_Faults.Contains (Name.Local_Name)
then
return Node.Interface_Faults.Element (Name.Local_Name);
end if;
for J of Node.Extended_Interfaces loop
Result := Resolve_Interface_Fault (J, Name);
if Result /= null then
return Result;
end if;
end loop;
raise Program_Error;
end Resolve_Interface_Fault;
---------------------------------
-- Resolve_Interface_Operation --
---------------------------------
procedure Resolve_Interface_Operation
(Node : not null WSDL.AST.Interface_Access;
Local_Name : League.Strings.Universal_String;
Result : out WSDL.AST.Interface_Operation_Access) is
begin
Result := null;
if Node.Interface_Operations.Contains (Local_Name) then
Result := Node.Interface_Operations.Element (Local_Name);
return;
end if;
for J of Node.Extended_Interfaces loop
Resolve_Interface_Operation (J, Local_Name, Result);
if Result /= null then
return;
end if;
end loop;
end Resolve_Interface_Operation;
---------------------------------
-- Resolve_Interface_Operation --
---------------------------------
function Resolve_Interface_Operation
(Node : not null WSDL.AST.Interface_Access;
Local_Name : League.Strings.Universal_String)
return WSDL.AST.Interface_Operation_Access
is
Aux : WSDL.AST.Interface_Operation_Access;
begin
Resolve_Interface_Operation (Node, Local_Name, Aux);
if Aux /= null then
return Aux;
else
raise Program_Error;
end if;
end Resolve_Interface_Operation;
--------------
-- Set_Root --
--------------
procedure Set_Root
(Self : in out Name_Resolver'Class;
Root : WSDL.AST.Description_Access) is
begin
Self.Root := Root;
end Set_Root;
end WSDL.Name_Resolvers;
|
thierr26/ada-keystore | Ada | 4,170 | ads | -----------------------------------------------------------------------
-- keystore-tests -- Tests for akt command
-- Copyright (C) 2019 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 Ada.Strings.Unbounded;
with Util.Tests;
with Util.Systems.Os;
package Keystore.Tests is
function Is_Windows return Boolean is
(Util.Systems.Os.Directory_Separator = '\');
EXE : constant String
:= (if Is_Windows then ".exe" else "");
procedure Add_Tests (Suite : in Util.Tests.Access_Test_Suite);
type Test is new Util.Tests.Test with null record;
-- Test the akt help command.
procedure Test_Tool_Help (T : in out Test);
-- Test the akt keystore creation.
procedure Test_Tool_Create (T : in out Test);
procedure Test_Tool_Create_Error (T : in out Test);
-- Test the akt keystore creation with password file.
procedure Test_Tool_Create_Password_File (T : in out Test);
procedure Test_Tool_Create_Password_Command (T : in out Test);
-- Test the akt command adding and removing values.
procedure Test_Tool_Set_Remove (T : in out Test);
procedure Test_Tool_Set_Remove_2 (T : in out Test);
-- Test the akt command setting a big file.
procedure Test_Tool_Set_Big (T : in out Test);
-- Test the akt get command.
procedure Test_Tool_Get (T : in out Test);
-- Test the akt get command with errors.
procedure Test_Tool_Get_Error (T : in out Test);
-- Test the akt command with invalid parameters.
procedure Test_Tool_Invalid (T : in out Test);
-- Test the akt edit command.
procedure Test_Tool_Edit (T : in out Test);
-- Test the akt store and akt extract commands.
procedure Test_Tool_Store_Extract (T : in out Test);
procedure Test_Tool_Store_Extract_Tree (T : in out Test);
-- Test the akt store command with errors.
procedure Test_Tool_Store_Error (T : in out Test);
procedure Test_Tool_Extract_Error (T : in out Test);
-- Test the akt password-set command.
procedure Test_Tool_Password_Set (T : in out Test);
-- Test the akt with an interactive password.
procedure Test_Tool_Interactive_Password (T : in out Test);
-- Test the akt with data blocks written in separate files.
procedure Test_Tool_Separate_Data (T : in out Test);
-- Test the akt config command.
procedure Test_Tool_Set_Config (T : in out Test);
-- Test the akt info command on several keystore files.
procedure Test_Tool_Info (T : in out Test);
-- Test the akt commands with --wallet-key-file
procedure Test_Tool_With_Wallet_Key_File (T : in out Test);
procedure Execute (T : in out Test;
Command : in String;
Input : in String;
Output : in String;
Result : out Ada.Strings.Unbounded.Unbounded_String;
Status : in Natural := 0);
procedure Execute (T : in out Test;
Command : in String;
Result : out Ada.Strings.Unbounded.Unbounded_String;
Status : in Natural := 0);
procedure Execute (T : in out Test;
Command : in String;
Expect : in String;
Status : in Natural := 0);
procedure Store_Extract (T : in out Test;
Command : in String;
Name : in String;
Path : in String);
end Keystore.Tests;
|
kjseefried/coreland-cgbc | Ada | 976 | adb | with Ada.Strings;
with CGBC.Bounded_Wide_Wide_Strings;
with Test;
procedure T_WWBstr_Append_E01 is
package BS renames CGBC.Bounded_Wide_Wide_Strings;
TC : Test.Context_t;
S1 : BS.Bounded_String (8);
Caught : Boolean;
begin
Test.Initialize
(Test_Context => TC,
Program => "t_wwbstr_append_e01",
Test_DB => "TEST_DB",
Test_Results => "TEST_RESULTS");
BS.Append (S1, "ABCD");
pragma Assert (BS.Length (S1) = 4);
begin
Caught := False;
BS.Append
(Source => S1,
New_Item => "012345678",
Drop => Ada.Strings.Error);
exception
when Ada.Strings.Length_Error => Caught := True;
end;
Test.Check (TC, 2205, Caught, "Caught");
Test.Check (TC, 2206, BS.Length (S1) = 4, "BS.Length (S1) = 4");
Test.Check (TC, 2207, BS.Maximum_Length (S1) = 8, "BS.Maximum_Length (S1) = 8");
Test.Check (TC, 2208, BS.To_String (S1) = "ABCD", "BS.To_String (S1) = ""ABCD""");
end T_WWBstr_Append_E01;
|
AdaCore/training_material | Ada | 3,519 | adb | -----------------------------------------------------------------------
-- Ada Labs --
-- --
-- Copyright (C) 2008-2009, AdaCore --
-- --
-- Labs is free software; you can redistribute it and/or modify it --
-- under the terms of the GNU General Public License as published by --
-- the Free Software Foundation; either version 2 of the License, or --
-- (at your option) any later version. --
-- --
-- This 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, write to the Free Software Foundation, Inc., 59 Temple --
-- Place - Suite 330, Boston, MA 02111-1307, USA. --
-----------------------------------------------------------------------
with Libm_Single; use Libm_Single;
package body Solar_System is
procedure Init_Body
(B : Bodies_Enum_T;
Bodies : in out Bodies_Array_T;
Radius : Float;
Color : RGBA_T;
Distance : Float;
Angle : Float;
Speed : Float;
Turns_Around : Bodies_Enum_T;
Visible : Boolean := True)
is
begin
Bodies (B) :=
(Distance => Distance,
Speed => Speed,
Angle => Angle,
Turns_Around => Turns_Around,
Visible => Visible,
Color => Color,
Radius => Radius,
others => <>);
end Init_Body;
-- implement a function to compute the X coordinate
-- x of the reference + distance * cos(angle)
function Compute_X
(Body_To_Move : Body_T;
Turns_Around : Body_T) return Float;
-- implement a function to compute the Y coordinate
-- y of the reference + distance * sin(angle)
function Compute_Y
(Body_To_Move : Body_T;
Turns_Around : Body_T) return Float;
function Compute_X
(Body_To_Move : Body_T;
Turns_Around : Body_T) return Float
is
begin
return Turns_Around.X + Body_To_Move.Distance * Cos (Body_To_Move.Angle);
end Compute_X;
function Compute_Y
(Body_To_Move : Body_T;
Turns_Around : Body_T) return Float
is
begin
return Turns_Around.Y + Body_To_Move.Distance * Sin (Body_To_Move.Angle);
end Compute_Y;
procedure Move (Body_To_Move : in out Body_T; Bodies : Bodies_Array_T) is
begin
Body_To_Move.X :=
Compute_X (Body_To_Move, Bodies (Body_To_Move.Turns_Around));
Body_To_Move.Y :=
Compute_Y (Body_To_Move, Bodies (Body_To_Move.Turns_Around));
Body_To_Move.Angle := Body_To_Move.Angle + Body_To_Move.Speed;
end Move;
procedure Move_All (Bodies : in out Bodies_Array_T) is
begin
-- loop over all bodies and call Move procedure
for B of Bodies loop
-- call the move procedure for each body
Move (B, Bodies);
end loop;
end Move_All;
end Solar_System;
|
optikos/oasis | Ada | 3,568 | ads | -- Copyright (c) 2019 Maxim Reznik <[email protected]>
--
-- SPDX-License-Identifier: MIT
-- License-Filename: LICENSE
-------------------------------------------------------------
with Program.Elements.Declarations;
with Program.Lexical_Elements;
with Program.Elements.Defining_Names;
with Program.Elements.Expressions;
with Program.Elements.Parameter_Associations;
with Program.Elements.Aspect_Specifications;
package Program.Elements.Procedure_Instantiations is
pragma Pure (Program.Elements.Procedure_Instantiations);
type Procedure_Instantiation is
limited interface and Program.Elements.Declarations.Declaration;
type Procedure_Instantiation_Access is
access all Procedure_Instantiation'Class with Storage_Size => 0;
not overriding function Name
(Self : Procedure_Instantiation)
return not null Program.Elements.Defining_Names.Defining_Name_Access
is abstract;
not overriding function Generic_Procedure_Name
(Self : Procedure_Instantiation)
return not null Program.Elements.Expressions.Expression_Access
is abstract;
not overriding function Parameters
(Self : Procedure_Instantiation)
return Program.Elements.Parameter_Associations
.Parameter_Association_Vector_Access is abstract;
not overriding function Aspects
(Self : Procedure_Instantiation)
return Program.Elements.Aspect_Specifications
.Aspect_Specification_Vector_Access is abstract;
not overriding function Has_Not
(Self : Procedure_Instantiation)
return Boolean is abstract;
not overriding function Has_Overriding
(Self : Procedure_Instantiation)
return Boolean is abstract;
type Procedure_Instantiation_Text is limited interface;
type Procedure_Instantiation_Text_Access is
access all Procedure_Instantiation_Text'Class with Storage_Size => 0;
not overriding function To_Procedure_Instantiation_Text
(Self : aliased in out Procedure_Instantiation)
return Procedure_Instantiation_Text_Access is abstract;
not overriding function Not_Token
(Self : Procedure_Instantiation_Text)
return Program.Lexical_Elements.Lexical_Element_Access is abstract;
not overriding function Overriding_Token
(Self : Procedure_Instantiation_Text)
return Program.Lexical_Elements.Lexical_Element_Access is abstract;
not overriding function Procedure_Token
(Self : Procedure_Instantiation_Text)
return not null Program.Lexical_Elements.Lexical_Element_Access
is abstract;
not overriding function Is_Token
(Self : Procedure_Instantiation_Text)
return not null Program.Lexical_Elements.Lexical_Element_Access
is abstract;
not overriding function New_Token
(Self : Procedure_Instantiation_Text)
return not null Program.Lexical_Elements.Lexical_Element_Access
is abstract;
not overriding function Left_Bracket_Token
(Self : Procedure_Instantiation_Text)
return Program.Lexical_Elements.Lexical_Element_Access is abstract;
not overriding function Right_Bracket_Token
(Self : Procedure_Instantiation_Text)
return Program.Lexical_Elements.Lexical_Element_Access is abstract;
not overriding function With_Token
(Self : Procedure_Instantiation_Text)
return Program.Lexical_Elements.Lexical_Element_Access is abstract;
not overriding function Semicolon_Token
(Self : Procedure_Instantiation_Text)
return not null Program.Lexical_Elements.Lexical_Element_Access
is abstract;
end Program.Elements.Procedure_Instantiations;
|
reznikmm/matreshka | Ada | 4,005 | 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.Number_Grouping_Attributes;
package Matreshka.ODF_Number.Grouping_Attributes is
type Number_Grouping_Attribute_Node is
new Matreshka.ODF_Number.Abstract_Number_Attribute_Node
and ODF.DOM.Number_Grouping_Attributes.ODF_Number_Grouping_Attribute
with null record;
overriding function Create
(Parameters : not null access Matreshka.DOM_Attributes.Attribute_L2_Parameters)
return Number_Grouping_Attribute_Node;
overriding function Get_Local_Name
(Self : not null access constant Number_Grouping_Attribute_Node)
return League.Strings.Universal_String;
end Matreshka.ODF_Number.Grouping_Attributes;
|
charlie5/lace | Ada | 29,419 | ads | -- Copyright (c) 2011, Felix Krause <[email protected]>
--
-- Permission to use, copy, modify, and/or distribute this software for any
-- purpose with or without fee is hereby granted, provided that the above
-- copyright notice and this permission notice appear in all copies.
--
-- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
-- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
-- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
-- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
-- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
with System;
with Interfaces.C.Pointers;
with Interfaces.C.Extensions;
with Interfaces.C.Strings;
package GL.CGL is
-- CGL types and constants
subtype CGLContextObject is System.Address;
subtype CGLPixelFormatObject is System.Address;
subtype CGLRendererInfoObject is System.Address;
subtype CGLPBufferObject is System.Address;
type CGLPixelFormatAttribute is (Terminator ,
kCGLPFAAllRenderers ,
kCGLPFATripleBuffer ,
kCGLPFADoubleBuffer ,
kCGLPFAStereo ,
kCGLPFAAuxBuffers ,
kCGLPFAColorSize ,
kCGLPFAAlphaSize ,
kCGLPFADepthSize ,
kCGLPFAStencilSize ,
kCGLPFAAccumSize ,
kCGLPFAMinimumPolicy ,
kCGLPFAMaximumPolicy ,
kCGLPFAOffScreen ,
kCGLPFAFullScreen ,
kCGLPFASampleBuffers ,
kCGLPFASamples ,
kCGLPFAAuxDepthStencil ,
kCGLPFAColorFloat ,
kCGLPFAMultisample ,
kCGLPFASupersample ,
kCGLPFASampleAlpha ,
kCGLPFARendererID ,
kCGLPFASingleRenderer ,
kCGLPFANoRecovery ,
kCGLPFAAccelerated ,
kCGLPFAClosestPolicy ,
kCGLPFARobust ,
kCGLPFABackingStore ,
kCGLPFAMPSafe ,
kCGLPFAWindow ,
kCGLPFAMultiScreen ,
kCGLPFACompliant ,
kCGLPFADisplayMask ,
kCGLPFAPBuffer ,
kCGLPFARemotePBuffer ,
kCGLPFAAllowOfflineRenderers,
kCGLPFAAcceleratedCompute,
kCGLPFAOpenGLProfile ,
kCGLPFAVirtualScreenCount
);
type CGLRendererProperty is (kCGLRPOffScreen ,
kCGLRPFullScreen ,
kCGLRPRendererID ,
kCGLRPAccelerated ,
kCGLRPRobust ,
kCGLRPBackingStore ,
kCGLRPMPSafe ,
kCGLRPWindow ,
kCGLRPMultiScreen ,
kCGLRPCompliant ,
kCGLRPDisplayMask ,
kCGLRPBufferModes ,
kCGLRPColorModes ,
kCGLRPAccumModes ,
kCGLRPDepthModes ,
kCGLRPStencilModes ,
kCGLRPMaxAuxBuffers ,
kCGLRPMaxSampleBuffers ,
kCGLRPMaxSamples ,
kCGLRPSampleModes ,
kCGLRPSampleAlpha ,
kCGLRPVideoMemory ,
kCGLRPTextureMemory ,
kCGLRPGPUVertProcCapable ,
kCGLRPGPUFragProcCapable ,
kCGLRPRendererCount ,
kCGLRPOnline ,
kCGLRPAcceleratedCompute ,
kCGLRPVideoMemoryMegabytes ,
kCGLRPTextureMemoryMegabytes
);
type CGLContextEnable is (kCGLCESwapRectangle ,
kCGLCESwapLimit ,
kCGLCERasterization ,
kCGLCEStateValidation,
kCGLCESurfaceBackingSize,
kCGLCEDisplayListOptimization,
kCGLCEMPEngine ,
kCGLCECrashOnRemovedFunctions
);
type CGLContextParameter is (kCGLCPSwapRectangle ,
kCGLCPSwapInterval ,
kCGLCPDispatchTableSize ,
kCGLCPClientStorage ,
kCGLCPSurfaceTexture ,
kCGLCPSurfaceOrder ,
kCGLCPSurfaceOpacity ,
kCGLCPSurfaceBackingSize ,
kCGLCPSurfaceSurfaceVolatile,
kCGLCPReclaimResources ,
kCGLCPCurrentRendererID ,
kCGLCPGPUVertexProcessing ,
kCGLCPGPUFragmentProcessing ,
kCGLCPHasDrawable ,
kCGLCPMPSwapsInFlight
);
type CGLGlobalOption is (kCGLGOFormatCacheSize ,
kCGLGOClearFormatCache,
kCGLGORetainRenderers ,
kCGLGOResetLibrary ,
kCGLGOUseErrorHandler ,
kCGLGOUseBuildCache
);
type CGLOpenGLProfile is (kCGLOGLPVersion_Legacy ,
kCGLOGLPVersion_3_2_Core
);
type CGLError is (kCGLNoError ,
kCGLBadAttribute ,
kCGLBadProperty ,
kCGLBadPixelFormat ,
kCGLBadRendererInfo ,
kCGLBadContext ,
kCGLBadDrawable ,
kCGLBadDisplay ,
kCGLBadState ,
kCGLBadValue ,
kCGLBadMatch ,
kCGLBadEnumeration ,
kCGLBadOffScreen ,
kCGLBadFullScreen ,
kCGLBadWindow ,
kCGLBadAddress ,
kCGLBadCodeModule ,
kCGLBadAlloc ,
kCGLBadConnection
);
kCGLMonoscopicBit : constant := 16#00000001#;
kCGLStereoscopicBit: constant := 16#00000002#;
kCGLSingleBufferBit: constant := 16#00000004#;
kCGLDoubleBufferBit: constant := 16#00000008#;
kCGLTripleBufferBit: constant := 16#00000010#;
kCGL0Bit : constant := 16#00000001#;
kCGL1Bit : constant := 16#00000002#;
kCGL2Bit : constant := 16#00000004#;
kCGL3Bit : constant := 16#00000008#;
kCGL4Bit : constant := 16#00000010#;
kCGL5Bit : constant := 16#00000020#;
kCGL6Bit : constant := 16#00000040#;
kCGL8Bit : constant := 16#00000080#;
kCGL10Bit : constant := 16#00000100#;
kCGL12Bit : constant := 16#00000200#;
kCGL16Bit : constant := 16#00000400#;
kCGL24Bit : constant := 16#00000800#;
kCGL32Bit : constant := 16#00001000#;
kCGL48Bit : constant := 16#00002000#;
kCGL64Bit : constant := 16#00004000#;
kCGL96Bit : constant := 16#00008000#;
kCGL128Bit : constant := 16#00010000#;
kCGLRGB444Bit : constant := 16#00000040#;
kCGLARGB4444Bit : constant := 16#00000080#;
kCGLRGB444A8Bit : constant := 16#00000100#;
kCGLRGB555Bit : constant := 16#00000200#;
kCGLARGB1555Bit : constant := 16#00000400#;
kCGLRGB555A8Bit : constant := 16#00000800#;
kCGLRGB565Bit : constant := 16#00001000#;
kCGLRGB565A8Bit : constant := 16#00002000#;
kCGLRGB888Bit : constant := 16#00004000#;
kCGLARGB8888Bit : constant := 16#00008000#;
kCGLRGB888A8Bit : constant := 16#00010000#;
kCGLRGB101010Bit : constant := 16#00020000#;
kCGLARGB2101010Bit : constant := 16#00040000#;
kCGLRGB101010_A8Bit: constant := 16#00080000#;
kCGLRGB121212Bit : constant := 16#00100000#;
kCGLARGB12121212Bit: constant := 16#00200000#;
kCGLRGB161616Bit : constant := 16#00400000#;
kCGLRGBA16161616Bit: constant := 16#00800000#;
kCGLRGBFloat64Bit : constant := 16#01000000#;
kCGLRGBAFloat64Bit : constant := 16#02000000#;
kCGLRGBFloat128Bit : constant := 16#04000000#;
kCGLRGBAFloat128Bit: constant := 16#08000000#;
kCGLRGBFloat256Bit : constant := 16#10000000#;
kCGLRGBAFloat256Bit: constant := 16#20000000#;
kCGLSupersampleBit : constant := 16#00000001#;
kCGLMultisampleBit : constant := 16#00000002#;
type CGLPixelFormatAttribute_Array is array (Positive range <>) of
aliased CGLPixelFormatAttribute;
-- Pixel format functions
function CGLChoosePixelFormat (attribs : access CGLPixelFormatAttribute;
pix : access CGLPixelFormatObject;
npix : access GLint) return CGLError;
function CGLDestroyPixelFormat (pix : CGLPixelFormatObject) return CGLError;
function CGLDescribePixelFormat (pix : CGLPixelFormatObject; pix_num : GLint;
attrib : CGLPixelFormatAttribute;
value : access GLint) return CGLError;
procedure CGLReleasePixelFormat (pix : in CGLPixelFormatObject);
function CGLRetainPixelFormat (pix : CGLPixelFormatObject)
return CGLPixelFormatObject;
function CGLGetPixelFormatRetainCount (pix : CGLPixelFormatObject)
return GLuint;
function CGLQueryRendererInfo (display_mask : GLuint;
rend : access CGLRendererInfoObject;
nrend : access GLint) return CGLError;
function CGLDestroyRendererInfo (rend : CGLRendererInfoObject)
return CGLError;
function CGLDescribeRenderer (rend : CGLRendererInfoObject; rend_num : GLint;
prop : CGLRendererProperty;
value : access GLint) return CGLError;
function CGLCreateContext (pix : CGLPixelFormatObject;
share : CGLContextObject;
ctx : access CGLContextObject) return CGLError;
function CGLDestroyContext (ctx : CGLContextObject) return CGLError;
function CGLCopyContext (src, dst : CGLContextObject;
mask : GLbitfield) return CGLError;
function CGLRetainContext (ctx : CGLContextObject) return CGLContextObject;
procedure CGLReleaseContext (ctx : in CGLContextObject);
function CGLGetContextRetainCount (ctx : CGLContextObject) return GLuint;
function CGLGetPixelFormat (ctx : CGLContextObject) return CGLPixelFormatObject;
function CGLCreatePBuffer (width, height : GLsizei;
target, internalFormat : GLenum;
max_level : GLint;
pbuffer : access CGLPBufferObject)
return CGLError;
function CGLDestroyPBuffer (pbuffer : CGLPBufferObject) return CGLError;
function CGLDescribePBuffer (obj : CGLPBufferObject;
width, height : access GLsizei;
target, internalFormat : access GLenum;
mipmap : access GLint) return CGLError;
function CGLTexImagePBuffer (ctx : CGLContextObject;
pbuffer : CGLPBufferObject;
source : GLenum) return CGLError;
function CGLRetainPBuffer (pbuffer : CGLPBufferObject)
return CGLPBufferObject;
procedure CGLReleasePBuffer (pbuffer : in CGLPBufferObject);
function CGLGetPBufferRetainCount (pbuffer : CGLPBufferObject) return GLuint;
function CGLSetOffScreen (ctx : CGLContextObject;
width, height : GLsizei;
rowbytes : GLint;
baseaddr : Interfaces.C.Extensions.void_ptr)
return CGLError;
function CGLGetOffScreen (ctx : CGLContextObject;
width, height : access GLsizei;
rowbytes : access GLint;
baseaddr : access Interfaces.C.Extensions.void_ptr)
return CGLError;
function CGLSetFullScreen (ctx : CGLContextObject) return CGLError;
function CGLSetFullScreenOnDisplay (ctx : CGLContextObject;
display_mask : GLuint) return CGLError;
function CGLSetPBuffer (ctx : CGLContextObject;
pbuffer : CGLPBufferObject;
face : GLenum;
level, screen : GLint) return CGLError;
function CGLGetPBuffer (ctx : CGLContextObject;
pbuffer : access CGLPBufferObject;
face : access GLenum;
level, screen : access GLint) return CGLError;
function CGLClearDrawable (ctx : CGLContextObject) return CGLError;
function CGLFlushDrawable (ctx : CGLContextObject) return CGLError;
function CGLEnable (ctx : CGLContextObject; pname : CGLContextEnable)
return CGLError;
function CGLDisable (ctx : CGLContextObject; pname : CGLContextEnable)
return CGLError;
function CGLIsEnabled (ctx : CGLContextObject; pname : CGLContextEnable;
enable : access GLint) return CGLError;
function CGLSetParameter (ctx : CGLContextObject;
pname : CGLContextParameter;
params : access constant GLint) return CGLError;
function CGLGetParameter (ctx : CGLContextObject;
pname : CGLContextParameter;
params : access GLint) return CGLError;
function CGLSetVirtualScreen (ctx : CGLContextObject; screen : GLint)
return CGLError;
function CGLGetVirtualScreen (ctx : CGLContextObject; screen : access GLint)
return CGLError;
function CGLUpdateContext (ctx : CGLContextObject) return CGLError;
function CGLSetGlobalOption (pname : CGLGlobalOption;
params : access constant GLint) return CGLError;
function CGLGetGlobalOption (pname : CGLGlobalOption;
params : access GLint) return CGLError;
function CGLSetOption (pname : CGLGlobalOption; param : GLint)
return CGLError;
function CGLGetOption (pname : CGLGlobalOption;
param : access GLint) return CGLError;
function CGLLockContext (ctx : CGLContextObject) return CGLError;
function CGLUnlockContext (ctx : CGLContextObject) return CGLError;
procedure CGLGetVersion (majorvers, minorvers : out GLint);
function CGLErrorString (error : CGLError)
return Interfaces.C.Strings.chars_ptr;
function CGLSetCurrentContext (ctx : CGLContextObject) return CGLError;
function CGLGetCurrentContext return CGLContextObject;
private
C_Enum_Size : constant := 32;
for CGLPixelFormatAttribute use (Terminator => 0,
kCGLPFAAllRenderers => 1,
kCGLPFATripleBuffer => 3,
kCGLPFADoubleBuffer => 5,
kCGLPFAStereo => 6,
kCGLPFAAuxBuffers => 7,
kCGLPFAColorSize => 8,
kCGLPFAAlphaSize => 11,
kCGLPFADepthSize => 12,
kCGLPFAStencilSize => 13,
kCGLPFAAccumSize => 14,
kCGLPFAMinimumPolicy => 51,
kCGLPFAMaximumPolicy => 52,
kCGLPFAOffScreen => 53,
kCGLPFAFullScreen => 54,
kCGLPFASampleBuffers => 55,
kCGLPFASamples => 56,
kCGLPFAAuxDepthStencil => 57,
kCGLPFAColorFloat => 58,
kCGLPFAMultisample => 59,
kCGLPFASupersample => 60,
kCGLPFASampleAlpha => 61,
kCGLPFARendererID => 70,
kCGLPFASingleRenderer => 71,
kCGLPFANoRecovery => 72,
kCGLPFAAccelerated => 73,
kCGLPFAClosestPolicy => 74,
kCGLPFARobust => 75,
kCGLPFABackingStore => 76,
kCGLPFAMPSafe => 78,
kCGLPFAWindow => 80,
kCGLPFAMultiScreen => 81,
kCGLPFACompliant => 83,
kCGLPFADisplayMask => 84,
kCGLPFAPBuffer => 90,
kCGLPFARemotePBuffer => 91,
kCGLPFAAllowOfflineRenderers => 96,
kCGLPFAAcceleratedCompute => 97,
kCGLPFAOpenGLProfile => 99,
kCGLPFAVirtualScreenCount => 128
);
for CGLPixelFormatAttribute'Size use C_Enum_Size;
pragma Convention (C, CGLPixelFormatAttribute);
for CGLRendererProperty use (kCGLRPOffScreen => 53,
kCGLRPFullScreen => 54,
kCGLRPRendererID => 70,
kCGLRPAccelerated => 73,
kCGLRPRobust => 75,
kCGLRPBackingStore => 76,
kCGLRPMPSafe => 78,
kCGLRPWindow => 80,
kCGLRPMultiScreen => 81,
kCGLRPCompliant => 83,
kCGLRPDisplayMask => 84,
kCGLRPBufferModes => 100,
kCGLRPColorModes => 103,
kCGLRPAccumModes => 104,
kCGLRPDepthModes => 105,
kCGLRPStencilModes => 106,
kCGLRPMaxAuxBuffers => 107,
kCGLRPMaxSampleBuffers => 108,
kCGLRPMaxSamples => 109,
kCGLRPSampleModes => 110,
kCGLRPSampleAlpha => 111,
kCGLRPVideoMemory => 120,
kCGLRPTextureMemory => 121,
kCGLRPGPUVertProcCapable => 122,
kCGLRPGPUFragProcCapable => 123,
kCGLRPRendererCount => 128,
kCGLRPOnline => 129,
kCGLRPAcceleratedCompute => 130,
kCGLRPVideoMemoryMegabytes => 131,
kCGLRPTextureMemoryMegabytes => 132
);
for CGLRendererProperty'Size use C_Enum_Size;
pragma Convention (C, CGLRendererProperty);
for CGLContextEnable use (kCGLCESwapRectangle => 201,
kCGLCESwapLimit => 203,
kCGLCERasterization => 221,
kCGLCEStateValidation => 301,
kCGLCESurfaceBackingSize => 305,
kCGLCEDisplayListOptimization => 307,
kCGLCEMPEngine => 313,
kCGLCECrashOnRemovedFunctions => 316
);
for CGLContextEnable'Size use C_Enum_Size;
pragma Convention (C, CGLContextEnable);
for CGLContextParameter use (kCGLCPSwapRectangle => 200,
kCGLCPSwapInterval => 222,
kCGLCPDispatchTableSize => 224,
kCGLCPClientStorage => 226,
kCGLCPSurfaceTexture => 228,
kCGLCPSurfaceOrder => 235,
kCGLCPSurfaceOpacity => 236,
kCGLCPSurfaceBackingSize => 304,
kCGLCPSurfaceSurfaceVolatile => 306,
kCGLCPReclaimResources => 308,
kCGLCPCurrentRendererID => 309,
kCGLCPGPUVertexProcessing => 310,
kCGLCPGPUFragmentProcessing => 311,
kCGLCPHasDrawable => 314,
kCGLCPMPSwapsInFlight => 315
);
for CGLContextParameter'Size use C_Enum_Size;
pragma Convention (C, CGLContextParameter);
for CGLGlobalOption use (kCGLGOFormatCacheSize => 501,
kCGLGOClearFormatCache => 502,
kCGLGORetainRenderers => 503,
kCGLGOResetLibrary => 504,
kCGLGOUseErrorHandler => 505,
kCGLGOUseBuildCache => 506
);
for CGLGlobalOption'Size use C_Enum_Size;
pragma Convention (C, CGLGlobalOption);
for CGLOpenGLProfile use (kCGLOGLPVersion_Legacy => 16#1000#,
kCGLOGLPVersion_3_2_Core => 16#3200#
);
for CGLOpenGLProfile'Size use C_Enum_Size;
pragma Convention (C, CGLOpenGLProfile);
for CGLError use (kCGLNoError => 0,
kCGLBadAttribute => 10000,
kCGLBadProperty => 10001,
kCGLBadPixelFormat => 10002,
kCGLBadRendererInfo => 10003,
kCGLBadContext => 10004,
kCGLBadDrawable => 10005,
kCGLBadDisplay => 10006,
kCGLBadState => 10007,
kCGLBadValue => 10008,
kCGLBadMatch => 10009,
kCGLBadEnumeration => 10010,
kCGLBadOffScreen => 10011,
kCGLBadFullScreen => 10012,
kCGLBadWindow => 10013,
kCGLBadAddress => 10014,
kCGLBadCodeModule => 10015,
kCGLBadAlloc => 10016,
kCGLBadConnection => 10017
);
for CGLError'Size use C_Enum_Size;
pragma Convention (C, CGLError);
pragma Import (C, CGLChoosePixelFormat, "CGLChoosePixelFormat");
pragma Import (C, CGLDestroyPixelFormat, "CGLDestroyPixelFormat");
pragma Import (C, CGLDescribePixelFormat, "CGLDescribePixelFormat");
pragma Import (C, CGLReleasePixelFormat, "CGLReleasePixelFormat");
pragma Import (C, CGLRetainPixelFormat, "CGLRetainPixelFormat");
pragma Import (C, CGLGetPixelFormatRetainCount, "CGLGetPixelFormatRetainCount");
pragma Import (C, CGLQueryRendererInfo, "CGLQueryRendererInfo");
pragma Import (C, CGLDestroyRendererInfo, "CGLDestroyRendererInfo");
pragma Import (C, CGLDescribeRenderer, "CGLDescribeRenderer");
pragma Import (C, CGLCreateContext, "CGLCreateContext");
pragma Import (C, CGLDestroyContext, "CGLDestroyContext");
pragma Import (C, CGLCopyContext, "CGLCopyContext");
pragma Import (C, CGLRetainContext, "CGLRetainContext");
pragma Import (C, CGLReleaseContext, "CGLReleaseContext");
pragma Import (C, CGLGetContextRetainCount, "CGLGetContextRetainCount");
pragma Import (C, CGLGetPixelFormat, "CGLGetPixelFormat");
pragma Import (C, CGLCreatePBuffer, "CGLCreatePBuffer");
pragma Import (C, CGLDestroyPBuffer, "CGLDestroyPBuffer");
pragma Import (C, CGLDescribePBuffer, "CGLDescribePBuffer");
pragma Import (C, CGLTexImagePBuffer, "CGLTexImagePBuffer");
pragma Import (C, CGLRetainPBuffer, "CGLRetainPBuffer");
pragma Import (C, CGLReleasePBuffer, "CGLReleasePBuffer");
pragma Import (C, CGLGetPBufferRetainCount, "CGLGetPBufferRetainCount");
pragma Import (C, CGLSetOffScreen, "CGLSetOffScreen");
pragma Import (C, CGLGetOffScreen, "CGLGetOffScreen");
pragma Import (C, CGLSetFullScreen, "CGLSetFullScreen");
pragma Import (C, CGLSetFullScreenOnDisplay, "CGLSetFullScreenOnDisplay");
pragma Import (C, CGLSetPBuffer, "CGLSetPBuffer");
pragma Import (C, CGLGetPBuffer, "CGLGetPBuffer");
pragma Import (C, CGLClearDrawable, "CGLClearDrawable");
pragma Import (C, CGLFlushDrawable, "CGLFlushDrawable");
pragma Import (C, CGLEnable, "CGLEnable");
pragma Import (C, CGLDisable, "CGLDisable");
pragma Import (C, CGLIsEnabled, "CGLIsEnabled");
pragma Import (C, CGLSetParameter, "CGLSetParameter");
pragma Import (C, CGLGetParameter, "CGLGetParameter");
pragma Import (C, CGLSetVirtualScreen, "CGLSetVirtualScreen");
pragma Import (C, CGLGetVirtualScreen, "CGLGetVirtualScreen");
pragma Import (C, CGLUpdateContext, "CGLUpdateContext");
pragma Import (C, CGLSetGlobalOption, "CGLSetGlobalOption");
pragma Import (C, CGLGetGlobalOption, "CGLGetGlobalOption");
pragma Import (C, CGLSetOption, "CGLSetOption");
pragma Import (C, CGLGetOption, "CGLGetOption");
pragma Import (C, CGLLockContext, "CGLLockContext");
pragma Import (C, CGLUnlockContext, "CGLUnlockContext");
pragma Import (C, CGLGetVersion, "CGLGetVersion");
pragma Import (C, CGLErrorString, "CGLErrorString");
pragma Import (C, CGLSetCurrentContext, "CGLSetCurrentContext");
pragma Import (C, CGLGetCurrentContext, "CGLGetCurrentContext");
end GL.CGL;
|
AdaCore/libadalang | Ada | 295 | adb | with Ada.Exceptions; use Ada.Exceptions;
with Ada.Text_IO; use Ada.Text_IO;
procedure Test_Exc is begin
raise Constraint_Error with "Lol what a complicated way to print";
exception
when E : Constraint_Error =>
Put_Line (Exception_Message (E));
pragma Test_Statement_UID;
end Test_Exc;
|
shintakezou/langkit | Ada | 2,432 | adb | with Ada.Text_IO; use Ada.Text_IO;
with GNAT.Source_Info;
with Langkit_Support.Adalog.Main_Support;
use Langkit_Support.Adalog.Main_Support;
-- Copy of the dyn_scheduling test. The interest is to see that debug
-- information in relation printing works correclty, i.e. that it is correctly
-- shown when printing a relation.
procedure Main is
use T_Solver, Refs, Solver_Ifc;
function S return String renames GNAT.Source_Info.Source_Location;
function Is_Even (Val : Integer) return Boolean is (Val mod 2 = 0);
function Is_Even (Var : Refs.Logic_Var; Dbg_String : String) return Relation
is (Predicate
(Var, Predicate (Is_Even'Access, "Is_Even"), Dbg_String));
X : constant Refs.Logic_Var := Create ("X");
Y : constant Refs.Logic_Var := Create ("Y");
Relations : constant array (Positive range <>) of Relation :=
(Unify (X, Y, Dbg_String => S) and Domain (X, (1, 2, 3), S),
-- Simple dynamic scheduling: the second relation must be evaluated
-- before the first one.
R_All((Domain (X, (1, 2, 3), S),
R_Any ((Domain (X, (10, 20)), Is_Even (Y, S)), S),
Domain (Y, (1, 3, 5, 10), S)), S),
-- The second AND relation (OR) cannot be evaluated completely, but it
-- makes progress.
R_All ((Is_Even (Y, S), Domain (X, (1, 2, 3), S)), S),
-- Unsolvable equation: nothing provides a value for Y, but the equation
-- still makes progress.
R_All ((Is_Even (Y, S), Is_Even (X, S)), S),
-- Likewise, but the equation makes no progress at all
R_Any ((Is_Even (Y, S), Domain (X, (1, 2), S)), S),
-- Likewise, but for ANY relations
R_Any ((Is_Even (X, S), Is_Even (Y, S)), S),
R_Any ((Is_Even (X, S),
R_All ((Domain (X, (1, 2, 3), S), Is_Even (Y, S)), S)), S),
R_All ((Domain (X, (1, 2, 3), S),
Is_Even (Y, S),
Domain (X, (1 => 2), S),
Unify (X, Y, S)), S)
-- Make sure that back-tracking, which happens for the second Member,
-- properly resets the state so that the second evaluation of this
-- second Member actually checks something. Without a proper reset, this
-- stateful relation just yields Unsatisfied.
);
begin
for R of Relations loop
Put_Line ((1 .. 72 => '='));
New_Line;
Reset (X);
Reset (Y);
Solve_All (R);
end loop;
end Main;
|
AdaCore/gpr | Ada | 47 | ads | package Pack1 is
procedure Dummy;
end Pack1; |
AdaCore/libadalang | Ada | 98 | ads | with Pkg_G.Child_Pkg_G;
package My_Pkg.My_Child_Pkg is new Child_Pkg_G (Foo);
pragma Test_Block;
|
charlie5/dynamic_distributed_computing | Ada | 488 | ads | package DDC.Worker.local
--
-- Provides a concrete Worker.
--
is
type Item is limited new DDC.Worker.item with private;
type View is access all Item'Class;
type Views is array (Positive range <>) of View;
procedure define (Self : access Item);
overriding
procedure process (Self : access Item; the_Samples : in Samples);
private
type Item is limited new DDC.Worker.item with
record
Id : worker_Id;
end record;
end DDC.Worker.local;
|
reznikmm/matreshka | Ada | 4,187 | adb | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Open Document Toolkit --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2013, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
with Matreshka.DOM_Nodes;
with XML.DOM.Elements.Internals;
package body ODF.DOM.Elements.Table.Table.Internals is
------------
-- Create --
------------
function Create
(Node : Matreshka.ODF_Elements.Table.Table.Table_Table_Access)
return ODF.DOM.Elements.Table.Table.ODF_Table_Table is
begin
return
(XML.DOM.Elements.Internals.Create
(Matreshka.DOM_Nodes.Element_Access (Node)) with null record);
end Create;
----------
-- Wrap --
----------
function Wrap
(Node : Matreshka.ODF_Elements.Table.Table.Table_Table_Access)
return ODF.DOM.Elements.Table.Table.ODF_Table_Table is
begin
return
(XML.DOM.Elements.Internals.Wrap
(Matreshka.DOM_Nodes.Element_Access (Node)) with null record);
end Wrap;
end ODF.DOM.Elements.Table.Table.Internals;
|
reznikmm/matreshka | Ada | 4,067 | 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_Reverse_Direction_Attributes;
package Matreshka.ODF_Chart.Reverse_Direction_Attributes is
type Chart_Reverse_Direction_Attribute_Node is
new Matreshka.ODF_Chart.Abstract_Chart_Attribute_Node
and ODF.DOM.Chart_Reverse_Direction_Attributes.ODF_Chart_Reverse_Direction_Attribute
with null record;
overriding function Create
(Parameters : not null access Matreshka.DOM_Attributes.Attribute_L2_Parameters)
return Chart_Reverse_Direction_Attribute_Node;
overriding function Get_Local_Name
(Self : not null access constant Chart_Reverse_Direction_Attribute_Node)
return League.Strings.Universal_String;
end Matreshka.ODF_Chart.Reverse_Direction_Attributes;
|
thieryw/snake | Ada | 1,960 | adb | with snake_functions,snake_types,ada.calendar,display,ada.text_io ;
use ada.text_io,ada.calendar ;
procedure main is
s : snake_types.Snake ;
dir : snake_types.Snake_direction:=snake_types.LEFT ;
has_new_user_input: boolean;
user_requested_direction : snake_types.Snake_direction ;
user_controls_default : snake_types.User_Controls.Map;
fruit : snake_types.Coordinates ;
fruit_timeout : integer ;
score : integer := 0 ;
timestamp : ada.calendar.time= clock ;
begin
user_controls_default := snake_functions.get_user_controls_default ;
s := snake_functions.create_snake ;
snake_functions.generate_fruit(s, fruit,fruit_timeout) ;
loop
snake_functions.render_game(s,fruit) ;
snake_functions.retreve_user_input(
has_new_user_input,
user_requested_direction,
user_controls_default
) ;
if has_new_user_input then
snake_functions.update_direction(dir,user_requested_direction) ;
end if ;
--FIXME: generate fruit and timeout
snake_functions.move_snake(s,dir,fruit,does_eat_fruit) ;
if snake_functions.is_end_of_game(s) then
exit ;
end if ;
fruit_timeout := fruit_timeout - 1 ;
if fruit_timeout = 0 then
snake_functions.generate_fruit(s, fruit,fruit_timeout) ;
end if ;
--FIXME
put_line("SCORE : " & integer'image(score)) ;
delay 0.1 - (timestamp - clock) ;
timestamp := ada.calendar.clock ;
end loop ;
put_line("YOU LOSE MOTHER FUCKER") ;
delay 3.0 ;
end main ;
|
jhumphry/parse_args | Ada | 3,117 | ads | -- generic_example_options
-- An example of the use of parse_args with generic option types
-- Copyright (c) 2015, James Humphry
--
-- Permission to use, copy, modify, and/or distribute this software for any
-- purpose with or without fee is hereby granted, provided that the above
-- copyright notice and this permission notice appear in all copies.
--
-- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
-- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
-- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
-- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
-- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
-- OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
-- PERFORMANCE OF THIS SOFTWARE.
with Ada.Unchecked_Deallocation;
with Parse_Args;
use Parse_Args;
with Parse_Args.Generic_Discrete_Options;
with Parse_Args.Generic_Options;
with Parse_Args.Generic_Indefinite_Options;
with Parse_Args.Split_CSV;
package Generic_Example_Options is
type Compass is (North, South, East, West);
package Compass_Option is new Generic_Discrete_Options(Element => Compass,
Fallback_Default => North);
procedure Is_Even(Arg : in Integer; Result : in out Boolean);
package Even_Option is new Generic_Discrete_Options(Element => Natural,
Fallback_Default => 0,
Valid => Is_Even);
package Float_Option is new Generic_Options(Element => Float,
Fallback_Default => 0.0,
Value => Float'Value,
Image => Float'Image);
type Float_Array is array (Integer range <>) of Float;
type Float_Array_Access is access Float_Array;
procedure Free_Float_Array is
new Ada.Unchecked_Deallocation(Object => Float_Array,
Name => Float_Array_Access);
function Split_Float_Array is new Split_CSV(Element => Float,
Element_Array => Float_Array,
Element_Array_Access => Float_Array_Access,
Value => Float'Value);
function Float_Array_Image(Arg : Float_Array_Access) return String is
("<Float array of length: " & Integer'Image(Arg.all'Length) & ">");
package Float_Array_Option is new Generic_Indefinite_Options(Element => Float_Array,
Element_Access => Float_Array_Access,
Value => Split_Float_Array,
Image => Float_Array_Image,
Free_Element => Free_Float_Array);
end Generic_Example_Options;
|
reznikmm/matreshka | Ada | 4,198 | ads | ------------------------------------------------------------------------------
-- --
-- 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 System.Storage_Elements;
with Interfaces;
with League.Calendars;
package Matreshka.Internals.SQL_Drivers.Oracle.Utils is
subtype Storage_Array is System.Storage_Elements.Storage_Array (1 .. 22);
function Decode_Number (Buffer : Storage_Array) return String;
procedure Encode_Number
(Image : String;
Buffer : in out Storage_Array);
type OCIDate is record
Year : Interfaces.Integer_16;
Month : Interfaces.Unsigned_8;
Day : Interfaces.Unsigned_8;
HH : Interfaces.Unsigned_8;
MM : Interfaces.Unsigned_8;
SS : Interfaces.Unsigned_8;
end record
with Pack, Convention => C;
function Encode_Date (Value : League.Calendars.Date) return OCIDate;
function Decode_Date (Buffer : OCIDate) return League.Calendars.Date;
end Matreshka.Internals.SQL_Drivers.Oracle.Utils;
|
zhmu/ananas | Ada | 523 | adb | -- { dg-do run }
with System;
procedure align_check is
N_Allocated_Buffers : Natural := 0;
--
function New_Buffer (N_Bytes : Natural) return System.Address is
begin
N_Allocated_Buffers := N_Allocated_Buffers + 1;
return System.Null_Address;
end;
--
Buffer_Address : constant System.Address := New_Buffer (N_Bytes => 8);
N : Natural;
for N'Address use Buffer_Address;
--
begin
if N_Allocated_Buffers /= 1 then
raise Program_Error;
end if;
end;
|
reznikmm/matreshka | Ada | 4,761 | ads | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Open Document Toolkit --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2014, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
with XML.DOM.Visitors;
with ODF.DOM.Form_Formatted_Text_Elements;
package Matreshka.ODF_Form.Formatted_Text_Elements is
type Form_Formatted_Text_Element_Node is
new Matreshka.ODF_Form.Abstract_Form_Element_Node
and ODF.DOM.Form_Formatted_Text_Elements.ODF_Form_Formatted_Text
with null record;
overriding function Create
(Parameters : not null access Matreshka.DOM_Elements.Element_L2_Parameters)
return Form_Formatted_Text_Element_Node;
overriding function Get_Local_Name
(Self : not null access constant Form_Formatted_Text_Element_Node)
return League.Strings.Universal_String;
overriding procedure Enter_Node
(Self : not null access Form_Formatted_Text_Element_Node;
Visitor : in out XML.DOM.Visitors.Abstract_Visitor'Class;
Control : in out XML.DOM.Visitors.Traverse_Control);
overriding procedure Leave_Node
(Self : not null access Form_Formatted_Text_Element_Node;
Visitor : in out XML.DOM.Visitors.Abstract_Visitor'Class;
Control : in out XML.DOM.Visitors.Traverse_Control);
overriding procedure Visit_Node
(Self : not null access Form_Formatted_Text_Element_Node;
Iterator : in out XML.DOM.Visitors.Abstract_Iterator'Class;
Visitor : in out XML.DOM.Visitors.Abstract_Visitor'Class;
Control : in out XML.DOM.Visitors.Traverse_Control);
end Matreshka.ODF_Form.Formatted_Text_Elements;
|
melwyncarlo/ProjectEuler | Ada | 303 | adb | with Ada.Text_IO;
with Ada.Integer_Text_IO;
-- Copyright 2021 Melwyn Francis Carlo
procedure A037 is
use Ada.Text_IO;
use Ada.Integer_Text_IO;
Str : constant String (1 .. 12) := "Hello World ";
Num : constant Integer := 2021;
begin
Put (Str);
Put (Num, Width => 0);
end A037;
|
AdaCore/langkit | Ada | 1,600 | ads | --
-- Copyright (C) 2014-2022, AdaCore
-- SPDX-License-Identifier: Apache-2.0
--
-- This package Contains the debug configuration for Adalog. There are two
-- main ways of configuring the debug mode in Adalog:
--
-- - The Debug_Enabled constant will determine at compile time whether
-- debugging is enabled or not. If it is False, no traces will be output,
-- and the Step mode won't be usable.
-- - If you set the Debug_Enabled constant to True, you still need to activate
-- a debug mode at runtime via Set_Debug_State.
package Langkit_Support.Adalog.Debug is
type Debug_State_Type is (None, Trace, Step, Step_At_First_Unsat);
-- Set the debug state for Adalog:
--
-- - If Trace, will trace the execution.
-- - If Step, will trace and stop at every step of the solve so that you
-- can trace the solve operation step-by-step.
-- - If Step_At_First_Unsat, will trace the execution, and set the mode to
-- Step as soon as *any* relation solving returns Unsatisfied.
--
-- WARNING: Trace and step mode are not thread safe. It would not make any
-- sense to try to use them with solving happening in several threads at
-- the same time.
Debug_Enabled : constant Boolean := True;
function Debug return Boolean
with Inline;
procedure Set_Debug_State (Val : Debug_State_Type);
-- Set the debug state
function Debug_State return Debug_State_Type;
-- Get the debug state
procedure Trace (Str : String);
-- Will output a string to stdout only if Debug is in Trace | Step
end Langkit_Support.Adalog.Debug;
|
BrickBot/Bound-T-H8-300 | Ada | 5,043 | ads | -- Calling.Stacked (decl)
--
-- Calling protocols that depend on the stack-heights at the call.
-- This class of protocol should be used only when the processor
-- and program under analysis have some stacks.
--
-- A component of the Bound-T Worst-Case Execution Time Tool.
--
-------------------------------------------------------------------------------
-- Copyright (c) 1999 .. 2015 Tidorum Ltd
-- All rights reserved.
--
-- Redistribution and use in source and binary forms, with or without
-- modification, are permitted provided that the following conditions are met:
--
-- 1. Redistributions of source code must retain the above copyright notice, this
-- list of conditions and the following disclaimer.
-- 2. Redistributions in binary form must reproduce the above copyright notice,
-- this list of conditions and the following disclaimer in the documentation
-- and/or other materials provided with the distribution.
--
-- This software is provided by the copyright holders and contributors "as is" and
-- any express or implied warranties, including, but not limited to, the implied
-- warranties of merchantability and fitness for a particular purpose are
-- disclaimed. In no event shall the copyright owner or contributors be liable for
-- any direct, indirect, incidental, special, exemplary, or consequential damages
-- (including, but not limited to, procurement of substitute goods or services;
-- loss of use, data, or profits; or business interruption) however caused and
-- on any theory of liability, whether in contract, strict liability, or tort
-- (including negligence or otherwise) arising in any way out of the use of this
-- software, even if advised of the possibility of such damage.
--
-- Other modules (files) of this software composition should contain their
-- own copyright statements, which may have different copyright and usage
-- conditions. The above conditions apply to this file.
-------------------------------------------------------------------------------
--
-- $Revision: 1.3 $
-- $Date: 2015/10/24 19:36:48 $
--
-- $Log: calling-stacked.ads,v $
-- Revision 1.3 2015/10/24 19:36:48 niklas
-- Moved to free licence.
--
-- Revision 1.2 2007-12-17 13:54:35 niklas
-- BT-CH-0098: Assertions on stack usage and final stack height, etc.
--
-- Revision 1.1 2005/02/23 09:05:17 niklas
-- BT-CH-0005.
--
with Programs;
with Storage;
with Storage.Bounds;
package Calling.Stacked is
type Stack_Height_Intervals_T is
array (Programs.Stack_Index_T range <>) of Storage.Bounds.Interval_T;
--
-- Interval bounds on the stack height of all stacks.
type Protocol_T (Num_Stacks : Natural) is abstract new Calling.Protocol_T
with record
Program : Programs.Program_T;
Intervals : Stack_Height_Intervals_T (1 .. Num_Stacks) := (
others => Storage.Bounds.Universal_Interval);
end record;
--
-- A class of calling protocols for which dynamic cell mapping
-- depends only on the values of the local stack height for all
-- stacks in the caller at the point of call.
--
-- The protocol can be constrained by bounding the value of the
-- local stack heights using the Intervals. The protocol is static
-- if the Intervals define a single value for each stack height,
-- that is, if Storage.Bounds.Singular (Intervals(S)) is True
-- for all S in Intervals'Range.
--
-- The initial value for Intervals reflects a completely unknown
-- value or range of local stack height.
--
-- Program
-- The program in which the protocol occurs.
-- The basis cells are Programs.Height for Programs.Stacks (Program)
-- excluding those bounded to a single value.
-- Intervals
-- The current bounds on the stack-height cells as determined for
-- this instance of the protocol.
type Protocol_Ref is access all Protocol_T'Class;
--
-- A reference to a stacked protocol object on the heap.
function Static (Item : Protocol_T) return Boolean;
--
-- True if Item.Intervals allows a single value for each stack-height
-- cell.
--
-- Overrides (implements) Storage.Bounds.Static.
function Basis (Item : Protocol_T) return Storage.Cell_List_T;
--
-- Returns those stack-height cells for which Item.Intervals allows
-- more than one value.
--
-- Overrides (implements) Storage.Bounds.Basis.
function Image (Item : Protocol_T) return String;
--
-- Returns "Stack" followed by the Intervals, separated by commas.
procedure Apply (
Bounds : in Storage.Bounds.Bounds_T'Class;
Upon : in Protocol_T;
Giving : out Calling.Protocol_Ref);
--
-- Uses the Bounds on the stack-height cells to constrain Upon.Intervals
-- and thus perhaps Giving a more constrained protocol which is the
-- same as the given one but with a narrower Upon.Interval. Returns
-- Giving as null if the Bounds do not constrain Upon.Intervals further.
--
-- Overrides (implements) Calling.Apply.
end Calling.Stacked;
|
damaki/SPARKNaCl | Ada | 1,853 | adb | with SPARKNaCl; use SPARKNaCl;
with SPARKNaCl.MAC; use SPARKNaCl.MAC;
with SPARKNaCl.Debug; use SPARKNaCl.Debug;
procedure Onetimeauth
is
RS : constant Poly_1305_Key :=
Construct ((16#ee#, 16#a6#, 16#a7#, 16#25#,
16#1c#, 16#1e#, 16#72#, 16#91#,
16#6d#, 16#11#, 16#c2#, 16#cb#,
16#21#, 16#4d#, 16#3c#, 16#25#,
16#25#, 16#39#, 16#12#, 16#1d#,
16#8e#, 16#23#, 16#4e#, 16#65#,
16#2d#, 16#65#, 16#1f#, 16#a4#,
16#c8#, 16#cf#, 16#f8#, 16#80#));
C : constant Byte_Seq (0 .. 130) :=
(16#8e#, 16#99#, 16#3b#, 16#9f#, 16#48#, 16#68#, 16#12#, 16#73#,
16#c2#, 16#96#, 16#50#, 16#ba#, 16#32#, 16#fc#, 16#76#, 16#ce#,
16#48#, 16#33#, 16#2e#, 16#a7#, 16#16#, 16#4d#, 16#96#, 16#a4#,
16#47#, 16#6f#, 16#b8#, 16#c5#, 16#31#, 16#a1#, 16#18#, 16#6a#,
16#c0#, 16#df#, 16#c1#, 16#7c#, 16#98#, 16#dc#, 16#e8#, 16#7b#,
16#4d#, 16#a7#, 16#f0#, 16#11#, 16#ec#, 16#48#, 16#c9#, 16#72#,
16#71#, 16#d2#, 16#c2#, 16#0f#, 16#9b#, 16#92#, 16#8f#, 16#e2#,
16#27#, 16#0d#, 16#6f#, 16#b8#, 16#63#, 16#d5#, 16#17#, 16#38#,
16#b4#, 16#8e#, 16#ee#, 16#e3#, 16#14#, 16#a7#, 16#cc#, 16#8a#,
16#b9#, 16#32#, 16#16#, 16#45#, 16#48#, 16#e5#, 16#26#, 16#ae#,
16#90#, 16#22#, 16#43#, 16#68#, 16#51#, 16#7a#, 16#cf#, 16#ea#,
16#bd#, 16#6b#, 16#b3#, 16#73#, 16#2b#, 16#c0#, 16#e9#, 16#da#,
16#99#, 16#83#, 16#2b#, 16#61#, 16#ca#, 16#01#, 16#b6#, 16#de#,
16#56#, 16#24#, 16#4a#, 16#9e#, 16#88#, 16#d5#, 16#f9#, 16#b3#,
16#79#, 16#73#, 16#f6#, 16#22#, 16#a4#, 16#3d#, 16#14#, 16#a6#,
16#59#, 16#9b#, 16#1f#, 16#65#, 16#4c#, 16#b4#, 16#5a#, 16#74#,
16#e3#, 16#55#, 16#a5#);
A : Bytes_16;
begin
Onetimeauth (A, C, RS);
DH ("A is", A);
end Onetimeauth;
|
stcarrez/ada-security | Ada | 1,944 | ads | -----------------------------------------------------------------------
-- security-auth-oauth-googleplus -- Google+ OAuth based authentication
-- Copyright (C) 2013 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 Security.OAuth.Clients;
-- === Google+ ===
-- The Google+ authentication is based on OAuth 2.0 and the OpenID Connect Basic Client Profile.
--
-- See https://developers.google.com/accounts/docs/OAuth2Login
package Security.Auth.OAuth.Googleplus is
-- ------------------------------
-- OAuth Manager
-- ------------------------------
-- The <b>Manager</b> provides the core operations for the OAuth authorization process.
type Manager is new Security.Auth.OAuth.Manager with private;
-- Verify the OAuth access token and retrieve information about the user.
overriding
procedure Verify_Access_Token (Realm : in Manager;
Assoc : in Association;
Request : in Parameters'Class;
Token : in Security.OAuth.Clients.Access_Token_Access;
Result : in out Authentication);
private
type Manager is new Security.Auth.OAuth.Manager with null record;
end Security.Auth.OAuth.Googleplus;
|
jscparker/math_packages | Ada | 15,003 | adb |
---------------------------------------------------------------------------
-- package body Hessenberg
-- Copyright (C) 2011-2018 Jonathan S. Parker
--
-- Permission to use, copy, modify, and/or distribute this software for any
-- purpose with or without fee is hereby granted, provided that the above
-- copyright notice and this permission notice appear in all copies.
-- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
-- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
-- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
-- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
-- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
---------------------------------------------------------------------------
with Ada.Numerics;
with Ada.Numerics.Generic_Elementary_Functions;
with Givens_Rotation;
package body Hessenberg is
package math is new Ada.Numerics.Generic_Elementary_Functions (Real); use math;
package Rotate is new Givens_Rotation (Real); use Rotate;
Zero : constant Real := +0.0;
One : constant Real := +1.0;
Two : constant Real := +2.0;
function Identity return A_Matrix is
Q : A_Matrix;
begin
Q := (others => (others => Zero));
for c in C_Index loop
Q(c, c) := One;
end loop;
return Q;
end Identity;
----------------------
-- Upper_Hessenberg --
----------------------
-- Operates only on square real blocks.
--
-- Want to use similarity transforms to make A into H,
-- upper Hessenberg. Let Qj be a 2x2 givens rotation matrix,
-- and let Qj' be its transpose (and inverse). Then form
--
-- A =
--
-- (Q1*...*Qn) * (Qn'*...*Q1') * A * (Q1*...*Qn) * (Qn'*...*Q1') =
--
-- Q * H * Q',
--
-- where H = Q' * A * Q.
--
-- To complete the decomposition of A to H, insert Qj * Qj' into
-- Q * H * Q' to get Q * (Qj * Qj') * H * (Qj * Qj') * Q'.
--
-- So to develop Q, we rotate columns of Q by multiplying on RHS with
-- Qj. H gets multiplied on the LHS by Qj' (rotating rows to zero out
-- the lower triangular region) and on the RHS by Qj.
--
-- Wind up with the eigenvalue equation A = Q * H * Q' which becomes
--
-- A * Q = Q * H.
--
-- If H were diagonal, then the column vectors of Q would be the eigenvectors
-- and the diagonal elements of H would be the eigenvalues.
procedure Upper_Hessenberg
(A : in out A_Matrix;
Q : out A_Matrix;
Starting_Col : in C_Index := C_Index'First;
Final_Col : in C_Index := C_Index'Last;
Initial_Q : in A_Matrix := Identity)
is
Final_Row : constant C_Index := Final_Col;
Pivot_Row : R_Index;
---------------------------------------
-- Rotate_to_Kill_Element_Lo_of_pCol --
---------------------------------------
-- Zero out A(Lo_Row, pCol) with a similarity transformation. In
-- other words, multiply A on left by Q_tr and on right by Q:
-- A_h = Q_transpose * A * Q
procedure Rotate_to_Kill_Element_Lo_of_pCol
(pCol : in C_Index;
Hi_Row : in R_Index;
Lo_Row : in R_Index)
is
sn, cs : Real;
cs_minus_1 : Real;
sn_minus_1 : Real;
hypot : Real;
P_bigger_than_L : Boolean;
Skip_Rotation : Boolean;
Pivot_Col : C_Index renames pCol;
Pivot_Row : R_Index renames Hi_Row;
Low_Row : R_Index renames Lo_Row;
A_pvt, A_low, Q_pvt, Q_low : Real;
P : constant Real := A(Pivot_Row, Pivot_Col); -- P is for Pivot
L : constant Real := A(Low_Row, Pivot_Col);
begin
Get_Rotation_That_Zeros_Out_Low
(P, L, sn, cs, cs_minus_1, sn_minus_1, hypot, P_bigger_than_L, Skip_Rotation);
if Skip_Rotation then return; end if;
-- Rotate rows. Multiply on LHS by givens rotation G.
-- Want Q' A Q = H = upper hessenberg.
-- Each step is: G A G' = partial H
-- So the desired Q will be the product of the G' matrices
-- which we obtain by repeatedly multiplying I on the RHS by G'.
if P_bigger_than_L then -- |s| < |c|
for c in Pivot_Col .. Final_Col loop
A_pvt := A(Pivot_Row, c);
A_low := A(Low_Row, c);
A(Pivot_Row, c) := A_pvt + ( cs_minus_1*A_pvt + sn*A_low);
A(Low_Row, c) := A_low + (-sn*A_pvt + cs_minus_1*A_low);
end loop;
else -- Abs_P <= Abs_L, so abs t := abs (P / L) <= 1
for c in Pivot_Col .. Final_Col loop
A_pvt := A(Pivot_Row, c);
A_low := A(Low_Row, c);
A(Pivot_Row, c) := A_low + ( cs*A_pvt + sn_minus_1*A_low);
A(Low_Row, c) :=-A_pvt + (-sn_minus_1*A_pvt + cs*A_low);
end loop;
end if;
A(Pivot_Row, Pivot_Col) := Real'Copy_Sign (Hypot, A(Pivot_Row, Pivot_Col));
-- Rotate corresponding columns. Multiply on RHS by transpose
-- of above givens matrix (second step of similarity transformation).
-- (Low_Row is Lo visually, but its index is higher than Pivot's.)
if P_bigger_than_L then -- |s| < |c|
for r in Starting_Col .. Final_Col loop
A_pvt := A(r, Pivot_Row);
A_low := A(r, Low_Row);
A(r, Pivot_Row) := A_pvt + ( cs_minus_1*A_pvt + sn*A_low);
A(r, Low_Row) := A_low + (-sn*A_pvt + cs_minus_1*A_low);
end loop;
else -- Abs_P <= Abs_L, so abs t := abs (P / L) <= 1
for r in Starting_Col .. Final_Col loop
A_pvt := A(r, Pivot_Row);
A_low := A(r, Low_Row);
A(r, Pivot_Row) := A_low + ( cs*A_pvt + sn_minus_1*A_low);
A(r, Low_Row) :=-A_pvt + (-sn_minus_1*A_pvt + cs*A_low);
end loop;
end if;
-- Rotate corresponding columns of Q. (Multiply on RHS by transpose
-- of above givens matrix to accumulate full Q.)
if P_bigger_than_L then -- |s| < |c|
for r in Starting_Col .. Final_Col loop
Q_pvt := Q(r, Pivot_Row);
Q_low := Q(r, Low_Row);
Q(r, Pivot_Row) := Q_pvt + ( cs_minus_1*Q_pvt + sn*Q_low);
Q(r, Low_Row) := Q_low + (-sn*Q_pvt + cs_minus_1*Q_low);
end loop;
else -- Abs_P <= Abs_L, so abs t := abs (P / L) <= 1
for r in Starting_Col .. Final_Col loop
Q_pvt := Q(r, Pivot_Row);
Q_low := Q(r, Low_Row);
Q(r, Pivot_Row) := Q_low + ( cs*Q_pvt + sn_minus_1*Q_low);
Q(r, Low_Row) :=-Q_pvt + (-sn_minus_1*Q_pvt + cs*Q_low);
end loop;
end if;
end Rotate_to_Kill_Element_Lo_of_pCol;
type Column is array(R_Index) of Real;
procedure Get_Sqrt_of_Sum_of_Sqrs_of_Col
(Col_Id : in C_Index;
Starting_Row : in R_Index;
Ending_Row : in R_Index;
Col_Sums : out Column)
is
Max : Real := Zero;
Un_Scale, Scale : Real := Zero;
Emin : constant Integer := Real'Machine_Emin;
Emax : constant Integer := Real'Machine_Emax;
Abs_A : Real := Zero;
M_exp : Integer := 0;
begin
Max := Abs A(Starting_Row, Col_Id);
if Ending_Row > Starting_Row then
for i in Starting_Row+1 .. Ending_Row loop
Abs_A := Abs A(i, Col_Id);
if Abs_A > Max then Max := Abs_A; end if;
end loop;
end if;
if Max < Two**Emin then Col_Sums := (others => Zero); return; end if;
if Max < Two**(Emin / 2) or else Max > Two**(Emax / 4) then
M_Exp := Real'Exponent (Max);
Scale := Two ** (-M_Exp);
Un_Scale := Two ** ( M_Exp);
else
Scale := One;
Un_Scale := One;
end if;
Col_Sums(Starting_Row) := Abs A(Starting_Row, Col_Id);
if Ending_Row > Starting_Row then
Compensated_Sum:
declare
val, Sum_tmp, Err, Sum : Real := Zero;
begin
for r in Starting_Row .. Ending_Row loop
Val := (Scale * A(r, Col_Id)) ** 2;
Val := Val - Err; -- correction to Val, next term in sum.
Sum_tmp := Sum + Val; -- now increment Sum
Err := (Sum_tmp - Sum) - Val;
Sum := Sum_tmp;
Col_Sums(r) := Un_Scale * Sqrt (Sum);
end loop;
end Compensated_Sum;
end if;
end Get_Sqrt_of_Sum_of_Sqrs_of_Col;
Col_Sums : Column := (others => Zero);
begin
Q := Initial_Q;
if (Final_Col - Starting_Col) < 2 then return; end if;
for Pivot_Col in Starting_Col .. Final_Col-2 loop
Pivot_Row := Pivot_Col + 1;
Get_Sqrt_of_Sum_of_Sqrs_of_Col -- version _2 Only takes Sqrt of full column sum
(Col_id => Pivot_Col,
Starting_Row => Pivot_Row,
Ending_Row => Final_Row,
Col_Sums => Col_Sums);
for Low_Row in Pivot_Row+1 .. Final_Row loop
Rotate_to_Kill_Element_Lo_of_pCol -- zero out A(Lo_Row, pCol)
(pCol => Pivot_Col,
Hi_Row => Pivot_Row, -- Hi = high to eye; its id is lower than Lo_Row.
Lo_Row => Low_Row);
A(Low_Row, Pivot_Col) := Zero;
A(Pivot_Row, Pivot_Col) :=
Real'Copy_Sign (Col_Sums(Low_Row), A(Pivot_Row, Pivot_Col));
end loop; -- over Low_Row
end loop; -- over Pivot_Col
end Upper_Hessenberg;
----------------------
-- Lower_Hessenberg --
----------------------
procedure Lower_Hessenberg
(A : in out A_Matrix;
Q : out A_Matrix;
Starting_Col : in C_Index := C_Index'First;
Final_Col : in C_Index := C_Index'Last;
Initial_Q : in A_Matrix := Identity)
is
Starting_Row : constant C_Index := Starting_Col;
Final_Row : constant C_Index := Final_Col;
Pivot_Col : R_Index := Starting_Col;
---------------------------------------
-- Rotate_to_Kill_Element_Hi_of_pRow --
---------------------------------------
-- Zero out A(Lo_Row, pCol) with a similarity transformation. In
-- other words, multiply A on left by Q_tr and on right by Q:
-- A_h = Q_transpose * A * Q
-- Use enhanced precision rotations here.
procedure Rotate_to_Kill_Element_Hi_of_pRow
(pRow : in R_Index;
Lo_Col : in R_Index;
Hi_Col : in R_Index)
is
sn, cs : Real;
cs_minus_1 : Real;
sn_minus_1 : Real;
hypot : Real;
P_bigger_than_H : Boolean;
Skip_Rotation : Boolean;
Pivot_Row : R_Index renames pRow;
Pivot_Col : C_Index renames Lo_Col;
A_pvt, A_hi , Q_pvt, Q_hi : Real;
P : constant Real := A(Pivot_Row, Pivot_Col); -- P is for Pivot
H : constant Real := A(Pivot_Row, Hi_Col);
pragma Assert(Pivot_Col = Pivot_Row+1);
begin
Get_Rotation_That_Zeros_Out_Low
(P, H, sn, cs, cs_minus_1, sn_minus_1, hypot, P_bigger_than_H, Skip_Rotation);
if Skip_Rotation then return; end if;
-- Rotate columns. Multiply on RHS by transpose
-- of above givens matrix (second step of similarity transformation).
-- (Hi_Col is to the rt. visually, and its index is higher than Pivot's.)
if P_bigger_than_H then -- |s| < |c|
for r in Starting_Row .. Final_Row loop
A_pvt := A(r, Pivot_Col);
A_hi := A(r, Hi_Col);
A(r, Pivot_Col) := A_pvt + ( cs_minus_1*A_pvt + sn*A_hi);
A(r, Hi_Col) := A_hi + (-sn*A_pvt + cs_minus_1*A_hi);
end loop;
else -- Abs_P <= Abs_H, so abs t := abs (P / H) <= 1
for r in Pivot_Row .. Final_Row loop
A_pvt := A(r, Pivot_Col);
A_hi := A(r, Hi_Col);
A(r, Pivot_Col) := A_hi + ( cs*A_pvt + sn_minus_1*A_hi);
A(r, Hi_Col) :=-A_pvt + (-sn_minus_1*A_pvt + cs*A_hi);
end loop;
end if;
-- Rotate corresponding columns of Q. (Multiply on RHS by transpose
-- of above givens matrix to accumulate full Q.)
if P_bigger_than_H then -- |s| < |c|
for r in Starting_Col .. Final_Col loop
Q_pvt := Q(r, Pivot_Col);
Q_hi := Q(r, Hi_Col);
Q(r, Pivot_Col) := Q_pvt + ( cs_minus_1*Q_pvt + sn*Q_hi);
Q(r, Hi_Col) := Q_hi + (-sn*Q_pvt + cs_minus_1*Q_hi);
end loop;
else -- Abs_P <= Abs_H, so abs t := abs (P / H) <= 1
for r in Starting_Col .. Final_Col loop
Q_pvt := Q(r, Pivot_Col);
Q_hi := Q(r, Hi_Col);
Q(r, Pivot_Col) := Q_hi + ( cs*Q_pvt + sn_minus_1*Q_hi);
Q(r, Hi_Col) :=-Q_pvt + (-sn_minus_1*Q_pvt + cs*Q_hi);
end loop;
end if;
-- Rotate rows. Multiply on LHS by givens rotation G.
-- Want Q' A Q = H = upper hessenberg.
-- Each step is: G A G' = partial H
-- So the desired Q will be the product of the G' matrices
-- which we obtain by repeatedly multiplying I on the RHS by G'.
if P_bigger_than_H then -- |s| < |c|
for c in Starting_Col .. Final_Col loop
A_pvt := A(Pivot_Col, c);
A_hi := A(Hi_Col, c);
A(Pivot_Col, c) := A_pvt + ( cs_minus_1*A_pvt + sn*A_hi);
A(Hi_Col, c) := A_hi + (-sn*A_pvt + cs_minus_1*A_hi);
end loop;
else -- Abs_P <= Abs_H, so abs t := abs (P / H) <= 1
for c in Starting_Col .. Final_Col loop
A_pvt := A(Pivot_Col, c);
A_hi := A(Hi_Col, c);
A(Pivot_Col, c) := A_hi + ( cs*A_pvt + sn_minus_1*A_hi);
A(Hi_Col, c) :=-A_pvt + (-sn_minus_1*A_pvt + cs*A_hi);
end loop;
end if;
end Rotate_to_Kill_Element_Hi_of_pRow;
begin
Q := Initial_Q;
if (Final_Col - Starting_Col) < 2 then return; end if;
for Pivot_Row in Starting_Row .. Final_Row-2 loop
Pivot_Col := Pivot_Row + 1; -- the lower off-diagonal
for Hi_Col in Pivot_Col+1 .. Final_Col loop
Rotate_to_Kill_Element_Hi_of_pRow -- zero out A(pRow, Hi_Col)
(pRow => Pivot_Row,
Lo_Col => Pivot_Col,
Hi_Col => Hi_Col);
A(Pivot_Row, Hi_Col) := Zero;
end loop; -- over Low_Row
end loop; -- over Pivot_Col
end Lower_Hessenberg;
end Hessenberg;
|
sungyeon/drake | Ada | 420 | ads | pragma License (Unrestricted);
-- implementation unit specialized for Linux
with C.signal;
package System.Interrupt_Numbers is
pragma Preelaborate;
First_Interrupt_Id : constant := C.signal.SIGHUP;
Last_Interrupt_Id : constant := C.signal.NSIG - 1;
-- SIGRTMAX (__libc_current_sigrtmax) = NSIG - 1 = 64
function Is_Reserved (Interrupt : C.signed_int) return Boolean;
end System.Interrupt_Numbers;
|
stcarrez/ada-util | Ada | 2,774 | ads | ------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- A U N I T . R E P O R T E R . X M L --
-- --
-- S p e c --
-- --
-- --
-- Copyright (C) 2000-2008, 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 2, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
-- for more details. You should have received a copy of the GNU General --
-- Public License distributed with GNAT; see file COPYING. If not, write --
-- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
-- Boston, MA 02110-1301, USA. --
-- --
-- GNAT is maintained by AdaCore (http://www.adacore.com) --
-- --
------------------------------------------------------------------------------
with AUnit.Reporter;
with AUnit.Test_Results;
with AUnit.Options;
with Ada.Text_IO;
with Ada.Strings.Unbounded;
-- XML reporter (fix AUnit issues and generate in a separate file instead of stdout).
package Util.Tests.Reporter is
type XML_Reporter is new AUnit.Reporter.Reporter with record
File : Ada.Strings.Unbounded.Unbounded_String;
end record;
overriding
procedure Report (Engine : in XML_Reporter;
R : in out AUnit.Test_Results.Result'Class;
Options : in AUnit.Options.AUnit_Options := AUnit.Options.Default_Options);
procedure Report (Engine : XML_Reporter;
File : in out Ada.Text_IO.File_Type;
R : in out AUnit.Test_Results.Result'Class);
end Util.Tests.Reporter;
|
davidkristola/vole | Ada | 1,836 | ads | with Ada.Containers.Vectors;
with Interfaces;
with kv.Ref_Counting_Mixin;
with kv.avm.Ini;
with kv.avm.Clients;
with kv.avm.Servers;
with kv.avm.Control;
package kv.avm.Affiliates is
type Affiliates_Type is tagged private;
procedure Initialize
(Self : in out Affiliates_Type;
Settings : in kv.avm.Ini.Settings_Type;
Server : in kv.avm.Servers.Server_Access;
Factory : in kv.avm.Clients.Factory_Access;
Machine : in kv.avm.Control.Control_Access);
function Client_Count(Self : Affiliates_Type) return Natural;
function Get_Client(Self : Affiliates_Type; Index : Positive) return kv.avm.Clients.Client_Access;
function Get_Domain_Client(Self : Affiliates_Type; Domain : Interfaces.Unsigned_32) return kv.avm.Clients.Client_Access;
procedure Open_Clients
(Self : in out Affiliates_Type);
-- Clients and the server are asynchronous entities and they periodically need to be polled
-- to pass data back and forth. They are not allowed to interrupt the main thread.
--
procedure Periodic_Processing
(Self : in out Affiliates_Type);
private
use kv.avm.Clients;
package Client_Lists is new Ada.Containers.Vectors
(Index_Type => Positive,
Element_Type => kv.avm.Clients.Client_Access);
type Affiliate_Data_Type is
record
Clients : Client_Lists.Vector;
Server : kv.avm.Servers.Server_Access;
Machine : kv.avm.Control.Control_Access;
Factory : kv.avm.Clients.Factory_Access;
end record;
type Affiliate_Access is access Affiliate_Data_Type;
package Ref_Count is new kv.Ref_Counting_Mixin(Affiliate_Data_Type, Affiliate_Access);
type Affiliates_Type is tagged
record
Ref : Ref_Count.Ref_Type;
end record;
end kv.avm.Affiliates;
|
reznikmm/matreshka | Ada | 4,601 | 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_Office.Display_Attributes is
------------
-- Create --
------------
overriding function Create
(Parameters : not null access Matreshka.DOM_Attributes.Attribute_L2_Parameters)
return Office_Display_Attribute_Node is
begin
return Self : Office_Display_Attribute_Node do
Matreshka.ODF_Office.Constructors.Initialize
(Self'Unchecked_Access,
Parameters.Document,
Matreshka.ODF_String_Constants.Office_Prefix);
end return;
end Create;
--------------------
-- Get_Local_Name --
--------------------
overriding function Get_Local_Name
(Self : not null access constant Office_Display_Attribute_Node)
return League.Strings.Universal_String
is
pragma Unreferenced (Self);
begin
return Matreshka.ODF_String_Constants.Display_Attribute;
end Get_Local_Name;
begin
Matreshka.DOM_Documents.Register_Attribute
(Matreshka.ODF_String_Constants.Office_URI,
Matreshka.ODF_String_Constants.Display_Attribute,
Office_Display_Attribute_Node'Tag);
end Matreshka.ODF_Office.Display_Attributes;
|
AdaCore/gpr | Ada | 4,447 | ads | ------------------------------------------------------------------------------
-- --
-- GPR2 PROJECT MANAGER --
-- --
-- Copyright (C) 2019-2023, AdaCore --
-- --
-- This is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. This software is distributed in the hope that it will be useful, --
-- but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- --
-- TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public --
-- License for more details. You should have received a copy of the GNU --
-- General Public License distributed with GNAT; see file COPYING. If not, --
-- see <http://www.gnu.org/licenses/>. --
-- --
------------------------------------------------------------------------------
-- Common utilities for all gpr tools
with Ada.Command_Line;
with GPR2.Path_Name;
with GPRtools.Options;
package GPRtools.Util is
use GPR2;
type Exit_Code_Type is
(E_Success, -- No warnings or errors
E_Warnings, -- Compiler warnings generated
E_No_Code, -- No code generated
E_No_Compile, -- Compilation not needed (smart recompilation)
E_Errors, -- Compiler error messages generated
E_Fatal, -- Fatal (serious) error, e.g. source file not found
E_Abort); -- Internally detected compiler error
procedure Set_Program_Name (Name : String);
-- Set GPR_TOOL environment variable if it is not yet defined.
-- Note: gprclean, gprbuild, gprls, gprname, gprinstall, gprdump & gprdoc
-- tools are setting GPR_TOOL to gprbuild instead of their own names.
procedure Output_Messages
(Options : GPRtools.Options.Base_Options'Class);
-- Output errors and if Verbose is True other messages from Log.
function Is_Ada_Predefined_Unit (Unit : Name_Type) return Boolean;
-- Return True if Unit is an Ada runtime unit
function Executable_Prefix_Path return String;
-- Return the absolute path parent directory of the directory where the
-- current executable resides, if its directory is named "bin", otherwise
-- return an empty string. When a directory is returned, it is guaranteed
-- to end with a directory separator.
function Locate_Exec_On_Path (Exec_Name : String) return String;
-- Get the path location of a given executable
-------------------------
-- Program termination --
-------------------------
procedure Fail_Program (Message : String);
-- Terminate program with a message and a fatal status code
procedure Project_Processing_Failed
(Options : GPRtools.Options.Base_Options'Class);
-- Output or not project processing error messages depend on Verbose
-- parameters. Output error message '"proj.gpr" processing failed' at the
-- end if not Quiet.
function Check_For_Default_Project return GPR2.Path_Name.Object;
-- Look for default project in the current directory,
-- return Undefined if no or several projects are in the current
-- directory.
procedure Finish_Program
(Exit_Code : Exit_Code_Type := E_Success;
Message : String := "");
-- Terminate program, with or without a message, setting the status code
-- according to Exit_Code.
procedure Exit_Program (Exit_Code : Exit_Code_Type);
pragma No_Return (Exit_Program);
-- A call to Exit_Program terminates execution with the given status.
-- A status of zero indicates normal completion, a non-zero status
-- indicates abnormal termination.
function Exit_Code
(Code : Exit_Code_Type) return Ada.Command_Line.Exit_Status;
-- Translate Code as Exit_Status
function Partial_Name
(Lib_Name : Simple_Name;
Number : Natural;
Object_Suffix : Simple_Name) return Simple_Name;
-- Returns the name of an object file created by the partial linker
end GPRtools.Util;
|
wooky/aoc | Ada | 1,918 | adb | with AOC; use AOC;
function Day10 (F : Aoc_File) return Solution is
type Unformatted_CRT_Display is array(1 .. 40 * 6) of Character;
type CPU_Parameters is record
Signal_Strength : Natural := 0;
Cycle : Natural := 0;
Cycles_To_Wait : Natural := 0;
Target_Cycle : Positive := 20;
X : Integer := 1;
CRT : Unformatted_CRT_Display;
end record;
procedure Wait_Cycles (CPU: in out CPU_Parameters) is
begin
while CPU.Cycles_To_Wait /= 0 loop
if CPU.Cycle mod 40 in CPU.X - 1 .. CPU.X + 1 then
CPU.CRT (CPU.Cycle + 1) := '#';
else
CPU.CRT (CPU.Cycle + 1) := '.';
end if;
CPU.Cycles_To_Wait := CPU.Cycles_To_Wait - 1;
CPU.Cycle := CPU.Cycle + 1;
if CPU.Cycle = CPU.Target_Cycle then
CPU.Signal_Strength := CPU.Signal_Strength + CPU.Target_Cycle * CPU.X;
CPU.Target_Cycle := CPU.Target_Cycle + 40;
end if;
end loop;
end Wait_Cycles;
CPU : CPU_Parameters;
begin
declare
begin
while not End_Of_File (F) loop
declare
Line : String := Get_Line (F);
begin
if Line = "noop" then
CPU.Cycles_To_Wait := 1;
else
CPU.Cycles_To_Wait := 2;
end if;
Wait_Cycles (CPU);
if Line /= "noop" then
declare
V : Integer := Integer'Value (Line (6 .. Line'Last));
begin
CPU.X := CPU.X + V;
end;
end if;
end;
end loop;
end;
Wait_Cycles (CPU);
declare
type Formatted_CRT_Display is array(1 .. 41 * 6) of Character;
CRT : Formatted_CRT_Display;
begin
for Row in 0 .. 5 loop
for Column in 1 .. 40 loop
CRT (Row * 41 + Column) := CPU.CRT (Row * 40 + Column);
end loop;
CRT (Row * 41 + 41) := Character'Val (10);
end loop;
return New_Solution (S1 => CPU.Signal_Strength'Image, S2 => String (CRT));
end;
end Day10;
|
sungyeon/drake | Ada | 19,046 | adb | -- diff (Ada.Exceptions.Finally)
with Ada.Unchecked_Conversion;
with Ada.Unchecked_Deallocation;
with System;
package body Ada.Containers.Hashed_Maps is
use type Hash_Tables.Table_Access;
use type Copy_On_Write.Data_Access;
function Upcast is
new Unchecked_Conversion (Cursor, Hash_Tables.Node_Access);
function Downcast is
new Unchecked_Conversion (Hash_Tables.Node_Access, Cursor);
function Upcast is
new Unchecked_Conversion (Data_Access, Copy_On_Write.Data_Access);
function Downcast is
new Unchecked_Conversion (Copy_On_Write.Data_Access, Data_Access);
-- diff
-- diff
procedure Free is new Unchecked_Deallocation (Node, Cursor);
type Context_Type is limited record
Left : not null access Key_Type;
end record;
pragma Suppress_Initialization (Context_Type);
function Equivalent_Key (
Position : not null Hash_Tables.Node_Access;
Params : System.Address)
return Boolean;
function Equivalent_Key (
Position : not null Hash_Tables.Node_Access;
Params : System.Address)
return Boolean
is
Context : Context_Type;
for Context'Address use Params;
begin
return Equivalent_Keys (
Context.Left.all,
Downcast (Position).Key);
end Equivalent_Key;
-- diff (Allocate_Element)
--
--
--
--
--
--
--
--
procedure Allocate_Node (
Item : out Cursor;
Key : Key_Type;
New_Item : Element_Type);
procedure Allocate_Node (
Item : out Cursor;
Key : Key_Type;
New_Item : Element_Type) is
-- diff
-- diff
-- diff
-- diff
-- diff
-- diff
-- diff
-- diff
-- diff
-- diff
begin
Item := new Node'(Super => <>, Key => Key, Element => New_Item);
-- diff
-- diff
-- diff
-- diff
end Allocate_Node;
procedure Copy_Node (
Target : out Hash_Tables.Node_Access;
Source : not null Hash_Tables.Node_Access);
procedure Copy_Node (
Target : out Hash_Tables.Node_Access;
Source : not null Hash_Tables.Node_Access)
is
Source_Node : constant Cursor := Downcast (Source);
New_Node : Cursor;
begin
Allocate_Node (New_Node, Source_Node.Key, Source_Node.Element);
Target := Upcast (New_Node);
end Copy_Node;
procedure Free_Node (Object : in out Hash_Tables.Node_Access);
procedure Free_Node (Object : in out Hash_Tables.Node_Access) is
X : Cursor := Downcast (Object);
begin
-- diff
-- diff
Free (X);
Object := null;
end Free_Node;
procedure Allocate_Data (
Target : out not null Copy_On_Write.Data_Access;
New_Length : Count_Type;
Capacity : Count_Type);
procedure Allocate_Data (
Target : out not null Copy_On_Write.Data_Access;
New_Length : Count_Type;
Capacity : Count_Type)
is
pragma Unreferenced (New_Length);
New_Data : constant Data_Access :=
new Data'(Super => <>, Table => null, Length => 0);
begin
Hash_Tables.Rebuild (New_Data.Table, Capacity);
Target := Upcast (New_Data);
end Allocate_Data;
procedure Copy_Data (
Target : out not null Copy_On_Write.Data_Access;
Source : not null Copy_On_Write.Data_Access;
Length : Count_Type;
New_Length : Count_Type;
Capacity : Count_Type);
procedure Copy_Data (
Target : out not null Copy_On_Write.Data_Access;
Source : not null Copy_On_Write.Data_Access;
Length : Count_Type;
New_Length : Count_Type;
Capacity : Count_Type)
is
pragma Unreferenced (Length);
pragma Unreferenced (New_Length);
New_Data : constant Data_Access :=
new Data'(Super => <>, Table => null, Length => 0);
begin
Hash_Tables.Copy (
New_Data.Table,
New_Data.Length,
Downcast (Source).Table,
Capacity,
Copy => Copy_Node'Access);
Target := Upcast (New_Data);
end Copy_Data;
procedure Free is new Unchecked_Deallocation (Data, Data_Access);
procedure Free_Data (Data : in out Copy_On_Write.Data_Access);
procedure Free_Data (Data : in out Copy_On_Write.Data_Access) is
X : Data_Access := Downcast (Data);
begin
Hash_Tables.Free (X.Table, X.Length, Free => Free_Node'Access);
Free (X);
Data := null;
end Free_Data;
procedure Reallocate (
Container : in out Map;
Capacity : Count_Type;
To_Update : Boolean);
procedure Reallocate (
Container : in out Map;
Capacity : Count_Type;
To_Update : Boolean) is
begin
Copy_On_Write.Unique (
Target => Container.Super'Access,
Target_Length => 0, -- Length is unused
Target_Capacity => Hashed_Maps.Capacity (Container),
New_Length => 0,
New_Capacity => Capacity,
To_Update => To_Update,
Allocate => Allocate_Data'Access,
Move => Copy_Data'Access,
Copy => Copy_Data'Access,
Free => Free_Data'Access,
Max_Length => Copy_On_Write.Zero'Access);
end Reallocate;
procedure Unique (Container : in out Map; To_Update : Boolean);
procedure Unique (Container : in out Map; To_Update : Boolean) is
begin
if Copy_On_Write.Shared (Container.Super.Data) then
Reallocate (
Container,
Capacity (Container), -- not shrinking
To_Update);
end if;
end Unique;
function Find (Container : Map; Hash : Hash_Type; Key : Key_Type)
return Cursor;
function Find (Container : Map; Hash : Hash_Type; Key : Key_Type)
return Cursor is
begin
if Is_Empty (Container) then
return null;
else
Unique (Container'Unrestricted_Access.all, False);
declare
Context : aliased Context_Type :=
(Left => Key'Unrestricted_Access);
begin
return Downcast (Hash_Tables.Find (
Downcast (Container.Super.Data).Table,
Hash,
Context'Address,
Equivalent => Equivalent_Key'Access));
end;
end if;
end Find;
-- implementation
function Empty_Map return Map is
begin
return (Finalization.Controlled with Super => (null, null));
end Empty_Map;
function Has_Element (Position : Cursor) return Boolean is
begin
return Position /= null;
end Has_Element;
overriding function "=" (Left, Right : Map) return Boolean is
function Equivalent (Left, Right : not null Hash_Tables.Node_Access)
return Boolean;
function Equivalent (Left, Right : not null Hash_Tables.Node_Access)
return Boolean is
begin
return Equivalent_Keys (
Downcast (Left).Key,
Downcast (Right).Key)
and then Downcast (Left).Element =
Downcast (Right).Element;
end Equivalent;
Left_Length : constant Count_Type := Length (Left);
Right_Length : constant Count_Type := Length (Right);
begin
if Left_Length /= Right_Length then
return False;
elsif Left_Length = 0 or else Left.Super.Data = Right.Super.Data then
return True;
else
Unique (Left'Unrestricted_Access.all, False); -- private
Unique (Right'Unrestricted_Access.all, False); -- private
declare
Left_Data : constant Data_Access := Downcast (Left.Super.Data);
Right_Data : constant Data_Access := Downcast (Right.Super.Data);
begin
return Hash_Tables.Equivalent (
Left_Data.Table,
Left_Data.Length,
Right_Data.Table,
Right_Data.Length,
Equivalent => Equivalent'Access);
end;
end if;
end "=";
function Capacity (Container : Map) return Count_Type is
Data : constant Data_Access := Downcast (Container.Super.Data);
begin
if Data = null then
return 0;
else
return Hash_Tables.Capacity (Data.Table);
end if;
end Capacity;
procedure Reserve_Capacity (
Container : in out Map;
Capacity : Count_Type)
is
New_Capacity : constant Count_Type :=
Count_Type'Max (Capacity, Length (Container));
begin
Reallocate (Container, New_Capacity, True);
end Reserve_Capacity;
function Length (Container : Map) return Count_Type is
Data : constant Data_Access := Downcast (Container.Super.Data);
begin
if Data = null then
return 0;
else
return Data.Length;
end if;
end Length;
function Is_Empty (Container : Map) return Boolean is
Data : constant Data_Access := Downcast (Container.Super.Data);
begin
return Data = null or else Data.Length = 0;
end Is_Empty;
procedure Clear (Container : in out Map) is
begin
Copy_On_Write.Clear (Container.Super'Access, Free => Free_Data'Access);
end Clear;
function Key (Position : Cursor) return Key_Type is
begin
return Position.Key;
end Key;
function Element (Position : Cursor) return Element_Type is
begin
return Position.Element;
end Element;
procedure Replace_Element (
Container : in out Map;
Position : Cursor;
New_Item : Element_Type) is
begin
Unique (Container, True);
-- diff
Position.Element := New_Item;
end Replace_Element;
procedure Query_Element (
Position : Cursor;
Process : not null access procedure (
Key : Key_Type;
Element : Element_Type)) is
begin
Process (Position.Key, Position.Element);
end Query_Element;
procedure Update_Element (
Container : in out Map'Class;
Position : Cursor;
Process : not null access procedure (
Key : Key_Type;
Element : in out Element_Type)) is
begin
Process (
Position.Key,
Reference (Map (Container), Position).Element.all);
end Update_Element;
function Constant_Reference (Container : aliased Map; Position : Cursor)
return Constant_Reference_Type
is
pragma Unreferenced (Container);
begin
return (Element => Position.all.Element'Access); -- [gcc-6] .all
end Constant_Reference;
function Reference (Container : aliased in out Map; Position : Cursor)
return Reference_Type is
begin
Unique (Container, True);
-- diff
return (Element => Position.all.Element'Access); -- [gcc-6] .all
end Reference;
function Constant_Reference (Container : aliased Map; Key : Key_Type)
return Constant_Reference_Type is
begin
return Constant_Reference (Container, Find (Container, Key));
end Constant_Reference;
function Reference (Container : aliased in out Map; Key : Key_Type)
return Reference_Type is
begin
return Reference (Container, Find (Container, Key));
end Reference;
procedure Assign (Target : in out Map; Source : Map) is
begin
Copy_On_Write.Assign (
Target.Super'Access,
Source.Super'Access,
Free => Free_Data'Access);
end Assign;
function Copy (Source : Map; Capacity : Count_Type := 0) return Map is
begin
return Result : Map do
Copy_On_Write.Copy (
Result.Super'Access,
Source.Super'Access,
0, -- Length is unused
Count_Type'Max (Capacity, Length (Source)),
Allocate => Allocate_Data'Access,
Copy => Copy_Data'Access);
end return;
end Copy;
procedure Move (Target : in out Map; Source : in out Map) is
begin
Copy_On_Write.Move (
Target.Super'Access,
Source.Super'Access,
Free => Free_Data'Access);
-- diff
end Move;
procedure Insert (
Container : in out Map;
Key : Key_Type;
New_Item : Element_Type;
Position : out Cursor;
Inserted : out Boolean)
is
-- diff
-- diff
-- diff
-- diff
-- diff
-- diff
-- diff
-- diff
-- diff
-- diff
-- diff
-- diff
-- diff
-- diff
New_Hash : constant Hash_Type := Hash (Key);
begin
-- diff
-- diff
Position := Find (Container, New_Hash, Key);
Inserted := Position = null;
if Inserted then
Unique (Container, True);
Allocate_Node (Position, Key, New_Item);
declare
Data : constant Data_Access := Downcast (Container.Super.Data);
begin
Hash_Tables.Insert (
Data.Table,
Data.Length,
New_Hash,
Upcast (Position));
end;
end if;
end Insert;
procedure Insert (
Container : in out Map;
Key : Key_Type;
Position : out Cursor;
Inserted : out Boolean)
is
New_Hash : constant Hash_Type := Hash (Key);
begin
Position := Find (Container, New_Hash, Key);
Inserted := Position = null;
if Inserted then
Unique (Container, True);
Position := new Node'(Super => <>, Key => Key, Element => <>);
declare
Data : constant Data_Access := Downcast (Container.Super.Data);
begin
Hash_Tables.Insert (
Data.Table,
Data.Length,
New_Hash,
Upcast (Position));
end;
end if;
end Insert;
procedure Insert (
Container : in out Map;
Key : Key_Type;
New_Item : Element_Type)
is
Position : Cursor;
Inserted : Boolean;
begin
Insert (Container, Key, New_Item, Position, Inserted);
if not Inserted then
raise Constraint_Error;
end if;
end Insert;
procedure Include (
Container : in out Map;
Key : Key_Type;
New_Item : Element_Type)
is
Position : Cursor;
Inserted : Boolean;
begin
Insert (Container, Key, New_Item, Position, Inserted);
if not Inserted then
Replace_Element (Container, Position, New_Item);
end if;
end Include;
procedure Replace (
Container : in out Map;
Key : Key_Type;
New_Item : Element_Type) is
begin
Replace_Element (Container, Find (Container, Key), New_Item);
end Replace;
procedure Exclude (Container : in out Map; Key : Key_Type) is
Position : Cursor := Find (Container, Key);
begin
if Position /= null then
Delete (Container, Position);
end if;
end Exclude;
procedure Delete (Container : in out Map; Key : Key_Type) is
Position : Cursor := Find (Container, Key);
begin
Delete (Container, Position);
end Delete;
procedure Delete (Container : in out Map; Position : in out Cursor) is
Position_2 : Hash_Tables.Node_Access := Upcast (Position);
begin
Unique (Container, True);
declare
Data : constant Data_Access := Downcast (Container.Super.Data);
begin
Hash_Tables.Remove (Data.Table, Data.Length, Position_2);
end;
Free_Node (Position_2);
Position := null;
end Delete;
function First (Container : Map) return Cursor is
begin
if Is_Empty (Container) then
return null;
else
Unique (Container'Unrestricted_Access.all, False);
return Downcast (Hash_Tables.First (
Downcast (Container.Super.Data).Table));
end if;
end First;
function Next (Position : Cursor) return Cursor is
begin
return Downcast (Position.Super.Next);
end Next;
procedure Next (Position : in out Cursor) is
begin
Position := Downcast (Position.Super.Next);
end Next;
function Find (Container : Map; Key : Key_Type) return Cursor is
begin
return Find (Container, Hash (Key), Key);
end Find;
function Element (
Container : Map'Class;
Key : Key_Type)
return Element_Type is
begin
return Element (Find (Map (Container), Key));
end Element;
function Contains (Container : Map; Key : Key_Type) return Boolean is
begin
return Find (Container, Key) /= null;
end Contains;
function Equivalent_Keys (Left, Right : Cursor) return Boolean is
begin
return Equivalent_Keys (Left.Key, Right.Key);
end Equivalent_Keys;
function Equivalent_Keys (Left : Cursor; Right : Key_Type) return Boolean is
begin
return Equivalent_Keys (Left.Key, Right);
end Equivalent_Keys;
function Equivalent_Keys (Left : Key_Type; Right : Cursor) return Boolean is
begin
return Equivalent_Keys (Left, Right.Key);
end Equivalent_Keys;
procedure Iterate (
Container : Map'Class;
Process : not null access procedure (Position : Cursor))
is
type P1 is access procedure (Position : Cursor);
type P2 is access procedure (Position : Hash_Tables.Node_Access);
function Cast is new Unchecked_Conversion (P1, P2);
begin
if not Is_Empty (Map (Container)) then
Unique (Map (Container)'Unrestricted_Access.all, False);
Hash_Tables.Iterate (
Downcast (Container.Super.Data).Table,
Cast (Process));
end if;
end Iterate;
function Iterate (Container : Map'Class)
return Map_Iterator_Interfaces.Forward_Iterator'Class is
begin
return Map_Iterator'(First => First (Map (Container)));
end Iterate;
overriding procedure Adjust (Object : in out Map) is
begin
Copy_On_Write.Adjust (Object.Super'Access);
end Adjust;
overriding function First (Object : Map_Iterator) return Cursor is
begin
return Object.First;
end First;
overriding function Next (Object : Map_Iterator; Position : Cursor)
return Cursor
is
pragma Unreferenced (Object);
begin
return Next (Position);
end Next;
package body Streaming is
procedure Read (
Stream : not null access Streams.Root_Stream_Type'Class;
Item : out Map)
is
Length : Count_Type'Base;
begin
Count_Type'Base'Read (Stream, Length);
Clear (Item);
for I in 1 .. Length loop
declare
New_Key : Key_Type;
Position : Cursor;
Inserted : Boolean;
begin
Key_Type'Read (Stream, New_Key);
Insert (Item, New_Key, Position, Inserted);
Element_Type'Read (Stream, Position.Element);
end;
end loop;
end Read;
procedure Write (
Stream : not null access Streams.Root_Stream_Type'Class;
Item : Map)
is
Length : constant Count_Type := Hashed_Maps.Length (Item);
begin
Count_Type'Write (Stream, Length);
if Length > 0 then
declare
Position : Cursor := First (Item);
begin
while Position /= null loop
Key_Type'Write (Stream, Position.Key);
Element_Type'Write (Stream, Position.Element);
Next (Position);
end loop;
end;
end if;
end Write;
end Streaming;
end Ada.Containers.Hashed_Maps;
|
clairvoyant/anagram | Ada | 9,656 | ads | -- Copyright (c) 2010-2017 Maxim Reznik <[email protected]>
--
-- SPDX-License-Identifier: MIT
-- License-Filename: LICENSE
-------------------------------------------------------------
with League.Strings;
package Anagram.Grammars is
pragma Preelaborate;
package S renames League.Strings;
type Terminal_Count is new Natural;
type Non_Terminal_Count is new Natural;
type Production_Count is new Natural;
type Part_Count is new Natural;
type Attribute_Declaration_Count is new Natural;
type Attribute_Count is new Natural;
type Rule_Count is new Natural;
subtype Terminal_Index is Terminal_Count range 1 .. Terminal_Count'Last;
subtype Non_Terminal_Index is Non_Terminal_Count
range 1 .. Non_Terminal_Count'Last;
subtype Production_Index is Production_Count
range 1 .. Production_Count'Last;
subtype Part_Index is Part_Count range 1 .. Part_Count'Last;
subtype Attribute_Declaration_Index is Attribute_Declaration_Count
range 1 .. Attribute_Declaration_Count'Last;
subtype Attribute_Index is Attribute_Count
range 1 .. Attribute_Count'Last;
subtype Rule_Index is Rule_Count range 1 .. Rule_Count'Last;
type Terminal is tagged private;
function Image (Self : Terminal) return S.Universal_String;
function Index (Self : Terminal) return Terminal_Index;
function First_Attribute
(Self : Terminal)
return Attribute_Declaration_Index;
function Last_Attribute
(Self : Terminal)
return Attribute_Declaration_Count;
type Non_Terminal is tagged private;
function Is_List (Self : Non_Terminal) return Boolean;
function Name (Self : Non_Terminal) return S.Universal_String;
function Index (Self : Non_Terminal) return Non_Terminal_Index;
function First (Self : Non_Terminal) return Production_Index;
function Last (Self : Non_Terminal) return Production_Count;
function First_Attribute
(Self : Non_Terminal)
return Attribute_Declaration_Index;
function Last_Attribute
(Self : Non_Terminal)
return Attribute_Declaration_Count;
type Production is tagged private;
function Name (Self : Production) return S.Universal_String;
function Index (Self : Production) return Production_Index;
function First (Self : Production) return Part_Index;
function Last (Self : Production) return Part_Count;
function First_Rule (Self : Production) return Rule_Index;
function Last_Rule (Self : Production) return Rule_Count;
function Parent (Self : Production) return Non_Terminal_Count;
function First_Attribute
(Self : Production)
return Attribute_Declaration_Index;
function Last_Attribute
(Self : Production)
return Attribute_Declaration_Count;
type Part is tagged private;
function Name (Self : Part) return S.Universal_String;
function Index (Self : Part) return Part_Index;
function Is_Terminal_Reference (Self : Part) return Boolean;
function Is_Non_Terminal_Reference (Self : Part) return Boolean;
function Is_List_Reference (Self : Part) return Boolean;
function Denote (Self : Part) return Terminal_Count;
-- Only if Is_Terminal_Reference
function Denote (Self : Part) return Non_Terminal_Count;
-- Only if Is_Non_Terminal_Reference or Is_List_Reference
function Is_Option (Self : Part) return Boolean;
-- Only if Is_Option:
function First (Self : Part) return Production_Index;
function Last (Self : Part) return Production_Count;
function Parent (Self : Part) return Production_Index;
type Attribute_Declaration is tagged private;
function Is_Inherited (Self : Attribute_Declaration) return Boolean;
function Is_Synthesized (Self : Attribute_Declaration) return Boolean;
function Is_Local (Self : Attribute_Declaration) return Boolean;
function Name
(Self : Attribute_Declaration)
return S.Universal_String;
function Type_Name
(Self : Attribute_Declaration)
return S.Universal_String;
function Index
(Self : Attribute_Declaration)
return Attribute_Declaration_Index;
type Attribute is tagged private;
function Has_Default (Self : Attribute) return Boolean;
function Is_Left_Hand_Side (Self : Attribute) return Boolean;
-- Attribute occurence for Non_Termilan itself or local attribute
function Index (Self : Attribute) return Attribute_Index;
function Parent (Self : Attribute) return Rule_Index;
function Origin (Self : Attribute) return Part_Count;
-- Only if not Is_Left_Hand_Side
function Declaration
(Self : Attribute)
return Attribute_Declaration_Index;
type Rule is tagged private;
function Index (Self : Rule) return Rule_Index;
function Result (Self : Rule) return Attribute_Index;
function First_Argument (Self : Rule) return Attribute_Index;
function Last_Argument (Self : Rule) return Attribute_Count;
function Parent (Self : Rule) return Production_Index;
function Text (Self : Rule) return S.Universal_String;
type Associate_Kind is (Undefined, None, Left, Right);
type Precedence_Level is new Natural;
type Precedence_Value (Associative : Associate_Kind := Undefined) is record
case Associative is
when Undefined =>
null;
when None | Left | Right =>
Level : Precedence_Level;
end case;
end record;
Undefined_Precedence : constant Precedence_Value :=
(Associative => Undefined);
function Precedence (Self : Terminal) return Precedence_Value;
function Precedence (Self : Production) return Precedence_Value;
type Terminal_Array is array (Terminal_Index range <>) of aliased Terminal;
type Non_Terminal_Array is array (Non_Terminal_Index range <>) of
aliased Non_Terminal;
type Production_Array is array (Production_Index range <>) of
aliased Production;
type Part_Array is array (Part_Index range <>) of aliased Part;
type Declaration_Array is array (Attribute_Declaration_Index range <>) of
aliased Attribute_Declaration;
type Attribute_Array is array (Attribute_Index range <>) of
aliased Attribute;
type Rule_Array is array (Rule_Index range <>) of aliased Rule;
type Grammar
(Last_Terminal : Terminal_Count;
Last_Non_Terminal : Non_Terminal_Count;
Last_Production : Production_Count;
Last_Part : Part_Count;
Last_Declaration : Attribute_Declaration_Count;
Last_Attribute : Attribute_Count;
Last_Rule : Rule_Count) is
tagged record
Root : Non_Terminal_Index;
Terminal : Terminal_Array (1 .. Last_Terminal);
Non_Terminal : Non_Terminal_Array (1 .. Last_Non_Terminal);
Production : Production_Array (1 .. Last_Production);
Part : Part_Array (1 .. Last_Part);
Declaration : Declaration_Array (1 .. Last_Declaration);
Attribute : Attribute_Array (1 .. Last_Attribute);
Rule : Rule_Array (1 .. Last_Rule);
With_List : S.Universal_String;
end record;
type Grammar_Access is access all Grammar;
private
type Terminal is tagged record
Image : S.Universal_String;
Index : Terminal_Index;
First_Attribute : Attribute_Declaration_Index := 1;
Last_Attribute : Attribute_Declaration_Count := 0;
Precedence : Precedence_Value;
end record;
type Non_Terminal is tagged record
Name : S.Universal_String;
Index : Non_Terminal_Index;
First : Production_Index;
Last : Production_Count;
Is_List : Boolean;
First_Attribute : Attribute_Declaration_Index := 1;
Last_Attribute : Attribute_Declaration_Count := 0;
end record;
type Production is tagged record
Name : S.Universal_String;
Index : Production_Index;
First : Part_Index;
Last : Part_Count;
First_Rule : Rule_Index := 1;
Last_Rule : Rule_Count := 0;
Parent : Non_Terminal_Count;
Precedence : Precedence_Value;
First_Attribute : Attribute_Declaration_Index := 1;
Last_Attribute : Attribute_Declaration_Count := 0;
end record;
type Part is tagged record
Name : S.Universal_String;
Index : Part_Index;
Parent : Production_Index;
Is_Terminal_Reference : Boolean;
Is_Non_Terminal_Reference : Boolean;
Is_List : Boolean;
Is_Option : Boolean;
Denoted_Terminal : Terminal_Count;
Denoted_Non_Terminal : Non_Terminal_Count;
First : Production_Index;
Last : Production_Count;
end record;
type Attribute_Kind is (Local, Inherited, Synthesized);
type Attribute_Declaration is tagged record
Name : S.Universal_String;
Type_Name : S.Universal_String;
Index : Attribute_Declaration_Index;
Kind : Attribute_Kind;
end record;
type Attribute is tagged record
Index : Attribute_Index;
Origin : Part_Count;
Parent : Rule_Index;
Has_Default : Boolean;
Declaration : Attribute_Declaration_Index;
end record;
type Rule is tagged record
Index : Rule_Index;
Result : Attribute_Count := 0;
First_Argument : Attribute_Index;
Last_Argument : Attribute_Count;
Parent : Production_Index;
Text : S.Universal_String;
end record;
end Anagram.Grammars;
|
gitter-badger/libAnne | Ada | 2,887 | ads | with Containers.Stacks;
generic
type Float_Type is digits <>;
with function Image(Value : Float_Type) return String is <>;
with function Wide_Image(Value : Float_Type) return Wide_String is <>;
with function Wide_Wide_Image(Value : Float_Type) return Wide_Wide_String is <>;
package Containers.Float_Stacks with Preelaborate is
package Base_Stack is new Containers.Stacks(Float_Type);
--Please ignore this
use Base_Stack;
type Stack is new Base_Stack.Stack with null record;
procedure Add(Self : in out Stack) with Pre => Self.Length >= 2;
--Add the top two numbers on the stack, and push the result back onto the stack
procedure Add(Self : in out Stack; Value : in Float_Type) with Pre => Self.Length >= 1;
--Add the top number on the stack with the specified value, and push the result back onto the stack
procedure Subtract(Self : in out Stack) with Pre => Self.Length >= 2;
--Subtract the top two numbers on the stack, and push the result back onto the stack
procedure Sub(Self : in out Stack) renames Subtract;
--Subtract the top two numbers on the stack, and push the result back onto the stack
procedure Subtract(Self : in out Stack; Value : in Float_Type) with Pre => Self.Length >= 1;
--Subtract the specified value from the top number of the stack, and push the result back onto the stack
procedure Sub(Self : in out Stack; Value : in Float_Type) renames Subtract;
--Subtract the specified value from the top number of the stack and push the result back onto the stack
procedure Multiply(Self : in out Stack) with Pre => Self.Length >= 2;
--Multiply the top two numbers on the stack, and push the result back onto the stack
procedure Mul(Self : in out Stack) renames Multiply;
--Multiply the top two numbers on the stack, and push the result back onto the stack
procedure Multiply(Self : in out Stack; Value : in Float_Type) with Pre => Self.Length >= 1;
--Multiply the top number on the stack with the specified value, and push the result back onto the stack
procedure Mul(Self : in out Stack; Value : in Float_Type) renames Multiply;
--Multiply the top number on the stack with the specified value, and push the result back onto the stack
procedure Divide(Self : in out Stack) with Pre => Self.Length >= 2;
--Divide the top two numbers on the stack, and push the result back onto the stack
procedure Div(Self : in out Stack) renames Divide;
--Divide the top two numbers on the stack, and push the result back onto the stack
procedure Divide(Self : in out Stack; Value : in Float_Type) with Pre => Self.Length >= 1;
--Divide the top number on the stack by the specified value, and push the result back onto the stack
procedure Div(Self : in out Stack; Value : in Float_Type) renames Divide;
--Divide the top number on the stack by the specified value, and push the result back onto the stack
end Containers.Float_Stacks;
|
osannolik/ada-canopen | Ada | 889 | ads | private with SocketCAN; -- Requires GNAT...
package ACO.Drivers.Socket is
type CAN_Driver is new Driver with private;
CAN_If_Name : constant String := "vcan0";
overriding
procedure Receive_Message_Blocking
(This : in out CAN_Driver;
Msg : out ACO.Messages.Message);
overriding
procedure Send_Message
(This : in out CAN_Driver;
Msg : in ACO.Messages.Message);
overriding
procedure Initialize
(This : in out CAN_Driver);
overriding
procedure Finalize
(This : in out CAN_Driver);
overriding
function Is_Message_Pending
(This : CAN_Driver)
return Boolean;
overriding
function Current_Time
(This : CAN_Driver)
return Ada.Real_Time.Time;
private
type CAN_Driver is new Driver with record
Socket : SocketCAN.Socket_Type;
end record;
end ACO.Drivers.Socket;
|
vikasbidhuri1995/DW1000 | Ada | 16,001 | ads | -------------------------------------------------------------------------------
-- Copyright (c) 2016 Daniel King
--
-- Permission is hereby granted, free of charge, to any person obtaining a
-- copy of this software and associated documentation files (the "Software"),
-- to deal in the Software without restriction, including without limitation
-- the rights to use, copy, modify, merge, publish, distribute, sublicense,
-- and/or sell copies of the Software, and to permit persons to whom the
-- Software is furnished to do so, subject to the following conditions:
--
-- The above copyright notice and this permission notice shall be included in
-- all copies or substantial portions of the Software.
--
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-- FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
-- DEALINGS IN THE SOFTWARE.
-------------------------------------------------------------------------------
with DW1000.Types; use DW1000.Types;
-- @summary
-- Types and functions for dealing with time derived from the DW1000 system
-- time (clocked at 63.8976 GHz).
--
-- @description
-- The DW1000's system time is used for several 40-bit timestamps which are
-- measured in units of approx. 15.65 picoseconds. The timestamps which use
-- this 40-bit 63.8976 GHz system time are listed below:
-- * System Time Counter (SYS_TIME register)
-- * Delayed Send or Receive Time (DX_TIME register)
-- * Adjusted Receive Timestamp (RX_STAMP field in the RX_TIME register)
-- * Raw Receive Timestamp (RX_RAWST field in the RX_TIME register)
-- * Adjusted Transmit Timestamp (TX_STAMP field in the TX_TIME register)
-- * Raw Transmit Timestamp (TX_RAWST field in the TX_TIME register)
--
-- Out of the above registers, not all are capable of measuring to the full
-- 40-bit granularity of 15.65 picoseconds. In some registers the 9 least
-- significant bits are ignored which gives 512x less precision, i.e. the
-- effective granularity is 8.013 nanoseconds. The registers that are capable
-- of the FULL precision of 15.65 picoseconds are listed below:
-- * Adjusted Receive Timestamp (RX_STAMP field in the RX_TIME register)
-- * Adjusted Transmit Timestamp (TX_STAMP field in the TX_TIME register)
--
-- The following registers ignore the 9 least significant bits, providing a
-- granularity of 8.013 nanoseconds:
-- * System Time Counter (SYS_TIME register)
-- * Delayed Send or Receive Time (DX_TIME register)
-- * Raw Receive Timestamp (RX_RAWST field in the RX_TIME register)
-- * Raw Transmit Timestamp (TX_RAWST field in the TX_TIME register)
--
-- To manage the two time stamp precisions, the System_Time package defines
-- two types:
-- * Fine_System_Time, capable of the full 15.65 picosecond precision.
-- * Coarse_System_Time, capable of the restricted 8.013 nanosecond
-- precision.
--
-- For both of these types, conversion functions are defined to convert to and
-- from the 40-bit representation type that is used by the DW1000 register
-- set. The To_Bits_40 function converts from either Fine_System_Time or
-- Coarse_System_Time to the Bits_40 type. The To_Fine_System_Time and
-- To_Coarse_System_Time functions convert from the Bits_40 representation to
-- the Fine_System_Time and Coarse_System_Time types respectively.
--
-- Furthermore, the antenna delay is also measured in units of
-- 15.65 picoseconds, but only has a 16-bit range (compared to the 40-bit
-- timestamps with a much bigger range). The antenna delay is represented
-- as the type Antenna_Delay_Time, which is a subtype of Fine_System_Time
-- with a maximum value of about 1.0256 microseconds.
--
-- For the antenna delay there are two conversion functions: To_Bits_16 and
-- To_Antenna_Delay_Time. The To_Bits_16 function converts from the
-- Antenna_Delay_Time type to its 16-bit representation. The
-- To_Antenna_Delay_Time function converts the other way; from the 16-bit
-- representation to the Antenna_Delay_Time type.
package DW1000.System_Time
with SPARK_Mode => On
is
Chipping_Rate_Hz : constant := 499_200_000.0;
-- DW1000 system clocks are referenced to the 499.2 MHz chipping rate
-- defined in the IEEE 802.15.4-2011 standard.
System_Time_Clock_Hz : constant := Chipping_Rate_Hz * 128.0;
-- System time and time stamps are based on time units which are at
-- 63.8976 GHz (499.2 MHz * 128). This yields a resolution of
-- approximately 15.65 picoseconds.
type Fine_System_Time is
delta 1.0 / System_Time_Clock_Hz
range 0.0 .. (2.0**40 - 1.0) / System_Time_Clock_Hz
with Small => 1.0 / System_Time_Clock_Hz,
Size => 40;
-- Type for representing the DW1000 fine-grained system time in seconds,
-- with a precision of at least 15.65 picoseconds.
--
-- The DW1000 uses Bits_40 to represent timestamp values (e.g. system time,
-- and tx/rx timestamps), which is measured in units of 499.2 MHz * 128,
-- i.e. it increments in units of about 15.65 picoseconds (when using the
-- PLL clock).
--
-- The Fine_System_Time is used for the transmit and receive time stamps.
--
-- WARNING: This type represents the system time when the PLL clock is
-- used. On power up, before the digital PLL is enabled, the System Time
-- increments in units of about 52.08 nanoseconds (3328x slower than the
-- PLL), and so this Fine_System_Time type is not appropriate in such
-- circumstances.
type Coarse_System_Time is
delta 512.0 / System_Time_Clock_Hz
range 0.0 .. (2.0**40 - 1.0) / System_Time_Clock_Hz
with Small => 1.0 / System_Time_Clock_Hz,
Size => 40;
-- Type for representing the DW1000 coarsely-grained system time in seconds,
-- with a precision of at least 8.013 nanoseconds.
--
-- The DW1000 uses Bits_40 to represent the system time counter and the
-- delayed tx/rx times, but ignores the low 9 order bits giving an
-- effective precision of 8.013 nanoseconds (512x less precise than the
-- fine-grained system time used for the transmit and receive timestamps).
--
-- The Coarse_System_Time is used for the System Time Counter, and the
-- delayed tx/rx times.
--
-- WARNING: This type represents the system time when the PLL clock is
-- used. On power up, before the digital PLL is enabled, the System Time
-- increments in units of about 26.67 microseconds (3328x slower than the
-- PLL), and so this Coarse_System_Time type is not appropriate in such
-- circumstances.
type System_Time_Span is new Fine_System_Time;
type Antenna_Delay_Time is
delta Fine_System_Time'Delta
range 0.0 .. Fine_System_Time'Delta * (2**16 - 1)
with Small => Fine_System_Time'Small,
Size => 16;
-- Type to represent an antenna delay time.
type Frame_Wait_Timeout_Time is
delta 512.0 / Chipping_Rate_Hz
range 0.0 .. ((2.0**16 - 1.0) * 512.0) / Chipping_Rate_Hz
with Small => 512.0 / Chipping_Rate_Hz,
Size => 16;
-- Type to represent the frame wait timeout.
--
-- The range of this type is 0.0 .. 0.067215385, i.e. the maximum value
-- is 67.215385 milliseconds.
--
-- The resolution of this type is 128 system block cycle
-- (about 1 microsecond).
type Response_Wait_Timeout_Time is
delta 512.0 / Chipping_Rate_Hz
range 0.0 .. ((2.0**20 - 1.0) * 512.0) / Chipping_Rate_Hz
with Small => 512.0 / Chipping_Rate_Hz,
Size => 20;
-- Type to represent the wait-for-response turnaround time.
--
-- The range of this type is 0.0 .. 1.0754615 i.e. the maximum value is
-- about 1.0754615 seconds.
--
-- The resolution of this type is 128 system block cycle
-- (about 1 microsecond).
type Sniff_Off_Time is
delta 512.0 / Chipping_Rate_Hz
range 0.0 .. ((2.0**8 - 1.0) * 512.0) / Chipping_Rate_Hz
with Small => 512.0 / Chipping_Rate_Hz,
Size => 8;
-- Type to represent the SNIFF mode OFF time.
--
-- The range of this type is 0.0 .. 0.000_262_051 i.e. the maximum value is
-- about 0.000_262_051 seconds (about 262 microseconds).
--
-- The resolution of this type is 128 system block cycle
-- (about 1 microsecond).
type Snooze_Time is
delta 1.0 / 37_500.0
range 0.0 .. (2.0**8 - 1.0) / 37_500.0
with Small => 1.0 / 37_500.0,
Size => 8;
-- Type to represent the snooze time (in seconds).
--
-- This represents the upper 8 bits of a 17-bit timer clocked from the
-- 19.2 MHz XTI internal clock. This means that this snooze time value
-- is in units of 37.5 KHz, i.e. about 26.7 microseconds.
--
-- The maximum value of this type is 0.0068 (6.8 milliseconds).
type Blink_Time is
delta 0.014
range 0.0 .. (2.0**8 - 1.0) * 0.014
with Small => 0.014,
Size => 8;
-- Type to represent the LED blink time (in seconds).
--
-- This is in units of 14 milliseconds, so a value of 0.4 will give a
-- blink time of 400 ms followed by an off blink of 400 ms.
--
-- The maximum value of this type is 3.57 seconds.
function To_Bits_40 (Time : in Fine_System_Time) return Bits_40 is
(Bits_40 (Time / Fine_System_Time (Fine_System_Time'Delta)));
-- Convert a Fine_System_Time value to its equivalent Bits_40
-- representation.
--
-- Note that is a surjective function, i.e. some values of System_Time
-- map to the same Bits_40 value. This is due System_Time supporting a
-- smaller granularity (approx. 0.9 picoseconds) than Bits_40
-- (approx. 15.65 picoseconds).
function To_Bits_40 (Time : in Coarse_System_Time) return Bits_40 is
(Bits_40 (Time / Coarse_System_Time (Coarse_System_Time'Delta)) * 512)
with Post => (To_Bits_40'Result and 2#1_1111_1111#) = 0;
-- Convert a Coarse_System_Time value to its 40-bit integer representation.
--
-- Note that for registers using a coarse time the 9 least significant bits
-- are 0.
function To_Bits_40 (Span : in System_Time_Span) return Bits_40
is (To_Bits_40 (Fine_System_Time (Span)));
-- Convert a System_Time_Span value to its equivalent Bits_40
-- representation.
--
-- System_Time_Span has the same resolution as Fine_System_Time, so the
-- LSB in the Bits_40 representation is approx. 15.65 picoseconds.
function To_Bits_16 (Time : in Antenna_Delay_Time) return Bits_16 is
(Bits_16 (Time / Antenna_Delay_Time (Antenna_Delay_Time'Delta)));
-- Convert a Antenna_Delay_Time value to its 16-bit representation.
function To_Bits_16 (Time : in Frame_Wait_Timeout_Time) return Bits_16 is
(Bits_16 (Time / Frame_Wait_Timeout_Time (Frame_Wait_Timeout_Time'Delta)));
-- Convert a Frame_Wait_Timeout_Time to its 16-bit representation.
function To_Fine_System_Time (Bits : in Bits_40) return Fine_System_Time
with Inline,
Global => null;
-- Convert a Bits_40 value to Fine_System_Time.
--
-- The DW1000 register set uses a 40-bit integer to represent the system
-- time and rx/tx timestamp values. This function converts the 40-bit
-- integer representation to the System_Time fixed-point representation.
function To_Coarse_System_Time (Bits : in Bits_40)
return Coarse_System_Time
with Inline,
Global => null;
-- Convert a 40-bit register value to Coarse_System_Time.
function To_System_Time_Span (Bits : in Bits_40) return System_Time_Span
is (System_Time_Span (To_Fine_System_Time (Bits)))
with Inline,
Global => null;
-- Convert a 40-bit time span to the equivalent System_Time_Span value.
function To_Antenna_Delay_Time (Bits : in Bits_16)
return Antenna_Delay_Time
with Inline,
Global => null;
-- Convert a 16-bit antenna delay register value to Antenna_Delay_Time.
function System_Time_Offset (Time : in Fine_System_Time;
Span : in System_Time_Span)
return Fine_System_Time;
-- Calculate the offset of a system time, with wrap-around.
--
-- Since the system time on the DW1000 is a counter which wraps-around,
-- it is also permitted to have System_Time wrap-around when calculating
-- a specific System_Time offset set in the future. This function handles
-- this wrap-around case correctly.
--
-- This function is particularly useful when calculating a specific time
-- at which the next packet should be set, relative to the previously
-- received packet's timestamp.
function System_Time_Offset (Time : in Coarse_System_Time;
Span : in System_Time_Span)
return Fine_System_Time
is (System_Time_Offset (Fine_System_Time (Time), Span));
function Calculate_Span (Start_Time : in Fine_System_Time;
End_Time : in Fine_System_Time)
return System_Time_Span;
-- Calculate the time span between two points in time.
--
-- Note that since the DW1000 system time wraps-around after about every
-- 17 seconds, so it is possible for the End_Time to be less than the
-- Start_Time. This function takes this wrap-around behavior into account.
function Calculate_Span (Start_Time : in Coarse_System_Time;
End_Time : in Coarse_System_Time)
return System_Time_Span
is (Calculate_Span (Fine_System_Time (Start_Time),
Fine_System_Time (End_Time)));
-- Calculate the time span between two points in time.
--
-- Note that since the DW1000 system time wraps-around after about every
-- 17 seconds, so it is possible for the End_Time to be less than the
-- Start_Time. This function takes this wrap-around behavior into account.
function Calculate_Span (Start_Time : in Fine_System_Time;
End_Time : in Coarse_System_Time)
return System_Time_Span
is (Calculate_Span (Start_Time, Fine_System_Time (End_Time)));
-- Calculate the time span between two points in time.
--
-- Note that since the DW1000 system time wraps-around after about every
-- 17 seconds, so it is possible for the End_Time to be less than the
-- Start_Time. This function takes this wrap-around behavior into account.
function Calculate_Span (Start_Time : in Coarse_System_Time;
End_Time : in Fine_System_Time)
return System_Time_Span
is (Calculate_Span (Fine_System_Time (Start_Time), End_Time));
-- Calculate the time span between two points in time.
--
-- Note that since the DW1000 system time wraps-around after about every
-- 17 seconds, so it is possible for the End_Time to be less than the
-- Start_Time. This function takes this wrap-around behavior into account.
private
type FP_40 is delta 1.0 range 0.0 .. 2.0**40 - 1.0
with Small => 1.0;
-- Helper fixed-point type to represent a 40-bit integer type.
function To_Fine_System_Time (Bits : in Bits_40) return Fine_System_Time is
(Fine_System_Time (Fine_System_Time'Delta) * FP_40 (Bits));
function To_Coarse_System_Time (Bits : in Bits_40)
return Coarse_System_Time is
(Coarse_System_Time (Coarse_System_Time'Delta) * FP_40 (Bits / 512));
function To_Antenna_Delay_Time (Bits : in Bits_16)
return Antenna_Delay_Time is
(Antenna_Delay_Time'Delta * Integer (Bits));
end DW1000.System_Time;
|
throwException/genode-world | Ada | 2,664 | adb | -------------------------------------------------------------------------------
-- This file is part of libsparkcrypto.
--
-- Copyright (C) 2019, Componolit GmbH
-- 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 nor the names of its contributors may be used
-- to endorse or promote products derived from this software without
-- specific prior written permission.
--
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
-- BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-- POSSIBILITY OF SUCH DAMAGE.
-------------------------------------------------------------------------------
pragma Style_Checks ("-s");
pragma Warnings (Off, "formal parameter ""T"" is not referenced");
package body LSC_Internal_Benchmark
is
function Routine_Name (T : Test_Case) return Message_String
is
begin
return Format ("Void");
end Routine_Name;
---------------------------------------------------------------------------
procedure Register_Tests (T : in out Test_Case) is
package Registration is new
AUnit.Test_Cases.Specific_Test_Case_Registration (Test_Case);
use Registration;
begin
null;
end Register_Tests;
---------------------------------------------------------------------------
function Name (T : Test_Case) return Test_String is
begin
pragma Unreferenced (T);
return Format ("Benchmark dummy");
end Name;
end LSC_Internal_Benchmark;
|
bitslab/CompilerInterrupts | Ada | 20,406 | adb | ----------------------------------------------------------------
-- ZLib for Ada thick binding. --
-- --
-- Copyright (C) 2002-2004 Dmitriy Anisimkov --
-- --
-- Open source license information is in the zlib.ads file. --
----------------------------------------------------------------
-- $Id: zlib.adb,v 1.1.1.1 2012/03/29 17:21:39 uid42307 Exp $
with Ada.Exceptions;
with Ada.Unchecked_Conversion;
with Ada.Unchecked_Deallocation;
with Interfaces.C.Strings;
with ZLib.Thin;
package body ZLib is
use type Thin.Int;
type Z_Stream is new Thin.Z_Stream;
type Return_Code_Enum is
(OK,
STREAM_END,
NEED_DICT,
ERRNO,
STREAM_ERROR,
DATA_ERROR,
MEM_ERROR,
BUF_ERROR,
VERSION_ERROR);
type Flate_Step_Function is access
function (Strm : in Thin.Z_Streamp; Flush : in Thin.Int) return Thin.Int;
pragma Convention (C, Flate_Step_Function);
type Flate_End_Function is access
function (Ctrm : in Thin.Z_Streamp) return Thin.Int;
pragma Convention (C, Flate_End_Function);
type Flate_Type is record
Step : Flate_Step_Function;
Done : Flate_End_Function;
end record;
subtype Footer_Array is Stream_Element_Array (1 .. 8);
Simple_GZip_Header : constant Stream_Element_Array (1 .. 10)
:= (16#1f#, 16#8b#, -- Magic header
16#08#, -- Z_DEFLATED
16#00#, -- Flags
16#00#, 16#00#, 16#00#, 16#00#, -- Time
16#00#, -- XFlags
16#03# -- OS code
);
-- The simplest gzip header is not for informational, but just for
-- gzip format compatibility.
-- Note that some code below is using assumption
-- Simple_GZip_Header'Last > Footer_Array'Last, so do not make
-- Simple_GZip_Header'Last <= Footer_Array'Last.
Return_Code : constant array (Thin.Int range <>) of Return_Code_Enum
:= (0 => OK,
1 => STREAM_END,
2 => NEED_DICT,
-1 => ERRNO,
-2 => STREAM_ERROR,
-3 => DATA_ERROR,
-4 => MEM_ERROR,
-5 => BUF_ERROR,
-6 => VERSION_ERROR);
Flate : constant array (Boolean) of Flate_Type
:= (True => (Step => Thin.Deflate'Access,
Done => Thin.DeflateEnd'Access),
False => (Step => Thin.Inflate'Access,
Done => Thin.InflateEnd'Access));
Flush_Finish : constant array (Boolean) of Flush_Mode
:= (True => Finish, False => No_Flush);
procedure Raise_Error (Stream : in Z_Stream);
pragma Inline (Raise_Error);
procedure Raise_Error (Message : in String);
pragma Inline (Raise_Error);
procedure Check_Error (Stream : in Z_Stream; Code : in Thin.Int);
procedure Free is new Ada.Unchecked_Deallocation
(Z_Stream, Z_Stream_Access);
function To_Thin_Access is new Ada.Unchecked_Conversion
(Z_Stream_Access, Thin.Z_Streamp);
procedure Translate_GZip
(Filter : in out Filter_Type;
In_Data : in Ada.Streams.Stream_Element_Array;
In_Last : out Ada.Streams.Stream_Element_Offset;
Out_Data : out Ada.Streams.Stream_Element_Array;
Out_Last : out Ada.Streams.Stream_Element_Offset;
Flush : in Flush_Mode);
-- Separate translate routine for make gzip header.
procedure Translate_Auto
(Filter : in out Filter_Type;
In_Data : in Ada.Streams.Stream_Element_Array;
In_Last : out Ada.Streams.Stream_Element_Offset;
Out_Data : out Ada.Streams.Stream_Element_Array;
Out_Last : out Ada.Streams.Stream_Element_Offset;
Flush : in Flush_Mode);
-- translate routine without additional headers.
-----------------
-- Check_Error --
-----------------
procedure Check_Error (Stream : in Z_Stream; Code : in Thin.Int) is
use type Thin.Int;
begin
if Code /= Thin.Z_OK then
Raise_Error
(Return_Code_Enum'Image (Return_Code (Code))
& ": " & Last_Error_Message (Stream));
end if;
end Check_Error;
-----------
-- Close --
-----------
procedure Close
(Filter : in out Filter_Type;
Ignore_Error : in Boolean := False)
is
Code : Thin.Int;
begin
if not Ignore_Error and then not Is_Open (Filter) then
raise Status_Error;
end if;
Code := Flate (Filter.Compression).Done (To_Thin_Access (Filter.Strm));
if Ignore_Error or else Code = Thin.Z_OK then
Free (Filter.Strm);
else
declare
Error_Message : constant String
:= Last_Error_Message (Filter.Strm.all);
begin
Free (Filter.Strm);
Ada.Exceptions.Raise_Exception
(ZLib_Error'Identity,
Return_Code_Enum'Image (Return_Code (Code))
& ": " & Error_Message);
end;
end if;
end Close;
-----------
-- CRC32 --
-----------
function CRC32
(CRC : in Unsigned_32;
Data : in Ada.Streams.Stream_Element_Array)
return Unsigned_32
is
use Thin;
begin
return Unsigned_32 (crc32 (ULong (CRC),
Data'Address,
Data'Length));
end CRC32;
procedure CRC32
(CRC : in out Unsigned_32;
Data : in Ada.Streams.Stream_Element_Array) is
begin
CRC := CRC32 (CRC, Data);
end CRC32;
------------------
-- Deflate_Init --
------------------
procedure Deflate_Init
(Filter : in out Filter_Type;
Level : in Compression_Level := Default_Compression;
Strategy : in Strategy_Type := Default_Strategy;
Method : in Compression_Method := Deflated;
Window_Bits : in Window_Bits_Type := Default_Window_Bits;
Memory_Level : in Memory_Level_Type := Default_Memory_Level;
Header : in Header_Type := Default)
is
use type Thin.Int;
Win_Bits : Thin.Int := Thin.Int (Window_Bits);
begin
if Is_Open (Filter) then
raise Status_Error;
end if;
-- We allow ZLib to make header only in case of default header type.
-- Otherwise we would either do header by ourselfs, or do not do
-- header at all.
if Header = None or else Header = GZip then
Win_Bits := -Win_Bits;
end if;
-- For the GZip CRC calculation and make headers.
if Header = GZip then
Filter.CRC := 0;
Filter.Offset := Simple_GZip_Header'First;
else
Filter.Offset := Simple_GZip_Header'Last + 1;
end if;
Filter.Strm := new Z_Stream;
Filter.Compression := True;
Filter.Stream_End := False;
Filter.Header := Header;
if Thin.Deflate_Init
(To_Thin_Access (Filter.Strm),
Level => Thin.Int (Level),
method => Thin.Int (Method),
windowBits => Win_Bits,
memLevel => Thin.Int (Memory_Level),
strategy => Thin.Int (Strategy)) /= Thin.Z_OK
then
Raise_Error (Filter.Strm.all);
end if;
end Deflate_Init;
-----------
-- Flush --
-----------
procedure Flush
(Filter : in out Filter_Type;
Out_Data : out Ada.Streams.Stream_Element_Array;
Out_Last : out Ada.Streams.Stream_Element_Offset;
Flush : in Flush_Mode)
is
No_Data : Stream_Element_Array := (1 .. 0 => 0);
Last : Stream_Element_Offset;
begin
Translate (Filter, No_Data, Last, Out_Data, Out_Last, Flush);
end Flush;
-----------------------
-- Generic_Translate --
-----------------------
procedure Generic_Translate
(Filter : in out ZLib.Filter_Type;
In_Buffer_Size : in Integer := Default_Buffer_Size;
Out_Buffer_Size : in Integer := Default_Buffer_Size)
is
In_Buffer : Stream_Element_Array
(1 .. Stream_Element_Offset (In_Buffer_Size));
Out_Buffer : Stream_Element_Array
(1 .. Stream_Element_Offset (Out_Buffer_Size));
Last : Stream_Element_Offset;
In_Last : Stream_Element_Offset;
In_First : Stream_Element_Offset;
Out_Last : Stream_Element_Offset;
begin
Main : loop
Data_In (In_Buffer, Last);
In_First := In_Buffer'First;
loop
Translate
(Filter => Filter,
In_Data => In_Buffer (In_First .. Last),
In_Last => In_Last,
Out_Data => Out_Buffer,
Out_Last => Out_Last,
Flush => Flush_Finish (Last < In_Buffer'First));
if Out_Buffer'First <= Out_Last then
Data_Out (Out_Buffer (Out_Buffer'First .. Out_Last));
end if;
exit Main when Stream_End (Filter);
-- The end of in buffer.
exit when In_Last = Last;
In_First := In_Last + 1;
end loop;
end loop Main;
end Generic_Translate;
------------------
-- Inflate_Init --
------------------
procedure Inflate_Init
(Filter : in out Filter_Type;
Window_Bits : in Window_Bits_Type := Default_Window_Bits;
Header : in Header_Type := Default)
is
use type Thin.Int;
Win_Bits : Thin.Int := Thin.Int (Window_Bits);
procedure Check_Version;
-- Check the latest header types compatibility.
procedure Check_Version is
begin
if Version <= "1.1.4" then
Raise_Error
("Inflate header type " & Header_Type'Image (Header)
& " incompatible with ZLib version " & Version);
end if;
end Check_Version;
begin
if Is_Open (Filter) then
raise Status_Error;
end if;
case Header is
when None =>
Check_Version;
-- Inflate data without headers determined
-- by negative Win_Bits.
Win_Bits := -Win_Bits;
when GZip =>
Check_Version;
-- Inflate gzip data defined by flag 16.
Win_Bits := Win_Bits + 16;
when Auto =>
Check_Version;
-- Inflate with automatic detection
-- of gzip or native header defined by flag 32.
Win_Bits := Win_Bits + 32;
when Default => null;
end case;
Filter.Strm := new Z_Stream;
Filter.Compression := False;
Filter.Stream_End := False;
Filter.Header := Header;
if Thin.Inflate_Init
(To_Thin_Access (Filter.Strm), Win_Bits) /= Thin.Z_OK
then
Raise_Error (Filter.Strm.all);
end if;
end Inflate_Init;
-------------
-- Is_Open --
-------------
function Is_Open (Filter : in Filter_Type) return Boolean is
begin
return Filter.Strm /= null;
end Is_Open;
-----------------
-- Raise_Error --
-----------------
procedure Raise_Error (Message : in String) is
begin
Ada.Exceptions.Raise_Exception (ZLib_Error'Identity, Message);
end Raise_Error;
procedure Raise_Error (Stream : in Z_Stream) is
begin
Raise_Error (Last_Error_Message (Stream));
end Raise_Error;
----------
-- Read --
----------
procedure Read
(Filter : in out Filter_Type;
Item : out Ada.Streams.Stream_Element_Array;
Last : out Ada.Streams.Stream_Element_Offset;
Flush : in Flush_Mode := No_Flush)
is
In_Last : Stream_Element_Offset;
Item_First : Ada.Streams.Stream_Element_Offset := Item'First;
V_Flush : Flush_Mode := Flush;
begin
pragma Assert (Rest_First in Buffer'First .. Buffer'Last + 1);
pragma Assert (Rest_Last in Buffer'First - 1 .. Buffer'Last);
loop
if Rest_Last = Buffer'First - 1 then
V_Flush := Finish;
elsif Rest_First > Rest_Last then
Read (Buffer, Rest_Last);
Rest_First := Buffer'First;
if Rest_Last < Buffer'First then
V_Flush := Finish;
end if;
end if;
Translate
(Filter => Filter,
In_Data => Buffer (Rest_First .. Rest_Last),
In_Last => In_Last,
Out_Data => Item (Item_First .. Item'Last),
Out_Last => Last,
Flush => V_Flush);
Rest_First := In_Last + 1;
exit when Stream_End (Filter)
or else Last = Item'Last
or else (Last >= Item'First and then Allow_Read_Some);
Item_First := Last + 1;
end loop;
end Read;
----------------
-- Stream_End --
----------------
function Stream_End (Filter : in Filter_Type) return Boolean is
begin
if Filter.Header = GZip and Filter.Compression then
return Filter.Stream_End
and then Filter.Offset = Footer_Array'Last + 1;
else
return Filter.Stream_End;
end if;
end Stream_End;
--------------
-- Total_In --
--------------
function Total_In (Filter : in Filter_Type) return Count is
begin
return Count (Thin.Total_In (To_Thin_Access (Filter.Strm).all));
end Total_In;
---------------
-- Total_Out --
---------------
function Total_Out (Filter : in Filter_Type) return Count is
begin
return Count (Thin.Total_Out (To_Thin_Access (Filter.Strm).all));
end Total_Out;
---------------
-- Translate --
---------------
procedure Translate
(Filter : in out Filter_Type;
In_Data : in Ada.Streams.Stream_Element_Array;
In_Last : out Ada.Streams.Stream_Element_Offset;
Out_Data : out Ada.Streams.Stream_Element_Array;
Out_Last : out Ada.Streams.Stream_Element_Offset;
Flush : in Flush_Mode) is
begin
if Filter.Header = GZip and then Filter.Compression then
Translate_GZip
(Filter => Filter,
In_Data => In_Data,
In_Last => In_Last,
Out_Data => Out_Data,
Out_Last => Out_Last,
Flush => Flush);
else
Translate_Auto
(Filter => Filter,
In_Data => In_Data,
In_Last => In_Last,
Out_Data => Out_Data,
Out_Last => Out_Last,
Flush => Flush);
end if;
end Translate;
--------------------
-- Translate_Auto --
--------------------
procedure Translate_Auto
(Filter : in out Filter_Type;
In_Data : in Ada.Streams.Stream_Element_Array;
In_Last : out Ada.Streams.Stream_Element_Offset;
Out_Data : out Ada.Streams.Stream_Element_Array;
Out_Last : out Ada.Streams.Stream_Element_Offset;
Flush : in Flush_Mode)
is
use type Thin.Int;
Code : Thin.Int;
begin
if not Is_Open (Filter) then
raise Status_Error;
end if;
if Out_Data'Length = 0 and then In_Data'Length = 0 then
raise Constraint_Error;
end if;
Set_Out (Filter.Strm.all, Out_Data'Address, Out_Data'Length);
Set_In (Filter.Strm.all, In_Data'Address, In_Data'Length);
Code := Flate (Filter.Compression).Step
(To_Thin_Access (Filter.Strm),
Thin.Int (Flush));
if Code = Thin.Z_STREAM_END then
Filter.Stream_End := True;
else
Check_Error (Filter.Strm.all, Code);
end if;
In_Last := In_Data'Last
- Stream_Element_Offset (Avail_In (Filter.Strm.all));
Out_Last := Out_Data'Last
- Stream_Element_Offset (Avail_Out (Filter.Strm.all));
end Translate_Auto;
--------------------
-- Translate_GZip --
--------------------
procedure Translate_GZip
(Filter : in out Filter_Type;
In_Data : in Ada.Streams.Stream_Element_Array;
In_Last : out Ada.Streams.Stream_Element_Offset;
Out_Data : out Ada.Streams.Stream_Element_Array;
Out_Last : out Ada.Streams.Stream_Element_Offset;
Flush : in Flush_Mode)
is
Out_First : Stream_Element_Offset;
procedure Add_Data (Data : in Stream_Element_Array);
-- Add data to stream from the Filter.Offset till necessary,
-- used for add gzip headr/footer.
procedure Put_32
(Item : in out Stream_Element_Array;
Data : in Unsigned_32);
pragma Inline (Put_32);
--------------
-- Add_Data --
--------------
procedure Add_Data (Data : in Stream_Element_Array) is
Data_First : Stream_Element_Offset renames Filter.Offset;
Data_Last : Stream_Element_Offset;
Data_Len : Stream_Element_Offset; -- -1
Out_Len : Stream_Element_Offset; -- -1
begin
Out_First := Out_Last + 1;
if Data_First > Data'Last then
return;
end if;
Data_Len := Data'Last - Data_First;
Out_Len := Out_Data'Last - Out_First;
if Data_Len <= Out_Len then
Out_Last := Out_First + Data_Len;
Data_Last := Data'Last;
else
Out_Last := Out_Data'Last;
Data_Last := Data_First + Out_Len;
end if;
Out_Data (Out_First .. Out_Last) := Data (Data_First .. Data_Last);
Data_First := Data_Last + 1;
Out_First := Out_Last + 1;
end Add_Data;
------------
-- Put_32 --
------------
procedure Put_32
(Item : in out Stream_Element_Array;
Data : in Unsigned_32)
is
D : Unsigned_32 := Data;
begin
for J in Item'First .. Item'First + 3 loop
Item (J) := Stream_Element (D and 16#FF#);
D := Shift_Right (D, 8);
end loop;
end Put_32;
begin
Out_Last := Out_Data'First - 1;
if not Filter.Stream_End then
Add_Data (Simple_GZip_Header);
Translate_Auto
(Filter => Filter,
In_Data => In_Data,
In_Last => In_Last,
Out_Data => Out_Data (Out_First .. Out_Data'Last),
Out_Last => Out_Last,
Flush => Flush);
CRC32 (Filter.CRC, In_Data (In_Data'First .. In_Last));
end if;
if Filter.Stream_End and then Out_Last <= Out_Data'Last then
-- This detection method would work only when
-- Simple_GZip_Header'Last > Footer_Array'Last
if Filter.Offset = Simple_GZip_Header'Last + 1 then
Filter.Offset := Footer_Array'First;
end if;
declare
Footer : Footer_Array;
begin
Put_32 (Footer, Filter.CRC);
Put_32 (Footer (Footer'First + 4 .. Footer'Last),
Unsigned_32 (Total_In (Filter)));
Add_Data (Footer);
end;
end if;
end Translate_GZip;
-------------
-- Version --
-------------
function Version return String is
begin
return Interfaces.C.Strings.Value (Thin.zlibVersion);
end Version;
-----------
-- Write --
-----------
procedure Write
(Filter : in out Filter_Type;
Item : in Ada.Streams.Stream_Element_Array;
Flush : in Flush_Mode := No_Flush)
is
Buffer : Stream_Element_Array (1 .. Buffer_Size);
In_Last : Stream_Element_Offset;
Out_Last : Stream_Element_Offset;
In_First : Stream_Element_Offset := Item'First;
begin
if Item'Length = 0 and Flush = No_Flush then
return;
end if;
loop
Translate
(Filter => Filter,
In_Data => Item (In_First .. Item'Last),
In_Last => In_Last,
Out_Data => Buffer,
Out_Last => Out_Last,
Flush => Flush);
if Out_Last >= Buffer'First then
Write (Buffer (1 .. Out_Last));
end if;
exit when In_Last = Item'Last or Stream_End (Filter);
In_First := In_Last + 1;
end loop;
end Write;
end ZLib;
|
charlie5/lace | Ada | 1,225 | ads | with
lace.Subject,
lace.Observer,
lace.make_Subject,
lace.make_Observer.deferred,
lace.Any;
private
with
ada.Strings.unbounded;
package lace.Subject_and_deferred_Observer
--
-- Provides a concrete type for a combined event subject and a deferred observer.
--
is
type Item is limited new lace.Any.limited_item
and lace.Subject .item
and lace.Observer .item with private;
type View is access all Item'Class;
package Forge
is
function to_Subject_and_Observer (Name : in String) return Item;
function new_Subject_and_Observer (Name : in String) return View;
end Forge;
procedure destroy (Self : in out Item);
procedure free (Self : in out View);
overriding
function Name (Self : in Item) return String;
private
use ada.Strings.unbounded;
package Subject is new make_Subject (Any.limited_item);
package Observer is new make_Observer (Subject .item);
package Deferred is new Observer.deferred (Observer .item);
type Item is limited new Deferred.item with
record
Name : unbounded_String;
end record;
end lace.Subject_and_deferred_Observer;
|
zhmu/ananas | Ada | 11,356 | adb | ------------------------------------------------------------------------------
-- --
-- GNAT RUN-TIME LIBRARY (GNARL) COMPONENTS --
-- --
-- S Y S T E M . I N T E R R U P T _ M A N A G E M E N T --
-- --
-- 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 the POSIX threads version of this package
-- Make a careful study of all signals available under the OS, to see which
-- need to be reserved, kept always unmasked, or kept always unmasked. Be on
-- the lookout for special signals that may be used by the thread library.
-- Since this is a multi target file, the signal <-> exception mapping
-- is simple minded. If you need a more precise and target specific
-- signal handling, create a new s-intman.adb that will fit your needs.
-- This file assumes that:
-- SIGFPE, SIGILL, SIGSEGV and SIGBUS exist. They are mapped as follows:
-- SIGPFE => Constraint_Error
-- SIGILL => Program_Error
-- SIGSEGV => Storage_Error
-- SIGBUS => Storage_Error
-- SIGINT exists and will be kept unmasked unless the pragma
-- Unreserve_All_Interrupts is specified anywhere in the application.
-- System.OS_Interface contains the following:
-- SIGADAABORT: the signal that will be used to abort tasks.
-- Unmasked: the OS specific set of signals that should be unmasked in
-- all the threads. SIGADAABORT is unmasked by
-- default
-- Reserved: the OS specific set of signals that are reserved.
with System.Task_Primitives;
package body System.Interrupt_Management is
use Interfaces.C;
use System.OS_Interface;
type Interrupt_List is array (Interrupt_ID range <>) of Interrupt_ID;
Exception_Interrupts : constant Interrupt_List :=
[SIGFPE, SIGILL, SIGSEGV, SIGBUS];
Unreserve_All_Interrupts : constant Interfaces.C.int;
pragma Import
(C, Unreserve_All_Interrupts, "__gl_unreserve_all_interrupts");
-----------------------
-- Local Subprograms --
-----------------------
function State (Int : Interrupt_ID) return Character;
pragma Import (C, State, "__gnat_get_interrupt_state");
-- Get interrupt state. Defined in init.c The input argument is the
-- interrupt number, and the result is one of the following:
User : constant Character := 'u';
Runtime : constant Character := 'r';
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)
procedure Notify_Exception
(signo : Signal;
siginfo : System.Address;
ucontext : System.Address);
-- This function identifies the Ada exception to be raised using the
-- information when the system received a synchronous signal. Since this
-- function is machine and OS dependent, different code has to be provided
-- for different target.
----------------------
-- Notify_Exception --
----------------------
Signal_Mask : aliased sigset_t;
-- The set of signals handled by Notify_Exception
procedure Notify_Exception
(signo : Signal;
siginfo : System.Address;
ucontext : System.Address)
is
pragma Unreferenced (siginfo);
Result : Interfaces.C.int;
begin
-- With the __builtin_longjmp, the signal mask is not restored, so we
-- need to restore it explicitly.
Result := pthread_sigmask (SIG_UNBLOCK, Signal_Mask'Access, null);
pragma Assert (Result = 0);
-- Perform the necessary context adjustments prior to a raise
-- from a signal handler.
Adjust_Context_For_Raise (signo, ucontext);
-- Check that treatment of exception propagation here is consistent with
-- treatment of the abort signal in System.Task_Primitives.Operations.
case signo is
when SIGFPE => raise Constraint_Error;
when SIGILL => raise Program_Error;
when SIGSEGV => raise Storage_Error;
when SIGBUS => raise Storage_Error;
when others => null;
end case;
end Notify_Exception;
----------------
-- Initialize --
----------------
Initialized : Boolean := False;
procedure Initialize is
act : aliased struct_sigaction;
old_act : aliased struct_sigaction;
Result : System.OS_Interface.int;
Use_Alternate_Stack : constant Boolean :=
System.Task_Primitives.Alternate_Stack_Size /= 0;
-- Whether to use an alternate signal stack for stack overflows
begin
if Initialized then
return;
end if;
Initialized := True;
-- Need to call pthread_init very early because it is doing signal
-- initializations.
pthread_init;
Abort_Task_Interrupt := SIGADAABORT;
act.sa_handler := Notify_Exception'Address;
-- Setting SA_SIGINFO asks the kernel to pass more than just the signal
-- number argument to the handler when it is called. The set of extra
-- parameters includes a pointer to the interrupted context, which the
-- ZCX propagation scheme needs.
-- Most man pages for sigaction mention that sa_sigaction should be set
-- instead of sa_handler when SA_SIGINFO is on. In practice, the two
-- fields are actually union'ed and located at the same offset.
-- On some targets, we set sa_flags to SA_NODEFER so that during the
-- handler execution we do not change the Signal_Mask to be masked for
-- the Signal.
-- This is a temporary fix to the problem that the Signal_Mask is not
-- restored after the exception (longjmp) from the handler. The right
-- fix should be made in sigsetjmp so that we save the Signal_Set and
-- restore it after a longjmp.
-- Since SA_NODEFER is obsolete, instead we reset explicitly the mask
-- in the exception handler.
Result := sigemptyset (Signal_Mask'Access);
pragma Assert (Result = 0);
-- Add signals that map to Ada exceptions to the mask
for J in Exception_Interrupts'Range loop
if State (Exception_Interrupts (J)) /= Default then
Result :=
sigaddset (Signal_Mask'Access, Signal (Exception_Interrupts (J)));
pragma Assert (Result = 0);
end if;
end loop;
act.sa_mask := Signal_Mask;
pragma Assert (Keep_Unmasked = [Interrupt_ID'Range => False]);
pragma Assert (Reserve = [Interrupt_ID'Range => False]);
-- Process state of exception signals
for J in Exception_Interrupts'Range loop
if State (Exception_Interrupts (J)) /= User then
Keep_Unmasked (Exception_Interrupts (J)) := True;
Reserve (Exception_Interrupts (J)) := True;
if State (Exception_Interrupts (J)) /= Default then
act.sa_flags := SA_SIGINFO;
if Use_Alternate_Stack
and then Exception_Interrupts (J) = SIGSEGV
then
act.sa_flags := act.sa_flags + SA_ONSTACK;
end if;
Result :=
sigaction
(Signal (Exception_Interrupts (J)), act'Unchecked_Access,
old_act'Unchecked_Access);
pragma Assert (Result = 0);
end if;
end if;
end loop;
if State (Abort_Task_Interrupt) /= User then
Keep_Unmasked (Abort_Task_Interrupt) := True;
Reserve (Abort_Task_Interrupt) := True;
end if;
-- Set SIGINT to unmasked state as long as it is not in "User" state.
-- Check for Unreserve_All_Interrupts last.
if State (SIGINT) /= User then
Keep_Unmasked (SIGINT) := True;
Reserve (SIGINT) := True;
end if;
-- Check all signals for state that requires keeping them unmasked and
-- reserved.
for J in Interrupt_ID'Range loop
if State (J) = Default or else State (J) = Runtime then
Keep_Unmasked (J) := True;
Reserve (J) := True;
end if;
end loop;
-- Add the set of signals that must always be unmasked for this target
for J in Unmasked'Range loop
Keep_Unmasked (Interrupt_ID (Unmasked (J))) := True;
Reserve (Interrupt_ID (Unmasked (J))) := True;
end loop;
-- Add target-specific reserved signals
for J in Reserved'Range loop
Reserve (Interrupt_ID (Reserved (J))) := True;
end loop;
-- Process pragma Unreserve_All_Interrupts. This overrides any settings
-- due to pragma Interrupt_State:
if Unreserve_All_Interrupts /= 0 then
Keep_Unmasked (SIGINT) := False;
Reserve (SIGINT) := False;
end if;
-- We do not really have Signal 0. We just use this value to identify
-- non-existent signals (see s-intnam.ads). Therefore, Signal should not
-- be used in all signal related operations hence mark it as reserved.
Reserve (0) := True;
end Initialize;
end System.Interrupt_Management;
|
strenkml/EE368 | Ada | 1,025 | ads |
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
package Benchmark.Trace is
-- Memory traces are sequences of memory access actions separated by
-- new lines. The format of each line is:
--
-- <action> <value>
--
-- where <action> is 'R' for read, 'W' for write, and 'I' for idle.
-- For reads and writes, <value> is a hexadecimal value indicating the
-- address. For idle states, <value> is the number of idle cycles.
-- Idle is used to separate reads and writes.
type Trace_Type is new Benchmark_Type with private;
type Trace_Pointer is access all Trace_Type'Class;
function Create_Trace return Benchmark_Pointer;
overriding
procedure Set_Argument(benchmark : in out Trace_Type;
arg : in String);
overriding
procedure Run(benchmark : in Trace_Type);
private
type Trace_Type is new Benchmark_Type with record
file_name : Unbounded_String := To_Unbounded_String("trace.txt");
end record;
end Benchmark.Trace;
|
reznikmm/matreshka | Ada | 4,695 | adb | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Open Document Toolkit --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2014, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
with Matreshka.DOM_Documents;
with Matreshka.ODF_String_Constants;
with ODF.DOM.Iterators;
with ODF.DOM.Visitors;
package body Matreshka.ODF_Text.String_Value_If_False_Attributes is
------------
-- Create --
------------
overriding function Create
(Parameters : not null access Matreshka.DOM_Attributes.Attribute_L2_Parameters)
return Text_String_Value_If_False_Attribute_Node is
begin
return Self : Text_String_Value_If_False_Attribute_Node do
Matreshka.ODF_Text.Constructors.Initialize
(Self'Unchecked_Access,
Parameters.Document,
Matreshka.ODF_String_Constants.Text_Prefix);
end return;
end Create;
--------------------
-- Get_Local_Name --
--------------------
overriding function Get_Local_Name
(Self : not null access constant Text_String_Value_If_False_Attribute_Node)
return League.Strings.Universal_String
is
pragma Unreferenced (Self);
begin
return Matreshka.ODF_String_Constants.String_Value_If_False_Attribute;
end Get_Local_Name;
begin
Matreshka.DOM_Documents.Register_Attribute
(Matreshka.ODF_String_Constants.Text_URI,
Matreshka.ODF_String_Constants.String_Value_If_False_Attribute,
Text_String_Value_If_False_Attribute_Node'Tag);
end Matreshka.ODF_Text.String_Value_If_False_Attributes;
|
AdaCore/Ada_Drivers_Library | Ada | 12,512 | adb | ------------------------------------------------------------------------------
-- --
-- Copyright (C) 2015-2018, AdaCore --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions are --
-- met: --
-- 1. Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- 2. Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in --
-- the documentation and/or other materials provided with the --
-- distribution. --
-- 3. Neither the name of the copyright holder nor the names of its --
-- contributors may be used to endorse or promote products derived --
-- from this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT --
-- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, --
-- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY --
-- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT --
-- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE --
-- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
with STM32.DCMI;
with Ada.Real_Time; use Ada.Real_Time;
with OV2640; use OV2640;
with OV7725; use OV7725;
with HAL.I2C; use HAL.I2C;
with HAL.Bitmap; use HAL.Bitmap;
with HAL; use HAL;
with STM32.PWM; use STM32.PWM;
with STM32.Setup;
package body OpenMV.Sensor is
package DCMI renames STM32.DCMI;
function Probe (Cam_Addr : out UInt10) return Boolean;
REG_PID : constant := 16#0A#;
-- REG_VER : constant := 16#0B#;
CLK_PWM_Mod : PWM_Modulator;
Camera_PID : HAL.UInt8 := 0;
Camera_2640 : OV2640_Camera (Sensor_I2C'Access);
Camera_7725 : OV7725_Camera (Sensor_I2C'Access);
Is_Initialized : Boolean := False;
-----------------
-- Initialized --
-----------------
function Initialized return Boolean is (Is_Initialized);
-----------
-- Probe --
-----------
function Probe (Cam_Addr : out UInt10) return Boolean is
Status : I2C_Status;
begin
for Addr in UInt10 range 0 .. 126 loop
Sensor_I2C.Master_Transmit (Addr => Addr,
Data => (0 => 0),
Status => Status,
Timeout => 10_000);
if Status = Ok then
Cam_Addr := Addr;
return True;
end if;
delay until Clock + Milliseconds (1);
end loop;
return False;
end Probe;
----------------
-- Initialize --
----------------
procedure Initialize is
procedure Initialize_Clock;
procedure Initialize_Camera;
procedure Initialize_IO;
procedure Initialize_DCMI;
procedure Initialize_DMA;
----------------------
-- Initialize_Clock --
----------------------
procedure Initialize_Clock is
begin
Configure_PWM_Timer (SENSOR_CLK_TIM'Access, SENSOR_CLK_FREQ);
CLK_PWM_Mod.Attach_PWM_Channel
(Generator => SENSOR_CLK_TIM'Access,
Channel => SENSOR_CLK_CHAN,
Point => SENSOR_CLK_IO,
PWM_AF => SENSOR_CLK_AF);
CLK_PWM_Mod.Set_Duty_Cycle (Value => 50);
CLK_PWM_Mod.Enable_Output;
end Initialize_Clock;
-----------------------
-- Initialize_Camera --
-----------------------
procedure Initialize_Camera is
Cam_Addr : UInt10;
Data : I2C_Data (1 .. 1);
Status : I2C_Status;
begin
-- Power cycle
Set (DCMI_PWDN);
delay until Clock + Milliseconds (10);
Clear (DCMI_PWDN);
delay until Clock + Milliseconds (10);
Initialize_Clock;
Set (DCMI_RST);
delay until Clock + Milliseconds (10);
Clear (DCMI_RST);
delay until Clock + Milliseconds (10);
if not Probe (Cam_Addr) then
-- Retry with reversed reset polarity
Set (DCMI_RST);
delay until Clock + Milliseconds (10);
if not Probe (Cam_Addr) then
raise Program_Error;
end if;
end if;
delay until Clock + Milliseconds (10);
-- Select sensor bank
Sensor_I2C.Mem_Write (Addr => Cam_Addr,
Mem_Addr => 16#FF#,
Mem_Addr_Size => Memory_Size_8b,
Data => (0 => 1),
Status => Status);
if Status /= Ok then
raise Program_Error;
end if;
delay until Clock + Milliseconds (10);
Sensor_I2C.Master_Transmit (Addr => Cam_Addr,
Data => (1 => REG_PID),
Status => Status);
if Status /= Ok then
raise Program_Error;
end if;
Sensor_I2C.Master_Receive (Addr => Cam_Addr,
Data => Data,
Status => Status);
if Status /= Ok then
raise Program_Error;
end if;
if Status /= Ok then
raise Program_Error;
end if;
Camera_PID := Data (Data'First);
case Camera_PID is
when OV2640_PID =>
Initialize (Camera_2640, Cam_Addr);
Set_Pixel_Format (Camera_2640, Pix_RGB565);
Set_Frame_Size (Camera_2640, QQVGA2);
when OV7725_PID =>
Initialize (Camera_7725, Cam_Addr);
Set_Pixel_Format (Camera_7725, Pix_RGB565);
Set_Frame_Size (Camera_7725, QQVGA2);
when others =>
raise Program_Error with "Unknown camera module";
end case;
end Initialize_Camera;
-------------------
-- Initialize_IO --
-------------------
procedure Initialize_IO is
GPIO_Conf : GPIO_Port_Configuration;
DCMI_AF_Points : constant GPIO_Points :=
GPIO_Points'(DCMI_D0, DCMI_D1, DCMI_D2, DCMI_D3, DCMI_D4,
DCMI_D5, DCMI_D6, DCMI_D7, DCMI_VSYNC, DCMI_HSYNC,
DCMI_PCLK);
DCMI_Out_Points : GPIO_Points :=
GPIO_Points'(DCMI_PWDN, DCMI_RST, FS_IN);
begin
STM32.Setup.Setup_I2C_Master (Port => Sensor_I2C,
SDA => Sensor_I2C_SDA,
SCL => Sensor_I2C_SCL,
SDA_AF => Sensor_I2C_AF,
SCL_AF => Sensor_I2C_AF,
Clock_Speed => 100_000);
Enable_Clock (DCMI_Out_Points);
-- Sensor PowerDown, Reset and FSIN
GPIO_Conf := (Mode => Mode_Out,
Output_Type => Push_Pull,
Speed => Speed_100MHz, -- not specified in previous version of this module
Resistors => Pull_Down);
Configure_IO (DCMI_Out_Points, GPIO_Conf);
Clear (DCMI_Out_Points);
GPIO_Conf := (Mode => Mode_AF,
AF => GPIO_AF_DCMI_13,
AF_Speed => Speed_100MHz, -- not specified in previous version of this module
AF_Output_Type => Push_Pull,
Resistors => Pull_Down);
Configure_IO (DCMI_AF_Points, GPIO_Conf);
end Initialize_IO;
---------------------
-- Initialize_DCMI --
---------------------
procedure Initialize_DCMI is
Vertical : DCMI.DCMI_Polarity;
Horizontal : DCMI.DCMI_Polarity;
Pixel_Clock : DCMI.DCMI_Polarity;
begin
case Camera_PID is
when OV2640_PID =>
Vertical := DCMI.Active_Low;
Horizontal := DCMI.Active_Low;
Pixel_Clock := DCMI.Active_High;
when OV7725_PID =>
Vertical := DCMI.Active_High;
Horizontal := DCMI.Active_Low;
Pixel_Clock := DCMI.Active_High;
when others =>
raise Program_Error with "Unknown camera module";
end case;
Enable_DCMI_Clock;
DCMI.Configure (Data_Mode => DCMI.DCMI_8bit,
Capture_Rate => DCMI.Capture_All,
Vertical_Polarity => Vertical,
Horizontal_Polarity => Horizontal,
Pixel_Clock_Polarity => Pixel_Clock,
Hardware_Sync => True,
JPEG => False);
DCMI.Disable_Crop;
DCMI.Enable_DCMI;
end Initialize_DCMI;
--------------------
-- Initialize_DMA --
--------------------
procedure Initialize_DMA is
Config : DMA_Stream_Configuration;
begin
Enable_Clock (Sensor_DMA);
Config.Channel := Sensor_DMA_Chan;
Config.Direction := Peripheral_To_Memory;
Config.Increment_Peripheral_Address := False;
Config.Increment_Memory_Address := True;
Config.Peripheral_Data_Format := Words;
Config.Memory_Data_Format := Words;
Config.Operation_Mode := Normal_Mode;
Config.Priority := Priority_High;
Config.FIFO_Enabled := True;
Config.FIFO_Threshold := FIFO_Threshold_Full_Configuration;
Config.Memory_Burst_Size := Memory_Burst_Inc4;
Config.Peripheral_Burst_Size := Peripheral_Burst_Single;
Configure (Sensor_DMA, Sensor_DMA_Stream, Config);
end Initialize_DMA;
begin
Initialize_IO;
Initialize_Camera;
Initialize_DCMI;
Initialize_DMA;
Is_Initialized := True;
end Initialize;
--------------
-- Snapshot --
--------------
procedure Snapshot (BM : not null HAL.Bitmap.Any_Bitmap_Buffer) is
Status : DMA_Error_Code;
Cnt : constant UInt16 := UInt16 ((BM.Width * BM.Height) / 2);
begin
if BM.Width /= Image_Width
or else
BM.Height /= Image_Height
or else
not BM.Mapped_In_RAM
then
raise Program_Error;
end if;
if not Compatible_Alignments (Sensor_DMA,
Sensor_DMA_Stream,
DCMI.Data_Register_Address,
BM.Memory_Address)
then
raise Program_Error;
end if;
Sensor_DMA_Int.Start_Transfer
(Source => DCMI.Data_Register_Address,
Destination => BM.Memory_Address,
Data_Count => Cnt);
DCMI.Start_Capture (DCMI.Snapshot);
Sensor_DMA_Int.Wait_For_Completion (Status);
if Status /= DMA_No_Error then
if Status = DMA_Timeout_Error then
raise Program_Error with "DMA timeout! Transferred: " &
Items_Transferred (Sensor_DMA, Sensor_DMA_Stream)'Img;
else
raise Program_Error;
end if;
end if;
end Snapshot;
end OpenMV.Sensor;
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.