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/lace | Ada | 13,064 | ads | with
ada.Strings.Maps;
package lace.Strings.superbounded
--
-- Based on the 'ada.Strings.superbounded' package provided by FSF GCC.
--
-- Modified to be a Pure package for use with DSA.
--
is
pragma Pure;
pragma Preelaborate;
use ada.Strings;
-- Type Bounded_String in Ada.Strings.Bounded.Generic_Bounded_Length is
-- derived from Super_String, with the constraint of the maximum length.
type Super_String (Max_Length : Positive) is
record
Current_Length : Natural := 0;
Data : String (1 .. Max_Length);
-- A previous version had a default initial value for Data, which is
-- no longer necessary, because we now special-case this type in the
-- compiler, so "=" composes properly for descendants of this type.
-- Leaving it out is more efficient.
end record;
-- The subprograms defined for Super_String are similar to those
-- defined for Bounded_String, except that they have different names, so
-- that they can be renamed in Ada.Strings.Bounded.Generic_Bounded_Length.
function Super_Length (Source : Super_String) return Natural;
--------------------------------------------------------
-- Conversion, Concatenation, and Selection Functions --
--------------------------------------------------------
function To_Super_String
(Source : String;
Max_Length : Natural;
Drop : Truncation := Error) return Super_String;
-- Note the additional parameter Max_Length, which specifies the maximum
-- length setting of the resulting Super_String value.
-- The following procedures have declarations (and semantics) that are
-- exactly analogous to those declared in Ada.Strings.Bounded.
function Super_To_String (Source : Super_String) return String;
procedure Set_Super_String
(Target : out Super_String;
Source : String;
Drop : Truncation := Error);
function Super_Append
(Left : Super_String;
Right : Super_String;
Drop : Truncation := Error) return Super_String;
function Super_Append
(Left : Super_String;
Right : String;
Drop : Truncation := Error) return Super_String;
function Super_Append
(Left : String;
Right : Super_String;
Drop : Truncation := Error) return Super_String;
function Super_Append
(Left : Super_String;
Right : Character;
Drop : Truncation := Error) return Super_String;
function Super_Append
(Left : Character;
Right : Super_String;
Drop : Truncation := Error) return Super_String;
procedure Super_Append
(Source : in out Super_String;
New_Item : Super_String;
Drop : Truncation := Error);
procedure Super_Append
(Source : in out Super_String;
New_Item : String;
Drop : Truncation := Error);
procedure Super_Append
(Source : in out Super_String;
New_Item : Character;
Drop : Truncation := Error);
function Concat
(Left : Super_String;
Right : Super_String) return Super_String;
function Concat
(Left : Super_String;
Right : String) return Super_String;
function Concat
(Left : String;
Right : Super_String) return Super_String;
function Concat
(Left : Super_String;
Right : Character) return Super_String;
function Concat
(Left : Character;
Right : Super_String) return Super_String;
function Super_Element
(Source : Super_String;
Index : Positive) return Character;
procedure Super_Replace_Element
(Source : in out Super_String;
Index : Positive;
By : Character);
function Super_Slice
(Source : Super_String;
Low : Positive;
High : Natural) return String;
function Super_Slice
(Source : Super_String;
Low : Positive;
High : Natural) return Super_String;
procedure Super_Slice
(Source : Super_String;
Target : out Super_String;
Low : Positive;
High : Natural);
overriding
function "="
(Left : Super_String;
Right : Super_String) return Boolean;
function Equal
(Left : Super_String;
Right : Super_String) return Boolean renames "=";
function Equal
(Left : Super_String;
Right : String) return Boolean;
function Equal
(Left : String;
Right : Super_String) return Boolean;
function Less
(Left : Super_String;
Right : Super_String) return Boolean;
function Less
(Left : Super_String;
Right : String) return Boolean;
function Less
(Left : String;
Right : Super_String) return Boolean;
function Less_Or_Equal
(Left : Super_String;
Right : Super_String) return Boolean;
function Less_Or_Equal
(Left : Super_String;
Right : String) return Boolean;
function Less_Or_Equal
(Left : String;
Right : Super_String) return Boolean;
function Greater
(Left : Super_String;
Right : Super_String) return Boolean;
function Greater
(Left : Super_String;
Right : String) return Boolean;
function Greater
(Left : String;
Right : Super_String) return Boolean;
function Greater_Or_Equal
(Left : Super_String;
Right : Super_String) return Boolean;
function Greater_Or_Equal
(Left : Super_String;
Right : String) return Boolean;
function Greater_Or_Equal
(Left : String;
Right : Super_String) return Boolean;
----------------------
-- Search Functions --
----------------------
function Super_Index
(Source : Super_String;
Pattern : String;
Going : Direction := Forward;
Mapping : Maps.Character_Mapping := Maps.Identity) return Natural;
function Super_Index
(Source : Super_String;
Pattern : String;
Going : Direction := Forward;
Mapping : Maps.Character_Mapping_Function) return Natural;
function Super_Index
(Source : Super_String;
Set : Maps.Character_Set;
Test : Membership := Inside;
Going : Direction := Forward) return Natural;
function Super_Index
(Source : Super_String;
Pattern : String;
From : Positive;
Going : Direction := Forward;
Mapping : Maps.Character_Mapping := Maps.Identity) return Natural;
function Super_Index
(Source : Super_String;
Pattern : String;
From : Positive;
Going : Direction := Forward;
Mapping : Maps.Character_Mapping_Function) return Natural;
function Super_Index
(Source : Super_String;
Set : Maps.Character_Set;
From : Positive;
Test : Membership := Inside;
Going : Direction := Forward) return Natural;
function Super_Index_Non_Blank
(Source : Super_String;
Going : Direction := Forward) return Natural;
function Super_Index_Non_Blank
(Source : Super_String;
From : Positive;
Going : Direction := Forward) return Natural;
function Super_Count
(Source : Super_String;
Pattern : String;
Mapping : Maps.Character_Mapping := Maps.Identity) return Natural;
function Super_Count
(Source : Super_String;
Pattern : String;
Mapping : Maps.Character_Mapping_Function) return Natural;
function Super_Count
(Source : Super_String;
Set : Maps.Character_Set) return Natural;
procedure Super_Find_Token
(Source : Super_String;
Set : Maps.Character_Set;
From : Positive;
Test : Membership;
First : out Positive;
Last : out Natural);
procedure Super_Find_Token
(Source : Super_String;
Set : Maps.Character_Set;
Test : Membership;
First : out Positive;
Last : out Natural);
------------------------------------
-- String Translation Subprograms --
------------------------------------
function Super_Translate
(Source : Super_String;
Mapping : Maps.Character_Mapping) return Super_String;
procedure Super_Translate
(Source : in out Super_String;
Mapping : Maps.Character_Mapping);
function Super_Translate
(Source : Super_String;
Mapping : Maps.Character_Mapping_Function) return Super_String;
procedure Super_Translate
(Source : in out Super_String;
Mapping : Maps.Character_Mapping_Function);
---------------------------------------
-- String Transformation Subprograms --
---------------------------------------
function Super_Replace_Slice
(Source : Super_String;
Low : Positive;
High : Natural;
By : String;
Drop : Truncation := Error) return Super_String;
procedure Super_Replace_Slice
(Source : in out Super_String;
Low : Positive;
High : Natural;
By : String;
Drop : Truncation := Error);
function Super_Insert
(Source : Super_String;
Before : Positive;
New_Item : String;
Drop : Truncation := Error) return Super_String;
procedure Super_Insert
(Source : in out Super_String;
Before : Positive;
New_Item : String;
Drop : Truncation := Error);
function Super_Overwrite
(Source : Super_String;
Position : Positive;
New_Item : String;
Drop : Truncation := Error) return Super_String;
procedure Super_Overwrite
(Source : in out Super_String;
Position : Positive;
New_Item : String;
Drop : Truncation := Error);
function Super_Delete
(Source : Super_String;
From : Positive;
Through : Natural) return Super_String;
procedure Super_Delete
(Source : in out Super_String;
From : Positive;
Through : Natural);
---------------------------------
-- String Selector Subprograms --
---------------------------------
function Super_Trim
(Source : Super_String;
Side : Trim_End) return Super_String;
procedure Super_Trim
(Source : in out Super_String;
Side : Trim_End);
function Super_Trim
(Source : Super_String;
Left : Maps.Character_Set;
Right : Maps.Character_Set) return Super_String;
procedure Super_Trim
(Source : in out Super_String;
Left : Maps.Character_Set;
Right : Maps.Character_Set);
function Super_Head
(Source : Super_String;
Count : Natural;
Pad : Character := Space;
Drop : Truncation := Error) return Super_String;
procedure Super_Head
(Source : in out Super_String;
Count : Natural;
Pad : Character := Space;
Drop : Truncation := Error);
function Super_Tail
(Source : Super_String;
Count : Natural;
Pad : Character := Space;
Drop : Truncation := Error) return Super_String;
procedure Super_Tail
(Source : in out Super_String;
Count : Natural;
Pad : Character := Space;
Drop : Truncation := Error);
------------------------------------
-- String Constructor Subprograms --
------------------------------------
-- Note: in some of the following routines, there is an extra parameter
-- Max_Length which specifies the value of the maximum length for the
-- resulting Super_String value.
function Times
(Left : Natural;
Right : Character;
Max_Length : Positive) return Super_String;
-- Note the additional parameter Max_Length
function Times
(Left : Natural;
Right : String;
Max_Length : Positive) return Super_String;
-- Note the additional parameter Max_Length
function Times
(Left : Natural;
Right : Super_String) return Super_String;
function Super_Replicate
(Count : Natural;
Item : Character;
Drop : Truncation := Error;
Max_Length : Positive) return Super_String;
-- Note the additional parameter Max_Length
function Super_Replicate
(Count : Natural;
Item : String;
Drop : Truncation := Error;
Max_Length : Positive) return Super_String;
-- Note the additional parameter Max_Length
function Super_Replicate
(Count : Natural;
Item : Super_String;
Drop : Truncation := Error) return Super_String;
private
-- Pragma Inline declarations
pragma Inline ("=");
pragma Inline (Less);
pragma Inline (Less_Or_Equal);
pragma Inline (Greater);
pragma Inline (Greater_Or_Equal);
pragma Inline (Concat);
pragma Inline (Super_Count);
pragma Inline (Super_Element);
pragma Inline (Super_Find_Token);
pragma Inline (Super_Index);
pragma Inline (Super_Index_Non_Blank);
pragma Inline (Super_Length);
pragma Inline (Super_Replace_Element);
pragma Inline (Super_Slice);
pragma Inline (Super_To_String);
end lace.Strings.superbounded;
|
jscparker/math_packages | Ada | 29,695 | adb |
--------------------------------------------------------------------------
-- package body Givens_QR, QR decomposition using Givens rotations
-- Copyright (C) 2008-2018 Jonathan S. Parker
--
-- Permission to use, copy, modify, and/or distribute this software for any
-- purpose with or without fee is hereby granted, provided that the above
-- copyright notice and this permission notice appear in all copies.
-- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
-- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
-- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
-- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
-- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
---------------------------------------------------------------------------
with Ada.Numerics;
with Ada.Numerics.Generic_Elementary_Functions;
package body Givens_QR is
package math is new Ada.Numerics.Generic_Elementary_Functions (Real); use math;
Zero : constant Real := +0.0;
One : constant Real := +1.0;
Two : constant Real := +2.0;
Exp_Min : constant Integer := Real'Machine_Emin;
Min_Allowed_Real : constant Real := Two**(Exp_Min - Exp_Min / 8);
type Int64 is range -2**63+1 .. 2**63-1;
-- Make these True:
Scaling_Desired : constant Boolean := True;
Pivoting_Desired : constant Boolean := True;
-- Scaling Prevents overflow during pivoting. With pivoting and
-- scaling enabled, the QR usually reveals the rank of matrix A.
-------------------------------
-- Inverse_Rotate_Col_Vector --
-------------------------------
-- for getting Q*B
procedure Inverse_Rotate_Col_Vector
(B : in out Col_Vector;
lower_right_id : in R_Index; -- low diagonal element (cos) of rot. matrix
upper_left_id : in R_Index; -- top diagonal element (cos) of rot. matrix
Rot : in Rotation;
P_bigger_than_L : in Boolean)
is
B_pvt, B_Low : Real;
c : real renames Rot.Cosine;
s : real renames Rot.Sine;
begin
-- all you do is flip the sign of Sine. s in part 1,
-- and in part 2, 1 + (s-1) becomes -1 - (s-1), where the s-1 is given as s.
if P_bigger_than_L then
if abs s > Zero then -- optimization uses fact that c is always positive.
B_pvt := B(upper_left_id);
B_Low := B(lower_right_id);
B(upper_left_id) := B_pvt - s*(-c*B_pvt + B_Low);
B(lower_right_id) := B_Low - s*( -B_pvt - c*B_Low);
end if;
else
B_pvt := B(upper_left_id);
B_Low := B(lower_right_id);
B(upper_left_id) :=-B_Low + c*( B_Pvt - s*B_Low);
B(lower_right_id) := B_Pvt + c*(+s*B_Pvt + B_Low);
end if;
end Inverse_Rotate_Col_Vector;
pragma Inline (Inverse_Rotate_Col_Vector);
-----------------------
-- Rotate_Col_Vector --
-----------------------
-- for getting Q'*B . Uses actual rotation stored in Q, which is the one
-- used to create R .. (so Q really contains Q_transpose.)
procedure Rotate_Col_Vector
(B : in out Col_Vector;
lower_right_id : in R_Index; -- low diagonal element (cos) of rot. matrix
upper_left_id : in R_Index; -- top diagonal element (cos) of rot. matrix
Rot : in Rotation;
P_bigger_than_L : in Boolean)
is
B_pvt, B_Low : Real;
c : real renames Rot.Cosine;
s : real renames Rot.Sine;
begin
if P_bigger_than_L then
if abs s > Zero then -- rot not identity: use fact c is always positive.
B_pvt := B(upper_left_id);
B_Low := B(lower_right_id);
B(upper_left_id) := B_pvt + s*( c*B_pvt + B_Low);
B(lower_right_id) := B_Low + s*( -B_pvt + c*B_Low);
end if;
else
B_pvt := B(upper_left_id);
B_Low := B(lower_right_id);
B(upper_left_id) := B_Low + c*( B_Pvt + s*B_Low);
B(lower_right_id) :=-B_Pvt + c*(-s*B_Pvt + B_Low);
end if;
end Rotate_Col_Vector;
pragma Inline (Rotate_Col_Vector);
-----------------------------------
-- Find_Id_Of_Max_Element_Of_Row --
-----------------------------------
procedure Get_Id_Of_Max_Element_Of_Row
(The_Row : in Row_Vector;
Starting_Col : in C_Index;
Final_Col : in C_Index;
Id_Of_Max_Element : out C_Index;
Val_of_Max_Element : out Real)
is
Val : Real;
begin
Id_Of_Max_Element := Starting_Col;
Val_of_Max_Element := Abs The_Row(Starting_Col);
if Final_Col > Starting_Col then
for k in Starting_Col+1 .. Final_Col loop
Val := The_Row(k);
if Abs Val > Val_of_Max_Element then
Val_of_Max_Element := Val;
Id_Of_Max_Element := k;
end if;
end loop;
end if;
end Get_Id_Of_Max_Element_Of_Row;
------------------
-- QR_Decompose --
------------------
procedure QR_Decompose
(A : in out A_Matrix;
Q : out Q_Matrix;
Row_Scalings : out Col_Vector;
Col_Permutation : out Permutation;
Final_Row : in R_Index := R_Index'Last;
Final_Col : in C_Index := C_Index'Last;
Starting_Row : in R_Index := R_Index'First;
Starting_Col : in C_Index := C_Index'First)
is
No_of_Rows : constant Real
:= Real (Final_Row) - Real (Starting_Row) + One;
No_of_Cols : constant Real
:= Real (Final_Col) - Real (Starting_Col) + One;
Pivot_Row : R_Index := Starting_Row; -- essential init.
Norm_Squ_of_Col_of_A : Row_Vector;
------------------------------------------------
-- Rotate_Rows_to_Zero_Out_Element_Lo_of_pCol --
------------------------------------------------
-- cos = P/r, sin = L/r, r = sqrt(P*P + L*L)
--
-- (P is for Pivot, L is for Low.
--
-- clockwise rotation: notice all rotations are centered on the diagonal
--
-- 1 0 0 0 0 0 0
-- 0 c s 0 0 P r
-- 0 -s c 0 0 x L = 0
-- 0 0 0 1 0 0 0
-- 0 0 0 0 1 0 0
--
--
-- if |L| >= |P| then tn = P/L <= 1
-- if |P| > |L| then tn = L/P < 1
--
--
-- let t = smaller / larger
--
-- let u = 1/sqrt(1+t*t) and w = sqrt(t*t/(1+t*t)) with
--
-- use (1 - 1/sqrt(1+t*t)) * (1 + 1/sqrt(1+t*t)) = t*t / (1 + t*t)
--
-- 1/sqrt(1+t*t) - 1 = - t*t/(sqrt(1+t*t) + 1+t*t)
-- = -(t/(sqrt(1+t*t))*(t/(1 + Sqrt(1+t*t)))
-- = - Abs (w) * Abs (t)/(1+ sqrt(1+t*t))
-- = u_lo
--
-- u_hi = 1 => u_lo + u_hi = 1/sqrt(1+t*t) = u = Abs (cs) if a<b
--
--
-- hypot = |L| * sqrt(1+t*t) = |L| * (1 + t*t/(1+sqrt(1+t*t)) = hi + lo if t<1
--
--
procedure Rotate_Rows_to_Zero_Out_Element_Lo_of_pCol
(pCol : in C_Index;
Hi_Row : in R_Index;
Lo_Row : in R_Index)
is
Pivot_Col : C_Index renames pCol;
Pivot_Row : R_Index renames Hi_Row;
Low_Row : R_Index renames Lo_Row;
tn, sq : real;
sn, cn : Real;
A_pvt, A_low : real;
cn_minus_1_over_sn, sn_minus_1_over_cn : real;
P : Real := A(Pivot_Row, Pivot_Col); -- P is for Pivot
L : Real := A(Low_Row, Pivot_Col);
Abs_P : constant Real := Abs (P);
Abs_L : constant Real := Abs (L);
P_bigger_than_L : Boolean := True;
begin
-- use Identity if no rotation is performed:
Q.Rot(Low_Row, Pivot_Col).Cosine := Zero;
Q.Rot(Low_Row, Pivot_Col).Sine := Zero;
Q.P_bigger_than_L(Low_Row, Pivot_Col) := True;
if (not L'Valid) or (not P'Valid) then
return; -- having updated Q w. identity
end if;
if Abs_P > Abs_L then -- |s| < |c|
if Abs_P > Zero then
P_bigger_than_L := True;
-- Make P>0 always, so if P<0 then flip signs of both P and L
-- to ensure zero'd out element.
if P < Zero then
L := -L; P := Abs_P;
end if;
tn := L / P; -- P>0 so t has sign of L
sq := Sqrt (One + tn*tn);
sn := tn / sq; -- sn has sign of L
cn_minus_1_over_sn :=-tn / (One + sq);
-- factored out the sn from cn_minus_1
for Col in Pivot_Col .. Final_Col loop
A_pvt := A(Pivot_Row, Col);
A_low := A(Low_Row, Col);
A(Pivot_Row, Col) := A_pvt + sn * (cn_minus_1_over_sn*A_pvt + A_low);
A(Low_Row, Col) := A_low + sn * (-A_pvt + cn_minus_1_over_sn*A_low);
end loop;
Q.Rot(Low_Row, Pivot_Col).Cosine := cn_minus_1_over_sn;
Q.Rot(Low_Row, Pivot_Col).Sine := sn;
Q.P_bigger_than_L(Low_Row, Pivot_Col) := P_bigger_than_L;
end if;
else -- Abs_P <= Abs_L, so abs t := abs (P / L) <= 1
if Abs_L > Zero then
P_bigger_than_L := False;
-- Make L>0 always, so if L<0 then flip signs of both P and L
-- to ensure zero'd out element.
if L < Zero then
L := Abs_L; P := -P;
end if;
tn := P / L; -- L>0 now so, t has sign of P.
sq := Sqrt (One + tn*tn);
cn := tn / sq; -- has sign of P
sn_minus_1_over_cn :=-tn / (One + sq);
-- factored out the cn from sn_minus_1
for Col in Pivot_Col .. Final_Col loop
A_pvt := A(Pivot_Row, Col);
A_low := A(Low_Row, Col);
A(Pivot_Row, Col) := A_low + cn * (A_pvt + sn_minus_1_over_cn*A_low);
A(Low_Row, Col) :=-A_pvt + cn * (-sn_minus_1_over_cn*A_pvt + A_low);
end loop;
Q.Rot(Low_Row, Pivot_Col).Cosine := cn;
Q.Rot(Low_Row, Pivot_Col).Sine := sn_minus_1_over_cn;
Q.P_bigger_than_L(Low_Row, Pivot_Col) := P_bigger_than_L;
end if; -- Abs_L > Zero
end if;
end Rotate_Rows_to_Zero_Out_Element_Lo_of_pCol;
procedure Scale_Rows
(Row_Scalings : out Col_Vector;
Starting_Col : in C_Index := C_Index'First;
Final_Col : in C_Index := C_Index'Last;
Starting_Row : in R_Index := R_Index'First;
Final_Row : in R_Index := R_Index'Last)
is
Norm : Real;
Scale_Factor, Abs_A : Real;
begin
Row_Scalings := (others => One); -- important init
for Row in Starting_Row .. Final_Row loop
--Norm := Zero;
--Get_1_Norm:
--for Col in Starting_Col .. Final_Col loop
--if not A(Row, Col)'valid then raise constraint_error with "7"; end if;
--Norm := Norm + abs A(Row, Col);
--end loop Get_1_Norm;
Norm := Zero;
Get_Infinity_Norm:
for Col in Starting_Col .. Final_Col loop
Abs_A := Abs A(Row, Col);
if Abs_A > Norm then Norm := Abs_A; end if;
end loop Get_Infinity_Norm;
if not Norm'Valid then
raise Ada.Numerics.Argument_Error with "Elements of input matrix invalid.";
end if;
if Norm < Two ** (Real'Machine_Emin - Real'Machine_Emin/16) then
Scale_Factor := Zero;
else
declare
Norm_Exp : constant Integer := Real'Exponent (Norm);
begin
Scale_Factor := Two ** (-Norm_Exp);
end;
end if;
Row_Scalings(Row) := Scale_Factor;
end loop;
for Row in Starting_Row .. Final_Row loop
for Col in Starting_Col .. Final_Col loop
A(Row, Col) := Row_Scalings(Row) * A(Row, Col);
end loop;
end loop;
end Scale_Rows;
-- Find sub Col_Vector with max norm, swap Columns if necessary.
procedure Do_Column_Pivoting
(Starting_Col : in C_Index;
Final_Col : in C_Index;
Starting_Row : in R_Index;
Final_Row : in R_Index;
Pivot_Col : in C_Index;
Col_Permutation : in out Permutation;
Col_Norm_Squared : in out Row_Vector)
is
Pivot_Row : constant R_Index := R_Index (Pivot_Col);
tmp_index, New_Pivot_Col : C_Index;
Pivot_Val, tmp : Real;
begin
if Pivot_Col >= Final_Col then return; end if;
if (Pivot_Col = Starting_Col) or else
((Int64(Pivot_Col) - Int64(Starting_Col)) mod 6 = 0) then
-- Without row scaling, we get overflows if matrix is too large.
-- Get the right answer accurately every N steps:
Col_Norm_Squared := (others => Zero);
for r in Pivot_Row .. Final_Row loop
for c in Pivot_Col .. Final_Col loop
Col_Norm_Squared(c) := Col_Norm_Squared(c) + A(r, c)**2;
end loop;
end loop; -- fastest with Ada array convention rather than fortran.
else
-- Optimization: length of Col is invariant under rotations, so just
-- subtract away the unwanted element in Col from the old sum for Norm_Squ:
-- Norm_Squared (Col) := Norm_Squared (Col) - A(Pivot_Row-1, Col)**2;
-- Has bad accuracy.
for c in Pivot_Col .. Final_Col loop
Col_Norm_Squared(c) := Col_Norm_Squared(c) - A(Pivot_Row-1, c)**2;
end loop;
end if;
Get_Id_Of_Max_Element_Of_Row
(The_Row => Col_Norm_Squared,
Starting_Col => Pivot_Col,
Final_Col => Final_Col,
Id_Of_Max_Element => New_Pivot_Col,
Val_of_Max_Element => Pivot_Val);
if New_Pivot_Col > Pivot_Col then
for r in Starting_Row .. Final_Row loop
tmp := A(r, New_Pivot_Col);
A(r, New_Pivot_Col) := A(r, Pivot_Col);
A(r, Pivot_Col) := tmp;
end loop;
tmp := Col_Norm_Squared (New_Pivot_Col);
Col_Norm_Squared(New_Pivot_Col) := Col_Norm_Squared (Pivot_Col);
Col_Norm_Squared(Pivot_Col) := tmp;
tmp_index := Col_Permutation(New_Pivot_Col);
Col_Permutation(New_Pivot_Col) := Col_Permutation(Pivot_Col);
Col_Permutation(Pivot_Col) := tmp_index;
end if;
end Do_Column_Pivoting;
begin
-- Important Inits.
Q.Rot := (others => (others => Identity));
Q.P_bigger_than_L := (others => (others => True));
Q.Final_Row := Final_Row;
Q.Final_Col := Final_Col;
Q.Starting_Row := Starting_Row;
Q.Starting_Col := Starting_Col;
Row_Scalings := (others => One); -- important init
for j in C_Index loop
Col_Permutation(j) := j;
end loop;
if No_Of_Cols > No_of_Rows then
raise Ada.Numerics.Argument_Error with "Can't have more columns than rows.";
end if;
if No_Of_Cols < 2.0 then
raise Ada.Numerics.Argument_Error with "Need at least 2 columns in matrix.";
end if;
-- Step 1. Column Scaling. Scaling prevents overflow when 2-norms are calculated.
if Scaling_Desired then
Scale_Rows
(Row_Scalings => Row_Scalings,
Starting_Col => Starting_Col,
Final_Col => Final_Col,
Starting_Row => Starting_Row,
Final_Row => Final_Row);
end if;
-- Start the QR decomposition
Pivot_Row := Starting_Row; -- essential init.
for Pivot_Col in Starting_Col .. Final_Col loop
if Pivoting_Desired then
Do_Column_Pivoting
(Starting_Col => Starting_Col,
Final_Col => Final_Col,
Starting_Row => Starting_Row,
Final_Row => Final_Row,
Pivot_Col => Pivot_Col,
Col_Permutation => Col_Permutation,
Col_Norm_Squared => Norm_Squ_of_Col_of_A);
end if; -- pivoting_desired
if Pivot_Row < Final_Row then
for Low_Row in Pivot_Row+1 .. Final_Row loop
Rotate_Rows_to_Zero_Out_Element_Lo_of_pCol
(pCol => Pivot_Col, -- Element to zero out is A(Lo_Row, pCol)
Hi_Row => Pivot_Row, -- High to the eye; its id is lower than Lo_Row's.
Lo_Row => Low_Row);
A(Low_Row, Pivot_Col) := Zero;
end loop; -- over Low_Row
end if; -- Pivot_Row < Final_Row
if Pivot_Row < Final_Row then Pivot_Row := Pivot_Row + 1; end if;
-- We are always finished if Pivot_Row = Final_Row because have M rows >= N cols
end loop; -- over Pivot_Col
-- To unscale the R matrix (A) you scale the Cols of A=R w/ Inv_Row_Scalings(Col).
-- Bad idea because the scaled R=A has diag elements in monotonic decreasing order.
end QR_Decompose;
--------------------
-- Q_x_Col_Vector --
--------------------
-- Get Product = Q*B
--
-- Apply the inverses of all the 2x2 rotation matrices in the order opposite to the
-- order in which they were created: Start w/ most recent and wrk backwards in time.
function Q_x_Col_Vector
(Q : in Q_Matrix;
B : in Col_Vector)
return Col_Vector
is
Product : Col_Vector;
Final_Row : R_Index renames Q.Final_Row;
Final_Col : C_Index renames Q.Final_Col;
Starting_Row : R_Index renames Q.Starting_Row;
Starting_Col : C_Index renames Q.Starting_Col;
Pivot_Row : R_Index := Starting_Row;
P_is_the_Bigger : Boolean;
begin
-- The loop bounds reflect the design of Q. Q is stored in
-- matrix A, which was defined to be M x N via Starting_Row,
-- Starting_Col, etc.
Product := B;
Pivot_Row := R_Index (Int64(Final_Col) + Int64(Starting_Row) - Int64(Starting_Col));
for Pivot_Col in reverse Starting_Col .. Final_Col loop
if Pivot_Row < Final_Row then
for Low_Row in reverse Pivot_Row+1 .. Final_Row loop
P_is_the_bigger := Q.P_bigger_than_L (Low_Row, Pivot_Col);
Inverse_Rotate_Col_Vector
(Product, Low_Row, Pivot_Row, Q.Rot(Low_Row, Pivot_Col), P_is_the_bigger);
end loop;
end if;
if Pivot_Row > Starting_Row then Pivot_Row := Pivot_Row - 1; end if;
end loop;
return Product;
end Q_x_Col_Vector;
------------------------------
-- Q_transpose_x_Col_Vector --
------------------------------
-- Get Product = Q'*B
--
-- Apply the the 2x2 rotation matrices in the order in which they were created.
-- Start w/ oldest and wrk forwards in time.
function Q_transpose_x_Col_Vector
(Q : in Q_Matrix;
B : in Col_Vector)
return Col_Vector
is
Product : Col_Vector;
Final_Row : R_Index renames Q.Final_Row;
Final_Col : C_Index renames Q.Final_Col;
Starting_Row : R_Index renames Q.Starting_Row;
Starting_Col : C_Index renames Q.Starting_Col;
Pivot_Row : R_Index := Starting_Row;
P_is_the_bigger : Boolean;
begin
-- The loop bounds reflect the design of Q. Q is stored in
-- matrix A, which was defined to be M x N via Starting_Row,
-- Starting_Col, etc.
Product := B;
Pivot_Row := Starting_Row;
for Pivot_Col in Starting_Col .. Final_Col loop
if Pivot_Row < Final_Row then
for Low_Row in Pivot_Row+1 .. Final_Row loop
P_is_the_bigger := Q.P_bigger_than_L (Low_Row, Pivot_Col);
Rotate_Col_Vector (Product, Low_Row, Pivot_Row,
Q.Rot(Low_Row, Pivot_Col), P_is_the_bigger);
end loop;
Pivot_Row := Pivot_Row + 1;
end if;
end loop;
return Product;
end Q_transpose_x_Col_Vector;
--------------
-- QR_Solve --
--------------
-- A*X = B.
-- S*A*P = Q*R where S is diagonal matrix of row scalings; P permutes cols.
-- So X = P*R^(-1)*Q'*S*B where Q is orthogonal, so Q' = Q^(-1).
procedure QR_Solve
(X : out Row_Vector;
B : in Col_Vector;
R : in A_Matrix; -- We overwrote A with R, so input A here.
Q : in Q_Matrix;
Row_Scalings : in Col_Vector;
Col_Permutation : in Permutation;
Singularity_Cutoff : in Real := Default_Singularity_Cutoff)
is
Final_Row : R_Index renames Q.Final_Row;
Final_Col : C_Index renames Q.Final_Col;
Starting_Row : R_Index renames Q.Starting_Row;
Starting_Col : C_Index renames Q.Starting_Col;
Max_R_Diagonal_Val : constant Real := Abs R(Starting_Row, Starting_Col);
R_Diagonal_Inv : Row_Vector;
Sum : Real;
B1, B2 : Col_Vector;
B0, X0 : Row_Vector;
Row : R_Index := Starting_Row;
begin
-- X = P * R_inverse * Q' * S * B where diagonal matrix S scaled the rows of A
for i in R_Index loop
B2(i) := Row_Scalings(i) * B(i); -- Row_Scalings was initialized to 1.
end loop;
-- X is out, so init:
for j in C_Index loop
X(j) := Zero;
X0(j) := Zero;
end loop;
-- Get B1 = Q'*B2
B1 := Q_transpose_x_Col_Vector (Q, B2);
-- put Column B1 into a row B0 of A (ie indexed by C_Index):
for i in Starting_Col .. Final_Col loop
Row := R_Index(Int64 (i-Starting_Col) + Int64(Starting_Row));
B0(i) := B1(Row);
end loop;
-- Now R*X0 = B0; solve for X0.
-- No_of_Rows >= No_of_Cols. We stop at Final_Col, so
-- effectively we are assuming that R is square (upper triangular actually).
Row := Starting_Row;
for Col in Starting_Col .. Final_Col loop
if Abs R(Row,Col) < Abs (Singularity_Cutoff * Max_R_Diagonal_Val) or
Abs R(Row,Col) < Min_Allowed_Real then
R_Diagonal_Inv(Col) := Zero;
else
R_Diagonal_Inv(Col) := One / R(Row,Col);
end if;
if Row < Final_Row then Row := Row + 1; end if;
end loop;
X0(Final_Col) := B0(Final_Col) * R_Diagonal_Inv(Final_Col);
if Final_Col > Starting_Col then
for Col in reverse Starting_Col .. Final_Col-1 loop
Row := R_Index (Int64 (Col-Starting_Col) + Int64 (Starting_Row));
Sum := Zero;
for j in Col+1 .. Final_Col loop
Sum := Sum + R(Row, j) * X0(j);
end loop;
X0(Col) := (B0(Col) - Sum) * R_Diagonal_Inv(Col);
end loop;
end if;
for i in C_Index loop
X(Col_Permutation(i)) := X0(i);
end loop;
-- x = S * P * R_inverse * Q' * B
end QR_Solve;
------------------
-- Q_x_V_Matrix --
------------------
-- Get Product = Q*V
-- The columns of V are vectors indexed by R_index.
-- Not Q' times Matrix V but Q*V, so
-- apply the inverses of all the 2x2 rotation matrices in the order opposite to the
-- order in which they were created: Start w/ most recent and wrk backwards in time.
-- The columns of V must be same length as Columns of original matrix A, (hence Q).
-- The number of these Cols is unimportant (set statically: V is a generic formal).
-- Q is MxM: No_of_Rows x No_of_Rows, since Q*R = A, and R has shape of A.
procedure Q_x_V_Matrix
(Q : in Q_Matrix;
V : in out V_Matrix)
is
Final_Row : R_Index renames Q.Final_Row;
Final_Col : C_Index renames Q.Final_Col;
Starting_Row : R_Index renames Q.Starting_Row;
Starting_Col : C_Index renames Q.Starting_Col;
s, c : Real;
V_pvt, V_Low : Real;
Pivot_Row : R_Index := Starting_Row;
begin
-- The loop bounds reflect the design of Q. Q is stored in
-- matrix A, which was defined to be M x N via Starting_Row,
-- Starting_Col, etc.
Pivot_Row := R_Index (Integer(Final_Col)
+ Integer (Starting_Row) - Integer(Starting_Col));
-- The following 2 loops range over all the 2x2 rotation matrices in Q.
-- Each 2x2 rotates 2 Row_Vectors of V.
-- The columns of V must be same length as Columns of original matrix A, (hence Q).
for Pivot_Col in reverse Starting_Col .. Final_Col loop
if Pivot_Row < Final_Row then
for Low_Row in reverse Pivot_Row+1 .. Final_Row loop
s := Q.Rot(Low_Row, Pivot_Col).Sine;
c := Q.Rot(Low_Row, Pivot_Col).Cosine;
if Q.P_bigger_than_L(Low_Row, Pivot_Col) then --abs A(piv,piv )> abs A(low,piv)
--if abs s > Zero then -- rot isn't identity: use fact c is always positive.
for Col in V'Range(2) loop
V_pvt := V(Pivot_Row, Col);
V_Low := V(Low_Row, Col);
V(Pivot_Row, Col) := V_pvt - s*(-c*V_pvt + V_Low);
V(Low_Row, Col) := V_Low - s*( -V_pvt - c*V_Low);
end loop;
--end if;
else
for Col in V'Range(2) loop
V_pvt := V(Pivot_Row, Col);
V_Low := V(Low_Row, Col);
V(Pivot_Row, Col) :=-V_Low + c*( V_Pvt - s*V_Low);
V(Low_Row, Col) := V_Pvt + c*(+s*V_Pvt + V_Low);
end loop;
end if;
end loop; -- Low_Row in Final_Row to Pivot_Row+1
end if;
if Pivot_Row > Starting_Row then Pivot_Row := Pivot_Row - 1; end if;
end loop;
end Q_x_V_Matrix;
----------------------------
-- Q_transpose_x_V_Matrix --
----------------------------
-- Get Product = Q'*V
--
-- Apply the the 2x2 rotation matrices in the order in which they were created.
-- Start w/ oldest and wrk forwards in time. Use the same rotation used to
-- create R (ie the actual rotation stored on Q, not its inverse.
-- Q really contains Q_transpose.)
--
-- The columns of V are vectors indexed by R_index.
-- The columns of V must be same length as Columns of original matrix A, (hence Q).
-- The number of these Cols is unimportant (set statically: V is a generic formal).
-- Q is MxM: No_of_Rows x No_of_Rows, (since Q*R = A, and R has shape of A).
--
procedure Q_transpose_x_V_Matrix
(Q : in Q_Matrix;
V : in out V_Matrix)
is
Final_Row : R_Index renames Q.Final_Row;
Final_Col : C_Index renames Q.Final_Col;
Starting_Row : R_Index renames Q.Starting_Row;
Starting_Col : C_Index renames Q.Starting_Col;
s, c : Real;
V_pvt, V_Low : Real;
Pivot_Row : R_Index := Starting_Row;
begin
-- The loop bounds reflect the design of Q. Q is stored in
-- matrix A, which was defined to be M x N via Starting_Row,
-- Starting_Col, etc.
-- The following 2 loops range over all the 2x2 rotation matrices in Q.
-- Each 2x2 rotates 2 Row_Vectors of V.
-- The columns of V must be same length as Columns of original matrix A, (hence Q).
Pivot_Row := Starting_Row;
for Pivot_Col in Starting_Col .. Final_Col loop
if Pivot_Row < Final_Row then
for Low_Row in Pivot_Row+1 .. Final_Row loop
s := Q.Rot(Low_Row, Pivot_Col).Sine;
c := Q.Rot(Low_Row, Pivot_Col).Cosine;
if Q.P_bigger_than_L(Low_Row, Pivot_Col) then --abs A(piv,piv )> abs A(low,piv)
--if abs s > Zero then -- rot not identity: use fact c is always positive.
for Col in V'Range(2) loop
V_pvt := V(Pivot_Row, Col);
V_Low := V(Low_Row, Col);
V(Pivot_Row, Col) := V_pvt + s*(c*V_pvt + V_Low);
V(Low_Row, Col) := V_Low + s*( -V_pvt + c*V_Low);
end loop;
--end if;
else
for Col in V'Range(2) loop
V_pvt := V(Pivot_Row, Col);
V_Low := V(Low_Row, Col);
V(Pivot_Row, Col) := V_Low + c*( V_Pvt + s*V_Low);
V(Low_Row, Col) :=-V_Pvt + c*(-s*V_Pvt + V_Low);
end loop;
end if;
end loop;
Pivot_Row := Pivot_Row + 1;
end if;
end loop;
end Q_transpose_x_V_Matrix;
--------------------
-- Q_x_Matrix --
--------------------
-- Get Product = Q*A
procedure Q_x_Matrix
(Q : in Q_Matrix;
A : in out A_Matrix)
is
B : Col_Vector := (others => Zero);
C : Col_Vector;
Final_Row : R_Index renames Q.Final_Row;
Final_Col : C_Index renames Q.Final_Col;
Starting_Row : R_Index renames Q.Starting_Row;
Starting_Col : C_Index renames Q.Starting_Col;
begin
for Col in Starting_Col .. Final_Col loop
for Row in Starting_Row .. Final_Row loop
B(Row) := A(Row, Col);
end loop;
C := Q_x_Col_Vector (Q, B);
for Row in Starting_Row .. Final_Row loop
A(Row, Col) := C(Row);
end loop;
end loop;
end Q_x_Matrix;
end Givens_QR;
|
zrmyers/VulkanAda | Ada | 1,826 | ads | --------------------------------------------------------------------------------
-- MIT License
--
-- Copyright (c) 2021 Zane Myers
--
-- 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.
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--< @group Vulkan Math Basic Types
--------------------------------------------------------------------------------
--< @summary
--< This package tests a single precision floating point vector with 3 components.
--------------------------------------------------------------------------------
package Vulkan.Math.Vec3.Test is
-- Test Harness for Mat2x2 regression tests
procedure Test_Vec3;
end Vulkan.Math.Vec3.Test;
|
MinimSecure/unum-sdk | Ada | 927 | ads | -- Copyright 2008-2019 Free Software Foundation, Inc.
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; either version 3 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
package Pck is
package First is
IntegerVar : Integer := 48;
end First;
package Second is
IntegerVar : Integer := 74;
end Second;
procedure Do_Nothing (Val : in out Integer);
end Pck;
|
optikos/oasis | Ada | 4,904 | ads | -- Copyright (c) 2019 Maxim Reznik <[email protected]>
--
-- SPDX-License-Identifier: MIT
-- License-Filename: LICENSE
-------------------------------------------------------------
with Program.Lexical_Elements;
with Program.Elements.Defining_Identifiers;
with Program.Elements.Discrete_Ranges;
with Program.Elements.Entry_Index_Specifications;
with Program.Element_Visitors;
package Program.Nodes.Entry_Index_Specifications is
pragma Preelaborate;
type Entry_Index_Specification is
new Program.Nodes.Node
and Program.Elements.Entry_Index_Specifications
.Entry_Index_Specification
and Program.Elements.Entry_Index_Specifications
.Entry_Index_Specification_Text
with private;
function Create
(For_Token : not null Program.Lexical_Elements
.Lexical_Element_Access;
Name : not null Program.Elements.Defining_Identifiers
.Defining_Identifier_Access;
In_Token : not null Program.Lexical_Elements
.Lexical_Element_Access;
Entry_Index_Subtype : not null Program.Elements.Discrete_Ranges
.Discrete_Range_Access)
return Entry_Index_Specification;
type Implicit_Entry_Index_Specification is
new Program.Nodes.Node
and Program.Elements.Entry_Index_Specifications
.Entry_Index_Specification
with private;
function Create
(Name : not null Program.Elements.Defining_Identifiers
.Defining_Identifier_Access;
Entry_Index_Subtype : not null Program.Elements.Discrete_Ranges
.Discrete_Range_Access;
Is_Part_Of_Implicit : Boolean := False;
Is_Part_Of_Inherited : Boolean := False;
Is_Part_Of_Instance : Boolean := False)
return Implicit_Entry_Index_Specification
with Pre =>
Is_Part_Of_Implicit or Is_Part_Of_Inherited or Is_Part_Of_Instance;
private
type Base_Entry_Index_Specification is
abstract new Program.Nodes.Node
and Program.Elements.Entry_Index_Specifications
.Entry_Index_Specification
with record
Name : not null Program.Elements.Defining_Identifiers
.Defining_Identifier_Access;
Entry_Index_Subtype : not null Program.Elements.Discrete_Ranges
.Discrete_Range_Access;
end record;
procedure Initialize
(Self : aliased in out Base_Entry_Index_Specification'Class);
overriding procedure Visit
(Self : not null access Base_Entry_Index_Specification;
Visitor : in out Program.Element_Visitors.Element_Visitor'Class);
overriding function Name
(Self : Base_Entry_Index_Specification)
return not null Program.Elements.Defining_Identifiers
.Defining_Identifier_Access;
overriding function Entry_Index_Subtype
(Self : Base_Entry_Index_Specification)
return not null Program.Elements.Discrete_Ranges.Discrete_Range_Access;
overriding function Is_Entry_Index_Specification_Element
(Self : Base_Entry_Index_Specification)
return Boolean;
overriding function Is_Declaration_Element
(Self : Base_Entry_Index_Specification)
return Boolean;
type Entry_Index_Specification is
new Base_Entry_Index_Specification
and Program.Elements.Entry_Index_Specifications
.Entry_Index_Specification_Text
with record
For_Token : not null Program.Lexical_Elements.Lexical_Element_Access;
In_Token : not null Program.Lexical_Elements.Lexical_Element_Access;
end record;
overriding function To_Entry_Index_Specification_Text
(Self : aliased in out Entry_Index_Specification)
return Program.Elements.Entry_Index_Specifications
.Entry_Index_Specification_Text_Access;
overriding function For_Token
(Self : Entry_Index_Specification)
return not null Program.Lexical_Elements.Lexical_Element_Access;
overriding function In_Token
(Self : Entry_Index_Specification)
return not null Program.Lexical_Elements.Lexical_Element_Access;
type Implicit_Entry_Index_Specification is
new Base_Entry_Index_Specification
with record
Is_Part_Of_Implicit : Boolean;
Is_Part_Of_Inherited : Boolean;
Is_Part_Of_Instance : Boolean;
end record;
overriding function To_Entry_Index_Specification_Text
(Self : aliased in out Implicit_Entry_Index_Specification)
return Program.Elements.Entry_Index_Specifications
.Entry_Index_Specification_Text_Access;
overriding function Is_Part_Of_Implicit
(Self : Implicit_Entry_Index_Specification)
return Boolean;
overriding function Is_Part_Of_Inherited
(Self : Implicit_Entry_Index_Specification)
return Boolean;
overriding function Is_Part_Of_Instance
(Self : Implicit_Entry_Index_Specification)
return Boolean;
end Program.Nodes.Entry_Index_Specifications;
|
micahwelf/FLTK-Ada | Ada | 1,790 | ads |
with
FLTK.Images.RGB,
FLTK.Images.Shared,
FLTK.Widgets.Groups.Windows;
package FLTK.Devices.Surfaces.Image is
type Image_Surface is new Surface_Device with private;
type Image_Surface_Reference (Data : not null access Image_Surface'Class) is
limited null record with Implicit_Dereference => Data;
package Forge is
function Create
(W, H : in Integer;
Highres : in Boolean := False)
return Image_Surface;
end Forge;
function Is_Highres
(This : in Image_Surface)
return Boolean;
procedure Draw_Widget
(This : in out Image_Surface;
Item : in FLTK.Widgets.Widget'Class;
Offset_X, Offset_Y : in Integer := 0);
procedure Draw_Decorated_Window
(This : in out Image_Surface;
Item : in FLTK.Widgets.Groups.Windows.Window'Class;
Offset_X, Offset_Y : in Integer := 0);
function Get_Image
(This : in Image_Surface)
return FLTK.Images.RGB.RGB_Image;
function Get_Highres_Image
(This : in Image_Surface)
return FLTK.Images.Shared.Shared_Image;
procedure Set_Current
(This : in out Image_Surface);
private
type Image_Surface is new Surface_Device with record
High : Boolean := False;
end record;
overriding procedure Finalize
(This : in out Image_Surface);
pragma Inline (Is_Highres);
pragma Inline (Draw_Widget);
pragma Inline (Draw_Decorated_Window);
pragma Inline (Get_Image);
pragma Inline (Get_Highres_Image);
pragma Inline (Set_Current);
end FLTK.Devices.Surfaces.Image;
|
stcarrez/ada-awa | Ada | 16,929 | adb | -----------------------------------------------------------------------
-- awa-wikis-tests -- Unit tests for wikis module
-- Copyright (C) 2018, 2019, 2020, 2022, 2023 Stephane Carrez
-- Written by Stephane Carrez ([email protected])
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-----------------------------------------------------------------------
with Util.Test_Caller;
with Util.Strings;
with ADO;
with Servlet.Streams;
with ASF.Tests;
with AWA.Tests.Helpers.Users;
with AWA.Storages.Beans;
with AWA.Storages.Models;
with AWA.Storages.Services;
with AWA.Storages.Modules;
with AWA.Services.Contexts;
with Security.Contexts;
package body AWA.Wikis.Tests is
use Ada.Strings.Unbounded;
use AWA.Tests;
use type AWA.Storages.Services.Storage_Service_Access;
package Caller is new Util.Test_Caller (Test, "Wikis.Beans");
procedure Add_Tests (Suite : in Util.Tests.Access_Test_Suite) is
begin
Caller.Add_Test (Suite, "Test AWA.Wikis.Beans.Load_List (Anonymous)",
Test_Anonymous_Access'Access);
Caller.Add_Test (Suite, "Test AWA.Wikis.Beans.Save",
Test_Create_Wiki'Access);
Caller.Add_Test (Suite, "Test AWA.Wikis.Beans.Load (missing)",
Test_Missing_Page'Access);
Caller.Add_Test (Suite, "Test AWA.Wikis.Beans.Load (image)",
Test_Page_With_Image'Access);
end Add_Tests;
-- ------------------------------
-- Setup an image for the wiki page.
-- ------------------------------
procedure Make_Wiki_Image (T : in out Test) is
Sec_Ctx : Security.Contexts.Security_Context;
Context : AWA.Services.Contexts.Service_Context;
Folder : AWA.Storages.Beans.Folder_Bean;
Store : AWA.Storages.Models.Storage_Ref;
Mgr : AWA.Storages.Services.Storage_Service_Access;
Outcome : Ada.Strings.Unbounded.Unbounded_String;
Path : constant String
:= Util.Tests.Get_Path ("regtests/files/images/Ada-Lovelace.jpg");
Wiki : constant String := To_String (T.Wiki_Ident);
begin
AWA.Tests.Helpers.Users.Login (Context, Sec_Ctx, "[email protected]");
Mgr := AWA.Storages.Modules.Get_Storage_Manager;
T.Assert (Mgr /= null, "Null storage manager");
-- Make a storage folder.
Folder.Module := AWA.Storages.Modules.Get_Storage_Module;
Folder.Set_Name ("Images");
Folder.Save (Outcome);
Store.Set_Folder (Folder);
Store.Set_Is_Public (True);
Store.Set_Mime_Type ("image/jpg");
Store.Set_Name ("Ada-Lovelace.jpg");
Mgr.Save (Store, Path, AWA.Storages.Models.FILE);
declare
Request : Servlet.Requests.Mockup.Request;
Reply : Servlet.Responses.Mockup.Response;
Id : constant String := ADO.Identifier'Image (Store.Get_Id);
begin
T.Image_Ident := To_Unbounded_String (Id (Id'First + 1 .. Id'Last));
AWA.Tests.Helpers.Users.Login ("[email protected]", Request);
ASF.Tests.Do_Get (Request, Reply,
"/wikis/images/" & Wiki & "/"
& Id (Id'First + 1 .. Id'Last)
& "/original/Ada-Lovelace.jpg",
"wiki-image-get-Ada-Lovelace.jpg");
ASF.Tests.Assert_Header (T, "Content-Type", "image/jpg", Reply);
Util.Tests.Assert_Equals (T, Servlet.Responses.SC_OK,
Reply.Get_Status,
"Invalid response for image");
T.Image_Link := To_Unbounded_String ("/wikis/images/" & Wiki
& "/" & Id (Id'First + 1 .. Id'Last)
& "/default/Ada-Lovelace.jpg");
end;
end Make_Wiki_Image;
-- ------------------------------
-- Get some access on the wiki as anonymous users.
-- ------------------------------
procedure Verify_Anonymous (T : in out Test;
Page : in String;
Title : in String) is
pragma Unreferenced (Title);
function Get_Link (Title : in String) return String;
Wiki : constant String := To_String (T.Wiki_Ident);
Request : Servlet.Requests.Mockup.Request;
Reply : Servlet.Responses.Mockup.Response;
function Get_Link (Title : in String) return String is
Stream : Servlet.Streams.Print_Stream := Reply.Get_Output_Stream;
Content : Ada.Strings.Unbounded.Unbounded_String;
begin
Reply.Read_Content (Content);
Stream.Write (Content);
return AWA.Tests.Helpers.Extract_Link (To_String (Content), Title);
end Get_Link;
begin
ASF.Tests.Do_Get (Request, Reply, "/wikis/list/" & Wiki & "/recent",
"wiki-list-recent.html");
ASF.Tests.Assert_Contains (T, "List of pages", Reply,
"Wiki list recent page is invalid");
ASF.Tests.Do_Get (Request, Reply, "/wikis/tags/" & Wiki,
"wiki-list-tagged.html");
ASF.Tests.Assert_Contains (T, "List of pages", Reply,
"Wiki tag page is invalid");
if Page'Length > 0 then
ASF.Tests.Do_Get (Request, Reply, "/wikis/view/" & Wiki & "/" & Page,
"wiki-page-" & Page & ".html");
ASF.Tests.Assert_Contains (T, "The wiki page content", Reply,
"Wiki page " & Page & " is invalid");
declare
Info : constant String := Get_Link ("Info");
History : constant String := Get_Link ("History");
begin
Util.Tests.Assert_Matches (T, "/asfunit/wikis/info/[0-9]+/[0-9]+$", Info,
"Invalid wiki info link in the response");
Util.Tests.Assert_Matches (T, "/asfunit/wikis/history/[0-9]+/[0-9]+$", History,
"Invalid wiki history link in the response");
-- Get the information page.
ASF.Tests.Do_Get (Request, Reply, Info (Info'First + 8 .. Info'Last),
"wiki-info-" & Page & ".html");
ASF.Tests.Assert_Contains (T, "wiki-word-list", Reply,
"Wiki info page " & Page & " is invalid");
-- Get the history page.
ASF.Tests.Do_Get (Request, Reply, History (History'First + 8 .. History'Last),
"wiki-history-" & Page & ".html");
ASF.Tests.Assert_Contains (T, "wiki-page-version", Reply,
"Wiki history page " & Page & " is invalid");
end;
end if;
end Verify_Anonymous;
-- ------------------------------
-- Verify that the wiki lists contain the given page.
-- ------------------------------
procedure Verify_List_Contains (T : in out Test;
Page : in String) is
Wiki : constant String := To_String (T.Wiki_Ident);
Request : Servlet.Requests.Mockup.Request;
Reply : Servlet.Responses.Mockup.Response;
begin
ASF.Tests.Do_Get (Request, Reply, "/wikis/list/" & Wiki & "/recent",
"wiki-list-recent.html");
ASF.Tests.Assert_Contains (T, "List of pages", Reply,
"Wiki list recent page is invalid");
ASF.Tests.Assert_Contains (T, "/wikis/view/" & To_String (T.Wiki_Ident)
& "/" & Page, Reply,
"Wiki list recent page does not reference the page");
ASF.Tests.Do_Get (Request, Reply, "/wikis/list/" & Wiki & "/popular",
"wiki-list-popular.html");
ASF.Tests.Assert_Contains (T, "List of pages", Reply,
"Wiki list popular page is invalid");
ASF.Tests.Assert_Contains (T, "/wikis/view/" & To_String (T.Wiki_Ident)
& "/" & Page, Reply,
"Wiki list popular page does not reference the page");
ASF.Tests.Do_Get (Request, Reply, "/wikis/list/" & Wiki & "/name",
"wiki-list-name.html");
ASF.Tests.Assert_Contains (T, "List of pages", Reply,
"Wiki list name page is invalid");
ASF.Tests.Assert_Contains (T, "/wikis/view/" & To_String (T.Wiki_Ident)
& "/" & Page, Reply,
"Wiki list name page does not reference the page");
ASF.Tests.Do_Get (Request, Reply, "/wikis/list/" & Wiki & "/name/grid",
"wiki-list-name-grid.html");
ASF.Tests.Assert_Contains (T, "List of pages", Reply,
"Wiki list name/grid page is invalid");
ASF.Tests.Assert_Contains (T, "/wikis/view/" & To_String (T.Wiki_Ident)
& "/" & Page, Reply,
"Wiki list name/grid page does not reference the page");
end Verify_List_Contains;
-- ------------------------------
-- Test access to the blog as anonymous user.
-- ------------------------------
procedure Test_Anonymous_Access (T : in out Test) is
begin
T.Verify_Anonymous ("", "");
end Test_Anonymous_Access;
-- ------------------------------
-- Create a wiki page.
-- ------------------------------
procedure Create_Page (T : in out Test;
Request : in out Servlet.Requests.Mockup.Request;
Reply : in out Servlet.Responses.Mockup.Response;
Name : in String;
Title : in String) is
begin
ASF.Tests.Do_Get (Request, Reply, "/wikis/create.html", "create-wiki-get.html");
Request.Set_Parameter ("page-wiki-id", To_String (T.Wiki_Ident));
-- Request.Set_Parameter ("post", "1");
Request.Set_Parameter ("page-title", Title);
Request.Set_Parameter ("text", "# Main title" & ASCII.LF
& "* The wiki page content." & ASCII.LF
& "* Second item." & ASCII.LF
& ASCII.LF
& "");
Request.Set_Parameter ("name", Name);
Request.Set_Parameter ("comment", "Created wiki page " & Name);
Request.Set_Parameter ("save", "1");
Request.Set_Parameter ("page-is-public", "1");
Request.Set_Parameter ("wiki-format", "FORMAT_MARKDOWN");
ASF.Tests.Set_CSRF (Request, "post", "create-wiki-get.html");
ASF.Tests.Do_Post (Request, Reply, "/wikis/create.html", "create-wiki.html");
T.Page_Ident := Helpers.Extract_Redirect (Reply, "/asfunit/wikis/view/"
& To_String (T.Wiki_Ident) & "/");
Util.Tests.Assert_Equals (T, Name, To_String (T.Page_Ident),
"Invalid redirect after wiki page creation");
-- Remove the 'wikiPage' bean from the request so that we get a new instance
-- for the next call.
Request.Remove_Attribute ("wikiPage");
end Create_Page;
-- ------------------------------
-- Test creation of blog by simulating web requests.
-- ------------------------------
procedure Test_Create_Wiki (T : in out Test) is
Request : Servlet.Requests.Mockup.Request;
Reply : Servlet.Responses.Mockup.Response;
begin
AWA.Tests.Helpers.Users.Login ("[email protected]", Request);
ASF.Tests.Do_Get (Request, Reply, "/wikis/setup.html", "setup-wiki-get.html");
Request.Set_Parameter ("title", "The Wiki Space Title");
Request.Set_Parameter ("create", "1");
ASF.Tests.Set_CSRF (Request, "post", "setup-wiki-get.html");
ASF.Tests.Do_Post (Request, Reply, "/wikis/setup.html", "setup-wiki.html");
T.Assert (Reply.Get_Status = Servlet.Responses.SC_MOVED_TEMPORARILY,
"Invalid response after wiki space creation");
declare
Ident : constant String
:= Helpers.Extract_Redirect (Reply, "/asfunit/wikis/list/");
Pos : constant Natural
:= Util.Strings.Index (Ident, '/');
begin
Util.Tests.Assert_Matches (T, "^[0-9]+/recent/grid$", Ident,
"Invalid wiki space identifier in the response");
T.Wiki_Ident := To_Unbounded_String (Ident (Ident'First .. Pos - 1));
end;
T.Create_Page (Request, Reply, "WikiPageTestName", "Wiki page title1");
T.Verify_List_Contains (To_String (T.Page_Ident));
T.Create_Page (Request, Reply, "WikiSecondPageName", "Wiki page title2");
T.Verify_List_Contains (To_String (T.Page_Ident));
T.Create_Page (Request, Reply, "WikiThirdPageName", "Wiki page title3");
T.Verify_Anonymous ("WikiPageTestName", "Wiki page title1");
T.Verify_Anonymous ("WikiSecondPageName", "Wiki page title2");
T.Verify_Anonymous ("WikiThirdPageName", "Wiki page title3");
end Test_Create_Wiki;
-- ------------------------------
-- Test getting a wiki page which does not exist.
-- ------------------------------
procedure Test_Missing_Page (T : in out Test) is
Wiki : constant String := To_String (T.Wiki_Ident);
Request : Servlet.Requests.Mockup.Request;
Reply : Servlet.Responses.Mockup.Response;
begin
ASF.Tests.Do_Get (Request, Reply, "/wikis/view/" & Wiki & "/MissingPage",
"wiki-page-missing.html");
ASF.Tests.Assert_Matches (T, ".title.Wiki page does not exist./title.", Reply,
"Wiki page 'MissingPage' is invalid",
Servlet.Responses.SC_NOT_FOUND);
ASF.Tests.Assert_Matches (T, ".h2.MissingPage./h2.", Reply,
"Wiki page 'MissingPage' header is invalid",
Servlet.Responses.SC_NOT_FOUND);
end Test_Missing_Page;
-- ------------------------------
-- Test creation of wiki page with an image.
-- ------------------------------
procedure Test_Page_With_Image (T : in out Test) is
Request : Servlet.Requests.Mockup.Request;
Reply : Servlet.Responses.Mockup.Response;
Wiki : constant String := To_String (T.Wiki_Ident);
begin
AWA.Tests.Helpers.Users.Login ("[email protected]", Request);
T.Make_Wiki_Image;
T.Create_Page (Request, Reply, "WikiImageTest", "Wiki image title3");
ASF.Tests.Do_Get (Request, Reply, "/wikis/view/" & Wiki & "/WikiImageTest",
"wiki-image-test.html");
ASF.Tests.Assert_Matches (T, "<img src=./asfunit/wikis/images/[0-9]*/[0-9]*"
& "/default/Ada-Lovelace.jpg.* alt=.Ada Lovelace.></img>",
Reply,
"Wiki page missing image link",
Servlet.Responses.SC_OK);
ASF.Tests.Do_Get (Request, Reply,
To_String (T.Image_Link),
"wiki-image-get-Ada-Lovelace.jpg");
ASF.Tests.Assert_Header (T, "Content-Type", "image/jpg", Reply);
Util.Tests.Assert_Equals (T, Servlet.Responses.SC_OK,
Reply.Get_Status,
"Invalid response for image");
ASF.Tests.Do_Get (Request, Reply, "/wikis/image-info/" & Wiki & "/"
& To_String (T.Image_Ident) & "/Images/Ada-Lovelace.jpg",
"wiki-image-info.html");
ASF.Tests.Assert_Contains (T, "<title>Image information</title>", Reply,
"Wiki image information page is invalid");
ASF.Tests.Assert_Matches (T, "<dt>File name</dt>",
Reply,
"Wiki image information invalid name (1)",
Servlet.Responses.SC_OK);
ASF.Tests.Assert_Matches (T, "<dd>Images/Ada-Lovelace.jpg</dd>",
Reply,
"Wiki image information invalid name (2)",
Servlet.Responses.SC_OK);
end Test_Page_With_Image;
end AWA.Wikis.Tests;
|
reznikmm/matreshka | Ada | 5,190 | ads | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- XML Processor --
-- --
-- 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 League.Strings;
with Matreshka.DOM_Character_Datas;
with Matreshka.DOM_Nodes;
with XML.DOM.Texts;
with XML.DOM.Visitors;
package Matreshka.DOM_Texts is
pragma Preelaborate;
type Text_Node is new Matreshka.DOM_Character_Datas.Character_Data_Node
and XML.DOM.Texts.DOM_Text with null record;
overriding procedure Enter_Node
(Self : not null access Text_Node;
Visitor : in out XML.DOM.Visitors.Abstract_Visitor'Class;
Control : in out XML.DOM.Visitors.Traverse_Control);
-- Dispatch call to corresponding subprogram of visitor interface.
overriding function Get_Node_Name
(Self : not null access constant Text_Node)
return League.Strings.Universal_String;
overriding function Get_Node_Type
(Self : not null access constant Text_Node)
return XML.DOM.Node_Type;
overriding function Get_Whole_Text
(Self : not null access constant Text_Node)
return League.Strings.Universal_String;
overriding procedure Leave_Node
(Self : not null access Text_Node;
Visitor : in out XML.DOM.Visitors.Abstract_Visitor'Class;
Control : in out XML.DOM.Visitors.Traverse_Control);
-- Dispatch call to corresponding subprogram of visitor interface.
overriding procedure Visit_Node
(Self : not null access Text_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);
-- Dispatch call to corresponding subprogram of iterator interface.
package Constructors is
procedure Initialize
(Self : not null access Text_Node'Class;
Document : not null Matreshka.DOM_Nodes.Document_Access;
Data : League.Strings.Universal_String);
end Constructors;
end Matreshka.DOM_Texts;
|
AdaCore/Ada_Drivers_Library | Ada | 8,438 | adb | ------------------------------------------------------------------------------
-- --
-- Copyright (C) 2021, 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 Ada.Unchecked_Conversion;
with Interfaces;
package body LPS25H.I2C is
use HAL;
-- Utility specs --
generic
Register : HAL.UInt8;
type Register_Type is private;
procedure Write_Register (This : LPS25H_Barometric_Sensor_I2C;
Value : Register_Type;
Status : out Boolean);
procedure Write
(This : LPS25H_Barometric_Sensor_I2C;
Index : HAL.UInt8;
Data : HAL.UInt8;
Status : out Boolean);
procedure Read
(This : LPS25H_Barometric_Sensor_I2C;
Index : HAL.UInt8;
Data : out HAL.UInt8_Array;
Status : out Boolean);
procedure Read
(This : LPS25H_Barometric_Sensor_I2C;
Index : HAL.UInt8;
Data : out HAL.UInt8;
Status : out Boolean);
--------------
-- Get_Data --
--------------
overriding
procedure Get_Data
(This : in out LPS25H_Barometric_Sensor_I2C;
Press : out Pressure;
Temp : out Temperature;
Asl : out Altitude;
Status : out Boolean)
is
Buf : HAL.UInt8_Array (0 .. 2) := (others => 0);
begin
-- Pressure
declare
type Integer_24 is range -(2 ** 23) .. 2 ** 23 - 1
with Size => 24;
subtype Buffer_3 is HAL.UInt8_Array (Buf'Range);
function Convert is new Ada.Unchecked_Conversion
(Buffer_3, Integer_24);
begin
This.Read (PRESS_OUT_XL or 2#1000_0000#,
Buf,
Status);
if not Status then
return;
end if;
Press := Float (Convert (Buf)) / 4096.0;
end;
-- Temperature
declare
subtype Buffer_2 is HAL.UInt8_Array (0 .. 1);
function Convert is new Ada.Unchecked_Conversion
(Buffer_2, Interfaces.Integer_16);
begin
This.Read (TEMP_OUT_L or 2#1000_0000#,
Buf (0 .. 1),
Status);
if not Status then
return;
end if;
Temp := 42.5 + Float (Convert (Buf (0 .. 1))) / 480.0;
end;
-- See Wikipedia, "Barometric formula": The pressure drops
-- approximately by 11.3 pascals per meter in first 1000 meters
-- above sea level.
-- See Wikipedia, "Atmospheric pressure": the standard atmosphere is
-- 1013.25 mbar.
-- 1 Pascal = 0.01 mbar
Asl := (1013.25 - Press) * (100.0 / 11.3);
end Get_Data;
----------------
-- Initialize --
----------------
overriding
procedure Initialize (This : in out LPS25H_Barometric_Sensor_I2C)
is
Data : UInt8;
Status : Boolean;
begin
This.Timing.Delay_Milliseconds (5); -- ?
This.I2C_Address := 2 * (16#5C# + (if This.Slave_Address_Odd
then 1
else 0));
This.Read (WHO_AM_I, Data, Status);
if not Status then
return;
end if;
if Data /= WAI_ID then
return;
end if;
declare
procedure Write_Ctrl_Reg1 is new Write_Register
(CTRL_REG1, Ctrl_Reg1_Register);
begin
Write_Ctrl_Reg1 (This,
(PD => 1, ODR => Hz_25, BDU => 1, others => <>),
Status);
if not Status then
return;
end if;
end;
This.Initialized := True;
end Initialize;
-- Utilities --
--------------------
-- Write_Register --
--------------------
procedure Write_Register (This : LPS25H_Barometric_Sensor_I2C;
Value : Register_Type;
Status : out Boolean) is
pragma Assert (Register_Type'Size = 8);
function Convert is new Ada.Unchecked_Conversion
(Register_Type, HAL.UInt8);
begin
Write (This,
Index => Register,
Data => Convert (Value),
Status => Status);
end Write_Register;
-----------
-- Write --
-----------
procedure Write
(This : LPS25H_Barometric_Sensor_I2C;
Index : HAL.UInt8;
Data : HAL.UInt8;
Status : out Boolean)
is
Outcome : HAL.I2C.I2C_Status;
use all type HAL.I2C.I2C_Status;
Buf : constant HAL.UInt8_Array := (1 => Index) & Data;
begin
This.Port.Mem_Write (Addr => This.I2C_Address,
Mem_Addr => HAL.UInt16 (Index),
Mem_Addr_Size => HAL.I2C.Memory_Size_8b,
Data => Buf,
Status => Outcome);
Status := Outcome = Ok;
end Write;
----------
-- Read --
----------
procedure Read
(This : LPS25H_Barometric_Sensor_I2C;
Index : HAL.UInt8;
Data : out HAL.UInt8_Array;
Status : out Boolean)
is
Outcome : HAL.I2C.I2C_Status;
use all type HAL.I2C.I2C_Status;
begin
This.Port.Mem_Read (Addr => This.I2C_Address,
Mem_Addr => UInt16 (Index),
Mem_Addr_Size => HAL.I2C.Memory_Size_8b,
Data => Data,
Status => Outcome);
Status := Outcome = Ok;
end Read;
----------
-- Read --
----------
procedure Read
(This : LPS25H_Barometric_Sensor_I2C;
Index : HAL.UInt8;
Data : out HAL.UInt8;
Status : out Boolean)
is
Outcome : HAL.I2C.I2C_Status;
use all type HAL.I2C.I2C_Status;
Buf : UInt8_Array (1 .. 1);
begin
This.Port.Mem_Read (Addr => This.I2C_Address,
Mem_Addr => UInt16 (Index),
Mem_Addr_Size => HAL.I2C.Memory_Size_8b,
Data => Buf,
Status => Outcome);
Status := Outcome = Ok;
if Status then
Data := Buf (1);
end if;
end Read;
end LPS25H.I2C;
|
zhmu/ananas | Ada | 2,573 | ads | ------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- G N A T . S O C K E T S . P O L L --
-- --
-- S p e c --
-- --
-- Copyright (C) 2020-2022, AdaCore --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. --
-- --
-- As a special exception under Section 7 of GPL version 3, you are granted --
-- additional permissions described in the GCC Runtime Library Exception, --
-- version 3.1, as published by the Free Software Foundation. --
-- --
-- You should have received a copy of the GNU General Public License and --
-- a copy of the GCC Runtime Library Exception along with this program; --
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
-- <http://www.gnu.org/licenses/>. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
-- This package is a placeholder for the sockets binding for platforms where
-- it is not implemented.
package GNAT.Sockets.Thin_Common is
pragma Unimplemented_Unit;
end GNAT.Sockets.Thin_Common;
|
stcarrez/swagger-ada | Ada | 174 | adb | with Servlet.Server.Web;
with TestAPI.Server;
procedure TestAPI_AWS is
Container : Servlet.Server.Web.AWS_Container;
begin
TestAPI.Server (Container);
end TestAPI_AWS;
|
damaki/libkeccak | Ada | 3,051 | ads | -------------------------------------------------------------------------------
-- Copyright (c) 2019, Daniel King
-- 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.
-- * The name of the copyright holder may not 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 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 Keccak.Generic_Duplex;
with Keccak.Generic_Sponge;
pragma Elaborate_All (Keccak.Generic_Duplex);
pragma Elaborate_All (Keccak.Generic_Sponge);
-- @summary
-- Instantiation of Keccak-p[800,12], with a Sponge and Duplex built on top of it.
package Keccak.Keccak_800.Rounds_12
with SPARK_Mode => On
is
procedure Permute is new KeccakF_800_Permutation.Permute
(Num_Rounds => 12);
package Sponge is new Keccak.Generic_Sponge
(State_Size_Bits => KeccakF_800.State_Size_Bits,
State_Type => State,
Init_State => KeccakF_800.Init,
Permute => Permute,
XOR_Bits_Into_State => KeccakF_800_Lanes.XOR_Bits_Into_State,
Extract_Data => KeccakF_800_Lanes.Extract_Bytes,
Pad => Keccak.Padding.Pad101_Multi_Blocks);
package Duplex is new Keccak.Generic_Duplex
(State_Size_Bits => KeccakF_800.State_Size_Bits,
State_Type => State,
Init_State => KeccakF_800.Init,
Permute => Permute,
XOR_Bits_Into_State => KeccakF_800_Lanes.XOR_Bits_Into_State,
Extract_Bits => KeccakF_800_Lanes.Extract_Bits,
Pad => Keccak.Padding.Pad101_Single_Block,
Min_Padding_Bits => Keccak.Padding.Pad101_Min_Bits);
end Keccak.Keccak_800.Rounds_12;
|
sungyeon/drake | Ada | 9,866 | ads | pragma License (Unrestricted);
private with System.UTF_Conversions.From_8_To_16;
private with System.UTF_Conversions.From_8_To_32;
private with System.UTF_Conversions.From_16_To_32;
private with System.UTF_Conversions.From_16_To_8;
private with System.UTF_Conversions.From_32_To_8;
private with System.UTF_Conversions.From_32_To_16;
package Ada.Characters.Conversions is
pragma Pure;
-- extended
-- Use Is_Wide_String instead of Is_Wide_Character for multi-byte sequence.
-- Is_Wide_String checks if all code-points of Item can be converted to
-- UTF-16 Wide_String (each code-point is in BMP or surrogate pair).
-- These functions Is_XXX_String assume Item contains a legal sequence.
function Is_Wide_Character (Item : Character) return Boolean;
function Is_Wide_String (Item : String) return Boolean;
-- extended
-- Use Is_Wide_Wide_String instead of Is_Wide_Wide_Character for multi-byte
-- sequence.
-- UTF-8 String can always be converted to UTF-32 Wide_Wide_String.
function Is_Wide_Wide_Character (Item : Character) return Boolean
renames Is_Wide_Character;
-- function Is_Wide_Wide_String (Item : String) return Boolean; -- True
-- Do not use Is_Character for Item that is greater than 16#7F#.
-- UTF-16 Wide_String can always be converted to UTF-8 String.
function Is_Character (Item : Wide_Character) return Boolean;
function Is_String (Item : Wide_String) return Boolean; -- True
-- extended
-- Do not use Is_Wide_Wide_Character for surrogate pair.
-- UTF-16 Wide_String can always be converted to UTF-32 Wide_Wide_String.
function Is_Wide_Wide_Character (Item : Wide_Character) return Boolean;
-- function Is_Wide_Wide_String (Item : Wide_String) return Boolean; -- True
-- Do not use Is_Character for Item that is greater than 16#7F#.
-- UTF-32 Wide_Wide_String can always be converted to UTF-8 String.
function Is_Character (Item : Wide_Wide_Character) return Boolean;
function Is_String (Item : Wide_Wide_String) return Boolean; -- True
-- Use Is_Wide_String instead of Is_Wide_Character for Item that is greater
-- than 16#FFFF#.
function Is_Wide_Character (Item : Wide_Wide_Character) return Boolean;
function Is_Wide_String (Item : Wide_Wide_String) return Boolean;
pragma Inline (Is_Character);
pragma Inline (Is_Wide_Character);
pragma Inline (Is_Wide_Wide_Character);
pragma Inline (Is_String);
-- modified
-- These functions use Substitute if Item contains illegal byte sequence.
function To_Wide_Character (
Item : Character;
Substitute : Wide_Character := ' ') -- additional
return Wide_Character;
function To_Wide_String (
Item : String;
Substitute : Wide_String := " ") -- additional
return Wide_String;
-- modified
function To_Wide_Wide_Character (
Item : Character;
Substitute : Wide_Wide_Character := ' ') -- additional
return Wide_Wide_Character;
function To_Wide_Wide_String (
Item : String;
Substitute : Wide_Wide_String := " ") -- additional
return Wide_Wide_String;
-- modified
function To_Wide_Wide_Character (
Item : Wide_Character;
Substitute : Wide_Wide_Character := ' ') -- additional
return Wide_Wide_Character;
function To_Wide_Wide_String (
Item : Wide_String;
Substitute : Wide_Wide_String := " ") -- additional
return Wide_Wide_String;
function To_Character (
Item : Wide_Character;
Substitute : Character := ' ')
return Character;
function To_String (
Item : Wide_String;
Substitute : Character := ' ')
return String;
-- extended
function To_String (
Item : Wide_String;
Substitute : String)
return String;
function To_Character (
Item : Wide_Wide_Character;
Substitute : Character := ' ')
return Character;
function To_String (
Item : Wide_Wide_String;
Substitute : Character := ' ')
return String;
-- extended
function To_String (
Item : Wide_Wide_String;
Substitute : String)
return String;
function To_Wide_Character (
Item : Wide_Wide_Character;
Substitute : Wide_Character := ' ')
return Wide_Character;
function To_Wide_String (
Item : Wide_Wide_String;
Substitute : Wide_Character := ' ')
return Wide_String;
-- extended
function To_Wide_String (
Item : Wide_Wide_String;
Substitute : Wide_String)
return Wide_String;
pragma Inline (To_String); -- renamed, or normal inline
pragma Inline (To_Wide_String); -- renamed, or normal inline
pragma Inline (To_Wide_Wide_String); -- renamed, or normal inline
-- extended
-- There are subprograms for code-point based decoding iteration.
procedure Get (
Item : String;
Last : out Natural;
Value : out Wide_Wide_Character;
Substitute : Wide_Wide_Character := ' ');
procedure Get (
Item : String;
Last : out Natural;
Value : out Wide_Wide_Character;
Is_Illegal_Sequence : out Boolean);
procedure Get_Reverse (
Item : String;
First : out Positive;
Value : out Wide_Wide_Character;
Substitute : Wide_Wide_Character := ' ');
procedure Get_Reverse (
Item : String;
First : out Positive;
Value : out Wide_Wide_Character;
Is_Illegal_Sequence : out Boolean);
procedure Get (
Item : Wide_String;
Last : out Natural;
Value : out Wide_Wide_Character;
Substitute : Wide_Wide_Character := ' ');
procedure Get (
Item : Wide_String;
Last : out Natural;
Value : out Wide_Wide_Character;
Is_Illegal_Sequence : out Boolean);
procedure Get_Reverse (
Item : Wide_String;
First : out Positive;
Value : out Wide_Wide_Character;
Substitute : Wide_Wide_Character := ' ');
procedure Get_Reverse (
Item : Wide_String;
First : out Positive;
Value : out Wide_Wide_Character;
Is_Illegal_Sequence : out Boolean);
procedure Get (
Item : Wide_Wide_String;
Last : out Natural;
Value : out Wide_Wide_Character;
Substitute : Wide_Wide_Character := ' ');
procedure Get (
Item : Wide_Wide_String;
Last : out Natural;
Value : out Wide_Wide_Character;
Is_Illegal_Sequence : out Boolean);
procedure Get_Reverse (
Item : Wide_Wide_String;
First : out Positive;
Value : out Wide_Wide_Character;
Substitute : Wide_Wide_Character := ' ');
procedure Get_Reverse (
Item : Wide_Wide_String;
First : out Positive;
Value : out Wide_Wide_Character;
Is_Illegal_Sequence : out Boolean);
-- extended
-- Encoding subprograms:
procedure Put (
Value : Wide_Wide_Character;
Item : out String;
Last : out Natural);
procedure Put (
Value : Wide_Wide_Character;
Item : out Wide_String;
Last : out Natural);
procedure Put (
Value : Wide_Wide_Character;
Item : out Wide_Wide_String;
Last : out Natural);
-- extended
-- Max lengths of each one multi-byte character,
-- and the rates of expansion:
Max_Length_In_String : constant := 6;
Max_Length_In_Wide_String : constant := 2;
Max_Length_In_Wide_Wide_String : constant := 1;
Expanding_From_String_To_Wide_String : constant := 1;
Expanding_From_String_To_Wide_Wide_String : constant := 1;
Expanding_From_Wide_String_To_String : constant := 3;
Expanding_From_Wide_String_To_Wide_Wide_String : constant := 1;
Expanding_From_Wide_Wide_String_To_String : constant := 6;
Expanding_From_Wide_Wide_String_To_Wide_String : constant := 2;
Expanding_From_String_To_UTF_8 : constant := 1;
Expanding_From_String_To_UTF_16 : constant := 1;
Expanding_From_String_To_UTF_32 : constant := 1;
Expanding_From_Wide_String_To_UTF_8 : constant := 3;
Expanding_From_Wide_String_To_UTF_16 : constant := 1;
Expanding_From_Wide_String_To_UTF_32 : constant := 1;
Expanding_From_Wide_Wide_String_To_UTF_8 : constant := 6;
Expanding_From_Wide_Wide_String_To_UTF_16 : constant := 2;
Expanding_From_Wide_Wide_String_To_UTF_32 : constant := 1;
Expanding_From_UTF_8_To_String : constant := 1;
Expanding_From_UTF_8_To_Wide_String : constant := 1;
Expanding_From_UTF_8_To_Wide_Wide_String : constant := 1;
Expanding_From_UTF_16_To_String : constant := 3;
Expanding_From_UTF_16_To_Wide_String : constant := 1;
Expanding_From_UTF_16_To_Wide_Wide_String : constant := 1;
Expanding_From_UTF_32_To_String : constant := 6;
Expanding_From_UTF_32_To_Wide_String : constant := 2;
Expanding_From_UTF_32_To_Wide_Wide_String : constant := 1;
private
function To_Wide_String (
Item : String;
Substitute : Wide_String := " ")
return Wide_String
renames System.UTF_Conversions.From_8_To_16.Convert;
function To_Wide_Wide_String (
Item : String;
Substitute : Wide_Wide_String := " ")
return Wide_Wide_String
renames System.UTF_Conversions.From_8_To_32.Convert;
function To_Wide_Wide_String (
Item : Wide_String;
Substitute : Wide_Wide_String := " ")
return Wide_Wide_String
renames System.UTF_Conversions.From_16_To_32.Convert;
function To_String (
Item : Wide_String;
Substitute : String)
return String
renames System.UTF_Conversions.From_16_To_8.Convert;
function To_String (
Item : Wide_Wide_String;
Substitute : String)
return String
renames System.UTF_Conversions.From_32_To_8.Convert;
function To_Wide_String (
Item : Wide_Wide_String;
Substitute : Wide_String)
return Wide_String
renames System.UTF_Conversions.From_32_To_16.Convert;
end Ada.Characters.Conversions;
|
rveenker/sdlada | Ada | 1,605 | adb | with SDL;
with SDL.CPUS;
with SDL.Error;
with SDL.Log;
with SDL.Platform;
with System;
use type System.Bit_Order;
procedure Platform is
Endian : System.Bit_Order renames System.Default_Bit_Order;
begin
SDL.Log.Set (Category => SDL.Log.Application, Priority => SDL.Log.Debug);
SDL.Log.Put_Debug ("This system is running : " & SDL.Platform.Platforms'Image (SDL.Platform.Get));
-- Endian-ness.
SDL.Log.Put_Debug ("Bit Order : " & System.Bit_Order'Image (Endian));
SDL.Log.Put_Debug ("...in other words : " &
(if Endian = System.High_Order_First then "Big-endian" else "Little-endian"));
-- CPU Info.
SDL.Log.Put_Debug ("CPU count : " & Positive'Image (SDL.CPUS.Count));
SDL.Log.Put_Debug ("CPU cache line size : " & Positive'Image (SDL.CPUS.Cache_Line_Size));
SDL.Log.Put_Debug ("RDTSC : " & Boolean'Image (SDL.CPUS.Has_RDTSC));
SDL.Log.Put_Debug ("AltiVec : " & Boolean'Image (SDL.CPUS.Has_AltiVec));
SDL.Log.Put_Debug ("3DNow! : " & Boolean'Image (SDL.CPUS.Has_3DNow));
SDL.Log.Put_Debug ("SSE : " & Boolean'Image (SDL.CPUS.Has_SSE));
SDL.Log.Put_Debug ("SSE2 : " & Boolean'Image (SDL.CPUS.Has_SSE_2));
SDL.Log.Put_Debug ("SSE3 : " & Boolean'Image (SDL.CPUS.Has_SSE_3));
SDL.Log.Put_Debug ("SSE4.1 : " & Boolean'Image (SDL.CPUS.Has_SSE_4_1));
SDL.Log.Put_Debug ("SSE4.2 : " & Boolean'Image (SDL.CPUS.Has_SSE_4_2));
SDL.Finalise;
end Platform;
|
AdaCore/Ada_Drivers_Library | Ada | 5,296 | adb | ------------------------------------------------------------------------------
-- --
-- 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 Ada.Real_Time; use Ada.Real_Time;
with STM32.Board; use STM32.Board;
with STM32.Device; use STM32.Device;
with STM32.GPIO; use STM32.GPIO;
with STM32.EXTI; use STM32.EXTI;
package body STM32.User_Button is
Button_High : Boolean := True;
Debounce_Time : constant Time_Span := Milliseconds (250);
EXTI_Line : constant External_Line_Number := User_Button_Point.Interrupt_Line_Number;
Initialization_Complete : Boolean := False;
------------
-- Button --
------------
protected Button is
pragma Interrupt_Priority;
function Current_State return Boolean;
procedure Clear_State;
private
procedure Interrupt;
pragma Attach_Handler (Interrupt, User_Button_Interrupt);
Pressed : Boolean := False;
Start_Time : Time := Clock;
end Button;
------------
-- Button --
------------
protected body Button is
---------------
-- Interrupt --
---------------
procedure Interrupt is
begin
Clear_External_Interrupt (EXTI_Line);
if (Button_High and then User_Button_Point.Set)
or else (not Button_High and then not User_Button_Point.Set)
then
if Clock - Start_Time > Debounce_Time then
Pressed := True;
end if;
end if;
end Interrupt;
-------------------
-- Current_State --
-------------------
function Current_State return Boolean is
begin
return Pressed;
end Current_State;
-----------------
-- Clear_State --
-----------------
procedure Clear_State is
begin
if Pressed then
Start_Time := Clock;
Pressed := False;
end if;
end Clear_State;
end Button;
----------------
-- Initialize --
----------------
procedure Initialize (Use_Rising_Edge : Boolean := True) is
Edge : constant EXTI.External_Triggers :=
(if Use_Rising_Edge then Interrupt_Rising_Edge
else Interrupt_Falling_Edge);
begin
Enable_Clock (User_Button_Point);
User_Button_Point.Configure_IO
((Mode => Mode_In,
Resistors => (if Use_Rising_Edge then Pull_Down else Pull_Up)));
-- Connect the button's pin to the External Interrupt Handler
User_Button_Point.Configure_Trigger (Edge);
Button_High := Use_Rising_Edge;
Initialization_Complete := True;
end Initialize;
----------------------
-- Has_Been_Pressed --
----------------------
function Has_Been_Pressed return Boolean is
State : Boolean;
begin
State := Button.Current_State;
Button.Clear_State;
return State;
end Has_Been_Pressed;
-----------------
-- Initialized --
-----------------
function Initialized return Boolean is (Initialization_Complete);
end STM32.User_Button;
|
zhmu/ananas | Ada | 125 | ads | package Taft_Type3_Pkg is
type T is private;
private
type Buffer_T;
type T is access Buffer_T;
end Taft_Type3_Pkg;
|
DrenfongWong/tkm-rpc | Ada | 421 | ads | with Ada.Unchecked_Conversion;
package Tkmrpc.Request.Ike.Isa_Create_Child.Convert is
function To_Request is new Ada.Unchecked_Conversion (
Source => Isa_Create_Child.Request_Type,
Target => Request.Data_Type);
function From_Request is new Ada.Unchecked_Conversion (
Source => Request.Data_Type,
Target => Isa_Create_Child.Request_Type);
end Tkmrpc.Request.Ike.Isa_Create_Child.Convert;
|
onox/orka | Ada | 1,115 | 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 AUnit.Test_Fixtures;
with Orka.Numerics.Singles.Tensors.CPU;
with Generic_Test_Tensors_Matrices;
use all type Orka.Numerics.Singles.Tensors.CPU.CPU_QR_Factorization;
package Test_Tensors_CPU_Singles_Matrices is new Generic_Test_Tensors_Matrices
("CPU - Singles",
AUnit.Test_Fixtures.Test_Fixture,
Orka.Numerics.Singles.Tensors,
Orka.Numerics.Singles.Tensors.CPU.CPU_Tensor,
Orka.Numerics.Singles.Tensors.CPU.CPU_QR_Factorization);
|
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_Horizontal_Pos_Attributes is
pragma Preelaborate;
type ODF_Style_Horizontal_Pos_Attribute is limited interface
and XML.DOM.Attributes.DOM_Attribute;
type ODF_Style_Horizontal_Pos_Attribute_Access is
access all ODF_Style_Horizontal_Pos_Attribute'Class
with Storage_Size => 0;
end ODF.DOM.Style_Horizontal_Pos_Attributes;
|
persan/A-gst | Ada | 20,501 | ads | pragma Ada_2005;
pragma Style_Checks (Off);
pragma Warnings (Off);
with Interfaces.C; use Interfaces.C;
with glib;
with glib.Values;
with System;
-- with GStreamer.GST_Low_Level.glib_2_0_glib_gquark_h;
with GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstobject_h;
with System;
-- with GStreamer.GST_Low_Level.sys_types_h;
-- with GStreamer.GST_Low_Level.bits_types_time_t_h;
with glib;
limited with GStreamer.GST_Low_Level.gstreamer_0_10_gst_gststructure_h;
-- limited with GStreamer.GST_Low_Level.glib_2_0_glib_glist_h;
package GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstplugin_h is
-- unsupported macro: GST_PLUGIN_ERROR gst_plugin_error_quark ()
-- unsupported macro: GST_TYPE_PLUGIN (gst_plugin_get_type())
-- arg-macro: function GST_IS_PLUGIN (obj)
-- return G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_PLUGIN);
-- arg-macro: function GST_IS_PLUGIN_CLASS (klass)
-- return G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_PLUGIN);
-- arg-macro: function GST_PLUGIN_GET_CLASS (obj)
-- return G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_PLUGIN, GstPluginClass);
-- arg-macro: function GST_PLUGIN (obj)
-- return G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_PLUGIN, GstPlugin);
-- arg-macro: function GST_PLUGIN_CLASS (klass)
-- return G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_PLUGIN, GstPluginClass);
-- arg-macro: function GST_PLUGIN_CAST (obj)
-- return (GstPlugin*)(obj);
-- arg-macro: procedure GST_PLUGIN_DEFINE (major, minor, name, description, init, version, license, package, origin)
-- G_BEGIN_DECLS GST_PLUGIN_EXPORT GstPluginDesc gst_plugin_desc := { major, minor, name, (gchar *) description, init, version, license, PACKAGE, package, origin, __GST_PACKAGE_RELEASE_DATETIME, GST_PADDING_INIT }; G_END_DECLS
-- unsupported macro: GST_PLUGIN_DEFINE_STATIC(major,minor,name,description,init,version,license,package,origin) static void GST_GNUC_CONSTRUCTOR _gst_plugin_static_init__ ##init (void) { static GstPluginDesc plugin_desc_ = { major, minor, name, (gchar *) description, init, version, license, PACKAGE, package, origin, NULL, GST_PADDING_INIT }; _gst_plugin_register_static (&plugin_desc_); }
GST_LICENSE_UNKNOWN : aliased constant String := "unknown" & ASCII.NUL; -- gst/gstplugin.h:328
-- GStreamer
-- * Copyright (C) 1999,2000 Erik Walthinsen <[email protected]>
-- * 2000 Wim Taymans <[email protected]>
-- *
-- * gstplugin.h: Header for plugin subsystem
-- *
-- * This library is free software; you can redistribute it and/or
-- * modify it under the terms of the GNU Library General Public
-- * License as published by the Free Software Foundation; either
-- * version 2 of the License, or (at your option) any later version.
-- *
-- * This library is distributed in the hope that it will be useful,
-- * but WITHOUT ANY WARRANTY; without even the implied warranty of
-- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-- * Library General Public License for more details.
-- *
-- * You should have received a copy of the GNU Library General Public
-- * License along with this library; if not, write to the
-- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-- * Boston, MA 02111-1307, USA.
--
-- time_t
-- off_t
-- off_t
type GstPlugin;
type u_GstPlugin_u_gst_reserved_array is array (0 .. 2) of System.Address;
--subtype GstPlugin is u_GstPlugin; -- gst/gstplugin.h:39
type GstPluginClass;
type u_GstPluginClass_u_gst_reserved_array is array (0 .. 3) of System.Address;
--subtype GstPluginClass is u_GstPluginClass; -- gst/gstplugin.h:40
-- skipped empty struct u_GstPluginPrivate
-- skipped empty struct GstPluginPrivate
type GstPluginDesc;
type u_GstPluginDesc_u_gst_reserved_array is array (0 .. 2) of System.Address;
--subtype GstPluginDesc is u_GstPluginDesc; -- gst/gstplugin.h:42
--*
-- * gst_plugin_error_quark:
-- *
-- * Get the error quark.
-- *
-- * Returns: The error quark used in GError messages
--
function gst_plugin_error_quark return Glib.GQuark; -- gst/gstplugin.h:51
pragma Import (C, gst_plugin_error_quark, "gst_plugin_error_quark");
--*
-- * GST_PLUGIN_ERROR:
-- *
-- * The error message category quark
--
--*
-- * GstPluginError:
-- * @GST_PLUGIN_ERROR_MODULE: The plugin could not be loaded
-- * @GST_PLUGIN_ERROR_DEPENDENCIES: The plugin has unresolved dependencies
-- * @GST_PLUGIN_ERROR_NAME_MISMATCH: The plugin has already be loaded from a different file
-- *
-- * The plugin loading errors
--
type GstPluginError is
(GST_PLUGIN_ERROR_MODULE,
GST_PLUGIN_ERROR_DEPENDENCIES,
GST_PLUGIN_ERROR_NAME_MISMATCH);
pragma Convention (C, GstPluginError); -- gst/gstplugin.h:72
--*
-- * GstPluginFlags:
-- * @GST_PLUGIN_FLAG_CACHED: Temporarily loaded plugins
-- * @GST_PLUGIN_FLAG_BLACKLISTED: The plugin won't be scanned (again)
-- *
-- * The plugin loading state
--
subtype GstPluginFlags is unsigned;
GST_PLUGIN_FLAG_CACHED : constant GstPluginFlags := 1;
GST_PLUGIN_FLAG_BLACKLISTED : constant GstPluginFlags := 2; -- gst/gstplugin.h:85
--*
-- * GstPluginDependencyFlags:
-- * @GST_PLUGIN_DEPENDENCY_FLAG_NONE : no special flags
-- * @GST_PLUGIN_DEPENDENCY_FLAG_RECURSE : recurse into subdirectories
-- * @GST_PLUGIN_DEPENDENCY_FLAG_PATHS_ARE_DEFAULT_ONLY : use paths
-- * argument only if none of the environment variables is set
-- * @GST_PLUGIN_DEPENDENCY_FLAG_FILE_NAME_IS_SUFFIX : interpret
-- * filename argument as filter suffix and check all matching files in
-- * the directory
-- *
-- * Flags used in connection with gst_plugin_add_dependency().
-- *
-- * Since: 0.10.22
--
subtype GstPluginDependencyFlags is unsigned;
GST_PLUGIN_DEPENDENCY_FLAG_NONE : constant GstPluginDependencyFlags := 0;
GST_PLUGIN_DEPENDENCY_FLAG_RECURSE : constant GstPluginDependencyFlags := 1;
GST_PLUGIN_DEPENDENCY_FLAG_PATHS_ARE_DEFAULT_ONLY : constant GstPluginDependencyFlags := 2;
GST_PLUGIN_DEPENDENCY_FLAG_FILE_NAME_IS_SUFFIX : constant GstPluginDependencyFlags := 4; -- gst/gstplugin.h:106
--*
-- * GstPluginInitFunc:
-- * @plugin: The plugin object
-- *
-- * A plugin should provide a pointer to a function of this type in the
-- * plugin_desc struct.
-- * This function will be called by the loader at startup. One would then
-- * register each #GstPluginFeature.
-- *
-- * Returns: %TRUE if plugin initialised successfully
--
-- FIXME 0.11: Make return void
type GstPluginInitFunc is access function (arg1 : access GstPlugin) return GLIB.gboolean;
pragma Convention (C, GstPluginInitFunc); -- gst/gstplugin.h:120
--*
-- * GstPluginInitFullFunc:
-- * @plugin: The plugin object
-- * @user_data: extra data
-- *
-- * A plugin should provide a pointer to a function of either #GstPluginInitFunc
-- * or this type in the plugin_desc struct.
-- * The function will be called by the loader at startup. One would then
-- * register each #GstPluginFeature. This version allows
-- * user data to be passed to init function (useful for bindings).
-- *
-- * Returns: %TRUE if plugin initialised successfully
-- *
-- * Since: 0.10.24
-- *
--
-- FIXME 0.11: Merge with GstPluginInitFunc
type GstPluginInitFullFunc is access function (arg1 : access GstPlugin; arg2 : System.Address) return GLIB.gboolean;
pragma Convention (C, GstPluginInitFullFunc); -- gst/gstplugin.h:139
--*
-- * GstPluginDesc:
-- * @major_version: the major version number of core that plugin was compiled for
-- * @minor_version: the minor version number of core that plugin was compiled for
-- * @name: a unique name of the plugin
-- * @description: description of plugin
-- * @plugin_init: pointer to the init function of this plugin.
-- * @version: version of the plugin
-- * @license: effective license of plugin
-- * @source: source module plugin belongs to
-- * @package: shipped package plugin belongs to
-- * @origin: URL to provider of plugin
-- * @release_datetime: date time string in ISO 8601 format (or rather, a
-- * subset thereof), or NULL. Allowed are the following formats:
-- * "YYYY-MM-DD" and "YYY-MM-DDTHH:MMZ" (with 'T' a separator and 'Z'
-- * indicating UTC/Zulu time). This field should be set via the
-- * GST_PACKAGE_RELEASE_DATETIME preprocessor macro (Since: 0.10.31)
-- *
-- * A plugin should export a variable of this type called plugin_desc. The plugin
-- * loader will use the data provided there to initialize the plugin.
-- *
-- * The @licence parameter must be one of: LGPL, GPL, QPL, GPL/QPL, MPL,
-- * BSD, MIT/X11, Proprietary, unknown.
--
type GstPluginDesc is record
major_version : aliased GLIB.gint; -- gst/gstplugin.h:166
minor_version : aliased GLIB.gint; -- gst/gstplugin.h:167
name : access GLIB.gchar; -- gst/gstplugin.h:168
description : access GLIB.gchar; -- gst/gstplugin.h:169
plugin_init : GstPluginInitFunc; -- gst/gstplugin.h:170
version : access GLIB.gchar; -- gst/gstplugin.h:171
license : access GLIB.gchar; -- gst/gstplugin.h:172
source : access GLIB.gchar; -- gst/gstplugin.h:173
c_package : access GLIB.gchar; -- gst/gstplugin.h:174
origin : access GLIB.gchar; -- gst/gstplugin.h:175
release_datetime : access GLIB.gchar; -- gst/gstplugin.h:176
u_gst_reserved : u_GstPluginDesc_u_gst_reserved_array; -- gst/gstplugin.h:178
end record;
pragma Convention (C_Pass_By_Copy, GstPluginDesc); -- gst/gstplugin.h:165
--< private >
--*
-- * GstPlugin:
-- *
-- * The plugin object
--
type GstPlugin is record
object : aliased GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstobject_h.GstObject; -- gst/gstplugin.h:196
desc : aliased GstPluginDesc; -- gst/gstplugin.h:199
orig_desc : access GstPluginDesc; -- gst/gstplugin.h:201
flags : aliased unsigned; -- gst/gstplugin.h:203
filename : access GLIB.gchar; -- gst/gstplugin.h:205
basename : access GLIB.gchar; -- gst/gstplugin.h:206
module : System.Address; -- gst/gstplugin.h:208
file_size : aliased GStreamer.GST_Low_Level.sys_types_h.off_t; -- gst/gstplugin.h:210
file_mtime : aliased GStreamer.GST_Low_Level.bits_types_time_t_h.time_t; -- gst/gstplugin.h:211
registered : aliased GLIB.gboolean; -- gst/gstplugin.h:212
priv : System.Address; -- gst/gstplugin.h:215
u_gst_reserved : u_GstPlugin_u_gst_reserved_array; -- gst/gstplugin.h:216
end record;
pragma Convention (C_Pass_By_Copy, GstPlugin); -- gst/gstplugin.h:195
--< private >
-- base name (non-dir part) of plugin path
-- contains the module if plugin is loaded
-- TRUE when the registry has seen a filename
-- * that matches the plugin's basename
type GstPluginClass is record
object_class : aliased GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstobject_h.GstObjectClass; -- gst/gstplugin.h:220
u_gst_reserved : u_GstPluginClass_u_gst_reserved_array; -- gst/gstplugin.h:223
end record;
pragma Convention (C_Pass_By_Copy, GstPluginClass); -- gst/gstplugin.h:219
--< private >
--*
-- * GST_PLUGIN_DEFINE:
-- * @major: major version number of the gstreamer-core that plugin was compiled for
-- * @minor: minor version number of the gstreamer-core that plugin was compiled for
-- * @name: short, but unique name of the plugin
-- * @description: information about the purpose of the plugin
-- * @init: function pointer to the plugin_init method with the signature of <code>static gboolean plugin_init (GstPlugin * plugin)</code>.
-- * @version: full version string (e.g. VERSION from config.h)
-- * @license: under which licence the package has been released, e.g. GPL, LGPL.
-- * @package: the package-name (e.g. PACKAGE_NAME from config.h)
-- * @origin: a description from where the package comes from (e.g. the homepage URL)
-- *
-- * This macro needs to be used to define the entry point and meta data of a
-- * plugin. One would use this macro to export a plugin, so that it can be used
-- * by other applications.
-- *
-- * The macro uses a define named PACKAGE for the #GstPluginDesc,source field.
-- * When using autoconf, this is usually set automatically via the AC_INIT
-- * macro, and set in config.h. If you are not using autoconf, you will need to
-- * define PACKAGE yourself and set it to a short mnemonic string identifying
-- * your application/package, e.g. 'someapp' or 'my-plugins-foo.
-- *
-- * If defined, the GST_PACKAGE_RELEASE_DATETIME will also be used for the
-- * #GstPluginDesc,release_datetime field.
--
--*
-- * GST_PLUGIN_DEFINE_STATIC:
-- * @major: major version number of the gstreamer-core that plugin was compiled for
-- * @minor: minor version number of the gstreamer-core that plugin was compiled for
-- * @name: short, but unique name of the plugin
-- * @description: information about the purpose of the plugin
-- * @init: function pointer to the plugin_init method with the signature of <code>static gboolean plugin_init (GstPlugin * plugin)</code>.
-- * @version: full version string (e.g. VERSION from config.h)
-- * @license: under which licence the package has been released, e.g. GPL, LGPL.
-- * @package: the package-name (e.g. PACKAGE_NAME from config.h)
-- * @origin: a description from where the package comes from (e.g. the homepage URL)
-- *
-- * This macro needs to be used to define the entry point and meta data of a
-- * local plugin. One would use this macro to define a local plugin that can only
-- * be used by the own application.
-- *
-- * The macro uses a define named PACKAGE for the #GstPluginDesc.source field.
-- *
-- * Deprecated: Use gst_plugin_register_static() instead. This macro was
-- * deprecated because it uses constructors, which is a compiler feature not
-- * available on all compilers.
-- *
--
-- We don't have deprecation guards here on purpose, it's enough to have
-- * deprecation guards around _gst_plugin_register_static(), and will result in
-- * much better error messages when compiling with -DGST_DISABLE_DEPRECATED
--*
-- * GST_LICENSE_UNKNOWN:
-- *
-- * To be used in GST_PLUGIN_DEFINE or GST_PLUGIN_DEFINE_STATIC if usure about
-- * the licence.
--
-- function for filters
--*
-- * GstPluginFilter:
-- * @plugin: the plugin to check
-- * @user_data: the user_data that has been passed on e.g. gst_registry_plugin_filter()
-- *
-- * A function that can be used with e.g. gst_registry_plugin_filter()
-- * to get a list of plugins that match certain criteria.
-- *
-- * Returns: TRUE for a positive match, FALSE otherwise
--
type GstPluginFilter is access function (arg1 : access GstPlugin; arg2 : System.Address) return GLIB.gboolean;
pragma Convention (C, GstPluginFilter); -- gst/gstplugin.h:342
function gst_plugin_get_type return GLIB.GType; -- gst/gstplugin.h:345
pragma Import (C, gst_plugin_get_type, "gst_plugin_get_type");
-- skipped func _gst_plugin_register_static
function gst_plugin_register_static
(major_version : GLIB.gint;
minor_version : GLIB.gint;
name : access GLIB.gchar;
description : access GLIB.gchar;
init_func : GstPluginInitFunc;
version : access GLIB.gchar;
license : access GLIB.gchar;
source : access GLIB.gchar;
c_package : access GLIB.gchar;
origin : access GLIB.gchar) return GLIB.gboolean; -- gst/gstplugin.h:351
pragma Import (C, gst_plugin_register_static, "gst_plugin_register_static");
function gst_plugin_register_static_full
(major_version : GLIB.gint;
minor_version : GLIB.gint;
name : access GLIB.gchar;
description : access GLIB.gchar;
init_full_func : GstPluginInitFullFunc;
version : access GLIB.gchar;
license : access GLIB.gchar;
source : access GLIB.gchar;
c_package : access GLIB.gchar;
origin : access GLIB.gchar;
user_data : System.Address) return GLIB.gboolean; -- gst/gstplugin.h:362
pragma Import (C, gst_plugin_register_static_full, "gst_plugin_register_static_full");
function gst_plugin_get_name (plugin : access GstPlugin) return access GLIB.gchar; -- gst/gstplugin.h:374
pragma Import (C, gst_plugin_get_name, "gst_plugin_get_name");
function gst_plugin_get_description (plugin : access GstPlugin) return access GLIB.gchar; -- gst/gstplugin.h:375
pragma Import (C, gst_plugin_get_description, "gst_plugin_get_description");
function gst_plugin_get_filename (plugin : access GstPlugin) return access GLIB.gchar; -- gst/gstplugin.h:376
pragma Import (C, gst_plugin_get_filename, "gst_plugin_get_filename");
function gst_plugin_get_version (plugin : access GstPlugin) return access GLIB.gchar; -- gst/gstplugin.h:377
pragma Import (C, gst_plugin_get_version, "gst_plugin_get_version");
function gst_plugin_get_license (plugin : access GstPlugin) return access GLIB.gchar; -- gst/gstplugin.h:378
pragma Import (C, gst_plugin_get_license, "gst_plugin_get_license");
function gst_plugin_get_source (plugin : access GstPlugin) return access GLIB.gchar; -- gst/gstplugin.h:379
pragma Import (C, gst_plugin_get_source, "gst_plugin_get_source");
function gst_plugin_get_package (plugin : access GstPlugin) return access GLIB.gchar; -- gst/gstplugin.h:380
pragma Import (C, gst_plugin_get_package, "gst_plugin_get_package");
function gst_plugin_get_origin (plugin : access GstPlugin) return access GLIB.gchar; -- gst/gstplugin.h:381
pragma Import (C, gst_plugin_get_origin, "gst_plugin_get_origin");
function gst_plugin_get_cache_data (plugin : access GstPlugin) return access constant GStreamer.GST_Low_Level.gstreamer_0_10_gst_gststructure_h.GstStructure; -- gst/gstplugin.h:382
pragma Import (C, gst_plugin_get_cache_data, "gst_plugin_get_cache_data");
procedure gst_plugin_set_cache_data (plugin : access GstPlugin; cache_data : access GStreamer.GST_Low_Level.gstreamer_0_10_gst_gststructure_h.GstStructure); -- gst/gstplugin.h:383
pragma Import (C, gst_plugin_set_cache_data, "gst_plugin_set_cache_data");
function gst_plugin_get_module (plugin : access GstPlugin) return System.Address; -- gst/gstplugin.h:385
pragma Import (C, gst_plugin_get_module, "gst_plugin_get_module");
function gst_plugin_is_loaded (plugin : access GstPlugin) return GLIB.gboolean; -- gst/gstplugin.h:386
pragma Import (C, gst_plugin_is_loaded, "gst_plugin_is_loaded");
function gst_plugin_name_filter (plugin : access GstPlugin; name : access GLIB.gchar) return GLIB.gboolean; -- gst/gstplugin.h:388
pragma Import (C, gst_plugin_name_filter, "gst_plugin_name_filter");
function gst_plugin_load_file (filename : access GLIB.gchar; error : System.Address) return access GstPlugin; -- gst/gstplugin.h:390
pragma Import (C, gst_plugin_load_file, "gst_plugin_load_file");
function gst_plugin_load (plugin : access GstPlugin) return access GstPlugin; -- gst/gstplugin.h:392
pragma Import (C, gst_plugin_load, "gst_plugin_load");
function gst_plugin_load_by_name (name : access GLIB.gchar) return access GstPlugin; -- gst/gstplugin.h:393
pragma Import (C, gst_plugin_load_by_name, "gst_plugin_load_by_name");
procedure gst_plugin_add_dependency
(plugin : access GstPlugin;
env_vars : System.Address;
paths : System.Address;
names : System.Address;
flags : GstPluginDependencyFlags); -- gst/gstplugin.h:395
pragma Import (C, gst_plugin_add_dependency, "gst_plugin_add_dependency");
procedure gst_plugin_add_dependency_simple
(plugin : access GstPlugin;
env_vars : access GLIB.gchar;
paths : access GLIB.gchar;
names : access GLIB.gchar;
flags : GstPluginDependencyFlags); -- gst/gstplugin.h:401
pragma Import (C, gst_plugin_add_dependency_simple, "gst_plugin_add_dependency_simple");
procedure gst_plugin_list_free (list : access GStreamer.GST_Low_Level.glib_2_0_glib_glist_h.GList); -- gst/gstplugin.h:407
pragma Import (C, gst_plugin_list_free, "gst_plugin_list_free");
end GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstplugin_h;
|
stcarrez/dynamo | Ada | 148,120 | adb | ------------------------------------------------------------------------------
-- --
-- ASIS-for-GNAT IMPLEMENTATION COMPONENTS --
-- --
-- A S I S . E X P R E S S I O N S --
-- --
-- B o d y --
-- --
-- Copyright (C) 1995-2012, Free Software Foundation, Inc. --
-- --
-- ASIS-for-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 --
-- Software Foundation; either version 2, or (at your option) any later --
-- version. ASIS-for-GNAT is distributed in the hope that it will be use- --
-- ful, but WITHOUT ANY WARRANTY; without even the implied warranty of MER- --
-- CHANTABILITY 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 ASIS-for-GNAT; see file --
-- COPYING. If not, write to the Free Software Foundation, 51 Franklin --
-- Street, Fifth Floor, Boston, MA 02110-1301, USA. --
-- --
-- --
-- --
-- --
-- --
-- --
-- --
-- --
-- ASIS-for-GNAT was originally developed by the ASIS-for-GNAT team at the --
-- Software Engineering Laboratory of the Swiss Federal Institute of --
-- Technology (LGL-EPFL) in Lausanne, Switzerland, in cooperation with the --
-- Scientific Research Computer Center of Moscow State University (SRCC --
-- MSU), Russia, with funding partially provided by grants from the Swiss --
-- National Science Foundation and the Swiss Academy of Engineering --
-- Sciences. ASIS-for-GNAT is now maintained by AdaCore --
-- (http://www.adacore.com). --
-- --
------------------------------------------------------------------------------
with Ada.Characters.Handling; use Ada.Characters.Handling;
with Asis.Declarations; use Asis.Declarations;
with Asis.Errors; use Asis.Errors;
with Asis.Exceptions; use Asis.Exceptions;
with Asis.Extensions; use Asis.Extensions;
with Asis.Elements; use Asis.Elements;
with Asis.Iterator; use Asis.Iterator;
with Asis.Limited_Views; use Asis.Limited_Views;
with Asis.Statements; use Asis.Statements;
with Asis.Set_Get; use Asis.Set_Get;
with A4G.A_Debug; use A4G.A_Debug;
with A4G.A_Output; use A4G.A_Output;
with A4G.A_Sem; use A4G.A_Sem;
with A4G.A_Sinput; use A4G.A_Sinput;
with A4G.Asis_Tables; use A4G.Asis_Tables;
with A4G.Contt.UT; use A4G.Contt.UT;
with A4G.Expr_Sem; use A4G.Expr_Sem;
with A4G.Mapping; use A4G.Mapping;
with A4G.Norm; use A4G.Norm;
with A4G.Vcheck; use A4G.Vcheck;
with Atree; use Atree;
with Einfo; use Einfo;
with Namet; use Namet;
with Nlists; use Nlists;
with Output; use Output;
with Sinfo; use Sinfo;
with Snames; use Snames;
with Stand; use Stand;
with Uintp; use Uintp;
package body Asis.Expressions is
Package_Name : constant String := "Asis.Expressions.";
------------------------------------------------------------------------------
---------------------------
-- ASIS 2005 Draft stuff --
---------------------------
----------------------------------------------
-- Corresponding_Expression_Type_Definition --
----------------------------------------------
function Corresponding_Expression_Type_Definition
(Expression : Asis.Expression)
return Asis.Element
is
Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Expression);
Result : constant Asis.Expression := Asis.Nil_Element;
begin
Check_Validity
(Expression, Package_Name &
"Corresponding_Expression_Type_Definition");
if Arg_Kind not in Internal_Expression_Kinds then
Raise_ASIS_Inappropriate_Element
(Diagnosis => Package_Name &
"Corresponding_Expression_Type_Definition",
Wrong_Kind => Arg_Kind);
end if;
-- first, we filter out cases for which Nil_Element should be
-- returned (may be, the check below is too trivial???)
if not Is_True_Expression (Expression) then
return Nil_Element;
end if;
Not_Implemented_Yet
(Diagnosis => Package_Name &
"Corresponding_Expression_Type_Definition");
return Result;
exception
when ASIS_Inappropriate_Element =>
raise;
when ASIS_Failed =>
if Status_Indicator = Unhandled_Exception_Error then
Add_Call_Information
(Argument => Expression,
Outer_Call => Package_Name &
"Corresponding_Expression_Type_Definition");
end if;
raise;
when Ex : others =>
Report_ASIS_Bug
(Query_Name => Package_Name &
"Corresponding_Expression_Type_Definition",
Ex => Ex,
Arg_Element => Expression);
end Corresponding_Expression_Type_Definition;
------------------------------------------------------------------------------
-- GENERAL DOCUMENTATION ITEMS --
------------------------------------------------------------------------------
-----------------------------
-- A_Function_Call Problem --
-----------------------------
-- As for now, the following consideration can be applied to explicit
-- elements only!!!
-- The following situations should be distinguished:
--
-- - the called function is a predefined operation (it can also be its
-- renaming);
-- - the called function is a user-defined function, but it has an operation
-- symbol as its designator;
-- - the called function is a "usual" user-defined function;
-- - the called function is an attribute;
--
-- - the call is prefix;
-- - the call is infix;
--
-- As a result, in an AST we can have the following situations;
--
-- - prefix call to a predefined operator:
--
-- Node is rewritten, the Original Node is of N_Function_Call kind
-- and its Name field points to the node of N_Operator_Symbol kind,
-- or of N_Expanded_Name kind, but anyway
-- the rewritten node is of N_Op_Xxxx kind and Original Node
-- contains the corresponding substructures only for naming
-- associations (if any). The rewritten node contains both parameters,
-- but in the form of positional association.
--
-- Compiler-time optimization for static expressions: the rewritten
-- node may be of N_Identifier kind (when optimizing calls to
-- boolean functions), N_Integer/Real_Literal king, when optimizing
-- function returning numeric results,
--
-- - infix call to a predefined operator:
--
-- Usually the node is unchanged, it is of N_Op_Xxx kind.
-- But the node may be rewritten into N_Integer_Literal or
-- N_Real_Literl, if the compiler optimizes an expression like
-- 1 + 2! It also may be rewritten into N_Identifier node,
-- if the compiler optimizes an expression like "not True"
-- or "False and True". Finally, it may be rewritten into
-- N_String_Literal, if the compiler optimizes an expression like
-- "The " & "Beatles"
--
-- The situation when a predefined operator is (re)defined by a renaming
-- declaration should be considered as a special case. The call is
-- rewritten into the node of the same N_Op_Xxx kind.
--
-- - prefix call to a user-defined operator:
--
-- node is unchanged, it is of N_Function_Call kind, but its Name
-- field points to the node of N_Operator_Symbol kind, if the prefix
-- consists on the operator symbol only, or to the node of N_Expanded_Name
-- kind.
--
-- - infix call to a user-defined operator:
--
-- node is unchanged, it is of N_Function_Call kind, but its Name
-- field points to the node of N_Identifier kind.
--
-- !! THIS MEANS THAT AN ELEMENT OF An_Operator_Symbol KIND MAY BE
-- BASED ON THE NODE OF N_Identifier kind!!!
--
-- - prefix call to a "usual" user-defined function:
--
-- node is unchanged, it is of N_Function_Call kind, its Name
-- field points to the node of N_Identifier or N_Expanded_Name kind
-- (as it should).
--
-- - call to an attribute-function (only the prefix form is possible)
--
-- node may or may nor be rewritten, but the Node field of the
-- corresponding element definitely is of N_Attribute_Reference
-- kind, and its Expressions field should be used for obtaining the
-- list of the function call parameters.
--
-- This is important for the functions:
--
-- Prefix
-- Is_Prefix_Call
-- Corresponding_Called_Function (?)
-- Function_Call_Parameters
--
-- having A_Function_Call as their appropriate kind, and also for
-- Name_Image (in the case of getting the image of an operator symbol)
--
-- THE MAPPING.2 DOCUMENT ALSO REQUIRES CORRECTIONS!!!
------------------------------------------------------------------------------
function Corresponding_Expression_Type
(Expression : Asis.Expression)
return Asis.Declaration
is
Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Expression);
begin
-- this is the result of the first attempt to implement this function
-- the code is rather dirty, non-effective and not well-organized
Check_Validity
(Expression, Package_Name & "Corresponding_Expression_Type");
if Arg_Kind not in Internal_Expression_Kinds then
Raise_ASIS_Inappropriate_Element
(Diagnosis => Package_Name & "Corresponding_Expression_Type",
Wrong_Kind => Arg_Kind);
end if;
-- first, we filter out cases for which Nil_Element should be
-- returned (may be, the check below is too trivial???)
if not Is_True_Expression (Expression) then
return Nil_Element;
end if;
-- we incapsulate the real processing in the function
-- A4G.Expr_Sem.Expr_Type:
return Expr_Type (Expression);
exception
when ASIS_Inappropriate_Element =>
raise;
when ASIS_Failed =>
if Status_Indicator = Unhandled_Exception_Error then
Add_Call_Information
(Argument => Expression,
Outer_Call => Package_Name & "Corresponding_Expression_Type");
end if;
raise;
when Ex : others =>
Report_ASIS_Bug
(Query_Name => Package_Name & "Corresponding_Expression_Type",
Ex => Ex,
Arg_Element => Expression);
end Corresponding_Expression_Type;
----------------
-- Name_Image --
----------------
function Name_Image (Expression : Asis.Expression) return Wide_String is
Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Expression);
Arg_Node : Node_Id;
Arg_R_Node : Node_Id;
Def_Name : Asis.Element;
Tmp_Node : Node_Id;
Image_Start : Source_Ptr;
Image_End : Source_Ptr;
begin
Check_Validity (Expression, "Asis_Declarations.Name_Image");
if not (Arg_Kind = An_Identifier or else
Arg_Kind in Internal_Operator_Symbol_Kinds or else
Arg_Kind = A_Character_Literal or else
Arg_Kind = An_Enumeration_Literal)
then
Raise_ASIS_Inappropriate_Element
(Diagnosis => Package_Name & "Name_Image",
Wrong_Kind => Arg_Kind);
end if;
-- Let's first handle special cases:
--
-- = of fake Numeric_Error renaming (see B712-0050)
-- = of a named number rewritten as a literal node (see BB10-002)
case Special_Case (Expression) is
when Numeric_Error_Renaming =>
return "Constraint_Error";
when Rewritten_Named_Number =>
-- The problem here is that the references to the named numbers
-- are rewritten as numeric literals, and in expanded generics the
-- original tree structure for such references is lost. So in an
-- expended generic we have to get the image from the defining
-- occurrence of the name
if Is_Part_Of_Instance (Expression) then
return Defining_Name_Image
(Corresponding_Name_Definition (Expression));
end if;
when Dummy_Class_Attribute_Designator =>
return "Class";
when Dummy_Base_Attribute_Designator =>
return "Base";
when others =>
null;
end case;
Arg_Node := Node (Expression);
Arg_R_Node := R_Node (Expression);
if not Comes_From_Source (Arg_Node)
and then
Arg_Kind not in Internal_Operator_Symbol_Kinds
and then
Arg_Kind /= An_Enumeration_Literal
and then
Special_Case (Expression) not in
Dummy_Base_Attribute_Prefix .. Dummy_Class_Attribute_Prefix
and then
Nkind (Arg_Node) /= N_Attribute_Reference
and then
Part_Of_Pass_Generic_Actual (Arg_Node)
then
Arg_Node := Entity (Arg_Node);
Arg_R_Node := Arg_Node;
end if;
case Arg_Kind is
when A_Character_Literal =>
return ''' &
Wide_Character'Val
(Integer (UI_To_CC
(Char_Literal_Value (Arg_Node)))) &
''';
when Internal_Operator_Symbol_Kinds =>
-- three alternatives can be possible:
--
-- the Element is based on N_Op_Xxx node
-- -> an infix call of a predefined operator
--
-- the Element is based on N_Operator_Symbol node
-- -> definitely a prefix call
--
-- the Element is based on N_Identifier node
-- -> an infix call of a user-defined operator
--
-- But in any case the result should be enclosed in quoters
if Nkind (Arg_Node) = N_Operator_Symbol then
return Wide_String_Image (Arg_Node);
else
-- N_Identifier and N_Op_Xxx nodes are processed
-- in the same way
return To_Wide_String (Operator_Image (Arg_Node));
end if;
when others =>
-- really only An_Identifier | An_Enumeration_Literal
-- are possible,
-- see the condition for defining the appropriate
-- argument
-- The special case exists for names which are type marks
-- in the parameter and result profiles in the implicit inherited
-- subprograms
Tmp_Node := Node_Field_1 (Expression);
if Nkind (Arg_Node) /= N_Attribute_Reference
and then
Nkind (Arg_Node) in N_Has_Entity
and then
Entity_Present (Arg_Node)
and then
Ekind (Entity (Arg_Node)) in Einfo.Type_Kind
and then
Is_From_Inherited (Expression)
and then
(Ekind (Tmp_Node) = E_Procedure or else
Ekind (Tmp_Node) = E_Function)
then
Arg_Node := Get_Derived_Type
(Type_Entity => Entity (Arg_Node),
Inherited_Subpr => Tmp_Node);
end if;
if Sloc (Arg_Node) <= Standard_Location
or else
(Special_Case (Expression) = Is_From_Imp_Neq_Declaration
and then
Nkind (Parent (Arg_Node)) = N_Function_Specification
and then
Arg_Node = Result_Definition (Parent (Arg_Node)))
-- This condition describes the return type of implicit
-- "/=". It is always Boolean
or else
Normalization_Case (Expression) =
Is_Normalized_Defaulted_For_Box
-- This condition defines the "implicit naming expression"
-- that should be returned as a part of normalized generic
-- association if the formal contains the box default, and
-- the actual subprogram is defined at place of instantiation.
-- We do not really care about the name, but the problem
-- is that the Sloc field for the corresponding node is not
-- set properly whereas Chars is.
then
return To_Wide_String (Normalized_Namet_String (Arg_Node));
elsif Is_Rewrite_Substitution (Arg_R_Node)
and then
Nkind (Arg_R_Node) = N_Identifier
and then
Nkind (Arg_Node) = N_Identifier
and then
Is_From_Instance (Arg_R_Node)
and then
Ekind (Entity (Arg_R_Node)) = E_Package
and then
Renamed_Entity (Entity (Arg_Node)) =
Entity (Arg_R_Node)
then
-- This condition corresponds to the case when we have a name
-- that is a reference to the generic unit name inside expanded
-- generic (see F627-001)
Def_Name := Corresponding_Name_Definition (Expression);
if Defining_Name_Kind (Def_Name) = A_Defining_Expanded_Name then
Def_Name := Defining_Selector (Def_Name);
end if;
return Defining_Name_Image (Def_Name);
else
if Special_Case (Expression) = Dummy_Class_Attribute_Prefix then
Arg_Node := Etype (Entity (Arg_Node));
elsif Special_Case (Expression) =
Dummy_Base_Attribute_Prefix
then
Arg_Node := Associated_Node (Arg_Node);
while Is_Itype (Arg_Node) loop
Arg_Node := Associated_Node_For_Itype (Arg_Node);
Arg_Node := Defining_Identifier (Arg_Node);
end loop;
end if;
Image_Start := Sloc (Arg_Node);
-- special processing is needed for some cases:
if Get_Character (Image_Start) = ''' then
-- special processing for an "ordinary" attribute
-- designator
Image_Start := Next_Identifier (Image_Start);
elsif Get_Character (Image_Start) = '.' then
-- This is the case for a subtype mark in expanded
-- subprogram spec in case if in the template we have a
-- formal type, and the actual type is represented by
-- an expanded name
Image_Start := Image_Start + 1;
elsif Nkind (Arg_Node) = N_Attribute_Definition_Clause then
-- special processing for an attribute designator being
-- a child element of a pseudo attribute reference from
-- an attribute definition clause
Image_Start := Search_Rightmost_Symbol (Image_Start, ''');
Image_Start := Next_Identifier (Image_Start);
if Nkind (Sinfo.Name (Arg_Node)) = N_Attribute_Reference then
-- See FA30-016
Image_Start := Search_Rightmost_Symbol (Image_Start, ''');
Image_Start := Next_Identifier (Image_Start);
end if;
end if;
Image_End := Get_Word_End (P => Image_Start,
In_Word => In_Identifier'Access);
return Get_Wide_Word (Image_Start, Image_End);
end if;
end case;
exception
when ASIS_Inappropriate_Element =>
raise;
when ASIS_Failed =>
if Status_Indicator = Unhandled_Exception_Error then
Add_Call_Information
(Argument => Expression,
Outer_Call => Package_Name & "Name_Image");
end if;
raise;
when Ex : others =>
Report_ASIS_Bug
(Query_Name => Package_Name & "Name_Image",
Ex => Ex,
Arg_Element => Expression);
end Name_Image;
-----------------------------------------------------------------------------
function Value_Image (Expression : Asis.Expression) return Wide_String
is
Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Expression);
Arg_Node : Node_Id;
Image_Start : Source_Ptr;
Image_End : Source_Ptr;
begin
Check_Validity (Expression, Package_Name & "Value_Image");
if not (Arg_Kind = An_Integer_Literal or else
Arg_Kind = A_Real_Literal or else
Arg_Kind = A_String_Literal)
then
Raise_ASIS_Inappropriate_Element
(Diagnosis => Package_Name & "Value_Image",
Wrong_Kind => Arg_Kind);
end if;
Arg_Node := Node (Expression);
if Sloc (Arg_Node) <= Standard_Location then
case Arg_Kind is
when An_Integer_Literal =>
UI_Image (Intval (Arg_Node));
return To_Wide_String (UI_Image_Buffer (1 .. UI_Image_Length));
when A_Real_Literal =>
return To_Wide_String (Ureal_Image (Arg_Node));
when others =>
raise Internal_Implementation_Error;
end case;
else
case Arg_Kind is
when An_Integer_Literal
| A_Real_Literal =>
Image_Start := Sloc (Arg_Node);
Image_End := Get_Num_Literal_End (P => Image_Start);
return Get_Wide_Word (Image_Start, Image_End);
when A_String_Literal =>
return Wide_String_Image (Arg_Node);
when others =>
raise Internal_Implementation_Error;
-- this choice can never been reached,
-- see the condition for defining the appropriate argument
end case;
end if;
exception
when ASIS_Inappropriate_Element =>
raise;
when ASIS_Failed =>
if Status_Indicator = Unhandled_Exception_Error then
Add_Call_Information
(Argument => Expression,
Outer_Call => Package_Name & "Value_Image");
end if;
raise;
when Ex : others =>
Report_ASIS_Bug
(Query_Name => Package_Name & "Value_Image",
Ex => Ex,
Arg_Element => Expression);
end Value_Image;
-----------------------------------------------------------------------------
------------------------------------------------------------------------------
-- OPEN PROBLEMS:
--
-- 1. A_Defining_Expanded_Name: is the recursive construction of the result
-- of the String type a really good thing here? The performance can be poor
-- but, from the other hand, this can happen not very often.
--
-- 2. The Asis_Declarations.Defining_Name_Image function contains the
-- (almost) exact
-- copy of the part of the code of this function (except the part for
-- processing A_Defining_Expanded_Name). May be, it should be better
-- to separate it on low-level function.
-------------------------------------------------------------------------------
-- PARTIALLY IMPLEMENTED, case Implicitly => True is not implemented
function References
(Name : Asis.Element;
Within_Element : Asis.Element;
Implicitly : Boolean := False)
return Asis.Name_List
is
Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Name);
Arg_Name : Asis.Element;
Search_Reference_Control : Traverse_Control := Continue;
Search_Reference_State : No_State := Not_Used;
procedure Check_Reference
(Element : Asis.Element;
Control : in out Traverse_Control;
State : in out No_State);
-- Actual for Pre_Operation: checks if Element is a reference to
-- Name, and if it is, puts it into Element table
procedure Collect_References is new Traverse_Element
(State_Information => No_State,
Pre_Operation => Check_Reference,
Post_Operation => No_Op);
procedure Check_Reference
(Element : Asis.Element;
Control : in out Traverse_Control;
State : in out No_State)
is
begin
pragma Unreferenced (Control);
pragma Unreferenced (State);
if Is_Reference (Arg_Name, Element) then
Asis_Element_Table.Append (Element);
end if;
end Check_Reference;
begin
Check_Validity (Name, Package_Name & "References");
if not (Arg_Kind in Internal_Defining_Name_Kinds) then
Raise_ASIS_Inappropriate_Element
(Diagnosis => Package_Name & "References",
Wrong_Kind => Arg_Kind);
elsif Implicitly then
Not_Implemented_Yet
(Diagnosis => Package_Name & "References (Implicitly => True)");
end if;
Arg_Name := Enclosing_Element (Name);
if Int_Kind (Arg_Name) /= A_Defining_Expanded_Name then
Arg_Name := Name;
end if;
Asis_Element_Table.Init;
Collect_References
(Element => Within_Element,
Control => Search_Reference_Control,
State => Search_Reference_State);
return Asis.Name_List
(Asis_Element_Table.Table (1 .. Asis_Element_Table.Last));
exception
when ASIS_Inappropriate_Element =>
raise;
when ASIS_Failed =>
if Status_Indicator = Unhandled_Exception_Error then
Add_Call_Information
(Argument => Name,
Bool_Par => Implicitly,
Outer_Call => Package_Name & "References");
end if;
raise;
when Ex : others =>
Report_ASIS_Bug
(Query_Name => Package_Name & "References",
Ex => Ex,
Arg_Element => Name,
Arg_Element_2 => Within_Element,
Bool_Par_ON => Implicitly);
end References;
------------------------------------------------------------------------------
-- PARTIALLY IMPLEMENTED, case Implicitly => True is not implemented
function Is_Referenced
(Name : Asis.Element;
Within_Element : Asis.Element;
Implicitly : Boolean := False)
return Boolean
is
Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Name);
Arg_Name : Asis.Element;
Result : Boolean := False;
Search_Reference_Control : Traverse_Control := Continue;
Search_Reference_State : No_State := Not_Used;
procedure Search_Reference
(Element : Asis.Element;
Control : in out Traverse_Control;
State : in out No_State);
-- Actual for Pre_Operation: looks for (the first) reference to Name.
-- Sets Result to True if such a reference is found
procedure Check_Reference is new Traverse_Element
(State_Information => No_State,
Pre_Operation => Search_Reference,
Post_Operation => No_Op);
procedure Search_Reference
(Element : Asis.Element;
Control : in out Traverse_Control;
State : in out No_State)
is
begin
pragma Unreferenced (State);
if Is_Reference (Arg_Name, Element) then
Result := True;
Control := Terminate_Immediately;
end if;
end Search_Reference;
begin -- Is_Referenced
Check_Validity (Name, Package_Name & "Is_Referenced");
if not (Arg_Kind in Internal_Defining_Name_Kinds) then
return False;
elsif Implicitly then
Not_Implemented_Yet
(Diagnosis => Package_Name & "Is_Referenced (Implicitly => True)");
end if;
Arg_Name := Enclosing_Element (Name);
if Int_Kind (Arg_Name) /= A_Defining_Expanded_Name then
Arg_Name := Name;
end if;
Check_Reference
(Element => Within_Element,
Control => Search_Reference_Control,
State => Search_Reference_State);
return Result;
exception
when ASIS_Inappropriate_Element =>
raise;
when ASIS_Failed =>
if Status_Indicator = Unhandled_Exception_Error then
Add_Call_Information
(Argument => Name,
Bool_Par => Implicitly,
Outer_Call => Package_Name & "Is_Referenced");
end if;
raise;
when Ex : others =>
Report_ASIS_Bug
(Query_Name => Package_Name & "Is_Referenced",
Ex => Ex,
Arg_Element => Name,
Arg_Element_2 => Within_Element,
Bool_Par_ON => Implicitly);
end Is_Referenced;
-----------------------------------
-- Corresponding_Name_Definition --
-----------------------------------
function Corresponding_Name_Definition
(Reference : Asis.Expression)
return Asis.Defining_Name
is
Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Reference);
Result : Element;
Parent_Node : Node_Id;
begin
Check_Validity
(Reference, Package_Name & "Corresponding_Name_Definition");
if not (Arg_Kind = An_Identifier or else
Arg_Kind in Internal_Operator_Symbol_Kinds or else
Arg_Kind = A_Character_Literal or else
Arg_Kind = An_Enumeration_Literal) or else
Is_Aspect_Mark (Reference) or else
Is_Aspect_Specific_Identifier (Reference) or else
(not Is_Uniquely_Defined (Reference))
then
Raise_ASIS_Inappropriate_Element
(Diagnosis => Package_Name & "Corresponding_Name_Definition",
Wrong_Kind => Arg_Kind);
end if;
if Is_From_Limited_View (Reference) then
return Nil_Element;
end if;
if Arg_Kind = An_Identifier or else
Arg_Kind = An_Enumeration_Literal or else
Arg_Kind in Internal_Operator_Symbol_Kinds
then
-- A special case of fake Numeric_Error renaming is handled
-- separately (see B712-005)
if Special_Case (Reference) = Numeric_Error_Renaming then
Result :=
Node_To_Element_New
(Node => Standard_Constraint_Error,
Starting_Element => Reference,
Internal_Kind => A_Defining_Identifier,
Spec_Case => Explicit_From_Standard);
else
if Is_Predefined_Operator (Reference)
or else
Is_Default_For_Null_Procedure (Reference)
then
Result := Nil_Element;
else
-- First, process a special case when Reference is a label
-- from goto statement that is rewritten into an infinite loop
-- in the tree. The node of such Reference does not have the
-- Entity field set
Parent_Node := Parent (R_Node (Reference));
if Nkind (Parent_Node) = N_Loop_Statement
and then
Is_Rewrite_Substitution (Parent_Node)
and then
Nkind (Original_Node (Parent_Node)) = N_Goto_Statement
then
Result := Enclosing_Element (Reference);
Result := Corresponding_Destination_Statement (Result);
Result := Label_Names (Result) (1);
else
Result := Identifier_Name_Definition (Reference);
end if;
end if;
if Is_Nil (Result) then
null;
elsif Special_Case (Reference) = Rewritten_Named_Number then
Correct_Result (Result, Reference);
elsif Defining_Name_Kind (Result) /= A_Defining_Expanded_Name
and then
Is_Implicit_Formal_Par (Result)
then
Correct_Impl_Form_Par (Result, Reference);
end if;
end if;
else
Result := Character_Literal_Name_Definition (Reference);
end if;
return Result;
exception
when ASIS_Inappropriate_Element =>
raise;
when ASIS_Failed =>
if Status_Indicator = Unhandled_Exception_Error then
Add_Call_Information
(Argument => Reference,
Outer_Call => Package_Name & "Corresponding_Name_Definition");
end if;
raise;
when Ex : others =>
Report_ASIS_Bug
(Query_Name => Package_Name & "Corresponding_Name_Definition",
Ex => Ex,
Arg_Element => Reference);
end Corresponding_Name_Definition;
----------------------------------------
-- Corresponding_Name_Definition_List --
----------------------------------------
function Corresponding_Name_Definition_List
(Reference : Asis.Element)
return Asis.Defining_Name_List
is
Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Reference);
begin
Check_Validity (Reference, Package_Name & "Name_Definition_List");
if not (Arg_Kind = An_Identifier or else
Arg_Kind in Internal_Operator_Symbol_Kinds or else
Arg_Kind = A_Character_Literal or else
Arg_Kind = An_Enumeration_Literal)
then
Raise_ASIS_Inappropriate_Element
(Diagnosis => Package_Name & "Corresponding_Name_Definition_List",
Wrong_Kind => Arg_Kind);
end if;
if Is_From_Limited_View (Reference) then
return Nil_Element_List;
end if;
Asis_Element_Table.Init;
if Needs_List (Reference) then
Collect_Overloaded_Entities (Reference);
else
Asis_Element_Table.Append (Corresponding_Name_Definition (Reference));
end if;
return Asis.Declaration_List
(Asis_Element_Table.Table (1 .. Asis_Element_Table.Last));
exception
when ASIS_Inappropriate_Element =>
raise;
when ASIS_Failed =>
if Status_Indicator = Unhandled_Exception_Error then
Add_Call_Information (
Argument => Reference,
Outer_Call => Package_Name & "Name_Definition_List");
end if;
raise;
when Ex : others =>
Report_ASIS_Bug
(Query_Name => Package_Name & "Name_Definition_List",
Ex => Ex,
Arg_Element => Reference);
end Corresponding_Name_Definition_List;
------------------------------------------------------------------------------
function Corresponding_Name_Declaration
(Reference : Asis.Expression)
return Asis.Declaration
is
Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Reference);
Result : Asis.Element;
begin
Check_Validity
(Reference, Package_Name & "Corresponding_Name_Declaration");
if not (Arg_Kind = An_Identifier or else
Arg_Kind in Internal_Operator_Symbol_Kinds or else
Arg_Kind = A_Character_Literal or else
Arg_Kind = An_Enumeration_Literal)
then
Raise_ASIS_Inappropriate_Element
(Diagnosis => Package_Name & "Corresponding_Name_Declaration",
Wrong_Kind => Arg_Kind);
end if;
if Is_From_Limited_View (Reference) then
return Nil_Element;
end if;
Result := Corresponding_Name_Definition (Reference);
if not Is_Nil (Result) then
Result := Enclosing_Element (Result);
end if;
return Result;
exception
when ASIS_Inappropriate_Element =>
raise;
when ASIS_Failed =>
if Status_Indicator = Unhandled_Exception_Error then
Add_Call_Information
(Argument => Reference,
Outer_Call => Package_Name & "Corresponding_Name_Declaration");
end if;
raise;
when Ex : others =>
Report_ASIS_Bug
(Query_Name => Package_Name & "Corresponding_Name_Declaration",
Ex => Ex,
Arg_Element => Reference);
end Corresponding_Name_Declaration;
-----------------------------------------------------------------------------
function Prefix (Expression : Asis.Expression) return Asis.Expression is
Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Expression);
Arg_Node : Node_Id;
Returned_Kind : Internal_Expression_Kinds;
Res_Spec_Case : Special_Cases := Not_A_Special_Case;
Result_Node : Node_Id;
begin
-- ???
-- the code is really awful!!! too many return statements!!!
Check_Validity (Expression, Package_Name & "Prefix");
if not (Arg_Kind = An_Explicit_Dereference or else
Arg_Kind in Internal_Attribute_Reference_Kinds or else
Arg_Kind = A_Function_Call or else
Arg_Kind = An_Indexed_Component or else
Arg_Kind = A_Selected_Component or else
Arg_Kind = A_Slice)
then
Raise_ASIS_Inappropriate_Element
(Diagnosis => Package_Name & "Prefix",
Wrong_Kind => Arg_Kind);
end if;
Arg_Node := Node (Expression);
if (Nkind (Arg_Node) = N_Identifier or else
Nkind (Arg_Node) = N_Expanded_Name)
and then
-- Special case: F.A, where either F or A is a function call
Nkind (R_Node (Expression)) = N_Function_Call
then
Arg_Node := R_Node (Expression);
end if;
-- We might implement this as shown below (the name following
-- the arrow (->) is the name of the Sinfo-defined tree access
-- function which should be used to obtain the result node,
-- the infix form of A_Function_Call should be treated as a special
-- case:
-- case Arg_Kind is
--
-- when An_Explicit_Dereference =>
-- -- N_Explicit_Dereference -> Prefix
--
-- when Internal_Attribute_Reference_Kinds =>
-- -- N_Attribute_Reference -> Prefix
--
-- when A_Function_Call =>
-- -- N_Function_Call -- prefix call -> Name
-- -- N_Op_* -- infix call -> the result should be based
-- -- on the same node
-- -- N_Attribute_Reference -> the result should be based
-- on the same node
--
-- when An_Indexed_Component =>
-- -- N_Indexed_Component -> Prefix
--
-- when A_Selected_Component =>
-- -- N_Selected_Component -> Prefix
-- -- N_Expanded_Name -> Prefix
--
-- when A_Slice =>
-- -- N_Slice -> Prefix
--
-- when others =>
--
-- return Nil_Element; -- to make the code formally correct,
-- -- see the condition for determining the
-- end case; -- appropriate element
-- but it is more convenient to use the Node_Kind-driven
-- case statement for implementing just the same processing:
Result_Node := Arg_Node;
-- for N_Op_* cases only; it may seem as being a bit tricky, but another
-- variants are too long ;-)
if Debug_Flag_1 then
Write_Node (Arg_Node, "Prefix: Arg_Node -> ");
Write_Eol;
end if;
case Nkind (Arg_Node) is
when N_Explicit_Dereference -- Prefix node access function
| N_Slice -- should be used for tree traversing
| N_Indexed_Component -- traversing
| N_Selected_Component
| N_Expanded_Name =>
-- !!The Node of N_Identifier kind cannot be processed by the
-- !!general Node_To_Element function (involving the auto
-- !!determination of the Element kind), because the subcomponents
-- !!of the prefix of a defining_unit_name do not have the Entity
-- !!attribute set.
Result_Node := Prefix (Arg_Node);
if Nkind (Result_Node) = N_Identifier and then
not Is_Rewrite_Substitution (Result_Node)
then
return Node_To_Element_New (
Node => Result_Node,
Starting_Element => Expression,
Internal_Kind => An_Identifier,
Considering_Parent_Count => False);
else
return Node_To_Element_New (
Node => Result_Node,
Starting_Element => Expression,
Considering_Parent_Count => False);
end if;
when N_Attribute_Definition_Clause =>
-- special processing for pseudo-attribute being the child
-- element of An_Attribute_Definition_Clause Element
Result_Node := Sinfo.Name (Arg_Node);
return Node_To_Element_New
(Starting_Element => Expression,
Node => Result_Node);
when N_Attribute_Reference =>
-- two cases should be distinguished: when the function argument is
-- of A_Function_Call kind and when it is in
-- Internal_Attribute_Reference_Kinds
if Debug_Flag_1 then
Write_Str
(Package_Name & "Prefix: "
& "processing N_Attribute_Reference Node...");
Write_Eol;
Write_Node (Arg_Node, "Arg Node -> ");
Write_Eol;
end if;
if Arg_Kind = A_Function_Call then
-- the result should be based on the same node, so the
-- Result_Node setting should not be changed, but the kind
-- of the result should be determined by hand
Returned_Kind := Subprogram_Attribute_Kind (Result_Node);
return Node_To_Element_New (
Node => R_Node (Expression),
Starting_Element => Expression,
Internal_Kind => Returned_Kind,
Considering_Parent_Count => False);
else
-- just the same processing as for the previous
-- case alternative:
Result_Node := Prefix (Arg_Node);
if Debug_Flag_1 then
Write_Str (Package_Name & "Prefix: "
& "processing N_Attribute_Reference Prefix Node...");
Write_Eol;
Write_Node (Result_Node, "Result Node -> ");
Write_Eol;
end if;
if Nkind (Result_Node) = N_Identifier and then
not Is_Rewrite_Substitution (Result_Node)
then
return Node_To_Element_New (
Node => Result_Node,
Starting_Element => Expression,
Internal_Kind => An_Identifier,
Considering_Parent_Count => False);
else
return Node_To_Element_New (
Node => Result_Node,
Starting_Element => Expression,
Considering_Parent_Count => False);
end if;
end if;
when N_Function_Call |
N_Procedure_Call_Statement =>
-- N_Procedure_Call_Statement corresponds to the argument of pragma
-- Debug which is treated as A_Function_Call
-- Name node access function should be used for tree traversing
if Debug_Flag_1 then
Write_Str ("Prefix: processing N_Function_Call Node:");
Write_Eol;
Write_Str ("Node is rewritten more than once - ");
Write_Eol;
Write_Str (Boolean'Image (Is_Rewrite_Substitution (Arg_Node)));
Write_Eol;
end if;
-- See comments under "A_Function_Call Problem" headline in the
-- beginning of the package body - we shall distinguish the case
-- of the infix call of the user - defined operator. The Name
-- function gives the result of N_Identifier kind, but really it
-- corresponds to the An_Operator_Symbol Element!
Result_Node := Sinfo.Name (Arg_Node);
if Is_Rewrite_Substitution (Result_Node)
and then
Nkind (Result_Node) = N_Explicit_Dereference
and then
Nkind (Prefix (Result_Node)) = N_Function_Call
then
-- Needed to process cases like F (1), where F - parameterless
-- function that returns access-to-subprogram result.
Result_Node := Prefix (Result_Node);
end if;
if Debug_Flag_1 then
Write_Node (Result_Node, "Prefix: Result_Node -> ");
Write_Eol;
end if;
if Nkind (Result_Node) = N_Identifier and then
Chars (Result_Node) in Any_Operator_Name
then
-- really we have a infix call of a user-defined operator!
Returned_Kind :=
A4G.Mapping.N_Operator_Symbol_Mapping (Result_Node);
else
return Node_To_Element_New (
Node => Result_Node,
Starting_Element => Expression,
Considering_Parent_Count => False);
end if;
-- when N_Op_* => -- N_Op_* cases corresponding to the infix function
-- call, the result should be based on the same node;
-- only the internal kind of the returned element is
-- determined in the case statement; the return
-- statement for N_Op_* alternatives is located
-- outside the case statement
when N_Op_And => -- "and"
Returned_Kind := An_And_Operator;
when N_Op_Or => -- "or"
Returned_Kind := An_Or_Operator;
when N_Op_Xor => -- "xor"
Returned_Kind := An_Xor_Operator;
when N_Op_Eq => -- "="
Returned_Kind := An_Equal_Operator;
when N_Op_Ne => -- "/="
Returned_Kind := A_Not_Equal_Operator;
when N_Op_Lt => -- "<"
Returned_Kind := A_Less_Than_Operator;
when N_Op_Le => -- "<="
Returned_Kind := A_Less_Than_Or_Equal_Operator;
when N_Op_Gt => -- ">"
Returned_Kind := A_Greater_Than_Operator;
when N_Op_Ge => -- ">="
Returned_Kind := A_Greater_Than_Or_Equal_Operator;
when N_Op_Add => -- "+" (binary)
Returned_Kind := A_Plus_Operator;
when N_Op_Subtract => -- "-" (binary)
Returned_Kind := A_Minus_Operator;
when N_Op_Concat => -- "&"
Returned_Kind := A_Concatenate_Operator;
when N_Op_Plus => -- "+" (unary)
Returned_Kind := A_Unary_Plus_Operator;
when N_Op_Minus => -- "-" (unary)
Returned_Kind := A_Unary_Minus_Operator;
when N_Op_Multiply => -- "*"
Returned_Kind := A_Multiply_Operator;
when N_Op_Divide => -- "/"
Returned_Kind := A_Divide_Operator;
when N_Op_Mod => -- "mod"
Returned_Kind := A_Mod_Operator;
when N_Op_Rem => -- "rem"
Returned_Kind := A_Rem_Operator;
when N_Op_Expon => -- "**"
Returned_Kind := An_Exponentiate_Operator;
when N_Op_Abs => -- "abs"
Returned_Kind := An_Abs_Operator;
when N_Op_Not => -- "not"
Returned_Kind := A_Not_Operator;
when N_Identifier =>
-- See F410-011. The argument is the artificial 'Class attribute
-- reference in the instance that corresponds to the actual
-- class-wide type.
if Is_Part_Of_Instance (Expression)
and then
(Represents_Class_Wide_Type_In_Instance (Arg_Node)
or else
Represents_Base_Type_In_Instance (Arg_Node))
then
Result_Node := Arg_Node;
Returned_Kind := An_Identifier;
if Represents_Class_Wide_Type_In_Instance (Arg_Node) then
Res_Spec_Case := Dummy_Class_Attribute_Prefix;
else
Res_Spec_Case := Dummy_Base_Attribute_Prefix;
end if;
elsif (Nkind (Arg_Node) = N_Identifier
and then
not Comes_From_Source (Arg_Node)
and then
Ekind (Entity (Arg_Node)) = E_Class_Wide_Type) -- See FA13-008
or else
Is_Aspect_Mark (Expression)
then
Result_Node := Arg_Node;
Returned_Kind := An_Identifier;
else
pragma Assert (False);
null;
end if;
when others =>
-- to make the code formally correct, nothing else could be possible
pragma Assert (False);
return Nil_Element;
end case;
-- forming the result for N_Op_* cases and for the infix call of a
-- user-defined operator:
-- ??? !!! This is the ad hoc patch for Enclosing_Element needs:
-- we should keep rewritten node for function calls rewritten as
-- results of compiler-time optimisations
if Returned_Kind in Internal_Operator_Symbol_Kinds
and then
Nkind (Node (Expression)) /= N_Function_Call
and then
Is_Rewrite_Substitution (R_Node (Expression))
then
Result_Node := R_Node (Expression);
end if;
return Node_To_Element_New (
Node => Result_Node,
Starting_Element => Expression,
Internal_Kind => Returned_Kind,
Spec_Case => Res_Spec_Case,
Considering_Parent_Count => False);
exception
when ASIS_Inappropriate_Element =>
raise;
when ASIS_Failed =>
if Status_Indicator = Unhandled_Exception_Error then
Add_Call_Information
(Argument => Expression,
Outer_Call => Package_Name & "Prefix");
end if;
raise;
when Ex : others =>
Report_ASIS_Bug
(Query_Name => Package_Name & "Prefix",
Ex => Ex,
Arg_Element => Expression);
end Prefix;
------------------------------------------------------------------------------
function Index_Expressions
(Expression : Asis.Expression)
return Asis.Expression_List
is
Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Expression);
Arg_Node : Node_Id;
begin
Check_Validity (Expression, Package_Name & "Index_Expressions");
if not (Arg_Kind = An_Indexed_Component) then
Raise_ASIS_Inappropriate_Element
(Diagnosis => Package_Name & "Index_Expressions",
Wrong_Kind => Arg_Kind);
end if;
Arg_Node := Node (Expression);
return N_To_E_List_New
(List => Sinfo.Expressions (Arg_Node),
Starting_Element => Expression);
exception
when ASIS_Inappropriate_Element =>
raise;
when ASIS_Failed =>
if Status_Indicator = Unhandled_Exception_Error then
Add_Call_Information
(Argument => Expression,
Outer_Call => Package_Name & "Index_Expressions");
end if;
raise;
when Ex : others =>
Report_ASIS_Bug
(Query_Name => Package_Name & "Index_Expressions",
Ex => Ex,
Arg_Element => Expression);
end Index_Expressions;
-----------------------------------------------------------------------------
function Slice_Range
(Expression : Asis.Expression)
return Asis.Discrete_Range
is
Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Expression);
Arg_Node : Node_Id;
begin
Check_Validity (Expression, Package_Name & "Slice_Range");
if not (Arg_Kind = A_Slice) then
Raise_ASIS_Inappropriate_Element
(Diagnosis => Package_Name & "Slice_Range",
Wrong_Kind => Arg_Kind);
end if;
Arg_Node := Node (Expression);
return Node_To_Element_New
(Node => Sinfo.Discrete_Range (Arg_Node),
Starting_Element => Expression);
exception
when ASIS_Inappropriate_Element =>
raise;
when ASIS_Failed =>
if Status_Indicator = Unhandled_Exception_Error then
Add_Call_Information
(Argument => Expression,
Outer_Call => Package_Name & "Slice_Range");
end if;
raise;
when Ex : others =>
Report_ASIS_Bug
(Query_Name => Package_Name & "Slice_Range",
Ex => Ex,
Arg_Element => Expression);
end Slice_Range;
-----------------------------------------------------------------------------
-----------------------------------------------
-- local functions for the Selector function --
-----------------------------------------------
function Last_Selector (Node : Node_Id) return Boolean;
-- Node should be of N_Identifier kind, obtained as a Selector_Name
-- form N_Selected_Component or N_Expanded name node;
-- a caller is responsible for this. This function checks if
-- Node is the last selector in the corresponding selected component
-- or expanded name
function Is_Enumeration_Literal (Node : Node_Id) return Boolean;
-- Node should be of N_Identifier kind, obtained as a Selector_Name
-- form N_Selected_Component or N_Expanded name node;
-- moreover, this is the last selector in the enclosing construct
-- a caller is responsible for this. This function checks if
-- its argument should be classified as An_Enumeration_Literal
-- by checking the Entity fields of the outermost "enclosing"
-- node of N_Expanded_Name kind
function Last_Selector (Node : Node_Id) return Boolean is
begin
return not ((Nkind (Parent (Node)) = N_Expanded_Name or else
Nkind (Parent (Node)) = N_Selected_Component)
and then
(Nkind (Parent (Parent (Node))) = N_Expanded_Name or else
Nkind (Parent (Parent (Node))) = N_Selected_Component));
end Last_Selector;
function Is_Enumeration_Literal (Node : Node_Id) return Boolean is
Entity_Node : Node_Id := Empty;
begin
Entity_Node := Entity (Node);
if No (Entity_Node) then
Entity_Node := Original_Node (Parent (Node));
if Nkind (Entity_Node) = N_Function_Call then
-- this may be the case for an expanded name which is a reference
-- to an overloaded enumeration literal
Entity_Node := Sinfo.Name (Entity_Node);
end if;
if Nkind (Entity_Node) in N_Has_Entity then
Entity_Node := Entity (Entity_Node);
end if;
end if;
if Nkind (Entity_Node) in N_Entity and then
Ekind (Entity_Node) = E_Enumeration_Literal
then
return True;
else
return False;
end if;
end Is_Enumeration_Literal;
function Selector
(Expression : Asis.Expression)
return Asis.Expression
is
Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Expression);
Arg_Node : Node_Id;
Result_Node : Node_Id;
Result_Kind : Internal_Element_Kinds;
begin
Check_Validity (Expression, Package_Name & "Selector");
if not (Arg_Kind = A_Selected_Component) then
Raise_ASIS_Inappropriate_Element
(Diagnosis => Package_Name & "Selector",
Wrong_Kind => Arg_Kind);
end if;
Arg_Node := Node (Expression);
Result_Node := Selector_Name (Arg_Node);
if not (Nkind (Result_Node) = N_Identifier) then
return Node_To_Element_New (Node => Result_Node,
Starting_Element => Expression);
end if;
if Last_Selector (Result_Node) and then
Is_Enumeration_Literal (Result_Node)
then
Result_Kind := An_Enumeration_Literal;
else
Result_Kind := An_Identifier;
end if;
return Node_To_Element_New (Node => Result_Node,
Internal_Kind => Result_Kind,
Starting_Element => Expression);
exception
when ASIS_Inappropriate_Element =>
raise;
when ASIS_Failed =>
if Status_Indicator = Unhandled_Exception_Error then
Add_Call_Information
(Argument => Expression,
Outer_Call => Package_Name & "Selector");
end if;
raise;
when Ex : others =>
Report_ASIS_Bug
(Query_Name => Package_Name & "Selector",
Ex => Ex,
Arg_Element => Expression);
end Selector;
-----------------------------------------------------------------------------
function Attribute_Designator_Identifier
(Expression : Asis.Expression)
return Asis.Expression
is
Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Expression);
Result : Asis.Element := Nil_Element;
begin
Check_Validity
(Expression, Package_Name & "Attribute_Designator_Identifier");
if not (Arg_Kind in Internal_Attribute_Reference_Kinds) then
Raise_ASIS_Inappropriate_Element
(Diagnosis => Package_Name & "Attribute_Designator_Identifier",
Wrong_Kind => Arg_Kind);
end if;
-- Attribute designator is based on the same node as the argument of
-- the function, this is a special case of identifier handling!!!
Result := Node_To_Element_New
(Starting_Element => Expression,
Node => R_Node (Expression),
Internal_Kind => An_Identifier);
if Represents_Class_Wide_Type_In_Instance (Node (Expression))
-- See F410-011
or else
Nkind (Parent (R_Node (Expression))) = N_Aspect_Specification
then
Set_Special_Case (Result, Dummy_Class_Attribute_Designator);
elsif Represents_Base_Type_In_Instance ((Node (Expression))) then
Set_Special_Case (Result, Dummy_Base_Attribute_Designator);
end if;
return Result;
exception
when ASIS_Inappropriate_Element =>
raise;
when ASIS_Failed =>
if Status_Indicator = Unhandled_Exception_Error then
Add_Call_Information
(Argument => Expression,
Outer_Call => Package_Name & "Attribute_Designator_Identifier");
end if;
raise;
when Ex : others =>
Report_ASIS_Bug
(Query_Name => Package_Name & "Attribute_Designator_Identifier",
Ex => Ex,
Arg_Element => Expression);
end Attribute_Designator_Identifier;
-----------------------------------------------------------------------------
function Attribute_Designator_Expressions
(Expression : Asis.Expression)
return Asis.Expression_List
is
Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Expression);
Arg_Node : Node_Id;
begin
Check_Validity
(Expression, Package_Name & "Attribute_Designator_Expressions");
if not (Arg_Kind = A_First_Attribute or else
Arg_Kind = A_Last_Attribute or else
Arg_Kind = A_Length_Attribute or else
Arg_Kind = A_Range_Attribute or else
Arg_Kind = An_Implementation_Defined_Attribute or else
Arg_Kind = An_Unknown_Attribute)
then
Raise_ASIS_Inappropriate_Element
(Diagnosis => Package_Name & "Attribute_Designator_Expressions",
Wrong_Kind => Arg_Kind);
end if;
Arg_Node := Node (Expression);
if Nkind (Arg_Node) = N_Attribute_Definition_Clause or else
Is_GNAT_Attribute_Routine (Arg_Node)
then
return Nil_Element_List;
-- just in case - for an implementation-defined attribute in an
-- attribute definition clause
end if;
if Debug_Flag_1 then
Write_Str ("Attribute_Designator_Expressions: Arg_Node:");
Write_Eol;
Write_Node (Arg_Node, "->");
Write_Eol;
end if;
return N_To_E_List_New
(List => Sinfo.Expressions (Arg_Node),
Starting_Element => Expression);
exception
when ASIS_Inappropriate_Element =>
raise;
when ASIS_Failed =>
if Status_Indicator = Unhandled_Exception_Error then
Add_Call_Information
(Argument => Expression,
Outer_Call => Package_Name &
"Attribute_Designator_Expressions");
end if;
raise;
when Ex : others =>
Report_ASIS_Bug
(Query_Name => Package_Name & "Attribute_Designator_Expressions",
Ex => Ex,
Arg_Element => Expression);
end Attribute_Designator_Expressions;
------------------------------------------------------------------------------
function Record_Component_Associations
(Expression : Asis.Expression;
Normalized : Boolean := False)
return Asis.Association_List
is
Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Expression);
Arg_Node : Node_Id;
Returned_List_Length : ASIS_Integer;
Positional_List_Length : Int;
Named_List_Length : Int;
begin
Check_Validity
(Expression, Package_Name & "Record_Component_Associations");
if not (Arg_Kind = A_Record_Aggregate or else
Arg_Kind = An_Extension_Aggregate)
then
Raise_ASIS_Inappropriate_Element
(Diagnosis => Package_Name & "Record_Component_Associations",
Wrong_Kind => Arg_Kind);
end if;
Arg_Node := Node (Expression);
if Null_Record_Present (Arg_Node) then
return Nil_Element_List;
end if;
if Normalized then
return Normalized_Record_Component_Associations (Expression);
end if;
-- computing the returned list length:
if Present (Sinfo.Expressions (Arg_Node)) then
Positional_List_Length := List_Length (Sinfo.Expressions (Arg_Node));
else
Positional_List_Length := 0;
end if;
if Present (Component_Associations (Arg_Node)) then
Named_List_Length := List_Length (Component_Associations (Arg_Node));
else
Named_List_Length := 0;
end if;
Returned_List_Length :=
ASIS_Integer (Positional_List_Length + Named_List_Length);
-- Returned_List_Length cannot be equal to 0 here!
declare -- for proper exception handling
Returned_List : Asis.Association_List (1 .. Returned_List_Length);
begin
-- obtaining the association list:
if Debug_Flag_1 then
Write_Str ("obtaining the association list");
Write_Eol;
Write_Str ("List length is ");
Write_Int (Int (Returned_List_Length));
Write_Eol;
end if;
Returned_List :=
N_To_E_List_New
(List => Sinfo.Expressions (Arg_Node),
Internal_Kind => A_Record_Component_Association,
Starting_Element => Expression)
&
N_To_E_List_New
(List => Component_Associations (Arg_Node),
Internal_Kind => A_Record_Component_Association,
Starting_Element => Expression);
return Returned_List;
end;
exception
when ASIS_Inappropriate_Element =>
raise;
when ASIS_Failed =>
if Status_Indicator = Unhandled_Exception_Error then
Add_Call_Information
(Argument => Expression,
Bool_Par => Normalized,
Outer_Call => Package_Name & "Record_Component_Associations");
end if;
raise;
when Ex : others =>
Report_ASIS_Bug
(Query_Name => Package_Name & "Record_Component_Associations",
Ex => Ex,
Arg_Element => Expression,
Bool_Par_ON => Normalized);
end Record_Component_Associations;
-----------------------------------------------------------------------------
function Extension_Aggregate_Expression
(Expression : Asis.Expression)
return Asis.Expression
is
Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Expression);
Arg_Node : Node_Id;
begin
Check_Validity
(Expression, Package_Name & "Extension_Aggregate_Expression");
if not (Arg_Kind = An_Extension_Aggregate) then
Raise_ASIS_Inappropriate_Element
(Diagnosis => Package_Name & "Extension_Aggregate_Expression",
Wrong_Kind => Arg_Kind);
end if;
Arg_Node := Node (Expression);
return Node_To_Element_New
(Node => Ancestor_Part (Arg_Node),
Starting_Element => Expression);
exception
when ASIS_Inappropriate_Element =>
raise;
when ASIS_Failed =>
if Status_Indicator = Unhandled_Exception_Error then
Add_Call_Information
(Argument => Expression,
Outer_Call => Package_Name & "Extension_Aggregate_Expression");
end if;
raise;
when Ex : others =>
Report_ASIS_Bug
(Query_Name => Package_Name & "Extension_Aggregate_Expression",
Ex => Ex,
Arg_Element => Expression);
end Extension_Aggregate_Expression;
-----------------------------------------------------------------------------
function Array_Component_Associations
(Expression : Asis.Expression)
return Asis.Association_List
is
Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Expression);
Arg_Node : Node_Id;
Named_Associations : List_Id;
Pos_Associations : List_Id;
begin
Check_Validity
(Expression, Package_Name & "Array_Component_Associations");
if not (Arg_Kind = A_Positional_Array_Aggregate or else
Arg_Kind = A_Named_Array_Aggregate)
then
Raise_ASIS_Inappropriate_Element
(Diagnosis => Package_Name & "Array_Component_Associations",
Wrong_Kind => Arg_Kind);
end if;
Arg_Node := Node (Expression);
Named_Associations := Component_Associations (Arg_Node);
Pos_Associations := Sinfo.Expressions (Arg_Node);
if Arg_Kind = A_Named_Array_Aggregate then
return N_To_E_List_New
(List => Named_Associations,
Internal_Kind => An_Array_Component_Association,
Starting_Element => Expression);
elsif No (Named_Associations) then
-- that is, no "others" choice in a positional array aggregate
return N_To_E_List_New
(List => Pos_Associations,
Internal_Kind => An_Array_Component_Association,
Starting_Element => Expression);
else
-- a positional array aggregate with "others"
return (N_To_E_List_New
(List => Pos_Associations,
Internal_Kind => An_Array_Component_Association,
Starting_Element => Expression)
&
Node_To_Element_New
(Node => First (Named_Associations),
Internal_Kind => An_Array_Component_Association,
Starting_Element => Expression));
end if;
exception
when ASIS_Inappropriate_Element =>
raise;
when ASIS_Failed =>
if Status_Indicator = Unhandled_Exception_Error then
Add_Call_Information
(Argument => Expression,
Outer_Call => Package_Name & "Array_Component_Associations");
end if;
raise;
when Ex : others =>
Report_ASIS_Bug
(Query_Name => Package_Name & "Array_Component_Associations",
Ex => Ex,
Arg_Element => Expression);
end Array_Component_Associations;
-----------------------------------------------------------------------------
function Array_Component_Choices
(Association : Asis.Association)
return Asis.Expression_List
is
Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Association);
Arg_Node : Node_Id;
begin
Check_Validity (Association, Package_Name & "Array_Component_Choices");
if not (Arg_Kind = An_Array_Component_Association) then
Raise_ASIS_Inappropriate_Element
(Diagnosis => Package_Name & "Array_Component_Choices",
Wrong_Kind => Arg_Kind);
end if;
Arg_Node := Node (Association);
if Nkind (Arg_Node) = N_Component_Association then
-- named association
return Discrete_Choice_Node_To_Element_List
(Choice_List => Choices (Arg_Node),
Starting_Element => Association);
else
-- positional association
return Nil_Element_List;
end if;
exception
when ASIS_Inappropriate_Element =>
raise;
when ASIS_Failed =>
if Status_Indicator = Unhandled_Exception_Error then
Add_Call_Information
(Argument => Association,
Outer_Call => Package_Name & "Array_Component_Choices");
end if;
raise;
when Ex : others =>
Report_ASIS_Bug
(Query_Name => Package_Name & "Array_Component_Choices",
Ex => Ex,
Arg_Element => Association);
end Array_Component_Choices;
-----------------------------------------------------------------------------
function Record_Component_Choices
(Association : Asis.Association)
return Asis.Expression_List
is
Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Association);
Arg_Node : Node_Id;
Result_Node : Node_Id;
Temp_Node : Node_Id;
Result_Unit : Asis.Compilation_Unit;
Result_Element : Asis.Element;
-- for handling the normalized A_Record_Component_Association only
begin
Check_Validity (Association, Package_Name & "Record_Component_Choices");
if not (Arg_Kind = A_Record_Component_Association) then
Raise_ASIS_Inappropriate_Element
(Diagnosis => Package_Name & "Record_Component_Choices",
Wrong_Kind => Arg_Kind);
end if;
Arg_Node := Node (Association);
if Normalization_Case (Association) = Is_Normalized then
-- it is definitely A_Record_Component_Association
-- based on the N_Component_Association Node
-- and the returned list should definitely contain exactly one
-- component of A_Defining_Name kind, which should not
-- test as Is_Normalized
--
-- Note, that if the argument Is_Normalized, its Node and R_Node
-- fields are the same
Result_Node :=
Original_Record_Component (Entity (First (Choices (Arg_Node))));
Result_Unit :=
Enclosing_Unit (Encl_Cont_Id (Association), Result_Node);
Result_Element := Node_To_Element_New
(Starting_Element => Association,
Node => Result_Node,
Internal_Kind => A_Defining_Identifier,
In_Unit => Result_Unit);
-- And now we have to correct some fields in Result_Element.
-- First, Association Is_Normalized, but its components are
-- not Is_Normalized. Therefore
Set_Special_Case (Result_Element, Not_A_Special_Case);
-- Then, we should check whether or not Result_Element represents
-- the implicit inherited component of some derived type
-- The idea (based on the tree structure of 3.05) is to go from
-- Result_Node up to the corresponding full type declaration,
-- then one step down to the type defining identifier and then
-- to check if it Is_Internal
Temp_Node := Parent (Parent (Result_Node));
-- this Parent (Parent) gives us either N_Component_List node
-- (if Result_Node corresponds to a record component) or
-- N_Full_Type_Declaration node (if Result_Node corresponds to a
-- discriminant). In the former case we have to apply Parent
-- twice more to go to a N_Full_Type_Declaration node
if Nkind (Temp_Node) = N_Component_List then
Temp_Node := Parent (Parent (Temp_Node));
end if;
-- and now - the test and the related corrections if the test
-- is successful:
if Nkind (Temp_Node) = N_Full_Type_Declaration then
-- if Result_Node corresponds to a record component from a record
-- extension part, we should be in N_Derived_Type_Definition
-- node here, and we have nothing to correct in Result_Element
-- in that case
Temp_Node := Defining_Identifier (Temp_Node);
if Is_Internal (Temp_Node) then
Set_From_Implicit (Result_Element);
Set_From_Inherited (Result_Element);
end if;
end if;
return (1 => Result_Element);
end if;
-- processing a non-normalized association:
if Nkind (Arg_Node) = N_Component_Association then
return N_To_E_List_New
(List => Choices (Arg_Node),
Starting_Element => Association);
else
return Nil_Element_List;
-- what else can we get from a positional association?
end if;
exception
when ASIS_Inappropriate_Element =>
raise;
when ASIS_Failed =>
if Status_Indicator = Unhandled_Exception_Error then
Add_Call_Information
(Argument => Association,
Outer_Call => Package_Name & "Record_Component_Choices");
end if;
raise;
when Ex : others =>
Report_ASIS_Bug
(Query_Name => Package_Name & "Record_Component_Choices",
Ex => Ex,
Arg_Element => Association);
end Record_Component_Choices;
-----------------------------------------------------------------------------
function Component_Expression
(Association : Asis.Association)
return Asis.Expression
is
Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Association);
Arg_Node : Node_Id;
Returned_Element : Element;
Result_Node : Node_Id;
Result_Kind : Internal_Element_Kinds := Not_An_Element;
Temp_Node : Node_Id;
Norm_Expr_Sloc : Source_Ptr;
begin
Check_Validity (Association, Package_Name & "Component_Expression");
if not (Arg_Kind = A_Record_Component_Association or else
Arg_Kind = An_Array_Component_Association)
then
Raise_ASIS_Inappropriate_Element
(Diagnosis => Package_Name & "Component_Expression",
Wrong_Kind => Arg_Kind);
end if;
Arg_Node := Node (Association);
-- ??? May be, we have to use R_Node here???
if Normalization_Case (Association) = Is_Normalized then
-- the idea of the implementation is: to go up to the
-- (rewritten!) N_Aggregate node, then to go to the corresponding
-- expression in the corresponding non-normalized association
-- through the original aggregate node. The corresponding
-- expression is the expression having the same Sloc value
-- (we are traversing the same tree all the time, so we do not
-- need relative Slocs.
--
-- It may look a bit crazy - why do not we use the expression
-- subtree from the rewritten aggregate. At least one reason is
-- that some details of the original expression structure are
-- lost in the rewritten aggregate as a result of compile-time
-- optimizations of static expressions
Result_Node := Parent (Arg_Node);
-- here we are in the rewritten aggregate node. Now coming to its
-- original node:
Result_Node := Original_Node (Result_Node);
-- and now - trying to find the corresponding expression:
Norm_Expr_Sloc := Sloc (Sinfo.Expression (Arg_Node));
if Present (Sinfo.Expressions (Result_Node)) then
-- starting from positional associations, if any:
Temp_Node := First (Sinfo.Expressions (Result_Node));
while Present (Temp_Node) loop
if Sloc (Temp_Node) = Norm_Expr_Sloc then
Result_Node := Temp_Node;
goto Find;
end if;
Temp_Node := Next (Temp_Node);
end loop;
end if;
if Present (Component_Associations (Result_Node)) then
Temp_Node := First (Component_Associations (Result_Node));
while Present (Temp_Node) loop
if Sloc (Sinfo.Expression (Temp_Node)) = Norm_Expr_Sloc then
Result_Node := (Sinfo.Expression (Temp_Node));
goto Find;
end if;
Temp_Node := Next (Temp_Node);
end loop;
end if;
<<Find>>
if Nkind (Result_Node) = N_Aggregate then
-- This means, that there is some error in the implementation,
-- or the tree structure has been changed, and it does not
-- correspond to this implementation approach any more
raise Internal_Implementation_Error;
end if;
Returned_Element := Node_To_Element_New
(Starting_Element => Association,
Node => Result_Node);
-- And now we have to correct the Result_Element before returning
-- it. Association Is_Normalized, but its components are
-- not Is_Normalized. Therefore
Set_Special_Case (Returned_Element, Not_A_Special_Case);
return Returned_Element;
else
-- processing non-normalized A_Record_Component_Association or
-- An_Array_Component_Association
if Nkind (Arg_Node) = N_Component_Association then
Result_Node := Sinfo.Expression (Arg_Node);
else
Result_Node := R_Node (Association);
end if;
if Special_Case (Association) = Rewritten_Named_Number then
Result_Kind := An_Identifier;
end if;
return Node_To_Element_New (Node => Result_Node,
Internal_Kind => Result_Kind,
Starting_Element => Association);
end if;
exception
when ASIS_Inappropriate_Element =>
raise;
when ASIS_Failed =>
if Status_Indicator = Unhandled_Exception_Error then
Add_Call_Information
(Argument => Association,
Outer_Call => Package_Name & "Component_Expression");
end if;
raise;
when Ex : others =>
Report_ASIS_Bug
(Query_Name => Package_Name & "Component_Expression",
Ex => Ex,
Arg_Element => Association);
end Component_Expression;
------------------------------------------------------------------------------
-- PARTIALLY IMPLEMENTED, CANNOT HANDLE THE NORMALIZED ARGUMENT
-- ??? NEEDS REVISING BADLY!!!
function Formal_Parameter
(Association : Asis.Association)
return Asis.Element
is
Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Association);
Arg_Node : Node_Id;
Result_Node : Node_Id;
Result_Unit : Compilation_Unit;
Result_Kind : Internal_Element_Kinds := An_Identifier;
Is_Iherited : Boolean := False;
Subprogram_Entity : Entity_Id := Empty;
Nil_To_Be_Returned : Boolean := False;
begin
Check_Validity (Association, Package_Name & "Formal_Parameter");
if not (Arg_Kind = A_Parameter_Association or else
Arg_Kind = A_Generic_Association or else
Arg_Kind = A_Pragma_Argument_Association)
then
Raise_ASIS_Inappropriate_Element
(Diagnosis => Package_Name & "Formal_Parameter",
Wrong_Kind => Arg_Kind);
end if;
Arg_Node := Node (Association);
if Normalization_Case (Association) in Normalized_Association then
if Arg_Kind = A_Generic_Association
or else
Arg_Kind = A_Parameter_Association
then
-- see the documentation for the body of
-- Norm.Normalized_Generic_Associations:
Result_Node := Arg_Node;
if Nkind (Result_Node) = N_Defining_Identifier then
Result_Kind := A_Defining_Identifier;
else
Result_Kind := Not_An_Element;
-- In this case Result_Kind should be detected
-- automatically
end if;
Subprogram_Entity := Node_Field_1 (Association);
Is_Iherited := Present (Subprogram_Entity);
Result_Unit :=
Enclosing_Unit (Encl_Cont_Id (Association), Result_Node);
return Node_To_Element_New (Node => Result_Node,
Internal_Kind => Result_Kind,
Node_Field_1 => Subprogram_Entity,
Inherited => Is_Iherited,
In_Unit => Result_Unit);
else
Not_Implemented_Yet (Diagnosis =>
Package_Name & "Formal_Parameter: "
& ASIS_Line_Terminator
& " Cannot handle the NORMALIZED parameter association");
end if;
else
if Arg_Kind = A_Parameter_Association then
if not (Nkind (Arg_Node) = N_Parameter_Association) then
-- positional (non-normalized) association
Nil_To_Be_Returned := True;
else
Result_Node := Selector_Name (Arg_Node);
end if;
elsif Arg_Kind = A_Generic_Association then
if Nkind (Arg_Node) = N_Others_Choice then
Result_Kind := An_Others_Choice;
Result_Node := Arg_Node;
-- For the rest of IF paths
-- Arg_Node_Kind = N_Generic_Association
-- is always True
elsif No (Selector_Name (Arg_Node)) then
-- positional (non-normalized) association
Nil_To_Be_Returned := True;
else
Result_Node := Selector_Name (Arg_Node);
if Nkind (Result_Node) = N_Operator_Symbol then
Result_Kind := Not_An_Element;
-- In this case Result_Kind should be detected
-- automatically
end if;
end if;
else -- Arg_Kind = A_Pragma_Argument_Association
-- special treatment by an identifier in the tree
if Chars (Arg_Node) = No_Name then
-- no pragma argument identifier
Nil_To_Be_Returned := True;
else
Result_Node := Arg_Node;
end if;
end if;
if Nil_To_Be_Returned then
return Nil_Element;
else
return Node_To_Element_New (
Node => Result_Node,
Internal_Kind => Result_Kind,
Starting_Element => Association);
end if;
end if;
exception
when ASIS_Inappropriate_Element =>
raise;
when ASIS_Failed =>
if Status_Indicator = Unhandled_Exception_Error then
Add_Call_Information
(Argument => Association,
Outer_Call => Package_Name & "Formal_Parameter");
end if;
raise;
when Ex : others =>
Report_ASIS_Bug
(Query_Name => Package_Name & "Formal_Parameter",
Ex => Ex,
Arg_Element => Association);
end Formal_Parameter;
------------------------------------------------------------------------------
function Actual_Parameter
(Association : Asis.Association)
return Asis.Expression
is
Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Association);
Arg_Node : Node_Id;
Result_Node : Node_Id;
Result_Kind : Internal_Element_Kinds := Not_An_Element;
Result_Norm_Case : Normalization_Cases := Is_Not_Normalized;
Result_Spec_Case : Special_Cases := Not_A_Special_Case;
Result_Unit : Compilation_Unit;
Pragma_Chars : Name_Id;
Is_Inherited : Boolean := False;
Subprogram_Entity : Entity_Id := Empty;
Result : Asis.Element;
begin
Check_Validity (Association, Package_Name & "Actual_Parameter");
if not (Arg_Kind = A_Parameter_Association or else
Arg_Kind = A_Generic_Association or else
Arg_Kind = A_Pragma_Argument_Association)
then
Raise_ASIS_Inappropriate_Element
(Diagnosis => Package_Name & "Actual_Parameter",
Wrong_Kind => Arg_Kind);
end if;
Arg_Node := Node (Association);
if Normalization_Case (Association) in Normalized_Association then
if Arg_Kind = A_Generic_Association
or else
Arg_Kind = A_Parameter_Association
then
-- see the documentation for the body of
-- Norm.Normalized_Generic_Associations:
Result_Node := Node_Field_2 (Association);
if Normalization_Case (Association) = Is_Normalized_Defaulted then
-- the actual parameter is taken by default from the
-- declaration of the corresponding formal, it may be
-- in another Compilation Unit
Result_Unit :=
Enclosing_Unit (Encl_Cont_Id (Association), Result_Node);
else
Result_Unit := Encl_Unit (Association);
end if;
-- in case of the default defined at the place of
-- an instantiation for A_Box_Default; we will keep
-- Special_Case equal to Is_Normalized_Defaulted_For_Box
-- (just in case).
if Normalization_Case (Association) =
Is_Normalized_Defaulted_For_Box
then
Result_Norm_Case := Is_Normalized_Defaulted_For_Box;
end if;
if Normalization_Case (Association) = Is_Normalized
and then
Arg_Kind = A_Generic_Association
then
Result_Spec_Case := Is_From_Gen_Association;
end if;
if Is_Defaulted_Association (Association) then
Subprogram_Entity := Node_Field_1 (Association);
Is_Inherited := Present (Subprogram_Entity);
end if;
-- See FB27-003 - we need a special processing for the
-- case when we have an attribute passed as an actual for a
-- formal subprogram
if Arg_Kind = A_Generic_Association
and then
Nkind (Result_Node) = N_Attribute_Reference
and then
Nkind (Original_Node (Parent (Result_Node))) =
N_Subprogram_Renaming_Declaration
then
Result_Kind := Subprogram_Attribute_Kind (Result_Node);
end if;
Result := Node_To_Element_New (Node => Result_Node,
Norm_Case => Result_Norm_Case,
Spec_Case => Result_Spec_Case,
Node_Field_1 => Subprogram_Entity,
Inherited => Is_Inherited,
Internal_Kind => Result_Kind,
In_Unit => Result_Unit);
-- If we have an actual corresponding to
-- Is_Normalized_Defaulted_For_Box, we may have to correct
-- Is_Part_Of_Instance of the result. The corresponding naming
-- expression is taken from the artificial renaming, so
-- it in any case is classified as being from instance. But
-- for this particular case of getting actual from normalized
-- association we should check that not the result node, but the
-- corresponding instantiation is from instance, that is, that the
-- instantiation chain has at least three elements. Another
-- possibility to check this is to check if the corresponding
-- instantiation is from instance
if (Result_Norm_Case = Is_Normalized_Defaulted_For_Box
or else
Result_Spec_Case = Is_From_Gen_Association)
and then
not Is_From_Instance (Enclosing_Element (Association))
then
Set_From_Instance (Result, False);
end if;
else
Not_Implemented_Yet (Diagnosis =>
Package_Name & "Actual_Parameter: "
& ASIS_Line_Terminator
& " Cannot handle the NORMALIZED parameter association");
end if;
else
if Arg_Kind = A_Parameter_Association then
if not (Nkind (Arg_Node) = N_Parameter_Association) then
-- positional (non-normalized) association
Result_Node := R_Node (Association);
if Nkind (Result_Node) = N_Unchecked_Type_Conversion then
-- Sometimes the front-end creates a "wrapper"
-- N_Unchecked_Type_Conversion structures for calls from
-- RTL, see E622-015 and the corresponding note in
-- Function_Call_Parameters
Result_Node := Sinfo.Expression (Result_Node);
end if;
else
Result_Node := Explicit_Actual_Parameter (Arg_Node);
end if;
elsif Arg_Kind = A_Generic_Association then
if Nkind (Arg_Node) = N_Others_Choice then
return Nil_Element;
else
-- NKind (Arg_Node) = N_Generic_Association is always True
Result_Spec_Case := Is_From_Gen_Association;
Result_Node := Explicit_Generic_Actual_Parameter (Arg_Node);
-- See FB27-003 - we need a special processing for the
-- case when we have an attribute passed as an actual for a
-- formal subprogram
if Nkind (Result_Node) = N_Attribute_Reference
and then
Nkind (Original_Node (Parent (Result_Node))) =
N_Subprogram_Renaming_Declaration
then
Result_Kind := Subprogram_Attribute_Kind (Result_Node);
end if;
end if;
else
-- Arg_Kind = A_Pragma_Argument_Association
-- Special processing is needed for a Debug pragma:
Pragma_Chars := Pragma_Name (Original_Node (Parent (Arg_Node)));
if Pragma_Chars = Name_Debug then
-- We have to use the rewritten tree structures here, because
-- in the original structures the procedure call in pragma
-- Debug is not decorated. The problem with the rewritten
-- structure is that it is an IF statement with block statement
-- with procedure call from the Debug pragma as its statement
-- sequence.
Result_Node := Parent (Arg_Node);
Result_Node := First (Then_Statements (Result_Node));
Result_Node :=
First (Sinfo.Statements
(Handled_Statement_Sequence (Result_Node)));
while Nkind (Result_Node) /= N_Procedure_Call_Statement loop
Result_Node := Next (Result_Node);
end loop;
Result_Kind := A_Function_Call;
else
Result_Node := Sinfo.Expression (Arg_Node);
end if;
end if;
Result := Node_To_Element_New (Node => Result_Node,
Starting_Element => Association,
Spec_Case => Result_Spec_Case,
Internal_Kind => Result_Kind);
end if;
return Result;
exception
when ASIS_Inappropriate_Element =>
raise;
when ASIS_Failed =>
if Status_Indicator = Unhandled_Exception_Error then
Add_Call_Information
(Argument => Association,
Outer_Call => Package_Name & "Actual_Parameter");
end if;
raise;
when Ex : others =>
Report_ASIS_Bug
(Query_Name => Package_Name & "Actual_Parameter",
Ex => Ex,
Arg_Element => Association);
end Actual_Parameter;
------------------------------------------------------------------------------
-- PARTIALLY IMPLEMENTED, CANNOT HANDLE THE NORMALIZED ARGUMENT
function Discriminant_Selector_Names
(Association : Asis.Discriminant_Association)
return Asis.Expression_List
is
Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Association);
Arg_Node : Node_Id;
begin
Check_Validity
(Association, Package_Name & "Discriminant_Selector_Names");
if not (Arg_Kind = A_Discriminant_Association) then
Raise_ASIS_Inappropriate_Element
(Diagnosis => Package_Name & "Discriminant_Selector_Names",
Wrong_Kind => Arg_Kind);
end if;
Arg_Node := Node (Association);
if Normalization_Case (Association) = Is_Normalized then
return (1 => Discr_Def_Name (Association));
else
if not (Nkind (Arg_Node) = N_Discriminant_Association) then
-- positional association
return Nil_Element_List;
else
return N_To_E_List_New
(List => Selector_Names (Arg_Node),
Internal_Kind => An_Identifier,
Starting_Element => Association);
end if;
end if;
exception
when ASIS_Inappropriate_Element =>
raise;
when ASIS_Failed =>
if Status_Indicator = Unhandled_Exception_Error then
Add_Call_Information
(Argument => Association,
Outer_Call => Package_Name & "Discriminant_Selector_Names");
end if;
raise;
when Ex : others =>
Report_ASIS_Bug
(Query_Name => Package_Name & "Discriminant_Selector_Names",
Ex => Ex,
Arg_Element => Association);
end Discriminant_Selector_Names;
-----------------------------
-- Discriminant_Expression --
-----------------------------
function Discriminant_Expression
(Association : Asis.Discriminant_Association)
return Asis.Expression
is
Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Association);
Arg_Node : Node_Id;
begin
Check_Validity (Association, Package_Name & "Discriminant_Expression");
if not (Arg_Kind = A_Discriminant_Association) then
Raise_ASIS_Inappropriate_Element
(Diagnosis => Package_Name & "Discriminant_Expression",
Wrong_Kind => Arg_Kind);
end if;
Arg_Node := R_Node (Association);
if Nkind (Arg_Node) = N_Discriminant_Association then
-- named association
return Node_To_Element_New (
Node => Sinfo.Expression (Arg_Node),
Starting_Element => Association);
else
-- positional or normalized association
return Node_To_Element_New (
Node => Arg_Node,
Starting_Element => Association);
end if;
exception
when ASIS_Inappropriate_Element =>
raise;
when ASIS_Failed =>
if Status_Indicator = Unhandled_Exception_Error then
Add_Call_Information
(Argument => Association,
Outer_Call => Package_Name & "Discriminant_Expression");
end if;
raise;
when Ex : others =>
Report_ASIS_Bug
(Query_Name => Package_Name & "Discriminant_Expression",
Ex => Ex,
Arg_Element => Association);
end Discriminant_Expression;
-----------------------------------------------------------------------------
function Is_Normalized (Association : Asis.Association) return Boolean is
Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Association);
Norm_Case : Normalization_Cases;
begin
Check_Validity (Association, Package_Name & "Is_Normalized");
if not (Arg_Kind = A_Discriminant_Association or else
Arg_Kind = A_Record_Component_Association or else
Arg_Kind = A_Parameter_Association or else
Arg_Kind = A_Generic_Association)
then
return False;
else
Norm_Case := Normalization_Case (Association);
return Norm_Case in Normalized_Association;
end if;
end Is_Normalized;
-----------------------------------------------------------------------------
function Is_Defaulted_Association
(Association : Asis.Element)
return Boolean
is
Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Association);
Norm_Case : Normalization_Cases;
begin
Check_Validity (Association, Package_Name & "Is_Defaulted_Association");
if not (Arg_Kind = A_Parameter_Association or else
Arg_Kind = A_Generic_Association)
then
return False;
else
Norm_Case := Normalization_Case (Association);
return Norm_Case in Defaulted_Association;
end if;
end Is_Defaulted_Association;
------------------------------------------------------------------------------
function Expression_Parenthesized
(Expression : Asis.Expression)
return Asis.Expression
is
Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Expression);
Res_Parenth_Count : Nat;
Result : Asis.Expression;
begin
Check_Validity (Expression, Package_Name & "Expression_Parenthesized");
if not (Arg_Kind = A_Parenthesized_Expression) then
Raise_ASIS_Inappropriate_Element
(Diagnosis => Package_Name & "Expression_Parenthesized",
Wrong_Kind => Arg_Kind);
end if;
Res_Parenth_Count := Parenth_Count (Expression) - 1;
if Res_Parenth_Count = 0 then
-- Returning unparenthesized expression
Result := Node_To_Element_New
(Node => R_Node (Expression),
Considering_Parent_Count => False,
Starting_Element => Expression);
else
-- Cut away one level of parentheses
Result := Expression;
Set_Parenth_Count (Result, Res_Parenth_Count);
end if;
return Result;
exception
when ASIS_Inappropriate_Element =>
raise;
when ASIS_Failed =>
if Status_Indicator = Unhandled_Exception_Error then
Add_Call_Information
(Argument => Expression,
Outer_Call => Package_Name & "Expression_Parenthesized");
end if;
raise;
when Ex : others =>
Report_ASIS_Bug
(Query_Name => Package_Name & "Expression_Parenthesized",
Ex => Ex,
Arg_Element => Expression);
end Expression_Parenthesized;
-----------------------------------------------------------------------------
function Is_Prefix_Call (Expression : Asis.Expression) return Boolean is
Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Expression);
Arg_Node : Node_Id;
begin
Check_Validity (Expression, Package_Name & "Is_Prefix_Call");
if Arg_Kind /= A_Function_Call then
return False;
end if;
Arg_Node := Node (Expression);
if (Nkind (Arg_Node) = N_Identifier or else
Nkind (Arg_Node) = N_Expanded_Name)
and then
-- Special case: F.A, where either F or A is a function call
Nkind (R_Node (Expression)) = N_Function_Call
then
Arg_Node := R_Node (Expression);
end if;
if Nkind (Arg_Node) = N_Attribute_Reference or else
Nkind (Arg_Node) = N_Procedure_Call_Statement
then
-- N_Procedure_Call_Statement corresponds to the argument of
-- Debug pragma
return True;
elsif Nkind (Arg_Node) = N_Identifier then
-- Special case: F.A , where F - parameterless function returning
-- a record type
return True;
elsif not (Nkind (Arg_Node) = N_Function_Call) then
return False;
else
return Nkind (Sinfo.Name (Arg_Node)) /= N_Identifier
or else
Chars (Sinfo.Name (Arg_Node)) not in Any_Operator_Name;
end if;
exception
when ASIS_Inappropriate_Element =>
raise;
when ASIS_Failed =>
if Status_Indicator = Unhandled_Exception_Error then
Add_Call_Information
(Argument => Expression,
Outer_Call => Package_Name & "Is_Prefix_Call");
end if;
raise;
when Ex : others =>
Report_ASIS_Bug
(Query_Name => Package_Name & "Is_Prefix_Call",
Ex => Ex,
Arg_Element => Expression);
end Is_Prefix_Call;
-----------------------------------------------------------------------------
function Corresponding_Called_Function
(Expression : Asis.Expression)
return Asis.Declaration
is
Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Expression);
begin
Check_Validity
(Expression, Package_Name & "Corresponding_Called_Function");
if not (Arg_Kind = A_Function_Call) then
Raise_ASIS_Inappropriate_Element
(Diagnosis => Package_Name & "Corresponding_Called_Function",
Wrong_Kind => Arg_Kind);
end if;
return Get_Corr_Called_Entity (Expression);
exception
when ASIS_Inappropriate_Element =>
raise;
when ASIS_Failed =>
if Status_Indicator = Unhandled_Exception_Error then
Add_Call_Information
(Argument => Expression,
Outer_Call => Package_Name & "Corresponding_Called_Function");
end if;
raise;
when Ex : others =>
Report_ASIS_Bug
(Query_Name => Package_Name & "Corresponding_Called_Function",
Ex => Ex,
Arg_Element => Expression);
end Corresponding_Called_Function;
------------------------------------------------------------------------------
function Function_Call_Parameters
(Expression : Asis.Expression;
Normalized : Boolean := False)
return Asis.Association_List
is
Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Expression);
Arg_Node : Node_Id;
Tmp_El : Asis.Element;
Function_Call_Node : Node_Id;
Func_Call_Or_Node : Node_Id;
Function_Call_Node_Kind : Node_Kind;
Association_Node_List : List_Id;
Infix_Operands : Asis.Association_List (1 .. 2);
begin
-- !!! In case if Normalized is set ON, we return non-nil result only if
-- Corresponding_Called_Function (Expression) is not nil!
Check_Validity (Expression, Package_Name & "Function_Call_Parameters");
Arg_Node := Node (Expression);
if not (Arg_Kind = A_Function_Call) or else
(Normalized and then Nkind (Arg_Node) = N_Attribute_Reference)
then
Raise_ASIS_Inappropriate_Element
(Diagnosis => Package_Name & "Function_Call_Parameters",
Wrong_Kind => Arg_Kind);
end if;
-- There is a number of different situations when the frontend
-- rewrites or changes in some other way the node heading
-- the subtree representing a function call. So we have to start
-- from computing the node to represent a function call.
if Nkind (R_Node (Expression)) = N_Raise_Constraint_Error or else
Nkind (R_Node (Expression)) = N_Raise_Program_Error or else
Nkind (R_Node (Expression)) = N_Conditional_Expression
then
Function_Call_Node := Node (Expression);
elsif Nkind (Arg_Node) = N_Attribute_Reference then
Function_Call_Node := Arg_Node;
elsif Nkind (R_Node (Expression)) = N_Unchecked_Type_Conversion then
-- Sometimes the front-end creates a "wrapper"
-- N_Unchecked_Type_Conversion structures for calls from RTL, see
-- E622-015 and the corresponding note in Actual_Parameter
Function_Call_Node := Sinfo.Expression (R_Node (Expression));
else
Function_Call_Node := R_Node (Expression);
-- Special cases when we need not the rewritten, but the original
-- node (or something else.
if Nkind (Function_Call_Node) = N_Integer_Literal or else
Nkind (Function_Call_Node) = N_Real_Literal or else
Nkind (Function_Call_Node) = N_Identifier or else
Nkind (Function_Call_Node) = N_String_Literal or else
-- this means, that the compiler has optimized a call like
-- 1 + 2, and we have to go back to the original node!
Nkind (Function_Call_Node) = N_Explicit_Dereference
-- this happens, but I do not know why...
then
Function_Call_Node := Arg_Node;
end if;
if Nkind (Function_Call_Node) = N_Op_Not and then
Is_Rewrite_Substitution (Function_Call_Node) and then
Nkind (Original_Node (Function_Call_Node)) = N_Op_Ne
then
-- '/=' is rewritten as 'not ( = )'
Function_Call_Node := Arg_Node;
end if;
if Nkind (Function_Call_Node) = N_Type_Conversion and then
Is_Rewrite_Substitution (Function_Call_Node) and then
Nkind (Original_Node (Function_Call_Node)) =
Nkind (Original_Node (Sinfo.Expression (Function_Call_Node)))
then
Function_Call_Node := Sinfo.Expression (Function_Call_Node);
end if;
end if;
-- See the general comment under the "A_Function_Call Problem"
-- headline in the beginning of the package body!! The prefix call
-- of the predefined operations should be processed on the base of
-- the rewritten node, in all the other cases, except
-- N_Attribute_Reference (which corresponds to the call to an
-- attribute-function and is handled separately: the node for such
-- a call may or may not be rewritten, but the processing is based on
-- the original node) the node is not rewritten.
-- -- temporary fix for "+"(1, 2) problem ??? 3.11w
--
-- if Nkind (Node (Expression)) = N_Function_Call and then
-- (Nkind (R_Node (Expression)) in N_Op_Add .. N_Op_Xor or else
-- Nkind (R_Node (Expression)) in N_Op_Abs .. N_Op_Plus)
-- then
-- Function_Call_Node := R_Node (Expression);
-- end if;
--
-- to activate this fix, one should decomment this if statement
-- and to comment out the fragment between
-- -- temporary fix for "+"(1, 2) problem - start and
-- -- temporary fix for "+"(1, 2) problem - end sentinels
if Normalized then
Tmp_El := Corresponding_Called_Function (Expression);
if Declaration_Kind (Tmp_El) in
A_Procedure_Instantiation .. A_Function_Instantiation
then
Tmp_El := Corresponding_Declaration (Tmp_El);
end if;
if Is_Nil (Tmp_El)
or else
Is_Nil (Parameter_Profile (Tmp_El))
then
return Nil_Element_List;
else
return Normalized_Param_Associations (Call_Elem => Expression);
end if;
else
Function_Call_Node_Kind := Nkind (Function_Call_Node);
if Function_Call_Node_Kind = N_Attribute_Reference then
-- the (prefix) call of the attribute function
return N_To_E_List_New
(List => Sinfo.Expressions (Function_Call_Node),
Starting_Element => Expression,
Internal_Kind => A_Parameter_Association);
elsif Function_Call_Node_Kind = N_Function_Call or else
Function_Call_Node_Kind = N_Procedure_Call_Statement
then
-- N_Procedure_Call_Statement corresponds to the argument of Debug
-- pragma
if No (Parameter_Associations (Function_Call_Node)) then
return Nil_Element_List;
else
return N_To_E_List_New
(List => Parameter_Associations
(Function_Call_Node),
Starting_Element => Expression,
Internal_Kind => A_Parameter_Association);
end if;
elsif Function_Call_Node_Kind in N_Op_Add .. N_Op_Xor then
-- here we have infix or prefix call of a binary predefined
-- operation
-- first, we construct the non-normalized association list
Infix_Operands (1) :=
Node_To_Element_New
(Node => Left_Opnd (Function_Call_Node),
Internal_Kind => A_Parameter_Association,
Starting_Element => Expression);
Infix_Operands (2) :=
Node_To_Element_New
(Node => Right_Opnd (Function_Call_Node),
Internal_Kind => A_Parameter_Association,
Starting_Element => Expression);
-- temporary fix for "+"(1, 2) problem - start
if Is_Prefix_Call (Expression) then
-- It is a real pity, but we have to worry about the crazy
-- situation like "+" (Right => X, Left => Y). For a prefix
-- call to a predefined operation an argument node is
-- rewritten to N_Op_Xxx node, and the original node of
-- N_Function_Call kind contains references to named
-- parameter associations, if any
-- So, we have to check if this situation takes place
-- If not Is_Prefix_Call (Expression), we have nothing to do!
Func_Call_Or_Node := Node (Expression);
if Func_Call_Or_Node /= Function_Call_Node and then
-- Func_Call_Or_Node can be of N_Function_Call kind only!
-- and we have the prefix call here!
--
-- Present (Parameter_Associations (Func_Call_Or_Node))
--
-- cannot be used to complete the check, because we have
-- empty list, but not No_List if there is positional
-- associations. Therefore -
List_Length (Parameter_Associations (Func_Call_Or_Node)) > 0
then
-- we have named associations, and we have to correct the
-- result
Association_Node_List :=
Parameter_Associations (Func_Call_Or_Node);
if List_Length (Association_Node_List) = 2 then
-- we have two named associations, so we cannot return
-- Infix_Operands. We will not correct it, we will
-- recreate the returned list:
return N_To_E_List_New
(List => Association_Node_List,
Include_Pragmas => False, -- ???
Starting_Element => Expression,
Internal_Kind => A_Parameter_Association);
else
-- if we are here, the only possibility is that
-- List_Length (Association_Node_List) = 1 and we are
-- processing the call like "+"(13, Right => Y).
-- So the first component of Infix_Operands is OK,
-- but the second should be re-created from the
-- positional association pointed by the original node:
Infix_Operands (2) := Node_To_Element_New (
Node => First (Association_Node_List),
Internal_Kind => A_Parameter_Association,
Starting_Element => Expression);
end if;
end if;
end if;
-- temporary fix for "+"(1, 2) problem - end
return Infix_Operands;
elsif Function_Call_Node_Kind in N_Op_Abs .. N_Op_Plus then
-- unary operation, Sinfo.ads rev. 1.251
-- infix_call, here we have infix or prefix call of an unary
-- predefined operation
-- the situation is more simple, then for binary predefined
-- operation - we have only one component in the returned list
-- we start from checking if we have the crazy case with
-- named association (something like "+"(Right => X)
Func_Call_Or_Node := Node (Expression);
if Func_Call_Or_Node /= Function_Call_Node and then
Nkind (Func_Call_Or_Node) = N_Function_Call and then
List_Length (Parameter_Associations (Func_Call_Or_Node)) > 0
then
-- we have named association
Association_Node_List :=
Parameter_Associations (Func_Call_Or_Node);
Infix_Operands (1) :=
Node_To_Element_New
(Node => First (Association_Node_List),
Internal_Kind => A_Parameter_Association,
Starting_Element => Expression);
else
Infix_Operands (1) :=
Node_To_Element_New
(Node => Right_Opnd (Function_Call_Node),
Internal_Kind => A_Parameter_Association,
Starting_Element => Expression);
end if;
return Infix_Operands (1 .. 1);
else
-- really nothing else could be possible, this alternative
-- could be chosen only as the result of some bug in the
-- implementation
raise Internal_Implementation_Error;
end if;
end if;
exception
when ASIS_Inappropriate_Element =>
raise;
when ASIS_Failed =>
if Status_Indicator = Unhandled_Exception_Error then
Add_Call_Information
(Argument => Expression,
Bool_Par => Normalized,
Outer_Call => Package_Name & "Function_Call_Parameters");
end if;
raise;
when Ex : others =>
Report_ASIS_Bug
(Query_Name => Package_Name & "Function_Call_Parameters",
Ex => Ex,
Arg_Element => Expression,
Bool_Par_ON => Normalized);
end Function_Call_Parameters;
-----------------------------------------------------------------------------
function Short_Circuit_Operation_Left_Expression
(Expression : Asis.Expression)
return Asis.Expression
is
Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Expression);
Arg_Node : Node_Id;
begin
Check_Validity
(Expression, Package_Name & "Short_Circuit_Operation_Left_Expression");
if not (Arg_Kind = An_And_Then_Short_Circuit or else
Arg_Kind = An_Or_Else_Short_Circuit)
then
Raise_ASIS_Inappropriate_Element
(Diagnosis =>
Package_Name & "Short_Circuit_Operation_Left_Expression",
Wrong_Kind => Arg_Kind);
end if;
Arg_Node := Node (Expression);
return Node_To_Element_New (Node => Left_Opnd (Arg_Node),
Starting_Element => Expression);
exception
when ASIS_Inappropriate_Element =>
raise;
when ASIS_Failed =>
if Status_Indicator = Unhandled_Exception_Error then
Add_Call_Information
(Argument => Expression,
Outer_Call => Package_Name &
"Short_Circuit_Operation_Left_Expression");
end if;
raise;
when Ex : others =>
Report_ASIS_Bug
(Query_Name => Package_Name &
"Short_Circuit_Operation_Left_Expression",
Ex => Ex,
Arg_Element => Expression);
end Short_Circuit_Operation_Left_Expression;
-----------------------------------------------------------------------------
function Short_Circuit_Operation_Right_Expression
(Expression : Asis.Expression)
return Asis.Expression
is
Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Expression);
Arg_Node : Node_Id;
begin
Check_Validity
(Expression,
Package_Name & "Short_Circuit_Operation_Right_Expression");
if not (Arg_Kind = An_And_Then_Short_Circuit or else
Arg_Kind = An_Or_Else_Short_Circuit)
then
Raise_ASIS_Inappropriate_Element
(Diagnosis =>
Package_Name & "Short_Circuit_Operation_Right_Expression",
Wrong_Kind => Arg_Kind);
end if;
Arg_Node := Node (Expression);
return Node_To_Element_New (Node => Right_Opnd (Arg_Node),
Starting_Element => Expression);
exception
when ASIS_Inappropriate_Element =>
raise;
when ASIS_Failed =>
if Status_Indicator = Unhandled_Exception_Error then
Add_Call_Information
(Argument => Expression,
Outer_Call => Package_Name &
"Short_Circuit_Operation_Right_Expression");
end if;
raise;
when Ex : others =>
Report_ASIS_Bug
(Query_Name => Package_Name &
"Short_Circuit_Operation_Right_Expression",
Ex => Ex,
Arg_Element => Expression);
end Short_Circuit_Operation_Right_Expression;
-----------------------------------------------------------------------------
function Membership_Test_Expression
(Expression : Asis.Expression)
return Asis.Expression
is
Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Expression);
Arg_Node : Node_Id;
begin
Check_Validity (Expression, Package_Name & "Membership_Test_Expression");
if Arg_Kind not in
An_In_Membership_Test .. A_Not_In_Membership_Test
then
Raise_ASIS_Inappropriate_Element
(Diagnosis => Package_Name & "Membership_Test_Expression",
Wrong_Kind => Arg_Kind);
end if;
Arg_Node := Node (Expression);
return Node_To_Element_New (Node => Left_Opnd (Arg_Node),
Starting_Element => Expression);
exception
when ASIS_Inappropriate_Element =>
raise;
when ASIS_Failed =>
if Status_Indicator = Unhandled_Exception_Error then
Add_Call_Information
(Argument => Expression,
Outer_Call => Package_Name & "Membership_Test_Expression");
end if;
raise;
when Ex : others =>
Report_ASIS_Bug
(Query_Name => Package_Name & "Membership_Test_Expression",
Ex => Ex,
Arg_Element => Expression);
end Membership_Test_Expression;
-----------------------------------------------------------------------------
function Membership_Test_Range
(Expression : Asis.Expression)
return Asis.Range_Constraint
is
Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Expression);
Arg_Node : Node_Id;
Result_Node : Node_Id;
Result_Or_Node : Node_Id;
Result_Kind : Internal_Element_Kinds;
begin
Check_Validity (Expression, Package_Name & "Membership_Test_Range");
if not (Arg_Kind in An_In_Membership_Test .. A_Not_In_Membership_Test
and then
Is_Range_Memberchip_Test (Expression))
then
Raise_ASIS_Inappropriate_Element
(Diagnosis => Package_Name & "Membership_Test_Range",
Wrong_Kind => Arg_Kind);
end if;
Arg_Node := Node (Expression);
-- we cannot use the auto determination of the result kind
-- because of the possible rewriting of A'Range as
-- A'First .. A'Last.
Result_Node := Right_Opnd (Arg_Node);
Result_Or_Node := Original_Node (Result_Node);
if Nkind (Result_Or_Node) = N_Attribute_Reference then
Result_Kind := A_Range_Attribute_Reference;
else
Result_Kind := A_Simple_Expression_Range;
end if;
return Node_To_Element_New (Node => Result_Node,
Internal_Kind => Result_Kind,
Starting_Element => Expression);
exception
when ASIS_Inappropriate_Element =>
raise;
when ASIS_Failed =>
if Status_Indicator = Unhandled_Exception_Error then
Add_Call_Information
(Argument => Expression,
Outer_Call => Package_Name & "Membership_Test_Range");
end if;
raise;
when Ex : others =>
Report_ASIS_Bug
(Query_Name => Package_Name & "Membership_Test_Range",
Ex => Ex,
Arg_Element => Expression);
end Membership_Test_Range;
-----------------------------------------------------------------------------
function Membership_Test_Subtype_Mark
(Expression : Asis.Expression)
return Asis.Expression
is
Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Expression);
Arg_Node : Node_Id;
begin
Check_Validity
(Expression, Package_Name & "Membership_Test_Subtype_Mark");
if not (Arg_Kind in An_In_Membership_Test .. A_Not_In_Membership_Test
and then
Is_Type_Memberchip_Test (Expression))
then
Raise_ASIS_Inappropriate_Element
(Diagnosis => Package_Name & "Membership_Test_Expression",
Wrong_Kind => Arg_Kind);
end if;
Arg_Node := Node (Expression);
return Node_To_Element_New (Node => Right_Opnd (Arg_Node),
Starting_Element => Expression);
exception
when ASIS_Inappropriate_Element =>
raise;
when ASIS_Failed =>
if Status_Indicator = Unhandled_Exception_Error then
Add_Call_Information
(Argument => Expression,
Outer_Call => Package_Name & "Membership_Test_Subtype_Mark");
end if;
raise;
when Ex : others =>
Report_ASIS_Bug
(Query_Name => Package_Name & "Membership_Test_Subtype_Mark",
Ex => Ex,
Arg_Element => Expression);
end Membership_Test_Subtype_Mark;
------------------------------------------------------------------------------
function Converted_Or_Qualified_Subtype_Mark
(Expression : Asis.Expression)
return Asis.Expression
is
Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Expression);
Arg_Node : Node_Id;
begin
Check_Validity
(Expression, Package_Name & "Converted_Or_Qualified_Subtype_Mark");
if not (Arg_Kind = A_Type_Conversion or else
Arg_Kind = A_Qualified_Expression)
then
Raise_ASIS_Inappropriate_Element
(Diagnosis => Package_Name & "Converted_Or_Qualified_Subtype_Mark",
Wrong_Kind => Arg_Kind);
end if;
Arg_Node := Node (Expression);
-- if Special_Case (Expression) = Type_Conversion_With_Attribute then
--
-- return Node_To_Element (
-- Node => Arg_Node,
-- -- that is, the node of N_Attribute_Reference kind!
-- Check_If_Type_Conversion => False,
-- -- and it is treated as the base for
-- -- An_Attribute_Reference Element
-- In_Unit => Encl_Unit (Expression));
-- else
-- return Node_To_Element (
-- Node => Sinfo.Subtype_Mark (Arg_Node),
-- In_Unit => Encl_Unit (Expression));
-- end if;
--
-- ??? It looks like Type_Conversion_With_Attribute is not needed
-- ??? any more as a Special_Cases value. We'll keep the old code
-- ??? (commented out) till the next application of the massive
-- ??? testing procedure
return Node_To_Element_New (
Node => Sinfo.Subtype_Mark (Arg_Node),
Starting_Element => Expression);
exception
when ASIS_Inappropriate_Element =>
raise;
when ASIS_Failed =>
if Status_Indicator = Unhandled_Exception_Error then
Add_Call_Information
(Argument => Expression,
Outer_Call => Package_Name &
"Converted_Or_Qualified_Subtype_Mark");
end if;
raise;
when Ex : others =>
Report_ASIS_Bug
(Query_Name => Package_Name &
"Converted_Or_Qualified_Subtype_Mark",
Ex => Ex,
Arg_Element => Expression);
end Converted_Or_Qualified_Subtype_Mark;
------------------------------------------------------------------------------
function Converted_Or_Qualified_Expression
(Expression : Asis.Expression)
return Asis.Expression
is
Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Expression);
Arg_Node : Node_Id;
begin
Check_Validity
(Expression, Package_Name & "Converted_Or_Qualified_Expression");
if not (Arg_Kind = A_Type_Conversion or else
Arg_Kind = A_Qualified_Expression)
then
Raise_ASIS_Inappropriate_Element
(Diagnosis => Package_Name & "Converted_Or_Qualified_Expression",
Wrong_Kind => Arg_Kind);
end if;
Arg_Node := Node (Expression);
return Node_To_Element_New
(Node => Sinfo.Expression (Arg_Node),
Starting_Element => Expression);
exception
when ASIS_Inappropriate_Element =>
raise;
when ASIS_Failed =>
if Status_Indicator = Unhandled_Exception_Error then
Add_Call_Information
(Argument => Expression,
Outer_Call => Package_Name &
"Converted_Or_Qualified_Expression");
end if;
raise;
when Ex : others =>
Report_ASIS_Bug
(Query_Name => Package_Name & "Converted_Or_Qualified_Expression",
Ex => Ex,
Arg_Element => Expression);
end Converted_Or_Qualified_Expression;
-----------------------------------------------------------------------------
function Allocator_Subtype_Indication
(Expression : Asis.Expression)
return Asis.Subtype_Indication
is
Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Expression);
Arg_Node : Node_Id;
begin
Check_Validity
(Expression, Package_Name & "Allocator_Subtype_Indication");
if not (Arg_Kind = An_Allocation_From_Subtype) then
Raise_ASIS_Inappropriate_Element
(Diagnosis => Package_Name & "Allocator_Subtype_Indication",
Wrong_Kind => Arg_Kind);
end if;
Arg_Node := Node (Expression);
return Node_To_Element_New
(Node => Sinfo.Expression (Arg_Node),
Internal_Kind => A_Subtype_Indication,
Starting_Element => Expression);
exception
when ASIS_Inappropriate_Element =>
raise;
when ASIS_Failed =>
if Status_Indicator = Unhandled_Exception_Error then
Add_Call_Information
(Argument => Expression,
Outer_Call => Package_Name & "Allocator_Subtype_Indication");
end if;
raise;
when Ex : others =>
Report_ASIS_Bug
(Query_Name => Package_Name & "Allocator_Subtype_Indication",
Ex => Ex,
Arg_Element => Expression);
end Allocator_Subtype_Indication;
------------------------------------------------------------------------------
function Allocator_Qualified_Expression
(Expression : Asis.Expression)
return Asis.Expression
is
Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Expression);
Arg_Node : Node_Id;
begin
Check_Validity
(Expression, Package_Name & "Allocator_Qualified_Expression");
if not (Arg_Kind = An_Allocation_From_Qualified_Expression) then
Raise_ASIS_Inappropriate_Element
(Diagnosis => Package_Name & "Allocator_Qualified_Expression",
Wrong_Kind => Arg_Kind);
end if;
Arg_Node := Node (Expression);
return Node_To_Element_New
(Node => Sinfo.Expression (Arg_Node),
Starting_Element => Expression);
exception
when ASIS_Inappropriate_Element =>
raise;
when ASIS_Failed =>
if Status_Indicator = Unhandled_Exception_Error then
Add_Call_Information
(Argument => Expression,
Outer_Call => Package_Name & "Allocator_Qualified_Expression");
end if;
raise;
when Ex : others =>
Report_ASIS_Bug
(Query_Name => Package_Name & "Allocator_Qualified_Expression",
Ex => Ex,
Arg_Element => Expression);
end Allocator_Qualified_Expression;
------------------------------------------------------------------------------
-- Processing of the Ada extensions that most likely will be included in --
-- Ada 2015 and that are already implemented in GNAT --
------------------------------------------------------------------------------
-----------------------------
-- Conditional Expressions --
-----------------------------
----------------------
-- Expression_Paths --
----------------------
function Expression_Paths
(Expression : Asis.Expression)
return Asis.Element_List
is
Res_Node : Node_Id;
First_Path_Kind : Internal_Element_Kinds := An_If_Expression_Path;
Next_Cond_Expr_Node : Node_Id := Node (Expression);
procedure Get_If_Paths;
-- Get expression paths from the Expressions list of
-- N_Conditional_Expression node that is the current value of
-- Next_Cond_Expr_Node. It uses the value of First_Path_Kind to set
-- the kind of the first path element.
--
-- For IF expression, The Expressions list may have the following
-- structure:
--
-- (1) expr1 -> expr2, this corresponds to IF expr1 THEN expr2
-- no ELSE or ELSIF paths
--
-- (2) expr1 -> expr2 -> expr3, this corresponds to
-- IF expr1 THEN expr2 ELSE expr3
-- no ELSIF paths
--
-- (3) expr1 -> expr2 -> cond_expr, this corresponds to a conditional
-- expression with ELSIF path
--
-- This procedure creates and appends to Asis_Element_Table.Table
-- elements corresponding to expr1, expr2 and expr3, and in case (3)
-- sets Next_Cond_Expr_Node to cond_expr. In cases (1) and (2)
-- Next_Cond_Expr_Node is set to Empty
procedure Get_If_Paths is
begin
Res_Node := First (Sinfo.Expressions (Next_Cond_Expr_Node));
-- This Element represents the condition from IF/ELSIF path, so
Res_Node := Next (Res_Node);
Asis_Element_Table.Append
(Node_To_Element_New
(Node => Res_Node,
Starting_Element => Expression,
Internal_Kind => First_Path_Kind));
Res_Node := Next (Res_Node);
if Present (Res_Node)
and then
Comes_From_Source (Res_Node)
then
if Nkind (Res_Node) = N_Conditional_Expression then
Next_Cond_Expr_Node := Res_Node;
else
Asis_Element_Table.Append
(Node_To_Element_New
(Node => Res_Node,
Starting_Element => Expression,
Internal_Kind => An_Else_Expression_Path));
Next_Cond_Expr_Node := Empty;
end if;
else
Next_Cond_Expr_Node := Empty;
end if;
end Get_If_Paths;
begin
Check_Validity (Expression, Package_Name & "Expression_Paths");
if Expression_Kind (Expression) not in
A_Case_Expression .. An_If_Expression
then
Raise_ASIS_Inappropriate_Element
(Diagnosis => Package_Name & "Expression_Paths",
Wrong_Kind => Int_Kind (Expression));
end if;
Asis_Element_Table.Init;
if Expression_Kind (Expression) = An_If_Expression then
Next_Cond_Expr_Node := Node (Expression);
Get_If_Paths;
First_Path_Kind := An_Elsif_Expression_Path;
while Present (Next_Cond_Expr_Node) loop
Get_If_Paths;
end loop;
else
Res_Node := First (Alternatives (Node (Expression)));
while Present (Res_Node) loop
Asis_Element_Table.Append
(Node_To_Element_New
(Node => Res_Node,
Starting_Element => Expression,
Internal_Kind => A_Case_Expression_Path));
Res_Node := Next (Res_Node);
end loop;
end if;
return Asis.Element_List
(Asis_Element_Table.Table (1 .. Asis_Element_Table.Last));
exception
when ASIS_Inappropriate_Element =>
raise;
when ASIS_Failed =>
if Status_Indicator = Unhandled_Exception_Error then
Add_Call_Information
(Argument => Expression,
Outer_Call => Package_Name & "Expression_Paths");
end if;
raise;
when Ex : others =>
Report_ASIS_Bug
(Query_Name => Package_Name & "Expression_Paths",
Ex => Ex,
Arg_Element => Expression);
end Expression_Paths;
-------------------------------
-- Path_Condition_Expression --
-------------------------------
-- function Path_Condition_Expression
-- (Path : Asis.Element)
-- return Asis.Expression
-- is
-- Res_Node : Node_Id;
-- begin
-- Check_Validity (Path, Package_Name & "Path_Condition_Expression");
-- if Expression_Path_Kind (Path) not in
-- An_If_Expression_Path .. An_Elsif_Expression_Path
-- then
-- Raise_ASIS_Inappropriate_Element
-- (Diagnosis => Package_Name & "Path_Condition_Expression",
-- Wrong_Kind => Int_Kind (Path));
-- end if;
-- Res_Node := R_Node (Path);
-- pragma Assert (Is_List_Member (Res_Node));
-- Res_Node := Prev (Res_Node);
-- return Node_To_Element_New
-- (Node => Res_Node,
-- Starting_Element => Path);
-- exception
-- when ASIS_Inappropriate_Element =>
-- raise;
-- when ASIS_Failed =>
-- if Status_Indicator = Unhandled_Exception_Error then
-- Add_Call_Information
-- (Argument => Path,
-- Outer_Call => Package_Name & "Path_Condition_Expression");
-- end if;
-- raise;
-- when Ex : others =>
-- Report_ASIS_Bug
-- (Query_Name => Package_Name & "Path_Condition_Expression",
-- Ex => Ex,
-- Arg_Element => Path);
-- end Path_Condition_Expression;
--------------------------
-- Dependent_Expression --
--------------------------
function Dependent_Expression
(Path : Asis.Element)
return Asis.Expression
is
Arg_Kind : constant Path_Kinds := Path_Kind (Path);
Result_Node : Node_Id;
begin
Check_Validity (Path, Package_Name & "Dependent_Expression");
if Arg_Kind not in
A_Case_Expression_Path .. An_Else_Expression_Path
then
Raise_ASIS_Inappropriate_Element
(Diagnosis => Package_Name & "Dependent_Expression",
Wrong_Kind => Int_Kind (Path));
end if;
Result_Node := R_Node (Path);
if Arg_Kind = A_Case_Expression_Path then
Result_Node := Sinfo.Expression (Result_Node);
end if;
return Node_To_Element_New
(Node => Result_Node,
Starting_Element => Path);
exception
when ASIS_Inappropriate_Element =>
raise;
when ASIS_Failed =>
if Status_Indicator = Unhandled_Exception_Error then
Add_Call_Information
(Argument => Path,
Outer_Call => Package_Name & "Dependent_Expression");
end if;
raise;
when Ex : others =>
Report_ASIS_Bug
(Query_Name => Package_Name & "Dependent_Expression",
Ex => Ex,
Arg_Element => Path);
end Dependent_Expression;
----------------------------------
-- Generalized Membership Tests --
----------------------------------
function Membership_Test_Choices
(Expression : Asis.Expression)
return Asis.Element_List
is
Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Expression);
Arg_Node : Node_Id;
Res_Node : Node_Id;
begin
if Arg_Kind not in An_In_Membership_Test .. A_Not_In_Membership_Test then
Raise_ASIS_Inappropriate_Element
(Diagnosis => Package_Name & "Membership_Test_Choices",
Wrong_Kind => Arg_Kind);
end if;
Asis_Element_Table.Init;
Arg_Node := Node (Expression);
if No (Alternatives (Arg_Node)) then
Asis_Element_Table.Append
(Node_To_Element_New
(Node => Right_Opnd (Arg_Node),
Starting_Element => Expression));
else
Res_Node := First (Alternatives (Arg_Node));
while Present (Res_Node) loop
Asis_Element_Table.Append
(Node_To_Element_New
(Node => Res_Node,
Starting_Element => Expression));
Res_Node := Next (Res_Node);
end loop;
end if;
return Asis.Element_List
(Asis_Element_Table.Table (1 .. Asis_Element_Table.Last));
exception
when ASIS_Inappropriate_Element =>
raise;
when ASIS_Failed =>
if Status_Indicator = Unhandled_Exception_Error then
Add_Call_Information
(Argument => Expression,
Outer_Call => Package_Name & "Membership_Test_Choices");
end if;
raise;
when Ex : others =>
Report_ASIS_Bug
(Query_Name => Package_Name & "Membership_Test_Choices",
Ex => Ex,
Arg_Element => Expression);
end Membership_Test_Choices;
----------------------------
-- Quantified Expressions --
----------------------------
----------------------------
-- Iterator_Specification --
----------------------------
function Iterator_Specification
(Expression : Asis.Expression)
return Asis.Declaration
is
Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Expression);
Result_Node : Node_Id;
begin
Check_Validity (Expression, Package_Name & "Iterator_Specification");
if Arg_Kind not in
A_For_All_Quantified_Expression .. A_For_Some_Quantified_Expression
then
Raise_ASIS_Inappropriate_Element
(Diagnosis => Package_Name & "Iterator_Specification",
Wrong_Kind => Arg_Kind);
end if;
Result_Node := Loop_Parameter_Specification (Node (Expression));
if No (Result_Node) then
Result_Node := Iterator_Specification (Node (Expression));
end if;
return Node_To_Element_New (Node => Result_Node,
Starting_Element => Expression);
exception
when ASIS_Inappropriate_Element =>
raise;
when ASIS_Failed =>
if Status_Indicator = Unhandled_Exception_Error then
Add_Call_Information
(Argument => Expression,
Outer_Call => Package_Name & "Iterator_Specification");
end if;
raise;
when Ex : others =>
Report_ASIS_Bug
(Query_Name => Package_Name & "Iterator_Specification",
Ex => Ex,
Arg_Element => Expression);
end Iterator_Specification;
---------------
-- Predicate --
---------------
function Predicate
(Expression : Asis.Expression)
return Asis.Expression
is
Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Expression);
begin
Check_Validity (Expression, Package_Name & "Predicate");
if Arg_Kind not in
A_For_All_Quantified_Expression .. A_For_Some_Quantified_Expression
then
Raise_ASIS_Inappropriate_Element
(Diagnosis => Package_Name & "Predicate",
Wrong_Kind => Arg_Kind);
end if;
return Node_To_Element_New
(Node => Condition (Node (Expression)),
Starting_Element => Expression);
exception
when ASIS_Inappropriate_Element =>
raise;
when ASIS_Failed =>
if Status_Indicator = Unhandled_Exception_Error then
Add_Call_Information
(Argument => Expression,
Outer_Call => Package_Name & "Predicate");
end if;
raise;
when Ex : others =>
Report_ASIS_Bug
(Query_Name => Package_Name & "Predicate",
Ex => Ex,
Arg_Element => Expression);
end Predicate;
---------------------------
-- Subpool in allocator --
---------------------------
function Subpool_Name
(Expression : Asis.Expression)
return Asis.Expression
is
Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Expression);
begin
Check_Validity (Expression, Package_Name & "Subpool_Name");
if Arg_Kind not in An_Allocation_From_Subtype ..
An_Allocation_From_Qualified_Expression
then
Raise_ASIS_Inappropriate_Element
(Diagnosis => Package_Name & "Subpool_Name",
Wrong_Kind => Arg_Kind);
end if;
-- return Node_To_Element_New
-- (Node => Subpool_Handle_Name (Node (Expression)),
-- Starting_Element => Expression);
raise ASIS_Inappropriate_Element; -- SCz
return Expression;
exception
when ASIS_Inappropriate_Element =>
raise;
when ASIS_Failed =>
if Status_Indicator = Unhandled_Exception_Error then
Add_Call_Information
(Argument => Expression,
Outer_Call => Package_Name & "Subpool_Name");
end if;
raise;
when Ex : others =>
Report_ASIS_Bug
(Query_Name => Package_Name & "Subpool_Name",
Ex => Ex,
Arg_Element => Expression);
end Subpool_Name;
end Asis.Expressions;
|
reznikmm/matreshka | Ada | 7,004 | ads | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- XML Processor --
-- --
-- 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 League.Strings;
with Matreshka.DOM_Nodes;
with XML.DOM.Attributes;
with XML.DOM.Elements;
with XML.DOM.Visitors;
package Matreshka.DOM_Elements is
pragma Preelaborate;
type Abstract_Element_Node is
abstract new Matreshka.DOM_Nodes.Node
and XML.DOM.Elements.DOM_Element with
record
First_Attribute : Matreshka.DOM_Nodes.Node_Access;
Last_Attribute : Matreshka.DOM_Nodes.Node_Access;
end record;
type Element_L2_Parameters is record
Document : not null Matreshka.DOM_Nodes.Document_Access;
Namespace_URI : League.Strings.Universal_String;
Prefix : League.Strings.Universal_String;
Local_Name : League.Strings.Universal_String;
end record;
not overriding function Create
(Parameters : not null access Element_L2_Parameters)
return Abstract_Element_Node is abstract;
-- Dispatching constructor.
overriding procedure Enter_Node
(Self : not null access Abstract_Element_Node;
Visitor : in out XML.DOM.Visitors.Abstract_Visitor'Class;
Control : in out XML.DOM.Visitors.Traverse_Control);
-- Dispatch call to corresponding subprogram of visitor interface.
overriding function Get_Attribute_Node_NS
(Self : not null access Abstract_Element_Node;
Namespace_URI : League.Strings.Universal_String;
Local_Name : League.Strings.Universal_String)
return XML.DOM.Attributes.DOM_Attribute_Access;
overriding function Get_Node_Type
(Self : not null access constant Abstract_Element_Node)
return XML.DOM.Node_Type;
overriding function Get_Tag_Name
(Self : not null access constant Abstract_Element_Node)
return League.Strings.Universal_String;
overriding function Get_Node_Name
(Self : not null access constant Abstract_Element_Node)
return League.Strings.Universal_String renames Get_Tag_Name;
overriding procedure Leave_Node
(Self : not null access Abstract_Element_Node;
Visitor : in out XML.DOM.Visitors.Abstract_Visitor'Class;
Control : in out XML.DOM.Visitors.Traverse_Control);
-- Dispatch call to corresponding subprogram of visitor interface.
overriding function Set_Attribute_Node_NS
(Self : not null access Abstract_Element_Node;
New_Attr : not null XML.DOM.Attributes.DOM_Attribute_Access)
return XML.DOM.Attributes.DOM_Attribute_Access;
overriding procedure Visit_Node
(Self : not null access Abstract_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);
-- Dispatch call to corresponding subprogram of iterator interface.
type Element_Node is new Abstract_Element_Node
and XML.DOM.Elements.DOM_Element with
record
Namespace_URI : League.Strings.Universal_String;
Prefix : League.Strings.Universal_String;
Local_Name : League.Strings.Universal_String;
end record;
overriding function Create
(Parameters : not null access Element_L2_Parameters)
return Element_Node;
overriding function Get_Local_Name
(Self : not null access constant Element_Node)
return League.Strings.Universal_String;
overriding function Get_Namespace_URI
(Self : not null access constant Element_Node)
return League.Strings.Universal_String;
package Constructors is
procedure Initialize
(Self : not null access Abstract_Element_Node'Class;
Document : not null Matreshka.DOM_Nodes.Document_Access);
end Constructors;
end Matreshka.DOM_Elements;
|
reznikmm/matreshka | Ada | 4,097 | 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.Draw_Handle_Range_X_Minimum_Attributes;
package Matreshka.ODF_Draw.Handle_Range_X_Minimum_Attributes is
type Draw_Handle_Range_X_Minimum_Attribute_Node is
new Matreshka.ODF_Draw.Abstract_Draw_Attribute_Node
and ODF.DOM.Draw_Handle_Range_X_Minimum_Attributes.ODF_Draw_Handle_Range_X_Minimum_Attribute
with null record;
overriding function Create
(Parameters : not null access Matreshka.DOM_Attributes.Attribute_L2_Parameters)
return Draw_Handle_Range_X_Minimum_Attribute_Node;
overriding function Get_Local_Name
(Self : not null access constant Draw_Handle_Range_X_Minimum_Attribute_Node)
return League.Strings.Universal_String;
end Matreshka.ODF_Draw.Handle_Range_X_Minimum_Attributes;
|
optikos/oasis | Ada | 2,827 | 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_Identifiers;
with Program.Elements.Aspect_Specifications;
with Program.Elements.Expressions;
with Program.Elements.Task_Definitions;
package Program.Elements.Single_Task_Declarations is
pragma Pure (Program.Elements.Single_Task_Declarations);
type Single_Task_Declaration is
limited interface and Program.Elements.Declarations.Declaration;
type Single_Task_Declaration_Access is
access all Single_Task_Declaration'Class with Storage_Size => 0;
not overriding function Name
(Self : Single_Task_Declaration)
return not null Program.Elements.Defining_Identifiers
.Defining_Identifier_Access is abstract;
not overriding function Aspects
(Self : Single_Task_Declaration)
return Program.Elements.Aspect_Specifications
.Aspect_Specification_Vector_Access is abstract;
not overriding function Progenitors
(Self : Single_Task_Declaration)
return Program.Elements.Expressions.Expression_Vector_Access is abstract;
not overriding function Definition
(Self : Single_Task_Declaration)
return not null Program.Elements.Task_Definitions.Task_Definition_Access
is abstract;
type Single_Task_Declaration_Text is limited interface;
type Single_Task_Declaration_Text_Access is
access all Single_Task_Declaration_Text'Class with Storage_Size => 0;
not overriding function To_Single_Task_Declaration_Text
(Self : aliased in out Single_Task_Declaration)
return Single_Task_Declaration_Text_Access is abstract;
not overriding function Task_Token
(Self : Single_Task_Declaration_Text)
return not null Program.Lexical_Elements.Lexical_Element_Access
is abstract;
not overriding function With_Token
(Self : Single_Task_Declaration_Text)
return Program.Lexical_Elements.Lexical_Element_Access is abstract;
not overriding function Is_Token
(Self : Single_Task_Declaration_Text)
return not null Program.Lexical_Elements.Lexical_Element_Access
is abstract;
not overriding function New_Token
(Self : Single_Task_Declaration_Text)
return Program.Lexical_Elements.Lexical_Element_Access is abstract;
not overriding function With_Token_2
(Self : Single_Task_Declaration_Text)
return Program.Lexical_Elements.Lexical_Element_Access is abstract;
not overriding function Semicolon_Token
(Self : Single_Task_Declaration_Text)
return not null Program.Lexical_Elements.Lexical_Element_Access
is abstract;
end Program.Elements.Single_Task_Declarations;
|
ekoeppen/STM32_Generic_Ada_Drivers | Ada | 144 | adb | with STM32_SVD; use STM32_SVD;
package body STM32GD.Board is
procedure Init is
begin
USART.Init;
end Init;
end STM32GD.Board;
|
zhmu/ananas | Ada | 15,833 | adb | ------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- E X P _ C H 8 --
-- --
-- B o d y --
-- --
-- Copyright (C) 1992-2022, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
-- for more details. You should have received a copy of the GNU General --
-- Public License distributed with GNAT; see file COPYING3. If not, go to --
-- http://www.gnu.org/licenses for a complete copy of the license. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
with Atree; use Atree;
with Einfo; use Einfo;
with Einfo.Entities; use Einfo.Entities;
with Einfo.Utils; use Einfo.Utils;
with Exp_Ch3; use Exp_Ch3;
with Exp_Ch4; use Exp_Ch4;
with Exp_Ch6; use Exp_Ch6;
with Exp_Dbug; use Exp_Dbug;
with Exp_Util; use Exp_Util;
with Freeze; use Freeze;
with Namet; use Namet;
with Nmake; use Nmake;
with Nlists; use Nlists;
with Opt; use Opt;
with Sem; use Sem;
with Sem_Aux; use Sem_Aux;
with Sem_Ch8; use Sem_Ch8;
with Sem_Util; use Sem_Util;
with Sinfo; use Sinfo;
with Sinfo.Nodes; use Sinfo.Nodes;
with Sinfo.Utils; use Sinfo.Utils;
with Snames; use Snames;
with Stand; use Stand;
with Tbuild; use Tbuild;
package body Exp_Ch8 is
---------------------------------------------
-- Expand_N_Exception_Renaming_Declaration --
---------------------------------------------
procedure Expand_N_Exception_Renaming_Declaration (N : Node_Id) is
Decl : Node_Id;
begin
Decl := Debug_Renaming_Declaration (N);
if Present (Decl) then
Insert_Action (N, Decl);
end if;
end Expand_N_Exception_Renaming_Declaration;
------------------------------------------
-- Expand_N_Object_Renaming_Declaration --
------------------------------------------
-- Most object renaming cases can be done by just capturing the address
-- of the renamed object. The cases in which this is not true are when
-- this address is not computable, since it involves extraction of a
-- packed array element, or of a record component to which a component
-- clause applies (that can specify an arbitrary bit boundary), or where
-- the enclosing record itself has a non-standard representation.
-- In Ada 2022, a third case arises when the renamed object is a nonatomic
-- subcomponent of an atomic object, because reads of or writes to it must
-- access the enclosing atomic object. That's also the case for an object
-- subject to the Volatile_Full_Access GNAT aspect/pragma in any language
-- version. For the sake of simplicity, we treat any subcomponent of an
-- atomic or Volatile_Full_Access object in any language version this way.
-- In these three cases, we pre-evaluate the renaming expression, by
-- extracting and freezing the values of any subscripts, and then we
-- set the flag Is_Renaming_Of_Object which means that any reference
-- to the object will be handled by macro substitution in the front
-- end, and the back end will know to ignore the renaming declaration.
-- An additional odd case that requires processing by expansion is
-- the renaming of a discriminant of a mutable record type. The object
-- is a constant because it renames something that cannot be assigned to,
-- but in fact the underlying value can change and must be reevaluated
-- at each reference. Gigi does have a notion of a "constant view" of
-- an object, and therefore the front-end must perform the expansion.
-- For simplicity, and to bypass some obscure code-generation problem,
-- we use macro substitution for all renamed discriminants, whether the
-- enclosing type is constrained or not.
-- The other special processing required is for the case of renaming
-- of an object of a class wide type, where it is necessary to build
-- the appropriate subtype for the renamed object.
-- More comments needed for this para ???
procedure Expand_N_Object_Renaming_Declaration (N : Node_Id) is
function Evaluation_Required (Nam : Node_Id) return Boolean;
-- Determines whether it is necessary to do static name evaluation for
-- renaming of Nam. It is considered necessary if evaluating the name
-- involves indexing a packed array, or extracting a component of a
-- record to which a component clause applies, or a subcomponent of an
-- atomic object. Note that we are only interested in these operations
-- if they occur as part of the name itself, subscripts are just values
-- that are computed as part of the evaluation, so they are unimportant.
-- In addition, always return True for Modify_Tree_For_C since the
-- code generator doesn't know how to handle renamings.
-------------------------
-- Evaluation_Required --
-------------------------
function Evaluation_Required (Nam : Node_Id) return Boolean is
begin
if Modify_Tree_For_C then
return True;
elsif Nkind (Nam) in N_Indexed_Component | N_Slice then
if Is_Packed (Etype (Prefix (Nam))) then
return True;
elsif Is_Full_Access_Object (Prefix (Nam)) then
return True;
else
return Evaluation_Required (Prefix (Nam));
end if;
elsif Nkind (Nam) = N_Selected_Component then
declare
Rec_Type : constant Entity_Id := Etype (Prefix (Nam));
begin
if Present (Component_Clause (Entity (Selector_Name (Nam))))
or else Has_Non_Standard_Rep (Rec_Type)
then
return True;
elsif Ekind (Entity (Selector_Name (Nam))) = E_Discriminant
and then Is_Record_Type (Rec_Type)
and then not Is_Concurrent_Record_Type (Rec_Type)
then
return True;
elsif Is_Full_Access_Object (Prefix (Nam)) then
return True;
else
return Evaluation_Required (Prefix (Nam));
end if;
end;
else
return False;
end if;
end Evaluation_Required;
-- Local variables
Decl : Node_Id;
Nam : constant Node_Id := Name (N);
T : constant Entity_Id := Etype (Defining_Identifier (N));
-- Start of processing for Expand_N_Object_Renaming_Declaration
begin
-- Perform name evaluation if required
if Evaluation_Required (Nam) then
Evaluate_Name (Nam);
Set_Is_Renaming_Of_Object (Defining_Identifier (N));
end if;
-- Deal with construction of subtype in class-wide case
if Is_Class_Wide_Type (T) then
Expand_Subtype_From_Expr (N, T, Subtype_Mark (N), Name (N));
Find_Type (Subtype_Mark (N));
Set_Etype (Defining_Identifier (N), Entity (Subtype_Mark (N)));
-- Freeze the class-wide subtype here to ensure that the subtype
-- and equivalent type are frozen before the renaming.
Freeze_Before (N, Entity (Subtype_Mark (N)));
end if;
-- Ada 2005 (AI-318-02): If the renamed object is a call to a build-in-
-- place function, then a temporary return object needs to be created
-- and access to it must be passed to the function.
if Is_Build_In_Place_Function_Call (Nam) then
Make_Build_In_Place_Call_In_Anonymous_Context (Nam);
-- Ada 2005 (AI-318-02): Specialization of previous case for renaming
-- containing build-in-place function calls whose returned object covers
-- interface types.
elsif Present (Unqual_BIP_Iface_Function_Call (Nam)) then
Make_Build_In_Place_Iface_Call_In_Anonymous_Context (Nam);
end if;
-- Create renaming entry for debug information. Mark the entity as
-- needing debug info if it comes from sources because the current
-- setting in Freeze_Entity occurs too late. ???
Set_Debug_Info_Defining_Id (N);
Decl := Debug_Renaming_Declaration (N);
if Present (Decl) then
Insert_Action (N, Decl);
end if;
end Expand_N_Object_Renaming_Declaration;
-------------------------------------------
-- Expand_N_Package_Renaming_Declaration --
-------------------------------------------
procedure Expand_N_Package_Renaming_Declaration (N : Node_Id) is
Decl : Node_Id;
begin
Decl := Debug_Renaming_Declaration (N);
if Present (Decl) then
-- If we are in a compilation unit, then this is an outer
-- level declaration, and must have a scope of Standard
if Nkind (Parent (N)) = N_Compilation_Unit then
declare
Aux : constant Node_Id := Aux_Decls_Node (Parent (N));
begin
Push_Scope (Standard_Standard);
if No (Actions (Aux)) then
Set_Actions (Aux, New_List (Decl));
else
Append (Decl, Actions (Aux));
end if;
Analyze (Decl);
-- Enter the debug variable in the qualification list, which
-- must be done at this point because auxiliary declarations
-- occur at the library level and aren't associated with a
-- normal scope.
Qualify_Entity_Names (Decl);
Pop_Scope;
end;
-- Otherwise, just insert after the package declaration
else
Insert_Action (N, Decl);
end if;
end if;
end Expand_N_Package_Renaming_Declaration;
----------------------------------------------
-- Expand_N_Subprogram_Renaming_Declaration --
----------------------------------------------
procedure Expand_N_Subprogram_Renaming_Declaration (N : Node_Id) is
Loc : constant Source_Ptr := Sloc (N);
Id : constant Entity_Id := Defining_Entity (N);
function Build_Body_For_Renaming (Typ : Entity_Id) return Node_Id;
-- Build and return the body for the renaming declaration of an equality
-- or inequality operator of type Typ.
-----------------------------
-- Build_Body_For_Renaming --
-----------------------------
function Build_Body_For_Renaming (Typ : Entity_Id) return Node_Id is
Left : constant Entity_Id := First_Formal (Id);
Right : constant Entity_Id := Next_Formal (Left);
Body_Id : Entity_Id;
Decl : Node_Id;
begin
Set_Alias (Id, Empty);
Set_Has_Completion (Id, False);
Rewrite (N,
Make_Subprogram_Declaration (Loc,
Specification => Specification (N)));
Set_Has_Delayed_Freeze (Id);
Body_Id := Make_Defining_Identifier (Loc, Chars (Id));
Set_Debug_Info_Needed (Body_Id);
if Has_Variant_Part (Typ) then
Decl :=
Build_Variant_Record_Equality
(Typ => Typ,
Body_Id => Body_Id,
Param_Specs => Copy_Parameter_List (Id));
-- Build body for renamed equality, to capture its current meaning.
-- It may be redefined later, but the renaming is elaborated where
-- it occurs. This is technically known as Squirreling semantics.
-- Renaming is rewritten as a subprogram declaration, and the
-- generated body is inserted into the freeze actions for the
-- subprogram.
else
Decl :=
Make_Subprogram_Body (Loc,
Specification =>
Make_Function_Specification (Loc,
Defining_Unit_Name => Body_Id,
Parameter_Specifications => Copy_Parameter_List (Id),
Result_Definition =>
New_Occurrence_Of (Standard_Boolean, Loc)),
Declarations => Empty_List,
Handled_Statement_Sequence =>
Make_Handled_Sequence_Of_Statements (Loc,
Statements => New_List (
Make_Simple_Return_Statement (Loc,
Expression =>
Expand_Record_Equality
(Id,
Typ => Typ,
Lhs => Make_Identifier (Loc, Chars (Left)),
Rhs => Make_Identifier (Loc, Chars (Right)))))));
end if;
return Decl;
end Build_Body_For_Renaming;
-- Local variables
Nam : constant Node_Id := Name (N);
-- Start of processing for Expand_N_Subprogram_Renaming_Declaration
begin
-- When the prefix of the name is a function call, we must force the
-- call to be made by removing side effects from the call, since we
-- must only call the function once.
if Nkind (Nam) = N_Selected_Component
and then Nkind (Prefix (Nam)) = N_Function_Call
then
Remove_Side_Effects (Prefix (Nam));
-- For an explicit dereference, the prefix must be captured to prevent
-- reevaluation on calls through the renaming, which could result in
-- calling the wrong subprogram if the access value were to be changed.
elsif Nkind (Nam) = N_Explicit_Dereference then
Force_Evaluation (Prefix (Nam));
end if;
-- Handle cases where we build a body for a renamed equality
if Is_Entity_Name (Nam)
and then Chars (Entity (Nam)) = Name_Op_Eq
and then Scope (Entity (Nam)) = Standard_Standard
then
declare
Typ : constant Entity_Id := Etype (First_Formal (Id));
begin
-- Check whether this is a renaming of a predefined equality on an
-- untagged record type (AI05-0123).
if Ada_Version >= Ada_2012
and then Is_Record_Type (Typ)
and then not Is_Tagged_Type (Typ)
and then not Is_Frozen (Typ)
then
Append_Freeze_Action (Id, Build_Body_For_Renaming (Typ));
end if;
end;
end if;
end Expand_N_Subprogram_Renaming_Declaration;
end Exp_Ch8;
|
reznikmm/matreshka | Ada | 7,021 | 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.Insertion_Cut_Off_Elements is
------------
-- Create --
------------
overriding function Create
(Parameters : not null access Matreshka.DOM_Elements.Element_L2_Parameters)
return Table_Insertion_Cut_Off_Element_Node is
begin
return Self : Table_Insertion_Cut_Off_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_Insertion_Cut_Off_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_Insertion_Cut_Off
(ODF.DOM.Table_Insertion_Cut_Off_Elements.ODF_Table_Insertion_Cut_Off_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_Insertion_Cut_Off_Element_Node)
return League.Strings.Universal_String
is
pragma Unreferenced (Self);
begin
return Matreshka.ODF_String_Constants.Insertion_Cut_Off_Element;
end Get_Local_Name;
----------------
-- Leave_Node --
----------------
overriding procedure Leave_Node
(Self : not null access Table_Insertion_Cut_Off_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_Insertion_Cut_Off
(ODF.DOM.Table_Insertion_Cut_Off_Elements.ODF_Table_Insertion_Cut_Off_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_Insertion_Cut_Off_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_Insertion_Cut_Off
(Visitor,
ODF.DOM.Table_Insertion_Cut_Off_Elements.ODF_Table_Insertion_Cut_Off_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.Insertion_Cut_Off_Element,
Table_Insertion_Cut_Off_Element_Node'Tag);
end Matreshka.ODF_Table.Insertion_Cut_Off_Elements;
|
AdaCore/gpr | Ada | 22,620 | ads | ------------------------------------------------------------------------------
-- --
-- GPR2 PROJECT MANAGER --
-- --
-- Copyright (C) 2022-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/>. --
-- --
------------------------------------------------------------------------------
-- This package handles the command line options.
--
-- In particular this handles:
-- switch indexes in the form of --switch:index
-- switch parameters with various delimiters:
-- -P<param> and -P param
-- -P param only
-- -jnnn no space between switch and parameter
-- --foo=param or --foo param
-- switch sections, that is sections where switches handling is delegated
-- to a separate tool so is unknown. Such handling supports also to go
-- back to own section. For example:
-- gprbuild -cargs [gcc arguments] -gargs [back to gprbuild arguments]
-- Note that switch sections can support indexes:
-- gprbuild -cargs:ada [gnat1 specific arguments]
--
-- The switch definitions are handled by groups of switches to better
-- separate various functionality (such as project loading, autoconf,
-- verbosity or tool-specific switches).
--
-- From the command line definition, the parser issues a Usage string
-- when the tool is invoked with -h or --help, and a copyright/tool version
-- string when invoked with --version.
with GPR2.Containers;
private with Ada.Strings.Equal_Case_Insensitive;
private with Ada.Strings.Less_Case_Insensitive;
private with Ada.Strings.Unbounded;
private with Ada.Containers.Indefinite_Ordered_Maps;
private with Ada.Containers.Indefinite_Ordered_Sets;
package GPRtools.Command_Line is
Command_Line_Definition_Error : exception;
-- Raised when there's issues with the definition of switches in the
-- command line parser.
type Switch_Type is new String
with Dynamic_Predicate =>
Switch_Type'Length > 0
and then Switch_Type (Switch_Type'First) = '-';
------------------------------------
-- COMMAND LINE RESULT DEFINITION --
------------------------------------
type Command_Line_Result is interface;
function Remaining_Arguments
(Result : Command_Line_Result)
return GPR2.Containers.Value_List is abstract;
procedure Append_Argument
(Result : in out Command_Line_Result;
Value : GPR2.Value_Type) is abstract;
--------------------------------------
-- COMMAND LINE ARGUMENT DEFINITION --
--------------------------------------
type Argument_Definition is private;
-- Definition of a command line argument
type Argument_Parameter_Delimiter is
(None, Space, Optional_Space, Equal);
-- Delimiter to be used between a switch and its parameter if expected.
--
-- None: switch and argument are aggregated (for example -gnatwa)
-- Space: blank space between switch and argument (-P project)
-- Optional_Space: space or argument immediately following the switch
-- Equal: equal sign or space
function Is_Defined (Def : Argument_Definition) return Boolean;
function Name (Def : Argument_Definition) return Switch_Type
with Pre => Is_Defined (Def);
function Has_Alt_Name (Def : Argument_Definition) return Boolean
with Pre => Is_Defined (Def);
function Alt_Name (Def : Argument_Definition) return Switch_Type
with Pre => Has_Alt_Name (Def);
function Create
(Name : Switch_Type;
Help : String;
Index : String := "";
In_Switch_Attr : Boolean := True;
Hidden : Boolean := False)
return Argument_Definition;
-- Argument definition without parameter or alternative name.
--
-- Name: is the argument (for example "-A", "-switch" or "--switch")
-- Help: is the description of the switch displayed in the Usage
-- Index: when not empty, indicates that the switch accepts indexes.
-- Indexes are separated from the argument via a colon (for example
-- "-switch:ada"). The value of the Index parameter is used in the Usage
-- string.
-- In_Switch_Attr: whether the argument is allowed in a Package'Switch
-- attribute definition.
-- Hidden: when set, the attribute definition won't be displayed in the
-- Usage string.
function Create
(Name : Switch_Type;
Alt_Name : Switch_Type;
Help : String;
Index : String := "";
In_Switch_Attr : Boolean := True;
Hidden : Boolean := False)
return Argument_Definition;
-- Argument definition without parameter, Allows setting t2o switches
-- for the same action, for example -h and --help.
--
-- Name: is the argument (for example "-A", "-switch" or "--switch")
-- Alt_Name: an alternative name for the switch (for example "-s",
-- "--switch"). Note : argument callback is always called using Name as
-- argument.
-- Help: is the description of the switch displayed in the Usage
-- Index: when not empty, indicates that the switch accepts indexes.
-- Indexes are separated from the argument via a colon (for example
-- "-switch:ada"). The value of the Index parameter is used in the Usage
-- string.
-- In_Switch_Attr: whether the argument is allowed in a Package'Switch
-- attribute definition.
-- Hidden: when set, the attribute definition won't be displayed in the
-- Usage string.
function Create
(Name : Switch_Type;
Help : String;
Delimiter : Argument_Parameter_Delimiter;
Parameter : String := "ARG";
Default : String := "";
Required : Boolean := False;
Index : String := "";
In_Switch_Attr : Boolean := True;
Hidden : Boolean := False)
return Argument_Definition;
-- Argument definition with parameter
function Create
(Name : Switch_Type;
Alt_Name : Switch_Type;
Help : String;
Delimiter : Argument_Parameter_Delimiter;
Parameter : String := "ARG";
Default : String := "";
Required : Boolean := False;
Index : String := "";
In_Switch_Attr : Boolean := True;
Hidden : Boolean := False)
return Argument_Definition;
-- Argument definition with parameter and alternate name
-------------------------------
-- ARGUMENT GROUP DEFINITION --
-------------------------------
type Argument_Group is private;
-- An argument group displays together conceptually related arguments
-- in the Usage display.
-- Mutually_Exclusive argument groups on the other hand identifies
-- arguments or groups of arguments that are mutually exclusive.
No_Group : constant Argument_Group;
-------------------------
-- COMMAND LINE PARSER --
-------------------------
type Command_Line_Parser is tagged private;
type Argument_Action is access procedure
(Parser : Command_Line_Parser'Class;
Result : not null access Command_Line_Result'Class;
Arg : Switch_Type;
Index : String;
Param : String);
-- Callback when parsing a new known argument.
--
-- Parser: the parser being used to parse the command line
-- Result: the structure holding the result
-- Arg: the primary name of the switch
-- Index: the switch index, if any, or the empty string
-- Param: the switch parameter, if any, or the empty string.
type Section_Action is access procedure
(Parser : Command_Line_Parser'Class;
Result : not null access Command_Line_Result'Class;
Section : String;
Index : String;
Arg : Switch_Type);
-- Callback when an argument for an external section is founc.
--
-- Parser: the parser being used to parse the command line
-- Result: the structure holding the result
-- Section: the switch used to delimit a new section
-- Index: if defined for the switch, or the empty string
-- Arg: the argument to handle
function Is_Defined (Self : Command_Line_Parser) return Boolean;
function Create
(Initial_Year : String;
Cmd_Line : String := "";
Tool_Name : String := "";
Help : String := "") return Command_Line_Parser'Class
with Post => Create'Result.Is_Defined;
-- Initialize internal structures and sets values for version and help
-- arguments
function Main_Group
(Self : in out Command_Line_Parser) return Argument_Group
with Pre => Self.Is_Defined;
function Has_Group
(Self : Command_Line_Parser;
Name : GPR2.Name_Type) return Boolean
with Pre => Self.Is_Defined;
function Group
(Self : Command_Line_Parser;
Name : GPR2.Name_Type) return Argument_Group
with
Pre => Self.Is_Defined,
Post => (if Self.Has_Group (Name)
then Group'Result /= No_Group
else Group'Result = No_Group);
procedure Version (Self : Command_Line_Parser)
with Pre => Self.Is_Defined;
-- Displays the version string. This is automatically called when --version
-- is found in the command line.
procedure Usage (Self : Command_Line_Parser)
with Pre => Self.Is_Defined;
-- Displays the usage string. This is automatically called when -h or
-- --help is found in the command line.
procedure Try_Help;
-- Displays 'try "<tool> --help" for more information'. Typically called
-- when catching a Usage_Error exception.
procedure Get_Opt
(Self : Command_Line_Parser;
Result : in out Command_Line_Result'Class)
with Pre => Self.Is_Defined;
-- Parse the command line from Ada.Command_Line
procedure Get_Opt
(Self : Command_Line_Parser;
From_Pack : GPR2.Package_Id;
Values : GPR2.Containers.Source_Value_List;
Result : in out Command_Line_Result'Class);
-- Parse the command line from an attribute value (typically the Switches
-- attribute).
function Has_Argument
(Self : Command_Line_Parser;
Name : Switch_Type) return Boolean
with Pre => Self.Is_Defined;
procedure Add_Argument
(Self : in out Command_Line_Parser;
Group : Argument_Group;
Def : Argument_Definition)
with Pre => not Self.Has_Argument (Name (Def))
and then (not Has_Alt_Name (Def)
or else not Self.Has_Argument (Alt_Name (Def)));
-- Add an argument definition to the new argument group
function Add_Argument_Group
(Self : in out Command_Line_Parser;
Name : GPR2.Name_Type;
Callback : Argument_Action;
Help : String := "";
Last : Boolean := False) return Argument_Group
with Pre => not Self.Has_Group (Name);
-- Add a new Argument group.
--
-- Name: the name of the group. Will be displayed in the Usage string as
-- " <group> switches:"
-- followed by the group's switches definition unless the name is prefixed
-- with an underscore.
-- Callback: the subprogram to call whenever a switch of the group is
-- found in the command line.
-- Help: if not empty, is displayed before the list of the group's switches
-- in the usage string.
-- Last: two series of groups are defined, regular ones and last ones. If
-- set, the group is appended to the last ones else it is appended to
-- regular ones. The regular groups are displayed before the last groups
-- in the usage string.
procedure Add_Section_Argument
(Self : in out Command_Line_Parser;
Name : Switch_Type;
Alt_Name : Switch_Type;
Callback : Section_Action;
Help : String := "";
Index : String := "";
In_Switch_Attr : Boolean := True)
with Pre => not Self.Has_Argument (Name)
and then not Self.Has_Argument (Alt_Name);
-- Add a new section argument. Such argument instruct the parser that
-- the switches after that are meant for a different tool, so should
-- not be handled by the parser but be preserved as-is without
-- analysis.
-- If Index is not empty, then the section accepts an index parameter
-- in the form -switch:index.
-- If Callback is null, this instructs the parser that the new section
-- is back to default, so that following switches need to be parsed
-- normally. Only one such section can be defined.
procedure Add_Section_Argument
(Self : in out Command_Line_Parser;
Name : Switch_Type;
Callback : Section_Action;
Help : String := "";
Index : String := "";
In_Switch_Attr : Boolean := True)
with Pre => not Self.Has_Argument (Name);
private
use Ada;
use Ada.Strings.Unbounded;
function To_Unbounded_String (S : Switch_Type) return Unbounded_String
is (To_Unbounded_String (String (S)));
type Argument_Group is new Unbounded_String;
No_Group : constant Argument_Group :=
Argument_Group (Null_Unbounded_String);
type Argument_Definition (With_Value : Boolean := False) is record
Name : Unbounded_String;
Alt_Name : Unbounded_String;
Group : Argument_Group;
Help : Unbounded_String;
Index : Unbounded_String;
In_Attr : Boolean := True;
Hidden : Boolean := False;
case With_Value is
when False =>
Is_Section : Boolean := False;
Section_Callback : Section_Action;
when True =>
Parameter : Unbounded_String;
Delimiter : Argument_Parameter_Delimiter;
Default : Unbounded_String;
Required : Boolean := False;
end case;
end record;
function Is_Defined (Def : Argument_Definition) return Boolean is
(Def /= Argument_Definition'(others => <>));
function Name (Def : Argument_Definition) return Switch_Type is
(Switch_Type (To_String (Def.Name)));
function Has_Alt_Name (Def : Argument_Definition) return Boolean is
(Length (Def.Alt_Name) > 0);
function Alt_Name (Def : Argument_Definition) return Switch_Type is
(Switch_Type (To_String (Def.Alt_Name)));
------------
-- Create --
------------
function Create
(Name : Switch_Type;
Help : String;
Index : String := "";
In_Switch_Attr : Boolean := True;
Hidden : Boolean := False) return Argument_Definition
is (Argument_Definition'(With_Value => False,
Name => To_Unbounded_String (Name),
Alt_Name => Null_Unbounded_String,
Group => No_Group,
Help => To_Unbounded_String (Help),
Index => To_Unbounded_String (Index),
In_Attr => In_Switch_Attr,
Hidden => Hidden,
Is_Section => False,
Section_Callback => null));
function Create
(Name : Switch_Type;
Alt_Name : Switch_Type;
Help : String;
Index : String := "";
In_Switch_Attr : Boolean := True;
Hidden : Boolean := False) return Argument_Definition
is (Argument_Definition'(With_Value => False,
Name => To_Unbounded_String (Name),
Alt_Name => To_Unbounded_String (Alt_Name),
Group => No_Group,
Help => To_Unbounded_String (Help),
Index => To_Unbounded_String (Index),
In_Attr => In_Switch_Attr,
Hidden => Hidden,
Is_Section => False,
Section_Callback => null));
function Create
(Name : Switch_Type;
Help : String;
Delimiter : Argument_Parameter_Delimiter;
Parameter : String := "ARG";
Default : String := "";
Required : Boolean := False;
Index : String := "";
In_Switch_Attr : Boolean := True;
Hidden : Boolean := False) return Argument_Definition
is (Argument_Definition'(With_Value => True,
Name => To_Unbounded_String (Name),
Alt_Name => Null_Unbounded_String,
Group => No_Group,
Help => To_Unbounded_String (Help),
Index => To_Unbounded_String (Index),
In_Attr => In_Switch_Attr,
Hidden => Hidden,
Parameter => To_Unbounded_String (Parameter),
Delimiter => Delimiter,
Default => To_Unbounded_String (Default),
Required => Required));
function Create
(Name : Switch_Type;
Alt_Name : Switch_Type;
Help : String;
Delimiter : Argument_Parameter_Delimiter;
Parameter : String := "ARG";
Default : String := "";
Required : Boolean := False;
Index : String := "";
In_Switch_Attr : Boolean := True;
Hidden : Boolean := False) return Argument_Definition
is (Argument_Definition'(With_Value => True,
Name => To_Unbounded_String (Name),
Alt_Name => To_Unbounded_String (Alt_Name),
Group => No_Group,
Help => To_Unbounded_String (Help),
Index => To_Unbounded_String (Index),
In_Attr => In_Switch_Attr,
Hidden => Hidden,
Parameter => To_Unbounded_String (Parameter),
Delimiter => Delimiter,
Default => To_Unbounded_String (Default),
Required => Required));
function Dash_Dash
(S : Switch_Type) return Boolean
is (if S'Length > 2 then S (S'First .. S'First + 1) = "--" else False);
function Arg_Less (S1, S2 : Switch_Type) return Boolean is
(if Dash_Dash (S1) /= Dash_Dash (S2)
then not Dash_Dash (S1)
elsif Strings.Equal_Case_Insensitive (String (S1), String (S2))
then S1 < S2
else Strings.Less_Case_Insensitive (String (S1), String (S2)));
-- We use case insensitive sort for displaying the switches in the
-- usage string, but switch comparison is always case sensitive.
package Switches_Sets is new Ada.Containers.Indefinite_Ordered_Sets
(Switch_Type, "<" => Arg_Less);
package Switches_Maps is new Ada.Containers.Indefinite_Ordered_Maps
(Switch_Type, Switch_Type);
type Argument_Group_Internal is record
Help : Unbounded_String;
Switches : Switches_Sets.Set;
Callback : Argument_Action;
Subgroups : GPR2.Containers.Name_List;
Last_Subgroups : GPR2.Containers.Name_List;
Exclusive : Boolean;
Required : Boolean;
end record;
package Group_Maps is new Ada.Containers.Indefinite_Ordered_Maps
(GPR2.Name_Type, Argument_Group_Internal, "<" => GPR2."<");
package Arg_Maps is new Ada.Containers.Indefinite_Ordered_Maps
(Switch_Type, Argument_Definition, Arg_Less);
type Command_Line_Parser is tagged record
Groups : Group_Maps.Map;
Cmd_Line_Help : Unbounded_String;
Tool : Unbounded_String;
Initial_Year : Unbounded_String;
Help : Unbounded_String;
Default_Section : Unbounded_String;
Switches : Arg_Maps.Map;
Aliases : Switches_Maps.Map;
end record;
function Add_Argument_Group
(Self : in out Command_Line_Parser;
Group : Argument_Group;
Name : GPR2.Name_Type;
Callback : Argument_Action;
Help : String := "";
Last : Boolean := False) return Argument_Group;
-- Add a subgroup to an existing group
function Add_Mutually_Exclusive_Argument_Group
(Self : in out Command_Line_Parser;
Group : Argument_Group;
Name : GPR2.Name_Type;
Help : String := "";
Required : Boolean := False) return Argument_Group;
function Is_Defined (Self : Command_Line_Parser) return Boolean is
(Self /= Command_Line_Parser'(others => <>));
function Has_Group
(Self : Command_Line_Parser;
Name : GPR2.Name_Type) return Boolean
is (Self.Groups.Contains (Name));
function Group
(Self : Command_Line_Parser;
Name : GPR2.Name_Type) return Argument_Group
is (if Self.Groups.Contains (Name)
then To_Unbounded_String (String (Name))
else No_Group);
function Main_Group
(Self : in out Command_Line_Parser) return Argument_Group
is (To_Unbounded_String ("_root"));
function Has_Argument
(Self : Command_Line_Parser;
Name : Switch_Type) return Boolean
is (Self.Switches.Contains (Name));
end GPRtools.Command_Line;
|
charlie5/cBound | Ada | 1,378 | 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_glx_is_enabled_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_glx_is_enabled_cookie_t
.Item;
-- Pointer
--
package C_Pointers is new Interfaces.C.Pointers
(Index => Interfaces.C.size_t,
Element => xcb.xcb_glx_is_enabled_cookie_t.Item,
Element_Array => xcb.xcb_glx_is_enabled_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_glx_is_enabled_cookie_t
.Pointer;
-- Pointer_Pointer
--
package C_Pointer_Pointers is new Interfaces.C.Pointers
(Index => Interfaces.C.size_t,
Element => xcb.xcb_glx_is_enabled_cookie_t.Pointer,
Element_Array => xcb.xcb_glx_is_enabled_cookie_t.Pointer_Array,
Default_Terminator => null);
subtype Pointer_Pointer is C_Pointer_Pointers.Pointer;
end xcb.xcb_glx_is_enabled_cookie_t;
|
AdaCore/Ada_Drivers_Library | Ada | 3,367 | ads | ------------------------------------------------------------------------------
-- --
-- Copyright © AdaCore and other contributors, 2017-2020 --
-- See https://github.com/AdaCore/Ada_Drivers_Library/graphs/contributors --
-- for more information --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions are --
-- met: --
-- 1. Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- 2. Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in --
-- the documentation and/or other materials provided with the --
-- distribution. --
-- 3. Neither the name of the copyright holder nor the names of its --
-- contributors may be used to endorse or promote products derived --
-- from this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT --
-- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, --
-- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY --
-- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT --
-- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE --
-- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
with HAL; use HAL;
package nRF.ADC is
type Bits_Resolution is (Res_8bit, Res_10bit, Res_12bit);
type Analog_Pin is range 0 .. 7;
type Pin_Input_Selection is (Pin_Quadruple, Pin_Double, Pin_Full, Pin_Half,
Pin_One_Third, Pin_One_Forth, Pin_One_Fifth,
Pin_One_Sixth);
type VDD_Input_Selection is (VDD_One_Fifth, VDD_One_Sixth);
type Reference_Selection is (Internal_0V6, VDD_One_Forth);
function Do_Pin_Conversion
(Pin : Analog_Pin;
Input : Pin_Input_Selection;
Ref : Reference_Selection;
Res : Bits_Resolution) return UInt16;
function Do_VDD_Conversion
(Input : VDD_Input_Selection;
Ref : Reference_Selection;
Res : Bits_Resolution) return UInt16;
function Busy return Boolean;
end nRF.ADC;
|
muharihar/Amass | Ada | 1,474 | ads | -- Copyright 2017-2021 Jeff Foley. All rights reserved.
-- Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
local json = require("json")
name = "ReconDev"
type = "api"
function start()
set_rate_limit(5)
end
function check()
local c
local cfg = datasrc_config()
if cfg ~= nil then
c = cfg.credentials
end
if (c ~= nil and c.key ~= nil and c.key ~= "") then
return true
end
return false
end
function vertical(ctx, domain)
local c
local cfg = datasrc_config()
if cfg ~= nil then
c = cfg.credentials
end
if (c == nil or c.key == nil or c.key == "") then
return
end
local resp, err = request(ctx, {['url']=build_url(domain, c.key)})
if (err ~= nil and err ~= "") then
log(ctx, "vertical request to service failed: " .. err)
return
end
local data = json.decode(resp)
if (data == nil or #data == 0) then
return
end
for i, set in pairs(data) do
local domains = set["rawDomains"]
if domains ~= nil and #domains > 0 then
for _, name in pairs(domains) do
new_name(ctx, name)
end
end
local addr = set["rawIp"]
if addr ~= nil then
new_addr(ctx, addr, domain)
end
end
end
function build_url(domain, key)
return "https://recon.dev/api/search?key=" .. key .. "&domain=" .. domain
end
|
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.Dr3d_Vup_Attributes;
package Matreshka.ODF_Dr3d.Vup_Attributes is
type Dr3d_Vup_Attribute_Node is
new Matreshka.ODF_Dr3d.Abstract_Dr3d_Attribute_Node
and ODF.DOM.Dr3d_Vup_Attributes.ODF_Dr3d_Vup_Attribute
with null record;
overriding function Create
(Parameters : not null access Matreshka.DOM_Attributes.Attribute_L2_Parameters)
return Dr3d_Vup_Attribute_Node;
overriding function Get_Local_Name
(Self : not null access constant Dr3d_Vup_Attribute_Node)
return League.Strings.Universal_String;
end Matreshka.ODF_Dr3d.Vup_Attributes;
|
BrickBot/Bound-T-H8-300 | Ada | 7,302 | ads | -- Calling.Single_Cell (decl)
--
-- Calling protocols that depend on the value of a single cell.
--
-- 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.4 $
-- $Date: 2015/10/24 19:36:48 $
--
-- $Log: calling-single_cell.ads,v $
-- Revision 1.4 2015/10/24 19:36:48 niklas
-- Moved to free licence.
--
-- Revision 1.3 2009-11-27 11:28:07 niklas
-- BT-CH-0184: Bit-widths, Word_T, failed modular analysis.
--
-- Revision 1.2 2005/03/04 09:40:21 niklas
-- Added the new primitive operations Static_Caller_Cell and
-- Dynamic_Caller_Cell, and added a default implementation of
-- Caller_Cell that makes use of them.
--
-- Revision 1.1 2005/02/23 09:05:16 niklas
-- BT-CH-0005.
--
with Arithmetic;
with Storage;
with Storage.Bounds;
package Calling.Single_Cell is
type Protocol_T is abstract new Calling.Protocol_T with record
Cell : Storage.Cell_T;
Interval : Storage.Bounds.Interval_T :=
Storage.Bounds.Universal_Interval;
end record;
--
-- A class of calling protocols for which dynamic cell mapping
-- depends only on the value of one Cell in the caller at the point
-- of call. For example, this cell might be the local stack height.
--
-- The protocol can be constrained by bounding the value of the Cell
-- using an Interval_T. The protocol is static if the Interval defines
-- a single value, that is, if Storage.Bounds.Singular (Interval)
-- is True.
--
-- The initial value for Interval may be reduced if there is good
-- reason. For example, if the Cell is a stack-height, then it should
-- have only non-negative values.
type Protocol_Ref is access all Protocol_T'Class;
--
-- A reference to a single-cell-protocol object on the heap.
function Static (Item : Protocol_T) return Boolean;
--
-- True if Item.Interval allows a single value for Interval.Cell.
--
-- Overrides (implements) Storage.Bounds.Static.
function Basis (Item : Protocol_T) return Storage.Cell_List_T;
--
-- Returns the Item.Cell, or a null list if the protocol is constrained
-- to be static.
--
-- Overrides (implements) Storage.Bounds.Basis.
function Image (Item : Protocol_T) return String;
--
-- Returns "Single_Cell" and the Image of Item.Interval as
-- bounds on Item.Cell.
function Static_Caller_Cell (
Callee : Storage.Cell_T;
Under : Protocol_T)
return Storage.Cell_T;
--
-- The caller-frame cell that is associated with (describes the
-- same data-location as) the given callee-frame cell, Under the
-- given calling protocol when the Callee has a Static Map_Kind.
--
-- This is a new primitive operation for Protocol_T, not inherited
-- from the parent type. This operation is used in the default
-- implementation of the inherited Caller_Cell function, see below.
--
-- The default implementation emits a Fault and raises Program_Error.
-- This is not a working implementation but it means that derived
-- types that override the inherited Caller_Cell function and have
-- no need for this new Static_Caller_Cell function do not have to
-- provide another implementation of this new function.
function Dynamic_Caller_Cell (
Callee : Storage.Cell_T;
Under : Protocol_T;
Value : Arithmetic.Value_T)
return Storage.Cell_T;
--
-- The caller-frame cell that is associated with (describes the
-- same data-location as) the given callee-frame cell, Under the
-- given calling protocol when the Value of Under.Cell is known.
--
-- This is a new primitive operation for Protocol_T, not inherited
-- from the parent type. This operation is used in the default
-- implementation of the inherited Caller_Cell function, see below.
--
-- The default implementation emits a Fault and raises Program_Error.
-- This is not a working implementation but it means that derived
-- types that override the inherited Caller_Cell function and have
-- no need for this new Dynamic_Caller_Cell function do not have to
-- provide another implementation of this new function.
function Caller_Cell (
Callee : Storage.Cell_T;
Under : Protocol_T)
return Storage.Cell_T;
--
-- The caller-frame cell that is associated with (describes the
-- same data-location as) the given callee-frame cell, Under the
-- given calling protocol.
--
-- The default implementation works as follows:
--
-- > if the Callee cell has a Dynamic mapping:
--
-- if Under.Interval constrains Under.Cell to a single value
-- return Dynamic_Caller_Cell (Callee, Under, Value),
-- with redispatching on Under
-- else
-- return No_Cell (unbounded)
--
-- > else if the Callee cell has a Static mapping:
--
-- return Static_Caller_Cell (Callee, Under)
-- with redispatching on Under
--
-- > else return the Callee unchanged.
--
-- Overrides (implements) Calling.Caller_Cell.
procedure Apply (
Bounds : in Storage.Bounds.Bounds_T'Class;
Upon : in Protocol_T;
Giving : out Calling.Protocol_Ref);
--
-- Uses the Bounds on Upon.Cell to constrain Upon.Interval 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.Interval further.
--
-- Overrides (implements) Calling.Apply.
end Calling.Single_Cell;
|
AdaCore/training_material | Ada | 2,154 | ads | pragma Ada_2005;
pragma Style_Checks (Off);
with Interfaces.C; use Interfaces.C;
with SDL_SDL_stdinc_h;
with SDL_SDL_keysym_h;
with Interfaces.C.Strings;
package SDL_SDL_keyboard_h is
SDL_ALL_HOTKEYS : constant := 16#FFFFFFFF#; -- ../include/SDL/SDL_keyboard.h:67
SDL_DEFAULT_REPEAT_DELAY : constant := 500; -- ../include/SDL/SDL_keyboard.h:84
SDL_DEFAULT_REPEAT_INTERVAL : constant := 30; -- ../include/SDL/SDL_keyboard.h:85
type SDL_keysym is record
scancode : aliased SDL_SDL_stdinc_h.Uint8; -- ../include/SDL/SDL_keyboard.h:60
sym : aliased SDL_SDL_keysym_h.SDLKey; -- ../include/SDL/SDL_keyboard.h:61
c_mod : aliased SDL_SDL_keysym_h.SDLMod; -- ../include/SDL/SDL_keyboard.h:62
unicode : aliased SDL_SDL_stdinc_h.Uint16; -- ../include/SDL/SDL_keyboard.h:63
end record;
pragma Convention (C_Pass_By_Copy, SDL_keysym); -- ../include/SDL/SDL_keyboard.h:59
function SDL_EnableUNICODE (enable : int) return int; -- ../include/SDL/SDL_keyboard.h:82
pragma Import (C, SDL_EnableUNICODE, "SDL_EnableUNICODE");
function SDL_EnableKeyRepeat (c_delay : int; interval : int) return int; -- ../include/SDL/SDL_keyboard.h:98
pragma Import (C, SDL_EnableKeyRepeat, "SDL_EnableKeyRepeat");
procedure SDL_GetKeyRepeat (c_delay : access int; interval : access int); -- ../include/SDL/SDL_keyboard.h:99
pragma Import (C, SDL_GetKeyRepeat, "SDL_GetKeyRepeat");
function SDL_GetKeyState (numkeys : access int) return access SDL_SDL_stdinc_h.Uint8; -- ../include/SDL/SDL_keyboard.h:110
pragma Import (C, SDL_GetKeyState, "SDL_GetKeyState");
function SDL_GetModState return SDL_SDL_keysym_h.SDLMod; -- ../include/SDL/SDL_keyboard.h:115
pragma Import (C, SDL_GetModState, "SDL_GetModState");
procedure SDL_SetModState (modstate : SDL_SDL_keysym_h.SDLMod); -- ../include/SDL/SDL_keyboard.h:121
pragma Import (C, SDL_SetModState, "SDL_SetModState");
function SDL_GetKeyName (key : SDL_SDL_keysym_h.SDLKey) return Interfaces.C.Strings.chars_ptr; -- ../include/SDL/SDL_keyboard.h:126
pragma Import (C, SDL_GetKeyName, "SDL_GetKeyName");
end SDL_SDL_keyboard_h;
|
hbarrientosg/cs-mp | Ada | 1,262 | adb | separate(practica4)--funcion para saber que esta separado
--del fichero de prueba
procedure Separar(R_Total: in Unbounded_String;
R_Letra: out Unbounded_String;
R_numer: out Unbounded_String) is
Todo:constant string:=" ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
--Es la ristra que se va a comparar para las subristras
s,N:Natural;
carac:Unbounded_string;
begin
s:=length(r_total);--Aqui va la longitud de la ristra r_total
for i in 1..s loop
carac:=to_unbounded_string(slice(r_total,i,i));
N:=index(to_unbounded_string(todo),to_string(carac));
if N > 1 and N < 53 then-- si esta en el rango entonces es un caracter de letra
r_Letra:=r_Letra & carac;
else
if N > 52 then-- si no es el caracter letra es un caracter numero que se encuentra a
-- partir de la posicion 53 y lo concateno en la ristra de numeros
r_numer:=r_numer & carac;
else-- si no es ninguno de los dos casos entonces el index vale 1 y es el caracter espacio
--en blanco y lo concateno en las dos ristras
if n=1 then
r_numer:=r_numer & carac;
r_Letra:=r_Letra & carac;
end if;
end if;--en caso de que el caracter no sea los que estan en la ristra se deshechara
end if;
end loop;
return;
end separar;
|
persan/A-gst | Ada | 30,133 | ads | pragma Ada_2005;
pragma Style_Checks (Off);
pragma Warnings (Off);
with Interfaces.C; use Interfaces.C;
with glib;
with glib;
with glib.Values;
with System;
with System;
with GLIB; -- with GStreamer.GST_Low_Level.glibconfig_h;
limited with GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstcaps_h;
limited with GStreamer.GST_Low_Level.gstreamer_0_10_gst_gststructure_h;
-- limited with GStreamer.GST_Low_Level.glib_2_0_glib_gdate_h;
package GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstvalue_h is
-- arg-macro: function GST_MAKE_FOURCC (a, b, c, d)
-- return (guint32)((a)or(b)<<8or(c)<<16or(d)<<24);
-- arg-macro: function GST_STR_FOURCC (f)
-- return (guint32)(((f)(0))or((f)(1)<<8)or((f)(2)<<16)or((f)(3)<<24));
GST_FOURCC_FORMAT : aliased constant String := "c%c%c%c" & ASCII.NUL; -- gst/gstvalue.h:73
-- arg-macro: function GST_FOURCC_ARGS (fourcc)
-- return (gchar) ((fourcc) and16#ff#)), ((gchar) (((fourcc)>>8 )and16#ff#)), ((gchar) (((fourcc)>>16)and16#ff#)), ((gchar) (((fourcc)>>24)and16#ff#);
-- arg-macro: function GST_VALUE_HOLDS_FOURCC (x)
-- return G_VALUE_HOLDS((x), gst_fourcc_get_type ());
-- arg-macro: function GST_VALUE_HOLDS_INT_RANGE (x)
-- return G_VALUE_HOLDS((x), gst_int_range_get_type ());
-- arg-macro: function GST_VALUE_HOLDS_INT64_RANGE (x)
-- return G_VALUE_HOLDS((x), gst_int64_range_get_type ());
-- arg-macro: function GST_VALUE_HOLDS_DOUBLE_RANGE (x)
-- return G_VALUE_HOLDS((x), gst_double_range_get_type ());
-- arg-macro: function GST_VALUE_HOLDS_FRACTION_RANGE (x)
-- return G_VALUE_HOLDS((x), gst_fraction_range_get_type ());
-- arg-macro: function GST_VALUE_HOLDS_LIST (x)
-- return G_VALUE_HOLDS((x), gst_value_list_get_type ());
-- arg-macro: function GST_VALUE_HOLDS_ARRAY (x)
-- return G_VALUE_HOLDS((x), gst_value_array_get_type ());
-- arg-macro: function GST_VALUE_HOLDS_CAPS (x)
-- return G_VALUE_HOLDS((x), GST_TYPE_CAPS);
-- arg-macro: function GST_VALUE_HOLDS_STRUCTURE (x)
-- return G_VALUE_HOLDS((x), GST_TYPE_STRUCTURE);
-- arg-macro: function GST_VALUE_HOLDS_BUFFER (x)
-- return G_VALUE_HOLDS((x), GST_TYPE_BUFFER);
-- arg-macro: function GST_VALUE_HOLDS_FRACTION (x)
-- return G_VALUE_HOLDS((x), gst_fraction_get_type ());
-- arg-macro: function GST_VALUE_HOLDS_DATE (x)
-- return G_VALUE_HOLDS((x), gst_date_get_type ());
-- arg-macro: function GST_VALUE_HOLDS_DATE_TIME (x)
-- return G_VALUE_HOLDS((x), gst_date_time_get_type ());
-- unsupported macro: GST_TYPE_FOURCC gst_fourcc_get_type ()
-- unsupported macro: GST_TYPE_INT_RANGE gst_int_range_get_type ()
-- unsupported macro: GST_TYPE_INT64_RANGE gst_int64_range_get_type ()
-- unsupported macro: GST_TYPE_DOUBLE_RANGE gst_double_range_get_type ()
-- unsupported macro: GST_TYPE_FRACTION_RANGE gst_fraction_range_get_type ()
-- unsupported macro: GST_TYPE_LIST gst_value_list_get_type ()
-- unsupported macro: GST_TYPE_ARRAY gst_value_array_get_type ()
-- unsupported macro: GST_TYPE_FRACTION gst_fraction_get_type ()
-- unsupported macro: GST_TYPE_DATE gst_date_get_type ()
-- unsupported macro: GST_TYPE_DATE_TIME gst_date_time_get_type ()
GST_VALUE_LESS_THAN : constant := (-1); -- gst/gstvalue.h:310
GST_VALUE_EQUAL : constant := 0; -- gst/gstvalue.h:318
GST_VALUE_GREATER_THAN : constant := 1; -- gst/gstvalue.h:326
GST_VALUE_UNORDERED : constant := 2; -- gst/gstvalue.h:334
-- GStreamer
-- * Copyright (C) <2003> David A. Schleef <[email protected]>
-- *
-- * This library is free software; you can redistribute it and/or
-- * modify it under the terms of the GNU Library General Public
-- * License as published by the Free Software Foundation; either
-- * version 2 of the License, or (at your option) any later version.
-- *
-- * This library is distributed in the hope that it will be useful,
-- * but WITHOUT ANY WARRANTY; without even the implied warranty of
-- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-- * Library General Public License for more details.
-- *
-- * You should have received a copy of the GNU Library General Public
-- * License along with this library; if not, write to the
-- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-- * Boston, MA 02111-1307, USA.
--
--*
-- * GST_MAKE_FOURCC:
-- * @a: the first character
-- * @b: the second character
-- * @c: the third character
-- * @d: the fourth character
-- *
-- * Transform four characters into a #guint32 fourcc value with host
-- * endianness.
-- * <informalexample>
-- * <programlisting>
-- * guint32 fourcc = GST_MAKE_FOURCC ('M', 'J', 'P', 'G');
-- * </programlisting>
-- * </informalexample>
--
--*
-- * GST_STR_FOURCC:
-- * @f: a string with at least four characters
-- *
-- * Transform an input string into a #guint32 fourcc value with host
-- * endianness.
-- * Caller is responsible for ensuring the input string consists of at least
-- * four characters.
-- * <informalexample>
-- * <programlisting>
-- * guint32 fourcc = GST_STR_FOURCC ("MJPG");
-- * </programlisting>
-- * </informalexample>
--
--*
-- * GST_FOURCC_FORMAT:
-- *
-- * Can be used together with #GST_FOURCC_ARGS to properly output a
-- * #guint32 fourcc value in a printf()-style text message.
-- * <informalexample>
-- * <programlisting>
-- * printf ("fourcc: %" GST_FOURCC_FORMAT "\n", GST_FOURCC_ARGS (fcc));
-- * </programlisting>
-- * </informalexample>
--
--*
-- * GST_FOURCC_ARGS:
-- * @fourcc: a #guint32 fourcc value to output
-- *
-- * Can be used together with #GST_FOURCC_FORMAT to properly output a
-- * #guint32 fourcc value in a printf()-style text message.
--
--*
-- * GST_VALUE_HOLDS_FOURCC:
-- * @x: the #GValue to check
-- *
-- * Checks if the given #GValue contains a #GST_TYPE_FOURCC value.
--
--*
-- * GST_VALUE_HOLDS_INT_RANGE:
-- * @x: the #GValue to check
-- *
-- * Checks if the given #GValue contains a #GST_TYPE_INT_RANGE value.
--
--*
-- * GST_VALUE_HOLDS_INT64_RANGE:
-- * @x: the #GValue to check
-- *
-- * Checks if the given #GValue contains a #GST_TYPE_INT64_RANGE value.
-- *
-- * Since: 0.10.31
--
--*
-- * GST_VALUE_HOLDS_DOUBLE_RANGE:
-- * @x: the #GValue to check
-- *
-- * Checks if the given #GValue contains a #GST_TYPE_DOUBLE_RANGE value.
--
--*
-- * GST_VALUE_HOLDS_FRACTION_RANGE:
-- * @x: the #GValue to check
-- *
-- * Checks if the given #GValue contains a #GST_TYPE_FRACTION_RANGE value.
--
--*
-- * GST_VALUE_HOLDS_LIST:
-- * @x: the #GValue to check
-- *
-- * Checks if the given #GValue contains a #GST_TYPE_LIST value.
--
--*
-- * GST_VALUE_HOLDS_ARRAY:
-- * @x: the #GValue to check
-- *
-- * Checks if the given #GValue contains a #GST_TYPE_ARRAY value.
--
--*
-- * GST_VALUE_HOLDS_CAPS:
-- * @x: the #GValue to check
-- *
-- * Checks if the given #GValue contains a #GST_TYPE_CAPS value.
--
--*
-- * GST_VALUE_HOLDS_STRUCTURE:
-- * @x: the #GValue to check
-- *
-- * Checks if the given #GValue contains a #GST_TYPE_STRUCTURE value.
-- *
-- * Since: 0.10.15
--
--*
-- * GST_VALUE_HOLDS_BUFFER:
-- * @x: the #GValue to check
-- *
-- * Checks if the given #GValue contains a #GST_TYPE_BUFFER value.
--
--*
-- * GST_VALUE_HOLDS_FRACTION:
-- * @x: the #GValue to check
-- *
-- * Checks if the given #GValue contains a #GST_TYPE_FRACTION value.
--
--*
-- * GST_VALUE_HOLDS_DATE:
-- * @x: the #GValue to check
-- *
-- * Checks if the given #GValue contains a #GST_TYPE_DATE value.
--
--*
-- * GST_VALUE_HOLDS_DATE_TIME:
-- * @x: the #GValue to check
-- *
-- * Checks if the given #GValue contains a #GST_TYPE_DATE_TIME value.
-- *
-- * Since: 0.10.31
--
--*
-- * GST_TYPE_FOURCC:
-- *
-- * a #GValue type that represents 4 byte identifier (e.g. used for codecs)
-- *
-- * Returns: the #GType of GstFourcc
--
--*
-- * GST_TYPE_INT_RANGE:
-- *
-- * a #GValue type that represents an integer range
-- *
-- * Returns: the #GType of GstIntRange
--
--*
-- * GST_TYPE_INT64_RANGE:
-- *
-- * a #GValue type that represents an #gint64 range
-- *
-- * Returns: the #GType of GstInt64Range
-- *
-- * Since: 0.10.31
--
--*
-- * GST_TYPE_DOUBLE_RANGE:
-- *
-- * a #GValue type that represents a floating point range with double precission
-- *
-- * Returns: the #GType of GstIntRange
--
--*
-- * GST_TYPE_FRACTION_RANGE:
-- *
-- * a #GValue type that represents a GstFraction range
-- *
-- * Returns: the #GType of GstFractionRange
--
--*
-- * GST_TYPE_LIST:
-- *
-- * a #GValue type that represents an unordered list of #GValue values. This
-- * is used for example to express a list of possible values for a field in
-- * a caps structure, like a list of possible sample rates, of which only one
-- * will be chosen in the end. This means that all values in the list are
-- * meaningful on their own.
-- *
-- * Returns: the #GType of GstValueList (which is not explicitly typed)
--
--*
-- * GST_TYPE_ARRAY:
-- *
-- * a #GValue type that represents an ordered list of #GValue values. This is
-- * used to express a set of values that is meaningful only in their specific
-- * combination and order of values. Each value on its own is not particularly
-- * meaningful, only the ordered array in its entirety is meaningful. This is
-- * used for example to express channel layouts for multichannel audio where
-- * each channel needs to be mapped to a position in the room.
-- *
-- * Returns: the #GType of GstArrayList (which is not explicitly typed)
--
--*
-- * GST_TYPE_FRACTION:
-- *
-- * a #GValue type that represents a fraction of an integer numerator over
-- * an integer denominator
-- *
-- * Returns: the #GType of GstFraction (which is not explicitly typed)
--
--*
-- * GST_TYPE_DATE:
-- *
-- * a boxed #GValue type for #GDate that represents a date.
-- *
-- * Returns: the #GType of GstDate
--
--*
-- * GST_TYPE_DATE_TIME:
-- *
-- * a boxed #GValue type for #GstDateTime that represents a date and time.
-- *
-- * Returns: the #GType of GstDateTime
-- * Since: 0.10.31
--
--*
-- * GST_VALUE_LESS_THAN:
-- *
-- * Indicates that the first value provided to a comparison function
-- * (gst_value_compare()) is lesser than the second one.
--
--*
-- * GST_VALUE_EQUAL:
-- *
-- * Indicates that the first value provided to a comparison function
-- * (gst_value_compare()) is equal to the second one.
--
--*
-- * GST_VALUE_GREATER_THAN:
-- *
-- * Indicates that the first value provided to a comparison function
-- * (gst_value_compare()) is greater than the second one.
--
--*
-- * GST_VALUE_UNORDERED:
-- *
-- * Indicates that the comparison function (gst_value_compare()) can not
-- * determine a order for the two provided values.
--
--*
-- * GstValueCompareFunc:
-- * @value1: first value for comparison
-- * @value2: second value for comparison
-- *
-- * Used together with gst_value_compare() to compare #GValue items.
-- *
-- * Returns: one of GST_VALUE_LESS_THAN, GST_VALUE_EQUAL, GST_VALUE_GREATER_THAN
-- * or GST_VALUE_UNORDERED
--
type GstValueCompareFunc is access function (arg1 : access constant Glib.Values.GValue; arg2 : access constant Glib.Values.GValue) return GLIB.gint;
pragma Convention (C, GstValueCompareFunc); -- gst/gstvalue.h:346
--*
-- * GstValueSerializeFunc:
-- * @value1: a #GValue
-- *
-- * Used by gst_value_serialize() to obtain a non-binary form of the #GValue.
-- *
-- * Free-function: g_free
-- *
-- * Returns: (transfer full): the string representation of the value
--
type GstValueSerializeFunc is access function (arg1 : access constant Glib.Values.GValue) return access GLIB.gchar;
pragma Convention (C, GstValueSerializeFunc); -- gst/gstvalue.h:359
--*
-- * GstValueDeserializeFunc:
-- * @dest: a #GValue
-- * @s: a string
-- *
-- * Used by gst_value_deserialize() to parse a non-binary form into the #GValue.
-- *
-- * Returns: %TRUE for success
--
type GstValueDeserializeFunc is access function (arg1 : access Glib.Values.GValue; arg2 : access GLIB.gchar) return GLIB.gboolean;
pragma Convention (C, GstValueDeserializeFunc); -- gst/gstvalue.h:370
--*
-- * GstValueUnionFunc:
-- * @dest: a #GValue for the result
-- * @value1: a #GValue operand
-- * @value2: a #GValue operand
-- *
-- * Used by gst_value_union() to perform unification for a specific #GValue
-- * type. Register a new implementation with gst_value_register_union_func().
-- *
-- * Returns: %TRUE if a union was successful
--
type GstValueUnionFunc is access function
(arg1 : access Glib.Values.GValue;
arg2 : access constant Glib.Values.GValue;
arg3 : access constant Glib.Values.GValue) return GLIB.gboolean;
pragma Convention (C, GstValueUnionFunc); -- gst/gstvalue.h:384
--*
-- * GstValueIntersectFunc:
-- * @dest: (out caller-allocates): a #GValue for the result
-- * @value1: a #GValue operand
-- * @value2: a #GValue operand
-- *
-- * Used by gst_value_intersect() to perform intersection for a specific #GValue
-- * type. If the intersection is non-empty, the result is
-- * placed in @dest and TRUE is returned. If the intersection is
-- * empty, @dest is unmodified and FALSE is returned.
-- * Register a new implementation with gst_value_register_intersect_func().
-- *
-- * Returns: %TRUE if the values can intersect
--
type GstValueIntersectFunc is access function
(arg1 : access Glib.Values.GValue;
arg2 : access constant Glib.Values.GValue;
arg3 : access constant Glib.Values.GValue) return GLIB.gboolean;
pragma Convention (C, GstValueIntersectFunc); -- gst/gstvalue.h:402
--*
-- * GstValueSubtractFunc:
-- * @dest: (out caller-allocates): a #GValue for the result
-- * @minuend: a #GValue operand
-- * @subtrahend: a #GValue operand
-- *
-- * Used by gst_value_subtract() to perform subtraction for a specific #GValue
-- * type. Register a new implementation with gst_value_register_subtract_func().
-- *
-- * Returns: %TRUE if the subtraction is not empty
--
type GstValueSubtractFunc is access function
(arg1 : access Glib.Values.GValue;
arg2 : access constant Glib.Values.GValue;
arg3 : access constant Glib.Values.GValue) return GLIB.gboolean;
pragma Convention (C, GstValueSubtractFunc); -- gst/gstvalue.h:417
type GstValueTable;
type u_GstValueTable_u_gst_reserved_array is array (0 .. 3) of System.Address;
--subtype GstValueTable is u_GstValueTable; -- gst/gstvalue.h:421
--*
-- * GstValueTable:
-- * @type: a #GType
-- * @compare: a #GstValueCompareFunc
-- * @serialize: a #GstValueSerializeFunc
-- * @deserialize: a #GstValueDeserializeFunc
-- *
-- * VTable for the #GValue @type.
--
type GstValueTable is record
c_type : aliased GLIB.GType; -- gst/gstvalue.h:432
compare : GstValueCompareFunc; -- gst/gstvalue.h:433
serialize : GstValueSerializeFunc; -- gst/gstvalue.h:434
deserialize : GstValueDeserializeFunc; -- gst/gstvalue.h:435
u_gst_reserved : u_GstValueTable_u_gst_reserved_array; -- gst/gstvalue.h:438
end record;
pragma Convention (C_Pass_By_Copy, GstValueTable); -- gst/gstvalue.h:431
--< private >
function gst_int_range_get_type return GLIB.GType; -- gst/gstvalue.h:441
pragma Import (C, gst_int_range_get_type, "gst_int_range_get_type");
function gst_int64_range_get_type return GLIB.GType; -- gst/gstvalue.h:442
pragma Import (C, gst_int64_range_get_type, "gst_int64_range_get_type");
function gst_double_range_get_type return GLIB.GType; -- gst/gstvalue.h:443
pragma Import (C, gst_double_range_get_type, "gst_double_range_get_type");
function gst_fraction_range_get_type return GLIB.GType; -- gst/gstvalue.h:444
pragma Import (C, gst_fraction_range_get_type, "gst_fraction_range_get_type");
function gst_fourcc_get_type return GLIB.GType; -- gst/gstvalue.h:445
pragma Import (C, gst_fourcc_get_type, "gst_fourcc_get_type");
function gst_fraction_get_type return GLIB.GType; -- gst/gstvalue.h:446
pragma Import (C, gst_fraction_get_type, "gst_fraction_get_type");
function gst_value_list_get_type return GLIB.GType; -- gst/gstvalue.h:447
pragma Import (C, gst_value_list_get_type, "gst_value_list_get_type");
function gst_value_array_get_type return GLIB.GType; -- gst/gstvalue.h:448
pragma Import (C, gst_value_array_get_type, "gst_value_array_get_type");
function gst_date_get_type return GLIB.GType; -- gst/gstvalue.h:450
pragma Import (C, gst_date_get_type, "gst_date_get_type");
function gst_date_time_get_type return GLIB.GType; -- gst/gstvalue.h:451
pragma Import (C, gst_date_time_get_type, "gst_date_time_get_type");
procedure gst_value_register (table : access constant GstValueTable); -- gst/gstvalue.h:453
pragma Import (C, gst_value_register, "gst_value_register");
procedure gst_value_init_and_copy (dest : access Glib.Values.GValue; src : access constant Glib.Values.GValue); -- gst/gstvalue.h:454
pragma Import (C, gst_value_init_and_copy, "gst_value_init_and_copy");
function gst_value_serialize (value : access constant Glib.Values.GValue) return access GLIB.gchar; -- gst/gstvalue.h:457
pragma Import (C, gst_value_serialize, "gst_value_serialize");
function gst_value_deserialize (dest : access Glib.Values.GValue; src : access GLIB.gchar) return GLIB.gboolean; -- gst/gstvalue.h:458
pragma Import (C, gst_value_deserialize, "gst_value_deserialize");
-- list
procedure gst_value_list_append_value (value : access Glib.Values.GValue; append_value : access constant Glib.Values.GValue); -- gst/gstvalue.h:462
pragma Import (C, gst_value_list_append_value, "gst_value_list_append_value");
procedure gst_value_list_prepend_value (value : access Glib.Values.GValue; prepend_value : access constant Glib.Values.GValue); -- gst/gstvalue.h:464
pragma Import (C, gst_value_list_prepend_value, "gst_value_list_prepend_value");
procedure gst_value_list_concat
(dest : access Glib.Values.GValue;
value1 : access constant Glib.Values.GValue;
value2 : access constant Glib.Values.GValue); -- gst/gstvalue.h:466
pragma Import (C, gst_value_list_concat, "gst_value_list_concat");
procedure gst_value_list_merge
(dest : access Glib.Values.GValue;
value1 : access constant Glib.Values.GValue;
value2 : access constant Glib.Values.GValue); -- gst/gstvalue.h:469
pragma Import (C, gst_value_list_merge, "gst_value_list_merge");
function gst_value_list_get_size (value : access constant Glib.Values.GValue) return GLIB.guint; -- gst/gstvalue.h:472
pragma Import (C, gst_value_list_get_size, "gst_value_list_get_size");
function gst_value_list_get_value (value : access constant Glib.Values.GValue; index : GLIB.guint) return access constant Glib.Values.GValue; -- gst/gstvalue.h:473
pragma Import (C, gst_value_list_get_value, "gst_value_list_get_value");
-- array
procedure gst_value_array_append_value (value : access Glib.Values.GValue; append_value : access constant Glib.Values.GValue); -- gst/gstvalue.h:477
pragma Import (C, gst_value_array_append_value, "gst_value_array_append_value");
procedure gst_value_array_prepend_value (value : access Glib.Values.GValue; prepend_value : access constant Glib.Values.GValue); -- gst/gstvalue.h:479
pragma Import (C, gst_value_array_prepend_value, "gst_value_array_prepend_value");
function gst_value_array_get_size (value : access constant Glib.Values.GValue) return GLIB.guint; -- gst/gstvalue.h:481
pragma Import (C, gst_value_array_get_size, "gst_value_array_get_size");
function gst_value_array_get_value (value : access constant Glib.Values.GValue; index : GLIB.guint) return access constant Glib.Values.GValue; -- gst/gstvalue.h:482
pragma Import (C, gst_value_array_get_value, "gst_value_array_get_value");
-- fourcc
procedure gst_value_set_fourcc (value : access Glib.Values.GValue; fourcc : GLIB.guint32); -- gst/gstvalue.h:486
pragma Import (C, gst_value_set_fourcc, "gst_value_set_fourcc");
function gst_value_get_fourcc (value : access constant Glib.Values.GValue) return GLIB.guint32; -- gst/gstvalue.h:488
pragma Import (C, gst_value_get_fourcc, "gst_value_get_fourcc");
-- int range
procedure gst_value_set_int_range
(value : access Glib.Values.GValue;
start : GLIB.gint;
c_end : GLIB.gint); -- gst/gstvalue.h:491
pragma Import (C, gst_value_set_int_range, "gst_value_set_int_range");
function gst_value_get_int_range_min (value : access constant Glib.Values.GValue) return GLIB.gint; -- gst/gstvalue.h:494
pragma Import (C, gst_value_get_int_range_min, "gst_value_get_int_range_min");
function gst_value_get_int_range_max (value : access constant Glib.Values.GValue) return GLIB.gint; -- gst/gstvalue.h:495
pragma Import (C, gst_value_get_int_range_max, "gst_value_get_int_range_max");
-- int64 range
procedure gst_value_set_int64_range
(value : access Glib.Values.GValue;
start : GLIB.gint64;
c_end : GLIB.gint64); -- gst/gstvalue.h:498
pragma Import (C, gst_value_set_int64_range, "gst_value_set_int64_range");
function gst_value_get_int64_range_min (value : access constant Glib.Values.GValue) return GLIB.gint64; -- gst/gstvalue.h:501
pragma Import (C, gst_value_get_int64_range_min, "gst_value_get_int64_range_min");
function gst_value_get_int64_range_max (value : access constant Glib.Values.GValue) return GLIB.gint64; -- gst/gstvalue.h:502
pragma Import (C, gst_value_get_int64_range_max, "gst_value_get_int64_range_max");
-- double range
procedure gst_value_set_double_range
(value : access Glib.Values.GValue;
start : GLIB.gdouble;
c_end : GLIB.gdouble); -- gst/gstvalue.h:505
pragma Import (C, gst_value_set_double_range, "gst_value_set_double_range");
function gst_value_get_double_range_min (value : access constant Glib.Values.GValue) return GLIB.gdouble; -- gst/gstvalue.h:508
pragma Import (C, gst_value_get_double_range_min, "gst_value_get_double_range_min");
function gst_value_get_double_range_max (value : access constant Glib.Values.GValue) return GLIB.gdouble; -- gst/gstvalue.h:509
pragma Import (C, gst_value_get_double_range_max, "gst_value_get_double_range_max");
-- caps
function gst_value_get_caps (value : access constant Glib.Values.GValue) return access constant GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstcaps_h.GstCaps; -- gst/gstvalue.h:512
pragma Import (C, gst_value_get_caps, "gst_value_get_caps");
procedure gst_value_set_caps (value : access Glib.Values.GValue; caps : access constant GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstcaps_h.GstCaps); -- gst/gstvalue.h:513
pragma Import (C, gst_value_set_caps, "gst_value_set_caps");
-- structure
function gst_value_get_structure (value : access constant Glib.Values.GValue) return access constant GStreamer.GST_Low_Level.gstreamer_0_10_gst_gststructure_h.GstStructure; -- gst/gstvalue.h:518
pragma Import (C, gst_value_get_structure, "gst_value_get_structure");
procedure gst_value_set_structure (value : access Glib.Values.GValue; structure : access constant GStreamer.GST_Low_Level.gstreamer_0_10_gst_gststructure_h.GstStructure); -- gst/gstvalue.h:519
pragma Import (C, gst_value_set_structure, "gst_value_set_structure");
-- fraction
procedure gst_value_set_fraction
(value : access Glib.Values.GValue;
numerator : GLIB.gint;
denominator : GLIB.gint); -- gst/gstvalue.h:523
pragma Import (C, gst_value_set_fraction, "gst_value_set_fraction");
function gst_value_get_fraction_numerator (value : access constant Glib.Values.GValue) return GLIB.gint; -- gst/gstvalue.h:526
pragma Import (C, gst_value_get_fraction_numerator, "gst_value_get_fraction_numerator");
function gst_value_get_fraction_denominator (value : access constant Glib.Values.GValue) return GLIB.gint; -- gst/gstvalue.h:527
pragma Import (C, gst_value_get_fraction_denominator, "gst_value_get_fraction_denominator");
function gst_value_fraction_multiply
(product : access Glib.Values.GValue;
factor1 : access constant Glib.Values.GValue;
factor2 : access constant Glib.Values.GValue) return GLIB.gboolean; -- gst/gstvalue.h:528
pragma Import (C, gst_value_fraction_multiply, "gst_value_fraction_multiply");
function gst_value_fraction_subtract
(dest : access Glib.Values.GValue;
minuend : access constant Glib.Values.GValue;
subtrahend : access constant Glib.Values.GValue) return GLIB.gboolean; -- gst/gstvalue.h:531
pragma Import (C, gst_value_fraction_subtract, "gst_value_fraction_subtract");
-- fraction range
procedure gst_value_set_fraction_range
(value : access Glib.Values.GValue;
start : access constant Glib.Values.GValue;
c_end : access constant Glib.Values.GValue); -- gst/gstvalue.h:536
pragma Import (C, gst_value_set_fraction_range, "gst_value_set_fraction_range");
procedure gst_value_set_fraction_range_full
(value : access Glib.Values.GValue;
numerator_start : GLIB.gint;
denominator_start : GLIB.gint;
numerator_end : GLIB.gint;
denominator_end : GLIB.gint); -- gst/gstvalue.h:539
pragma Import (C, gst_value_set_fraction_range_full, "gst_value_set_fraction_range_full");
function gst_value_get_fraction_range_min (value : access constant Glib.Values.GValue) return access constant Glib.Values.GValue; -- gst/gstvalue.h:544
pragma Import (C, gst_value_get_fraction_range_min, "gst_value_get_fraction_range_min");
function gst_value_get_fraction_range_max (value : access constant Glib.Values.GValue) return access constant Glib.Values.GValue; -- gst/gstvalue.h:545
pragma Import (C, gst_value_get_fraction_range_max, "gst_value_get_fraction_range_max");
-- date
function gst_value_get_date (value : access constant Glib.Values.GValue) return access constant GStreamer.GST_Low_Level.glib_2_0_glib_gdate_h.GDate; -- gst/gstvalue.h:548
pragma Import (C, gst_value_get_date, "gst_value_get_date");
procedure gst_value_set_date (value : access Glib.Values.GValue; date : access constant GStreamer.GST_Low_Level.glib_2_0_glib_gdate_h.GDate); -- gst/gstvalue.h:549
pragma Import (C, gst_value_set_date, "gst_value_set_date");
-- compare
function gst_value_compare (value1 : access constant Glib.Values.GValue; value2 : access constant Glib.Values.GValue) return GLIB.gint; -- gst/gstvalue.h:553
pragma Import (C, gst_value_compare, "gst_value_compare");
function gst_value_can_compare (value1 : access constant Glib.Values.GValue; value2 : access constant Glib.Values.GValue) return GLIB.gboolean; -- gst/gstvalue.h:555
pragma Import (C, gst_value_can_compare, "gst_value_can_compare");
-- union
function gst_value_union
(dest : access Glib.Values.GValue;
value1 : access constant Glib.Values.GValue;
value2 : access constant Glib.Values.GValue) return GLIB.gboolean; -- gst/gstvalue.h:558
pragma Import (C, gst_value_union, "gst_value_union");
function gst_value_can_union (value1 : access constant Glib.Values.GValue; value2 : access constant Glib.Values.GValue) return GLIB.gboolean; -- gst/gstvalue.h:561
pragma Import (C, gst_value_can_union, "gst_value_can_union");
procedure gst_value_register_union_func
(type1 : GLIB.GType;
type2 : GLIB.GType;
func : GstValueUnionFunc); -- gst/gstvalue.h:563
pragma Import (C, gst_value_register_union_func, "gst_value_register_union_func");
-- intersection
function gst_value_intersect
(dest : access Glib.Values.GValue;
value1 : access constant Glib.Values.GValue;
value2 : access constant Glib.Values.GValue) return GLIB.gboolean; -- gst/gstvalue.h:568
pragma Import (C, gst_value_intersect, "gst_value_intersect");
function gst_value_can_intersect (value1 : access constant Glib.Values.GValue; value2 : access constant Glib.Values.GValue) return GLIB.gboolean; -- gst/gstvalue.h:571
pragma Import (C, gst_value_can_intersect, "gst_value_can_intersect");
procedure gst_value_register_intersect_func
(type1 : GLIB.GType;
type2 : GLIB.GType;
func : GstValueIntersectFunc); -- gst/gstvalue.h:573
pragma Import (C, gst_value_register_intersect_func, "gst_value_register_intersect_func");
-- subtraction
function gst_value_subtract
(dest : access Glib.Values.GValue;
minuend : access constant Glib.Values.GValue;
subtrahend : access constant Glib.Values.GValue) return GLIB.gboolean; -- gst/gstvalue.h:578
pragma Import (C, gst_value_subtract, "gst_value_subtract");
function gst_value_can_subtract (minuend : access constant Glib.Values.GValue; subtrahend : access constant Glib.Values.GValue) return GLIB.gboolean; -- gst/gstvalue.h:581
pragma Import (C, gst_value_can_subtract, "gst_value_can_subtract");
procedure gst_value_register_subtract_func
(minuend_type : GLIB.GType;
subtrahend_type : GLIB.GType;
func : GstValueSubtractFunc); -- gst/gstvalue.h:583
pragma Import (C, gst_value_register_subtract_func, "gst_value_register_subtract_func");
-- fixation
function gst_value_is_fixed (value : access constant Glib.Values.GValue) return GLIB.gboolean; -- gst/gstvalue.h:588
pragma Import (C, gst_value_is_fixed, "gst_value_is_fixed");
end GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstvalue_h;
|
mimo/Tracker | Ada | 1,208 | ads |
package tracker is
type Item_Status is (UNSTARTED, PAUSE, PROGRESS, DONE, CANCELED);
type Item is record
name : String (1 .. 42);
name_length : Natural;
state : Item_Status;
end record;
type Fixed_Collection is array (1 .. 50) of Item;
type Items_Count_By_State is array (Item_Status'Range) of Natural;
type Collection is record
Name : String (1 .. 42);
Items : Fixed_Collection;
Items_Count : Integer := 0;
Counter : Items_Count_By_State;
Focused : Boolean := False;
end record;
procedure Set_Name (Object : in out Collection; Name : String);
procedure Add_Item (
Object : in out Collection;
Name : String;
S : Item_Status := UNSTARTED);
procedure Percentage (Object : in out Collection);
procedure Move_Up (Object : in out Collection; Item : Integer);
procedure Move_Down (Object : in out Collection; Item : Integer);
type Fixed_Board is array (1 .. 12) of Collection;
type Board is record
Collections : Fixed_Board;
Collection_Count : Integer := 0;
end record;
procedure Add_Collection (Object : in out Board; Col : Collection);
Activities : Board;
end tracker;
|
sungyeon/drake | Ada | 109 | adb | with Ada.Text_IO;
procedure pkgversion is
begin
Ada.Text_IO.Put_Line (Ada.Text_IO'Version);
end pkgversion;
|
reznikmm/matreshka | Ada | 3,963 | 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_Name_Attributes;
package Matreshka.ODF_Chart.Name_Attributes is
type Chart_Name_Attribute_Node is
new Matreshka.ODF_Chart.Abstract_Chart_Attribute_Node
and ODF.DOM.Chart_Name_Attributes.ODF_Chart_Name_Attribute
with null record;
overriding function Create
(Parameters : not null access Matreshka.DOM_Attributes.Attribute_L2_Parameters)
return Chart_Name_Attribute_Node;
overriding function Get_Local_Name
(Self : not null access constant Chart_Name_Attribute_Node)
return League.Strings.Universal_String;
end Matreshka.ODF_Chart.Name_Attributes;
|
zhmu/ananas | Ada | 2,750 | ads | ------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- G N A T . S O C K E T S . L I N K E R _ O P T I O N S --
-- --
-- S p e c --
-- --
-- Copyright (C) 2001-2022, AdaCore --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. --
-- --
-- As a special exception under Section 7 of GPL version 3, you are granted --
-- additional permissions described in the GCC Runtime Library Exception, --
-- version 3.1, as published by the Free Software Foundation. --
-- --
-- You should have received a copy of the GNU General Public License and --
-- a copy of the GCC Runtime Library Exception along with this program; --
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
-- <http://www.gnu.org/licenses/>. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
-- This package is used to provide target specific linker_options for the
-- support of sockets as required by the package GNAT.Sockets.
-- This is the LynxOS version of this package
-- This package should not be directly with'ed by an application program
package GNAT.Sockets.Linker_Options is
private
pragma Linker_Options ("-lbsd");
end GNAT.Sockets.Linker_Options;
|
zhmu/ananas | Ada | 2,238 | adb | -- { dg-do run }
with Ada.Text_IO; use Ada.Text_IO;
procedure Wide_Wide_Value1 is
begin
begin
declare
Str : constant Wide_Wide_String :=
Wide_Wide_Character'Val (16#00000411#) &
Wide_Wide_Character'Val (16#0000043e#) &
Wide_Wide_Character'Val (16#00000434#) &
Wide_Wide_Character'Val (16#00000430#) &
Wide_Wide_Character'Val (16#00000443#) &
Wide_Wide_Character'Val (16#00000431#) &
Wide_Wide_Character'Val (16#00000430#) &
Wide_Wide_Character'Val (16#00000435#) &
Wide_Wide_Character'Val (16#00000432#) &
Wide_Wide_Character'Val (16#00000416#) &
Wide_Wide_Character'Val (16#00000443#) &
Wide_Wide_Character'Val (16#0000043c#) &
Wide_Wide_Character'Val (16#00000430#) &
Wide_Wide_Character'Val (16#00000442#) &
Wide_Wide_Character'Val (16#0000041c#) &
Wide_Wide_Character'Val (16#00000430#) &
Wide_Wide_Character'Val (16#00000440#) &
Wide_Wide_Character'Val (16#00000430#) &
Wide_Wide_Character'Val (16#00000442#) &
Wide_Wide_Character'Val (16#0000043e#) &
Wide_Wide_Character'Val (16#00000432#) &
Wide_Wide_Character'Val (16#00000438#) &
Wide_Wide_Character'Val (16#00000447#);
Val : constant Integer := Integer'Wide_Wide_Value (Str);
begin
Put_Line ("ERROR: 1: Constraint_Error not raised");
end;
exception
when Constraint_Error =>
null;
when others =>
Put_Line ("ERROR: 1: unexpected exception");
end;
begin
declare
Str : Wide_Wide_String (1 .. 128) :=
(others => Wide_Wide_Character'Val (16#0FFFFFFF#));
Val : constant Integer := Integer'Wide_Wide_Value (Str);
begin
Put_Line ("ERROR: 1: Constraint_Error not raised");
end;
exception
when Constraint_Error =>
null;
when others =>
Put_Line ("ERROR: 1: unexpected exception");
end;
end Wide_Wide_Value1;
|
zhmu/ananas | Ada | 3,310 | ads | ------------------------------------------------------------------------------
-- --
-- GNAT RUN-TIME LIBRARY COMPONENTS --
-- --
-- S Y S T E M . C O M P A R E _ A R R A Y _ U N S I G N E D _ 1 2 8 --
-- --
-- S p e c --
-- --
-- Copyright (C) 2002-2022, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. --
-- --
-- As a special exception under Section 7 of GPL version 3, you are granted --
-- additional permissions described in the GCC Runtime Library Exception, --
-- version 3.1, as published by the Free Software Foundation. --
-- --
-- You should have received a copy of the GNU General Public License and --
-- a copy of the GCC Runtime Library Exception along with this program; --
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
-- <http://www.gnu.org/licenses/>. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
-- This package contains functions for runtime comparisons on arrays whose
-- elements are 128-bit discrete type values to be treated as unsigned.
package System.Compare_Array_Unsigned_128 is
-- Note: although the functions in this package are in a sense Pure, the
-- package cannot be declared as Pure, since the arguments are addresses,
-- not the data, and the result is not pure wrt the address values.
function Compare_Array_U128
(Left : System.Address;
Right : System.Address;
Left_Len : Natural;
Right_Len : Natural) return Integer;
-- Compare the array starting at address Left of length Left_Len
-- with the array starting at address Right of length Right_Len.
-- The comparison is in the normal Ada semantic sense of array
-- comparison. The result is -1,0,+1 for Left<Right, Left=Right,
-- Left>Right respectively.
end System.Compare_Array_Unsigned_128;
|
glencornell/ada-object-framework | Ada | 4,435 | ads | -- Copyright (C) 2020 Glen Cornell <[email protected]>
--
-- This program is free software: you can redistribute it and/or
-- modify it under the terms of the GNU General Public License as
-- published by the Free Software Foundation, either version 3 of the
-- License, or (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-- General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see
-- <http://www.gnu.org/licenses/>.
with Ada.Containers.Doubly_Linked_Lists;
with Ada.Strings.Unbounded;
with Aof.Core.Root_Objects;
with Aof.Core.Signals;
with Aof.Core.Properties;
package Aof.Core.Objects is
pragma Preelaborate;
-- Publicly accessible parts of the Object type. No objects should
-- be made of this type. Rather, see Object below.
type Public_Part is abstract limited new Aof.Core.Root_Objects.Root_Object with record
Name : Aof.Core.Properties.Unbounded_Strings.Property;
Destroyed : Aof.Core.Signals.Access_Objects.Signal;
end record;
overriding procedure Finalize (This : in out Public_Part);
-- The object type is the root object in the Ada Object Framework.
-- All objects should be derived from this type.
type Object is limited new Public_Part with private;
type Access_Object is access all Object'Class;
package Object_List is new Ada.Containers.Doubly_Linked_Lists
(Element_Type => Access_Object);
-- This exception is raised when an attempt is made to insert a
-- parent as a child of an object, creating a circular hierarchy
-- of objects.
Circular_Reference_Exception : exception;
-- Accessor to the object's name as a simple string. This is a
-- convenience subprogram that is the same as
-- Ada.Strings.Unbounded.To_String(This.Object_Name.Get).
function Get_Name (This : in Object'Class) return String;
procedure Set_Name (This : in out Object'Class; Name : in String);
-- Accessors to the object's parent.
function Get_Parent (This : in Object'Class) return Access_Object;
procedure Set_Parent -- raises Circular_Reference_Exception
(This : in out Object'Class;
Parent : in not null Access_Object);
-- Accessors to the object's children.
function Get_Children (This : in Object'Class) return Object_List.List;
type Find_Child_Options is
(Find_Direct_Children_Only,
Find_Children_Recursively);
function Find_Child
(This : in Object'Class;
Name : in Ada.Strings.Unbounded.Unbounded_String;
Options : in Find_Child_Options := Find_Children_Recursively) return Access_Object;
function Find_Child
(This : in Object'Class;
Name : in String;
Options : in Find_Child_Options := Find_Children_Recursively) return Access_Object;
function Find_Children
(This : in Object'Class;
Name : in Ada.Strings.Unbounded.Unbounded_String;
Options : in Find_Child_Options := Find_Children_Recursively) return Object_List.List;
function Find_Children
(This : in Object'Class;
Name : in String;
Options : in Find_Child_Options := Find_Children_Recursively) return Object_List.List;
generic
with procedure Proc(This : in out Access_Object);
procedure Iterate
(This : in Access_Object;
Options : in Find_Child_Options := Find_Children_Recursively);
function Contains
(This : in out Object'Class;
Child : in not null Access_Object) return Boolean;
private
procedure Delete_Child
(This : in out Object'Class;
Child : in out not null Access_Object;
Options : in Find_Child_Options := Find_Children_Recursively);
-- This type is derived from Ada.Finalization.Limited_Controlled
-- to ensure that memory is reclaimed when the object is destroyed
-- or goes out of scope. When the object is destroyed, so are all
-- of its childern.
type Object is limited new Public_Part with record
Parent : Access_Object := null;
Children : Object_List.List;
end record;
overriding procedure Finalize(This : in out Object);
end Aof.Core.Objects;
|
reznikmm/matreshka | Ada | 7,101 | 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.Cell_Content_Deletion_Elements is
------------
-- Create --
------------
overriding function Create
(Parameters : not null access Matreshka.DOM_Elements.Element_L2_Parameters)
return Table_Cell_Content_Deletion_Element_Node is
begin
return Self : Table_Cell_Content_Deletion_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_Cell_Content_Deletion_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_Cell_Content_Deletion
(ODF.DOM.Table_Cell_Content_Deletion_Elements.ODF_Table_Cell_Content_Deletion_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_Cell_Content_Deletion_Element_Node)
return League.Strings.Universal_String
is
pragma Unreferenced (Self);
begin
return Matreshka.ODF_String_Constants.Cell_Content_Deletion_Element;
end Get_Local_Name;
----------------
-- Leave_Node --
----------------
overriding procedure Leave_Node
(Self : not null access Table_Cell_Content_Deletion_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_Cell_Content_Deletion
(ODF.DOM.Table_Cell_Content_Deletion_Elements.ODF_Table_Cell_Content_Deletion_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_Cell_Content_Deletion_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_Cell_Content_Deletion
(Visitor,
ODF.DOM.Table_Cell_Content_Deletion_Elements.ODF_Table_Cell_Content_Deletion_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.Cell_Content_Deletion_Element,
Table_Cell_Content_Deletion_Element_Node'Tag);
end Matreshka.ODF_Table.Cell_Content_Deletion_Elements;
|
io7m/coreland-c_string | Ada | 532 | adb | with Ada.Text_IO;
package body Test is
package IO renames Ada.Text_IO;
procedure Sys_Exit (Code : Integer);
pragma Import (c, Sys_Exit, "exit");
procedure Assert
(Check : in Boolean;
Pass_Message : in String := "Assertion passed";
Fail_Message : in String := "Assertion failed") is
begin
if Check then
IO.Put_Line (IO.Current_Error, "pass: " & Pass_Message);
else
IO.Put_Line (IO.Current_Error, "fail: " & Fail_Message);
Sys_Exit (1);
end if;
end Assert;
end Test;
|
reznikmm/matreshka | Ada | 7,789 | adb | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- XML Processor --
-- --
-- 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 Ada.Wide_Wide_Text_IO; use Ada.Wide_Wide_Text_IO;
with XML.DOM.Nodes.Attrs;
with XML.DOM.Nodes.Character_Datas.Texts;
with XML.DOM.Nodes.Elements;
with ODF.DOM.Documents;
package body Matreshka.DOM_Builders is
procedure Push (Self : in out DOM_Builder'Class);
procedure Pop (Self : in out DOM_Builder'Class);
----------------
-- Characters --
----------------
overriding procedure Characters
(Self : in out DOM_Builder;
Text : League.Strings.Universal_String;
Success : in out Boolean)
is
Aux : XML.DOM.Nodes.Character_Datas.Texts.DOM_Text_Access
:= Self.Document.Create_Text_Node (Text);
begin
Self.Current.Append_Child (XML.DOM.Nodes.DOM_Node_Access (Aux));
XML.DOM.Nodes.Dereference (XML.DOM.Nodes.DOM_Node_Access (Aux));
end Characters;
-----------------
-- End_Element --
-----------------
overriding procedure End_Element
(Self : in out DOM_Builder;
Namespace_URI : League.Strings.Universal_String;
Local_Name : League.Strings.Universal_String;
Qualified_Name : League.Strings.Universal_String;
Success : in out Boolean) is
begin
Self.Pop;
end End_Element;
------------------
-- Error_String --
------------------
overriding function Error_String
(Self : DOM_Builder) return League.Strings.Universal_String is
begin
return League.Strings.Empty_Universal_String;
end Error_String;
------------------
-- Get_Document --
------------------
function Get_Document
(Self : DOM_Builder'Class)
return XML.DOM.Nodes.Documents.DOM_Document_Access is
begin
return Self.Document;
end Get_Document;
---------
-- Pop --
---------
procedure Pop (Self : in out DOM_Builder'Class) is
begin
Self.Current := Self.Parent;
if not Self.Stack.Is_Empty then
Self.Parent := Self.Stack.Last_Element;
Self.Stack.Delete_Last;
else
Self.Parent := null;
end if;
end Pop;
----------
-- Push --
----------
procedure Push (Self : in out DOM_Builder'Class) is
begin
Self.Stack.Append (Self.Parent);
Self.Parent := Self.Current;
Self.Current := null;
end Push;
--------------------
-- Start_Document --
--------------------
overriding procedure Start_Document
(Self : in out DOM_Builder;
Success : in out Boolean) is
begin
Self.Document := new ODF.DOM.Documents.ODF_Document;
Self.Current := XML.DOM.Nodes.DOM_Node_Access (Self.Document);
end Start_Document;
-------------------
-- Start_Element --
-------------------
overriding procedure Start_Element
(Self : in out DOM_Builder;
Namespace_URI : League.Strings.Universal_String;
Local_Name : League.Strings.Universal_String;
Qualified_Name : League.Strings.Universal_String;
Attributes : XML.SAX.Attributes.SAX_Attributes;
Success : in out Boolean)
is
Element : XML.DOM.Nodes.Elements.DOM_Element_Access;
Attribute : XML.DOM.Nodes.Attrs.DOM_Attr_Access;
begin
Self.Push;
if Local_Name.Is_Empty then
raise Program_Error;
else
Put_Line
('{'
& Namespace_URI.To_Wide_Wide_String
& '}'
& Local_Name.To_Wide_Wide_String
& ' '
& Qualified_Name.To_Wide_Wide_String);
Element :=
Self.Document.Create_Element_NS (Namespace_URI, Qualified_Name);
Self.Current := XML.DOM.Nodes.DOM_Node_Access (Element);
Self.Parent.Append_Child (Self.Current);
XML.DOM.Nodes.Dereference (XML.DOM.Nodes.DOM_Node_Access (Element));
end if;
-- Process attributes.
for J in 1 .. Attributes.Length loop
if Attributes.Local_Name (J).Is_Empty then
raise Program_Error;
else
Attribute :=
Self.Document.Create_Attribute_NS
(Attributes.Namespace_URI (J), Attributes.Qualified_Name (J));
XML.DOM.Nodes.Elements.DOM_Element_Access
(Self.Current).Set_Attribute_Node_NS (Attribute);
Attribute.Set_Value (Attributes.Value (J));
XML.DOM.Nodes.Dereference
(XML.DOM.Nodes.DOM_Node_Access (Attribute));
end if;
end loop;
end Start_Element;
end Matreshka.DOM_Builders;
|
tj800x/SPARKNaCl | Ada | 420 | ads | package SPARKNaCl.Scalar
with SPARK_Mode => On
is
--------------------------------------------------------
-- Scalar multiplication
--------------------------------------------------------
function Mult (N : in Bytes_32;
P : in Bytes_32) return Bytes_32
with Global => null;
function Mult_Base (N : in Bytes_32) return Bytes_32
with Global => null;
end SPARKNaCl.Scalar;
|
reznikmm/matreshka | Ada | 15,404 | 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$
------------------------------------------------------------------------------
-- This file is generated, don't edit it.
------------------------------------------------------------------------------
with AMF.DC;
with AMF.DG.Fills;
with AMF.Elements;
with AMF.Internals.Helpers;
with AMF.Internals.Tables.DD_Attributes;
with AMF.Real_Collections;
with AMF.Visitors.DG_Iterators;
with AMF.Visitors.DG_Visitors;
with League.Strings.Internals;
with Matreshka.Internals.Strings;
package body AMF.Internals.DG_Styles is
--------------
-- Get_Fill --
--------------
overriding function Get_Fill
(Self : not null access constant DG_Style_Proxy)
return AMF.DG.Fills.DG_Fill_Access is
begin
return
AMF.DG.Fills.DG_Fill_Access
(AMF.Internals.Helpers.To_Element
(AMF.Internals.Tables.DD_Attributes.Internal_Get_Fill
(Self.Element)));
end Get_Fill;
--------------
-- Set_Fill --
--------------
overriding procedure Set_Fill
(Self : not null access DG_Style_Proxy;
To : AMF.DG.Fills.DG_Fill_Access) is
begin
AMF.Internals.Tables.DD_Attributes.Internal_Set_Fill
(Self.Element,
AMF.Internals.Helpers.To_Element
(AMF.Elements.Element_Access (To)));
end Set_Fill;
--------------------
-- Get_Fill_Color --
--------------------
overriding function Get_Fill_Color
(Self : not null access constant DG_Style_Proxy)
return AMF.DC.Optional_DC_Color is
begin
return
AMF.Internals.Tables.DD_Attributes.Internal_Get_Fill_Color
(Self.Element);
end Get_Fill_Color;
--------------------
-- Set_Fill_Color --
--------------------
overriding procedure Set_Fill_Color
(Self : not null access DG_Style_Proxy;
To : AMF.DC.Optional_DC_Color) is
begin
AMF.Internals.Tables.DD_Attributes.Internal_Set_Fill_Color
(Self.Element, To);
end Set_Fill_Color;
----------------------
-- Get_Fill_Opacity --
----------------------
overriding function Get_Fill_Opacity
(Self : not null access constant DG_Style_Proxy)
return AMF.Optional_Real is
begin
return
AMF.Internals.Tables.DD_Attributes.Internal_Get_Fill_Opacity
(Self.Element);
end Get_Fill_Opacity;
----------------------
-- Set_Fill_Opacity --
----------------------
overriding procedure Set_Fill_Opacity
(Self : not null access DG_Style_Proxy;
To : AMF.Optional_Real) is
begin
AMF.Internals.Tables.DD_Attributes.Internal_Set_Fill_Opacity
(Self.Element, To);
end Set_Fill_Opacity;
----------------------
-- Get_Stroke_Width --
----------------------
overriding function Get_Stroke_Width
(Self : not null access constant DG_Style_Proxy)
return AMF.Optional_Real is
begin
return
AMF.Internals.Tables.DD_Attributes.Internal_Get_Stroke_Width
(Self.Element);
end Get_Stroke_Width;
----------------------
-- Set_Stroke_Width --
----------------------
overriding procedure Set_Stroke_Width
(Self : not null access DG_Style_Proxy;
To : AMF.Optional_Real) is
begin
AMF.Internals.Tables.DD_Attributes.Internal_Set_Stroke_Width
(Self.Element, To);
end Set_Stroke_Width;
------------------------
-- Get_Stroke_Opacity --
------------------------
overriding function Get_Stroke_Opacity
(Self : not null access constant DG_Style_Proxy)
return AMF.Optional_Real is
begin
return
AMF.Internals.Tables.DD_Attributes.Internal_Get_Stroke_Opacity
(Self.Element);
end Get_Stroke_Opacity;
------------------------
-- Set_Stroke_Opacity --
------------------------
overriding procedure Set_Stroke_Opacity
(Self : not null access DG_Style_Proxy;
To : AMF.Optional_Real) is
begin
AMF.Internals.Tables.DD_Attributes.Internal_Set_Stroke_Opacity
(Self.Element, To);
end Set_Stroke_Opacity;
----------------------
-- Get_Stroke_Color --
----------------------
overriding function Get_Stroke_Color
(Self : not null access constant DG_Style_Proxy)
return AMF.DC.Optional_DC_Color is
begin
return
AMF.Internals.Tables.DD_Attributes.Internal_Get_Stroke_Color
(Self.Element);
end Get_Stroke_Color;
----------------------
-- Set_Stroke_Color --
----------------------
overriding procedure Set_Stroke_Color
(Self : not null access DG_Style_Proxy;
To : AMF.DC.Optional_DC_Color) is
begin
AMF.Internals.Tables.DD_Attributes.Internal_Set_Stroke_Color
(Self.Element, To);
end Set_Stroke_Color;
----------------------------
-- Get_Stroke_Dash_Length --
----------------------------
overriding function Get_Stroke_Dash_Length
(Self : not null access constant DG_Style_Proxy)
return AMF.Real_Collections.Sequence_Of_Real is
begin
return
AMF.Internals.Tables.DD_Attributes.Internal_Get_Stroke_Dash_Length
(Self.Element);
end Get_Stroke_Dash_Length;
-------------------
-- Get_Font_Size --
-------------------
overriding function Get_Font_Size
(Self : not null access constant DG_Style_Proxy)
return AMF.Optional_Real is
begin
return
AMF.Internals.Tables.DD_Attributes.Internal_Get_Font_Size
(Self.Element);
end Get_Font_Size;
-------------------
-- Set_Font_Size --
-------------------
overriding procedure Set_Font_Size
(Self : not null access DG_Style_Proxy;
To : AMF.Optional_Real) is
begin
AMF.Internals.Tables.DD_Attributes.Internal_Set_Font_Size
(Self.Element, To);
end Set_Font_Size;
-------------------
-- Get_Font_Name --
-------------------
overriding function Get_Font_Name
(Self : not null access constant DG_Style_Proxy)
return AMF.Optional_String is
begin
declare
use type Matreshka.Internals.Strings.Shared_String_Access;
Aux : constant Matreshka.Internals.Strings.Shared_String_Access
:= AMF.Internals.Tables.DD_Attributes.Internal_Get_Font_Name (Self.Element);
begin
if Aux = null then
return (Is_Empty => True);
else
return (False, League.Strings.Internals.Create (Aux));
end if;
end;
end Get_Font_Name;
-------------------
-- Set_Font_Name --
-------------------
overriding procedure Set_Font_Name
(Self : not null access DG_Style_Proxy;
To : AMF.Optional_String) is
begin
if To.Is_Empty then
AMF.Internals.Tables.DD_Attributes.Internal_Set_Font_Name
(Self.Element, null);
else
AMF.Internals.Tables.DD_Attributes.Internal_Set_Font_Name
(Self.Element,
League.Strings.Internals.Internal (To.Value));
end if;
end Set_Font_Name;
--------------------
-- Get_Font_Color --
--------------------
overriding function Get_Font_Color
(Self : not null access constant DG_Style_Proxy)
return AMF.DC.Optional_DC_Color is
begin
return
AMF.Internals.Tables.DD_Attributes.Internal_Get_Font_Color
(Self.Element);
end Get_Font_Color;
--------------------
-- Set_Font_Color --
--------------------
overriding procedure Set_Font_Color
(Self : not null access DG_Style_Proxy;
To : AMF.DC.Optional_DC_Color) is
begin
AMF.Internals.Tables.DD_Attributes.Internal_Set_Font_Color
(Self.Element, To);
end Set_Font_Color;
---------------------
-- Get_Font_Italic --
---------------------
overriding function Get_Font_Italic
(Self : not null access constant DG_Style_Proxy)
return AMF.Optional_Boolean is
begin
return
AMF.Internals.Tables.DD_Attributes.Internal_Get_Font_Italic
(Self.Element);
end Get_Font_Italic;
---------------------
-- Set_Font_Italic --
---------------------
overriding procedure Set_Font_Italic
(Self : not null access DG_Style_Proxy;
To : AMF.Optional_Boolean) is
begin
AMF.Internals.Tables.DD_Attributes.Internal_Set_Font_Italic
(Self.Element, To);
end Set_Font_Italic;
-------------------
-- Get_Font_Bold --
-------------------
overriding function Get_Font_Bold
(Self : not null access constant DG_Style_Proxy)
return AMF.Optional_Boolean is
begin
return
AMF.Internals.Tables.DD_Attributes.Internal_Get_Font_Bold
(Self.Element);
end Get_Font_Bold;
-------------------
-- Set_Font_Bold --
-------------------
overriding procedure Set_Font_Bold
(Self : not null access DG_Style_Proxy;
To : AMF.Optional_Boolean) is
begin
AMF.Internals.Tables.DD_Attributes.Internal_Set_Font_Bold
(Self.Element, To);
end Set_Font_Bold;
------------------------
-- Get_Font_Underline --
------------------------
overriding function Get_Font_Underline
(Self : not null access constant DG_Style_Proxy)
return AMF.Optional_Boolean is
begin
return
AMF.Internals.Tables.DD_Attributes.Internal_Get_Font_Underline
(Self.Element);
end Get_Font_Underline;
------------------------
-- Set_Font_Underline --
------------------------
overriding procedure Set_Font_Underline
(Self : not null access DG_Style_Proxy;
To : AMF.Optional_Boolean) is
begin
AMF.Internals.Tables.DD_Attributes.Internal_Set_Font_Underline
(Self.Element, To);
end Set_Font_Underline;
-----------------------------
-- Get_Font_Strike_Through --
-----------------------------
overriding function Get_Font_Strike_Through
(Self : not null access constant DG_Style_Proxy)
return AMF.Optional_Boolean is
begin
return
AMF.Internals.Tables.DD_Attributes.Internal_Get_Font_Strike_Through
(Self.Element);
end Get_Font_Strike_Through;
-----------------------------
-- Set_Font_Strike_Through --
-----------------------------
overriding procedure Set_Font_Strike_Through
(Self : not null access DG_Style_Proxy;
To : AMF.Optional_Boolean) is
begin
AMF.Internals.Tables.DD_Attributes.Internal_Set_Font_Strike_Through
(Self.Element, To);
end Set_Font_Strike_Through;
-------------------
-- Enter_Element --
-------------------
overriding procedure Enter_Element
(Self : not null access constant DG_Style_Proxy;
Visitor : in out AMF.Visitors.Abstract_Visitor'Class;
Control : in out AMF.Visitors.Traverse_Control) is
begin
if Visitor in AMF.Visitors.DG_Visitors.DG_Visitor'Class then
AMF.Visitors.DG_Visitors.DG_Visitor'Class
(Visitor).Enter_Style
(AMF.DG.Styles.DG_Style_Access (Self),
Control);
end if;
end Enter_Element;
-------------------
-- Leave_Element --
-------------------
overriding procedure Leave_Element
(Self : not null access constant DG_Style_Proxy;
Visitor : in out AMF.Visitors.Abstract_Visitor'Class;
Control : in out AMF.Visitors.Traverse_Control) is
begin
if Visitor in AMF.Visitors.DG_Visitors.DG_Visitor'Class then
AMF.Visitors.DG_Visitors.DG_Visitor'Class
(Visitor).Leave_Style
(AMF.DG.Styles.DG_Style_Access (Self),
Control);
end if;
end Leave_Element;
-------------------
-- Visit_Element --
-------------------
overriding procedure Visit_Element
(Self : not null access constant DG_Style_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.DG_Iterators.DG_Iterator'Class then
AMF.Visitors.DG_Iterators.DG_Iterator'Class
(Iterator).Visit_Style
(Visitor,
AMF.DG.Styles.DG_Style_Access (Self),
Control);
end if;
end Visit_Element;
end AMF.Internals.DG_Styles;
|
AdaCore/training_material | Ada | 2,774 | ads | pragma Ada_2005;
pragma Style_Checks (Off);
with Interfaces.C; use Interfaces.C;
with Interfaces.C.Strings;
package SDL_error_h is
-- arg-macro: procedure SDL_OutOfMemory ()
-- SDL_Error(SDL_ENOMEM)
-- arg-macro: procedure SDL_Unsupported ()
-- SDL_Error(SDL_UNSUPPORTED)
-- arg-macro: procedure SDL_InvalidParamError (param)
-- SDL_SetError("Parameter '%s' is invalid", (param))
-- Simple DirectMedia Layer
-- Copyright (C) 1997-2018 Sam Lantinga <[email protected]>
-- This software is provided 'as-is', without any express or implied
-- warranty. In no event will the authors be held liable for any damages
-- arising from the use of this software.
-- Permission is granted to anyone to use this software for any purpose,
-- including commercial applications, and to alter it and redistribute it
-- freely, subject to the following restrictions:
-- 1. The origin of this software must not be misrepresented; you must not
-- claim that you wrote the original software. If you use this software
-- in a product, an acknowledgment in the product documentation would be
-- appreciated but is not required.
-- 2. Altered source versions must be plainly marked as such, and must not be
-- misrepresented as being the original software.
-- 3. This notice may not be removed or altered from any source distribution.
--
--*
-- * \file SDL_error.h
-- *
-- * Simple error message routines for SDL.
--
-- Set up for C function definitions, even when using C++
-- Public functions
-- SDL_SetError() unconditionally returns -1.
function SDL_SetError (fmt : Interfaces.C.Strings.chars_ptr -- , ...
) return int; -- ..\SDL2_tmp\SDL_error.h:41
pragma Import (C, SDL_SetError, "SDL_SetError");
function SDL_GetError return Interfaces.C.Strings.chars_ptr; -- ..\SDL2_tmp\SDL_error.h:42
pragma Import (C, SDL_GetError, "SDL_GetError");
procedure SDL_ClearError; -- ..\SDL2_tmp\SDL_error.h:43
pragma Import (C, SDL_ClearError, "SDL_ClearError");
--*
-- * \name Internal error functions
-- *
-- * \internal
-- * Private error reporting function - used internally.
--
-- @{
type SDL_errorcode is
(SDL_ENOMEM,
SDL_EFREAD,
SDL_EFWRITE,
SDL_EFSEEK,
SDL_UNSUPPORTED,
SDL_LASTERROR);
pragma Convention (C, SDL_errorcode); -- ..\SDL2_tmp\SDL_error.h:63
-- SDL_Error() unconditionally returns -1.
function SDL_Error (code : SDL_errorcode) return int; -- ..\SDL2_tmp\SDL_error.h:65
pragma Import (C, SDL_Error, "SDL_Error");
-- @}
-- Internal error functions
-- Ends C function definitions when using C++
-- vi: set ts=4 sw=4 expandtab:
end SDL_error_h;
|
AdaCore/Ada_Drivers_Library | Ada | 3,769 | ads | ------------------------------------------------------------------------------
-- --
-- Copyright (C) 2017, AdaCore --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions are --
-- met: --
-- 1. Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- 2. Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in --
-- the documentation and/or other materials provided with the --
-- distribution. --
-- 3. Neither the name of the copyright holder nor the names of its --
-- contributors may be used to endorse or promote products derived --
-- from this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT --
-- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, --
-- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY --
-- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT --
-- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE --
-- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- This package provides a protected interrupt handler that knows how to
-- handle all the DMA interrupts. It is used by clients to await a specific
-- interrupt occurrence. It is a reusable package and PO type.
-- For example:
--
-- Controller : DMA_Controller renames DMA_2;
--
-- Stream : constant DMA_Stream_Selector := Stream_0;
--
-- IRQ : constant Ada.Interrupts.Interrupt_ID := DMA2_Stream0_Interrupt;
-- -- must match that of the selected controller and stream number!
--
-- DMA_IRQ_Handler : DMA_Unit_IRQ_Handler (Controller'Access, Stream, IRQ);
with Ada.Interrupts; use Ada.Interrupts;
with STM32.DMA; use STM32.DMA;
package DMA_Interrupt_Handling is
protected type DMA_Unit_IRQ_Handler
(Controller : access DMA_Controller;
Stream : DMA_Stream_Selector;
IRQ : Interrupt_ID)
is
pragma Interrupt_Priority;
entry Await_Event (Occurrence : out DMA_Interrupt);
-- Blocks the caller until the next interrupt. Returns that interrupt in
-- Occurrence.
private
Event_Occurred : Boolean := False;
Event_Kind : DMA_Interrupt;
procedure IRQ_Handler;
pragma Attach_Handler (IRQ_Handler, IRQ);
-- Handles the interrupts and signals the entry, passing the interrupt
-- identifier via Event_Kind.
end DMA_Unit_IRQ_Handler;
end DMA_Interrupt_Handling;
|
notdb/LC-Practice | Ada | 187 | adb | function Increment_By
(I : Integer := 0;
Incr : Integer := 1) return Integer is
-- ^ Default value for parameters
begin
return I + Incr;
end Increment_By; |
AdaCore/libadalang | Ada | 212 | adb | procedure Test is
type Access_Proc is access procedure (Flag : Boolean);
function Func return Access_Proc is (null);
X : Access_Proc;
begin
X := Func.all'Access;
pragma Test_Statement;
end Test;
|
AdaCore/training_material | Ada | 5,269 | 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;
with Ada.Real_Time; use Ada.Real_Time;
package body Solar_System is
procedure Init_Body
(B : Bodies_Enum;
Radius : Float;
Color : RGBA_T;
Distance : Float;
Speed : Float;
Turns_Around : Bodies_Enum;
Angle : Float := 0.0;
Tail : Boolean := False;
Visible : Boolean := True)
is
begin
Bodies (B).Set_Data
((Distance => Distance,
Speed => Speed,
Angle => Angle,
Turns_Around => Turns_Around,
Visible => Visible,
Color => Color,
Radius => Radius,
Pos => (0.0, 0.0),
With_Tail => Tail,
Tail => (others => (0.0, 0.0))));
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_Type;
Turns_Around : Body_Type) return Float;
-- implement a function to compute the Y coordinate
-- y of the reference + distance * sin(angle)
function Compute_Y
(Body_To_Move : Body_Type;
Turns_Around : Body_Type) return Float;
function Compute_X
(Body_To_Move : Body_Type;
Turns_Around : Body_Type) return Float
is
begin
return Turns_Around.Pos.X +
Body_To_Move.Distance * Cos (Body_To_Move.Angle);
end Compute_X;
function Compute_X
(X_Ref : Float;
Angle : Float;
Distance : Float) return Float
is
begin
return X_Ref + Distance * Cos (Angle);
end Compute_X;
function Compute_Y
(Body_To_Move : Body_Type;
Turns_Around : Body_Type) return Float
is
begin
return Turns_Around.Pos.Y +
Body_To_Move.Distance * Sin (Body_To_Move.Angle);
end Compute_Y;
function Compute_Y
(Y_Ref : Float;
Angle : Float;
Distance : Float) return Float
is
begin
return Y_Ref + Distance * Sin (Angle);
end Compute_Y;
procedure Move
(Body_To_Move : in out Body_Type;
Turns_Around : Body_Type)
is
begin
Body_To_Move.Pos.X := Compute_X (Body_To_Move, Turns_Around);
Body_To_Move.Pos.Y := Compute_Y (Body_To_Move, Turns_Around);
Body_To_Move.Angle := Body_To_Move.Angle + Body_To_Move.Speed;
if Body_To_Move.With_Tail then
for I in Body_To_Move.Tail'First .. Body_To_Move.Tail'Last - 1 loop
Body_To_Move.Tail (I) := Body_To_Move.Tail (I + 1);
end loop;
Body_To_Move.Tail (T_Tail'Last) := Body_To_Move.Pos;
end if;
end Move;
protected body P_Body is
function Get_Data return Body_Type is
begin
return Data;
end Get_Data;
procedure Set_Data (B : Body_Type) is
begin
Data := B;
end Set_Data;
end P_Body;
protected body Dispatch_Tasks is
procedure Get_Next_Body (B : out Bodies_Enum) is
begin
B := Current;
if Current /= Bodies_Enum'Last then
Current := Bodies_Enum'Succ (Current);
end if;
end Get_Next_Body;
end Dispatch_Tasks;
task body T_Move_Body is
-- declare a variable Now of type Time to record current time
Now : Time;
-- declare a constant Period of 40 milliseconds of type Time_Span defining the loop period
Period : constant Time_Span := Milliseconds (20);
Current : Body_Type;
Turns_Around : Body_Type;
B : Bodies_Enum;
begin
Dispatch_Tasks.Get_Next_Body (B);
loop
Now := Clock;
Current := Bodies (B).Get_Data;
Turns_Around := Bodies (Current.Turns_Around).Get_Data;
Move (Current, Turns_Around);
Bodies (B).Set_Data (Current);
delay until Now + Period;
end loop;
end T_Move_Body;
end Solar_System;
|
AdaCore/libadalang | Ada | 666 | adb | with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
procedure Test2 is
S : String := "Hello" & '.' & "." & '.' & "World!";
pragma Test_Statement;
U : String := "Good" & ('/' & '\') & " bye";
pragma Test_Statement;
type T is array (Positive range <>) of Integer;
X : T := (1, 2, 3);
pragma Test_Statement;
Y : T := X & (4, 5, 6);
pragma Test_Statement;
Z : T := 7 & Y & 8;
pragma Test_Statement;
US1 : Unbounded_String := To_Unbounded_String ("!!!");
US2 : Unbounded_String;
begin
US2 := 'U' & "nbounded" & US1;
pragma Test_Statement_UID;
US2 := US1 & "dednuobn" & 'U';
pragma Test_Statement_UID;
end Test2;
|
alexcamposruiz/dds-requestreply | Ada | 83 | ads | package DDS.Request_Reply.treqtrepsimplereplier is
pragma Elaborate_Body;
end;
|
zhmu/ananas | Ada | 7,933 | adb | ------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- S Y S T E M . D O U B L E _ R E A L --
-- --
-- B o d y --
-- --
-- Copyright (C) 2021-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.Double_Real is
function Is_NaN (N : Num) return Boolean is (N /= N);
-- Return True if N is a NaN
function Is_Infinity (N : Num) return Boolean is (Is_NaN (N - N));
-- Return True if N is an infinity. Used to avoid propagating meaningless
-- errors when the result of a product is an infinity.
function Is_Zero (N : Num) return Boolean is (N = -N);
-- Return True if N is a Zero. Used to preserve the sign when the result of
-- a product is a zero.
package Product is
function Two_Prod (A, B : Num) return Double_T;
function Two_Sqr (A : Num) return Double_T;
end Product;
-- The low-level implementation of multiplicative operations
package body Product is separate;
-- This is a separate body because the implementation depends on whether a
-- Fused Multiply-Add instruction is available on the target.
-------------------
-- Quick_Two_Sum --
-------------------
function Quick_Two_Sum (A, B : Num) return Double_T is
S : constant Num := A + B;
V : constant Num := S - A;
E : constant Num := B - V;
begin
return (S, E);
end Quick_Two_Sum;
-------------
-- Two_Sum --
-------------
function Two_Sum (A, B : Num) return Double_T is
S : constant Num := A + B;
V : constant Num := S - A;
E : constant Num := (A - (S - V)) + (B - V);
begin
return (S, E);
end Two_Sum;
--------------
-- Two_Diff --
--------------
function Two_Diff (A, B : Num) return Double_T is
S : constant Num := A - B;
V : constant Num := S - A;
E : constant Num := (A - (S - V)) - (B + V);
begin
return (S, E);
end Two_Diff;
--------------
-- Two_Prod --
--------------
function Two_Prod (A, B : Num) return Double_T renames Product.Two_Prod;
-------------
-- Two_Sqr --
-------------
function Two_Sqr (A : Num) return Double_T renames Product.Two_Sqr;
---------
-- "+" --
---------
function "+" (A : Double_T; B : Num) return Double_T is
S : constant Double_T := Two_Sum (A.Hi, B);
begin
return Quick_Two_Sum (S.Hi, S.Lo + A.Lo);
end "+";
function "+" (A, B : Double_T) return Double_T is
S1 : constant Double_T := Two_Sum (A.Hi, B.Hi);
S2 : constant Double_T := Two_Sum (A.Lo, B.Lo);
S3 : constant Double_T := Quick_Two_Sum (S1.Hi, S1.Lo + S2.Hi);
begin
return Quick_Two_Sum (S3.Hi, S3.Lo + S2.Lo);
end "+";
---------
-- "-" --
---------
function "-" (A : Double_T; B : Num) return Double_T is
D : constant Double_T := Two_Diff (A.Hi, B);
begin
return Quick_Two_Sum (D.Hi, D.Lo + A.Lo);
end "-";
function "-" (A, B : Double_T) return Double_T is
D1 : constant Double_T := Two_Diff (A.Hi, B.Hi);
D2 : constant Double_T := Two_Diff (A.Lo, B.Lo);
D3 : constant Double_T := Quick_Two_Sum (D1.Hi, D1.Lo + D2.Hi);
begin
return Quick_Two_Sum (D3.Hi, D3.Lo + D2.Lo);
end "-";
---------
-- "*" --
---------
function "*" (A : Double_T; B : Num) return Double_T is
P : constant Double_T := Two_Prod (A.Hi, B);
begin
if Is_Infinity (P.Hi) or else Is_Zero (P.Hi) then
return (P.Hi, 0.0);
else
return Quick_Two_Sum (P.Hi, P.Lo + A.Lo * B);
end if;
end "*";
function "*" (A, B : Double_T) return Double_T is
P : constant Double_T := Two_Prod (A.Hi, B.Hi);
begin
if Is_Infinity (P.Hi) or else Is_Zero (P.Hi) then
return (P.Hi, 0.0);
else
return Quick_Two_Sum (P.Hi, P.Lo + A.Hi * B.Lo + A.Lo * B.Hi);
end if;
end "*";
---------
-- "/" --
---------
function "/" (A : Double_T; B : Num) return Double_T is
Q1, Q2 : Num;
P, R : Double_T;
begin
Q1 := A.Hi / B;
-- Compute R = A - B * Q1
P := Two_Prod (B, Q1);
R := Two_Diff (A.Hi, P.Hi);
R.Lo := (R.Lo + A.Lo) - P.Lo;
Q2 := (R.Hi + R.Lo) / B;
return Quick_Two_Sum (Q1, Q2);
end "/";
function "/" (A, B : Double_T) return Double_T is
Q1, Q2, Q3 : Num;
R, S : Double_T;
begin
Q1 := A.Hi / B.Hi;
R := A - B * Q1;
Q2 := R.Hi / B.Hi;
R := R - B * Q2;
Q3 := R.Hi / B.Hi;
S := Quick_Two_Sum (Q1, Q2);
return Quick_Two_Sum (S.Hi, S.Lo + Q3);
end "/";
---------
-- Sqr --
---------
function Sqr (A : Double_T) return Double_T is
Q : constant Double_T := Two_Sqr (A.Hi);
begin
if Is_Infinity (Q.Hi) or else Is_Zero (Q.Hi) then
return (Q.Hi, 0.0);
else
return Quick_Two_Sum (Q.Hi, Q.Lo + 2.0 * A.Hi * A.Lo + A.Lo * A.Lo);
end if;
end Sqr;
-------------------
-- From_Unsigned --
-------------------
function From_Unsigned (U : Uns) return Double_T is
begin
return To_Double (Num (U));
end From_Unsigned;
-----------------
-- To_Unsigned --
-----------------
function To_Unsigned (D : Double_T) return Uns is
Hi : constant Num := Num'Truncation (D.Hi);
begin
-- If the high part is already an integer, add Floor of the low part,
-- which means subtract Ceiling of its opposite if it is negative.
if Hi = D.Hi then
if D.Lo < 0.0 then
return Uns (Hi) - Uns (Num'Ceiling (-D.Lo));
else
return Uns (Hi) + Uns (Num'Floor (D.Lo));
end if;
else
return Uns (Hi);
end if;
end To_Unsigned;
end System.Double_Real;
|
stcarrez/ada-el | Ada | 1,973 | adb | -----------------------------------------------------------------------
-- el-contexts-tls -- EL context and Thread Local Support
-- Copyright (C) 2015, 2021 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 EL.Contexts.TLS is
Context : EL.Contexts.ELContext_Access := null with Thread_Local_Storage;
-- pragma Thread_Local_Storage (Context);
-- ------------------------------
-- Get the current EL context associated with the current thread.
-- ------------------------------
function Current return EL.Contexts.ELContext_Access is
begin
return Context;
end Current;
-- ------------------------------
-- Initialize and setup a new per-thread EL context.
-- ------------------------------
overriding
procedure Initialize (Obj : in out TLS_Context) is
begin
Obj.Previous := Context;
Context := Obj'Unchecked_Access;
EL.Contexts.Default.Default_Context (Obj).Initialize;
end Initialize;
-- ------------------------------
-- Restore the previous per-thread EL context.
-- ------------------------------
overriding
procedure Finalize (Obj : in out TLS_Context) is
begin
Context := Obj.Previous;
EL.Contexts.Default.Default_Context (Obj).Finalize;
end Finalize;
end EL.Contexts.TLS;
|
stcarrez/swagger-ada | Ada | 2,202 | adb | -----------------------------------------------------------------------
-- openapi-clients-tests -- Unit tests for clients
-- Copyright (C) 2017, 2022 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.Test_Caller;
package body OpenAPI.Clients.Tests is
package Caller is new Util.Test_Caller (Test, "OpenAPI.Clients");
procedure Add_Tests (Suite : in Util.Tests.Access_Test_Suite) is
begin
Caller.Add_Test (Suite, "Test OpenAPI.Clients.Set_Path",
Test_Set_Path'Access);
Caller.Add_Test (Suite, "Test OpenAPI.Clients.Add_Param",
Test_Add_Param'Access);
end Add_Tests;
-- ------------------------------
-- Test Set_Path operations.
-- ------------------------------
procedure Test_Set_Path (T : in out Test) is
URI : URI_Type;
begin
URI.Set_Path ("/admin/{user}");
URI.Set_Path_Param ("user", "admin");
Util.Tests.Assert_Equals (T, "/admin/admin", URI.To_String,
"To_String on URI is invalid");
end Test_Set_Path;
-- ------------------------------
-- Test Add_Param operations.
-- ------------------------------
procedure Test_Add_Param (T : in out Test) is
URI : URI_Type;
begin
URI.Set_Path ("/admin/list");
URI.Add_Param ("status", "active");
Util.Tests.Assert_Equals (T, "/admin/list?status=active", URI.To_String,
"To_String on URI is invalid");
end Test_Add_Param;
end OpenAPI.Clients.Tests;
|
annexi-strayline/AURA | Ada | 3,561 | adb | ------------------------------------------------------------------------------
-- --
-- Ada User Repository Annex (AURA) --
-- ANNEXI-STRAYLINE Reference Implementation --
-- --
-- Command Line Interface --
-- --
-- ------------------------------------------------------------------------ --
-- --
-- Copyright (C) 2020, ANNEXI-STRAYLINE Trans-Human Ltd. --
-- All rights reserved. --
-- --
-- Original Contributors: --
-- * Richard Wai (ANNEXI-STRAYLINE) --
-- --
-- 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 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 --
-- 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. --
-- --
------------------------------------------------------------------------------
package body Configuration.Executive is
end Configuration.Executive;
|
SietsevanderMolen/fly-thing | Ada | 8,335 | adb | with Ada.IO_Exceptions;
with Ada.Strings.Fixed;
with Interfaces; use Interfaces;
with Interfaces.C;
package body I2C is
function Read_Bit_Data (C : Chip'class;
R : Register;
Bit_Num : Integer) return Byte
is
Value : constant Integer := i2c_interface_c.read_byte_data
(Integer (C.On_Bus.FD), C.Address, R);
begin
if Value < 0 then
raise Ada.IO_Exceptions.Device_Error with "reading bit from chip"
& Chip_Address'Image (C.Address) & " at register "
& Register'Image (R) & " and bit number "
& Integer'Image (Bit_Num);
else
declare
Data : constant Byte := Byte (Value) and Shift_Left (1, Bit_Num);
begin
return Data;
end;
end if;
end Read_Bit_Data;
function Read_Bits_Data (C : Chip'class;
R : Register;
Start_Bit : Integer;
Length : Integer) return Byte
is
Value : constant Integer := i2c_interface_c.read_byte_data
(Integer (C.On_Bus.FD), C.Address, R);
begin
if Value < 0 then
raise Ada.IO_Exceptions.Device_Error with "reading from chip"
& Chip_Address'Image (C.Address);
else
-- 01101001 read byte
-- 76543210 bit numbers
-- xxx args: bitStart=4, length=3
-- 010 masked
-- -> 010 shifted
declare
Mask : constant Byte := Shift_Left (((Shift_Left (1, Length)) - 1),
(Start_Bit - Length + 1));
Masked_Data : constant Byte := Byte (Value) and Mask;
Shifted_Data : constant Byte :=
Shift_Right (Masked_Data, Start_Bit - Length + 1);
begin
return Shifted_Data;
end;
end if;
end Read_Bits_Data;
function Read_Byte (C : Chip'class) return Byte
is
Value : constant Integer := i2c_interface_c.read_byte
(Integer (C.On_Bus.FD), C.Address);
begin
if Value < 0 then
raise Ada.IO_Exceptions.Device_Error with "reading from chip"
& Chip_Address'Image (C.Address);
else
return Byte (Value);
end if;
end Read_Byte;
procedure Write_Byte (C : Chip'class; Data : Byte)
is
Status : Integer;
begin
Status := i2c_interface_c.write_byte
(Integer (C.On_Bus.FD), C.Address, Data);
if Status < 0 then
raise Ada.IO_Exceptions.Device_Error
with "writing " & Byte'Image (Data)
& " to chip " & Chip_Address'Image (C.Address);
end if;
end Write_Byte;
function Read_Byte_Data (C : Chip'class; R : Register) return Byte
is
Value : constant Integer := i2c_interface_c.read_byte_data
(Integer (C.On_Bus.FD), C.Address, R);
begin
if Value < 0 then
raise Ada.IO_Exceptions.Device_Error
with "reading from chip " & Chip_Address'Image (C.Address)
& " register" & Register'Image (R);
else
return Byte (Value);
end if;
end Read_Byte_Data;
procedure Write_Byte_Data (C : Chip'class; R : Register; D : Byte)
is
Status : Integer;
begin
Status :=
i2c_interface_c.write_byte_data
(Integer (C.On_Bus.FD), C.Address, R, D);
if Status < 0 then
raise Ada.IO_Exceptions.Device_Error
with "writing to chip " & Chip_Address'Image (C.Address)
& " register" & Register'Image (R);
end if;
end Write_Byte_Data;
function Read_Word_Data (C : Chip'class; R : Register) return Word
is
Value : constant Integer := i2c_interface_c.read_word_data
(Integer (C.On_Bus.FD), C.Address, R);
begin
if Value < 0 then
raise Ada.IO_Exceptions.Device_Error
with "reading from chip" & Chip_Address'Image (C.Address)
& " register" & Register'Image (R);
else
return Word (Value);
end if;
end Read_Word_Data;
procedure Write_Word_Data (C : Chip'class; R : Register; D : Word)
is
Status : Integer;
begin
Status := i2c_interface_c.write_word_data
(Integer (C.On_Bus.FD), C.Address, R, D);
if Status < 0 then
raise Ada.IO_Exceptions.Device_Error
with "writing to chip" & Chip_Address'Image (C.Address)
& " register" & Register'Image (R);
end if;
end Write_Word_Data;
procedure Write_Array_Data (C : Chip'class;
R : Register;
Values : Byte_Array) is
Status : Integer;
begin
Status := i2c_interface_c.write_i2c_block_data
(Integer (C.On_Bus.FD), C.Address, R, Values'Length, Values);
if Status < 0 then
raise Ada.IO_Exceptions.Device_Error
with "writing to register " & Register'Image (R)
& " on chip " & Chip_Address'Image (C.Address);
end if;
end Write_Array_Data;
function Read_Array_Data (C : Chip'class;
R : Register;
L : Integer) return Byte_Array is
Status : Integer;
Values : Byte_Array (0 .. L - 1);
begin
Status := i2c_interface_c.read_i2c_block_data
(Integer (C.On_Bus.FD), C.Address, R, Byte (L), Values);
if Status < 0 then
raise Ada.IO_Exceptions.Device_Error
with "reading from register " & Register'Image (R)
& " on chip " & Chip_Address'Image (C.Address)
& " status was " & Integer'Image (Status);
else
return Values;
end if;
end Read_Array_Data;
procedure Set_Slave_Address_To (C : in Chip) is
I2C_SLAVE : constant := 16#0703#;
function ioctl (FD : Interfaces.C.int;
Request : Interfaces.C.unsigned_long;
Address : Interfaces.C.int) return Interfaces.C.int;
pragma Import (C, ioctl, "ioctl");
use type Interfaces.C.int;
begin
if ioctl (Interfaces.C.int (C.On_Bus.FD),
I2C_SLAVE,
Interfaces.C.int (C.Address)) < 0
then
raise Ada.IO_Exceptions.Use_Error
with "unable to set slave address to"
& Chip_Address'Image (C.Address);
end if;
end Set_Slave_Address_To;
overriding
procedure Initialize (B : in out Bus)
is
use type GNAT.OS_Lib.File_Descriptor;
Which_Bus : constant String
:= Ada.Strings.Fixed.Trim (Adapter_Number_T'Image (B.Adapter_Number),
Side => Ada.Strings.Both);
begin
if B.FD /= GNAT.OS_Lib.Invalid_FD then
raise Ada.IO_Exceptions.Use_Error
with "I2C bus " & Which_Bus & " already open";
end if;
B.FD := GNAT.OS_Lib.Open_Read_Write
(Name => "/dev/i2c/" & Which_Bus,
Fmode => GNAT.OS_Lib.Binary);
if B.FD = GNAT.OS_Lib.Invalid_FD then
B.FD := GNAT.OS_Lib.Open_Read_Write
(Name => "/dev/i2c-" & Which_Bus,
Fmode => GNAT.OS_Lib.Binary);
end if;
if B.FD = GNAT.OS_Lib.Invalid_FD then
raise Ada.IO_Exceptions.Name_Error
with "unable to open either /dev/i2c/" & Which_Bus
& " or /dev/i2c-" & Which_Bus;
end if;
end Initialize;
overriding
procedure Finalize (B : in out Bus)
is
use type GNAT.OS_Lib.File_Descriptor;
begin
if B.FD /= GNAT.OS_Lib.Invalid_FD then
GNAT.OS_Lib.Close (B.FD);
B.FD := GNAT.OS_Lib.Invalid_FD;
end if;
end Finalize;
overriding
procedure Initialize (C : in out Chip)
is
I2C_SLAVE : constant := 16#0703#;
function ioctl (FD : Interfaces.C.int;
Request : Interfaces.C.unsigned_long;
Address : Interfaces.C.int) return Interfaces.C.int;
pragma Import (C, ioctl, "ioctl");
use type Interfaces.C.int;
begin
if ioctl (Interfaces.C.int (C.On_Bus.FD),
I2C_SLAVE,
Interfaces.C.int (C.Address)) < 0
then
raise Ada.IO_Exceptions.Use_Error
with "unable to set slave address to"
& Chip_Address'Image (C.Address);
end if;
end Initialize;
end I2C;
|
burratoo/Acton | Ada | 1,148 | ads | ------------------------------------------------------------------------------------------
-- --
-- OAKLAND COMPONENTS --
-- --
-- ADA.REAL_TIME.DELAYS --
-- --
-- Copyright (C) 2011-2021, Patrick Bernardi --
-- --
------------------------------------------------------------------------------------------
package Ada.Real_Time.Delays is
procedure Delay_Until (T : Time);
-- Delay until Clock has reached (at least) time T,
-- or the task is aborted to at least the current ATC nesting level.
-- The body of this procedure must perform all the processing
-- required for an abort point.
end Ada.Real_Time.Delays;
|
tum-ei-rcs/StratoX | Ada | 18,633 | ads | -- This spec has been automatically generated from STM32F40x.svd
pragma Restrictions (No_Elaboration_Code);
pragma Ada_2012;
with HAL;
with System;
package STM32_SVD.SDIO is
pragma Preelaborate;
---------------
-- Registers --
---------------
--------------------
-- POWER_Register --
--------------------
subtype POWER_PWRCTRL_Field is HAL.UInt2;
-- power control register
type POWER_Register is record
-- PWRCTRL
PWRCTRL : POWER_PWRCTRL_Field := 16#0#;
-- unspecified
Reserved_2_31 : HAL.UInt30 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for POWER_Register use record
PWRCTRL at 0 range 0 .. 1;
Reserved_2_31 at 0 range 2 .. 31;
end record;
--------------------
-- CLKCR_Register --
--------------------
subtype CLKCR_CLKDIV_Field is HAL.Byte;
subtype CLKCR_WIDBUS_Field is HAL.UInt2;
-- SDI clock control register
type CLKCR_Register is record
-- Clock divide factor
CLKDIV : CLKCR_CLKDIV_Field := 16#0#;
-- Clock enable bit
CLKEN : Boolean := False;
-- Power saving configuration bit
PWRSAV : Boolean := False;
-- Clock divider bypass enable bit
BYPASS : Boolean := False;
-- Wide bus mode enable bit
WIDBUS : CLKCR_WIDBUS_Field := 16#0#;
-- SDIO_CK dephasing selection bit
NEGEDGE : Boolean := False;
-- HW Flow Control enable
HWFC_EN : Boolean := False;
-- unspecified
Reserved_15_31 : HAL.UInt17 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for CLKCR_Register use record
CLKDIV at 0 range 0 .. 7;
CLKEN at 0 range 8 .. 8;
PWRSAV at 0 range 9 .. 9;
BYPASS at 0 range 10 .. 10;
WIDBUS at 0 range 11 .. 12;
NEGEDGE at 0 range 13 .. 13;
HWFC_EN at 0 range 14 .. 14;
Reserved_15_31 at 0 range 15 .. 31;
end record;
------------------
-- CMD_Register --
------------------
subtype CMD_CMDINDEX_Field is HAL.UInt6;
subtype CMD_WAITRESP_Field is HAL.UInt2;
-- command register
type CMD_Register is record
-- Command index
CMDINDEX : CMD_CMDINDEX_Field := 16#0#;
-- Wait for response bits
WAITRESP : CMD_WAITRESP_Field := 16#0#;
-- CPSM waits for interrupt request
WAITINT : Boolean := False;
-- CPSM Waits for ends of data transfer (CmdPend internal signal).
WAITPEND : Boolean := False;
-- Command path state machine (CPSM) Enable bit
CPSMEN : Boolean := False;
-- SD I/O suspend command
SDIOSuspend : Boolean := False;
-- Enable CMD completion
ENCMDcompl : Boolean := False;
-- not Interrupt Enable
nIEN : Boolean := False;
-- CE-ATA command
CE_ATACMD : Boolean := False;
-- unspecified
Reserved_15_31 : HAL.UInt17 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for CMD_Register use record
CMDINDEX at 0 range 0 .. 5;
WAITRESP at 0 range 6 .. 7;
WAITINT at 0 range 8 .. 8;
WAITPEND at 0 range 9 .. 9;
CPSMEN at 0 range 10 .. 10;
SDIOSuspend at 0 range 11 .. 11;
ENCMDcompl at 0 range 12 .. 12;
nIEN at 0 range 13 .. 13;
CE_ATACMD at 0 range 14 .. 14;
Reserved_15_31 at 0 range 15 .. 31;
end record;
----------------------
-- RESPCMD_Register --
----------------------
subtype RESPCMD_RESPCMD_Field is HAL.UInt6;
-- command response register
type RESPCMD_Register is record
-- Read-only. Response command index
RESPCMD : RESPCMD_RESPCMD_Field;
-- unspecified
Reserved_6_31 : HAL.UInt26;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for RESPCMD_Register use record
RESPCMD at 0 range 0 .. 5;
Reserved_6_31 at 0 range 6 .. 31;
end record;
-------------------
-- DLEN_Register --
-------------------
subtype DLEN_DATALENGTH_Field is HAL.UInt25;
-- data length register
type DLEN_Register is record
-- Data length value
DATALENGTH : DLEN_DATALENGTH_Field := 16#0#;
-- unspecified
Reserved_25_31 : HAL.UInt7 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for DLEN_Register use record
DATALENGTH at 0 range 0 .. 24;
Reserved_25_31 at 0 range 25 .. 31;
end record;
--------------------
-- DCTRL_Register --
--------------------
subtype DCTRL_DBLOCKSIZE_Field is HAL.UInt4;
-- data control register
type DCTRL_Register is record
-- DTEN
DTEN : Boolean := False;
-- Data transfer direction selection
DTDIR : Boolean := False;
-- Data transfer mode selection 1: Stream or SDIO multibyte data
-- transfer.
DTMODE : Boolean := False;
-- DMA enable bit
DMAEN : Boolean := False;
-- Data block size
DBLOCKSIZE : DCTRL_DBLOCKSIZE_Field := 16#0#;
-- Read wait start
RWSTART : Boolean := False;
-- Read wait stop
RWSTOP : Boolean := False;
-- Read wait mode
RWMOD : Boolean := False;
-- SD I/O enable functions
SDIOEN : Boolean := False;
-- unspecified
Reserved_12_31 : HAL.UInt20 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for DCTRL_Register use record
DTEN at 0 range 0 .. 0;
DTDIR at 0 range 1 .. 1;
DTMODE at 0 range 2 .. 2;
DMAEN at 0 range 3 .. 3;
DBLOCKSIZE at 0 range 4 .. 7;
RWSTART at 0 range 8 .. 8;
RWSTOP at 0 range 9 .. 9;
RWMOD at 0 range 10 .. 10;
SDIOEN at 0 range 11 .. 11;
Reserved_12_31 at 0 range 12 .. 31;
end record;
---------------------
-- DCOUNT_Register --
---------------------
subtype DCOUNT_DATACOUNT_Field is HAL.UInt25;
-- data counter register
type DCOUNT_Register is record
-- Read-only. Data count value
DATACOUNT : DCOUNT_DATACOUNT_Field;
-- unspecified
Reserved_25_31 : HAL.UInt7;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for DCOUNT_Register use record
DATACOUNT at 0 range 0 .. 24;
Reserved_25_31 at 0 range 25 .. 31;
end record;
------------------
-- STA_Register --
------------------
-- status register
type STA_Register is record
-- Read-only. Command response received (CRC check failed)
CCRCFAIL : Boolean;
-- Read-only. Data block sent/received (CRC check failed)
DCRCFAIL : Boolean;
-- Read-only. Command response timeout
CTIMEOUT : Boolean;
-- Read-only. Data timeout
DTIMEOUT : Boolean;
-- Read-only. Transmit FIFO underrun error
TXUNDERR : Boolean;
-- Read-only. Received FIFO overrun error
RXOVERR : Boolean;
-- Read-only. Command response received (CRC check passed)
CMDREND : Boolean;
-- Read-only. Command sent (no response required)
CMDSENT : Boolean;
-- Read-only. Data end (data counter, SDIDCOUNT, is zero)
DATAEND : Boolean;
-- Read-only. Start bit not detected on all data signals in wide bus
-- mode
STBITERR : Boolean;
-- Read-only. Data block sent/received (CRC check passed)
DBCKEND : Boolean;
-- Read-only. Command transfer in progress
CMDACT : Boolean;
-- Read-only. Data transmit in progress
TXACT : Boolean;
-- Read-only. Data receive in progress
RXACT : Boolean;
-- Read-only. Transmit FIFO half empty: at least 8 words can be written
-- into the FIFO
TXFIFOHE : Boolean;
-- Read-only. Receive FIFO half full: there are at least 8 words in the
-- FIFO
RXFIFOHF : Boolean;
-- Read-only. Transmit FIFO full
TXFIFOF : Boolean;
-- Read-only. Receive FIFO full
RXFIFOF : Boolean;
-- Read-only. Transmit FIFO empty
TXFIFOE : Boolean;
-- Read-only. Receive FIFO empty
RXFIFOE : Boolean;
-- Read-only. Data available in transmit FIFO
TXDAVL : Boolean;
-- Read-only. Data available in receive FIFO
RXDAVL : Boolean;
-- Read-only. SDIO interrupt received
SDIOIT : Boolean;
-- Read-only. CE-ATA command completion signal received for CMD61
CEATAEND : Boolean;
-- unspecified
Reserved_24_31 : HAL.Byte;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for STA_Register use record
CCRCFAIL at 0 range 0 .. 0;
DCRCFAIL at 0 range 1 .. 1;
CTIMEOUT at 0 range 2 .. 2;
DTIMEOUT at 0 range 3 .. 3;
TXUNDERR at 0 range 4 .. 4;
RXOVERR at 0 range 5 .. 5;
CMDREND at 0 range 6 .. 6;
CMDSENT at 0 range 7 .. 7;
DATAEND at 0 range 8 .. 8;
STBITERR at 0 range 9 .. 9;
DBCKEND at 0 range 10 .. 10;
CMDACT at 0 range 11 .. 11;
TXACT at 0 range 12 .. 12;
RXACT at 0 range 13 .. 13;
TXFIFOHE at 0 range 14 .. 14;
RXFIFOHF at 0 range 15 .. 15;
TXFIFOF at 0 range 16 .. 16;
RXFIFOF at 0 range 17 .. 17;
TXFIFOE at 0 range 18 .. 18;
RXFIFOE at 0 range 19 .. 19;
TXDAVL at 0 range 20 .. 20;
RXDAVL at 0 range 21 .. 21;
SDIOIT at 0 range 22 .. 22;
CEATAEND at 0 range 23 .. 23;
Reserved_24_31 at 0 range 24 .. 31;
end record;
------------------
-- ICR_Register --
------------------
-- interrupt clear register
type ICR_Register is record
-- CCRCFAIL flag clear bit
CCRCFAILC : Boolean := False;
-- DCRCFAIL flag clear bit
DCRCFAILC : Boolean := False;
-- CTIMEOUT flag clear bit
CTIMEOUTC : Boolean := False;
-- DTIMEOUT flag clear bit
DTIMEOUTC : Boolean := False;
-- TXUNDERR flag clear bit
TXUNDERRC : Boolean := False;
-- RXOVERR flag clear bit
RXOVERRC : Boolean := False;
-- CMDREND flag clear bit
CMDRENDC : Boolean := False;
-- CMDSENT flag clear bit
CMDSENTC : Boolean := False;
-- DATAEND flag clear bit
DATAENDC : Boolean := False;
-- STBITERR flag clear bit
STBITERRC : Boolean := False;
-- DBCKEND flag clear bit
DBCKENDC : Boolean := False;
-- unspecified
Reserved_11_21 : HAL.UInt11 := 16#0#;
-- SDIOIT flag clear bit
SDIOITC : Boolean := False;
-- CEATAEND flag clear bit
CEATAENDC : Boolean := False;
-- unspecified
Reserved_24_31 : HAL.Byte := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for ICR_Register use record
CCRCFAILC at 0 range 0 .. 0;
DCRCFAILC at 0 range 1 .. 1;
CTIMEOUTC at 0 range 2 .. 2;
DTIMEOUTC at 0 range 3 .. 3;
TXUNDERRC at 0 range 4 .. 4;
RXOVERRC at 0 range 5 .. 5;
CMDRENDC at 0 range 6 .. 6;
CMDSENTC at 0 range 7 .. 7;
DATAENDC at 0 range 8 .. 8;
STBITERRC at 0 range 9 .. 9;
DBCKENDC at 0 range 10 .. 10;
Reserved_11_21 at 0 range 11 .. 21;
SDIOITC at 0 range 22 .. 22;
CEATAENDC at 0 range 23 .. 23;
Reserved_24_31 at 0 range 24 .. 31;
end record;
-------------------
-- MASK_Register --
-------------------
-- mask register
type MASK_Register is record
-- Command CRC fail interrupt enable
CCRCFAILIE : Boolean := False;
-- Data CRC fail interrupt enable
DCRCFAILIE : Boolean := False;
-- Command timeout interrupt enable
CTIMEOUTIE : Boolean := False;
-- Data timeout interrupt enable
DTIMEOUTIE : Boolean := False;
-- Tx FIFO underrun error interrupt enable
TXUNDERRIE : Boolean := False;
-- Rx FIFO overrun error interrupt enable
RXOVERRIE : Boolean := False;
-- Command response received interrupt enable
CMDRENDIE : Boolean := False;
-- Command sent interrupt enable
CMDSENTIE : Boolean := False;
-- Data end interrupt enable
DATAENDIE : Boolean := False;
-- Start bit error interrupt enable
STBITERRIE : Boolean := False;
-- Data block end interrupt enable
DBCKENDIE : Boolean := False;
-- Command acting interrupt enable
CMDACTIE : Boolean := False;
-- Data transmit acting interrupt enable
TXACTIE : Boolean := False;
-- Data receive acting interrupt enable
RXACTIE : Boolean := False;
-- Tx FIFO half empty interrupt enable
TXFIFOHEIE : Boolean := False;
-- Rx FIFO half full interrupt enable
RXFIFOHFIE : Boolean := False;
-- Tx FIFO full interrupt enable
TXFIFOFIE : Boolean := False;
-- Rx FIFO full interrupt enable
RXFIFOFIE : Boolean := False;
-- Tx FIFO empty interrupt enable
TXFIFOEIE : Boolean := False;
-- Rx FIFO empty interrupt enable
RXFIFOEIE : Boolean := False;
-- Data available in Tx FIFO interrupt enable
TXDAVLIE : Boolean := False;
-- Data available in Rx FIFO interrupt enable
RXDAVLIE : Boolean := False;
-- SDIO mode interrupt received interrupt enable
SDIOITIE : Boolean := False;
-- CE-ATA command completion signal received interrupt enable
CEATAENDIE : Boolean := False;
-- unspecified
Reserved_24_31 : HAL.Byte := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for MASK_Register use record
CCRCFAILIE at 0 range 0 .. 0;
DCRCFAILIE at 0 range 1 .. 1;
CTIMEOUTIE at 0 range 2 .. 2;
DTIMEOUTIE at 0 range 3 .. 3;
TXUNDERRIE at 0 range 4 .. 4;
RXOVERRIE at 0 range 5 .. 5;
CMDRENDIE at 0 range 6 .. 6;
CMDSENTIE at 0 range 7 .. 7;
DATAENDIE at 0 range 8 .. 8;
STBITERRIE at 0 range 9 .. 9;
DBCKENDIE at 0 range 10 .. 10;
CMDACTIE at 0 range 11 .. 11;
TXACTIE at 0 range 12 .. 12;
RXACTIE at 0 range 13 .. 13;
TXFIFOHEIE at 0 range 14 .. 14;
RXFIFOHFIE at 0 range 15 .. 15;
TXFIFOFIE at 0 range 16 .. 16;
RXFIFOFIE at 0 range 17 .. 17;
TXFIFOEIE at 0 range 18 .. 18;
RXFIFOEIE at 0 range 19 .. 19;
TXDAVLIE at 0 range 20 .. 20;
RXDAVLIE at 0 range 21 .. 21;
SDIOITIE at 0 range 22 .. 22;
CEATAENDIE at 0 range 23 .. 23;
Reserved_24_31 at 0 range 24 .. 31;
end record;
----------------------
-- FIFOCNT_Register --
----------------------
subtype FIFOCNT_FIFOCOUNT_Field is HAL.UInt24;
-- FIFO counter register
type FIFOCNT_Register is record
-- Read-only. Remaining number of words to be written to or read from
-- the FIFO.
FIFOCOUNT : FIFOCNT_FIFOCOUNT_Field;
-- unspecified
Reserved_24_31 : HAL.Byte;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for FIFOCNT_Register use record
FIFOCOUNT at 0 range 0 .. 23;
Reserved_24_31 at 0 range 24 .. 31;
end record;
-----------------
-- Peripherals --
-----------------
-- Secure digital input/output interface
type SDIO_Peripheral is record
-- power control register
POWER : POWER_Register;
-- SDI clock control register
CLKCR : CLKCR_Register;
-- argument register
ARG : HAL.Word;
-- command register
CMD : CMD_Register;
-- command response register
RESPCMD : RESPCMD_Register;
-- response 1..4 register
RESP1 : HAL.Word;
-- response 1..4 register
RESP2 : HAL.Word;
-- response 1..4 register
RESP3 : HAL.Word;
-- response 1..4 register
RESP4 : HAL.Word;
-- data timer register
DTIMER : HAL.Word;
-- data length register
DLEN : DLEN_Register;
-- data control register
DCTRL : DCTRL_Register;
-- data counter register
DCOUNT : DCOUNT_Register;
-- status register
STA : STA_Register;
-- interrupt clear register
ICR : ICR_Register;
-- mask register
MASK : MASK_Register;
-- FIFO counter register
FIFOCNT : FIFOCNT_Register;
-- data FIFO register
FIFO : HAL.Word;
end record
with Volatile;
for SDIO_Peripheral use record
POWER at 0 range 0 .. 31;
CLKCR at 4 range 0 .. 31;
ARG at 8 range 0 .. 31;
CMD at 12 range 0 .. 31;
RESPCMD at 16 range 0 .. 31;
RESP1 at 20 range 0 .. 31;
RESP2 at 24 range 0 .. 31;
RESP3 at 28 range 0 .. 31;
RESP4 at 32 range 0 .. 31;
DTIMER at 36 range 0 .. 31;
DLEN at 40 range 0 .. 31;
DCTRL at 44 range 0 .. 31;
DCOUNT at 48 range 0 .. 31;
STA at 52 range 0 .. 31;
ICR at 56 range 0 .. 31;
MASK at 60 range 0 .. 31;
FIFOCNT at 72 range 0 .. 31;
FIFO at 128 range 0 .. 31;
end record;
-- Secure digital input/output interface
SDIO_Periph : aliased SDIO_Peripheral
with Import, Address => SDIO_Base;
end STM32_SVD.SDIO;
|
VitalijBondarenko/Formatted_Output_NG | Ada | 14,958 | adb | ------------------------------------------------------------------------------
-- --
-- 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. --
------------------------------------------------------------------------------
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
with Ada.Float_Text_IO; use Ada.Float_Text_IO;
with Ada.Strings; use Ada.Strings;
with Ada.Strings.Fixed; use Ada.Strings.Fixed;
with Ada.Strings.Maps; use Ada.Strings.Maps;
with Interfaces.C.Strings; use Interfaces.C.Strings;
with L10n.Localeinfo; use L10n.Localeinfo;
package body Formatted_Output is
---------------
-- To_Format --
---------------
function To_Format (Fmt_String : String) return Format_Type is
begin
return To_Unbounded_String (Fmt_String);
end To_Format;
---------------
-- To_String --
---------------
function To_String (Fmt : Format_Type) return String is
CR : constant String (1 .. 1) := (1 => ASCII.CR);
LF : constant String (1 .. 1) := (1 => ASCII.LF);
BS : constant String (1 .. 1) := (1 => ASCII.BS);
HT : constant String (1 .. 1) := (1 => ASCII.HT);
FF : constant String (1 .. 1) := (1 => ASCII.FF);
I : Integer := 1;
Fmt_Copy : Unbounded_String := Unbounded_String (Fmt);
begin
while I < Length (Fmt_Copy) loop
if Element (Fmt_Copy, I) = '\' then
case Element (Fmt_Copy, I + 1) is
when 'n' =>
Replace_Slice (Fmt_Copy, I, I + 1, LF);
-- I := I + 1;
-- Uncomment line above, if your system using two-byte
-- representation of the next line character. Example of
-- such system is EZ2LOAD.
when 'r' =>
Replace_Slice (Fmt_Copy, I, I + 1, CR);
when 'b' =>
Replace_Slice (Fmt_Copy, I, I + 1, BS);
when 't' =>
Replace_Slice (Fmt_Copy, I, I + 1, HT);
when 'f' =>
Replace_Slice (Fmt_Copy, I, I + 1, FF);
when '\' =>
Delete (Fmt_Copy, I, I);
when others =>
null;
end case;
elsif Element (Fmt_Copy, I) = '%' then
case Element (Fmt_Copy, I + 1) is
when '%' =>
Delete (Fmt_Copy, I, I);
when others =>
raise Format_Error;
end case;
end if;
I := I + 1;
end loop;
return To_String (Fmt_Copy);
end To_String;
-------------------
-- Format_String --
-------------------
function Format_String
(Value : String;
Initial_Width : Integer;
Justification : Alignment) return String
is
Width : Integer;
begin
if Initial_Width < Value'Length then
Width := Value'Length;
else
Width := Initial_Width;
end if;
declare
S : String (1 .. Width);
begin
Move (Value, S, Justify => Justification, Pad => Filler);
return S;
end;
end Format_String;
---------
-- "&" --
---------
function "&" (Fmt : Format_Type; Value : String) return Format_Type is
Command_Start : constant Integer := Scan_To_Percent_Sign (Fmt);
Width : Integer := 0;
Digit_Occured : Boolean := False;
Justification_Changed : Boolean := False;
Justification : Alignment := Right;
Fmt_Copy : Unbounded_String;
begin
if Command_Start /= 0 then
Fmt_Copy := Unbounded_String (Fmt);
for I in Command_Start + 1 .. Length (Fmt_Copy) loop
case Element (Fmt_Copy, I) is
when 's' =>
Replace_Slice
(Fmt_Copy, Command_Start, I,
Format_String (Value, Width, Justification));
return Format_Type (Fmt_Copy);
when '-' | '+' | '*' =>
if Justification_Changed or else Digit_Occured then
raise Format_Error;
end if;
Justification_Changed := True;
case Element (Fmt_Copy, I) is
when '-' =>
Justification := Left;
when '+' =>
Justification := Right;
when '*' =>
Justification := Center;
when others =>
null;
end case;
when '0' .. '9' =>
Digit_Occured := True;
Width := Width * 10
+ Character'Pos (Element (Fmt_Copy, I))
- Character'Pos ('0');
when others =>
raise Format_Error;
end case;
end loop;
end if;
raise Format_Error;
end "&";
---------
-- Put --
---------
procedure Put (Fmt : Format_Type) is
begin
Put (To_String (Fmt));
end Put;
---------
-- Put --
---------
procedure Put (File : File_Type; Fmt : Format_Type) is
begin
Put (File, To_String (Fmt));
end Put;
--------------
-- Put_Line --
--------------
procedure Put_Line (Fmt : Format_Type) is
begin
Put_Line (To_String (Fmt));
end Put_Line;
--------------
-- Put_Line --
--------------
procedure Put_Line (File : File_Type; Fmt : Format_Type) is
begin
Put_Line (File, To_String (Fmt));
end Put_Line;
--------------------------
-- Scan_To_Percent_Sign --
--------------------------
function Scan_To_Percent_Sign (Fmt : Format_Type) return Integer is
I : Natural := 1;
begin
while I < Length (Fmt) loop
if Element (Fmt, I) = '%' then
if Element (Fmt, I + 1) /= '%' then
return I;
else
I := I + 1;
end if;
end if;
I := I + 1;
end loop;
return 0;
end Scan_To_Percent_Sign;
-----------------------------
-- Decimal_Point_Character --
-----------------------------
function Decimal_Point_Character return String is
Lconv : C_Lconv_Access := C_Localeconv;
begin
if Lconv.Decimal_Point = Null_Ptr then
return Ada_Dec_Point_Character;
else
return Value (Lconv.Decimal_Point);
end if;
exception
when others => return Ada_Dec_Point_Character;
end Decimal_Point_Character;
-----------------------------
-- Thousands_Sep_Character --
-----------------------------
function Thousands_Sep_Character return String is
Lconv : C_Lconv_Access := C_Localeconv;
begin
if Lconv.Thousands_Sep = Null_Ptr then
return "";
else
declare
S : String := Value (Lconv.Thousands_Sep);
begin
if S'Length > 1 then
return " ";
else
return S;
end if;
end;
end if;
exception
when others => return "";
end Thousands_Sep_Character;
---------------------------
-- Separate_Digit_Groups --
---------------------------
function Separate_Digit_Groups
(Text_Value : String;
Separator : String;
Group_Size : Integer) return String
is
Tmp : Unbounded_String := Null_Unbounded_String;
I : Integer;
J : Integer := Text_Value'Last;
begin
if Separator'Length = 0 then
return Text_Value;
end if;
while J >= Text_Value'First loop
I := J - Group_Size + 1;
if I <= Text_Value'First then
Insert (Tmp, 1, Text_Value (Text_Value'First .. J));
exit;
else
Insert (Tmp, 1, Separator & Text_Value (I .. J));
end if;
J := J - Group_Size;
end loop;
return To_String (Tmp);
exception
when others => return "";
end Separate_Digit_Groups;
-- ---------------------------------
-- -- Separate_Based_Digit_Groups --
-- ---------------------------------
--
-- function Separate_Based_Digit_Groups
-- (Text_Value : String;
-- Separator : String;
-- Group_Size : Integer) return String
-- is
-- Tmp : Unbounded_String := Null_Unbounded_String;
-- NS1 : Natural := Index (Text_Value, "#", Text_Value'First);
-- NS2 : Natural;
-- begin
-- if NS1 > 0 then
-- NS2 := Index (Text_Value, "#", NS1 + 1);
-- else
-- return "";
-- end if;
--
-- declare
-- TS : String := Text_Value (NS1 + 1 .. NS2 - 1);
-- I : Integer;
-- J : Integer := TS'Last;
-- begin
-- while J >= TS'First loop
-- I := J - Group_Size + 1;
--
-- if I <= TS'First then
-- Insert (Tmp, 1, TS (TS'First .. J));
-- exit;
-- end if;
--
-- Insert (Tmp, 1, Separator & TS (I .. J));
-- J := J - Group_Size;
-- end loop;
-- end;
--
-- Tmp := Text_Value (Text_Value'First .. NS1) & Tmp;
-- Tmp := Tmp & Text_Value (NS2 .. Text_Value'Last);
-- return To_String (Tmp);
--
-- exception
-- when others => return "";
-- end Separate_Based_Digit_Groups;
----------------------
-- Set_Leading_Zero --
----------------------
function Set_Leading_Zero (Img : String) return String is
S : String := Img;
FD : Natural := 0;
Cur : Natural := 0;
NS1 : Natural := 0;
begin
FD := Index_Non_Blank (Img, Forward);
if Img (FD) = '-' or else Img (FD) = '+' then
S (1) := Img (FD);
Cur := 1;
FD := FD + 1;
end if;
-- check using base
NS1 := Index
(Source => Img,
Set => To_Set ("#xX"),
From => FD,
Test => Inside,
Going => Forward);
if NS1 > 0 then
for I in FD .. NS1 loop
Cur := Cur + 1;
S (Cur) := Img (I);
end loop;
for I in Cur + 1 .. NS1 loop
S (I) := '0';
end loop;
else
for I in Cur + 1 .. FD - 1 loop
S (I) := '0';
end loop;
end if;
return S;
end Set_Leading_Zero;
----------------------
-- Set_Leading_Zero --
----------------------
function Set_Leading_Zero
(Img : String; Separator : String; Group_Size : Integer) return String
is
S : String := Img;
FD : Natural := Index_Non_Blank (Img, Forward);
Cur : Natural := 0;
NS1 : Natural := 0;
NS2 : Natural := 0;
I : Integer := 0;
J : Integer := 0;
begin
if Separator'Length = 0 then
return Set_Leading_Zero (Img);
end if;
FD := Index_Non_Blank (Img, Forward);
if Img (FD) = '-' or else Img (FD) = '+' then
S (1) := Img (FD);
Cur := 1;
FD := FD + 1;
end if;
-- check using base
NS1 := Index
(Source => Img,
Set => To_Set ("#xX"),
From => FD,
Test => Inside,
Going => Forward);
NS2 := Index (Img, Separator, FD);
if NS1 > 0 then
for I in FD .. NS1 loop
Cur := Cur + 1;
S (Cur) := Img (I);
end loop;
I := Cur + 1;
J := NS1;
if NS2 = 0 then
NS2 := Img'Length - Group_Size - 1;
end if;
else
I := Cur + 1;
J := FD - 1;
if NS2 = 0 then
NS2 := Img'Length - Group_Size;
end if;
end if;
for P in I .. J loop
S (P) := '0';
end loop;
S (NS2) := Separator (Separator'First);
J := NS2;
while J >= Cur + 1 loop
I := J - Group_Size - 1;
if I >= Cur + 1 then
S (I) := Separator (Separator'First);
end if;
J := I;
end loop;
if NS1 = 0 and then S (Cur + 1) = Separator (Separator'First) then
if Cur = 0 then
S (1) := Filler;
else
S (Cur + 1) := S (Cur);
S (Cur) := Filler;
end if;
elsif NS1 > 0 and then S (Cur + 1) = Separator (Separator'First) then
for P in reverse 2 .. Cur + 1 loop
S (P) := S (P - 1);
end loop;
S (1) := Filler;
end if;
return S;
end Set_Leading_Zero;
end Formatted_Output;
|
AdaCore/Ada_Drivers_Library | Ada | 2,865 | adb | ------------------------------------------------------------------------------
-- --
-- Copyright (C) 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 STM32.EXTI; use STM32.EXTI;
package body Gyro_Interrupts is
-------------
-- Handler --
-------------
protected body Handler is
-----------------
-- IRQ_Handler --
-----------------
procedure IRQ_Handler is
begin
if External_Interrupt_Pending (EXTI_Line_2) then
Set_True (Data_Available);
Clear_External_Interrupt (EXTI_Line_2);
end if;
end IRQ_Handler;
end Handler;
end Gyro_Interrupts;
|
AdaCore/ada-traits-containers | Ada | 5,886 | adb | package body Use_Maps with SPARK_Mode is
pragma Unevaluated_Use_Of_Old (Allow);
function My_Find (S : My_Maps.Map; K : Positive) return Cursor is
Cu : Cursor := First (S);
begin
while Has_Element (S, Cu) loop
pragma Loop_Invariant
(for all I in 1 .. P_Get (Positions (S), Cu) - 1 =>
Get (S_Keys (S), I) /= K);
if As_Key (S, Cu) = K then
return Cu;
end if;
Cu := Next (S, Cu);
end loop;
return No_Element;
end My_Find;
procedure Apply_F (S : My_Maps.Map; R : in out My_Maps.Map) is
Cu : Cursor := First (S);
begin
Clear (R);
while Has_Element (S, Cu) loop
pragma Loop_Invariant (Length (R) = P_Get (Positions (S), Cu) - 1);
pragma Loop_Invariant
(for all I in 1 .. P_Get (Positions (S), Cu) - 1 =>
(for some K of R =>
As_Element (R, K) =
F (As_Element (S, Get (S_Keys (S), I)))));
pragma Loop_Invariant
(for all K of R =>
(for some I in 1 .. P_Get (Positions (S), Cu) - 1 =>
As_Element (R, K) =
F (As_Element (S, Get (S_Keys (S), I)))));
pragma Loop_Invariant
(for all I in P_Get (Positions (S), Cu) .. Length (S) =>
not Mem (Model (R), Get (S_Keys (S), I)));
Set (R, As_Key (S, Cu), F (Element (S, Cu)));
Cu := Next (S, Cu);
end loop;
end Apply_F;
procedure Apply_F_2 (S : My_Maps.Map; R : in out My_Maps.Map) is
Cu : Cursor := First (S);
begin
Clear (R);
while Has_Element (S, Cu) loop
pragma Loop_Invariant (Length (R) = P_Get (Positions (S), Cu) - 1);
pragma Loop_Invariant
(for all I in 1 .. P_Get (Positions (S), Cu) - 1 =>
Mem (Model (R), Get (S_Keys (S), I))
and then As_Element (R, Get (S_Keys (S), I)) =
F (As_Element (S, Get (S_Keys (S), I))));
pragma Loop_Invariant
(for all K of R =>
(for some I in 1 .. P_Get (Positions (S), Cu) - 1 =>
K = Get (S_Keys (S), I)));
Set (R, As_Key (S, Cu), F (Element (S, Cu)));
Cu := Next (S, Cu);
end loop;
end Apply_F_2;
procedure Apply_F_3 (S : in out My_Maps.Map) is
Cu : Cursor := First (S);
begin
while Has_Element (S, Cu) loop
pragma Loop_Invariant (Capacity (S) = Capacity (S)'Loop_Entry);
pragma Loop_Invariant (Positions (S) = Positions (S)'Loop_Entry);
pragma Loop_Invariant (S_Keys (S) = S_Keys (S)'Loop_Entry);
pragma Loop_Invariant
(for all I in 1 .. P_Get (Positions (S), Cu) - 1 =>
As_Element (S, Get (S_Keys (S), I)) =
F (Element (Model (S)'Loop_Entry, Get (S_Keys (S), I))));
pragma Loop_Invariant
(for all I in P_Get (Positions (S), Cu) .. Length (S) =>
Element (Model (S)'Loop_Entry, Get (S_Keys (S), I)) =
As_Element (S, Get (S_Keys (S), I)));
Set (S, As_Key (S, Cu), F (As_Element (S, Cu)));
Cu := Next (S, Cu);
end loop;
end Apply_F_3;
procedure Apply_F_4 (S : in out My_Maps.Map) is
Cu : Cursor := First (S);
begin
while Has_Element (S, Cu) loop
pragma Loop_Invariant (Capacity (S) = Capacity (S)'Loop_Entry);
pragma Loop_Invariant (Positions (S) = Positions (S)'Loop_Entry);
pragma Loop_Invariant (S_Keys (S) = S_Keys (S)'Loop_Entry);
pragma Loop_Invariant
(for all I in 1 .. P_Get (Positions (S), Cu) - 1 =>
As_Element (S, Get (S_Keys (S), I)) =
F (Element (Model (S)'Loop_Entry, Get (S_Keys (S), I))));
pragma Loop_Invariant
(for all I in P_Get (Positions (S), Cu) .. Length (S) =>
Element (Model (S)'Loop_Entry, Get (S_Keys (S), I)) =
As_Element (S, Get (S_Keys (S), I)));
Set (S, As_Key (S, Cu), F (As_Element (S, Cu)));
Cu := Next (S, Cu);
end loop;
end Apply_F_4;
function Are_Disjoint (S1, S2 : My_Maps.Map) return Boolean is
Cu : Cursor := First (S1);
begin
while Has_Element (S1, Cu) loop
pragma Loop_Invariant
(for all I in 1 .. P_Get (Positions (S1), Cu) - 1 =>
not Mem (Model (S2), Get (S_Keys (S1), I)));
if Impl.Contains (S2, As_Key (S1, Cu)) then
return False;
end if;
Cu := Next (S1, Cu);
end loop;
return True;
end Are_Disjoint;
procedure Union_P (S1 : in out My_Maps.Map; S2 : My_Maps.Map) is
Cu : Cursor := First (S2);
begin
while Has_Element (S2, Cu) loop
pragma Loop_Invariant
(Length (S1) < Length (S1)'Loop_Entry + P_Get (Positions (S2), Cu));
pragma Loop_Invariant
(for all K of S1 => P (Get (Model (S1), K)));
Set (S1, As_Key (S2, Cu), As_Element (S2, Cu));
Cu := Next (S2, Cu);
end loop;
end Union_P;
procedure Insert_Count (M : in out My_Maps.Map) is
begin
Set (M, 1, 0);
Set (M, 2, 0);
Set (M, 3, 0);
Set (M, 4, 0);
Set (M, 5, 0);
end Insert_Count;
function Q (E : Integer) return Boolean is
begin
return E >= 0;
end Q;
procedure From_S_Keys_To_Model (S : My_Maps.Map) is null;
procedure From_Model_To_S_Keys (S : My_Maps.Map) is null;
procedure From_S_Keys_To_Cursors (S : My_Maps.Map) is null;
procedure From_Cursors_To_S_Keys (S : My_Maps.Map) is
begin
Impl.Lift_Abstraction_Level (S);
end From_Cursors_To_S_Keys;
procedure From_Model_To_Cursors (S : My_Maps.Map) is null;
procedure From_Cursors_To_Model (S : My_Maps.Map) is
begin
Impl.Lift_Abstraction_Level (S);
end From_Cursors_To_Model;
end Use_Maps;
|
sparre/Command-Line-Parser-Generator | Ada | 501 | adb | with Ada.Text_IO;
package body Using_An_Enumeration is
use Ada.Text_IO;
procedure Run (Mode : in Choices := Interactive) is
begin
Put_Line ("Mode = " & Choices'Image (Mode));
end Run;
procedure Run (Configuration_File : in String;
Mode : in Choices) is
begin
Put_Line ("Configuration_File = """ & Configuration_File & """");
Put_Line ("Mode = " & Choices'Image (Mode));
end Run;
end Using_An_Enumeration;
|
ekoeppen/STM32_Generic_Ada_Drivers | Ada | 1,669 | adb | with STM32_SVD.GPIO; use STM32_SVD.GPIO;
with STM32GD.EXTI;
with STM32GD.EXTI.IRQ;
package body STM32GD.GPIO_IRQ is
function Interrupt_Line_Number return STM32GD.EXTI.External_Line_Number is
begin
return STM32GD.EXTI.External_Line_Number'Val (Integer (Pin.Pin));
end Interrupt_Line_Number;
procedure Wait_For_Trigger is
begin
STM32GD.EXTI.IRQ.IRQ_Handler.Wait;
end Wait_For_Trigger;
procedure Clear_Trigger is
begin
STM32GD.EXTI.IRQ.IRQ_Handler.Reset_Status (Interrupt_Line_Number);
end Clear_Trigger;
function Triggered return Boolean is
begin
return STM32GD.EXTI.IRQ.IRQ_Handler.Status (Interrupt_Line_Number);
end Triggered;
procedure Cancel_Wait is
begin
STM32GD.EXTI.IRQ.IRQ_Handler.Cancel;
end Cancel_Wait;
procedure Configure_Trigger (Event : Boolean := False; Rising : Boolean := False; Falling : Boolean := False) is
use STM32GD.EXTI;
Line : constant External_Line_Number := External_Line_Number'Val (Integer (Pin.Pin));
T : External_Triggers;
begin
Connect_External_Interrupt (Pin.Pin, Pin.Port_Index);
if Event then
if Rising and Falling then T := Event_Rising_Falling_Edge;
elsif Rising then T := Event_Rising_Edge;
else T := Event_Falling_Edge;
Enable_External_Event (Line, T);
end if;
else
if Rising and Falling then T := Interrupt_Rising_Falling_Edge;
elsif Rising then T := Interrupt_Rising_Edge;
else T := Interrupt_Falling_Edge;
end if;
Enable_External_Interrupt (Line, T);
end if;
end Configure_Trigger;
end STM32GD.GPIO_IRQ;
|
charlie5/cBound | Ada | 1,892 | 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_copy_area_request_t is
-- Item
--
type Item is record
major_opcode : aliased Interfaces.Unsigned_8;
pad0 : aliased Interfaces.Unsigned_8;
length : aliased Interfaces.Unsigned_16;
src_drawable : aliased xcb.xcb_drawable_t;
dst_drawable : aliased xcb.xcb_drawable_t;
gc : aliased xcb.xcb_gcontext_t;
src_x : aliased Interfaces.Integer_16;
src_y : aliased Interfaces.Integer_16;
dst_x : aliased Interfaces.Integer_16;
dst_y : aliased Interfaces.Integer_16;
width : aliased Interfaces.Unsigned_16;
height : aliased Interfaces.Unsigned_16;
end record;
-- Item_Array
--
type Item_Array is
array
(Interfaces.C.size_t range <>) of aliased xcb.xcb_copy_area_request_t
.Item;
-- Pointer
--
package C_Pointers is new Interfaces.C.Pointers
(Index => Interfaces.C.size_t,
Element => xcb.xcb_copy_area_request_t.Item,
Element_Array => xcb.xcb_copy_area_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_copy_area_request_t
.Pointer;
-- Pointer_Pointer
--
package C_Pointer_Pointers is new Interfaces.C.Pointers
(Index => Interfaces.C.size_t,
Element => xcb.xcb_copy_area_request_t.Pointer,
Element_Array => xcb.xcb_copy_area_request_t.Pointer_Array,
Default_Terminator => null);
subtype Pointer_Pointer is C_Pointer_Pointers.Pointer;
end xcb.xcb_copy_area_request_t;
|
faelys/natools | Ada | 12,865 | adb | ------------------------------------------------------------------------------
-- Copyright (c) 2014-2019, Natacha Porté --
-- --
-- Permission to use, copy, modify, and distribute this software for any --
-- purpose with or without fee is hereby granted, provided that the above --
-- copyright notice and this permission notice appear in all copies. --
-- --
-- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES --
-- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF --
-- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR --
-- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES --
-- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN --
-- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF --
-- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. --
------------------------------------------------------------------------------
with GNAT.MD5;
with GNAT.SHA1;
with GNAT.SHA256;
with Natools.GNAT_HMAC.MD5;
with Natools.GNAT_HMAC.SHA1;
with Natools.GNAT_HMAC.SHA256;
with Natools.S_Expressions.Encodings;
with Natools.S_Expressions.Test_Tools;
package body Natools.HMAC_Tests is
package Test_Tools renames Natools.S_Expressions.Test_Tools;
generic
type Context is private;
with function HMAC_Initial_Context (Key : String) return Context;
with procedure Update (C : in out Context; Input : S_Expressions.Atom);
with function Digest (C : Context) return S_Expressions.Atom;
function GNAT_HMAC_Digest (Key, Message : S_Expressions.Atom)
return S_Expressions.Atom;
function Hex_Atom (Hexadecimal : String) return S_Expressions.Atom;
------------------------------
-- Local Helper Subprograms --
------------------------------
function GNAT_HMAC_Digest (Key, Message : S_Expressions.Atom)
return S_Expressions.Atom
is
C : Context := HMAC_Initial_Context (S_Expressions.To_String (Key));
begin
Update (C, Message);
return Digest (C);
end GNAT_HMAC_Digest;
function GNAT_HMAC_MD5_Digest is new GNAT_HMAC_Digest
(GNAT.MD5.Context,
GNAT.MD5.HMAC_Initial_Context,
GNAT.MD5.Update,
GNAT.MD5.Digest);
function GNAT_HMAC_SHA1_Digest is new GNAT_HMAC_Digest
(GNAT.SHA1.Context,
GNAT.SHA1.HMAC_Initial_Context,
GNAT.SHA1.Update,
GNAT.SHA1.Digest);
function GNAT_HMAC_SHA256_Digest is new GNAT_HMAC_Digest
(GNAT.SHA256.Context,
GNAT.SHA256.HMAC_Initial_Context,
GNAT.SHA256.Update,
GNAT.SHA256.Digest);
function Hex_Atom (Hexadecimal : String) return S_Expressions.Atom is
begin
return S_Expressions.Encodings.Decode_Hex
(S_Expressions.To_Atom (Hexadecimal));
end Hex_Atom;
-------------------------
-- Complete Test Suite --
-------------------------
procedure All_Tests (Report : in out NT.Reporter'Class) is
begin
RFC_2104 (Report);
RFC_4231 (Report);
Wikipedia (Report);
Vanilla_GNAT (Report);
end All_Tests;
-----------------------
-- Inidividual Tests --
-----------------------
procedure RFC_2104 (Report : in out NT.Reporter'Class) is
Test : NT.Test := Report.Item ("HMAC-MD5 test vectors from RFC-2104");
begin
Test_Tools.Test_Atom
(Test,
Hex_Atom ("9294727a3638bb1c13f48ef8158bfc9d"),
GNAT_HMAC.MD5.Digest
(S_Expressions.Atom'(1 .. 16 => 16#0b#),
S_Expressions.To_Atom ("Hi There")));
Test_Tools.Test_Atom
(Test,
Hex_Atom ("750c783e6ab0b503eaa86e310a5db738"),
GNAT_HMAC.MD5.Digest
("Jefe",
S_Expressions.To_Atom ("what do ya want for nothing?")));
Test_Tools.Test_Atom
(Test,
Hex_Atom ("56be34521d144c88dbb8c733f0e8b3f6"),
GNAT_HMAC.MD5.Digest
(S_Expressions.Atom'(1 .. 16 => 16#aa#),
(1 .. 50 => 16#dd#)));
exception
when Error : others => Test.Report_Exception (Error);
end RFC_2104;
procedure RFC_4231 (Report : in out NT.Reporter'Class) is
Test : NT.Test := Report.Item ("HMAC-SHA256 test vectors from RFC-4231");
begin
declare
Context : GNAT_HMAC.SHA256.Context;
begin
GNAT_HMAC.SHA256.Setup (Context,
S_Expressions.Atom'(1 .. 20 => 16#0b#));
GNAT_HMAC.SHA256.Update (Context, "Hi There");
Test_Tools.Test_Atom
(Test,
Hex_Atom ("b0344c61d8db38535ca8afceaf0bf12b"
& "881dc200c9833da726e9376c2e32cff7"),
GNAT_HMAC.SHA256.Digest (Context));
GNAT_HMAC.SHA256.Setup (Context, "Jefe");
GNAT_HMAC.SHA256.Update (Context, "what do ya want for nothing?");
Test_Tools.Test_Atom
(Test,
Hex_Atom ("5bdcc146bf60754e6a042426089575c7"
& "5a003f089d2739839dec58b964ec3843"),
GNAT_HMAC.SHA256.Digest (Context));
GNAT_HMAC.SHA256.Setup (Context,
S_Expressions.Atom'(1 .. 20 => 16#aa#));
GNAT_HMAC.SHA256.Update (Context,
S_Expressions.Atom'(1 .. 50 => 16#dd#));
Test_Tools.Test_Atom
(Test,
Hex_Atom ("773ea91e36800e46854db8ebd09181a7"
& "2959098b3ef8c122d9635514ced565fe"),
GNAT_HMAC.SHA256.Digest (Context));
GNAT_HMAC.SHA256.Setup (Context,
Hex_Atom ("0102030405060708090a0b0c0d0e0f10111213141516171819"));
GNAT_HMAC.SHA256.Update (Context,
S_Expressions.Atom'(1 .. 50 => 16#CD#));
Test_Tools.Test_Atom
(Test,
Hex_Atom ("82558a389a443c0ea4cc819899f2083a"
& "85f0faa3e578f8077a2e3ff46729665b"),
GNAT_HMAC.SHA256.Digest (Context));
GNAT_HMAC.SHA256.Setup (Context,
S_Expressions.Atom'(1 .. 131 => 16#AA#));
GNAT_HMAC.SHA256.Update (Context,
"Test Using Larger Than Block-Size Key - Hash Key First");
Test_Tools.Test_Atom
(Test,
Hex_Atom ("60e431591ee0b67f0d8a26aacbf5b77f"
& "8e0bc6213728c5140546040f0ee37f54"),
GNAT_HMAC.SHA256.Digest (Context));
GNAT_HMAC.SHA256.Setup (Context,
S_Expressions.Atom'(1 .. 131 => 16#aa#));
GNAT_HMAC.SHA256.Update (Context,
"This is a test using a larger than block-size key and a larger"
& " than block-size data. The key needs to be hashed before"
& " being used by the HMAC algorithm.");
Test_Tools.Test_Atom
(Test,
Hex_Atom ("9b09ffa71b942fcb27635fbcd5b0e944"
& "bfdc63644f0713938a7f51535c3a35e2"),
GNAT_HMAC.SHA256.Digest (Context));
end;
exception
when Error : others => Test.Report_Exception (Error);
end RFC_4231;
procedure Vanilla_GNAT (Report : in out NT.Reporter'Class) is
Test : NT.Test := Report.Item ("Test vanilla GNAT HMAC implementation");
begin
-- RFC 2104 test vectors
Test_Tools.Test_Atom
(Test,
Hex_Atom ("9294727a3638bb1c13f48ef8158bfc9d"),
GNAT_HMAC_MD5_Digest
(S_Expressions.Atom'(1 .. 16 => 16#0b#),
S_Expressions.To_Atom ("Hi There")));
Test_Tools.Test_Atom
(Test,
Hex_Atom ("750c783e6ab0b503eaa86e310a5db738"),
GNAT_HMAC_MD5_Digest
(S_Expressions.To_Atom ("Jefe"),
S_Expressions.To_Atom ("what do ya want for nothing?")));
Test_Tools.Test_Atom
(Test,
Hex_Atom ("56be34521d144c88dbb8c733f0e8b3f6"),
GNAT_HMAC_MD5_Digest
(S_Expressions.Atom'(1 .. 16 => 16#aa#),
(1 .. 50 => 16#dd#)));
-- RFC 4231 test vectors
Test_Tools.Test_Atom
(Test,
Hex_Atom ("b0344c61d8db38535ca8afceaf0bf12b"
& "881dc200c9833da726e9376c2e32cff7"),
GNAT_HMAC_SHA256_Digest
(S_Expressions.Atom'(1 .. 20 => 16#0b#),
S_Expressions.To_Atom ("Hi There")));
Test_Tools.Test_Atom
(Test,
Hex_Atom ("5bdcc146bf60754e6a042426089575c7"
& "5a003f089d2739839dec58b964ec3843"),
GNAT_HMAC_SHA256_Digest
(S_Expressions.To_Atom ("Jefe"),
S_Expressions.To_Atom ("what do ya want for nothing?")));
Test_Tools.Test_Atom
(Test,
Hex_Atom ("773ea91e36800e46854db8ebd09181a7"
& "2959098b3ef8c122d9635514ced565fe"),
GNAT_HMAC_SHA256_Digest
(S_Expressions.Atom'(1 .. 20 => 16#aa#),
S_Expressions.Atom'(1 .. 50 => 16#dd#)));
Test_Tools.Test_Atom
(Test,
Hex_Atom ("82558a389a443c0ea4cc819899f2083a"
& "85f0faa3e578f8077a2e3ff46729665b"),
GNAT_HMAC_SHA256_Digest
(Hex_Atom ("0102030405060708090a0b0c0d0e0f10111213141516171819"),
S_Expressions.Atom'(1 .. 50 => 16#CD#)));
Test_Tools.Test_Atom
(Test,
Hex_Atom ("60e431591ee0b67f0d8a26aacbf5b77f"
& "8e0bc6213728c5140546040f0ee37f54"),
GNAT_HMAC_SHA256_Digest
(S_Expressions.Atom'(1 .. 131 => 16#AA#),
S_Expressions.To_Atom
("Test Using Larger Than Block-Size Key - Hash Key First")));
Test_Tools.Test_Atom
(Test,
Hex_Atom ("9b09ffa71b942fcb27635fbcd5b0e944"
& "bfdc63644f0713938a7f51535c3a35e2"),
GNAT_HMAC_SHA256_Digest
(S_Expressions.Atom'(1 .. 131 => 16#aa#),
S_Expressions.To_Atom
("This is a test using a larger than block-size key and a larger"
& " than block-size data. The key needs to be hashed before"
& " being used by the HMAC algorithm.")));
-- Wikipedia non-null test vectors (since GNAT HMAC rejects empty keys)
Test_Tools.Test_Atom
(Test,
Hex_Atom ("80070713463e7749b90c2dc24911e275"),
GNAT_HMAC_MD5_Digest
(S_Expressions.To_Atom ("key"),
S_Expressions.To_Atom
("The quick brown fox jumps over the lazy dog")));
Test_Tools.Test_Atom
(Test,
Hex_Atom ("de7c9b85b8b78aa6bc8a7a36f70a90701c9db4d9"),
GNAT_HMAC_SHA1_Digest
(S_Expressions.To_Atom ("key"),
S_Expressions.To_Atom
("The quick brown fox jumps over the lazy dog")));
Test_Tools.Test_Atom
(Test,
Hex_Atom ("f7bc83f430538424b13298e6aa6fb143"
& "ef4d59a14946175997479dbc2d1a3cd8"),
GNAT_HMAC_SHA256_Digest
(S_Expressions.To_Atom ("key"),
S_Expressions.To_Atom
("The quick brown fox jumps over the lazy dog")));
exception
when Error : others => Test.Report_Exception (Error);
end Vanilla_GNAT;
procedure Wikipedia (Report : in out NT.Reporter'Class) is
Test : NT.Test := Report.Item ("Test vectors from Wikipedia");
begin
Test_Tools.Test_Atom
(Test,
Hex_Atom ("74e6f7298a9c2d168935f58c001bad88"),
GNAT_HMAC.MD5.Digest
(S_Expressions.Null_Atom,
S_Expressions.Null_Atom));
Test_Tools.Test_Atom
(Test,
Hex_Atom ("80070713463e7749b90c2dc24911e275"),
GNAT_HMAC.MD5.Digest
("key",
S_Expressions.To_Atom
("The quick brown fox jumps over the lazy dog")));
Test_Tools.Test_Atom
(Test,
Hex_Atom ("fbdb1d1b18aa6c08324b7d64b71fb76370690e1d"),
GNAT_HMAC.SHA1.Digest
(S_Expressions.Null_Atom,
S_Expressions.Null_Atom));
Test_Tools.Test_Atom
(Test,
Hex_Atom ("de7c9b85b8b78aa6bc8a7a36f70a90701c9db4d9"),
GNAT_HMAC.SHA1.Digest
("key",
S_Expressions.To_Atom
("The quick brown fox jumps over the lazy dog")));
Test_Tools.Test_Atom
(Test,
Hex_Atom ("b613679a0814d9ec772f95d778c35fc5"
& "ff1697c493715653c6c712144292c5ad"),
GNAT_HMAC.SHA256.Digest
(S_Expressions.Null_Atom,
S_Expressions.Null_Atom));
Test_Tools.Test_Atom
(Test,
Hex_Atom ("f7bc83f430538424b13298e6aa6fb143"
& "ef4d59a14946175997479dbc2d1a3cd8"),
GNAT_HMAC.SHA256.Digest
("key",
S_Expressions.To_Atom
("The quick brown fox jumps over the lazy dog")));
exception
when Error : others => Test.Report_Exception (Error);
end Wikipedia;
end Natools.HMAC_Tests;
|
eqcola/ada-ado | Ada | 5,400 | adb | -----------------------------------------------------------------------
-- ado-queries -- Database Queries
-- Copyright (C) 2011, 2012, 2013, 2014, 2015 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.Queries.Loaders;
package body ADO.Queries is
-- ------------------------------
-- Set the query definition which identifies the SQL query to execute.
-- The query is represented by the <tt>sql</tt> XML entry.
-- ------------------------------
procedure Set_Query (Into : in out Context;
Query : in Query_Definition_Access) is
begin
Into.Query_Def := Query;
Into.Is_Count := False;
end Set_Query;
-- ------------------------------
-- Set the query definition which identifies the SQL query to execute.
-- The query count is represented by the <tt>sql-count</tt> XML entry.
-- ------------------------------
procedure Set_Count_Query (Into : in out Context;
Query : in Query_Definition_Access) is
begin
Into.Query_Def := Query;
Into.Is_Count := True;
end Set_Count_Query;
procedure Set_Query (Into : in out Context;
Name : in String) is
begin
Into.Query_Def := ADO.Queries.Loaders.Find_Query (Name);
end Set_Query;
-- ------------------------------
-- Set the query to execute as SQL statement.
-- ------------------------------
procedure Set_SQL (Into : in out Context;
SQL : in String) is
begin
ADO.SQL.Clear (Into.SQL);
ADO.SQL.Append (Into.SQL, SQL);
end Set_SQL;
-- ------------------------------
-- Set the limit for the SQL query.
-- ------------------------------
procedure Set_Limit (Into : in out Context;
First : in Natural;
Last : in Natural) is
begin
Into.First := First;
Into.Last := Last;
end Set_Limit;
-- ------------------------------
-- Get the first row index.
-- ------------------------------
function Get_First_Row_Index (From : in Context) return Natural is
begin
return From.First;
end Get_First_Row_Index;
-- ------------------------------
-- Get the last row index.
-- ------------------------------
function Get_Last_Row_Index (From : in Context) return Natural is
begin
return From.Last;
end Get_Last_Row_Index;
-- ------------------------------
-- Get the maximum number of rows that the SQL query can return.
-- This operation uses the <b>sql-count</b> query.
-- ------------------------------
function Get_Max_Row_Count (From : in Context) return Natural is
begin
return From.Max_Row_Count;
end Get_Max_Row_Count;
-- ------------------------------
-- Get the SQL query that correspond to the query context.
-- ------------------------------
function Get_SQL (From : in Context;
Driver : in ADO.Drivers.Driver_Index) return String is
begin
if From.Query_Def = null then
return ADO.SQL.To_String (From.SQL);
else
return Get_SQL (From.Query_Def, Driver, From.Is_Count);
end if;
end Get_SQL;
-- ------------------------------
-- Find the query with the given name.
-- Returns the query definition that matches the name or null if there is none
-- ------------------------------
function Find_Query (File : in Query_File;
Name : in String) return Query_Definition_Access is
Query : Query_Definition_Access := File.Queries;
begin
while Query /= null loop
if Query.Name.all = Name then
return Query;
end if;
Query := Query.Next;
end loop;
return null;
end Find_Query;
function Get_SQL (From : in Query_Definition_Access;
Driver : in ADO.Drivers.Driver_Index;
Use_Count : in Boolean) return String is
Query : Query_Info_Ref.Ref;
begin
ADO.Queries.Loaders.Read_Query (From);
Query := From.Query.Get;
if Query.Is_Null then
return "";
end if;
if Use_Count then
if Length (Query.Value.Count_Query (Driver).SQL) > 0 then
return To_String (Query.Value.Count_Query (Driver).SQL);
else
return To_String (Query.Value.Count_Query (ADO.Drivers.Driver_Index'First).SQL);
end if;
elsif Length (Query.Value.Main_Query (Driver).SQL) > 0 then
return To_String (Query.Value.Main_Query (Driver).SQL);
else
return To_String (Query.Value.Main_Query (ADO.Drivers.Driver_Index'First).SQL);
end if;
end Get_SQL;
end ADO.Queries;
|
RREE/ada-util | Ada | 3,029 | ads | -----------------------------------------------------------------------
-- util-beans-basic-ranges -- Range of values with helper for list iteration
-- 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.Beans.Objects;
with Util.Beans.Basic;
-- The <b>Util.Beans.Basic.Ranges</b> generic package defines an object that holds
-- a range definition. It implements the <b>List_Bean</b> interface which allows to
-- iterate over the values of the defined range.
generic
type T is (<>);
with function To_Object (From : in T) return Util.Beans.Objects.Object is <>;
package Util.Beans.Basic.Ranges is
-- ------------------------------
-- Range of discrete values
-- ------------------------------
-- The <b>Range_Bean</b> defines a discrete range. It holds a lower and upper bound.
-- A current value is also used for the <b>List_Bean</b> interface to iterate over the range.
type Range_Bean is new Util.Beans.Basic.List_Bean with private;
type Range_Bean_Access is access all Range_Bean'Class;
-- Create a range definition.
function Create (First, Last : in T) return Range_Bean;
-- Get the range lower bound.
function Get_First (From : in Range_Bean) return T;
-- Get the range upper bound.
function Get_Last (From : in Range_Bean) return T;
-- Get the current value within the first/last bounds.
function Get_Current (From : in Range_Bean) return T;
-- Get the value identified by the name.
-- If the name cannot be found, the method should return the Null object.
overriding
function Get_Value (From : in Range_Bean;
Name : in String) return Util.Beans.Objects.Object;
-- Get the number of elements in the list.
overriding
function Get_Count (From : in Range_Bean) return Natural;
-- Set the current row index. Valid row indexes start at 1.
overriding
procedure Set_Row_Index (From : in out Range_Bean;
Index : in Natural);
-- Get the element at the current row index.
overriding
function Get_Row (From : in Range_Bean) return Util.Beans.Objects.Object;
private
type Range_Bean is new Util.Beans.Basic.List_Bean with record
First : T := T'First;
Last : T := T'First;
Current : T := T'First;
end record;
end Util.Beans.Basic.Ranges;
|
faelys/natools | Ada | 30,629 | adb | ------------------------------------------------------------------------------
-- Copyright (c) 2014, Natacha Porté --
-- --
-- Permission to use, copy, modify, and distribute this software for any --
-- purpose with or without fee is hereby granted, provided that the above --
-- copyright notice and this permission notice appear in all copies. --
-- --
-- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES --
-- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF --
-- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR --
-- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES --
-- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN --
-- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF --
-- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. --
------------------------------------------------------------------------------
with Natools.S_Expressions.Atom_Ref_Constructors;
with Natools.S_Expressions.Interpreter_Loop;
with Natools.Static_Maps.S_Expressions.Templates.Integers;
package body Natools.S_Expressions.Templates.Generic_Integers is
package Commands
renames Natools.Static_Maps.S_Expressions.Templates.Integers;
function Create (Data : Atom) return Atom_Refs.Immutable_Reference
renames Atom_Ref_Constructors.Create;
procedure Insert_Image
(State : in out Format;
Context : in Meaningless_Type;
Image : in Atom);
procedure Update_Image
(State : in out Format;
Context : in Meaningless_Type;
Name : in Atom;
Arguments : in out Lockable.Descriptor'Class);
procedure Update_Format
(State : in out Format;
Context : in Meaningless_Type;
Name : in Atom;
Arguments : in out Lockable.Descriptor'Class);
------------------------------
-- Local Helper Subprograms --
------------------------------
procedure Insert_Image
(State : in out Format;
Context : in Meaningless_Type;
Image : in Atom)
is
pragma Unreferenced (Context);
begin
State.Append_Image (Image);
end Insert_Image;
procedure Update_Image
(State : in out Format;
Context : in Meaningless_Type;
Name : in Atom;
Arguments : in out Lockable.Descriptor'Class)
is
pragma Unreferenced (Context);
Value : T;
begin
begin
Value := T'Value (To_String (Name));
exception
when Constraint_Error =>
return;
end;
case Arguments.Current_Event is
when Events.Add_Atom =>
State.Set_Image (Value, Arguments.Current_Atom);
when others =>
State.Remove_Image (Value);
end case;
end Update_Image;
procedure Image_Interpreter is new Interpreter_Loop
(Format, Meaningless_Type, Update_Image, Insert_Image);
procedure Update_Format
(State : in out Format;
Context : in Meaningless_Type;
Name : in Atom;
Arguments : in out Lockable.Descriptor'Class)
is
pragma Unreferenced (Context);
Command : constant String := To_String (Name);
Event : Events.Event;
begin
case Commands.Main (Command) is
when Commands.Error =>
null;
when Commands.Align =>
case Arguments.Current_Event is
when Events.Add_Atom =>
case Commands.To_Align_Command
(To_String (Arguments.Current_Atom))
is
when Commands.Unknown_Align =>
null;
when Commands.Set_Left =>
State.Set_Align (Left_Aligned);
when Commands.Set_Center =>
State.Set_Align (Centered);
when Commands.Set_Right =>
State.Set_Align (Right_Aligned);
end case;
when others =>
null;
end case;
when Commands.Align_Center =>
State.Set_Align (Centered);
when Commands.Align_Left =>
State.Set_Align (Left_Aligned);
when Commands.Align_Right =>
State.Set_Align (Right_Aligned);
when Commands.Base =>
State.Set_Symbols (Arguments);
when Commands.Image_Range =>
Parse (State.Images, Arguments);
when Commands.Images =>
Image_Interpreter (Arguments, State, Meaningless_Value);
when Commands.Padding =>
case Arguments.Current_Event is
when Events.Add_Atom =>
State.Left_Padding := Create (Arguments.Current_Atom);
State.Right_Padding := State.Left_Padding;
when others =>
return;
end case;
Arguments.Next (Event);
case Event is
when Events.Add_Atom =>
State.Set_Right_Padding (Arguments.Current_Atom);
when others =>
null;
end case;
when Commands.Padding_Left =>
case Arguments.Current_Event is
when Events.Add_Atom =>
State.Set_Left_Padding (Arguments.Current_Atom);
when others =>
null;
end case;
when Commands.Padding_Right =>
case Arguments.Current_Event is
when Events.Add_Atom =>
State.Set_Right_Padding (Arguments.Current_Atom);
when others =>
null;
end case;
when Commands.Prefix =>
Parse (State.Prefix, Arguments);
when Commands.Sign =>
case Arguments.Current_Event is
when Events.Add_Atom =>
State.Set_Positive_Sign (Arguments.Current_Atom);
when others =>
return;
end case;
Arguments.Next (Event);
case Event is
when Events.Add_Atom =>
State.Set_Negative_Sign (Arguments.Current_Atom);
when others =>
null;
end case;
when Commands.Suffix =>
Parse (State.Suffix, Arguments);
when Commands.Width =>
case Arguments.Current_Event is
when Events.Add_Atom =>
declare
New_Width : constant Width
:= Width'Value (To_String (Arguments.Current_Atom));
begin
State.Set_Maximum_Width (New_Width);
State.Set_Minimum_Width (New_Width);
end;
when others =>
return;
end case;
Arguments.Next (Event);
case Event is
when Events.Add_Atom =>
State.Set_Maximum_Width
(Width'Value (To_String (Arguments.Current_Atom)));
when others =>
return;
end case;
Arguments.Next (Event);
case Event is
when Events.Add_Atom =>
State.Set_Overflow_Message (Arguments.Current_Atom);
when others =>
return;
end case;
when Commands.Width_Max =>
case Arguments.Current_Event is
when Events.Add_Atom =>
State.Set_Maximum_Width
(Width'Value (To_String (Arguments.Current_Atom)));
when others =>
return;
end case;
Arguments.Next (Event);
case Event is
when Events.Add_Atom =>
State.Set_Overflow_Message (Arguments.Current_Atom);
when others =>
return;
end case;
when Commands.Width_Min =>
case Arguments.Current_Event is
when Events.Add_Atom =>
State.Set_Minimum_Width
(Width'Value (To_String (Arguments.Current_Atom)));
when others =>
null;
end case;
end case;
end Update_Format;
procedure Interpreter is new Interpreter_Loop
(Format, Meaningless_Type, Update_Format, Insert_Image);
-------------------------
-- Dynamic Atom Arrays --
-------------------------
function Create (Atom_List : in out S_Expressions.Descriptor'Class)
return Atom_Array
is
function Current_Atom return Atom is (Atom_List.Current_Atom);
New_Ref : Atom_Refs.Immutable_Reference;
begin
case Atom_List.Current_Event is
when Events.Add_Atom =>
New_Ref := Atom_Refs.Create (Current_Atom'Access);
Atom_List.Next;
return (0 => New_Ref) & Create (Atom_List);
when others =>
return Atom_Array'(1 .. 0 => <>);
end case;
end Create;
function Create (Atom_List : in out S_Expressions.Descriptor'Class)
return Atom_Arrays.Immutable_Reference
is
function Create_Array return Atom_Array is (Create (Atom_List));
begin
return Atom_Arrays.Create (Create_Array'Access);
end Create;
function Decimal return Atom_Arrays.Immutable_Reference is
function Create return Atom_Array
is ((0 => Create ((1 => Character'Pos ('0'))),
1 => Create ((1 => Character'Pos ('1'))),
2 => Create ((1 => Character'Pos ('2'))),
3 => Create ((1 => Character'Pos ('3'))),
4 => Create ((1 => Character'Pos ('4'))),
5 => Create ((1 => Character'Pos ('5'))),
6 => Create ((1 => Character'Pos ('6'))),
7 => Create ((1 => Character'Pos ('7'))),
8 => Create ((1 => Character'Pos ('8'))),
9 => Create ((1 => Character'Pos ('9')))));
begin
if Base_10.Is_Empty then
Base_10 := Atom_Arrays.Create (Create'Access);
end if;
return Base_10;
end Decimal;
procedure Reverse_Render
(Value : in Natural_T;
Symbols : in Atom_Array;
Output : in out Atom_Buffers.Atom_Buffer;
Length : out Width)
is
Digit : Natural_T;
Remainder : Natural_T := Value;
begin
Length := 0;
loop
Digit := Remainder mod Symbols'Length;
Remainder := Remainder / Symbols'Length;
Length := Length + 1;
Output.Append (Symbols (Digit).Query.Data.all);
exit when Remainder = 0;
end loop;
end Reverse_Render;
-----------------------
-- Dynamic Atom Maps --
-----------------------
procedure Exclude
(Map : in out Atom_Maps.Map;
Values : in Interval)
is
procedure Delete_And_Next
(Target : in out Atom_Maps.Map;
Cursor : in out Atom_Maps.Cursor);
procedure Delete_And_Next
(Target : in out Atom_Maps.Map;
Cursor : in out Atom_Maps.Cursor)
is
Next : constant Atom_Maps.Cursor := Atom_Maps.Next (Cursor);
begin
Target.Delete (Cursor);
Cursor := Next;
end Delete_And_Next;
Cursor : Atom_Maps.Cursor := Map.Ceiling ((Values.First, Values.First));
begin
if not Atom_Maps.Has_Element (Cursor) then
return;
end if;
pragma Assert (not (Atom_Maps.Key (Cursor).Last < Values.First));
if Atom_Maps.Key (Cursor).First < Values.First then
declare
Old_Key : constant Interval := Atom_Maps.Key (Cursor);
Prefix_Key : constant Interval
:= (Old_Key.First, T'Pred (Values.First));
Prefix_Image : constant Displayed_Atom
:= Atom_Maps.Element (Cursor);
begin
Delete_And_Next (Map, Cursor);
Map.Insert (Prefix_Key, Prefix_Image);
if Values.Last < Old_Key.Last then
Map.Insert ((T'Succ (Values.Last), Old_Key.Last), Prefix_Image);
return;
end if;
end;
end if;
while Atom_Maps.Has_Element (Cursor)
and then not (Values.Last < Atom_Maps.Key (Cursor).Last)
loop
Delete_And_Next (Map, Cursor);
end loop;
if Atom_Maps.Has_Element (Cursor)
and then not (Values.Last < Atom_Maps.Key (Cursor).First)
then
declare
Old_Key : constant Interval := Atom_Maps.Key (Cursor);
Suffix_Key : constant Interval
:= (T'Succ (Values.Last), Old_Key.Last);
Suffix_Image : constant Displayed_Atom
:= Atom_Maps.Element (Cursor);
begin
Delete_And_Next (Map, Cursor);
Map.Insert (Suffix_Key, Suffix_Image);
end;
end if;
end Exclude;
procedure Include
(Map : in out Atom_Maps.Map;
Values : in Interval;
Image : in Atom_Refs.Immutable_Reference;
Width : in Generic_Integers.Width) is
begin
Exclude (Map, Values);
if not Image.Is_Empty then
Map.Insert (Values, (Image, Width));
end if;
end Include;
procedure Parse
(Map : in out Atom_Maps.Map;
Expression : in out Lockable.Descriptor'Class)
is
Event : Events.Event := Expression.Current_Event;
Lock : Lockable.Lock_State;
begin
loop
case Event is
when Events.Add_Atom =>
declare
Image : constant Atom := Expression.Current_Atom;
begin
Include
(Map,
(T'First, T'Last),
Create (Image),
Image'Length);
end;
when Events.Open_List =>
Expression.Lock (Lock);
begin
Expression.Next;
Parse_Single_Affix (Map, Expression);
exception
when others =>
Expression.Unlock (Lock, False);
raise;
end;
Expression.Unlock (Lock);
Event := Expression.Current_Event;
exit when Event in Events.Error | Events.End_Of_Input;
when Events.Close_List | Events.Error | Events.End_Of_Input =>
exit;
end case;
Expression.Next (Event);
end loop;
end Parse;
procedure Parse_Single_Affix
(Map : in out Atom_Maps.Map;
Expression : in out Lockable.Descriptor'Class)
is
function Read_Interval (Exp : in out Descriptor'Class) return Interval;
function Read_Interval (Exp : in out Descriptor'Class) return Interval is
Event : Events.Event;
First, Last : T;
begin
Exp.Next (Event);
case Event is
when Events.Add_Atom =>
First := T'Value (To_String (Exp.Current_Atom));
when others =>
raise Constraint_Error with "Lower bound not an atom";
end case;
Exp.Next (Event);
case Event is
when Events.Add_Atom =>
Last := T'Value (To_String (Exp.Current_Atom));
when others =>
raise Constraint_Error with "Upper bound not an atom";
end case;
if Last < First then
raise Constraint_Error with "Invalid interval (Last < First)";
end if;
return (First, Last);
end Read_Interval;
Event : Events.Event := Expression.Current_Event;
Lock : Lockable.Lock_State;
Affix : Atom_Refs.Immutable_Reference;
Affix_Width : Width := 0;
begin
case Event is
when Events.Add_Atom =>
declare
Current : constant Atom := Expression.Current_Atom;
begin
if Current'Length > 0 then
Affix := Create (Current);
Affix_Width := Current'Length;
end if;
end;
when Events.Open_List =>
Expression.Lock (Lock);
begin
Expression.Next (Event);
if Event /= Events.Add_Atom then
Expression.Unlock (Lock, False);
return;
end if;
Affix := Create (Expression.Current_Atom);
Affix_Width := Affix.Query.Data.all'Length;
Expression.Next (Event);
if Event = Events.Add_Atom then
begin
Affix_Width := Width'Value
(To_String (Expression.Current_Atom));
exception
when Constraint_Error => null;
end;
end if;
exception
when others =>
Expression.Unlock (Lock, False);
raise;
end;
Expression.Unlock (Lock);
when others =>
return;
end case;
loop
Expression.Next (Event);
case Event is
when Events.Add_Atom =>
declare
Value : T;
begin
Value := T'Value (To_String (Expression.Current_Atom));
Include (Map, (Value, Value), Affix, Affix_Width);
exception
when Constraint_Error => null;
end;
when Events.Open_List =>
Expression.Lock (Lock);
begin
Include
(Map, Read_Interval (Expression),
Affix, Affix_Width);
exception
when Constraint_Error =>
null;
when others =>
Expression.Unlock (Lock, False);
raise;
end;
Expression.Unlock (Lock);
when others =>
exit;
end case;
end loop;
end Parse_Single_Affix;
----------------------
-- Public Interface --
----------------------
function Render (Value : T; Template : Format) return Atom is
function "*" (Count : Width; Symbol : Atom) return Atom;
function Safe_Atom
(Ref : Atom_Refs.Immutable_Reference;
Fallback : String)
return Atom;
-- The expression below seems to trigger an infinite loop in
-- GNAT-AUX 4.9.0 20140422, but the if-statement form doesn't.
-- is (if Ref.Is_Empty then To_Atom (Fallback) else Ref.Query.Data.all);
function Safe_Atom
(Ref : Atom_Refs.Immutable_Reference;
Fallback : String)
return Atom is
begin
if Ref.Is_Empty then
return To_Atom (Fallback);
else
return Ref.Query.Data.all;
end if;
end Safe_Atom;
function "*" (Count : Width; Symbol : Atom) return Atom is
Result : Atom (1 .. Offset (Count) * Symbol'Length);
begin
for I in 0 .. Offset (Count) - 1 loop
Result (I * Symbol'Length + 1 .. (I + 1) * Symbol'Length)
:= Symbol;
end loop;
return Result;
end "*";
Output : Atom_Buffers.Atom_Buffer;
Has_Sign : Boolean := True;
Length : Width;
Symbols : constant Atom_Arrays.Immutable_Reference
:= (if Template.Symbols.Is_Empty then Decimal else Template.Symbols);
begin
Check_Explicit_Image :
declare
Cursor : constant Atom_Maps.Cursor
:= Template.Images.Find ((Value, Value));
begin
if Atom_Maps.Has_Element (Cursor) then
return Atom_Maps.Element (Cursor).Image.Query.Data.all;
end if;
end Check_Explicit_Image;
if Value < 0 then
Reverse_Render (-Value, Symbols.Query.Data.all, Output, Length);
Output.Append (Safe_Atom (Template.Negative_Sign, "-"));
else
Reverse_Render (Value, Symbols.Query.Data.all, Output, Length);
if not Template.Positive_Sign.Is_Empty then
Output.Append (Template.Positive_Sign.Query.Data.all);
else
Has_Sign := False;
end if;
end if;
if Has_Sign then
Length := Length + 1;
end if;
Add_Prefix :
declare
Cursor : constant Atom_Maps.Cursor
:= Template.Prefix.Find ((Value, Value));
begin
if Atom_Maps.Has_Element (Cursor) then
declare
Data : constant Displayed_Atom := Atom_Maps.Element (Cursor);
begin
Output.Append_Reverse (Data.Image.Query.Data.all);
Length := Length + Data.Width;
end;
end if;
end Add_Prefix;
Output.Invert;
Add_Suffix :
declare
Cursor : constant Atom_Maps.Cursor
:= Template.Suffix.Find ((Value, Value));
begin
if Atom_Maps.Has_Element (Cursor) then
declare
Data : constant Displayed_Atom := Atom_Maps.Element (Cursor);
begin
Output.Append (Data.Image.Query.Data.all);
Length := Length + Data.Width;
end;
end if;
end Add_Suffix;
if Length > Template.Maximum_Width then
return Safe_Atom (Template.Overflow_Message, "");
end if;
if Length < Template.Minimum_Width then
declare
Needed : constant Width := Template.Minimum_Width - Length;
Left_Count, Right_Count : Width := 0;
begin
case Template.Align is
when Left_Aligned =>
Right_Count := Needed;
when Centered =>
Left_Count := Needed / 2;
Right_Count := Needed - Left_Count;
when Right_Aligned =>
Left_Count := Needed;
end case;
return Left_Count * Safe_Atom (Template.Left_Padding, " ")
& Output.Data
& Right_Count * Safe_Atom (Template.Right_Padding, " ");
end;
end if;
return Output.Data;
end Render;
procedure Parse
(Template : in out Format;
Expression : in out Lockable.Descriptor'Class) is
begin
Interpreter (Expression, Template, Meaningless_Value);
end Parse;
procedure Render
(Output : in out Ada.Streams.Root_Stream_Type'Class;
Template : in out Lockable.Descriptor'Class;
Value : in T)
is
Parsed_Template : Format;
begin
Parse (Parsed_Template, Template);
Output.Write (Render (Value, Parsed_Template));
end Render;
procedure Render
(Output : in out Ada.Streams.Root_Stream_Type'Class;
Default_Format : in Format;
Template : in out Lockable.Descriptor'Class;
Value : in T)
is
Parsed_Template : Format := Default_Format;
begin
Parse (Parsed_Template, Template);
Output.Write (Render (Value, Parsed_Template));
end Render;
---------------------
-- Format Mutators --
---------------------
procedure Append_Image
(Object : in out Format;
Image : in Atom_Refs.Immutable_Reference) is
begin
Set_Image (Object, Next_Index (Object.Images), Image);
end Append_Image;
procedure Append_Image
(Object : in out Format;
Image : in Atom) is
begin
Append_Image (Object, Create (Image));
end Append_Image;
procedure Remove_Image (Object : in out Format; Value : in T) is
begin
Exclude (Object.Images, (Value, Value));
end Remove_Image;
procedure Remove_Prefix
(Object : in out Format;
Value : in T) is
begin
Remove_Prefix (Object, (Value, Value));
end Remove_Prefix;
procedure Remove_Prefix
(Object : in out Format;
Values : in Interval) is
begin
Set_Prefix (Object, Values, Atom_Refs.Null_Immutable_Reference, 0);
end Remove_Prefix;
procedure Remove_Suffix
(Object : in out Format;
Value : in T) is
begin
Remove_Suffix (Object, (Value, Value));
end Remove_Suffix;
procedure Remove_Suffix
(Object : in out Format;
Values : in Interval) is
begin
Set_Suffix (Object, Values, Atom_Refs.Null_Immutable_Reference, 0);
end Remove_Suffix;
procedure Set_Align (Object : in out Format; Value : in Alignment) is
begin
Object.Align := Value;
end Set_Align;
procedure Set_Image
(Object : in out Format;
Value : in T;
Image : in Atom_Refs.Immutable_Reference) is
begin
Include (Object.Images, (Value, Value), Image, 0);
end Set_Image;
procedure Set_Image
(Object : in out Format;
Value : in T;
Image : in Atom) is
begin
Set_Image (Object, Value, Create (Image));
end Set_Image;
procedure Set_Left_Padding
(Object : in out Format;
Symbol : in Atom_Refs.Immutable_Reference) is
begin
Object.Left_Padding := Symbol;
end Set_Left_Padding;
procedure Set_Left_Padding
(Object : in out Format;
Symbol : in Atom) is
begin
Set_Left_Padding (Object, Create (Symbol));
end Set_Left_Padding;
procedure Set_Maximum_Width (Object : in out Format; Value : in Width) is
begin
Object.Maximum_Width := Value;
if Object.Minimum_Width > Object.Maximum_Width then
Object.Minimum_Width := Value;
end if;
end Set_Maximum_Width;
procedure Set_Minimum_Width (Object : in out Format; Value : in Width) is
begin
Object.Minimum_Width := Value;
if Object.Minimum_Width > Object.Maximum_Width then
Object.Maximum_Width := Value;
end if;
end Set_Minimum_Width;
procedure Set_Negative_Sign
(Object : in out Format;
Sign : in Atom_Refs.Immutable_Reference) is
begin
Object.Negative_Sign := Sign;
end Set_Negative_Sign;
procedure Set_Negative_Sign
(Object : in out Format;
Sign : in Atom) is
begin
Set_Negative_Sign (Object, Create (Sign));
end Set_Negative_Sign;
procedure Set_Overflow_Message
(Object : in out Format;
Message : in Atom_Refs.Immutable_Reference) is
begin
Object.Overflow_Message := Message;
end Set_Overflow_Message;
procedure Set_Overflow_Message
(Object : in out Format;
Message : in Atom) is
begin
Set_Overflow_Message (Object, Create (Message));
end Set_Overflow_Message;
procedure Set_Positive_Sign
(Object : in out Format;
Sign : in Atom_Refs.Immutable_Reference) is
begin
Object.Positive_Sign := Sign;
end Set_Positive_Sign;
procedure Set_Positive_Sign
(Object : in out Format;
Sign : in Atom) is
begin
Set_Positive_Sign (Object, Create (Sign));
end Set_Positive_Sign;
procedure Set_Prefix
(Object : in out Format;
Value : in T;
Prefix : in Atom_Refs.Immutable_Reference;
Width : in Generic_Integers.Width) is
begin
Set_Prefix (Object, (Value, Value), Prefix, Width);
end Set_Prefix;
procedure Set_Prefix
(Object : in out Format;
Value : in T;
Prefix : in Atom) is
begin
Set_Prefix (Object, Value, Prefix, Prefix'Length);
end Set_Prefix;
procedure Set_Prefix
(Object : in out Format;
Value : in T;
Prefix : in Atom;
Width : in Generic_Integers.Width) is
begin
Set_Prefix (Object, Value, Create (Prefix), Width);
end Set_Prefix;
procedure Set_Prefix
(Object : in out Format;
Values : in Interval;
Prefix : in Atom_Refs.Immutable_Reference;
Width : in Generic_Integers.Width) is
begin
Include (Object.Prefix, Values, Prefix, Width);
end Set_Prefix;
procedure Set_Prefix
(Object : in out Format;
Values : in Interval;
Prefix : in Atom) is
begin
Set_Prefix (Object, Values, Prefix, Prefix'Length);
end Set_Prefix;
procedure Set_Prefix
(Object : in out Format;
Values : in Interval;
Prefix : in Atom;
Width : in Generic_Integers.Width) is
begin
Set_Prefix (Object, Values, Create (Prefix), Width);
end Set_Prefix;
procedure Set_Right_Padding
(Object : in out Format;
Symbol : in Atom_Refs.Immutable_Reference) is
begin
Object.Right_Padding := Symbol;
end Set_Right_Padding;
procedure Set_Right_Padding
(Object : in out Format;
Symbol : in Atom) is
begin
Set_Right_Padding (Object, Create (Symbol));
end Set_Right_Padding;
procedure Set_Suffix
(Object : in out Format;
Value : in T;
Suffix : in Atom_Refs.Immutable_Reference;
Width : in Generic_Integers.Width) is
begin
Set_Suffix (Object, (Value, Value), Suffix, Width);
end Set_Suffix;
procedure Set_Suffix
(Object : in out Format;
Value : in T;
Suffix : in Atom) is
begin
Set_Suffix (Object, Value, Suffix, Suffix'Length);
end Set_Suffix;
procedure Set_Suffix
(Object : in out Format;
Value : in T;
Suffix : in Atom;
Width : in Generic_Integers.Width) is
begin
Set_Suffix (Object, Value, Create (Suffix), Width);
end Set_Suffix;
procedure Set_Suffix
(Object : in out Format;
Values : in Interval;
Suffix : in Atom_Refs.Immutable_Reference;
Width : in Generic_Integers.Width) is
begin
Include (Object.Suffix, Values, Suffix, Width);
end Set_Suffix;
procedure Set_Suffix
(Object : in out Format;
Values : in Interval;
Suffix : in Atom) is
begin
Set_Suffix (Object, Values, Suffix, Suffix'Length);
end Set_Suffix;
procedure Set_Suffix
(Object : in out Format;
Values : in Interval;
Suffix : in Atom;
Width : in Generic_Integers.Width) is
begin
Set_Suffix (Object, Values, Create (Suffix), Width);
end Set_Suffix;
procedure Set_Symbols
(Object : in out Format;
Symbols : in Atom_Arrays.Immutable_Reference) is
begin
if not Symbols.Is_Empty and then Symbols.Query.Data.all'Length >= 2 then
Object.Symbols := Symbols;
end if;
end Set_Symbols;
procedure Set_Symbols
(Object : in out Format;
Expression : in out S_Expressions.Descriptor'Class) is
begin
Set_Symbols (Object, Create (Expression));
end Set_Symbols;
end Natools.S_Expressions.Templates.Generic_Integers;
|
1Crazymoney/LearnAda | Ada | 798 | adb | with Ada.Text_IO;
use Ada.Text_IO;
procedure Szummazas_Rek is
type Index is new Integer;
type Elem is new Integer;
type Tomb is array (Index range <>) of Elem;
function Szumma ( T: Tomb; S: Elem ) return Elem is
begin
if T'Length > 1 then
return Szumma(T(T'First..Index'Pred(T'Last)), S + T(T'Last));
else
return S + T(T'Last);
end if;
end Szumma;
function Szumma2 ( T: Tomb ) return Elem is
begin
if T'Length > 1 then
return T(T'Last) + Szumma2(T(T'First..Index'Pred(T'Last)));
else
return T(T'Last);
end if;
end Szumma2;
begin
Put_Line( Elem'Image( Szumma((3,2,5,7,1), 0) ) );
Put_Line( Elem'Image( Szumma2((3,2,5,7,1)) ) );
end Szummazas_Rek;
|
reznikmm/markdown | Ada | 3,675 | adb | -- SPDX-FileCopyrightText: 2020 Max Reznik <[email protected]>
--
-- SPDX-License-Identifier: MIT
----------------------------------------------------------------
with League.String_Vectors;
package body Markdown.Common_Patterns is
Link_Destination : constant Wide_Wide_String := "\<([^\<\>\\]|\\.)*\>";
Link_Destination_Pattern : constant League.Regexps.Regexp_Pattern :=
League.Regexps.Compile
(League.Strings.To_Universal_String (Link_Destination));
----------------------------
-- Parse_Link_Destination --
----------------------------
procedure Parse_Link_Destination
(Line : League.Strings.Universal_String;
Last : out Natural;
URL : out League.Strings.Universal_String)
is
function Unescape
(Text : League.Strings.Universal_String)
return League.Strings.Universal_String;
--------------
-- Unescape --
--------------
function Unescape
(Text : League.Strings.Universal_String)
return League.Strings.Universal_String
is
Masked : constant League.Strings.Universal_String :=
League.Strings.To_Universal_String
("!""#$%&'()*+,-./:;<=>?@[]^_`{|}~");
List : constant League.String_Vectors.Universal_String_Vector :=
Text.Split ('\');
Result : League.Strings.Universal_String;
begin
if List.Length > 0 then
Result := List (1);
end if;
for J in 2 .. List.Length loop
declare
Item : constant League.Strings.Universal_String := List (J);
begin
if Item.Is_Empty or else Masked.Index (Item (1)) = 0 then
Result.Append ("\");
end if;
Result.Append (Item);
end;
end loop;
return Result;
end Unescape;
Is_Escape : Boolean := False;
Stop : Natural := 0; -- index of first unmatched '('
Count : Natural := 0; -- Count of unmatched '('
begin
if Line.Starts_With ("<") then
declare
Match : constant League.Regexps.Regexp_Match :=
Link_Destination_Pattern.Find_Match (Line);
Text : League.Strings.Universal_String;
begin
if Match.Is_Matched then
Text := Match.Capture;
URL := Unescape (Text.Slice (2, Text.Length - 1));
Last := Match.Last_Index;
else
Last := 0;
end if;
return;
end;
end if;
Last := Line.Length;
for J in 1 .. Line.Length loop
declare
Char : constant Wide_Wide_Character :=
Line (J).To_Wide_Wide_Character;
begin
if Is_Escape then
Is_Escape := False;
elsif Char = '\' then
Is_Escape := True;
elsif Char <= ' ' then
Last := J - 1;
exit;
elsif Char = '(' then
if Count = 0 then
Stop := J;
end if;
Count := Count + 1;
elsif Char = ')' then
if Count = 0 then
Last := J - 1;
exit;
else
Count := Count - 1;
end if;
end if;
end;
end loop;
if Count > 0 then
Last := Stop - 1;
elsif Is_Escape then
Last := Last - 1;
end if;
if Last > 0 then
URL := Unescape (Line.Head_To (Last));
end if;
end Parse_Link_Destination;
end Markdown.Common_Patterns;
|
annexi-strayline/ASAP-Simple_HTTP | Ada | 17,390 | ads | ------------------------------------------------------------------------------
-- --
-- Simple HTTP --
-- --
-- Basic HTTP 1.1 support for API endpoints --
-- --
-- ------------------------------------------------------------------------ --
-- --
-- Copyright (C) 2021, ANNEXI-STRAYLINE Trans-Human Ltd. --
-- All rights reserved. --
-- --
-- Original Contributors: --
-- * Richard Wai (ANNEXI-STRAYLINE) --
-- --
-- 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 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 --
-- 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. --
-- --
------------------------------------------------------------------------------
with Ada.Streams;
with Ada.Strings.Bounded;
with Ada.Strings.Bounded.Hash;
with Ada.Containers.Bounded_Hashed_Sets;
with Simple_HTTP.RFC_7230_7231;
generic
Path_Bounds : in Positive := 200;
-- This the bounds for the actual path component of a Request URI
Field_Bounds: in Positive := 80;
Value_Bounds: in Positive := 200;
-- These are the bounds for the Field and Value strings for both
-- the Headers, and for Request URI query components.
Header_Limit: in Ada.Containers.Count_Type := 20;
-- This is the maximum number of Headers that can be in a message
Query_Limit : in Ada.Containers.Count_Type := 20;
-- This is the maximum number of Queries that can be in a Request message
Query_Fields_Case_Insensitive: in Boolean := False;
-- RFC 2616 requres that header fields are case-insensitive, but no such
-- provision is made for queries. If true, all query field names will be
-- converted to lower-case, including when used in a search.
--
-- The prevailing consensus seems to suggest that queries fields follow
-- generally the convention of common programming languages used by APIs,
-- which are typically case-sensistive.
Slowloris_Timeout: in Duration := 10.0;
-- This is the _total_ amount of time that any messare 'Read or 'Input
-- operation can take to complete. This should be combined with a similar
-- timeout value for source stream itself, if possible, to mitigate
-- slowloris attacks.
Whitespace_Limit: in Positive := 60;
-- This is the maximum number of consecutive "LWS" whitespace characters
-- that may appear when skipping whitespace during parsing of an HTTP
-- message.
package Simple_HTTP.HTTP_Message_Processor is
use type Ada.Containers.Hash_Type;
use type Ada.Containers.Count_Type;
------------------
-- HTTP_Message --
------------------
type HTTP_Message_Status is
(OK,
-- Message is valid
Timeout,
-- Message took too long to complete (Slowloris_Timeout exceeded)
Too_Much_Whitespace,
-- Whitespace_Limit was exceeded.
Bad_Input,
-- A general violation of the input data was encountered.
Bad_Version,
-- Message version was not HTTP 1.1.
-- These messages are still parsed as if they are HTTP 1.1,
-- and so the user can decide how they wish to proceed
Bad_Method,
-- The given request method was not recognized.
Bad_Status,
-- The given reply status value was out of range or of an unexpected
-- format
Bad_URI,
-- The format of the request URI was invalid
Bad_Query,
-- This typicaly means a query without a field name was found in the URI,
-- an empty query was found, or a duplicate.
-- For example "GET /index.html?=1337", "GET /?x=y&&", or "GET /?x=y&x=q"
URI_Too_Long,
-- The URI of the request was longer than Path_Bounds
Bad_Header,
-- The format of a Header was incorrect
Header_Field_Too_Long,
-- The header's field was longer than Field_Bounds
Header_Value_Too_Long,
-- The header's value was longer than Value_Bounds
Too_Many_Headers);
-- Header_Capacity was exceeded
type HTTP_Message is abstract tagged private;
-- HTTP_Message is the root type for both HTTP_Request and HTTP_Response
-- messages.
function Status (Message: HTTP_Message) return HTTP_Message_Status;
procedure Clear_Headers (Message: in out HTTP_Message);
-- Removes all Headers from Message.
function Header_Count (Message: HTTP_Message)
return Ada.Containers.Count_Type;
-- Returns the number of headers contained in the Message
procedure Add_Header (Message : in out HTTP_Message;
Field, Value : in String)
with Pre => Header_Count (Message) < Header_Limit
and Field'Length > 0
and Value'Length > 0;
-- Adds a specified Header to Message. If this exceeds the the capacity
-- of Message, or if Name or Value are null strings, Constraint_Error is
-- raised.
--
-- If Field already exists in the message, Value is appended to the current
-- value, immediately after a ','. This is the convention specified in
-- RFC 7230-3.2.2, and preserves the order. Note that "Set-Cookie" (RFC6265)
-- would need separate treatment. This parser does not treat "Set-Cookie"
-- specially, so it will collapse multiple "Set-Cookies". See RFC7230-3.2.2
-- for additional commentary on this issue.
--
-- Note that the 'Read and 'Input operations invoke (in effect) Add_Header,
-- and will therefore also obey the order of multiple instances of the same
-- header Field name.
--
-- RFC 7230 specifies that header field names are case-insensitive (Section
-- 3.2). Therefore, Field is automatically converted to lower-case.
--
-- Add_Header does not validate the contents of Field or Value, however,
-- 'Input/'Read does. It is therefore important that the user ensure that
-- the contents of Field and Value are valid (including being properly
-- escaped) when adding them programatically.
--
-- Notes:
-- * Headers will be stored (and output) in an arbitrary order.
-- * 'Input/'Read does NOT support "obsolete line folding". Such input will
-- result in a Bad_Header status.
function Header_Value (Message: HTTP_Message; Field: String)
return String;
-- Returns the Value of the specific Field. If the specified Field does not
-- exist, a null String is returned. Field is case-insensitive. Note that
-- header fields without a value are not accepted.
procedure Iterate_Headers
(Message: in HTTP_Message;
Process: not null access procedure (Field, Value: in String));
-- Invokes Process for each header, in an arbitrary order.
------------------
-- HTTP_Request --
------------------
type HTTP_Request is new HTTP_Message with private;
function Method (Request: HTTP_Request) return RFC_7230_7231.Request_Method;
procedure Set_Method (Request: in out HTTP_Request;
Method : in RFC_7230_7231.Request_Method);
-- Note that extension-methods are not supported by this implementation.
-- Any such methods will cause the HTTP_Request to be invalid.
function Base_URI (Request: HTTP_Request) return String;
procedure Set_Base_URI (Request: in out HTTP_Request;
URI : in String);
-- Returns/Sets the part of the RFC2396 URI containing "scheme", "authority"
-- and "net_path" / "abs_path" components of the as any user and authority
-- components, if given. These components may be seperatedly identified and
-- stripped via specialized functions in the RFC_2396 package. Base_URI
-- shall not contain any query components when set.
--
-- During HTTP_Request'Read/'Input, the Query components are specially
-- parsed and removed from the URI. During 'Write/'Output, any query
-- components are added to the Request-Line URI automatically.
--
-- Note that fragments are not supported or recognized by this
-- implementation. The presence of a fragment in Set_Base_URI will cause
-- Constraint_Error. For 'Input/'Read, fragments are stripped from
-- HTTP_Request URIs and discarded.
function Query_Count (Request: HTTP_Request)
return Ada.Containers.Count_Type;
-- Returns the number of queries contained in the Request
procedure Clear_Queries (Request: in out HTTP_Request);
-- Removes all queries from the request
procedure Add_Query (Request : in out HTTP_Request;
Field, Value: in String)
with Pre => Query_Count (Request) < Query_Limit
and Field'Length > 0;
-- Adds a specified query to Request. If this exceeds the the capacity
-- of Request, or if Name or Value are null strings, Constraint_Error is
-- raised.
--
-- Note: See the formal parameter Query_Fields_Case_Insensitive for
-- details on the case handling of query Field names.
--
-- Note that headers will be stored (and output) in an arbitrary order.
function Query_Exists (Request: HTTP_Request; Field: String)
return Boolean;
-- Returns True if Field exists as a query.
function Query (Request: HTTP_Request; Field: String) return String;
-- Returns the Value for the given Field. If no such Query exits,
-- a null String is returned. Note that a query might exist, but have
-- a nil value. See Query_Exists to differentiate these cases.
procedure Iterate_Queries
(Request: in HTTP_Request;
Process: not null access procedure (Field, Value: in String));
-- Invokes Process for each query, in an arbitrary order.
procedure Write_Request
(Stream : not null access Ada.Streams.Root_Stream_Type'Class;
Request: in HTTP_Request)
with Pre => Request.Status = OK;
procedure Read_Request
(Stream : not null access Ada.Streams.Root_Stream_Type'Class;
Request: out HTTP_Request);
function Input_Request
(Stream: not null access Ada.Streams.Root_Stream_Type'Class)
return HTTP_Request;
for HTTP_Request'Write use Write_Request;
for HTTP_Request'Output use Write_Request;
for HTTP_Request'Read use Read_Request;
for HTTP_Request'Input use Input_Request;
-- Read and Input will mark the Request as invalid immediately upon receipt
-- of any invalidating data, and will not continue to read the stream.
--
-- Note that headers are always converted to lower-case
-------------------
-- HTTP_Response --
-------------------
type HTTP_Response is new HTTP_Message with private;
function Status_Code (Response: HTTP_Response)
return RFC_7230_7231.Response_Status;
function Reason_Phrase (Response: HTTP_Response) return String;
-- Note that the Status_Phrase is limited to a maximum of 200 characters,
-- and will be truncated if exceeded.
procedure Set_Standard_Status
(Response: in out HTTP_Response;
Code : in RFC_7230_7231.Standard_Response_Status);
-- Sets the response code and phrase, based on the code. Code must be
-- one of the standard codes defined in RFC 7231, else Constraint_Error
-- is explicitly raised (assuming predicate checking is not enabled).
procedure Set_Explicit_Status
(Response: in out HTTP_Response;
Code : in RFC_7230_7231.Response_Status;
Phrase : in String)
with Pre => Phrase'Length <= 200;
procedure Write_Response
(Stream : not null access Ada.Streams.Root_Stream_Type'Class;
Response: in HTTP_Response);
procedure Read_Response
(Stream : not null access Ada.Streams.Root_Stream_Type'Class;
Response: out HTTP_Response);
function Input_Response
(Stream: not null access Ada.Streams.Root_Stream_Type'Class)
return HTTP_Response;
for HTTP_Response'Write use Write_Response;
for HTTP_Response'Output use Write_Response;
for HTTP_Response'Read use Read_Response;
for HTTP_Response'Input use Input_Response;
private
package Field_Strings is new Ada.Strings.Bounded.Generic_Bounded_Length
(Field_Bounds);
package Value_Strings is new Ada.Strings.Bounded.Generic_Bounded_Length
(Value_Bounds);
package Path_Strings is new Ada.Strings.Bounded.Generic_Bounded_Length
(Path_Bounds);
package Phrase_Strings is new Ada.Strings.Bounded.Generic_Bounded_Length
(200);
------------------
-- HTTP_Message --
------------------
type HTTP_Header is
record
Field: Field_Strings.Bounded_String;
Value: Value_Strings.Bounded_String;
end record;
function Header_Field_Hash is new Ada.Strings.Bounded.Hash (Field_Strings);
function HTTP_Header_Hash (Header: HTTP_Header)
return Ada.Containers.Hash_Type
is (Header_Field_Hash (Header.Field));
function Equivalent_Header (Left, Right: HTTP_Header) return Boolean
is (Field_Strings."=" (Left.Field, Right.Field));
package Header_Sets is new Ada.Containers.Bounded_Hashed_Sets
(Element_Type => HTTP_Header,
Hash => HTTP_Header_Hash,
Equivalent_Elements => Equivalent_Header);
Default_Header_Set_Modulus: constant Ada.Containers.Hash_Type
:= Header_Sets.Default_Modulus (Header_Limit);
subtype Header_Set is Header_Sets.Set
(Capacity => Header_Limit,
Modulus => Default_Header_Set_Modulus);
type HTTP_Message is abstract tagged
record
Status : HTTP_Message_Status;
Headers: Header_Set;
end record;
------------------
-- HTTP_Request --
------------------
Default_Query_Set_Modulus: constant Ada.Containers.Hash_Type
:= Header_Sets.Default_Modulus (Query_Limit);
subtype Query_Set is Header_Sets.Set
(Capacity => Query_Limit,
Modulus => Default_Query_Set_Modulus);
type HTTP_Request is new HTTP_Message with
record
Method : RFC_7230_7231.Request_Method;
URI : Path_Strings.Bounded_String;
Queries : Query_Set;
end record;
-------------------
-- HTTP_Response --
-------------------
type HTTP_Response is new HTTP_Message with
record
Status_Code : RFC_7230_7231.Response_Status;
Reason_Phrase: Phrase_Strings.Bounded_String;
end record;
end Simple_HTTP.HTTP_Message_Processor;
|
micahwelf/FLTK-Ada | Ada | 1,667 | ads |
package FLTK.Widgets.Valuators.Sliders.Value is
type Value_Slider is new Slider with private;
type Value_Slider_Reference (Data : not null access Value_Slider'Class) is
limited null record with Implicit_Dereference => Data;
package Forge is
function Create
(X, Y, W, H : in Integer;
Text : in String)
return Value_Slider;
end Forge;
function Get_Text_Color
(This : in Value_Slider)
return Color;
procedure Set_Text_Color
(This : in out Value_Slider;
To : in Color);
function Get_Text_Font
(This : in Value_Slider)
return Font_Kind;
procedure Set_Text_Font
(This : in out Value_Slider;
To : in Font_Kind);
function Get_Text_Size
(This : in Value_Slider)
return Font_Size;
procedure Set_Text_Size
(This : in out Value_Slider;
To : in Font_Size);
procedure Draw
(This : in out Value_Slider);
function Handle
(This : in out Value_Slider;
Event : in Event_Kind)
return Event_Outcome;
private
type Value_Slider is new Slider with null record;
overriding procedure Finalize
(This : in out Value_Slider);
pragma Inline (Get_Text_Color);
pragma Inline (Set_Text_Color);
pragma Inline (Get_Text_Font);
pragma Inline (Set_Text_Font);
pragma Inline (Get_Text_Size);
pragma Inline (Set_Text_Size);
pragma Inline (Draw);
pragma Inline (Handle);
end FLTK.Widgets.Valuators.Sliders.Value;
|
stcarrez/mat | Ada | 5,853 | ads | private package MAT.Expressions.Parser_Shift_Reduce is
type Small_Integer is range -32_000 .. 32_000;
type Shift_Reduce_Entry is record
T : Small_Integer;
Act : Small_Integer;
end record;
pragma Pack (Shift_Reduce_Entry);
type Row is new Integer range -1 .. Integer'Last;
-- pragma suppress(index_check);
type Shift_Reduce_Array is array (Row range <>) of Shift_Reduce_Entry;
Shift_Reduce_Matrix : constant Shift_Reduce_Array :=
((-1, -1) -- Dummy Entry
-- State 0
, (2, 28), (3, 26), (4, 27), (8, 5), (9, 4), (10, 3), (13, 10)
, (14, 13), (15, 6), (22, 9), (24, 7), (25, 8), (28, 17), (29, 19)
, (30, 18), (31, 20), (32, 21), (33, 22), (34, 23), (35, 24), (36, 11)
, (38, 14), (39, 16), (46, 12), (49, 2), (-1, -3000)
-- State 1
, (11, 30), (12, 31), (-1, -1)
-- State 2
, (2, 28), (3, 26), (4, 27), (8, 5), (9, 4), (10, 3), (13, 10)
, (14, 13), (15, 6), (22, 9), (24, 7), (25, 8), (28, 17), (29, 19)
, (30, 18), (31, 20), (32, 21), (33, 22), (34, 23), (35, 24), (36, 11)
, (38, 14), (39, 16), (46, 12), (49, 2), (-1, -3000)
-- State 3
, (2, 28), (3, 26), (4, 27), (8, 5), (9, 4), (10, 3), (13, 10)
, (14, 13), (15, 6), (22, 9), (24, 7), (25, 8), (28, 17), (29, 19)
, (30, 18), (31, 20), (32, 21), (33, 22), (34, 23), (35, 24), (36, 11)
, (38, 14), (39, 16), (46, 12), (49, 2), (-1, -3000)
-- State 4
, (26, 34), (-1, -46)
-- State 5
, (26, 34), (-1, -46)
-- State 6
, (3, 38), (39, 37), (-1, -3000)
-- State 7
, (3, 38), (39, 37), (-1, -3000)
-- State 8
, (3, 38), (39, 37), (-1, -3000)
-- State 9
, (2, 28), (4, 27), (-1, -3000)
-- State 10
, (40, 43), (41, 44), (42, 45), (43, 46), (44, 48), (45, 47), (-1, -3000)
-- State 11
, (40, 43), (41, 44), (42, 45), (43, 46), (44, 48), (45, 47), (-1, -3000)
-- State 12
, (3, 26), (-1, -3000)
-- State 13
, (40, 43), (41, 44), (42, 45), (43, 46), (44, 48), (45, 47), (-1, -3000)
-- State 14
, (40, 43), (41, 44), (42, 45), (43, 46), (44, 48), (45, 47), (-1, -3000)
-- State 15
, (37, 54), (-1, -3000)
-- State 16
, (40, 43), (41, 44), (42, 45), (43, 46), (44, 48), (45, 47), (-1, -3000)
-- State 17
, (-1, -20)
-- State 18
, (-1, -21)
-- State 19
, (-1, -22)
-- State 20
, (-1, -23)
-- State 21
, (-1, -24)
-- State 22
, (-1, -25)
-- State 23
, (-1, -26)
-- State 24
, (-1, -27)
-- State 25
, (-1, -28)
-- State 26
, (-1, -43)
-- State 27
, (-1, -36)
-- State 28
, (-1, -37)
-- State 29
, (0, -3001), (-1, -3000)
-- State 30
, (2, 28), (3, 26), (4, 27), (8, 5), (9, 4), (10, 3), (13, 10)
, (14, 13), (15, 6), (22, 9), (24, 7), (25, 8), (28, 17), (29, 19)
, (30, 18), (31, 20), (32, 21), (33, 22), (34, 23), (35, 24), (36, 11)
, (38, 14), (39, 16), (46, 12), (49, 2), (-1, -3000)
-- State 31
, (2, 28), (3, 26), (4, 27), (8, 5), (9, 4), (10, 3), (13, 10)
, (14, 13), (15, 6), (22, 9), (24, 7), (25, 8), (28, 17), (29, 19)
, (30, 18), (31, 20), (32, 21), (33, 22), (34, 23), (35, 24), (36, 11)
, (38, 14), (39, 16), (46, 12), (49, 2), (-1, -3000)
-- State 32
, (11, 30), (12, 31), (50, 59), (-1, -3000)
-- State 33
, (-1, -3)
-- State 34
, (-1, -47)
-- State 35
, (2, 28), (4, 27), (-1, -3000)
-- State 36
, (2, 28), (3, 26), (4, 27), (-1, -3000)
-- State 37
, (-1, -44)
-- State 38
, (-1, -45)
-- State 39
, (18, 63), (-1, -3000)
-- State 40
, (-1, -10)
-- State 41
, (-1, -11)
-- State 42
, (-1, -12)
-- State 43
, (3, 26), (-1, -3000)
-- State 44
, (3, 26), (-1, -3000)
-- State 45
, (3, 26), (-1, -3000)
-- State 46
, (3, 26), (-1, -3000)
-- State 47
, (3, 26), (-1, -3000)
-- State 48
, (3, 26), (-1, -3000)
-- State 49
, (-1, -13)
-- State 50
, (-1, -14)
-- State 51
, (-1, -15)
-- State 52
, (-1, -16)
-- State 53
, (-1, -17)
-- State 54
, (3, 26), (-1, -3000)
-- State 55
, (-1, -19)
-- State 56
, (-1, -3000)
-- State 57
, (12, 31), (-1, -4)
-- State 58
, (-1, -5)
-- State 59
, (-1, -2)
-- State 60
, (-1, -6)
-- State 61
, (-1, -7)
-- State 62
, (-1, -8)
-- State 63
, (3, 38), (39, 37), (-1, -3000)
-- State 64
, (-1, -29)
-- State 65
, (-1, -30)
-- State 66
, (-1, -31)
-- State 67
, (-1, -32)
-- State 68
, (37, 72), (-1, -34)
-- State 69
, (-1, -35)
-- State 70
, (-1, -18)
-- State 71
, (-1, -9)
-- State 72
, (3, 26), (-1, -3000)
-- State 73
, (-1, -33)
);
-- The offset vector
Shift_Reduce_Offset : constant array (0 .. 73) of Row :=
(0,
26, 29, 55, 81, 83, 85, 88, 91, 94, 97,
104, 111, 113, 120, 127, 129, 136, 137, 138, 139,
140, 141, 142, 143, 144, 145, 146, 147, 148, 150,
176, 202, 206, 207, 208, 211, 215, 216, 217, 219,
220, 221, 222, 224, 226, 228, 230, 232, 234, 235,
236, 237, 238, 239, 241, 242, 243, 245, 246, 247,
248, 249, 250, 253, 254, 255, 256, 257, 259, 260,
261, 262, 264);
end MAT.Expressions.Parser_Shift_Reduce;
|
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_Error_Lower_Range_Attributes;
package Matreshka.ODF_Chart.Error_Lower_Range_Attributes is
type Chart_Error_Lower_Range_Attribute_Node is
new Matreshka.ODF_Chart.Abstract_Chart_Attribute_Node
and ODF.DOM.Chart_Error_Lower_Range_Attributes.ODF_Chart_Error_Lower_Range_Attribute
with null record;
overriding function Create
(Parameters : not null access Matreshka.DOM_Attributes.Attribute_L2_Parameters)
return Chart_Error_Lower_Range_Attribute_Node;
overriding function Get_Local_Name
(Self : not null access constant Chart_Error_Lower_Range_Attribute_Node)
return League.Strings.Universal_String;
end Matreshka.ODF_Chart.Error_Lower_Range_Attributes;
|
zhmu/ananas | Ada | 3,473 | adb | ------------------------------------------------------------------------------
-- --
-- GNAT RUN-TIME COMPONENTS --
-- --
-- A D A . S T R I N G S . U N B O U N D E D . A U X --
-- --
-- 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. --
-- --
------------------------------------------------------------------------------
package body Ada.Strings.Unbounded.Aux is
----------------
-- Get_String --
----------------
procedure Get_String
(U : Unbounded_String;
S : out Big_String_Access;
L : out Natural)
is
X : aliased Big_String;
for X'Address use U.Reference.Data'Address;
begin
S := X'Unchecked_Access;
L := U.Reference.Last;
end Get_String;
----------------
-- Set_String --
----------------
procedure Set_String
(U : out Unbounded_String;
Length : Positive;
Set : not null access procedure (S : out String))
is
TR : constant Shared_String_Access := U.Reference;
DR : Shared_String_Access;
begin
-- Try to reuse existing shared string
if Can_Be_Reused (TR, Length) then
Reference (TR);
DR := TR;
-- Otherwise allocate new shared string
else
DR := Allocate (Length);
U.Reference := DR;
end if;
Set (DR.Data (1 .. Length));
DR.Last := Length;
Unreference (TR);
end Set_String;
end Ada.Strings.Unbounded.Aux;
|
charlie5/lace | Ada | 1,968 | adb | with
openGL.Visual,
openGL.Model.Capsule.lit_colored_textured,
openGL.Palette,
openGL.Light,
openGL.Demo;
procedure launch_render_Capsules
--
-- Exercise the render of capsule models.
--
is
use openGL,
openGL.Model,
openGL.Math,
openGL.linear_Algebra_3d;
begin
Demo.print_Usage;
Demo.define ("openGL 'Render Capsules' Demo");
Demo.Camera.Position_is ([0.0, 3.0, 10.0],
y_Rotation_from (to_Radians (-0.0)));
Demo.Dolly.Speed_is (0.1);
declare
use openGL.Palette;
the_Light : openGL.Light.item := Demo.Renderer.new_Light;
the_Texture : constant asset_Name := to_Asset ("assets/opengl/texture/Face1.bmp");
-- The Models.
--
the_Capsule_Model : constant Model.Capsule.lit_colored_textured.view
:= Model.Capsule.lit_colored_textured.new_Capsule (Radius => 0.5,
Height => 2.0,
Color => (White, Opaque),
Image => the_Texture);
-- The Visuals.
--
use openGL.Visual.Forge;
the_Visuals : constant openGL.Visual.views := [1 => new_Visual (the_Capsule_Model.all'Access)];
begin
the_Light.Site_is ([0.0, 5.0, 10.0]);
Demo.Renderer.set (the_Light);
-- Main loop.
--
while not Demo.Done
loop
-- Handle user commands.
--
Demo.Dolly.evolve;
Demo.Done := Demo.Dolly.quit_Requested;
-- Render the sprites.
--
Demo.Camera.render (the_Visuals);
while not Demo.Camera.cull_Completed
loop
delay Duration'Small;
end loop;
Demo.Renderer.render;
Demo.FPS_Counter.increment; -- Frames per second display.
end loop;
end;
Demo.destroy;
end launch_render_Capsules;
|
guillaume-lin/tsc | Ada | 14,033 | adb | ------------------------------------------------------------------------------
-- --
-- GNAT ncurses Binding Samples --
-- --
-- Sample.Explanation --
-- --
-- B O D Y --
-- --
------------------------------------------------------------------------------
-- Copyright (c) 1998 Free Software Foundation, Inc. --
-- --
-- Permission is hereby granted, free of charge, to any person obtaining a --
-- copy of this software and associated documentation files (the --
-- "Software"), to deal in the Software without restriction, including --
-- without limitation the rights to use, copy, modify, merge, publish, --
-- distribute, distribute with modifications, sublicense, and/or sell --
-- copies of the Software, and to permit persons to whom the Software is --
-- furnished to do so, subject to the following conditions: --
-- --
-- The above copyright notice and this permission notice shall be included --
-- in all copies or substantial portions of the Software. --
-- --
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS --
-- OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF --
-- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. --
-- IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, --
-- DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR --
-- OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR --
-- THE USE OR OTHER DEALINGS IN THE SOFTWARE. --
-- --
-- Except as contained in this notice, the name(s) of the above copyright --
-- holders shall not be used in advertising or otherwise to promote the --
-- sale, use or other dealings in this Software without prior written --
-- authorization. --
------------------------------------------------------------------------------
-- Author: Juergen Pfeifer, 1996
-- Version Control
-- $Revision: 1.15 $
-- Binding Version 01.00
------------------------------------------------------------------------------
-- Poor mans help system. This scans a sequential file for key lines and
-- then reads the lines up to the next key. Those lines are presented in
-- a window as help or explanation.
--
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Unchecked_Deallocation;
with Terminal_Interface.Curses; use Terminal_Interface.Curses;
with Terminal_Interface.Curses.Panels; use Terminal_Interface.Curses.Panels;
with Sample.Keyboard_Handler; use Sample.Keyboard_Handler;
with Sample.Manifest; use Sample.Manifest;
with Sample.Function_Key_Setting; use Sample.Function_Key_Setting;
with Sample.Helpers; use Sample.Helpers;
package body Sample.Explanation is
Help_Keys : constant String := "HELPKEYS";
In_Help : constant String := "INHELP";
File_Name : String := "explain.msg";
F : File_Type;
type Help_Line;
type Help_Line_Access is access Help_Line;
pragma Controlled (Help_Line_Access);
type String_Access is access String;
pragma Controlled (String_Access);
type Help_Line is
record
Prev, Next : Help_Line_Access;
Line : String_Access;
end record;
procedure Explain (Key : in String;
Win : in Window);
procedure Release_String is
new Ada.Unchecked_Deallocation (String,
String_Access);
procedure Release_Help_Line is
new Ada.Unchecked_Deallocation (Help_Line,
Help_Line_Access);
function Search (Key : String) return Help_Line_Access;
procedure Release_Help (Root : in out Help_Line_Access);
procedure Explain (Key : in String)
is
begin
Explain (Key, Null_Window);
end Explain;
procedure Explain (Key : in String;
Win : in Window)
is
-- Retrieve the text associated with this key and display it in this
-- window. If no window argument is passed, the routine will create
-- a temporary window and use it.
function Filter_Key return Real_Key_Code;
procedure Unknown_Key;
procedure Redo;
procedure To_Window (C : in out Help_Line_Access;
More : in out Boolean);
Frame : Window := Null_Window;
W : Window := Win;
K : Real_Key_Code;
P : Panel;
Height : Line_Count;
Width : Column_Count;
Help : Help_Line_Access := Search (Key);
Current : Help_Line_Access;
Top_Line : Help_Line_Access;
Has_More : Boolean;
procedure Unknown_Key
is
begin
Add (W, "Help message with ID ");
Add (W, Key);
Add (W, " not found.");
Add (W, Character'Val (10));
Add (W, "Press the Function key labelled 'Quit' key to continue.");
end Unknown_Key;
procedure Redo
is
H : Help_Line_Access := Top_Line;
begin
if Top_Line /= null then
for L in 0 .. (Height - 1) loop
Add (W, L, 0, H.Line.all);
exit when H.Next = null;
H := H.Next;
end loop;
else
Unknown_Key;
end if;
end Redo;
function Filter_Key return Real_Key_Code
is
K : Real_Key_Code;
begin
loop
K := Get_Key (W);
if K in Special_Key_Code'Range then
case K is
when HELP_CODE =>
if not Find_Context (In_Help) then
Push_Environment (In_Help, False);
Explain (In_Help, W);
Pop_Environment;
Redo;
end if;
when EXPLAIN_CODE =>
if not Find_Context (Help_Keys) then
Push_Environment (Help_Keys, False);
Explain (Help_Keys, W);
Pop_Environment;
Redo;
end if;
when others => exit;
end case;
else
exit;
end if;
end loop;
return K;
end Filter_Key;
procedure To_Window (C : in out Help_Line_Access;
More : in out Boolean)
is
L : Line_Position := 0;
begin
loop
Add (W, L, 0, C.Line.all);
L := L + 1;
exit when C.Next = null or else L = Height;
C := C.Next;
end loop;
if C.Next /= null then
pragma Assert (L = Height);
More := True;
else
More := False;
end if;
end To_Window;
begin
if W = Null_Window then
Push_Environment ("HELP");
Default_Labels;
Frame := New_Window (Lines - 2, Columns, 0, 0);
if Has_Colors then
Set_Background (Win => Frame,
Ch => (Ch => ' ',
Color => Help_Color,
Attr => Normal_Video));
Set_Character_Attributes (Win => Frame,
Attr => Normal_Video,
Color => Help_Color);
Erase (Frame);
end if;
Box (Frame);
Set_Character_Attributes (Frame, (Reverse_Video => True,
others => False));
Add (Frame, Lines - 3, 2, "Cursor Up/Down scrolls");
Set_Character_Attributes (Frame); -- Back to default.
Window_Title (Frame, "Explanation");
W := Derived_Window (Frame, Lines - 4, Columns - 2, 1, 1);
Refresh_Without_Update (Frame);
Get_Size (W, Height, Width);
Set_Meta_Mode (W);
Set_KeyPad_Mode (W);
Allow_Scrolling (W, True);
Set_Echo_Mode (False);
P := Create (Frame);
Top (P);
Update_Panels;
else
Clear (W);
Refresh_Without_Update (W);
end if;
Current := Help; Top_Line := Help;
if null = Help then
Unknown_Key;
loop
K := Filter_Key;
exit when K = QUIT_CODE;
end loop;
else
To_Window (Current, Has_More);
if Has_More then
-- This means there are more lines available, so we have to go
-- into a scroll manager.
loop
K := Filter_Key;
if K in Special_Key_Code'Range then
case K is
when Key_Cursor_Down =>
if Current.Next /= null then
Move_Cursor (W, Height - 1, 0);
Scroll (W, 1);
Current := Current.Next;
Top_Line := Top_Line.Next;
Add (W, Current.Line.all);
end if;
when Key_Cursor_Up =>
if Top_Line.Prev /= null then
Move_Cursor (W, 0, 0);
Scroll (W, -1);
Top_Line := Top_Line.Prev;
Current := Current.Prev;
Add (W, Top_Line.Line.all);
end if;
when QUIT_CODE => exit;
when others => null;
end case;
end if;
end loop;
else
loop
K := Filter_Key;
exit when K = QUIT_CODE;
end loop;
end if;
end if;
Clear (W);
if Frame /= Null_Window then
Clear (Frame);
Delete (P);
Delete (W);
Delete (Frame);
Pop_Environment;
end if;
Update_Panels;
Update_Screen;
Release_Help (Help);
end Explain;
function Search (Key : String) return Help_Line_Access
is
Last : Natural;
Buffer : String (1 .. 256);
Root : Help_Line_Access := null;
Current : Help_Line_Access;
Tail : Help_Line_Access := null;
function Next_Line return Boolean;
function Next_Line return Boolean
is
H_End : constant String := "#END";
begin
Get_Line (F, Buffer, Last);
if Last = H_End'Length and then H_End = Buffer (1 .. Last) then
return False;
else
return True;
end if;
end Next_Line;
begin
Reset (F);
Outer :
loop
exit Outer when not Next_Line;
if Last = (1 + Key'Length) and then Key = Buffer (2 .. Last)
and then Buffer (1) = '#' then
loop
exit when not Next_Line;
exit when Buffer (1) = '#';
Current := new Help_Line'(null, null,
new String'(Buffer (1 .. Last)));
if Tail = null then
Release_Help (Root);
Root := Current;
else
Tail.Next := Current;
Current.Prev := Tail;
end if;
Tail := Current;
end loop;
exit Outer;
end if;
end loop Outer;
return Root;
end Search;
procedure Release_Help (Root : in out Help_Line_Access)
is
Next : Help_Line_Access;
begin
loop
exit when Root = null;
Next := Root.Next;
Release_String (Root.Line);
Release_Help_Line (Root);
Root := Next;
end loop;
end Release_Help;
procedure Explain_Context
is
begin
Explain (Context);
end Explain_Context;
procedure Notepad (Key : in String)
is
H : constant Help_Line_Access := Search (Key);
T : Help_Line_Access := H;
N : Line_Count := 1;
L : Line_Position := 0;
W : Window;
P : Panel;
begin
if H /= null then
loop
T := T.Next;
exit when T = null;
N := N + 1;
end loop;
W := New_Window (N + 2, Columns, Lines - N - 2, 0);
if Has_Colors then
Set_Background (Win => W,
Ch => (Ch => ' ',
Color => Notepad_Color,
Attr => Normal_Video));
Set_Character_Attributes (Win => W,
Attr => Normal_Video,
Color => Notepad_Color);
Erase (W);
end if;
Box (W);
Window_Title (W, "Notepad");
P := New_Panel (W);
T := H;
loop
Add (W, L + 1, 1, T.Line.all, Integer (Columns - 2));
L := L + 1;
T := T.Next;
exit when T = null;
end loop;
T := H;
Release_Help (T);
Refresh_Without_Update (W);
Notepad_To_Context (P);
end if;
end Notepad;
begin
Open (F, In_File, File_Name);
end Sample.Explanation;
|
lumalisan/EspeblancaYLos7PPs | Ada | 3,140 | adb | with Ada.Text_IO;
use Ada.Text_IO;
with def_monitor;
use def_monitor;
with Ada.Strings.Unbounded;
procedure BlancaNeus is
-- Constants
MAX_NANS : constant Integer := 7;
-- ** Especificacio **
-- Blanca Neus
task type Blanca is
entry Start (Idx: in Integer);
end Blanca;
-- Nan
task type Nan is
entry Start (Idx: in Integer);
end Nan;
-- ** Variables **
type a_nans is array (1..MAX_NANS) of Nan;
type a_noms is array (1..MAX_NANS) of Ada.Strings.Unbounded.Unbounded_String;
noms : a_noms;
n : a_nans;
b: Blanca;
mon : Monitor;
nansDormint : Integer := 0;
-- ** Cos **
-- Blanca Neus
task body Blanca is
My_Idx: Integer;
begin
-- En la creación del proceso "Blanca" se ejecuta su start
accept Start (Idx : in Integer) do
My_Idx := Idx;
Put_Line ("BON DIA som na Blancaneus");
end Start;
-- Blancanieves no acaba hasta que todos los enanos esten durmiendo
while nansDormint < MAX_NANS loop
Put_Line("Blancaneus sen va a fer una passejada");
delay 1.0;
while mon.ferMenjar loop
Put_Line("Blancaneus cuina per un nan");
delay 1.0;
mon.menjarUnlock;
end loop;
end loop;
Put_Line("Blancaneus sen va a DORMIR " & nansDormint'Img);
end Blanca;
-- Nan
task body Nan is
My_Idx : Integer;
-- max : Integer := 10;
contMenjades : Integer := 0;
begin
accept Start (Idx : in Integer) do
My_Idx := Idx;
Put_Line ("BON DIA som en " & Ada.Strings.Unbounded.To_String(noms(My_Idx)));
end Start;
while contMenjades < 2 loop
Put_Line (Ada.Strings.Unbounded.To_String(noms(My_Idx)) & " treballa a la mina");
delay 1.0;
Put_Line (Ada.Strings.Unbounded.To_String(noms(My_Idx)) & " espera per una cadira");
mon.cadiraLock;
Put_Line (Ada.Strings.Unbounded.To_String(noms(My_Idx)) & " ja seu");
Put_Line (Ada.Strings.Unbounded.To_String(noms(My_Idx)) & " espera torn per menjar");
mon.menjarLock;
Put_Line ("----------------------> " & Ada.Strings.Unbounded.To_String(noms(My_Idx)) & " menja!!!");
mon.cadiraUnlock;
contMenjades := contMenjades + 1;
end loop;
-- Cuando el enano acaba suma uno al contador de enanos durmiendo
nansDormint := nansDormint + 1;
Put_Line (Ada.Strings.Unbounded.To_String(noms(My_Idx)) & " sen va a DORMIR " & nansDormint'Img & "/7");
end Nan;
begin
noms(1) := Ada.Strings.Unbounded.To_Unbounded_String("Mudet");
noms(2) := Ada.Strings.Unbounded.To_Unbounded_String("Esternuts");
noms(3) := Ada.Strings.Unbounded.To_Unbounded_String("Dormilega");
noms(4) := Ada.Strings.Unbounded.To_Unbounded_String("Vergonyos");
noms(5) := Ada.Strings.Unbounded.To_Unbounded_String("Felis");
noms(6) := Ada.Strings.Unbounded.To_Unbounded_String("Rondinaire");
noms(7) := Ada.Strings.Unbounded.To_Unbounded_String("Savi");
b.Start(0);
for Idx in 1..MAX_NANS loop
n(Idx).Start(Idx);
end loop;
end BlancaNeus;
|
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.Elements;
package ODF.DOM.Office_Drawing_Elements is
pragma Preelaborate;
type ODF_Office_Drawing is limited interface
and XML.DOM.Elements.DOM_Element;
type ODF_Office_Drawing_Access is
access all ODF_Office_Drawing'Class
with Storage_Size => 0;
end ODF.DOM.Office_Drawing_Elements;
|
seL4/isabelle | Ada | 276 | adb | package body Sqrt is
function Isqrt(N: Natural) return Natural
is
R: Natural;
begin
R := 0;
loop
--# assert R * R <= N;
exit when N - R * R < 2 * R + 1;
R := R + 1;
end loop;
return R;
end Isqrt;
end Sqrt;
|
fengjixuchui/ewok-kernel | Ada | 3,313 | ads | --
-- Copyright 2018 The wookey project team <[email protected]>
-- - Ryad Benadjila
-- - Arnauld Michelizza
-- - Mathieu Renard
-- - Philippe Thierry
-- - Philippe Trebuchet
--
-- 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 m4.mpu;
with m4.scb;
package ewok.mpu
with spark_mode => on
is
type t_region_type is
(REGION_TYPE_USER_DATA,
REGION_TYPE_USER_CODE,
REGION_TYPE_USER_DEV,
REGION_TYPE_RO_USER_DEV,
REGION_TYPE_BOOTROM,
REGION_TYPE_ISR_DATA)
with size => 32;
SHARED_REGION : constant m4.mpu.t_region_number := 0;
KERN_CODE_REGION : constant m4.mpu.t_region_number := 1;
DEVICES_REGION : constant m4.mpu.t_region_number := 2;
BOOT_ROM_REGION : constant m4.mpu.t_region_number := 3;
KERN_DATA_REGION : constant m4.mpu.t_region_number := 3;
USER_DATA_REGION : constant m4.mpu.t_region_number := 4; -- USER_RAM
USER_CODE_REGION : constant m4.mpu.t_region_number := 5; -- USER_TXT
ISR_STACK_REGION : constant m4.mpu.t_region_number := 6;
USER_DEV1_REGION : constant m4.mpu.t_region_number := 6;
ISR_DEVICE_REGION : constant m4.mpu.t_region_number := 7;
USER_DEV2_REGION : constant m4.mpu.t_region_number := 7;
-- How many devices can be mapped in memory
MAX_DEVICE_REGIONS : constant := 2;
device_regions : array (unsigned_8 range 1 .. MAX_DEVICE_REGIONS)
of m4.mpu.t_region_number := (USER_DEV1_REGION, USER_DEV2_REGION);
---------------
-- Functions --
---------------
pragma assertion_policy (pre => IGNORE, post => IGNORE, assert => IGNORE);
-- Initialize the MPU
procedure init
(success : out boolean)
with global => (in_out => (m4.mpu.MPU, m4.scb.SCB));
-- That function is only used by SPARK prover
function get_region_size_mask (size : m4.mpu.t_region_size) return unsigned_32
is (2**(natural (size) + 1) - 1)
with ghost;
pragma warnings (off, "condition can only be False if invalid values present");
procedure regions_schedule
(region_number : in m4.mpu.t_region_number;
addr : in system_address;
size : in m4.mpu.t_region_size;
region_type : in t_region_type;
subregion_mask : in unsigned_8)
with
global => (in_out => (m4.mpu.MPU)),
pre =>
(region_number < 8
and
(addr and 2#11111#) = 0
and
size >= 4
and
(addr and get_region_size_mask(size)) = 0);
pragma warnings (on);
procedure bytes_to_region_size
(bytes : in unsigned_32;
region_size : out m4.mpu.t_region_size;
success : out boolean)
with global => null;
end ewok.mpu;
|
tum-ei-rcs/StratoX | Ada | 1,892 | ads | -- Institution: Technische Universitaet Muenchen
-- Department: Realtime Computer Systems (RCS)
-- Project: StratoX
-- Module: Estimator
--
-- Authors: Emanuel Regnath ([email protected])
--
-- Description: Estimates state data like orientation and velocity
--
-- ToDo:
-- [ ] Implementation
with Units; use Units;
with Units.Vectors; use Units.Vectors;
with Units.Navigation; use Units.Navigation;
with Interfaces; use Interfaces;
with Kalman;
-- @summary Sensor data fusion
package Estimator with SPARK_Mode is
-- init
procedure initialize;
procedure reset;
-- fetch fresh measurement data
procedure update( input : Kalman.Input_Vector );
procedure reset_log_calls;
procedure log_Info;
procedure lock_Home(position : GPS_Loacation_Type; baro_height : Altitude_Type);
function get_Orientation return Orientation_Type;
function get_Position return GPS_Loacation_Type;
function get_GPS_Fix return GPS_Fix_Type;
function get_Pos_Accuracy return Length_Type;
function get_Num_Sat return Unsigned_8;
function get_current_Height return Altitude_Type;
function get_relative_Height return Altitude_Type;
function get_max_Height return Altitude_Type;
function get_Baro_Height return Altitude_Type;
function get_Stable_Time return Time_Type;
private
function Orientation
(acc_vector : Linear_Acceleration_Vector) return Orientation_Type;
procedure update_Max_Height;
procedure check_stable_Time;
G_Object_Orientation : Orientation_Type := (0.0 * Degree, 0.0 * Degree, 0.0 * Degree);
G_Object_Position : GPS_Loacation_Type := (0.0 * Degree, 0.0 * Degree, 0.0 * Meter);
-- Object_Pose : Dynamics3D.Pose_Type := (
-- position => (0.0, 0.0, 0.0),
-- orientation => (others => 0.0) );
end Estimator;
|
yannickmoy/si_units | Ada | 2,383 | ads | --------------------------------------------------------------------------------
-- Copyright (C) 2020 by Heisenbug Ltd. ([email protected])
--
-- This work is free. You can redistribute it and/or modify it under the
-- terms of the Do What The Fuck You Want To Public License, Version 2,
-- as published by Sam Hocevar. See the LICENSE file for more details.
--------------------------------------------------------------------------------
pragma License (Unrestricted);
--------------------------------------------------------------------------------
-- Metric (SI) units scaling support.
--
-- Conversion between differently prefixed raw values, i.e. from hPa to Pa.
--------------------------------------------------------------------------------
package SI_Units.Metric.Scaling is
pragma Warnings (Off, "declaration hides ""Prefixes"""); -- intentional
type Prefixes is (yocto, zepto, atto, femto, pico, nano, micro, milli,
centi, deci,
None,
Deka, Hecto,
kilo, Mega, Giga, Tera, Peta, Exa, Zetta, Yotta) with
Size => Integer'Size;
pragma Warnings (On, "declaration hides ""Prefixes""");
for Prefixes use (yocto => -24,
zepto => -21,
atto => -18,
femto => -15,
pico => -12,
nano => -9,
micro => -6,
milli => -3,
centi => -2,
deci => -1,
None => 0,
Deka => 1,
Hecto => 2,
kilo => 3,
Mega => 6,
Giga => 9,
Tera => 12,
Peta => 15,
Exa => 18,
Zetta => 21,
Yotta => 24);
generic
type Item is delta <>;
function Fixed_Scale (Value : Item;
From_Prefix : Prefixes;
To_Prefix : Prefixes := None) return Item;
generic
type Item is digits <>;
function Float_Scale (Value : Item;
From_Prefix : Prefixes;
To_Prefix : Prefixes := None) return Item;
end SI_Units.Metric.Scaling;
|
reznikmm/matreshka | Ada | 6,820 | 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.Sequence_Elements is
------------
-- Create --
------------
overriding function Create
(Parameters : not null access Matreshka.DOM_Elements.Element_L2_Parameters)
return Text_Sequence_Element_Node is
begin
return Self : Text_Sequence_Element_Node do
Matreshka.ODF_Text.Constructors.Initialize
(Self'Unchecked_Access,
Parameters.Document,
Matreshka.ODF_String_Constants.Text_Prefix);
end return;
end Create;
----------------
-- Enter_Node --
----------------
overriding procedure Enter_Node
(Self : not null access Text_Sequence_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_Text_Sequence
(ODF.DOM.Text_Sequence_Elements.ODF_Text_Sequence_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 Text_Sequence_Element_Node)
return League.Strings.Universal_String
is
pragma Unreferenced (Self);
begin
return Matreshka.ODF_String_Constants.Sequence_Element;
end Get_Local_Name;
----------------
-- Leave_Node --
----------------
overriding procedure Leave_Node
(Self : not null access Text_Sequence_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_Text_Sequence
(ODF.DOM.Text_Sequence_Elements.ODF_Text_Sequence_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 Text_Sequence_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_Text_Sequence
(Visitor,
ODF.DOM.Text_Sequence_Elements.ODF_Text_Sequence_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.Text_URI,
Matreshka.ODF_String_Constants.Sequence_Element,
Text_Sequence_Element_Node'Tag);
end Matreshka.ODF_Text.Sequence_Elements;
|
persan/A-gst | Ada | 21,683 | ads | pragma Ada_2005;
pragma Style_Checks (Off);
pragma Warnings (Off);
with Interfaces.C; use Interfaces.C;
with glib;
with glib.Values;
with System;
with System;
with glib;
with GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstformat_h;
with GLIB; -- with GStreamer.GST_Low_Level.glibconfig_h;
-- limited with GStreamer.GST_Low_Level.glib_2_0_glib_glist_h;
with GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstobject_h;
package GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstindex_h is
-- unsupported macro: GST_TYPE_INDEX (gst_index_get_type ())
-- arg-macro: function GST_INDEX (obj)
-- return G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_INDEX, GstIndex);
-- arg-macro: function GST_IS_INDEX (obj)
-- return G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_INDEX);
-- arg-macro: function GST_INDEX_CLASS (klass)
-- return G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_INDEX, GstIndexClass);
-- arg-macro: function GST_IS_INDEX_CLASS (klass)
-- return G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_INDEX);
-- arg-macro: function GST_INDEX_GET_CLASS (obj)
-- return G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_INDEX, GstIndexClass);
-- unsupported macro: GST_TYPE_INDEX_ENTRY (gst_index_entry_get_type())
-- arg-macro: function GST_INDEX_NASSOCS (entry)
-- return (entry).data.assoc.nassocs;
-- arg-macro: function GST_INDEX_ASSOC_FLAGS (entry)
-- return (entry).data.assoc.flags;
-- arg-macro: function GST_INDEX_ASSOC_FORMAT (entry, i)
-- return (entry).data.assoc.assocs((i)).format;
-- arg-macro: function GST_INDEX_ASSOC_VALUE (entry, i)
-- return (entry).data.assoc.assocs((i)).value;
-- arg-macro: function GST_INDEX_FORMAT_FORMAT (entry)
-- return (entry).data.format.format;
-- arg-macro: function GST_INDEX_FORMAT_KEY (entry)
-- return (entry).data.format.key;
GST_INDEX_ID_INVALID : constant := (-1); -- gst/gstindex.h:180
-- arg-macro: function GST_INDEX_ID_DESCRIPTION (entry)
-- return (entry).data.id.description;
-- arg-macro: function GST_INDEX_IS_READABLE (obj)
-- return GST_OBJECT_FLAG_IS_SET (obj, GST_INDEX_READABLE);
-- arg-macro: function GST_INDEX_IS_WRITABLE (obj)
-- return GST_OBJECT_FLAG_IS_SET (obj, GST_INDEX_WRITABLE);
-- GStreamer
-- * Copyright (C) 1999,2000 Erik Walthinsen <[email protected]>
-- * 2000 Wim Taymans <[email protected]>
-- *
-- * gstindex.h: Header for GstIndex, base class to handle efficient
-- * storage or caching of seeking information.
-- *
-- * This library is free software; you can redistribute it and/or
-- * modify it under the terms of the GNU Library General Public
-- * License as published by the Free Software Foundation; either
-- * version 2 of the License, or (at your option) any later version.
-- *
-- * This library is distributed in the hope that it will be useful,
-- * but WITHOUT ANY WARRANTY; without even the implied warranty of
-- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-- * Library General Public License for more details.
-- *
-- * You should have received a copy of the GNU Library General Public
-- * License along with this library; if not, write to the
-- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-- * Boston, MA 02111-1307, USA.
--
-- new flags should start here
subtype GstAssocFlags is unsigned;
GST_ASSOCIATION_FLAG_NONE : constant GstAssocFlags := 0;
GST_ASSOCIATION_FLAG_KEY_UNIT : constant GstAssocFlags := 1;
GST_ASSOCIATION_FLAG_DELTA_UNIT : constant GstAssocFlags := 2;
GST_ASSOCIATION_FLAG_LAST : constant GstAssocFlags := 256; -- gst/gstindex.h:157
type GstIndexEntry;
type anon_222;
type anon_223 is record
description : access GLIB.gchar; -- gst/gstindex.h:202
end record;
pragma Convention (C_Pass_By_Copy, anon_223);
type anon_224 is record
nassocs : aliased GLIB.gint; -- gst/gstindex.h:205
assocs : System.Address; -- gst/gstindex.h:207
flags : aliased GstAssocFlags; -- gst/gstindex.h:208
end record;
pragma Convention (C_Pass_By_Copy, anon_224);
type anon_225 is record
key : access GLIB.gchar; -- gst/gstindex.h:211
c_type : aliased GLIB.GType; -- gst/gstindex.h:212
object : System.Address; -- gst/gstindex.h:213
end record;
pragma Convention (C_Pass_By_Copy, anon_225);
type anon_226 is record
format : aliased GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstformat_h.GstFormat; -- gst/gstindex.h:216
key : access GLIB.gchar; -- gst/gstindex.h:217
end record;
pragma Convention (C_Pass_By_Copy, anon_226);
type anon_222 (discr : unsigned := 0) is record
case discr is
when 0 =>
id : aliased anon_223; -- gst/gstindex.h:203
when 1 =>
assoc : aliased anon_224; -- gst/gstindex.h:209
when 2 =>
object : aliased anon_225; -- gst/gstindex.h:214
when others =>
format : aliased anon_226; -- gst/gstindex.h:218
end case;
end record;
pragma Convention (C_Pass_By_Copy, anon_222);
pragma Unchecked_Union (anon_222);--subtype GstIndexEntry is u_GstIndexEntry; -- gst/gstindex.h:42
type GstIndexGroup;
--subtype GstIndexGroup is u_GstIndexGroup; -- gst/gstindex.h:43
type GstIndex;
type u_GstIndex_u_gst_reserved_array is array (0 .. 2) of System.Address;
--subtype GstIndex is u_GstIndex; -- gst/gstindex.h:44
type GstIndexClass;
type u_GstIndexClass_u_gst_reserved_array is array (0 .. 3) of System.Address;
--subtype GstIndexClass is u_GstIndexClass; -- gst/gstindex.h:45
--*
-- * GstIndexCertainty:
-- * @GST_INDEX_UNKNOWN: accuracy is not known
-- * @GST_INDEX_CERTAIN: accuracy is perfect
-- * @GST_INDEX_FUZZY: accuracy is fuzzy
-- *
-- * The certainty of a group in the index.
--
type GstIndexCertainty is
(GST_INDEX_UNKNOWN,
GST_INDEX_CERTAIN,
GST_INDEX_FUZZY);
pragma Convention (C, GstIndexCertainty); -- gst/gstindex.h:59
--*
-- * GstIndexEntryType:
-- * @GST_INDEX_ENTRY_ID: This entry is an id that maps an index id to its owner object
-- * @GST_INDEX_ENTRY_ASSOCIATION: This entry is an association between formats
-- * @GST_INDEX_ENTRY_OBJECT: An object
-- * @GST_INDEX_ENTRY_FORMAT: A format definition
-- *
-- * The different types of entries in the index.
--
type GstIndexEntryType is
(GST_INDEX_ENTRY_ID,
GST_INDEX_ENTRY_ASSOCIATION,
GST_INDEX_ENTRY_OBJECT,
GST_INDEX_ENTRY_FORMAT);
pragma Convention (C, GstIndexEntryType); -- gst/gstindex.h:75
--*
-- * GstIndexLookupMethod:
-- * @GST_INDEX_LOOKUP_EXACT: There has to be an exact indexentry with the given format/value
-- * @GST_INDEX_LOOKUP_BEFORE: The exact entry or the one before it
-- * @GST_INDEX_LOOKUP_AFTER: The exact entry or the one after it
-- *
-- * Specify the method to find an index entry in the index.
--
type GstIndexLookupMethod is
(GST_INDEX_LOOKUP_EXACT,
GST_INDEX_LOOKUP_BEFORE,
GST_INDEX_LOOKUP_AFTER);
pragma Convention (C, GstIndexLookupMethod); -- gst/gstindex.h:89
--*
-- * GST_INDEX_NASSOCS:
-- * @entry: The entry to query
-- *
-- * Get the number of associations in the entry.
--
--*
-- * GST_INDEX_ASSOC_FLAGS:
-- * @entry: The entry to query
-- *
-- * Get the flags for this entry.
--
--*
-- * GST_INDEX_ASSOC_FORMAT:
-- * @entry: The entry to query
-- * @i: The format index
-- *
-- * Get the i-th format of the entry.
--
--*
-- * GST_INDEX_ASSOC_VALUE:
-- * @entry: The entry to query
-- * @i: The value index
-- *
-- * Get the i-th value of the entry.
--
type GstIndexAssociation;
--subtype GstIndexAssociation is u_GstIndexAssociation; -- gst/gstindex.h:125
--*
-- * GstIndexAssociation:
-- * @format: the format of the association
-- * @value: the value of the association
-- *
-- * An association in an entry.
--
type GstIndexAssociation is record
format : aliased GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstformat_h.GstFormat; -- gst/gstindex.h:135
value : aliased GLIB.gint64; -- gst/gstindex.h:136
end record;
pragma Convention (C_Pass_By_Copy, GstIndexAssociation); -- gst/gstindex.h:134
--*
-- * GstAssocFlags:
-- * @GST_ASSOCIATION_FLAG_NONE: no extra flags
-- * @GST_ASSOCIATION_FLAG_KEY_UNIT: the entry marks a key unit, a key unit is one
-- * that marks a place where one can randomly seek to.
-- * @GST_ASSOCIATION_FLAG_DELTA_UNIT: the entry marks a delta unit, a delta unit
-- * is one that marks a place where one can relatively seek to.
-- * @GST_ASSOCIATION_FLAG_LAST: extra user defined flags should start here.
-- *
-- * Flags for an association entry.
--
--*
-- * GST_INDEX_FORMAT_FORMAT:
-- * @entry: The entry to query
-- *
-- * Get the format of the format entry
--
--*
-- * GST_INDEX_FORMAT_KEY:
-- * @entry: The entry to query
-- *
-- * Get the key of the format entry
--
--*
-- * GST_INDEX_ID_INVALID:
-- *
-- * Constant for an invalid index id
--
--*
-- * GST_INDEX_ID_DESCRIPTION:
-- * @entry: The entry to query
-- *
-- * Get the description of the id entry
--
--*
-- * GstIndexEntry:
-- *
-- * The basic element of an index.
--
--< private >
type GstIndexEntry is record
c_type : aliased GstIndexEntryType; -- gst/gstindex.h:197
id : aliased GLIB.gint; -- gst/gstindex.h:198
data : aliased anon_222; -- gst/gstindex.h:219
end record;
pragma Convention (C_Pass_By_Copy, GstIndexEntry); -- gst/gstindex.h:195
--*
-- * GstIndexGroup:
-- *
-- * A group of related entries in an index.
--
--< private >
-- unique ID of group in index
type GstIndexGroup is record
groupnum : aliased GLIB.gint; -- gst/gstindex.h:231
entries : access GStreamer.GST_Low_Level.glib_2_0_glib_glist_h.GList; -- gst/gstindex.h:234
certainty : aliased GstIndexCertainty; -- gst/gstindex.h:237
peergroup : aliased GLIB.gint; -- gst/gstindex.h:240
end record;
pragma Convention (C_Pass_By_Copy, GstIndexGroup); -- gst/gstindex.h:228
-- list of entries
-- the certainty level of the group
-- peer group that contains more certain entries
--*
-- * GstIndexFilter:
-- * @index: The index being queried
-- * @entry: The entry to be added.
-- * @user_data: User data passed to the function.
-- *
-- * Function to filter out entries in the index.
-- *
-- * Returns: This function should return %TRUE if the entry is to be added
-- * to the index, %FALSE otherwise.
-- *
--
type GstIndexFilter is access function
(arg1 : access GstIndex;
arg2 : access GstIndexEntry;
arg3 : System.Address) return GLIB.gboolean;
pragma Convention (C, GstIndexFilter); -- gst/gstindex.h:255
--*
-- * GstIndexResolverMethod:
-- * @GST_INDEX_RESOLVER_CUSTOM: Use a custom resolver
-- * @GST_INDEX_RESOLVER_GTYPE: Resolve based on the GType of the object
-- * @GST_INDEX_RESOLVER_PATH: Resolve on the path in graph
-- *
-- * The method used to resolve index writers
--
type GstIndexResolverMethod is
(GST_INDEX_RESOLVER_CUSTOM,
GST_INDEX_RESOLVER_GTYPE,
GST_INDEX_RESOLVER_PATH);
pragma Convention (C, GstIndexResolverMethod); -- gst/gstindex.h:270
--*
-- * GstIndexResolver:
-- * @index: the index being queried.
-- * @writer: The object that wants to write
-- * @writer_string: A description of the writer.
-- * @user_data: user_data as registered
-- *
-- * Function to resolve ids to writer descriptions.
-- *
-- * Returns: %TRUE if an id could be assigned to the writer.
--
type GstIndexResolver is access function
(arg1 : access GstIndex;
arg2 : access GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstobject_h.GstObject;
arg3 : System.Address;
arg4 : System.Address) return GLIB.gboolean;
pragma Convention (C, GstIndexResolver); -- gst/gstindex.h:283
--*
-- * GstIndexFlags:
-- * @GST_INDEX_WRITABLE: The index is writable
-- * @GST_INDEX_READABLE: The index is readable
-- * @GST_INDEX_FLAG_LAST: First flag that can be used by subclasses
-- *
-- * Flags for this index
--
subtype GstIndexFlags is unsigned;
GST_INDEX_WRITABLE : constant GstIndexFlags := 16;
GST_INDEX_READABLE : constant GstIndexFlags := 32;
GST_INDEX_FLAG_LAST : constant GstIndexFlags := 4096; -- gst/gstindex.h:301
--*
-- * GST_INDEX_IS_READABLE:
-- * @obj: The index to check
-- *
-- * Check if the index can be read from
--
--*
-- * GST_INDEX_IS_WRITABLE:
-- * @obj: The index to check
-- *
-- * Check if the index can be written to
--
--*
-- * GstIndex:
-- *
-- * Opaque #GstIndex structure.
--
type GstIndex is record
object : aliased GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstobject_h.GstObject; -- gst/gstindex.h:325
groups : access GStreamer.GST_Low_Level.glib_2_0_glib_glist_h.GList; -- gst/gstindex.h:328
curgroup : access GstIndexGroup; -- gst/gstindex.h:329
maxgroup : aliased GLIB.gint; -- gst/gstindex.h:330
method : aliased GstIndexResolverMethod; -- gst/gstindex.h:332
resolver : GstIndexResolver; -- gst/gstindex.h:333
resolver_user_data : System.Address; -- gst/gstindex.h:334
filter : GstIndexFilter; -- gst/gstindex.h:336
filter_user_data : System.Address; -- gst/gstindex.h:337
filter_user_data_destroy : GStreamer.GST_Low_Level.glib_2_0_glib_gtypes_h.GDestroyNotify; -- gst/gstindex.h:338
writers : System.Address; -- gst/gstindex.h:340
last_id : aliased GLIB.gint; -- gst/gstindex.h:341
resolver_user_data_destroy : GStreamer.GST_Low_Level.glib_2_0_glib_gtypes_h.GDestroyNotify; -- gst/gstindex.h:344
u_gst_reserved : u_GstIndex_u_gst_reserved_array; -- gst/gstindex.h:347
end record;
pragma Convention (C_Pass_By_Copy, GstIndex); -- gst/gstindex.h:324
--< private >
-- ABI added since 0.10.18
--< private >
type GstIndexClass is record
parent_class : aliased GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstobject_h.GstObjectClass; -- gst/gstindex.h:351
get_writer_id : access function
(arg1 : access GstIndex;
arg2 : access GLIB.gint;
arg3 : access GLIB.gchar) return GLIB.gboolean; -- gst/gstindex.h:354
commit : access procedure (arg1 : access GstIndex; arg2 : GLIB.gint); -- gst/gstindex.h:356
add_entry : access procedure (arg1 : access GstIndex; arg2 : access GstIndexEntry); -- gst/gstindex.h:359
get_assoc_entry : access function
(arg1 : access GstIndex;
arg2 : GLIB.gint;
arg3 : GstIndexLookupMethod;
arg4 : GstAssocFlags;
arg5 : GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstformat_h.GstFormat;
arg6 : GLIB.gint64;
arg7 : GStreamer.GST_Low_Level.glib_2_0_glib_gtypes_h.GCompareDataFunc;
arg8 : System.Address) return access GstIndexEntry; -- gst/gstindex.h:365
entry_added : access procedure (arg1 : access GstIndex; arg2 : access GstIndexEntry); -- gst/gstindex.h:367
u_gst_reserved : u_GstIndexClass_u_gst_reserved_array; -- gst/gstindex.h:370
end record;
pragma Convention (C_Pass_By_Copy, GstIndexClass); -- gst/gstindex.h:350
--< protected >
-- abstract methods
-- signals
--< private >
function gst_index_get_type return GLIB.GType; -- gst/gstindex.h:373
pragma Import (C, gst_index_get_type, "gst_index_get_type");
function gst_index_new return access GstIndex; -- gst/gstindex.h:374
pragma Import (C, gst_index_new, "gst_index_new");
procedure gst_index_commit (index : access GstIndex; id : GLIB.gint); -- gst/gstindex.h:375
pragma Import (C, gst_index_commit, "gst_index_commit");
function gst_index_get_group (index : access GstIndex) return GLIB.gint; -- gst/gstindex.h:377
pragma Import (C, gst_index_get_group, "gst_index_get_group");
function gst_index_new_group (index : access GstIndex) return GLIB.gint; -- gst/gstindex.h:378
pragma Import (C, gst_index_new_group, "gst_index_new_group");
function gst_index_set_group (index : access GstIndex; groupnum : GLIB.gint) return GLIB.gboolean; -- gst/gstindex.h:379
pragma Import (C, gst_index_set_group, "gst_index_set_group");
procedure gst_index_set_certainty (index : access GstIndex; certainty : GstIndexCertainty); -- gst/gstindex.h:381
pragma Import (C, gst_index_set_certainty, "gst_index_set_certainty");
function gst_index_get_certainty (index : access GstIndex) return GstIndexCertainty; -- gst/gstindex.h:383
pragma Import (C, gst_index_get_certainty, "gst_index_get_certainty");
procedure gst_index_set_filter
(index : access GstIndex;
filter : GstIndexFilter;
user_data : System.Address); -- gst/gstindex.h:385
pragma Import (C, gst_index_set_filter, "gst_index_set_filter");
procedure gst_index_set_filter_full
(index : access GstIndex;
filter : GstIndexFilter;
user_data : System.Address;
user_data_destroy : GStreamer.GST_Low_Level.glib_2_0_glib_gtypes_h.GDestroyNotify); -- gst/gstindex.h:387
pragma Import (C, gst_index_set_filter_full, "gst_index_set_filter_full");
procedure gst_index_set_resolver
(index : access GstIndex;
resolver : GstIndexResolver;
user_data : System.Address); -- gst/gstindex.h:390
pragma Import (C, gst_index_set_resolver, "gst_index_set_resolver");
procedure gst_index_set_resolver_full
(index : access GstIndex;
resolver : GstIndexResolver;
user_data : System.Address;
user_data_destroy : GStreamer.GST_Low_Level.glib_2_0_glib_gtypes_h.GDestroyNotify); -- gst/gstindex.h:392
pragma Import (C, gst_index_set_resolver_full, "gst_index_set_resolver_full");
function gst_index_get_writer_id
(index : access GstIndex;
writer : access GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstobject_h.GstObject;
id : access GLIB.gint) return GLIB.gboolean; -- gst/gstindex.h:396
pragma Import (C, gst_index_get_writer_id, "gst_index_get_writer_id");
function gst_index_add_format
(index : access GstIndex;
id : GLIB.gint;
format : GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstformat_h.GstFormat) return access GstIndexEntry; -- gst/gstindex.h:398
pragma Import (C, gst_index_add_format, "gst_index_add_format");
function gst_index_add_associationv
(index : access GstIndex;
id : GLIB.gint;
flags : GstAssocFlags;
n : GLIB.gint;
list : access constant GstIndexAssociation) return access GstIndexEntry; -- gst/gstindex.h:399
pragma Import (C, gst_index_add_associationv, "gst_index_add_associationv");
function gst_index_add_association
(index : access GstIndex;
id : GLIB.gint;
flags : GstAssocFlags;
format : GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstformat_h.GstFormat;
value : GLIB.gint64 -- , ...
) return access GstIndexEntry; -- gst/gstindex.h:401
pragma Import (C, gst_index_add_association, "gst_index_add_association");
function gst_index_add_object
(index : access GstIndex;
id : GLIB.gint;
key : access GLIB.gchar;
c_type : GLIB.GType;
object : System.Address) return access GstIndexEntry; -- gst/gstindex.h:403
pragma Import (C, gst_index_add_object, "gst_index_add_object");
function gst_index_add_id
(index : access GstIndex;
id : GLIB.gint;
description : access GLIB.gchar) return access GstIndexEntry; -- gst/gstindex.h:405
pragma Import (C, gst_index_add_id, "gst_index_add_id");
function gst_index_get_assoc_entry
(index : access GstIndex;
id : GLIB.gint;
method : GstIndexLookupMethod;
flags : GstAssocFlags;
format : GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstformat_h.GstFormat;
value : GLIB.gint64) return access GstIndexEntry; -- gst/gstindex.h:408
pragma Import (C, gst_index_get_assoc_entry, "gst_index_get_assoc_entry");
function gst_index_get_assoc_entry_full
(index : access GstIndex;
id : GLIB.gint;
method : GstIndexLookupMethod;
flags : GstAssocFlags;
format : GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstformat_h.GstFormat;
value : GLIB.gint64;
func : GStreamer.GST_Low_Level.glib_2_0_glib_gtypes_h.GCompareDataFunc;
user_data : System.Address) return access GstIndexEntry; -- gst/gstindex.h:411
pragma Import (C, gst_index_get_assoc_entry_full, "gst_index_get_assoc_entry_full");
-- working with index entries
function gst_index_entry_get_type return GLIB.GType; -- gst/gstindex.h:418
pragma Import (C, gst_index_entry_get_type, "gst_index_entry_get_type");
function gst_index_entry_copy (c_entry : access GstIndexEntry) return access GstIndexEntry; -- gst/gstindex.h:419
pragma Import (C, gst_index_entry_copy, "gst_index_entry_copy");
procedure gst_index_entry_free (c_entry : access GstIndexEntry); -- gst/gstindex.h:420
pragma Import (C, gst_index_entry_free, "gst_index_entry_free");
function gst_index_entry_assoc_map
(c_entry : access GstIndexEntry;
format : GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstformat_h.GstFormat;
value : access GLIB.gint64) return GLIB.gboolean; -- gst/gstindex.h:421
pragma Import (C, gst_index_entry_assoc_map, "gst_index_entry_assoc_map");
end GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstindex_h;
|
Kidev/Ada_Drivers_Library | Ada | 6,172 | ads | ------------------------------------------------------------------------------
-- --
-- Copyright (C) 2015-2017, AdaCore --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions are --
-- met: --
-- 1. Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- 2. Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in --
-- the documentation and/or other materials provided with the --
-- distribution. --
-- 3. Neither the name of the copyright holder nor the names of its --
-- contributors may be used to endorse or promote products derived --
-- from this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT --
-- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, --
-- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY --
-- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT --
-- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE --
-- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
with HAL; use HAL;
with HAL.Bitmap; use HAL.Bitmap;
with Soft_Drawing_Bitmap; use Soft_Drawing_Bitmap;
with System;
package Memory_Mapped_Bitmap is
subtype Parent is Soft_Drawing_Bitmap_Buffer;
type Memory_Mapped_Bitmap_Buffer is new Parent with record
Addr : System.Address;
Actual_Width : Natural;
Actual_Height : Natural;
-- Width and Height of the buffer. Note that it's the user-visible width
-- (see below for the meaning of the Swapped value).
Actual_Color_Mode : Bitmap_Color_Mode;
-- The buffer color mode. Note that not all color modes are supported by
-- the hardware acceleration (if any), so you need to check your actual
-- hardware to optimize buffer transfers.
Currently_Swapped : Boolean := False;
-- If Swap is set, then operations on this buffer will consider:
-- Width0 = Height
-- Height0 = Width
-- Y0 = Buffer.Width - X - 1
-- X0 = Y
--
-- As an example, the Bitmap buffer that corresponds to a 240x320
-- swapped display (to display images in landscape mode) with have
-- the following values:
-- Width => 320
-- Height => 240
-- Swapped => True
-- So Put_Pixel (Buffer, 30, 10, Color) will place the pixel at
-- Y0 = 320 - 30 - 1 = 289
-- X0 = 10
Native_Source : UInt32 := 0;
-- Source color in native format
end record;
type Any_Memory_Mapped_Bitmap_Buffer is access all Memory_Mapped_Bitmap_Buffer'Class;
overriding
function Width (Buffer : Memory_Mapped_Bitmap_Buffer) return Natural is
(if Buffer.Currently_Swapped then Buffer.Actual_Height else Buffer.Actual_Width);
overriding
function Height (Buffer : Memory_Mapped_Bitmap_Buffer) return Natural is
(if Buffer.Currently_Swapped then Buffer.Actual_Width else Buffer.Actual_Height);
overriding
function Swapped (Buffer : Memory_Mapped_Bitmap_Buffer) return Boolean is
(Buffer.Currently_Swapped);
overriding
function Color_Mode (Buffer : Memory_Mapped_Bitmap_Buffer) return Bitmap_Color_Mode is
(Buffer.Actual_Color_Mode);
overriding
function Mapped_In_RAM (Buffer : Memory_Mapped_Bitmap_Buffer) return Boolean is
(True);
overriding
function Memory_Address (Buffer : Memory_Mapped_Bitmap_Buffer) return System.Address is
(Buffer.Addr);
overriding
procedure Set_Source (Buffer : in out Memory_Mapped_Bitmap_Buffer;
ARGB : Bitmap_Color);
overriding
procedure Set_Source (Buffer : in out Memory_Mapped_Bitmap_Buffer;
Native : UInt32);
overriding
function Source (Buffer : Memory_Mapped_Bitmap_Buffer)
return Bitmap_Color;
overriding
function Source (Buffer : Memory_Mapped_Bitmap_Buffer)
return UInt32;
overriding
procedure Set_Pixel
(Buffer : in out Memory_Mapped_Bitmap_Buffer;
Pt : Point);
overriding
procedure Set_Pixel
(Buffer : in out Memory_Mapped_Bitmap_Buffer;
Pt : Point;
Color : Bitmap_Color);
overriding
procedure Set_Pixel
(Buffer : in out Memory_Mapped_Bitmap_Buffer;
Pt : Point;
Raw : UInt32);
overriding
procedure Set_Pixel_Blend
(Buffer : in out Memory_Mapped_Bitmap_Buffer;
Pt : Point);
overriding
function Pixel
(Buffer : Memory_Mapped_Bitmap_Buffer;
Pt : Point)
return Bitmap_Color;
overriding
function Pixel
(Buffer : Memory_Mapped_Bitmap_Buffer;
Pt : Point)
return UInt32;
overriding
function Buffer_Size (Buffer : Memory_Mapped_Bitmap_Buffer) return Natural;
end Memory_Mapped_Bitmap;
|
reznikmm/matreshka | Ada | 3,749 | 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;
package body Matreshka.ODF_Attributes.Style.Family is
--------------------
-- Get_Local_Name --
--------------------
overriding function Get_Local_Name
(Self : not null access constant Style_Family_Node)
return League.Strings.Universal_String is
begin
return ODF.Constants.Family_Name;
end Get_Local_Name;
end Matreshka.ODF_Attributes.Style.Family;
|
jhumphry/Ada_BinToAsc | Ada | 3,662 | ads | -- BinToAsc.Base64
-- Binary data to ASCII codecs - Base64 codec as in RFC4648
-- Copyright (c) 2015, James Humphry - see LICENSE file for details
generic
Alphabet : Alphabet_64;
Padding : Character;
package BinToAsc.Base64 is
type Base64_To_String is new Codec_To_String with private;
overriding
procedure Reset (C : out Base64_To_String);
overriding
function Input_Group_Size (C : in Base64_To_String) return Positive is (3);
overriding
function Output_Group_Size (C : in Base64_To_String) return Positive is (4);
overriding
procedure Process (C : in out Base64_To_String;
Input : in Bin;
Output : out String;
Output_Length : out Natural)
with Post => (Output_Length = 0 or Output_Length = 4);
overriding
procedure Process (C : in out Base64_To_String;
Input : in Bin_Array;
Output : out String;
Output_Length : out Natural)
with Post => (Output_Length / 4 = Input'Length / 3 or
Output_Length / 4 = Input'Length / 3 + 1);
overriding
procedure Complete (C : in out Base64_To_String;
Output : out String;
Output_Length : out Natural)
with Post => (Output_Length = 0 or Output_Length = 4);
function To_String (Input : in Bin_Array) return String;
type Base64_To_Bin is new Codec_To_Bin with private;
overriding
procedure Reset (C : out Base64_To_Bin);
overriding
function Input_Group_Size (C : in Base64_To_Bin) return Positive is (4);
overriding
function Output_Group_Size (C : in Base64_To_Bin) return Positive is (3);
overriding
procedure Process (C : in out Base64_To_Bin;
Input : in Character;
Output : out Bin_Array;
Output_Length : out Bin_Array_Index)
with Post => (Output_Length >= 0 and Output_Length <= 3);
overriding
procedure Process (C : in out Base64_To_Bin;
Input : in String;
Output : out Bin_Array;
Output_Length : out Bin_Array_Index)
with Post => ((Output_Length / 3 >= Input'Length / 4 - 1 and
Output_Length / 3 <= Input'Length / 4 + 1) or
C.State = Failed);
-- Re: the postcondition. If the input is a given number four character
-- groups but with the last containing padding, the output may be less than
-- that number of three character groups. As usual, if the codec contained
-- some partially decoded data, the number of output groups can be one more
-- than otherwise expected.
overriding
procedure Complete (C : in out Base64_To_Bin;
Output : out Bin_Array;
Output_Length : out Bin_Array_Index)
with Post => (Output_Length = 0);
function To_Bin (Input : in String) return Bin_Array;
private
type Base64_Bin_Index is range 0..2;
type Base64_Bin_Buffer is array (Base64_Bin_Index) of Bin;
type Base64_To_String is new Codec_To_String with
record
Next_Index : Base64_Bin_Index := 0;
Buffer : Base64_Bin_Buffer := (others => 0);
end record;
type Base64_Reverse_Index is range 0..3;
type Base64_Reverse_Buffer is array (Base64_Reverse_Index) of Bin;
type Base64_To_Bin is new Codec_To_Bin with
record
Next_Index : Base64_Reverse_Index := 0;
Buffer : Base64_Reverse_Buffer := (others => 0);
Padding_Length : Bin_Array_Index := 0;
end record;
end BinToAsc.Base64;
|
charlie5/cBound | Ada | 1,617 | 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_glx_new_list_request_t is
-- Item
--
type Item is record
major_opcode : aliased Interfaces.Unsigned_8;
minor_opcode : aliased Interfaces.Unsigned_8;
length : aliased Interfaces.Unsigned_16;
context_tag : aliased xcb.xcb_glx_context_tag_t;
list : aliased Interfaces.Unsigned_32;
mode : aliased Interfaces.Unsigned_32;
end record;
-- Item_Array
--
type Item_Array is
array
(Interfaces.C.size_t range <>) of aliased xcb.xcb_glx_new_list_request_t
.Item;
-- Pointer
--
package C_Pointers is new Interfaces.C.Pointers
(Index => Interfaces.C.size_t,
Element => xcb.xcb_glx_new_list_request_t.Item,
Element_Array => xcb.xcb_glx_new_list_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_glx_new_list_request_t
.Pointer;
-- Pointer_Pointer
--
package C_Pointer_Pointers is new Interfaces.C.Pointers
(Index => Interfaces.C.size_t,
Element => xcb.xcb_glx_new_list_request_t.Pointer,
Element_Array => xcb.xcb_glx_new_list_request_t.Pointer_Array,
Default_Terminator => null);
subtype Pointer_Pointer is C_Pointer_Pointers.Pointer;
end xcb.xcb_glx_new_list_request_t;
|
dilawar/ahir | Ada | 2,676 | ads | -- This file is generated by SWIG. Do *not* modify by hand.
--
with Interfaces.C.Extensions;
package LLVM_execution_Engine is
-- LLVMOpaqueGenericValue
--
type LLVMOpaqueGenericValue is new
Interfaces.C.Extensions.opaque_structure_def;
type LLVMOpaqueGenericValue_array is
array (Interfaces.C.size_t range <>)
of aliased LLVM_execution_Engine.LLVMOpaqueGenericValue;
type LLVMOpaqueGenericValue_view is access all
LLVM_execution_Engine.LLVMOpaqueGenericValue;
-- LLVMGenericValueRef
--
type LLVMGenericValueRef is access all
LLVM_execution_Engine.LLVMOpaqueGenericValue;
type LLVMGenericValueRef_array is
array (Interfaces.C.size_t range <>)
of aliased LLVM_execution_Engine.LLVMGenericValueRef;
type LLVMGenericValueRef_view is access all
LLVM_execution_Engine.LLVMGenericValueRef;
-- LLVMOpaqueExecutionEngine
--
type LLVMOpaqueExecutionEngine is new
Interfaces.C.Extensions.opaque_structure_def;
type LLVMOpaqueExecutionEngine_array is
array (Interfaces.C.size_t range <>)
of aliased LLVM_execution_Engine.LLVMOpaqueExecutionEngine;
type LLVMOpaqueExecutionEngine_view is access all
LLVM_execution_Engine.LLVMOpaqueExecutionEngine;
-- LLVMExecutionEngineRef
--
type LLVMExecutionEngineRef is access all
LLVM_execution_Engine.LLVMOpaqueExecutionEngine;
type LLVMExecutionEngineRef_array is
array (Interfaces.C.size_t range <>)
of aliased LLVM_execution_Engine.LLVMExecutionEngineRef;
type LLVMExecutionEngineRef_view is access all
LLVM_execution_Engine.LLVMExecutionEngineRef;
-- LLVMTargetDataRef
--
type LLVMTargetDataRef is new Interfaces.C.Extensions.opaque_structure_def;
type LLVMTargetDataRef_array is
array (Interfaces.C.size_t range <>)
of aliased LLVM_execution_Engine.LLVMTargetDataRef;
type LLVMTargetDataRef_view is access all
LLVM_execution_Engine.LLVMTargetDataRef;
-- GenericValue
--
type GenericValue is new Interfaces.C.Extensions.opaque_structure_def;
type GenericValue_array is
array (Interfaces.C.size_t range <>)
of aliased LLVM_execution_Engine.GenericValue;
type GenericValue_view is access all LLVM_execution_Engine.GenericValue;
-- ExecutionEngine
--
type ExecutionEngine is new Interfaces.C.Extensions.incomplete_class_def;
type ExecutionEngine_array is
array (Interfaces.C.size_t range <>)
of aliased LLVM_execution_Engine.ExecutionEngine;
type ExecutionEngine_view is access all
LLVM_execution_Engine.ExecutionEngine;
end LLVM_execution_Engine;
|
charlie5/aIDE | Ada | 2,954 | adb | with
AdaM.Factory;
package body AdaM.a_Type.record_type
is
-- Storage Pool
--
record_Version : constant := 1;
pool_Size : constant := 5_000;
package Pool is new AdaM.Factory.Pools (storage_Folder => ".adam-store",
pool_Name => "record_types",
max_Items => pool_Size,
record_Version => record_Version,
Item => record_type.item,
View => record_type.view);
-- Forge
--
procedure define (Self : in out Item; Name : in String)
is
begin
Self.Name := +Name;
end define;
overriding
procedure destruct (Self : in out Item)
is
begin
null;
end destruct;
function new_Type (Name : in String := "") return record_type.View
is
new_View : constant record_type.view := Pool.new_Item;
begin
define (record_type.item (new_View.all), Name);
return new_View;
end new_Type;
procedure free (Self : in out record_type.view)
is
begin
destruct (a_Type.item (Self.all));
Pool.free (Self);
end free;
-- Attributes
--
overriding function Id (Self : access Item) return AdaM.Id
is
begin
return Pool.to_Id (Self);
end Id;
overriding
function to_Source (Self : in Item) return text_Vectors.Vector
is
pragma Unreferenced (Self);
the_Source : text_Vectors.Vector;
begin
raise Program_Error with "TODO";
return the_Source;
end to_Source;
function is_Abstract (Self : in Item) return Boolean
is
begin
return Self.is_Abstract;
end is_Abstract;
procedure is_Abstract (Self : out Item; Now : in Boolean := True)
is
begin
Self.is_Abstract := Now;
end is_Abstract;
function is_Tagged (Self : in Item) return Boolean
is
begin
return Self.is_Tagged;
end is_Tagged;
procedure is_Tagged (Self : out Item; Now : in Boolean := True)
is
begin
Self.is_Tagged := Now;
end is_Tagged;
function is_Limited (Self : in Item) return Boolean
is
begin
return Self.is_Limited;
end is_Limited;
procedure is_Limited (Self : out Item; Now : in Boolean := True)
is
begin
Self.is_Limited := Now;
end is_Limited;
----------
-- Streams
--
procedure View_write (Stream : not null access Ada.Streams.Root_Stream_Type'Class;
Self : in View)
renames Pool.View_write;
procedure View_read (Stream : not null access Ada.Streams.Root_Stream_Type'Class;
Self : out View)
renames Pool.View_read;
end AdaM.a_Type.record_type;
|
adammw/rtp_labs | Ada | 463 | adb | with Ada.Text_IO, Ada.Integer_Text_IO;
use Ada.Text_IO, Ada.Integer_Text_IO;
procedure Subprograms is
A, B, C, D : Integer;
procedure Max_Min (A, B: in Integer; C, D: out Integer) is
begin
if A > B then
C := A;
D := B;
else
C := B;
D := A;
end if;
end Max_Min;
begin
Put("A=");
Get(A); Skip_Line;
Put("B=");
Get(B); Skip_Line;
Max_Min(A, B, C, D);
Put_Line("C=" & C'Img & " D=" & D'Img);
end Subprograms;
|
reznikmm/matreshka | Ada | 3,779 | 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.Chart_Tick_Marks_Minor_Inner_Attributes is
pragma Preelaborate;
type ODF_Chart_Tick_Marks_Minor_Inner_Attribute is limited interface
and XML.DOM.Attributes.DOM_Attribute;
type ODF_Chart_Tick_Marks_Minor_Inner_Attribute_Access is
access all ODF_Chart_Tick_Marks_Minor_Inner_Attribute'Class
with Storage_Size => 0;
end ODF.DOM.Chart_Tick_Marks_Minor_Inner_Attributes;
|
reznikmm/matreshka | Ada | 18,590 | adb | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Localization, Internationalization, Globalization for Ada --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2010, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
with Ada.Containers.Vectors;
package body Matreshka.Internals.Regexps.Compiler.Generator is
use Matreshka.Internals.Regexps.Engine;
package Integer_Vectors is
new Ada.Containers.Vectors (Positive, Integer);
--------------
-- Generate --
--------------
function Generate
(Pattern : not null Shared_Pattern_Access) return Engine.Program
is
use Integer_Vectors;
Program : Instruction_Array (1 .. Pattern.Last * 9);
Last : Natural := 0;
procedure Compile
(Expression : Positive;
Instruction : out Positive;
Tails : out Vector);
procedure Connect_Tails (Tails : Vector; Instruction : Positive);
-------------
-- Compile --
-------------
procedure Compile
(Expression : Positive;
Instruction : out Positive;
Tails : out Vector)
is
procedure Compile_Next;
------------------
-- Compile_Next --
------------------
procedure Compile_Next is
begin
if Pattern.AST (Expression).Next /= 0 then
declare
Next_Instruction : Positive;
Previous_Tails : constant Vector := Tails;
begin
Compile
(Pattern.AST (Expression).Next, Next_Instruction, Tails);
Connect_Tails (Previous_Tails, Next_Instruction);
end;
end if;
end Compile_Next;
begin
case Pattern.AST (Expression).Kind is
when N_Alternation =>
Last := Last + 1;
Instruction := Last;
Tails.Clear;
declare
Ins_1 : Positive;
Ins_2 : Positive;
Tails_1 : Vector;
Tails_2 : Vector;
begin
Compile
(Get_Preferred (Pattern, Expression), Ins_1, Tails_1);
Compile (Get_Fallback (Pattern, Expression), Ins_2, Tails_2);
Program (Instruction) := (Split, Ins_1, Ins_2);
Tails := Tails_1 & Tails_2;
end;
when N_Match_Any =>
Last := Last + 1;
Instruction := Last;
Tails.Clear;
Program (Instruction) := (Any_Code_Point, 0);
Tails.Append (Instruction);
Compile_Next;
when N_Match_Code =>
Last := Last + 1;
Instruction := Last;
Tails.Clear;
Program (Instruction) :=
(Code_Point, 0, Pattern.AST (Expression).Code);
Tails.Append (Instruction);
Compile_Next;
when N_Match_Property =>
Last := Last + 1;
Instruction := Last;
Tails.Clear;
Program (Instruction) :=
(I_Property,
0,
Pattern.AST (Expression).Value,
Pattern.AST (Expression).Negative);
Tails.Append (Instruction);
Compile_Next;
when N_Member_Code =>
Last := Last + 1;
Instruction := Last;
if Pattern.AST (Expression).Next = 0 then
Program (Instruction) :=
(Code_Point, 0, Pattern.AST (Expression).Code);
Tails.Clear;
Tails.Append (Instruction);
else
declare
Ins_1 : Integer;
Ins_2 : Integer;
begin
Last := Last + 1;
Ins_1 := Last;
Compile (Pattern.AST (Expression).Next, Ins_2, Tails);
Program (Ins_1) :=
(Code_Point, 0, Pattern.AST (Expression).Code);
Tails.Append (Ins_1);
Program (Instruction) := (Split, Ins_1, Ins_2);
end;
end if;
when N_Member_Range =>
Last := Last + 1;
Instruction := Last;
if Pattern.AST (Expression).Next = 0 then
Program (Instruction) :=
(Code_Range,
0,
False,
Pattern.AST (Expression).Low,
Pattern.AST (Expression).High);
Tails.Clear;
Tails.Append (Instruction);
else
declare
Ins_1 : Integer;
Ins_2 : Integer;
begin
Last := Last + 1;
Ins_1 := Last;
Compile (Pattern.AST (Expression).Next, Ins_2, Tails);
Program (Ins_1) :=
(Code_Range,
0,
False,
Pattern.AST (Expression).Low,
Pattern.AST (Expression).High);
Tails.Append (Ins_1);
Program (Instruction) := (Split, Ins_1, Ins_2);
end;
end if;
when N_Member_Property =>
Last := Last + 1;
Instruction := Last;
if Pattern.AST (Expression).Next = 0 then
Program (Instruction) :=
(I_Property,
0,
Pattern.AST (Expression).Value,
Pattern.AST (Expression).Negative);
Tails.Clear;
Tails.Append (Instruction);
else
declare
Ins_1 : Integer;
Ins_2 : Integer;
begin
Last := Last + 1;
Ins_1 := Last;
Compile (Pattern.AST (Expression).Next, Ins_2, Tails);
Program (Ins_1) :=
(I_Property,
0,
Pattern.AST (Expression).Value,
Pattern.AST (Expression).Negative);
Tails.Append (Ins_1);
Program (Instruction) := (Split, Ins_1, Ins_2);
end;
end if;
when N_Character_Class =>
if not Pattern.AST (Expression).Negated then
Compile
(Get_Members (Pattern, Expression), Instruction, Tails);
else
declare
Ins_1 : Integer;
Ins_Terminate : Integer;
Ins_Any : Integer;
begin
Last := Last + 1;
Instruction := Last;
Tails.Clear;
Compile (Get_Members (Pattern, Expression), Ins_1, Tails);
Last := Last + 1;
Ins_Terminate := Last;
Last := Last + 1;
Ins_Any := Last;
Program (Instruction) := (Split, Ins_1, Ins_Any);
Connect_Tails (Tails, Ins_Terminate);
Program (Ins_Terminate) := (I_Terminate, Ins_Any);
Program (Ins_Any) := (Any_Code_Point, 0);
Tails.Clear;
Tails.Append (Ins_Any);
end;
end if;
Compile_Next;
when N_Multiplicity =>
if Pattern.AST (Expression).Lower = 0 then
if Pattern.AST (Expression).Upper = Natural'Last then
-- Zero or more
Last := Last + 1;
Instruction := Last;
declare
Ins_1 : Positive;
begin
Compile
(Get_Expression (Pattern, Expression), Ins_1, Tails);
Connect_Tails (Tails, Instruction);
if Pattern.AST (Expression).Greedy then
Program (Instruction) := (Split, Ins_1, 0);
else
Program (Instruction) := (Split, 0, Ins_1);
end if;
Tails.Clear;
Tails.Append (Instruction);
Compile_Next;
end;
elsif Pattern.AST (Expression).Upper >= 1 then
-- N optional elements
declare
Ins_1 : Positive;
Ins_2 : Positive;
Tails_L : Vector;
begin
Instruction := Last + 1;
Tails.Clear;
for J in Pattern.AST (Expression).Lower + 1
.. Pattern.AST (Expression).Upper loop
Last := Last + 1;
Ins_1 := Last;
Connect_Tails (Tails_L, Ins_1);
Tails.Append (Ins_1);
Compile
(Get_Expression (Pattern, Expression),
Ins_2,
Tails_L);
if Pattern.AST (Expression).Greedy then
Program (Ins_1) := (Split, Ins_2, 0);
else
Program (Ins_1) := (Split, 0, Ins_2);
end if;
end loop;
Tails.Append (Tails_L);
Compile_Next;
end;
end if;
else
declare
Ins_1 : Positive;
Ins_2 : Positive;
Tails_L : Vector;
begin
Tails.Clear;
for J in 1 .. Pattern.AST (Expression).Lower loop
Compile
(Get_Expression (Pattern, Expression), Ins_1, Tails);
Connect_Tails (Tails_L, Ins_1);
Tails_L := Tails;
if J = 1 then
Instruction := Ins_1;
end if;
end loop;
if Pattern.AST (Expression).Upper = Natural'Last then
Last := Last + 1;
Ins_2 := Last;
Connect_Tails (Tails_L, Ins_2);
if Pattern.AST (Expression).Greedy then
Program (Ins_2) := (Split, Ins_1, 0);
else
Program (Ins_2) := (Split, 0, Ins_1);
end if;
Tails.Clear;
Tails.Append (Ins_2);
else
Tails.Clear;
for J in Pattern.AST (Expression).Lower + 1
.. Pattern.AST (Expression).Upper loop
Last := Last + 1;
Ins_1 := Last;
Connect_Tails (Tails_L, Ins_1);
Tails.Append (Ins_1);
Compile
(Get_Expression (Pattern, Expression),
Ins_2,
Tails_L);
if Pattern.AST (Expression).Greedy then
Program (Ins_1) := (Split, Ins_2, 0);
else
Program (Ins_1) := (Split, 0, Ins_2);
end if;
end loop;
Tails.Append (Tails_L);
end if;
Compile_Next;
end;
end if;
when N_Subexpression =>
if Pattern.AST (Expression).Capture then
declare
Ins_1 : Positive;
begin
Last := Last + 1;
Instruction := Last;
Compile
(Get_Expression (Pattern, Expression), Ins_1, Tails);
Program (Instruction) :=
(Save, Ins_1, Pattern.AST (Expression).Index, True);
Last := Last + 1;
Ins_1 := Last;
Program (Ins_1) :=
(Save, 0, Pattern.AST (Expression).Index, False);
Connect_Tails (Tails, Ins_1);
Tails.Clear;
Tails.Append (Ins_1);
Compile_Next;
end;
else
Compile
(Get_Expression (Pattern, Expression), Instruction, Tails);
end if;
when N_Anchor =>
Last := Last + 1;
Instruction := Last;
Program (Instruction) :=
(I_Anchor,
0,
Pattern.AST (Expression).Start_Of_Line,
Pattern.AST (Expression).End_Of_Line);
Tails.Clear;
Tails.Append (Instruction);
Compile_Next;
when others =>
raise Program_Error;
end case;
end Compile;
-------------------
-- Connect_Tails --
-------------------
procedure Connect_Tails (Tails : Vector; Instruction : Positive) is
Position : Cursor := Tails.First;
begin
while Has_Element (Position) loop
if Program (Element (Position)).Kind = Split then
if Program (Element (Position)).Next = 0 then
Program (Element (Position)).Next := Instruction;
else
Program (Element (Position)).Another := Instruction;
end if;
else
Program (Element (Position)).Next := Instruction;
end if;
Next (Position);
end loop;
end Connect_Tails;
Ins_Split : Positive;
Ins_Any : Positive;
Ins_Save : Positive;
Ins_1 : Positive;
Tails_1 : Vector;
begin
Last := Last + 1;
Ins_Split := Last;
Last := Last + 1;
Ins_Any := Last;
Last := Last + 1;
Ins_Save := Last;
Program (Ins_Split) := (Split, Ins_Save, Ins_Any);
Program (Ins_Any) := (Any_Code_Point, Ins_Split);
Compile (Pattern.List (Pattern.Start).Head, Ins_1, Tails_1);
Program (Ins_Save) := (Save, Ins_1, 0, True);
Last := Last + 1;
Program (Last) := (Save, Last + 1, 0, False);
Connect_Tails (Tails_1, Last);
Last := Last + 1;
Program (Last) := (Kind => Match);
return (Last, Program (1 .. Last), Pattern.Captures);
end Generate;
end Matreshka.Internals.Regexps.Compiler.Generator;
|
godunko/adawebui | Ada | 3,530 | ads | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Web Framework --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2018-2020, 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: 5901 $ $Date: 2018-12-26 21:09:54 +0300 (Wed, 26 Dec 2018) $
------------------------------------------------------------------------------
with Web.Core.Slots_1;
package Web.UI.Slots.Integers is new Web.Core.Slots_1 (Integer);
pragma Preelaborate (Web.UI.Slots.Integers);
|
larsmmo/TTK4145 | Ada | 3,935 | adb | with Ada.Text_IO, Ada.Integer_Text_IO, Ada.Numerics.Float_Random;
use Ada.Text_IO, Ada.Integer_Text_IO, Ada.Numerics.Float_Random;
procedure exercise7 is
Count_Failed : exception; -- Exception to be raised when counting fails
Gen : Generator; -- Random number generator
protected type Transaction_Manager (N : Positive) is
entry Finished;
function Commit return Boolean;
procedure Signal_Abort;
private
Finished_Gate_Open : Boolean := False;
Aborted : Boolean := False;
Should_Commit : Boolean := True;
end Transaction_Manager;
protected body Transaction_Manager is
entry Finished when Finished_Gate_Open or Finished'Count = N is
begin
------------------------------------------
-- PART 3: Complete the exit protocol here
------------------------------------------
Finished_Gate_Open := True;
if Finished'Count = N then
Finished_Gate_Open := True;
Manager.Commit;
elsif Finished'count = 1 then
Finished_Gate_Open := False;
Manager.Signal_Abort;
end if;
end Finished;
procedure Signal_Abort is
begin
Aborted := True;
end Signal_Abort;
function Commit return Boolean is
begin
return Should_Commit;
end Commit;
end Transaction_Manager;
function Unreliable_Slow_Add (x : Integer) return Integer is
Error_Rate : Constant := 0.15; -- (between 0 and 1)
Random_number : Float := Random(Gen);
begin
-------------------------------------------
-- PART 1: Create the transaction work here
-------------------------------------------
if Random_number > Error_Rate then
delay Duration(4.0);
return x+10;
else
delay Duration(0.5);
raise Count_failed;
end if;
end Unreliable_Slow_Add;
task type Transaction_Worker (Initial : Integer; Manager : access Transaction_Manager);
task body Transaction_Worker is
Num : Integer := Initial;
Prev : Integer := Num;
Round_Num : Integer := 0;
begin
Put_Line ("Worker" & Integer'Image(Initial) & " started");
loop
Put_Line ("Worker" & Integer'Image(Initial) & " started round" & Integer'Image(Round_Num));
Round_Num := Round_Num + 1;
---------------------------------------
-- PART 2: Do the transaction work here
---------------------------------------
Num := Unreliable_Slow_Add(Prev);
begin
exception
when Count_Failed =>
Manager.Signal_Abort;
end;
Manager.Finished;
if Manager.Commit = True then
Put_Line (" Worker" & Integer'Image(Initial) & " comitting" & Integer'Image(Num));
else
Put_Line (" Worker" & Integer'Image(Initial) &
" reverting from" & Integer'Image(Num) &
" to" & Integer'Image(Prev));
-------------------------------------------
-- PART 2: Roll back to previous value here
-------------------------------------------
Num := Initial
end if;
Prev := Num;
delay 0.5;
end loop;
end Transaction_Worker;
Manager : aliased Transaction_Manager (3);
Worker_1 : Transaction_Worker (0, Manager'Access);
Worker_2 : Transaction_Worker (1, Manager'Access);
Worker_3 : Transaction_Worker (2, Manager'Access);
begin
Reset(Gen); -- Seed the random number generator
end exercise7;
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.