content stringlengths 23 1.05M |
|---|
-- Abstract :
--
-- Types and operations for computing grammar properties used in
-- generating a packrat parser.
--
-- We use the terminology in [tratt 2010] for recursion in
-- productions.
--
-- References :
--
-- See wisitoken-parse-packrat.ads.
--
-- Copyright (C) 2018 Free Software Foundation, Inc.
--
-- This library is free software; you can redistribute it and/or modify it
-- under terms of the GNU General Public License as published by the Free
-- Software Foundation; either version 3, or (at your option) any later
-- version. This library 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.
-- 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.
pragma License (Modified_GPL);
package WisiToken.Generate.Packrat is
type Data (First_Terminal, First_Nonterminal, Last_Nonterminal : Token_ID) is tagged
record
-- Data needed to check a grammar and generate code. Tagged to allow
-- Object.Method syntax. Descriptor not included to avoid duplicating
-- lots of discriminants.
Source_File_Name : Ada.Strings.Unbounded.Unbounded_String;
Grammar : WisiToken.Productions.Prod_Arrays.Vector;
Source_Line_Map : Productions.Source_Line_Maps.Vector;
Empty : Token_ID_Set (First_Nonterminal .. Last_Nonterminal);
Direct_Left_Recursive : Token_ID_Set (First_Nonterminal .. Last_Nonterminal);
First : Token_Array_Token_Set
(First_Nonterminal .. Last_Nonterminal, First_Terminal .. Last_Nonterminal);
Involved : Token_Array_Token_Set
(First_Nonterminal .. Last_Nonterminal, First_Nonterminal .. Last_Nonterminal);
end record;
function Initialize
(Source_File_Name : in String;
Grammar : in WisiToken.Productions.Prod_Arrays.Vector;
Source_Line_Map : in Productions.Source_Line_Maps.Vector;
First_Terminal : in Token_ID)
return Packrat.Data;
procedure Check_Recursion (Data : in Packrat.Data; Descriptor : in WisiToken.Descriptor);
-- Check that any rule recursion present is supported.
procedure Check_RHS_Order (Data : in Packrat.Data; Descriptor : in WisiToken.Descriptor);
-- For each production, check that right hand sides that share
-- prefixes have the longest right hand side first, and that any
-- empty right hand side is last.
--
-- Violations output a message to Ada.Text_IO.Standard_Error, and
-- set WisiToken.Generate.Error True.
procedure Check_All (Data : in Packrat.Data; Descriptor : in WisiToken.Descriptor);
-- Run all the above checks.
--
-- Note that WisiToken.Generate.Check_Consistent is run in
-- wisi-gen_generate_utils.To_Grammar.
function Potential_Direct_Left_Recursive
(Grammar : in WisiToken.Productions.Prod_Arrays.Vector;
Empty : in Token_ID_Set)
return Token_ID_Set;
end WisiToken.Generate.Packrat;
|
------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- L A Y O U T --
-- --
-- B o d y --
-- --
-- Copyright (C) 2001-2016, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
-- for more details. You should have received a copy of the GNU General --
-- Public License distributed with GNAT; see file COPYING3. If not, go to --
-- http://www.gnu.org/licenses for a complete copy of the license. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
with Atree; use Atree;
with Checks; use Checks;
with Debug; use Debug;
with Einfo; use Einfo;
with Errout; use Errout;
with Exp_Ch3; use Exp_Ch3;
with Exp_Util; use Exp_Util;
with Namet; use Namet;
with Nlists; use Nlists;
with Nmake; use Nmake;
with Opt; use Opt;
with Repinfo; use Repinfo;
with Sem; use Sem;
with Sem_Aux; use Sem_Aux;
with Sem_Case; use Sem_Case;
with Sem_Ch13; use Sem_Ch13;
with Sem_Eval; use Sem_Eval;
with Sem_Util; use Sem_Util;
with Sinfo; use Sinfo;
with Snames; use Snames;
with Stand; use Stand;
with Targparm; use Targparm;
with Tbuild; use Tbuild;
with Ttypes; use Ttypes;
with Uintp; use Uintp;
package body Layout is
------------------------
-- Local Declarations --
------------------------
SSU : constant Int := Ttypes.System_Storage_Unit;
-- Short hand for System_Storage_Unit
Vname : constant Name_Id := Name_uV;
-- Formal parameter name used for functions generated for size offset
-- values that depend on the discriminant. All such functions have the
-- following form:
--
-- function xxx (V : vtyp) return Unsigned is
-- begin
-- return ... expression involving V.discrim
-- end xxx;
-----------------------
-- Local Subprograms --
-----------------------
function Assoc_Add
(Loc : Source_Ptr;
Left_Opnd : Node_Id;
Right_Opnd : Node_Id) return Node_Id;
-- This is like Make_Op_Add except that it optimizes some cases knowing
-- that associative rearrangement is allowed for constant folding if one
-- of the operands is a compile time known value.
function Assoc_Multiply
(Loc : Source_Ptr;
Left_Opnd : Node_Id;
Right_Opnd : Node_Id) return Node_Id;
-- This is like Make_Op_Multiply except that it optimizes some cases
-- knowing that associative rearrangement is allowed for constant folding
-- if one of the operands is a compile time known value
function Assoc_Subtract
(Loc : Source_Ptr;
Left_Opnd : Node_Id;
Right_Opnd : Node_Id) return Node_Id;
-- This is like Make_Op_Subtract except that it optimizes some cases
-- knowing that associative rearrangement is allowed for constant folding
-- if one of the operands is a compile time known value
function Bits_To_SU (N : Node_Id) return Node_Id;
-- This is used when we cross the boundary from static sizes in bits to
-- dynamic sizes in storage units. If the argument N is anything other
-- than an integer literal, it is returned unchanged, but if it is an
-- integer literal, then it is taken as a size in bits, and is replaced
-- by the corresponding size in storage units.
function Compute_Length (Lo : Node_Id; Hi : Node_Id) return Node_Id;
-- Given expressions for the low bound (Lo) and the high bound (Hi),
-- Build an expression for the value hi-lo+1, converted to type
-- Standard.Unsigned. Takes care of the case where the operands
-- are of an enumeration type (so that the subtraction cannot be
-- done directly) by applying the Pos operator to Hi/Lo first.
procedure Compute_Size_Depends_On_Discriminant (E : Entity_Id);
-- Given an array type or an array subtype E, compute whether its size
-- depends on the value of one or more discriminants and set the flag
-- Size_Depends_On_Discriminant accordingly. This need not be called
-- in front end layout mode since it does the computation on its own.
function Expr_From_SO_Ref
(Loc : Source_Ptr;
D : SO_Ref;
Comp : Entity_Id := Empty) return Node_Id;
-- Given a value D from a size or offset field, return an expression
-- representing the value stored. If the value is known at compile time,
-- then an N_Integer_Literal is returned with the appropriate value. If
-- the value references a constant entity, then an N_Identifier node
-- referencing this entity is returned. If the value denotes a size
-- function, then returns a call node denoting the given function, with
-- a single actual parameter that either refers to the parameter V of
-- an enclosing size function (if Comp is Empty or its type doesn't match
-- the function's formal), or else is a selected component V.c when Comp
-- denotes a component c whose type matches that of the function formal.
-- The Loc value is used for the Sloc value of constructed notes.
function SO_Ref_From_Expr
(Expr : Node_Id;
Ins_Type : Entity_Id;
Vtype : Entity_Id := Empty;
Make_Func : Boolean := False) return Dynamic_SO_Ref;
-- This routine is used in the case where a size/offset value is dynamic
-- and is represented by the expression Expr. SO_Ref_From_Expr checks if
-- the Expr contains a reference to the identifier V, and if so builds
-- a function depending on discriminants of the formal parameter V which
-- is of type Vtype. Otherwise, if the parameter Make_Func is True, then
-- Expr will be encapsulated in a parameterless function; if Make_Func is
-- False, then a constant entity with the value Expr is built. The result
-- is a Dynamic_SO_Ref to the created entity. Note that Vtype can be
-- omitted if Expr does not contain any reference to V, the created entity.
-- The declaration created is inserted in the freeze actions of Ins_Type,
-- which also supplies the Sloc for created nodes. This function also takes
-- care of making sure that the expression is properly analyzed and
-- resolved (which may not be the case yet if we build the expression
-- in this unit).
function Get_Max_SU_Size (E : Entity_Id) return Node_Id;
-- E is an array type or subtype that has at least one index bound that
-- is the value of a record discriminant. For such an array, the function
-- computes an expression that yields the maximum possible size of the
-- array in storage units. The result is not defined for any other type,
-- or for arrays that do not depend on discriminants, and it is a fatal
-- error to call this unless Size_Depends_On_Discriminant (E) is True.
procedure Layout_Array_Type (E : Entity_Id);
-- Front-end layout of non-bit-packed array type or subtype
procedure Layout_Record_Type (E : Entity_Id);
-- Front-end layout of record type
procedure Rewrite_Integer (N : Node_Id; V : Uint);
-- Rewrite node N with an integer literal whose value is V. The Sloc for
-- the new node is taken from N, and the type of the literal is set to a
-- copy of the type of N on entry.
procedure Set_And_Check_Static_Size
(E : Entity_Id;
Esiz : SO_Ref;
RM_Siz : SO_Ref);
-- This procedure is called to check explicit given sizes (possibly stored
-- in the Esize and RM_Size fields of E) against computed Object_Size
-- (Esiz) and Value_Size (RM_Siz) values. Appropriate errors and warnings
-- are posted if specified sizes are inconsistent with specified sizes. On
-- return, Esize and RM_Size fields of E are set (either from previously
-- given values, or from the newly computed values, as appropriate).
procedure Set_Composite_Alignment (E : Entity_Id);
-- This procedure is called for record types and subtypes, and also for
-- atomic array types and subtypes. If no alignment is set, and the size
-- is 2 or 4 (or 8 if the word size is 8), then the alignment is set to
-- match the size.
----------------------------
-- Adjust_Esize_Alignment --
----------------------------
procedure Adjust_Esize_Alignment (E : Entity_Id) is
Abits : Int;
Esize_Set : Boolean;
begin
-- Nothing to do if size unknown
if Unknown_Esize (E) then
return;
end if;
-- Determine if size is constrained by an attribute definition clause
-- which must be obeyed. If so, we cannot increase the size in this
-- routine.
-- For a type, the issue is whether an object size clause has been set.
-- A normal size clause constrains only the value size (RM_Size)
if Is_Type (E) then
Esize_Set := Has_Object_Size_Clause (E);
-- For an object, the issue is whether a size clause is present
else
Esize_Set := Has_Size_Clause (E);
end if;
-- If size is known it must be a multiple of the storage unit size
if Esize (E) mod SSU /= 0 then
-- If not, and size specified, then give error
if Esize_Set then
Error_Msg_NE
("size for& not a multiple of storage unit size",
Size_Clause (E), E);
return;
-- Otherwise bump up size to a storage unit boundary
else
Set_Esize (E, (Esize (E) + SSU - 1) / SSU * SSU);
end if;
end if;
-- Now we have the size set, it must be a multiple of the alignment
-- nothing more we can do here if the alignment is unknown here.
if Unknown_Alignment (E) then
return;
end if;
-- At this point both the Esize and Alignment are known, so we need
-- to make sure they are consistent.
Abits := UI_To_Int (Alignment (E)) * SSU;
if Esize (E) mod Abits = 0 then
return;
end if;
-- Here we have a situation where the Esize is not a multiple of the
-- alignment. We must either increase Esize or reduce the alignment to
-- correct this situation.
-- The case in which we can decrease the alignment is where the
-- alignment was not set by an alignment clause, and the type in
-- question is a discrete type, where it is definitely safe to reduce
-- the alignment. For example:
-- t : integer range 1 .. 2;
-- for t'size use 8;
-- In this situation, the initial alignment of t is 4, copied from
-- the Integer base type, but it is safe to reduce it to 1 at this
-- stage, since we will only be loading a single storage unit.
if Is_Discrete_Type (Etype (E)) and then not Has_Alignment_Clause (E)
then
loop
Abits := Abits / 2;
exit when Esize (E) mod Abits = 0;
end loop;
Init_Alignment (E, Abits / SSU);
return;
end if;
-- Now the only possible approach left is to increase the Esize but we
-- can't do that if the size was set by a specific clause.
if Esize_Set then
Error_Msg_NE
("size for& is not a multiple of alignment",
Size_Clause (E), E);
-- Otherwise we can indeed increase the size to a multiple of alignment
else
Set_Esize (E, ((Esize (E) + (Abits - 1)) / Abits) * Abits);
end if;
end Adjust_Esize_Alignment;
---------------
-- Assoc_Add --
---------------
function Assoc_Add
(Loc : Source_Ptr;
Left_Opnd : Node_Id;
Right_Opnd : Node_Id) return Node_Id
is
L : Node_Id;
R : Uint;
begin
-- Case of right operand is a constant
if Compile_Time_Known_Value (Right_Opnd) then
L := Left_Opnd;
R := Expr_Value (Right_Opnd);
-- Case of left operand is a constant
elsif Compile_Time_Known_Value (Left_Opnd) then
L := Right_Opnd;
R := Expr_Value (Left_Opnd);
-- Neither operand is a constant, do the addition with no optimization
else
return Make_Op_Add (Loc, Left_Opnd, Right_Opnd);
end if;
-- Case of left operand is an addition
if Nkind (L) = N_Op_Add then
-- (C1 + E) + C2 = (C1 + C2) + E
if Compile_Time_Known_Value (Sinfo.Left_Opnd (L)) then
Rewrite_Integer
(Sinfo.Left_Opnd (L),
Expr_Value (Sinfo.Left_Opnd (L)) + R);
return L;
-- (E + C1) + C2 = E + (C1 + C2)
elsif Compile_Time_Known_Value (Sinfo.Right_Opnd (L)) then
Rewrite_Integer
(Sinfo.Right_Opnd (L),
Expr_Value (Sinfo.Right_Opnd (L)) + R);
return L;
end if;
-- Case of left operand is a subtraction
elsif Nkind (L) = N_Op_Subtract then
-- (C1 - E) + C2 = (C1 + C2) - E
if Compile_Time_Known_Value (Sinfo.Left_Opnd (L)) then
Rewrite_Integer
(Sinfo.Left_Opnd (L),
Expr_Value (Sinfo.Left_Opnd (L)) + R);
return L;
-- (E - C1) + C2 = E - (C1 - C2)
-- If the type is unsigned then only do the optimization if C1 >= C2,
-- to avoid creating a negative literal that can't be used with the
-- unsigned type.
elsif Compile_Time_Known_Value (Sinfo.Right_Opnd (L))
and then (not Is_Unsigned_Type (Etype (Sinfo.Right_Opnd (L)))
or else Expr_Value (Sinfo.Right_Opnd (L)) >= R)
then
Rewrite_Integer
(Sinfo.Right_Opnd (L),
Expr_Value (Sinfo.Right_Opnd (L)) - R);
return L;
end if;
end if;
-- Not optimizable, do the addition
return Make_Op_Add (Loc, Left_Opnd, Right_Opnd);
end Assoc_Add;
--------------------
-- Assoc_Multiply --
--------------------
function Assoc_Multiply
(Loc : Source_Ptr;
Left_Opnd : Node_Id;
Right_Opnd : Node_Id) return Node_Id
is
L : Node_Id;
R : Uint;
begin
-- Case of right operand is a constant
if Compile_Time_Known_Value (Right_Opnd) then
L := Left_Opnd;
R := Expr_Value (Right_Opnd);
-- Case of left operand is a constant
elsif Compile_Time_Known_Value (Left_Opnd) then
L := Right_Opnd;
R := Expr_Value (Left_Opnd);
-- Neither operand is a constant, do the multiply with no optimization
else
return Make_Op_Multiply (Loc, Left_Opnd, Right_Opnd);
end if;
-- Case of left operand is an multiplication
if Nkind (L) = N_Op_Multiply then
-- (C1 * E) * C2 = (C1 * C2) + E
if Compile_Time_Known_Value (Sinfo.Left_Opnd (L)) then
Rewrite_Integer
(Sinfo.Left_Opnd (L),
Expr_Value (Sinfo.Left_Opnd (L)) * R);
return L;
-- (E * C1) * C2 = E * (C1 * C2)
elsif Compile_Time_Known_Value (Sinfo.Right_Opnd (L)) then
Rewrite_Integer
(Sinfo.Right_Opnd (L),
Expr_Value (Sinfo.Right_Opnd (L)) * R);
return L;
end if;
end if;
-- Not optimizable, do the multiplication
return Make_Op_Multiply (Loc, Left_Opnd, Right_Opnd);
end Assoc_Multiply;
--------------------
-- Assoc_Subtract --
--------------------
function Assoc_Subtract
(Loc : Source_Ptr;
Left_Opnd : Node_Id;
Right_Opnd : Node_Id) return Node_Id
is
L : Node_Id;
R : Uint;
begin
-- Case of right operand is a constant
if Compile_Time_Known_Value (Right_Opnd) then
L := Left_Opnd;
R := Expr_Value (Right_Opnd);
-- Right operand is a constant, do the subtract with no optimization
else
return Make_Op_Subtract (Loc, Left_Opnd, Right_Opnd);
end if;
-- Case of left operand is an addition
if Nkind (L) = N_Op_Add then
-- (C1 + E) - C2 = (C1 - C2) + E
if Compile_Time_Known_Value (Sinfo.Left_Opnd (L)) then
Rewrite_Integer
(Sinfo.Left_Opnd (L),
Expr_Value (Sinfo.Left_Opnd (L)) - R);
return L;
-- (E + C1) - C2 = E + (C1 - C2)
elsif Compile_Time_Known_Value (Sinfo.Right_Opnd (L)) then
Rewrite_Integer
(Sinfo.Right_Opnd (L),
Expr_Value (Sinfo.Right_Opnd (L)) - R);
return L;
end if;
-- Case of left operand is a subtraction
elsif Nkind (L) = N_Op_Subtract then
-- (C1 - E) - C2 = (C1 - C2) + E
if Compile_Time_Known_Value (Sinfo.Left_Opnd (L)) then
Rewrite_Integer
(Sinfo.Left_Opnd (L),
Expr_Value (Sinfo.Left_Opnd (L)) + R);
return L;
-- (E - C1) - C2 = E - (C1 + C2)
elsif Compile_Time_Known_Value (Sinfo.Right_Opnd (L)) then
Rewrite_Integer
(Sinfo.Right_Opnd (L),
Expr_Value (Sinfo.Right_Opnd (L)) + R);
return L;
end if;
end if;
-- Not optimizable, do the subtraction
return Make_Op_Subtract (Loc, Left_Opnd, Right_Opnd);
end Assoc_Subtract;
----------------
-- Bits_To_SU --
----------------
function Bits_To_SU (N : Node_Id) return Node_Id is
begin
if Nkind (N) = N_Integer_Literal then
Set_Intval (N, (Intval (N) + (SSU - 1)) / SSU);
end if;
return N;
end Bits_To_SU;
--------------------
-- Compute_Length --
--------------------
function Compute_Length (Lo : Node_Id; Hi : Node_Id) return Node_Id is
Loc : constant Source_Ptr := Sloc (Lo);
Typ : constant Entity_Id := Etype (Lo);
Lo_Op : Node_Id;
Hi_Op : Node_Id;
Lo_Dim : Uint;
Hi_Dim : Uint;
begin
-- If the bounds are First and Last attributes for the same dimension
-- and both have prefixes that denotes the same entity, then we create
-- and return a Length attribute. This may allow the back end to
-- generate better code in cases where it already has the length.
if Nkind (Lo) = N_Attribute_Reference
and then Attribute_Name (Lo) = Name_First
and then Nkind (Hi) = N_Attribute_Reference
and then Attribute_Name (Hi) = Name_Last
and then Is_Entity_Name (Prefix (Lo))
and then Is_Entity_Name (Prefix (Hi))
and then Entity (Prefix (Lo)) = Entity (Prefix (Hi))
then
Lo_Dim := Uint_1;
Hi_Dim := Uint_1;
if Present (First (Expressions (Lo))) then
Lo_Dim := Expr_Value (First (Expressions (Lo)));
end if;
if Present (First (Expressions (Hi))) then
Hi_Dim := Expr_Value (First (Expressions (Hi)));
end if;
if Lo_Dim = Hi_Dim then
return
Make_Attribute_Reference (Loc,
Prefix => New_Occurrence_Of
(Entity (Prefix (Lo)), Loc),
Attribute_Name => Name_Length,
Expressions => New_List
(Make_Integer_Literal (Loc, Lo_Dim)));
end if;
end if;
Lo_Op := New_Copy_Tree (Lo);
Hi_Op := New_Copy_Tree (Hi);
-- If type is enumeration type, then use Pos attribute to convert
-- to integer type for which subtraction is a permitted operation.
if Is_Enumeration_Type (Typ) then
Lo_Op :=
Make_Attribute_Reference (Loc,
Prefix => New_Occurrence_Of (Typ, Loc),
Attribute_Name => Name_Pos,
Expressions => New_List (Lo_Op));
Hi_Op :=
Make_Attribute_Reference (Loc,
Prefix => New_Occurrence_Of (Typ, Loc),
Attribute_Name => Name_Pos,
Expressions => New_List (Hi_Op));
end if;
return
Assoc_Add (Loc,
Left_Opnd =>
Assoc_Subtract (Loc,
Left_Opnd => Hi_Op,
Right_Opnd => Lo_Op),
Right_Opnd => Make_Integer_Literal (Loc, 1));
end Compute_Length;
----------------------
-- Expr_From_SO_Ref --
----------------------
function Expr_From_SO_Ref
(Loc : Source_Ptr;
D : SO_Ref;
Comp : Entity_Id := Empty) return Node_Id
is
Ent : Entity_Id;
begin
if Is_Dynamic_SO_Ref (D) then
Ent := Get_Dynamic_SO_Entity (D);
if Is_Discrim_SO_Function (Ent) then
-- If a component is passed in whose type matches the type of
-- the function formal, then select that component from the "V"
-- parameter rather than passing "V" directly.
if Present (Comp)
and then Base_Type (Etype (Comp)) =
Base_Type (Etype (First_Formal (Ent)))
then
return
Make_Function_Call (Loc,
Name => New_Occurrence_Of (Ent, Loc),
Parameter_Associations => New_List (
Make_Selected_Component (Loc,
Prefix => Make_Identifier (Loc, Vname),
Selector_Name => New_Occurrence_Of (Comp, Loc))));
else
return
Make_Function_Call (Loc,
Name => New_Occurrence_Of (Ent, Loc),
Parameter_Associations => New_List (
Make_Identifier (Loc, Vname)));
end if;
else
return New_Occurrence_Of (Ent, Loc);
end if;
else
return Make_Integer_Literal (Loc, D);
end if;
end Expr_From_SO_Ref;
---------------------
-- Get_Max_SU_Size --
---------------------
function Get_Max_SU_Size (E : Entity_Id) return Node_Id is
Loc : constant Source_Ptr := Sloc (E);
Indx : Node_Id;
Ityp : Entity_Id;
Lo : Node_Id;
Hi : Node_Id;
S : Uint;
Len : Node_Id;
type Val_Status_Type is (Const, Dynamic);
type Val_Type (Status : Val_Status_Type := Const) is record
case Status is
when Const => Val : Uint;
when Dynamic => Nod : Node_Id;
end case;
end record;
-- Shows the status of the value so far. Const means that the value is
-- constant, and Val is the current constant value. Dynamic means that
-- the value is dynamic, and in this case Nod is the Node_Id of the
-- expression to compute the value.
Size : Val_Type;
-- Calculated value so far if Size.Status = Const,
-- or expression value so far if Size.Status = Dynamic.
SU_Convert_Required : Boolean := False;
-- This is set to True if the final result must be converted from bits
-- to storage units (rounding up to a storage unit boundary).
-----------------------
-- Local Subprograms --
-----------------------
procedure Max_Discrim (N : in out Node_Id);
-- If the node N represents a discriminant, replace it by the maximum
-- value of the discriminant.
procedure Min_Discrim (N : in out Node_Id);
-- If the node N represents a discriminant, replace it by the minimum
-- value of the discriminant.
-----------------
-- Max_Discrim --
-----------------
procedure Max_Discrim (N : in out Node_Id) is
begin
if Nkind (N) = N_Identifier
and then Ekind (Entity (N)) = E_Discriminant
then
N := Type_High_Bound (Etype (N));
end if;
end Max_Discrim;
-----------------
-- Min_Discrim --
-----------------
procedure Min_Discrim (N : in out Node_Id) is
begin
if Nkind (N) = N_Identifier
and then Ekind (Entity (N)) = E_Discriminant
then
N := Type_Low_Bound (Etype (N));
end if;
end Min_Discrim;
-- Start of processing for Get_Max_SU_Size
begin
pragma Assert (Size_Depends_On_Discriminant (E));
-- Initialize status from component size
if Known_Static_Component_Size (E) then
Size := (Const, Component_Size (E));
else
Size := (Dynamic, Expr_From_SO_Ref (Loc, Component_Size (E)));
end if;
-- Loop through indexes
Indx := First_Index (E);
while Present (Indx) loop
Ityp := Etype (Indx);
Lo := Type_Low_Bound (Ityp);
Hi := Type_High_Bound (Ityp);
Min_Discrim (Lo);
Max_Discrim (Hi);
-- Value of the current subscript range is statically known
if Compile_Time_Known_Value (Lo)
and then
Compile_Time_Known_Value (Hi)
then
S := Expr_Value (Hi) - Expr_Value (Lo) + 1;
-- If known flat bound, entire size of array is zero
if S <= 0 then
return Make_Integer_Literal (Loc, 0);
end if;
-- Current value is constant, evolve value
if Size.Status = Const then
Size.Val := Size.Val * S;
-- Current value is dynamic
else
-- An interesting little optimization, if we have a pending
-- conversion from bits to storage units, and the current
-- length is a multiple of the storage unit size, then we
-- can take the factor out here statically, avoiding some
-- extra dynamic computations at the end.
if SU_Convert_Required and then S mod SSU = 0 then
S := S / SSU;
SU_Convert_Required := False;
end if;
Size.Nod :=
Assoc_Multiply (Loc,
Left_Opnd => Size.Nod,
Right_Opnd =>
Make_Integer_Literal (Loc, Intval => S));
end if;
-- Value of the current subscript range is dynamic
else
-- If the current size value is constant, then here is where we
-- make a transition to dynamic values, which are always stored
-- in storage units, However, we do not want to convert to SU's
-- too soon, consider the case of a packed array of single bits,
-- we want to do the SU conversion after computing the size in
-- this case.
if Size.Status = Const then
-- If the current value is a multiple of the storage unit,
-- then most certainly we can do the conversion now, simply
-- by dividing the current value by the storage unit value.
-- If this works, we set SU_Convert_Required to False.
if Size.Val mod SSU = 0 then
Size :=
(Dynamic, Make_Integer_Literal (Loc, Size.Val / SSU));
SU_Convert_Required := False;
-- Otherwise, we go ahead and convert the value in bits, and
-- set SU_Convert_Required to True to ensure that the final
-- value is indeed properly converted.
else
Size := (Dynamic, Make_Integer_Literal (Loc, Size.Val));
SU_Convert_Required := True;
end if;
end if;
-- Length is hi-lo+1
Len := Compute_Length (Lo, Hi);
-- Check possible range of Len
declare
OK : Boolean;
LLo : Uint;
LHi : Uint;
pragma Warnings (Off, LHi);
begin
Set_Parent (Len, E);
Determine_Range (Len, OK, LLo, LHi);
Len := Convert_To (Standard_Unsigned, Len);
-- If we cannot verify that range cannot be super-flat, we need
-- a max with zero, since length must be non-negative.
if not OK or else LLo < 0 then
Len :=
Make_Attribute_Reference (Loc,
Prefix =>
New_Occurrence_Of (Standard_Unsigned, Loc),
Attribute_Name => Name_Max,
Expressions => New_List (
Make_Integer_Literal (Loc, 0),
Len));
end if;
end;
end if;
Next_Index (Indx);
end loop;
-- Here after processing all bounds to set sizes. If the value is a
-- constant, then it is bits, so we convert to storage units.
if Size.Status = Const then
return Bits_To_SU (Make_Integer_Literal (Loc, Size.Val));
-- Case where the value is dynamic
else
-- Do convert from bits to SU's if needed
if SU_Convert_Required then
-- The expression required is (Size.Nod + SU - 1) / SU
Size.Nod :=
Make_Op_Divide (Loc,
Left_Opnd =>
Make_Op_Add (Loc,
Left_Opnd => Size.Nod,
Right_Opnd => Make_Integer_Literal (Loc, SSU - 1)),
Right_Opnd => Make_Integer_Literal (Loc, SSU));
end if;
return Size.Nod;
end if;
end Get_Max_SU_Size;
-----------------------
-- Layout_Array_Type --
-----------------------
procedure Layout_Array_Type (E : Entity_Id) is
Loc : constant Source_Ptr := Sloc (E);
Ctyp : constant Entity_Id := Component_Type (E);
Indx : Node_Id;
Ityp : Entity_Id;
Lo : Node_Id;
Hi : Node_Id;
S : Uint;
Len : Node_Id;
Insert_Typ : Entity_Id;
-- This is the type with which any generated constants or functions
-- will be associated (i.e. inserted into the freeze actions). This
-- is normally the type being laid out. The exception occurs when
-- we are laying out Itype's which are local to a record type, and
-- whose scope is this record type. Such types do not have freeze
-- nodes (because we have no place to put them).
------------------------------------
-- How An Array Type is Laid Out --
------------------------------------
-- Here is what goes on. We need to multiply the component size of the
-- array (which has already been set) by the length of each of the
-- indexes. If all these values are known at compile time, then the
-- resulting size of the array is the appropriate constant value.
-- If the component size or at least one bound is dynamic (but no
-- discriminants are present), then the size will be computed as an
-- expression that calculates the proper size.
-- If there is at least one discriminant bound, then the size is also
-- computed as an expression, but this expression contains discriminant
-- values which are obtained by selecting from a function parameter, and
-- the size is given by a function that is passed the variant record in
-- question, and whose body is the expression.
type Val_Status_Type is (Const, Dynamic, Discrim);
type Val_Type (Status : Val_Status_Type := Const) is record
case Status is
when Const =>
Val : Uint;
-- Calculated value so far if Val_Status = Const
when Discrim
| Dynamic
=>
Nod : Node_Id;
-- Expression value so far if Val_Status /= Const
end case;
end record;
-- Records the value or expression computed so far. Const means that
-- the value is constant, and Val is the current constant value.
-- Dynamic means that the value is dynamic, and in this case Nod is
-- the Node_Id of the expression to compute the value, and Discrim
-- means that at least one bound is a discriminant, in which case Nod
-- is the expression so far (which will be the body of the function).
Size : Val_Type;
-- Value of size computed so far. See comments above
Vtyp : Entity_Id := Empty;
-- Variant record type for the formal parameter of the discriminant
-- function V if Status = Discrim.
SU_Convert_Required : Boolean := False;
-- This is set to True if the final result must be converted from
-- bits to storage units (rounding up to a storage unit boundary).
Storage_Divisor : Uint := UI_From_Int (SSU);
-- This is the amount that a nonstatic computed size will be divided
-- by to convert it from bits to storage units. This is normally
-- equal to SSU, but can be reduced in the case of packed components
-- that fit evenly into a storage unit.
Make_Size_Function : Boolean := False;
-- Indicates whether to request that SO_Ref_From_Expr should
-- encapsulate the array size expression in a function.
procedure Discrimify (N : in out Node_Id);
-- If N represents a discriminant, then the Size.Status is set to
-- Discrim, and Vtyp is set. The parameter N is replaced with the
-- proper expression to extract the discriminant value from V.
----------------
-- Discrimify --
----------------
procedure Discrimify (N : in out Node_Id) is
Decl : Node_Id;
Typ : Entity_Id;
begin
if Nkind (N) = N_Identifier
and then Ekind (Entity (N)) = E_Discriminant
then
Set_Size_Depends_On_Discriminant (E);
if Size.Status /= Discrim then
Decl := Parent (Parent (Entity (N)));
Size := (Discrim, Size.Nod);
Vtyp := Defining_Identifier (Decl);
end if;
Typ := Etype (N);
N :=
Make_Selected_Component (Loc,
Prefix => Make_Identifier (Loc, Vname),
Selector_Name => New_Occurrence_Of (Entity (N), Loc));
-- Set the Etype attributes of the selected name and its prefix.
-- Analyze_And_Resolve can't be called here because the Vname
-- entity denoted by the prefix will not yet exist (it's created
-- by SO_Ref_From_Expr, called at the end of Layout_Array_Type).
Set_Etype (Prefix (N), Vtyp);
Set_Etype (N, Typ);
end if;
end Discrimify;
-- Start of processing for Layout_Array_Type
begin
-- Default alignment is component alignment
if Unknown_Alignment (E) then
Set_Alignment (E, Alignment (Ctyp));
end if;
-- Calculate proper type for insertions
if Is_Record_Type (Underlying_Type (Scope (E))) then
Insert_Typ := Underlying_Type (Scope (E));
else
Insert_Typ := E;
end if;
-- If the component type is a generic formal type then there's no point
-- in determining a size for the array type.
if Is_Generic_Type (Ctyp) then
return;
end if;
-- Deal with component size if base type
if Ekind (E) = E_Array_Type then
-- Cannot do anything if Esize of component type unknown
if Unknown_Esize (Ctyp) then
return;
end if;
-- Set component size if not set already
if Unknown_Component_Size (E) then
Set_Component_Size (E, Esize (Ctyp));
end if;
end if;
-- (RM 13.3 (48)) says that the size of an unconstrained array
-- is implementation defined. We choose to leave it as Unknown
-- here, and the actual behavior is determined by the back end.
if not Is_Constrained (E) then
return;
end if;
-- Initialize status from component size
if Known_Static_Component_Size (E) then
Size := (Const, Component_Size (E));
else
Size := (Dynamic, Expr_From_SO_Ref (Loc, Component_Size (E)));
end if;
-- Loop to process array indexes
Indx := First_Index (E);
while Present (Indx) loop
Ityp := Etype (Indx);
-- If an index of the array is a generic formal type then there is
-- no point in determining a size for the array type.
if Is_Generic_Type (Ityp) then
return;
end if;
Lo := Type_Low_Bound (Ityp);
Hi := Type_High_Bound (Ityp);
-- Value of the current subscript range is statically known
if Compile_Time_Known_Value (Lo)
and then
Compile_Time_Known_Value (Hi)
then
S := Expr_Value (Hi) - Expr_Value (Lo) + 1;
-- If known flat bound, entire size of array is zero
if S <= 0 then
Set_Esize (E, Uint_0);
Set_RM_Size (E, Uint_0);
return;
end if;
-- If constant, evolve value
if Size.Status = Const then
Size.Val := Size.Val * S;
-- Current value is dynamic
else
-- An interesting little optimization, if we have a pending
-- conversion from bits to storage units, and the current
-- length is a multiple of the storage unit size, then we
-- can take the factor out here statically, avoiding some
-- extra dynamic computations at the end.
if SU_Convert_Required and then S mod SSU = 0 then
S := S / SSU;
SU_Convert_Required := False;
end if;
-- Now go ahead and evolve the expression
Size.Nod :=
Assoc_Multiply (Loc,
Left_Opnd => Size.Nod,
Right_Opnd =>
Make_Integer_Literal (Loc, Intval => S));
end if;
-- Value of the current subscript range is dynamic
else
-- If the current size value is constant, then here is where we
-- make a transition to dynamic values, which are always stored
-- in storage units, However, we do not want to convert to SU's
-- too soon, consider the case of a packed array of single bits,
-- we want to do the SU conversion after computing the size in
-- this case.
if Size.Status = Const then
-- If the current value is a multiple of the storage unit,
-- then most certainly we can do the conversion now, simply
-- by dividing the current value by the storage unit value.
-- If this works, we set SU_Convert_Required to False.
if Size.Val mod SSU = 0 then
Size :=
(Dynamic, Make_Integer_Literal (Loc, Size.Val / SSU));
SU_Convert_Required := False;
-- If the current value is a factor of the storage unit, then
-- we can use a value of one for the size and reduce the
-- strength of the later division.
elsif SSU mod Size.Val = 0 then
Storage_Divisor := SSU / Size.Val;
Size := (Dynamic, Make_Integer_Literal (Loc, Uint_1));
SU_Convert_Required := True;
-- Otherwise, we go ahead and convert the value in bits, and
-- set SU_Convert_Required to True to ensure that the final
-- value is indeed properly converted.
else
Size := (Dynamic, Make_Integer_Literal (Loc, Size.Val));
SU_Convert_Required := True;
end if;
end if;
Discrimify (Lo);
Discrimify (Hi);
-- Length is hi-lo+1
Len := Compute_Length (Lo, Hi);
-- If Len isn't a Length attribute, then its range needs to be
-- checked a possible Max with zero needs to be computed.
if Nkind (Len) /= N_Attribute_Reference
or else Attribute_Name (Len) /= Name_Length
then
declare
OK : Boolean;
LLo : Uint;
LHi : Uint;
begin
-- Check possible range of Len
Set_Parent (Len, E);
Determine_Range (Len, OK, LLo, LHi);
Len := Convert_To (Standard_Unsigned, Len);
-- If range definitely flat or superflat, result size is 0
if OK and then LHi <= 0 then
Set_Esize (E, Uint_0);
Set_RM_Size (E, Uint_0);
return;
end if;
-- If we cannot verify that range cannot be super-flat, we
-- need a max with zero, since length cannot be negative.
if not OK or else LLo < 0 then
Len :=
Make_Attribute_Reference (Loc,
Prefix =>
New_Occurrence_Of (Standard_Unsigned, Loc),
Attribute_Name => Name_Max,
Expressions => New_List (
Make_Integer_Literal (Loc, 0),
Len));
end if;
end;
end if;
-- At this stage, Len has the expression for the length
Size.Nod :=
Assoc_Multiply (Loc,
Left_Opnd => Size.Nod,
Right_Opnd => Len);
end if;
Next_Index (Indx);
end loop;
-- Here after processing all bounds to set sizes. If the value is a
-- constant, then it is bits, and the only thing we need to do is to
-- check against explicit given size and do alignment adjust.
if Size.Status = Const then
Set_And_Check_Static_Size (E, Size.Val, Size.Val);
Adjust_Esize_Alignment (E);
-- Case where the value is dynamic
else
-- Do convert from bits to SU's if needed
if SU_Convert_Required then
-- The expression required is:
-- (Size.Nod + Storage_Divisor - 1) / Storage_Divisor
Size.Nod :=
Make_Op_Divide (Loc,
Left_Opnd =>
Make_Op_Add (Loc,
Left_Opnd => Size.Nod,
Right_Opnd => Make_Integer_Literal
(Loc, Storage_Divisor - 1)),
Right_Opnd => Make_Integer_Literal (Loc, Storage_Divisor));
end if;
-- If the array entity is not declared at the library level and its
-- not nested within a subprogram that is marked for inlining, then
-- we request that the size expression be encapsulated in a function.
-- Since this expression is not needed in most cases, we prefer not
-- to incur the overhead of the computation on calls to the enclosing
-- subprogram except for subprograms that require the size.
if not Is_Library_Level_Entity (E) then
Make_Size_Function := True;
declare
Parent_Subp : Entity_Id := Enclosing_Subprogram (E);
begin
while Present (Parent_Subp) loop
if Is_Inlined (Parent_Subp) then
Make_Size_Function := False;
exit;
end if;
Parent_Subp := Enclosing_Subprogram (Parent_Subp);
end loop;
end;
end if;
-- Now set the dynamic size (the Value_Size is always the same as the
-- Object_Size for arrays whose length is dynamic).
-- ??? If Size.Status = Dynamic, Vtyp will not have been set.
-- The added initialization sets it to Empty now, but is this
-- correct?
Set_Esize
(E,
SO_Ref_From_Expr
(Size.Nod, Insert_Typ, Vtyp, Make_Func => Make_Size_Function));
Set_RM_Size (E, Esize (E));
end if;
end Layout_Array_Type;
------------------------------------------
-- Compute_Size_Depends_On_Discriminant --
------------------------------------------
procedure Compute_Size_Depends_On_Discriminant (E : Entity_Id) is
Indx : Node_Id;
Ityp : Entity_Id;
Lo : Node_Id;
Hi : Node_Id;
Res : Boolean := False;
begin
-- Loop to process array indexes
Indx := First_Index (E);
while Present (Indx) loop
Ityp := Etype (Indx);
-- If an index of the array is a generic formal type then there is
-- no point in determining a size for the array type.
if Is_Generic_Type (Ityp) then
return;
end if;
Lo := Type_Low_Bound (Ityp);
Hi := Type_High_Bound (Ityp);
if (Nkind (Lo) = N_Identifier
and then Ekind (Entity (Lo)) = E_Discriminant)
or else
(Nkind (Hi) = N_Identifier
and then Ekind (Entity (Hi)) = E_Discriminant)
then
Res := True;
end if;
Next_Index (Indx);
end loop;
if Res then
Set_Size_Depends_On_Discriminant (E);
end if;
end Compute_Size_Depends_On_Discriminant;
-------------------
-- Layout_Object --
-------------------
procedure Layout_Object (E : Entity_Id) is
T : constant Entity_Id := Etype (E);
begin
-- Nothing to do if backend does layout
if not Frontend_Layout_On_Target then
return;
end if;
-- Set size if not set for object and known for type. Use the RM_Size if
-- that is known for the type and Esize is not.
if Unknown_Esize (E) then
if Known_Esize (T) then
Set_Esize (E, Esize (T));
elsif Known_RM_Size (T) then
Set_Esize (E, RM_Size (T));
end if;
end if;
-- Set alignment from type if unknown and type alignment known
if Unknown_Alignment (E) and then Known_Alignment (T) then
Set_Alignment (E, Alignment (T));
end if;
-- Make sure size and alignment are consistent
Adjust_Esize_Alignment (E);
-- Final adjustment, if we don't know the alignment, and the Esize was
-- not set by an explicit Object_Size attribute clause, then we reset
-- the Esize to unknown, since we really don't know it.
if Unknown_Alignment (E) and then not Has_Size_Clause (E) then
Set_Esize (E, Uint_0);
end if;
end Layout_Object;
------------------------
-- Layout_Record_Type --
------------------------
procedure Layout_Record_Type (E : Entity_Id) is
Loc : constant Source_Ptr := Sloc (E);
Decl : Node_Id;
Comp : Entity_Id;
-- Current component being laid out
Prev_Comp : Entity_Id;
-- Previous laid out component
procedure Get_Next_Component_Location
(Prev_Comp : Entity_Id;
Align : Uint;
New_Npos : out SO_Ref;
New_Fbit : out SO_Ref;
New_NPMax : out SO_Ref;
Force_SU : Boolean);
-- Given the previous component in Prev_Comp, which is already laid
-- out, and the alignment of the following component, lays out the
-- following component, and returns its starting position in New_Npos
-- (Normalized_Position value), New_Fbit (Normalized_First_Bit value),
-- and New_NPMax (Normalized_Position_Max value). If Prev_Comp is empty
-- (no previous component is present), then New_Npos, New_Fbit and
-- New_NPMax are all set to zero on return. This procedure is also
-- used to compute the size of a record or variant by giving it the
-- last component, and the record alignment. Force_SU is used to force
-- the new component location to be aligned on a storage unit boundary,
-- even in a packed record, False means that the new position does not
-- need to be bumped to a storage unit boundary, True means a storage
-- unit boundary is always required.
procedure Layout_Component (Comp : Entity_Id; Prev_Comp : Entity_Id);
-- Lays out component Comp, given Prev_Comp, the previously laid-out
-- component (Prev_Comp = Empty if no components laid out yet). The
-- alignment of the record itself is also updated if needed. Both
-- Comp and Prev_Comp can be either components or discriminants.
procedure Layout_Components
(From : Entity_Id;
To : Entity_Id;
Esiz : out SO_Ref;
RM_Siz : out SO_Ref);
-- This procedure lays out the components of the given component list
-- which contains the components starting with From and ending with To.
-- The Next_Entity chain is used to traverse the components. On entry,
-- Prev_Comp is set to the component preceding the list, so that the
-- list is laid out after this component. Prev_Comp is set to Empty if
-- the component list is to be laid out starting at the start of the
-- record. On return, the components are all laid out, and Prev_Comp is
-- set to the last laid out component. On return, Esiz is set to the
-- resulting Object_Size value, which is the length of the record up
-- to and including the last laid out entity. For Esiz, the value is
-- adjusted to match the alignment of the record. RM_Siz is similarly
-- set to the resulting Value_Size value, which is the same length, but
-- not adjusted to meet the alignment. Note that in the case of variant
-- records, Esiz represents the maximum size.
procedure Layout_Non_Variant_Record;
-- Procedure called to lay out a non-variant record type or subtype
procedure Layout_Variant_Record;
-- Procedure called to lay out a variant record type. Decl is set to the
-- full type declaration for the variant record.
---------------------------------
-- Get_Next_Component_Location --
---------------------------------
procedure Get_Next_Component_Location
(Prev_Comp : Entity_Id;
Align : Uint;
New_Npos : out SO_Ref;
New_Fbit : out SO_Ref;
New_NPMax : out SO_Ref;
Force_SU : Boolean)
is
begin
-- No previous component, return zero position
if No (Prev_Comp) then
New_Npos := Uint_0;
New_Fbit := Uint_0;
New_NPMax := Uint_0;
return;
end if;
-- Here we have a previous component
declare
Loc : constant Source_Ptr := Sloc (Prev_Comp);
Old_Npos : constant SO_Ref := Normalized_Position (Prev_Comp);
Old_Fbit : constant SO_Ref := Normalized_First_Bit (Prev_Comp);
Old_NPMax : constant SO_Ref := Normalized_Position_Max (Prev_Comp);
Old_Esiz : constant SO_Ref := Esize (Prev_Comp);
Old_Maxsz : Node_Id;
-- Expression representing maximum size of previous component
begin
-- Case where previous field had a dynamic size
if Is_Dynamic_SO_Ref (Esize (Prev_Comp)) then
-- If the previous field had a dynamic length, then it is
-- required to occupy an integral number of storage units,
-- and start on a storage unit boundary. This means that
-- the Normalized_First_Bit value is zero in the previous
-- component, and the new value is also set to zero.
New_Fbit := Uint_0;
-- In this case, the new position is given by an expression
-- that is the sum of old normalized position and old size.
New_Npos :=
SO_Ref_From_Expr
(Assoc_Add (Loc,
Left_Opnd =>
Expr_From_SO_Ref (Loc, Old_Npos),
Right_Opnd =>
Expr_From_SO_Ref (Loc, Old_Esiz, Prev_Comp)),
Ins_Type => E,
Vtype => E);
-- Get maximum size of previous component
if Size_Depends_On_Discriminant (Etype (Prev_Comp)) then
Old_Maxsz := Get_Max_SU_Size (Etype (Prev_Comp));
else
Old_Maxsz := Expr_From_SO_Ref (Loc, Old_Esiz, Prev_Comp);
end if;
-- Now we can compute the new max position. If the max size
-- is static and the old position is static, then we can
-- compute the new position statically.
if Nkind (Old_Maxsz) = N_Integer_Literal
and then Known_Static_Normalized_Position_Max (Prev_Comp)
then
New_NPMax := Old_NPMax + Intval (Old_Maxsz);
-- Otherwise new max position is dynamic
else
New_NPMax :=
SO_Ref_From_Expr
(Assoc_Add (Loc,
Left_Opnd => Expr_From_SO_Ref (Loc, Old_NPMax),
Right_Opnd => Old_Maxsz),
Ins_Type => E,
Vtype => E);
end if;
-- Previous field has known static Esize
else
New_Fbit := Old_Fbit + Old_Esiz;
-- Bump New_Fbit to storage unit boundary if required
if New_Fbit /= 0 and then Force_SU then
New_Fbit := (New_Fbit + SSU - 1) / SSU * SSU;
end if;
-- If old normalized position is static, we can go ahead and
-- compute the new normalized position directly.
if Known_Static_Normalized_Position (Prev_Comp) then
New_Npos := Old_Npos;
if New_Fbit >= SSU then
New_Npos := New_Npos + New_Fbit / SSU;
New_Fbit := New_Fbit mod SSU;
end if;
-- Bump alignment if stricter than prev
if Align > Alignment (Etype (Prev_Comp)) then
New_Npos := (New_Npos + Align - 1) / Align * Align;
end if;
-- The max position is always equal to the position if
-- the latter is static, since arrays depending on the
-- values of discriminants never have static sizes.
New_NPMax := New_Npos;
return;
-- Case of old normalized position is dynamic
else
-- If new bit position is within the current storage unit,
-- we can just copy the old position as the result position
-- (we have already set the new first bit value).
if New_Fbit < SSU then
New_Npos := Old_Npos;
New_NPMax := Old_NPMax;
-- If new bit position is past the current storage unit, we
-- need to generate a new dynamic value for the position
-- ??? need to deal with alignment
else
New_Npos :=
SO_Ref_From_Expr
(Assoc_Add (Loc,
Left_Opnd => Expr_From_SO_Ref (Loc, Old_Npos),
Right_Opnd =>
Make_Integer_Literal (Loc,
Intval => New_Fbit / SSU)),
Ins_Type => E,
Vtype => E);
New_NPMax :=
SO_Ref_From_Expr
(Assoc_Add (Loc,
Left_Opnd => Expr_From_SO_Ref (Loc, Old_NPMax),
Right_Opnd =>
Make_Integer_Literal (Loc,
Intval => New_Fbit / SSU)),
Ins_Type => E,
Vtype => E);
New_Fbit := New_Fbit mod SSU;
end if;
end if;
end if;
end;
end Get_Next_Component_Location;
----------------------
-- Layout_Component --
----------------------
procedure Layout_Component (Comp : Entity_Id; Prev_Comp : Entity_Id) is
Ctyp : constant Entity_Id := Etype (Comp);
ORC : constant Entity_Id := Original_Record_Component (Comp);
Npos : SO_Ref;
Fbit : SO_Ref;
NPMax : SO_Ref;
Forc : Boolean;
begin
-- Increase alignment of record if necessary. Note that we do not
-- do this for packed records, which have an alignment of one by
-- default, or for records for which an explicit alignment was
-- specified with an alignment clause.
if not Is_Packed (E)
and then not Has_Alignment_Clause (E)
and then Alignment (Ctyp) > Alignment (E)
then
Set_Alignment (E, Alignment (Ctyp));
end if;
-- If original component set, then use same layout
if Present (ORC) and then ORC /= Comp then
Set_Normalized_Position (Comp, Normalized_Position (ORC));
Set_Normalized_First_Bit (Comp, Normalized_First_Bit (ORC));
Set_Normalized_Position_Max (Comp, Normalized_Position_Max (ORC));
Set_Component_Bit_Offset (Comp, Component_Bit_Offset (ORC));
Set_Esize (Comp, Esize (ORC));
return;
end if;
-- Parent field is always at start of record, this will overlap
-- the actual fields that are part of the parent, and that's fine
if Chars (Comp) = Name_uParent then
Set_Normalized_Position (Comp, Uint_0);
Set_Normalized_First_Bit (Comp, Uint_0);
Set_Normalized_Position_Max (Comp, Uint_0);
Set_Component_Bit_Offset (Comp, Uint_0);
Set_Esize (Comp, Esize (Ctyp));
return;
end if;
-- Check case of type of component has a scope of the record we are
-- laying out. When this happens, the type in question is an Itype
-- that has not yet been laid out (that's because such types do not
-- get frozen in the normal manner, because there is no place for
-- the freeze nodes).
if Scope (Ctyp) = E then
Layout_Type (Ctyp);
end if;
-- If component already laid out, then we are done
if Known_Normalized_Position (Comp) then
return;
end if;
-- Set size of component from type. We use the Esize except in a
-- packed record, where we use the RM_Size (since that is what the
-- RM_Size value, as distinct from the Object_Size is useful for).
if Is_Packed (E) then
Set_Esize (Comp, RM_Size (Ctyp));
else
Set_Esize (Comp, Esize (Ctyp));
end if;
-- Compute the component position from the previous one. See if
-- current component requires being on a storage unit boundary.
-- If record is not packed, we always go to a storage unit boundary
if not Is_Packed (E) then
Forc := True;
-- Packed cases
else
-- Elementary types do not need SU boundary in packed record
if Is_Elementary_Type (Ctyp) then
Forc := False;
-- Packed array types with a modular packed array type do not
-- force a storage unit boundary (since the code generation
-- treats these as equivalent to the underlying modular type),
elsif Is_Array_Type (Ctyp)
and then Is_Bit_Packed_Array (Ctyp)
and then Is_Modular_Integer_Type (Packed_Array_Impl_Type (Ctyp))
then
Forc := False;
-- Record types with known length less than or equal to the length
-- of long long integer can also be unaligned, since they can be
-- treated as scalars.
elsif Is_Record_Type (Ctyp)
and then not Is_Dynamic_SO_Ref (Esize (Ctyp))
and then Esize (Ctyp) <= Esize (Standard_Long_Long_Integer)
then
Forc := False;
-- All other cases force a storage unit boundary, even when packed
else
Forc := True;
end if;
end if;
-- Now get the next component location
Get_Next_Component_Location
(Prev_Comp, Alignment (Ctyp), Npos, Fbit, NPMax, Forc);
Set_Normalized_Position (Comp, Npos);
Set_Normalized_First_Bit (Comp, Fbit);
Set_Normalized_Position_Max (Comp, NPMax);
-- Set Component_Bit_Offset in the static case
if Known_Static_Normalized_Position (Comp)
and then Known_Normalized_First_Bit (Comp)
then
Set_Component_Bit_Offset (Comp, SSU * Npos + Fbit);
end if;
end Layout_Component;
-----------------------
-- Layout_Components --
-----------------------
procedure Layout_Components
(From : Entity_Id;
To : Entity_Id;
Esiz : out SO_Ref;
RM_Siz : out SO_Ref)
is
End_Npos : SO_Ref;
End_Fbit : SO_Ref;
End_NPMax : SO_Ref;
begin
-- Only lay out components if there are some to lay out
if Present (From) then
-- Lay out components with no component clauses
Comp := From;
loop
if Ekind (Comp) = E_Component
or else Ekind (Comp) = E_Discriminant
then
-- The compatibility of component clauses with composite
-- types isn't checked in Sem_Ch13, so we check it here.
if Present (Component_Clause (Comp)) then
if Is_Composite_Type (Etype (Comp))
and then Esize (Comp) < RM_Size (Etype (Comp))
then
Error_Msg_Uint_1 := RM_Size (Etype (Comp));
Error_Msg_NE
("size for & too small, minimum allowed is ^",
Component_Clause (Comp),
Comp);
end if;
else
Layout_Component (Comp, Prev_Comp);
Prev_Comp := Comp;
end if;
end if;
exit when Comp = To;
Next_Entity (Comp);
end loop;
end if;
-- Set size fields, both are zero if no components
if No (Prev_Comp) then
Esiz := Uint_0;
RM_Siz := Uint_0;
-- If record subtype with non-static discriminants, then we don't
-- know which variant will be the one which gets chosen. We don't
-- just want to set the maximum size from the base, because the
-- size should depend on the particular variant.
-- What we do is to use the RM_Size of the base type, which has
-- the necessary conditional computation of the size, using the
-- size information for the particular variant chosen. Records
-- with default discriminants for example have an Esize that is
-- set to the maximum of all variants, but that's not what we
-- want for a constrained subtype.
elsif Ekind (E) = E_Record_Subtype
and then not Has_Static_Discriminants (E)
then
declare
BT : constant Node_Id := Base_Type (E);
begin
Esiz := RM_Size (BT);
RM_Siz := RM_Size (BT);
Set_Alignment (E, Alignment (BT));
end;
else
-- First the object size, for which we align past the last field
-- to the alignment of the record (the object size is required to
-- be a multiple of the alignment).
Get_Next_Component_Location
(Prev_Comp,
Alignment (E),
End_Npos,
End_Fbit,
End_NPMax,
Force_SU => True);
-- If the resulting normalized position is a dynamic reference,
-- then the size is dynamic, and is stored in storage units. In
-- this case, we set the RM_Size to the same value, it is simply
-- not worth distinguishing Esize and RM_Size values in the
-- dynamic case, since the RM has nothing to say about them.
-- Note that a size cannot have been given in this case, since
-- size specifications cannot be given for variable length types.
declare
Align : constant Uint := Alignment (E);
begin
if Is_Dynamic_SO_Ref (End_Npos) then
RM_Siz := End_Npos;
-- Set the Object_Size allowing for the alignment. In the
-- dynamic case, we must do the actual runtime computation.
-- We can skip this in the non-packed record case if the
-- last component has a smaller alignment than the overall
-- record alignment.
if Is_Dynamic_SO_Ref (End_NPMax) then
Esiz := End_NPMax;
if Is_Packed (E)
or else Alignment (Etype (Prev_Comp)) < Align
then
-- The expression we build is:
-- (expr + align - 1) / align * align
Esiz :=
SO_Ref_From_Expr
(Expr =>
Make_Op_Multiply (Loc,
Left_Opnd =>
Make_Op_Divide (Loc,
Left_Opnd =>
Make_Op_Add (Loc,
Left_Opnd =>
Expr_From_SO_Ref (Loc, Esiz),
Right_Opnd =>
Make_Integer_Literal (Loc,
Intval => Align - 1)),
Right_Opnd =>
Make_Integer_Literal (Loc, Align)),
Right_Opnd =>
Make_Integer_Literal (Loc, Align)),
Ins_Type => E,
Vtype => E);
end if;
-- Here Esiz is static, so we can adjust the alignment
-- directly go give the required aligned value.
else
Esiz := (End_NPMax + Align - 1) / Align * Align * SSU;
end if;
-- Case where computed size is static
else
-- The ending size was computed in Npos in storage units,
-- but the actual size is stored in bits, so adjust
-- accordingly. We also adjust the size to match the
-- alignment here.
Esiz := (End_NPMax + Align - 1) / Align * Align * SSU;
-- Compute the resulting Value_Size (RM_Size). For this
-- purpose we do not force alignment of the record or
-- storage size alignment of the result.
Get_Next_Component_Location
(Prev_Comp,
Uint_0,
End_Npos,
End_Fbit,
End_NPMax,
Force_SU => False);
RM_Siz := End_Npos * SSU + End_Fbit;
Set_And_Check_Static_Size (E, Esiz, RM_Siz);
end if;
end;
end if;
end Layout_Components;
-------------------------------
-- Layout_Non_Variant_Record --
-------------------------------
procedure Layout_Non_Variant_Record is
Esiz : SO_Ref;
RM_Siz : SO_Ref;
begin
Layout_Components (First_Entity (E), Last_Entity (E), Esiz, RM_Siz);
Set_Esize (E, Esiz);
Set_RM_Size (E, RM_Siz);
end Layout_Non_Variant_Record;
---------------------------
-- Layout_Variant_Record --
---------------------------
procedure Layout_Variant_Record is
Tdef : constant Node_Id := Type_Definition (Decl);
First_Discr : Entity_Id;
Last_Discr : Entity_Id;
Esiz : SO_Ref;
RM_Siz : SO_Ref;
pragma Warnings (Off, SO_Ref);
RM_Siz_Expr : Node_Id := Empty;
-- Expression for the evolving RM_Siz value. This is typically an if
-- expression which involves tests of discriminant values that are
-- formed as references to the entity V. At the end of scanning all
-- the components, a suitable function is constructed in which V is
-- the parameter.
-----------------------
-- Local Subprograms --
-----------------------
procedure Layout_Component_List
(Clist : Node_Id;
Esiz : out SO_Ref;
RM_Siz_Expr : out Node_Id);
-- Recursive procedure, called to lay out one component list Esiz
-- and RM_Siz_Expr are set to the Object_Size and Value_Size values
-- respectively representing the record size up to and including the
-- last component in the component list (including any variants in
-- this component list). RM_Siz_Expr is returned as an expression
-- which may in the general case involve some references to the
-- discriminants of the current record value, referenced by selecting
-- from the entity V.
---------------------------
-- Layout_Component_List --
---------------------------
procedure Layout_Component_List
(Clist : Node_Id;
Esiz : out SO_Ref;
RM_Siz_Expr : out Node_Id)
is
Citems : constant List_Id := Component_Items (Clist);
Vpart : constant Node_Id := Variant_Part (Clist);
Prv : Node_Id;
Var : Node_Id;
RM_Siz : Uint;
RMS_Ent : Entity_Id;
begin
if Is_Non_Empty_List (Citems) then
Layout_Components
(From => Defining_Identifier (First (Citems)),
To => Defining_Identifier (Last (Citems)),
Esiz => Esiz,
RM_Siz => RM_Siz);
else
Layout_Components (Empty, Empty, Esiz, RM_Siz);
end if;
-- Case where no variants are present in the component list
if No (Vpart) then
-- The Esiz value has been correctly set by the call to
-- Layout_Components, so there is nothing more to be done.
-- For RM_Siz, we have an SO_Ref value, which we must convert
-- to an appropriate expression.
if Is_Static_SO_Ref (RM_Siz) then
RM_Siz_Expr :=
Make_Integer_Literal (Loc,
Intval => RM_Siz);
else
RMS_Ent := Get_Dynamic_SO_Entity (RM_Siz);
-- If the size is represented by a function, then we create
-- an appropriate function call using V as the parameter to
-- the call.
if Is_Discrim_SO_Function (RMS_Ent) then
RM_Siz_Expr :=
Make_Function_Call (Loc,
Name => New_Occurrence_Of (RMS_Ent, Loc),
Parameter_Associations => New_List (
Make_Identifier (Loc, Vname)));
-- If the size is represented by a constant, then the
-- expression we want is a reference to this constant
else
RM_Siz_Expr := New_Occurrence_Of (RMS_Ent, Loc);
end if;
end if;
-- Case where variants are present in this component list
else
declare
EsizV : SO_Ref;
RM_SizV : Node_Id;
Dchoice : Node_Id;
Discrim : Node_Id;
Dtest : Node_Id;
D_List : List_Id;
D_Entity : Entity_Id;
begin
RM_Siz_Expr := Empty;
Prv := Prev_Comp;
Var := Last (Variants (Vpart));
while Present (Var) loop
Prev_Comp := Prv;
Layout_Component_List
(Component_List (Var), EsizV, RM_SizV);
-- Set the Object_Size. If this is the first variant,
-- we just set the size of this first variant.
if Var = Last (Variants (Vpart)) then
Esiz := EsizV;
-- Otherwise the Object_Size is formed as a maximum
-- of Esiz so far from previous variants, and the new
-- Esiz value from the variant we just processed.
-- If both values are static, we can just compute the
-- maximum directly to save building junk nodes.
elsif not Is_Dynamic_SO_Ref (Esiz)
and then not Is_Dynamic_SO_Ref (EsizV)
then
Esiz := UI_Max (Esiz, EsizV);
-- If either value is dynamic, then we have to generate
-- an appropriate Standard_Unsigned'Max attribute call.
-- If one of the values is static then it needs to be
-- converted from bits to storage units to be compatible
-- with the dynamic value.
else
if Is_Static_SO_Ref (Esiz) then
Esiz := (Esiz + SSU - 1) / SSU;
end if;
if Is_Static_SO_Ref (EsizV) then
EsizV := (EsizV + SSU - 1) / SSU;
end if;
Esiz :=
SO_Ref_From_Expr
(Make_Attribute_Reference (Loc,
Attribute_Name => Name_Max,
Prefix =>
New_Occurrence_Of (Standard_Unsigned, Loc),
Expressions => New_List (
Expr_From_SO_Ref (Loc, Esiz),
Expr_From_SO_Ref (Loc, EsizV))),
Ins_Type => E,
Vtype => E);
end if;
-- Now deal with Value_Size (RM_Siz). We are aiming at
-- an expression that looks like:
-- if xxDx (V.disc) then rmsiz1
-- else if xxDx (V.disc) then rmsiz2
-- else ...
-- Where rmsiz1, rmsiz2... are the RM_Siz values for the
-- individual variants, and xxDx are the discriminant
-- checking functions generated for the variant type.
-- If this is the first variant, we simply set the result
-- as the expression. Note that this takes care of the
-- others case.
if No (RM_Siz_Expr) then
-- If this is the only variant and the size is a
-- literal, then use bit size as is, otherwise convert
-- to storage units and continue to the next variant.
if No (Prev (Var))
and then Nkind (RM_SizV) = N_Integer_Literal
then
RM_Siz_Expr := RM_SizV;
else
RM_Siz_Expr := Bits_To_SU (RM_SizV);
end if;
-- Otherwise construct the appropriate test
else
-- The test to be used in general is a call to the
-- discriminant checking function. However, it is
-- definitely worth special casing the very common
-- case where a single value is involved.
Dchoice := First (Discrete_Choices (Var));
if No (Next (Dchoice))
and then Nkind (Dchoice) /= N_Range
then
-- Discriminant to be tested
Discrim :=
Make_Selected_Component (Loc,
Prefix =>
Make_Identifier (Loc, Vname),
Selector_Name =>
New_Occurrence_Of
(Entity (Name (Vpart)), Loc));
Dtest :=
Make_Op_Eq (Loc,
Left_Opnd => Discrim,
Right_Opnd => New_Copy (Dchoice));
-- Generate a call to the discriminant-checking
-- function for the variant. Note that the result
-- has to be complemented since the function returns
-- False when the passed discriminant value matches.
else
-- The checking function takes all of the type's
-- discriminants as parameters, so a list of all
-- the selected discriminants must be constructed.
D_List := New_List;
D_Entity := First_Discriminant (E);
while Present (D_Entity) loop
Append_To (D_List,
Make_Selected_Component (Loc,
Prefix =>
Make_Identifier (Loc, Vname),
Selector_Name =>
New_Occurrence_Of (D_Entity, Loc)));
D_Entity := Next_Discriminant (D_Entity);
end loop;
Dtest :=
Make_Op_Not (Loc,
Right_Opnd =>
Make_Function_Call (Loc,
Name =>
New_Occurrence_Of
(Dcheck_Function (Var), Loc),
Parameter_Associations =>
D_List));
end if;
RM_Siz_Expr :=
Make_If_Expression (Loc,
Expressions =>
New_List
(Dtest, Bits_To_SU (RM_SizV), RM_Siz_Expr));
end if;
Prev (Var);
end loop;
end;
end if;
end Layout_Component_List;
Others_Present : Boolean;
pragma Warnings (Off, Others_Present);
-- Indicates others present, not used in this case
procedure Non_Static_Choice_Error (Choice : Node_Id);
-- Error routine invoked by the generic instantiation below when
-- the variant part has a nonstatic choice.
package Variant_Choices_Processing is new
Generic_Check_Choices
(Process_Empty_Choice => No_OP,
Process_Non_Static_Choice => Non_Static_Choice_Error,
Process_Associated_Node => No_OP);
use Variant_Choices_Processing;
-----------------------------
-- Non_Static_Choice_Error --
-----------------------------
procedure Non_Static_Choice_Error (Choice : Node_Id) is
begin
Flag_Non_Static_Expr
("choice given in case expression is not static!", Choice);
end Non_Static_Choice_Error;
-- Start of processing for Layout_Variant_Record
begin
-- Call Check_Choices here to ensure that Others_Discrete_Choices
-- gets set on any 'others' choice before the discriminant-checking
-- functions are generated. Otherwise the function for the 'others'
-- alternative will unconditionally return True, causing discriminant
-- checks to fail. However, Check_Choices is now normally delayed
-- until the type's freeze entity is processed, due to requirements
-- coming from subtype predicates, so doing it at this point is
-- probably not right in general, but it's not clear how else to deal
-- with this situation. Perhaps we should only generate declarations
-- for the checking functions here, and somehow delay generation of
-- their bodies, but that would be a nontrivial change. ???
declare
VP : constant Node_Id :=
Variant_Part (Component_List (Type_Definition (Decl)));
begin
Check_Choices
(VP, Variants (VP), Etype (Name (VP)), Others_Present);
end;
-- We need the discriminant checking functions, since we generate
-- calls to these functions for the RM_Size expression, so make
-- sure that these functions have been constructed in time.
Build_Discr_Checking_Funcs (Decl);
-- Lay out the discriminants
First_Discr := First_Discriminant (E);
Last_Discr := First_Discr;
while Present (Next_Discriminant (Last_Discr)) loop
Next_Discriminant (Last_Discr);
end loop;
Layout_Components
(From => First_Discr,
To => Last_Discr,
Esiz => Esiz,
RM_Siz => RM_Siz);
-- Lay out the main component list (this will make recursive calls
-- to lay out all component lists nested within variants).
Layout_Component_List (Component_List (Tdef), Esiz, RM_Siz_Expr);
Set_Esize (E, Esiz);
-- If the RM_Size is a literal, set its value
if Nkind (RM_Siz_Expr) = N_Integer_Literal then
Set_RM_Size (E, Intval (RM_Siz_Expr));
-- Otherwise we construct a dynamic SO_Ref
else
Set_RM_Size (E,
SO_Ref_From_Expr
(RM_Siz_Expr,
Ins_Type => E,
Vtype => E));
end if;
end Layout_Variant_Record;
-- Start of processing for Layout_Record_Type
begin
-- If this is a cloned subtype, just copy the size fields from the
-- original, nothing else needs to be done in this case, since the
-- components themselves are all shared.
if Ekind_In (E, E_Record_Subtype, E_Class_Wide_Subtype)
and then Present (Cloned_Subtype (E))
then
Set_Esize (E, Esize (Cloned_Subtype (E)));
Set_RM_Size (E, RM_Size (Cloned_Subtype (E)));
Set_Alignment (E, Alignment (Cloned_Subtype (E)));
-- Another special case, class-wide types. The RM says that the size
-- of such types is implementation defined (RM 13.3(48)). What we do
-- here is to leave the fields set as unknown values, and the backend
-- determines the actual behavior.
elsif Ekind (E) = E_Class_Wide_Type then
null;
-- All other cases
else
-- Initialize alignment conservatively to 1. This value will be
-- increased as necessary during processing of the record.
if Unknown_Alignment (E) then
Set_Alignment (E, Uint_1);
end if;
-- Initialize previous component. This is Empty unless there are
-- components which have already been laid out by component clauses.
-- If there are such components, we start our lay out of the
-- remaining components following the last such component.
Prev_Comp := Empty;
Comp := First_Component_Or_Discriminant (E);
while Present (Comp) loop
if Present (Component_Clause (Comp)) then
if No (Prev_Comp)
or else
Component_Bit_Offset (Comp) >
Component_Bit_Offset (Prev_Comp)
then
Prev_Comp := Comp;
end if;
end if;
Next_Component_Or_Discriminant (Comp);
end loop;
-- We have two separate circuits, one for non-variant records and
-- one for variant records. For non-variant records, we simply go
-- through the list of components. This handles all the non-variant
-- cases including those cases of subtypes where there is no full
-- type declaration, so the tree cannot be used to drive the layout.
-- For variant records, we have to drive the layout from the tree
-- since we need to understand the variant structure in this case.
if Present (Full_View (E)) then
Decl := Declaration_Node (Full_View (E));
else
Decl := Declaration_Node (E);
end if;
-- Scan all the components
if Nkind (Decl) = N_Full_Type_Declaration
and then Has_Discriminants (E)
and then Nkind (Type_Definition (Decl)) = N_Record_Definition
and then Present (Component_List (Type_Definition (Decl)))
and then
Present (Variant_Part (Component_List (Type_Definition (Decl))))
then
Layout_Variant_Record;
else
Layout_Non_Variant_Record;
end if;
end if;
end Layout_Record_Type;
-----------------
-- Layout_Type --
-----------------
procedure Layout_Type (E : Entity_Id) is
Desig_Type : Entity_Id;
begin
-- For string literal types, for now, kill the size always, this is
-- because gigi does not like or need the size to be set ???
if Ekind (E) = E_String_Literal_Subtype then
Set_Esize (E, Uint_0);
Set_RM_Size (E, Uint_0);
return;
end if;
-- For access types, set size/alignment. This is system address size,
-- except for fat pointers (unconstrained array access types), where the
-- size is two times the address size, to accommodate the two pointers
-- that are required for a fat pointer (data and template). Note that
-- E_Access_Protected_Subprogram_Type is not an access type for this
-- purpose since it is not a pointer but is equivalent to a record. For
-- access subtypes, copy the size from the base type since Gigi
-- represents them the same way.
if Is_Access_Type (E) then
Desig_Type := Underlying_Type (Designated_Type (E));
-- If we only have a limited view of the type, see whether the
-- non-limited view is available.
if From_Limited_With (Designated_Type (E))
and then Ekind (Designated_Type (E)) = E_Incomplete_Type
and then Present (Non_Limited_View (Designated_Type (E)))
then
Desig_Type := Non_Limited_View (Designated_Type (E));
end if;
-- If Esize already set (e.g. by a size clause), then nothing further
-- to be done here.
if Known_Esize (E) then
null;
-- Access to subprogram is a strange beast, and we let the backend
-- figure out what is needed (it may be some kind of fat pointer,
-- including the static link for example.
elsif Is_Access_Protected_Subprogram_Type (E) then
null;
-- For access subtypes, copy the size information from base type
elsif Ekind (E) = E_Access_Subtype then
Set_Size_Info (E, Base_Type (E));
Set_RM_Size (E, RM_Size (Base_Type (E)));
-- For other access types, we use either address size, or, if a fat
-- pointer is used (pointer-to-unconstrained array case), twice the
-- address size to accommodate a fat pointer.
elsif Present (Desig_Type)
and then Is_Array_Type (Desig_Type)
and then not Is_Constrained (Desig_Type)
and then not Has_Completion_In_Body (Desig_Type)
-- Debug Flag -gnatd6 says make all pointers to unconstrained thin
and then not Debug_Flag_6
then
Init_Size (E, 2 * System_Address_Size);
-- Check for bad convention set
if Warn_On_Export_Import
and then
(Convention (E) = Convention_C
or else
Convention (E) = Convention_CPP)
then
Error_Msg_N
("?x?this access type does not correspond to C pointer", E);
end if;
-- If the designated type is a limited view it is unanalyzed. We can
-- examine the declaration itself to determine whether it will need a
-- fat pointer.
elsif Present (Desig_Type)
and then Present (Parent (Desig_Type))
and then Nkind (Parent (Desig_Type)) = N_Full_Type_Declaration
and then Nkind (Type_Definition (Parent (Desig_Type))) =
N_Unconstrained_Array_Definition
and then not Debug_Flag_6
then
Init_Size (E, 2 * System_Address_Size);
-- Normal case of thin pointer
else
Init_Size (E, System_Address_Size);
end if;
Set_Elem_Alignment (E);
-- Scalar types: set size and alignment
elsif Is_Scalar_Type (E) then
-- For discrete types, the RM_Size and Esize must be set already,
-- since this is part of the earlier processing and the front end is
-- always required to lay out the sizes of such types (since they are
-- available as static attributes). All we do is to check that this
-- rule is indeed obeyed.
if Is_Discrete_Type (E) then
-- If the RM_Size is not set, then here is where we set it
-- Note: an RM_Size of zero looks like not set here, but this
-- is a rare case, and we can simply reset it without any harm.
if not Known_RM_Size (E) then
Set_Discrete_RM_Size (E);
end if;
-- If Esize for a discrete type is not set then set it
if not Known_Esize (E) then
declare
S : Int := 8;
begin
loop
-- If size is big enough, set it and exit
if S >= RM_Size (E) then
Init_Esize (E, S);
exit;
-- If the RM_Size is greater than 64 (happens only when
-- strange values are specified by the user, then Esize
-- is simply a copy of RM_Size, it will be further
-- refined later on)
elsif S = 64 then
Set_Esize (E, RM_Size (E));
exit;
-- Otherwise double possible size and keep trying
else
S := S * 2;
end if;
end loop;
end;
end if;
-- For non-discrete scalar types, if the RM_Size is not set, then set
-- it now to a copy of the Esize if the Esize is set.
else
if Known_Esize (E) and then Unknown_RM_Size (E) then
Set_RM_Size (E, Esize (E));
end if;
end if;
Set_Elem_Alignment (E);
-- Non-elementary (composite) types
else
-- For packed arrays, take size and alignment values from the packed
-- array type if a packed array type has been created and the fields
-- are not currently set.
if Is_Array_Type (E)
and then Present (Packed_Array_Impl_Type (E))
then
declare
PAT : constant Entity_Id := Packed_Array_Impl_Type (E);
begin
if Unknown_Esize (E) then
Set_Esize (E, Esize (PAT));
end if;
if Unknown_RM_Size (E) then
Set_RM_Size (E, RM_Size (PAT));
end if;
if Unknown_Alignment (E) then
Set_Alignment (E, Alignment (PAT));
end if;
end;
end if;
-- If Esize is set, and RM_Size is not, RM_Size is copied from Esize.
-- At least for now this seems reasonable, and is in any case needed
-- for compatibility with old versions of gigi.
if Known_Esize (E) and then Unknown_RM_Size (E) then
Set_RM_Size (E, Esize (E));
end if;
-- For array base types, set component size if object size of the
-- component type is known and is a small power of 2 (8, 16, 32, 64),
-- since this is what will always be used.
if Ekind (E) = E_Array_Type and then Unknown_Component_Size (E) then
declare
CT : constant Entity_Id := Component_Type (E);
begin
-- For some reason, access types can cause trouble, So let's
-- just do this for scalar types ???
if Present (CT)
and then Is_Scalar_Type (CT)
and then Known_Static_Esize (CT)
then
declare
S : constant Uint := Esize (CT);
begin
if Addressable (S) then
Set_Component_Size (E, S);
end if;
end;
end if;
end;
end if;
end if;
-- Lay out array and record types if front end layout set
if Frontend_Layout_On_Target then
if Is_Array_Type (E) and then not Is_Bit_Packed_Array (E) then
Layout_Array_Type (E);
elsif Is_Record_Type (E) then
Layout_Record_Type (E);
end if;
-- Case of backend layout, we still do a little in the front end
else
-- Processing for record types
if Is_Record_Type (E) then
-- Special remaining processing for record types with a known
-- size of 16, 32, or 64 bits whose alignment is not yet set.
-- For these types, we set a corresponding alignment matching
-- the size if possible, or as large as possible if not.
if Convention (E) = Convention_Ada and then not Debug_Flag_Q then
Set_Composite_Alignment (E);
end if;
-- Processing for array types
elsif Is_Array_Type (E) then
-- For arrays that are required to be atomic/VFA, we do the same
-- processing as described above for short records, since we
-- really need to have the alignment set for the whole array.
if Is_Atomic_Or_VFA (E) and then not Debug_Flag_Q then
Set_Composite_Alignment (E);
end if;
-- For unpacked array types, set an alignment of 1 if we know
-- that the component alignment is not greater than 1. The reason
-- we do this is to avoid unnecessary copying of slices of such
-- arrays when passed to subprogram parameters (see special test
-- in Exp_Ch6.Expand_Actuals).
if not Is_Packed (E) and then Unknown_Alignment (E) then
if Known_Static_Component_Size (E)
and then Component_Size (E) = 1
then
Set_Alignment (E, Uint_1);
end if;
end if;
-- We need to know whether the size depends on the value of one
-- or more discriminants to select the return mechanism. Skip if
-- errors are present, to prevent cascaded messages.
if Serious_Errors_Detected = 0 then
Compute_Size_Depends_On_Discriminant (E);
end if;
end if;
end if;
-- Final step is to check that Esize and RM_Size are compatible
if Known_Static_Esize (E) and then Known_Static_RM_Size (E) then
if Esize (E) < RM_Size (E) then
-- Esize is less than RM_Size. That's not good. First we test
-- whether this was set deliberately with an Object_Size clause
-- and if so, object to the clause.
if Has_Object_Size_Clause (E) then
Error_Msg_Uint_1 := RM_Size (E);
Error_Msg_F
("object size is too small, minimum allowed is ^",
Expression (Get_Attribute_Definition_Clause
(E, Attribute_Object_Size)));
end if;
-- Adjust Esize up to RM_Size value
declare
Size : constant Uint := RM_Size (E);
begin
Set_Esize (E, RM_Size (E));
-- For scalar types, increase Object_Size to power of 2, but
-- not less than a storage unit in any case (i.e., normally
-- this means it will be storage-unit addressable).
if Is_Scalar_Type (E) then
if Size <= System_Storage_Unit then
Init_Esize (E, System_Storage_Unit);
elsif Size <= 16 then
Init_Esize (E, 16);
elsif Size <= 32 then
Init_Esize (E, 32);
else
Set_Esize (E, (Size + 63) / 64 * 64);
end if;
-- Finally, make sure that alignment is consistent with
-- the newly assigned size.
while Alignment (E) * System_Storage_Unit < Esize (E)
and then Alignment (E) < Maximum_Alignment
loop
Set_Alignment (E, 2 * Alignment (E));
end loop;
end if;
end;
end if;
end if;
end Layout_Type;
---------------------
-- Rewrite_Integer --
---------------------
procedure Rewrite_Integer (N : Node_Id; V : Uint) is
Loc : constant Source_Ptr := Sloc (N);
Typ : constant Entity_Id := Etype (N);
begin
Rewrite (N, Make_Integer_Literal (Loc, Intval => V));
Set_Etype (N, Typ);
end Rewrite_Integer;
-------------------------------
-- Set_And_Check_Static_Size --
-------------------------------
procedure Set_And_Check_Static_Size
(E : Entity_Id;
Esiz : SO_Ref;
RM_Siz : SO_Ref)
is
SC : Node_Id;
procedure Check_Size_Too_Small (Spec : Uint; Min : Uint);
-- Spec is the number of bit specified in the size clause, and Min is
-- the minimum computed size. An error is given that the specified size
-- is too small if Spec < Min, and in this case both Esize and RM_Size
-- are set to unknown in E. The error message is posted on node SC.
procedure Check_Unused_Bits (Spec : Uint; Max : Uint);
-- Spec is the number of bits specified in the size clause, and Max is
-- the maximum computed size. A warning is given about unused bits if
-- Spec > Max. This warning is posted on node SC.
--------------------------
-- Check_Size_Too_Small --
--------------------------
procedure Check_Size_Too_Small (Spec : Uint; Min : Uint) is
begin
if Spec < Min then
Error_Msg_Uint_1 := Min;
Error_Msg_NE ("size for & too small, minimum allowed is ^", SC, E);
Init_Esize (E);
Init_RM_Size (E);
end if;
end Check_Size_Too_Small;
-----------------------
-- Check_Unused_Bits --
-----------------------
procedure Check_Unused_Bits (Spec : Uint; Max : Uint) is
begin
if Spec > Max then
Error_Msg_Uint_1 := Spec - Max;
Error_Msg_NE ("??^ bits of & unused", SC, E);
end if;
end Check_Unused_Bits;
-- Start of processing for Set_And_Check_Static_Size
begin
-- Case where Object_Size (Esize) is already set by a size clause
if Known_Static_Esize (E) then
SC := Size_Clause (E);
if No (SC) then
SC := Get_Attribute_Definition_Clause (E, Attribute_Object_Size);
end if;
-- Perform checks on specified size against computed sizes
if Present (SC) then
Check_Unused_Bits (Esize (E), Esiz);
Check_Size_Too_Small (Esize (E), RM_Siz);
end if;
end if;
-- Case where Value_Size (RM_Size) is set by specific Value_Size clause
-- (we do not need to worry about Value_Size being set by a Size clause,
-- since that will have set Esize as well, and we already took care of
-- that case).
if Known_Static_RM_Size (E) then
SC := Get_Attribute_Definition_Clause (E, Attribute_Value_Size);
-- Perform checks on specified size against computed sizes
if Present (SC) then
Check_Unused_Bits (RM_Size (E), Esiz);
Check_Size_Too_Small (RM_Size (E), RM_Siz);
end if;
end if;
-- Set sizes if unknown
if Unknown_Esize (E) then
Set_Esize (E, Esiz);
end if;
if Unknown_RM_Size (E) then
Set_RM_Size (E, RM_Siz);
end if;
end Set_And_Check_Static_Size;
-----------------------------
-- Set_Composite_Alignment --
-----------------------------
procedure Set_Composite_Alignment (E : Entity_Id) is
Siz : Uint;
Align : Nat;
begin
-- If alignment is already set, then nothing to do
if Known_Alignment (E) then
return;
end if;
-- Alignment is not known, see if we can set it, taking into account
-- the setting of the Optimize_Alignment mode.
-- If Optimize_Alignment is set to Space, then we try to give packed
-- records an aligmment of 1, unless there is some reason we can't.
if Optimize_Alignment_Space (E)
and then Is_Record_Type (E)
and then Is_Packed (E)
then
-- No effect for record with atomic/VFA components
if Is_Atomic_Or_VFA (E) then
Error_Msg_N ("Optimize_Alignment has no effect for &??", E);
if Is_Atomic (E) then
Error_Msg_N
("\pragma ignored for atomic record??", E);
else
Error_Msg_N
("\pragma ignored for bolatile full access record??", E);
end if;
return;
end if;
-- No effect if independent components
if Has_Independent_Components (E) then
Error_Msg_N ("Optimize_Alignment has no effect for &??", E);
Error_Msg_N
("\pragma ignored for record with independent components??", E);
return;
end if;
-- No effect if any component is atomic/VFA or is a by-reference type
declare
Ent : Entity_Id;
begin
Ent := First_Component_Or_Discriminant (E);
while Present (Ent) loop
if Is_By_Reference_Type (Etype (Ent))
or else Is_Atomic_Or_VFA (Etype (Ent))
or else Is_Atomic_Or_VFA (Ent)
then
Error_Msg_N ("Optimize_Alignment has no effect for &??", E);
if Is_Atomic (Etype (Ent)) or else Is_Atomic (Ent) then
Error_Msg_N
("\pragma is ignored if atomic "
& "components present??", E);
else
Error_Msg_N
("\pragma is ignored if bolatile full access "
& "components present??", E);
end if;
return;
else
Next_Component_Or_Discriminant (Ent);
end if;
end loop;
end;
-- Optimize_Alignment has no effect on variable length record
if not Size_Known_At_Compile_Time (E) then
Error_Msg_N ("Optimize_Alignment has no effect for &??", E);
Error_Msg_N ("\pragma is ignored for variable length record??", E);
return;
end if;
-- All tests passed, we can set alignment to 1
Align := 1;
-- Not a record, or not packed
else
-- The only other cases we worry about here are where the size is
-- statically known at compile time.
if Known_Static_Esize (E) then
Siz := Esize (E);
elsif Unknown_Esize (E) and then Known_Static_RM_Size (E) then
Siz := RM_Size (E);
else
return;
end if;
-- Size is known, alignment is not set
-- Reset alignment to match size if the known size is exactly 2, 4,
-- or 8 storage units.
if Siz = 2 * System_Storage_Unit then
Align := 2;
elsif Siz = 4 * System_Storage_Unit then
Align := 4;
elsif Siz = 8 * System_Storage_Unit then
Align := 8;
-- If Optimize_Alignment is set to Space, then make sure the
-- alignment matches the size, for example, if the size is 17
-- bytes then we want an alignment of 1 for the type.
elsif Optimize_Alignment_Space (E) then
if Siz mod (8 * System_Storage_Unit) = 0 then
Align := 8;
elsif Siz mod (4 * System_Storage_Unit) = 0 then
Align := 4;
elsif Siz mod (2 * System_Storage_Unit) = 0 then
Align := 2;
else
Align := 1;
end if;
-- If Optimize_Alignment is set to Time, then we reset for odd
-- "in between sizes", for example a 17 bit record is given an
-- alignment of 4.
elsif Optimize_Alignment_Time (E)
and then Siz > System_Storage_Unit
and then Siz <= 8 * System_Storage_Unit
then
if Siz <= 2 * System_Storage_Unit then
Align := 2;
elsif Siz <= 4 * System_Storage_Unit then
Align := 4;
else -- Siz <= 8 * System_Storage_Unit then
Align := 8;
end if;
-- No special alignment fiddling needed
else
return;
end if;
end if;
-- Here we have Set Align to the proposed improved value. Make sure the
-- value set does not exceed Maximum_Alignment for the target.
if Align > Maximum_Alignment then
Align := Maximum_Alignment;
end if;
-- Further processing for record types only to reduce the alignment
-- set by the above processing in some specific cases. We do not
-- do this for atomic/VFA records, since we need max alignment there,
if Is_Record_Type (E) and then not Is_Atomic_Or_VFA (E) then
-- For records, there is generally no point in setting alignment
-- higher than word size since we cannot do better than move by
-- words in any case. Omit this if we are optimizing for time,
-- since conceivably we may be able to do better.
if Align > System_Word_Size / System_Storage_Unit
and then not Optimize_Alignment_Time (E)
then
Align := System_Word_Size / System_Storage_Unit;
end if;
-- Check components. If any component requires a higher alignment,
-- then we set that higher alignment in any case. Don't do this if
-- we have Optimize_Alignment set to Space. Note that that covers
-- the case of packed records, where we already set alignment to 1.
if not Optimize_Alignment_Space (E) then
declare
Comp : Entity_Id;
begin
Comp := First_Component (E);
while Present (Comp) loop
if Known_Alignment (Etype (Comp)) then
declare
Calign : constant Uint := Alignment (Etype (Comp));
begin
-- The cases to process are when the alignment of the
-- component type is larger than the alignment we have
-- so far, and either there is no component clause for
-- the component, or the length set by the component
-- clause matches the length of the component type.
if Calign > Align
and then
(Unknown_Esize (Comp)
or else (Known_Static_Esize (Comp)
and then
Esize (Comp) =
Calign * System_Storage_Unit))
then
Align := UI_To_Int (Calign);
end if;
end;
end if;
Next_Component (Comp);
end loop;
end;
end if;
end if;
-- Set chosen alignment, and increase Esize if necessary to match the
-- chosen alignment.
Set_Alignment (E, UI_From_Int (Align));
if Known_Static_Esize (E)
and then Esize (E) < Align * System_Storage_Unit
then
Set_Esize (E, UI_From_Int (Align * System_Storage_Unit));
end if;
end Set_Composite_Alignment;
--------------------------
-- Set_Discrete_RM_Size --
--------------------------
procedure Set_Discrete_RM_Size (Def_Id : Entity_Id) is
FST : constant Entity_Id := First_Subtype (Def_Id);
begin
-- All discrete types except for the base types in standard are
-- constrained, so indicate this by setting Is_Constrained.
Set_Is_Constrained (Def_Id);
-- Set generic types to have an unknown size, since the representation
-- of a generic type is irrelevant, in view of the fact that they have
-- nothing to do with code.
if Is_Generic_Type (Root_Type (FST)) then
Set_RM_Size (Def_Id, Uint_0);
-- If the subtype statically matches the first subtype, then it is
-- required to have exactly the same layout. This is required by
-- aliasing considerations.
elsif Def_Id /= FST and then
Subtypes_Statically_Match (Def_Id, FST)
then
Set_RM_Size (Def_Id, RM_Size (FST));
Set_Size_Info (Def_Id, FST);
-- In all other cases the RM_Size is set to the minimum size. Note that
-- this routine is never called for subtypes for which the RM_Size is
-- set explicitly by an attribute clause.
else
Set_RM_Size (Def_Id, UI_From_Int (Minimum_Size (Def_Id)));
end if;
end Set_Discrete_RM_Size;
------------------------
-- Set_Elem_Alignment --
------------------------
procedure Set_Elem_Alignment (E : Entity_Id) is
begin
-- Do not set alignment for packed array types, unless we are doing
-- front end layout, because otherwise this is always handled in the
-- backend.
if Is_Packed_Array_Impl_Type (E)
and then not Frontend_Layout_On_Target
then
return;
-- If there is an alignment clause, then we respect it
elsif Has_Alignment_Clause (E) then
return;
-- If the size is not set, then don't attempt to set the alignment. This
-- happens in the backend layout case for access-to-subprogram types.
elsif not Known_Static_Esize (E) then
return;
-- For access types, do not set the alignment if the size is less than
-- the allowed minimum size. This avoids cascaded error messages.
elsif Is_Access_Type (E) and then Esize (E) < System_Address_Size then
return;
end if;
-- Here we calculate the alignment as the largest power of two multiple
-- of System.Storage_Unit that does not exceed either the object size of
-- the type, or the maximum allowed alignment.
declare
S : Int;
A : Nat;
Max_Alignment : Nat;
begin
-- The given Esize may be larger that int'last because of a previous
-- error, and the call to UI_To_Int will fail, so use default.
if Esize (E) / SSU > Ttypes.Maximum_Alignment then
S := Ttypes.Maximum_Alignment;
-- If this is an access type and the target doesn't have strict
-- alignment and we are not doing front end layout, then cap the
-- alignment to that of a regular access type. This will avoid
-- giving fat pointers twice the usual alignment for no practical
-- benefit since the misalignment doesn't really matter.
elsif Is_Access_Type (E)
and then not Target_Strict_Alignment
and then not Frontend_Layout_On_Target
then
S := System_Address_Size / SSU;
else
S := UI_To_Int (Esize (E)) / SSU;
end if;
-- If the default alignment of "double" floating-point types is
-- specifically capped, enforce the cap.
if Ttypes.Target_Double_Float_Alignment > 0
and then S = 8
and then Is_Floating_Point_Type (E)
then
Max_Alignment := Ttypes.Target_Double_Float_Alignment;
-- If the default alignment of "double" or larger scalar types is
-- specifically capped, enforce the cap.
elsif Ttypes.Target_Double_Scalar_Alignment > 0
and then S >= 8
and then Is_Scalar_Type (E)
then
Max_Alignment := Ttypes.Target_Double_Scalar_Alignment;
-- Otherwise enforce the overall alignment cap
else
Max_Alignment := Ttypes.Maximum_Alignment;
end if;
A := 1;
while 2 * A <= Max_Alignment and then 2 * A <= S loop
A := 2 * A;
end loop;
-- If alignment is currently not set, then we can safely set it to
-- this new calculated value.
if Unknown_Alignment (E) then
Init_Alignment (E, A);
-- Cases where we have inherited an alignment
-- For constructed types, always reset the alignment, these are
-- generally invisible to the user anyway, and that way we are
-- sure that no constructed types have weird alignments.
elsif not Comes_From_Source (E) then
Init_Alignment (E, A);
-- If this inherited alignment is the same as the one we computed,
-- then obviously everything is fine, and we do not need to reset it.
elsif Alignment (E) = A then
null;
else
-- Now we come to the difficult cases of subtypes for which we
-- have inherited an alignment different from the computed one.
-- We resort to the presence of alignment and size clauses to
-- guide our choices. Note that they can generally be present
-- only on the first subtype (except for Object_Size) and that
-- we need to look at the Rep_Item chain to correctly handle
-- derived types.
declare
FST : constant Entity_Id := First_Subtype (E);
function Has_Attribute_Clause
(E : Entity_Id;
Id : Attribute_Id) return Boolean;
-- Wrapper around Get_Attribute_Definition_Clause which tests
-- for the presence of the specified attribute clause.
--------------------------
-- Has_Attribute_Clause --
--------------------------
function Has_Attribute_Clause
(E : Entity_Id;
Id : Attribute_Id) return Boolean is
begin
return Present (Get_Attribute_Definition_Clause (E, Id));
end Has_Attribute_Clause;
begin
-- If the alignment comes from a clause, then we respect it.
-- Consider for example:
-- type R is new Character;
-- for R'Alignment use 1;
-- for R'Size use 16;
-- subtype S is R;
-- Here R has a specified size of 16 and a specified alignment
-- of 1, and it seems right for S to inherit both values.
if Has_Attribute_Clause (FST, Attribute_Alignment) then
null;
-- Now we come to the cases where we have inherited alignment
-- and size, and overridden the size but not the alignment.
elsif Has_Attribute_Clause (FST, Attribute_Size)
or else Has_Attribute_Clause (FST, Attribute_Object_Size)
or else Has_Attribute_Clause (E, Attribute_Object_Size)
then
-- This is tricky, it might be thought that we should try to
-- inherit the alignment, since that's what the RM implies,
-- but that leads to complex rules and oddities. Consider
-- for example:
-- type R is new Character;
-- for R'Size use 16;
-- It seems quite bogus in this case to inherit an alignment
-- of 1 from the parent type Character. Furthermore, if that
-- is what the programmer really wanted for some odd reason,
-- then he could specify the alignment directly.
-- Moreover we really don't want to inherit the alignment in
-- the case of a specified Object_Size for a subtype, since
-- there would be no way of overriding to give a reasonable
-- value (as we don't have an Object_Alignment attribute).
-- Consider for example:
-- subtype R is Character;
-- for R'Object_Size use 16;
-- If we inherit the alignment of 1, then it will be very
-- inefficient for the subtype and this cannot be fixed.
-- So we make the decision that if Size (or Object_Size) is
-- given and the alignment is not specified with a clause,
-- we reset the alignment to the appropriate value for the
-- specified size. This is a nice simple rule to implement
-- and document.
-- There is a theoretical glitch, which is that a confirming
-- size clause could now change the alignment, which, if we
-- really think that confirming rep clauses should have no
-- effect, could be seen as a no-no. However that's already
-- implemented by Alignment_Check_For_Size_Change so we do
-- not change the philosophy here.
-- Historical note: in versions prior to Nov 6th, 2011, an
-- odd distinction was made between inherited alignments
-- larger than the computed alignment (where the larger
-- alignment was inherited) and inherited alignments smaller
-- than the computed alignment (where the smaller alignment
-- was overridden). This was a dubious fix to get around an
-- ACATS problem which seems to have disappeared anyway, and
-- in any case, this peculiarity was never documented.
Init_Alignment (E, A);
-- If no Size (or Object_Size) was specified, then we have
-- inherited the object size, so we should also inherit the
-- alignment and not modify it.
else
null;
end if;
end;
end if;
end;
end Set_Elem_Alignment;
----------------------
-- SO_Ref_From_Expr --
----------------------
function SO_Ref_From_Expr
(Expr : Node_Id;
Ins_Type : Entity_Id;
Vtype : Entity_Id := Empty;
Make_Func : Boolean := False) return Dynamic_SO_Ref
is
Loc : constant Source_Ptr := Sloc (Ins_Type);
K : constant Entity_Id := Make_Temporary (Loc, 'K');
Decl : Node_Id;
Vtype_Primary_View : Entity_Id;
function Check_Node_V_Ref (N : Node_Id) return Traverse_Result;
-- Function used to check one node for reference to V
function Has_V_Ref is new Traverse_Func (Check_Node_V_Ref);
-- Function used to traverse tree to check for reference to V
----------------------
-- Check_Node_V_Ref --
----------------------
function Check_Node_V_Ref (N : Node_Id) return Traverse_Result is
begin
if Nkind (N) = N_Identifier then
if Chars (N) = Vname then
return Abandon;
else
return Skip;
end if;
else
return OK;
end if;
end Check_Node_V_Ref;
-- Start of processing for SO_Ref_From_Expr
begin
-- Case of expression is an integer literal, in this case we just
-- return the value (which must always be non-negative, since size
-- and offset values can never be negative).
if Nkind (Expr) = N_Integer_Literal then
pragma Assert (Intval (Expr) >= 0);
return Intval (Expr);
end if;
-- Case where there is a reference to V, create function
if Has_V_Ref (Expr) = Abandon then
pragma Assert (Present (Vtype));
-- Check whether Vtype is a view of a private type and ensure that
-- we use the primary view of the type (which is denoted by its
-- Etype, whether it's the type's partial or full view entity).
-- This is needed to make sure that we use the same (primary) view
-- of the type for all V formals, whether the current view of the
-- type is the partial or full view, so that types will always
-- match on calls from one size function to another.
if Has_Private_Declaration (Vtype) then
Vtype_Primary_View := Etype (Vtype);
else
Vtype_Primary_View := Vtype;
end if;
Set_Is_Discrim_SO_Function (K);
Decl :=
Make_Subprogram_Body (Loc,
Specification =>
Make_Function_Specification (Loc,
Defining_Unit_Name => K,
Parameter_Specifications => New_List (
Make_Parameter_Specification (Loc,
Defining_Identifier =>
Make_Defining_Identifier (Loc, Chars => Vname),
Parameter_Type =>
New_Occurrence_Of (Vtype_Primary_View, Loc))),
Result_Definition =>
New_Occurrence_Of (Standard_Unsigned, Loc)),
Declarations => Empty_List,
Handled_Statement_Sequence =>
Make_Handled_Sequence_Of_Statements (Loc,
Statements => New_List (
Make_Simple_Return_Statement (Loc,
Expression => Expr))));
-- The caller requests that the expression be encapsulated in a
-- parameterless function.
elsif Make_Func then
Decl :=
Make_Subprogram_Body (Loc,
Specification =>
Make_Function_Specification (Loc,
Defining_Unit_Name => K,
Parameter_Specifications => Empty_List,
Result_Definition =>
New_Occurrence_Of (Standard_Unsigned, Loc)),
Declarations => Empty_List,
Handled_Statement_Sequence =>
Make_Handled_Sequence_Of_Statements (Loc,
Statements => New_List (
Make_Simple_Return_Statement (Loc, Expression => Expr))));
-- No reference to V and function not requested, so create a constant
else
Decl :=
Make_Object_Declaration (Loc,
Defining_Identifier => K,
Object_Definition =>
New_Occurrence_Of (Standard_Unsigned, Loc),
Constant_Present => True,
Expression => Expr);
end if;
Append_Freeze_Action (Ins_Type, Decl);
Analyze (Decl);
return Create_Dynamic_SO_Ref (K);
end SO_Ref_From_Expr;
end Layout;
|
pragma Ada_2012;
pragma Style_Checks (Off);
with Interfaces.C; use Interfaces.C;
with mersenne_types_h;
package noise_h is
-- BSD 3-Clause License
-- *
-- * Copyright © 2008-2021, Jice and the libtcod contributors.
-- * 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.
-- *
-- * 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.
--
subtype TCOD_noise_type_t is unsigned;
TCOD_NOISE_PERLIN : constant unsigned := 1;
TCOD_NOISE_SIMPLEX : constant unsigned := 2;
TCOD_NOISE_WAVELET : constant unsigned := 4;
TCOD_NOISE_DEFAULT : constant unsigned := 0; -- noise.h:44
type anon1947_array1948 is array (0 .. 255) of aliased unsigned_char;
type anon1947_array1951 is array (0 .. 255, 0 .. 3) of aliased float;
type anon1947_array1952 is array (0 .. 127) of aliased float;
type TCOD_Noise is record
ndim : aliased int; -- noise.h:47
map : aliased anon1947_array1948; -- noise.h:49
buffer : aliased anon1947_array1951; -- noise.h:51
H : aliased float; -- noise.h:53
lacunarity : aliased float; -- noise.h:54
exponent : aliased anon1947_array1952; -- noise.h:55
waveletTileData : access float; -- noise.h:56
rand : access mersenne_types_h.TCOD_Random; -- noise.h:57
noise_type : aliased TCOD_noise_type_t; -- noise.h:59
end record
with Convention => C_Pass_By_Copy; -- noise.h:46
--* Randomized map of indexes into buffer
--* Random 256 x ndim buffer
-- fractal stuff
-- noise type
type TCOD_noise_t is access all TCOD_Noise; -- noise.h:61
-- create a new noise object
function TCOD_noise_new
(arg1 : int;
arg2 : float;
arg3 : float;
arg4 : mersenne_types_h.TCOD_random_t) return access TCOD_Noise -- noise.h:67
with Import => True,
Convention => C,
External_Name => "TCOD_noise_new";
-- simplified API
procedure TCOD_noise_set_type (noise : access TCOD_Noise; c_type : TCOD_noise_type_t) -- noise.h:70
with Import => True,
Convention => C,
External_Name => "TCOD_noise_set_type";
function TCOD_noise_get_ex
(noise : access TCOD_Noise;
f : access float;
c_type : TCOD_noise_type_t) return float -- noise.h:72
with Import => True,
Convention => C,
External_Name => "TCOD_noise_get_ex";
function TCOD_noise_get_fbm_ex
(noise : access TCOD_Noise;
f : access float;
octaves : float;
c_type : TCOD_noise_type_t) return float -- noise.h:74
with Import => True,
Convention => C,
External_Name => "TCOD_noise_get_fbm_ex";
function TCOD_noise_get_turbulence_ex
(noise : access TCOD_Noise;
f : access float;
octaves : float;
c_type : TCOD_noise_type_t) return float -- noise.h:77
with Import => True,
Convention => C,
External_Name => "TCOD_noise_get_turbulence_ex";
function TCOD_noise_get (noise : access TCOD_Noise; f : access float) return float -- noise.h:80
with Import => True,
Convention => C,
External_Name => "TCOD_noise_get";
function TCOD_noise_get_fbm
(noise : access TCOD_Noise;
f : access float;
octaves : float) return float -- noise.h:82
with Import => True,
Convention => C,
External_Name => "TCOD_noise_get_fbm";
function TCOD_noise_get_turbulence
(noise : access TCOD_Noise;
f : access float;
octaves : float) return float -- noise.h:84
with Import => True,
Convention => C,
External_Name => "TCOD_noise_get_turbulence";
-- delete the noise object
procedure TCOD_noise_delete (noise : access TCOD_Noise) -- noise.h:86
with Import => True,
Convention => C,
External_Name => "TCOD_noise_delete";
--*
-- Generate noise as a vectorized operation.
-- `noise` is the TCOD_Noise object to be used. Its dimensions will
-- determine how many input arrays are required.
-- `type` is which noise generator should be used.
-- Can be `TCOD_NOISE_DEFAULT` to use the type set by the TCOD_Noise object.
-- `n` is the length of the input and output arrrays.
-- `x[n]`, `y[n]`, `z[n]`, `w[n]` are the input coordinates for the noise
-- generator. For a 2D generator you'd provide the `x[n]` and `y[n]` arrays
-- and leave the remaining arrays as NULL.
-- `out[n]` is the output array, which will receive the noise values.
-- \rst
-- .. versionadded:: 1.16
-- \endrst
--
procedure TCOD_noise_get_vectorized
(noise : access TCOD_Noise;
c_type : TCOD_noise_type_t;
n : int;
x : access float;
y : access float;
z : access float;
w : access float;
c_out : access float) -- noise.h:108
with Import => True,
Convention => C,
External_Name => "TCOD_noise_get_vectorized";
--*
-- Generate noise as a vectorized operation with fractional Brownian motion.
-- `octaves` are the number of samples to take.
-- The remaining parameters are the same as `TCOD_noise_get_vectorized`.
-- \rst
-- .. versionadded:: 1.16
-- \endrst
--
procedure TCOD_noise_get_fbm_vectorized
(noise : access TCOD_Noise;
c_type : TCOD_noise_type_t;
octaves : float;
n : int;
x : access float;
y : access float;
z : access float;
w : access float;
c_out : access float) -- noise.h:128
with Import => True,
Convention => C,
External_Name => "TCOD_noise_get_fbm_vectorized";
--*
-- Generate noise as a vectorized operation with turbulence.
-- `octaves` are the number of samples to take.
-- The remaining parameters are the same as `TCOD_noise_get_vectorized`.
-- \rst
-- .. versionadded:: 1.16
-- \endrst
--
procedure TCOD_noise_get_turbulence_vectorized
(noise : access TCOD_Noise;
c_type : TCOD_noise_type_t;
octaves : float;
n : int;
x : access float;
y : access float;
z : access float;
w : access float;
c_out : access float) -- noise.h:149
with Import => True,
Convention => C,
External_Name => "TCOD_noise_get_turbulence_vectorized";
end noise_h;
|
-- Copyright (c) 2015-2019 Marcel Schneider
-- for details see License.txt
with Ada.Text_IO; use Ada.Text_IO;
with Punctuation; use Punctuation;
with Tokens; use Tokens;
with TokenValue; use TokenValue;
with Lexer; use Lexer;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
with Ada.Containers.Hashed_Maps; use Ada.Containers;
procedure AeonFlux is
P : Punctuation.Object;
TOK : Tokens.Token;
L : Lexer.Object;
TO : TokenValue.Object;
begin
Put_Line ("AeonFlux");
Put_Line ("--------");
Initialize (P);
TOK := Tokens.EOF;
Put_Line (TOK'Img);
TOK := P.Keywords.Element(To_Unbounded_String ("break"));
Put_Line (TOK'Img);
OpenFile (L, "Test.txt");
TO := ReadToken (L);
Put_Line (To_String (TO.Message));
Clear (P);
Put_Line ("");
end AeonFlux;
|
pragma Ada_2012;
pragma Style_Checks (Off);
with Interfaces.C; use Interfaces.C;
with bits_types_h;
package stdint_h is
INT8_MIN : constant := (-128); -- /usr/include/stdint.h:116
INT16_MIN : constant := (-32767-1); -- /usr/include/stdint.h:117
INT32_MIN : constant := (-2147483647-1); -- /usr/include/stdint.h:118
-- unsupported macro: INT64_MIN (-__INT64_C(9223372036854775807)-1)
INT8_MAX : constant := (127); -- /usr/include/stdint.h:121
INT16_MAX : constant := (32767); -- /usr/include/stdint.h:122
INT32_MAX : constant := (2147483647); -- /usr/include/stdint.h:123
-- unsupported macro: INT64_MAX (__INT64_C(9223372036854775807))
UINT8_MAX : constant := (255); -- /usr/include/stdint.h:127
UINT16_MAX : constant := (65535); -- /usr/include/stdint.h:128
UINT32_MAX : constant := (4294967295); -- /usr/include/stdint.h:129
-- unsupported macro: UINT64_MAX (__UINT64_C(18446744073709551615))
INT_LEAST8_MIN : constant := (-128); -- /usr/include/stdint.h:134
INT_LEAST16_MIN : constant := (-32767-1); -- /usr/include/stdint.h:135
INT_LEAST32_MIN : constant := (-2147483647-1); -- /usr/include/stdint.h:136
-- unsupported macro: INT_LEAST64_MIN (-__INT64_C(9223372036854775807)-1)
INT_LEAST8_MAX : constant := (127); -- /usr/include/stdint.h:139
INT_LEAST16_MAX : constant := (32767); -- /usr/include/stdint.h:140
INT_LEAST32_MAX : constant := (2147483647); -- /usr/include/stdint.h:141
-- unsupported macro: INT_LEAST64_MAX (__INT64_C(9223372036854775807))
UINT_LEAST8_MAX : constant := (255); -- /usr/include/stdint.h:145
UINT_LEAST16_MAX : constant := (65535); -- /usr/include/stdint.h:146
UINT_LEAST32_MAX : constant := (4294967295); -- /usr/include/stdint.h:147
-- unsupported macro: UINT_LEAST64_MAX (__UINT64_C(18446744073709551615))
INT_FAST8_MIN : constant := (-128); -- /usr/include/stdint.h:152
INT_FAST16_MIN : constant := (-9223372036854775807-1); -- /usr/include/stdint.h:154
INT_FAST32_MIN : constant := (-9223372036854775807-1); -- /usr/include/stdint.h:155
-- unsupported macro: INT_FAST64_MIN (-__INT64_C(9223372036854775807)-1)
INT_FAST8_MAX : constant := (127); -- /usr/include/stdint.h:162
INT_FAST16_MAX : constant := (9223372036854775807); -- /usr/include/stdint.h:164
INT_FAST32_MAX : constant := (9223372036854775807); -- /usr/include/stdint.h:165
-- unsupported macro: INT_FAST64_MAX (__INT64_C(9223372036854775807))
UINT_FAST8_MAX : constant := (255); -- /usr/include/stdint.h:173
UINT_FAST16_MAX : constant := (18446744073709551615); -- /usr/include/stdint.h:175
UINT_FAST32_MAX : constant := (18446744073709551615); -- /usr/include/stdint.h:176
-- unsupported macro: UINT_FAST64_MAX (__UINT64_C(18446744073709551615))
INTPTR_MIN : constant := (-9223372036854775807-1); -- /usr/include/stdint.h:186
INTPTR_MAX : constant := (9223372036854775807); -- /usr/include/stdint.h:187
UINTPTR_MAX : constant := (18446744073709551615); -- /usr/include/stdint.h:188
-- unsupported macro: INTMAX_MIN (-__INT64_C(9223372036854775807)-1)
-- unsupported macro: INTMAX_MAX (__INT64_C(9223372036854775807))
-- unsupported macro: UINTMAX_MAX (__UINT64_C(18446744073709551615))
PTRDIFF_MIN : constant := (-9223372036854775807-1); -- /usr/include/stdint.h:209
PTRDIFF_MAX : constant := (9223372036854775807); -- /usr/include/stdint.h:210
SIG_ATOMIC_MIN : constant := (-2147483647-1); -- /usr/include/stdint.h:222
SIG_ATOMIC_MAX : constant := (2147483647); -- /usr/include/stdint.h:223
SIZE_MAX : constant := (18446744073709551615); -- /usr/include/stdint.h:227
-- unsupported macro: WCHAR_MIN __WCHAR_MIN
-- unsupported macro: WCHAR_MAX __WCHAR_MAX
WINT_MIN : constant := (0); -- /usr/include/stdint.h:244
WINT_MAX : constant := (4294967295); -- /usr/include/stdint.h:245
-- arg-macro: procedure INT8_C (c)
-- c
-- arg-macro: procedure INT16_C (c)
-- c
-- arg-macro: procedure INT32_C (c)
-- c
-- unsupported macro: INT64_C(c) c ## L
-- arg-macro: procedure UINT8_C (c)
-- c
-- arg-macro: procedure UINT16_C (c)
-- c
-- unsupported macro: UINT32_C(c) c ## U
-- unsupported macro: UINT64_C(c) c ## UL
-- unsupported macro: INTMAX_C(c) c ## L
-- unsupported macro: UINTMAX_C(c) c ## UL
INT8_WIDTH : constant := 8; -- /usr/include/stdint.h:278
UINT8_WIDTH : constant := 8; -- /usr/include/stdint.h:279
INT16_WIDTH : constant := 16; -- /usr/include/stdint.h:280
UINT16_WIDTH : constant := 16; -- /usr/include/stdint.h:281
INT32_WIDTH : constant := 32; -- /usr/include/stdint.h:282
UINT32_WIDTH : constant := 32; -- /usr/include/stdint.h:283
INT64_WIDTH : constant := 64; -- /usr/include/stdint.h:284
UINT64_WIDTH : constant := 64; -- /usr/include/stdint.h:285
INT_LEAST8_WIDTH : constant := 8; -- /usr/include/stdint.h:287
UINT_LEAST8_WIDTH : constant := 8; -- /usr/include/stdint.h:288
INT_LEAST16_WIDTH : constant := 16; -- /usr/include/stdint.h:289
UINT_LEAST16_WIDTH : constant := 16; -- /usr/include/stdint.h:290
INT_LEAST32_WIDTH : constant := 32; -- /usr/include/stdint.h:291
UINT_LEAST32_WIDTH : constant := 32; -- /usr/include/stdint.h:292
INT_LEAST64_WIDTH : constant := 64; -- /usr/include/stdint.h:293
UINT_LEAST64_WIDTH : constant := 64; -- /usr/include/stdint.h:294
INT_FAST8_WIDTH : constant := 8; -- /usr/include/stdint.h:296
UINT_FAST8_WIDTH : constant := 8; -- /usr/include/stdint.h:297
-- unsupported macro: INT_FAST16_WIDTH __WORDSIZE
-- unsupported macro: UINT_FAST16_WIDTH __WORDSIZE
-- unsupported macro: INT_FAST32_WIDTH __WORDSIZE
-- unsupported macro: UINT_FAST32_WIDTH __WORDSIZE
INT_FAST64_WIDTH : constant := 64; -- /usr/include/stdint.h:302
UINT_FAST64_WIDTH : constant := 64; -- /usr/include/stdint.h:303
-- unsupported macro: INTPTR_WIDTH __WORDSIZE
-- unsupported macro: UINTPTR_WIDTH __WORDSIZE
INTMAX_WIDTH : constant := 64; -- /usr/include/stdint.h:308
UINTMAX_WIDTH : constant := 64; -- /usr/include/stdint.h:309
-- unsupported macro: PTRDIFF_WIDTH __WORDSIZE
SIG_ATOMIC_WIDTH : constant := 32; -- /usr/include/stdint.h:312
-- unsupported macro: SIZE_WIDTH __WORDSIZE
WCHAR_WIDTH : constant := 32; -- /usr/include/stdint.h:314
WINT_WIDTH : constant := 32; -- /usr/include/stdint.h:315
-- Copyright (C) 1997-2021 Free Software Foundation, Inc.
-- This file is part of the GNU C Library.
-- The GNU C Library is free software; you can redistribute it and/or
-- modify it under the terms of the GNU Lesser General Public
-- License as published by the Free Software Foundation; either
-- version 2.1 of the License, or (at your option) any later version.
-- The GNU C Library is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-- Lesser General Public License for more details.
-- You should have received a copy of the GNU Lesser General Public
-- License along with the GNU C Library; if not, see
-- <https://www.gnu.org/licenses/>.
-- * ISO C99: 7.18 Integer types <stdint.h>
--
-- Exact integral types.
-- Signed.
-- Unsigned.
-- Small types.
-- Signed.
subtype int_least8_t is bits_types_h.uu_int_least8_t; -- /usr/include/stdint.h:43
subtype int_least16_t is bits_types_h.uu_int_least16_t; -- /usr/include/stdint.h:44
subtype int_least32_t is bits_types_h.uu_int_least32_t; -- /usr/include/stdint.h:45
subtype int_least64_t is bits_types_h.uu_int_least64_t; -- /usr/include/stdint.h:46
-- Unsigned.
subtype uint_least8_t is bits_types_h.uu_uint_least8_t; -- /usr/include/stdint.h:49
subtype uint_least16_t is bits_types_h.uu_uint_least16_t; -- /usr/include/stdint.h:50
subtype uint_least32_t is bits_types_h.uu_uint_least32_t; -- /usr/include/stdint.h:51
subtype uint_least64_t is bits_types_h.uu_uint_least64_t; -- /usr/include/stdint.h:52
-- Fast types.
-- Signed.
subtype int_fast8_t is signed_char; -- /usr/include/stdint.h:58
subtype int_fast16_t is long; -- /usr/include/stdint.h:60
subtype int_fast32_t is long; -- /usr/include/stdint.h:61
subtype int_fast64_t is long; -- /usr/include/stdint.h:62
-- Unsigned.
subtype uint_fast8_t is unsigned_char; -- /usr/include/stdint.h:71
subtype uint_fast16_t is unsigned_long; -- /usr/include/stdint.h:73
subtype uint_fast32_t is unsigned_long; -- /usr/include/stdint.h:74
subtype uint_fast64_t is unsigned_long; -- /usr/include/stdint.h:75
-- Types for `void *' pointers.
subtype intptr_t is long; -- /usr/include/stdint.h:87
subtype uintptr_t is unsigned_long; -- /usr/include/stdint.h:90
-- Largest integral types.
subtype intmax_t is bits_types_h.uu_intmax_t; -- /usr/include/stdint.h:101
subtype uintmax_t is bits_types_h.uu_uintmax_t; -- /usr/include/stdint.h:102
-- Limits of integral types.
-- Minimum of signed integral types.
-- Maximum of signed integral types.
-- Maximum of unsigned integral types.
-- Minimum of signed integral types having a minimum size.
-- Maximum of signed integral types having a minimum size.
-- Maximum of unsigned integral types having a minimum size.
-- Minimum of fast signed integral types having a minimum size.
-- Maximum of fast signed integral types having a minimum size.
-- Maximum of fast unsigned integral types having a minimum size.
-- Values to test for integral types holding `void *' pointer.
-- Minimum for largest signed integral type.
-- Maximum for largest signed integral type.
-- Maximum for largest unsigned integral type.
-- Limits of other integer types.
-- Limits of `ptrdiff_t' type.
-- Limits of `sig_atomic_t'.
-- Limit of `size_t' type.
-- Limits of `wchar_t'.
-- These constants might also be defined in <wchar.h>.
-- Limits of `wint_t'.
-- Signed.
-- Unsigned.
-- Maximal type.
end stdint_h;
|
package Semaphores is
protected type SIMA (Initial_Value: Natural; Max_Value: Natural;) is
entry P;
entry V;
private
Count : Natural := Initial_Value;
Max_Count : Natural := Max_Value;
end SIMA;
end Semaphores;
|
with text_io;
procedure bug4 is
x : integer := integer'first;
y : integer := integer'first + 1;
begin
text_io.put_line("X = " & integer'image(x));
text_io.put_line("Y = " & integer'image(y));
end bug4;
|
------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- G N A T . O S _ L I B --
-- --
-- B o d y --
-- --
-- $Revision$
-- --
-- Copyright (C) 1995-2001 Ada Core Technologies, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 2, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
-- for more details. You should have received a copy of the GNU General --
-- Public License distributed with GNAT; see file COPYING. If not, write --
-- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
-- MA 02111-1307, USA. --
-- --
-- As a special exception, if other files instantiate generics from this --
-- unit, or you link this unit with other files to produce an executable, --
-- this unit does not by itself cause the resulting executable to be --
-- covered by the GNU General Public License. This exception does not --
-- however invalidate any other reasons why the executable file might be --
-- covered by the GNU Public License. --
-- --
-- GNAT is maintained by Ada Core Technologies Inc (http://www.gnat.com). --
-- --
------------------------------------------------------------------------------
with System.Soft_Links;
with Unchecked_Conversion;
with System; use System;
package body GNAT.OS_Lib is
package SSL renames System.Soft_Links;
-----------------------
-- Local Subprograms --
-----------------------
function Args_Length (Args : Argument_List) return Natural;
-- Returns total number of characters needed to create a string
-- of all Args terminated by ASCII.NUL characters
function C_String_Length (S : Address) return Integer;
-- Returns the length of a C string. Does check for null address
-- (returns 0).
procedure Spawn_Internal
(Program_Name : String;
Args : Argument_List;
Result : out Integer;
Pid : out Process_Id;
Blocking : Boolean);
-- Internal routine to implement the to Spawn (blocking and non blocking)
-- routines. If Blocking is set to True then the spawn is blocking
-- otherwise it is non blocking. In this latter case the Pid contains
-- the process id number. The first three parameters are as in Spawn.
function To_Path_String_Access
(Path_Addr : Address;
Path_Len : Integer)
return String_Access;
-- Converts a C String to an Ada String. We could do this making use of
-- Interfaces.C.Strings but we prefer not to import that entire package
-----------------
-- Args_Length --
-----------------
function Args_Length (Args : Argument_List) return Natural is
Len : Natural := 0;
begin
for J in Args'Range loop
Len := Len + Args (J)'Length + 1; -- One extra for ASCII.NUL
end loop;
return Len;
end Args_Length;
-----------------------------
-- Argument_String_To_List --
-----------------------------
function Argument_String_To_List
(Arg_String : String)
return Argument_List_Access
is
Max_Args : Integer := Arg_String'Length;
New_Argv : Argument_List (1 .. Max_Args);
New_Argc : Natural := 0;
Idx : Integer;
begin
Idx := Arg_String'First;
loop
declare
Quoted : Boolean := False;
Backqd : Boolean := False;
Old_Idx : Integer;
begin
Old_Idx := Idx;
loop
-- A vanilla space is the end of an argument
if not Backqd and then not Quoted
and then Arg_String (Idx) = ' '
then
exit;
-- Start of a quoted string
elsif not Backqd and then not Quoted
and then Arg_String (Idx) = '"'
then
Quoted := True;
-- End of a quoted string and end of an argument
elsif not Backqd and then Quoted
and then Arg_String (Idx) = '"'
then
Idx := Idx + 1;
exit;
-- Following character is backquoted
elsif Arg_String (Idx) = '\' then
Backqd := True;
-- Turn off backquoting after advancing one character
elsif Backqd then
Backqd := False;
end if;
Idx := Idx + 1;
exit when Idx > Arg_String'Last;
end loop;
-- Found an argument
New_Argc := New_Argc + 1;
New_Argv (New_Argc) :=
new String'(Arg_String (Old_Idx .. Idx - 1));
-- Skip extraneous spaces
while Idx <= Arg_String'Last and then Arg_String (Idx) = ' ' loop
Idx := Idx + 1;
end loop;
end;
exit when Idx > Arg_String'Last;
end loop;
return new Argument_List'(New_Argv (1 .. New_Argc));
end Argument_String_To_List;
---------------------
-- C_String_Length --
---------------------
function C_String_Length (S : Address) return Integer is
function Strlen (S : Address) return Integer;
pragma Import (C, Strlen, "strlen");
begin
if S = Null_Address then
return 0;
else
return Strlen (S);
end if;
end C_String_Length;
-----------------
-- Create_File --
-----------------
function Create_File
(Name : C_File_Name;
Fmode : Mode)
return File_Descriptor
is
function C_Create_File
(Name : C_File_Name;
Fmode : Mode)
return File_Descriptor;
pragma Import (C, C_Create_File, "__gnat_open_create");
begin
return C_Create_File (Name, Fmode);
end Create_File;
function Create_File
(Name : String;
Fmode : Mode)
return File_Descriptor
is
C_Name : String (1 .. Name'Length + 1);
begin
C_Name (1 .. Name'Length) := Name;
C_Name (C_Name'Last) := ASCII.NUL;
return Create_File (C_Name (C_Name'First)'Address, Fmode);
end Create_File;
---------------------
-- Create_New_File --
---------------------
function Create_New_File
(Name : C_File_Name;
Fmode : Mode)
return File_Descriptor
is
function C_Create_New_File
(Name : C_File_Name;
Fmode : Mode)
return File_Descriptor;
pragma Import (C, C_Create_New_File, "__gnat_open_new");
begin
return C_Create_New_File (Name, Fmode);
end Create_New_File;
function Create_New_File
(Name : String;
Fmode : Mode)
return File_Descriptor
is
C_Name : String (1 .. Name'Length + 1);
begin
C_Name (1 .. Name'Length) := Name;
C_Name (C_Name'Last) := ASCII.NUL;
return Create_New_File (C_Name (C_Name'First)'Address, Fmode);
end Create_New_File;
----------------------
-- Create_Temp_File --
----------------------
procedure Create_Temp_File
(FD : out File_Descriptor;
Name : out Temp_File_Name)
is
function Open_New_Temp
(Name : System.Address;
Fmode : Mode)
return File_Descriptor;
pragma Import (C, Open_New_Temp, "__gnat_open_new_temp");
begin
FD := Open_New_Temp (Name'Address, Binary);
end Create_Temp_File;
-----------------
-- Delete_File --
-----------------
procedure Delete_File (Name : Address; Success : out Boolean) is
R : Integer;
function unlink (A : Address) return Integer;
pragma Import (C, unlink, "unlink");
begin
R := unlink (Name);
Success := (R = 0);
end Delete_File;
procedure Delete_File (Name : String; Success : out Boolean) is
C_Name : String (1 .. Name'Length + 1);
begin
C_Name (1 .. Name'Length) := Name;
C_Name (C_Name'Last) := ASCII.NUL;
Delete_File (C_Name'Address, Success);
end Delete_File;
---------------------
-- File_Time_Stamp --
---------------------
function File_Time_Stamp (FD : File_Descriptor) return OS_Time is
function File_Time (FD : File_Descriptor) return OS_Time;
pragma Import (C, File_Time, "__gnat_file_time_fd");
begin
return File_Time (FD);
end File_Time_Stamp;
function File_Time_Stamp (Name : C_File_Name) return OS_Time is
function File_Time (Name : Address) return OS_Time;
pragma Import (C, File_Time, "__gnat_file_time_name");
begin
return File_Time (Name);
end File_Time_Stamp;
function File_Time_Stamp (Name : String) return OS_Time is
F_Name : String (1 .. Name'Length + 1);
begin
F_Name (1 .. Name'Length) := Name;
F_Name (F_Name'Last) := ASCII.NUL;
return File_Time_Stamp (F_Name'Address);
end File_Time_Stamp;
---------------------------
-- Get_Debuggable_Suffix --
---------------------------
function Get_Debuggable_Suffix return String_Access is
procedure Get_Suffix_Ptr (Length, Ptr : Address);
pragma Import (C, Get_Suffix_Ptr, "__gnat_get_debuggable_suffix_ptr");
procedure Strncpy (Astring_Addr, Cstring : Address; N : Integer);
pragma Import (C, Strncpy, "strncpy");
Suffix_Ptr : Address;
Suffix_Length : Integer;
Result : String_Access;
begin
Get_Suffix_Ptr (Suffix_Length'Address, Suffix_Ptr'Address);
Result := new String (1 .. Suffix_Length);
if Suffix_Length > 0 then
Strncpy (Result.all'Address, Suffix_Ptr, Suffix_Length);
end if;
return Result;
end Get_Debuggable_Suffix;
---------------------------
-- Get_Executable_Suffix --
---------------------------
function Get_Executable_Suffix return String_Access is
procedure Get_Suffix_Ptr (Length, Ptr : Address);
pragma Import (C, Get_Suffix_Ptr, "__gnat_get_executable_suffix_ptr");
procedure Strncpy (Astring_Addr, Cstring : Address; N : Integer);
pragma Import (C, Strncpy, "strncpy");
Suffix_Ptr : Address;
Suffix_Length : Integer;
Result : String_Access;
begin
Get_Suffix_Ptr (Suffix_Length'Address, Suffix_Ptr'Address);
Result := new String (1 .. Suffix_Length);
if Suffix_Length > 0 then
Strncpy (Result.all'Address, Suffix_Ptr, Suffix_Length);
end if;
return Result;
end Get_Executable_Suffix;
-----------------------
-- Get_Object_Suffix --
-----------------------
function Get_Object_Suffix return String_Access is
procedure Get_Suffix_Ptr (Length, Ptr : Address);
pragma Import (C, Get_Suffix_Ptr, "__gnat_get_object_suffix_ptr");
procedure Strncpy (Astring_Addr, Cstring : Address; N : Integer);
pragma Import (C, Strncpy, "strncpy");
Suffix_Ptr : Address;
Suffix_Length : Integer;
Result : String_Access;
begin
Get_Suffix_Ptr (Suffix_Length'Address, Suffix_Ptr'Address);
Result := new String (1 .. Suffix_Length);
if Suffix_Length > 0 then
Strncpy (Result.all'Address, Suffix_Ptr, Suffix_Length);
end if;
return Result;
end Get_Object_Suffix;
------------
-- Getenv --
------------
function Getenv (Name : String) return String_Access is
procedure Get_Env_Value_Ptr (Name, Length, Ptr : Address);
pragma Import (C, Get_Env_Value_Ptr, "__gnat_get_env_value_ptr");
procedure Strncpy (Astring_Addr, Cstring : Address; N : Integer);
pragma Import (C, Strncpy, "strncpy");
Env_Value_Ptr : Address;
Env_Value_Length : Integer;
F_Name : String (1 .. Name'Length + 1);
Result : String_Access;
begin
F_Name (1 .. Name'Length) := Name;
F_Name (F_Name'Last) := ASCII.NUL;
Get_Env_Value_Ptr
(F_Name'Address, Env_Value_Length'Address, Env_Value_Ptr'Address);
Result := new String (1 .. Env_Value_Length);
if Env_Value_Length > 0 then
Strncpy (Result.all'Address, Env_Value_Ptr, Env_Value_Length);
end if;
return Result;
end Getenv;
------------
-- GM_Day --
------------
function GM_Day (Date : OS_Time) return Day_Type is
Y : Year_Type;
Mo : Month_Type;
D : Day_Type;
H : Hour_Type;
Mn : Minute_Type;
S : Second_Type;
begin
GM_Split (Date, Y, Mo, D, H, Mn, S);
return D;
end GM_Day;
-------------
-- GM_Hour --
-------------
function GM_Hour (Date : OS_Time) return Hour_Type is
Y : Year_Type;
Mo : Month_Type;
D : Day_Type;
H : Hour_Type;
Mn : Minute_Type;
S : Second_Type;
begin
GM_Split (Date, Y, Mo, D, H, Mn, S);
return H;
end GM_Hour;
---------------
-- GM_Minute --
---------------
function GM_Minute (Date : OS_Time) return Minute_Type is
Y : Year_Type;
Mo : Month_Type;
D : Day_Type;
H : Hour_Type;
Mn : Minute_Type;
S : Second_Type;
begin
GM_Split (Date, Y, Mo, D, H, Mn, S);
return Mn;
end GM_Minute;
--------------
-- GM_Month --
--------------
function GM_Month (Date : OS_Time) return Month_Type is
Y : Year_Type;
Mo : Month_Type;
D : Day_Type;
H : Hour_Type;
Mn : Minute_Type;
S : Second_Type;
begin
GM_Split (Date, Y, Mo, D, H, Mn, S);
return Mo;
end GM_Month;
---------------
-- GM_Second --
---------------
function GM_Second (Date : OS_Time) return Second_Type is
Y : Year_Type;
Mo : Month_Type;
D : Day_Type;
H : Hour_Type;
Mn : Minute_Type;
S : Second_Type;
begin
GM_Split (Date, Y, Mo, D, H, Mn, S);
return S;
end GM_Second;
--------------
-- GM_Split --
--------------
procedure GM_Split
(Date : OS_Time;
Year : out Year_Type;
Month : out Month_Type;
Day : out Day_Type;
Hour : out Hour_Type;
Minute : out Minute_Type;
Second : out Second_Type)
is
procedure To_GM_Time
(P_Time_T, P_Year, P_Month, P_Day, P_Hours, P_Mins, P_Secs : Address);
pragma Import (C, To_GM_Time, "__gnat_to_gm_time");
T : OS_Time := Date;
Y : Integer;
Mo : Integer;
D : Integer;
H : Integer;
Mn : Integer;
S : Integer;
begin
-- Use the global lock because To_GM_Time is not thread safe.
Locked_Processing : begin
SSL.Lock_Task.all;
To_GM_Time
(T'Address, Y'Address, Mo'Address, D'Address,
H'Address, Mn'Address, S'Address);
SSL.Unlock_Task.all;
exception
when others =>
SSL.Unlock_Task.all;
raise;
end Locked_Processing;
Year := Y + 1900;
Month := Mo + 1;
Day := D;
Hour := H;
Minute := Mn;
Second := S;
end GM_Split;
-------------
-- GM_Year --
-------------
function GM_Year (Date : OS_Time) return Year_Type is
Y : Year_Type;
Mo : Month_Type;
D : Day_Type;
H : Hour_Type;
Mn : Minute_Type;
S : Second_Type;
begin
GM_Split (Date, Y, Mo, D, H, Mn, S);
return Y;
end GM_Year;
----------------------
-- Is_Absolute_Path --
----------------------
function Is_Absolute_Path (Name : String) return Boolean is
function Is_Absolute_Path (Name : Address) return Integer;
pragma Import (C, Is_Absolute_Path, "__gnat_is_absolute_path");
F_Name : String (1 .. Name'Length + 1);
begin
F_Name (1 .. Name'Length) := Name;
F_Name (F_Name'Last) := ASCII.NUL;
return Is_Absolute_Path (F_Name'Address) /= 0;
end Is_Absolute_Path;
------------------
-- Is_Directory --
------------------
function Is_Directory (Name : C_File_Name) return Boolean is
function Is_Directory (Name : Address) return Integer;
pragma Import (C, Is_Directory, "__gnat_is_directory");
begin
return Is_Directory (Name) /= 0;
end Is_Directory;
function Is_Directory (Name : String) return Boolean is
F_Name : String (1 .. Name'Length + 1);
begin
F_Name (1 .. Name'Length) := Name;
F_Name (F_Name'Last) := ASCII.NUL;
return Is_Directory (F_Name'Address);
end Is_Directory;
---------------------
-- Is_Regular_File --
---------------------
function Is_Regular_File (Name : C_File_Name) return Boolean is
function Is_Regular_File (Name : Address) return Integer;
pragma Import (C, Is_Regular_File, "__gnat_is_regular_file");
begin
return Is_Regular_File (Name) /= 0;
end Is_Regular_File;
function Is_Regular_File (Name : String) return Boolean is
F_Name : String (1 .. Name'Length + 1);
begin
F_Name (1 .. Name'Length) := Name;
F_Name (F_Name'Last) := ASCII.NUL;
return Is_Regular_File (F_Name'Address);
end Is_Regular_File;
----------------------
-- Is_Writable_File --
----------------------
function Is_Writable_File (Name : C_File_Name) return Boolean is
function Is_Writable_File (Name : Address) return Integer;
pragma Import (C, Is_Writable_File, "__gnat_is_writable_file");
begin
return Is_Writable_File (Name) /= 0;
end Is_Writable_File;
function Is_Writable_File (Name : String) return Boolean is
F_Name : String (1 .. Name'Length + 1);
begin
F_Name (1 .. Name'Length) := Name;
F_Name (F_Name'Last) := ASCII.NUL;
return Is_Writable_File (F_Name'Address);
end Is_Writable_File;
-------------------------
-- Locate_Exec_On_Path --
-------------------------
function Locate_Exec_On_Path
(Exec_Name : String)
return String_Access
is
function Locate_Exec_On_Path (C_Exec_Name : Address) return Address;
pragma Import (C, Locate_Exec_On_Path, "__gnat_locate_exec_on_path");
procedure Free (Ptr : System.Address);
pragma Import (C, Free, "free");
C_Exec_Name : String (1 .. Exec_Name'Length + 1);
Path_Addr : Address;
Path_Len : Integer;
Result : String_Access;
begin
C_Exec_Name (1 .. Exec_Name'Length) := Exec_Name;
C_Exec_Name (C_Exec_Name'Last) := ASCII.NUL;
Path_Addr := Locate_Exec_On_Path (C_Exec_Name'Address);
Path_Len := C_String_Length (Path_Addr);
if Path_Len = 0 then
return null;
else
Result := To_Path_String_Access (Path_Addr, Path_Len);
Free (Path_Addr);
return Result;
end if;
end Locate_Exec_On_Path;
-------------------------
-- Locate_Regular_File --
-------------------------
function Locate_Regular_File
(File_Name : C_File_Name;
Path : C_File_Name)
return String_Access
is
function Locate_Regular_File
(C_File_Name, Path_Val : Address) return Address;
pragma Import (C, Locate_Regular_File, "__gnat_locate_regular_file");
procedure Free (Ptr : System.Address);
pragma Import (C, Free, "free");
Path_Addr : Address;
Path_Len : Integer;
Result : String_Access;
begin
Path_Addr := Locate_Regular_File (File_Name, Path);
Path_Len := C_String_Length (Path_Addr);
if Path_Len = 0 then
return null;
else
Result := To_Path_String_Access (Path_Addr, Path_Len);
Free (Path_Addr);
return Result;
end if;
end Locate_Regular_File;
function Locate_Regular_File
(File_Name : String;
Path : String)
return String_Access
is
C_File_Name : String (1 .. File_Name'Length + 1);
C_Path : String (1 .. Path'Length + 1);
begin
C_File_Name (1 .. File_Name'Length) := File_Name;
C_File_Name (C_File_Name'Last) := ASCII.NUL;
C_Path (1 .. Path'Length) := Path;
C_Path (C_Path'Last) := ASCII.NUL;
return Locate_Regular_File (C_File_Name'Address, C_Path'Address);
end Locate_Regular_File;
------------------------
-- Non_Blocking_Spawn --
------------------------
function Non_Blocking_Spawn
(Program_Name : String;
Args : Argument_List)
return Process_Id
is
Junk : Integer;
Pid : Process_Id;
begin
Spawn_Internal (Program_Name, Args, Junk, Pid, Blocking => False);
return Pid;
end Non_Blocking_Spawn;
------------------------
-- Normalize_Pathname --
------------------------
function Normalize_Pathname
(Name : String;
Directory : String := "")
return String
is
Max_Path : Integer;
pragma Import (C, Max_Path, "max_path_len");
-- Maximum length of a path name
procedure Get_Current_Dir
(Dir : System.Address;
Length : System.Address);
pragma Import (C, Get_Current_Dir, "__gnat_get_current_dir");
Path_Buffer : String (1 .. Max_Path + Max_Path + 2);
End_Path : Natural := 0;
Link_Buffer : String (1 .. Max_Path + 2);
Status : Integer;
Last : Positive;
Start : Natural;
Finish : Positive;
Max_Iterations : constant := 500;
function Readlink
(Path : System.Address;
Buf : System.Address;
Bufsiz : Integer)
return Integer;
pragma Import (C, Readlink, "__gnat_readlink");
function To_Canonical_File_Spec
(Host_File : System.Address)
return System.Address;
pragma Import
(C, To_Canonical_File_Spec, "__gnat_to_canonical_file_spec");
The_Name : String (1 .. Name'Length + 1);
Canonical_File_Addr : System.Address;
Canonical_File_Len : Integer;
Need_To_Check_Drive_Letter : Boolean := False;
-- Set to true if Name is an absolute path that starts with "//"
function Strlen (S : System.Address) return Integer;
pragma Import (C, Strlen, "strlen");
function Get_Directory return String;
-- If Directory is not empty, return it, adding a directory separator
-- if not already present, otherwise return current working directory
-- with terminating directory separator.
function Final_Value (S : String) return String;
-- Make final adjustment to the returned string.
-- To compensate for non standard path name in Interix,
-- if S is "/x" or starts with "/x", where x is a capital
-- letter 'A' to 'Z', add an additional '/' at the beginning
-- so that the returned value starts with "//x".
-------------------
-- Get_Directory --
-------------------
function Get_Directory return String is
begin
-- Directory given, add directory separator if needed
if Directory'Length > 0 then
if Directory (Directory'Length) = Directory_Separator then
return Directory;
else
declare
Result : String (1 .. Directory'Length + 1);
begin
Result (1 .. Directory'Length) := Directory;
Result (Result'Length) := Directory_Separator;
return Result;
end;
end if;
-- Directory name not given, get current directory
else
declare
Buffer : String (1 .. Max_Path + 2);
Path_Len : Natural := Max_Path;
begin
Get_Current_Dir (Buffer'Address, Path_Len'Address);
if Buffer (Path_Len) /= Directory_Separator then
Path_Len := Path_Len + 1;
Buffer (Path_Len) := Directory_Separator;
end if;
return Buffer (1 .. Path_Len);
end;
end if;
end Get_Directory;
Reference_Dir : constant String := Get_Directory;
-- Current directory name specified
function Final_Value (S : String) return String is
begin
-- Interix has the non standard notion of disk drive
-- indicated by two '/' followed by a capital letter
-- 'A' .. 'Z'. One of the two '/' may have been removed
-- by Normalize_Pathname. It has to be added again.
-- For other OSes, this should not make no difference.
if Need_To_Check_Drive_Letter
and then S'Length >= 2
and then S (S'First) = '/'
and then S (S'First + 1) in 'A' .. 'Z'
and then (S'Length = 2 or else S (S'First + 2) = '/')
then
declare
Result : String (1 .. S'Length + 1);
begin
Result (1) := '/';
Result (2 .. Result'Last) := S;
return Result;
end;
else
return S;
end if;
end Final_Value;
-- Start of processing for Normalize_Pathname
begin
-- Special case, if name is null, then return null
if Name'Length = 0 then
return "";
end if;
-- First, convert VMS file spec to Unix file spec.
-- If Name is not in VMS syntax, then this is equivalent
-- to put Name at the begining of Path_Buffer.
VMS_Conversion : begin
The_Name (1 .. Name'Length) := Name;
The_Name (The_Name'Last) := ASCII.NUL;
Canonical_File_Addr := To_Canonical_File_Spec (The_Name'Address);
Canonical_File_Len := Strlen (Canonical_File_Addr);
-- If VMS syntax conversion has failed, return an empty string
-- to indicate the failure.
if Canonical_File_Len = 0 then
return "";
end if;
declare
subtype Path_String is String (1 .. Canonical_File_Len);
type Path_String_Access is access Path_String;
function Address_To_Access is new
Unchecked_Conversion (Source => Address,
Target => Path_String_Access);
Path_Access : Path_String_Access :=
Address_To_Access (Canonical_File_Addr);
begin
Path_Buffer (1 .. Canonical_File_Len) := Path_Access.all;
End_Path := Canonical_File_Len;
Last := 1;
end;
end VMS_Conversion;
-- Replace all '/' by Directory Separators (this is for Windows)
if Directory_Separator /= '/' then
for Index in 1 .. End_Path loop
if Path_Buffer (Index) = '/' then
Path_Buffer (Index) := Directory_Separator;
end if;
end loop;
end if;
-- Start the conversions
-- If this is not finished after Max_Iterations, give up and
-- return an empty string.
for J in 1 .. Max_Iterations loop
-- If we don't have an absolute pathname, prepend
-- the directory Reference_Dir.
if Last = 1
and then not Is_Absolute_Path (Path_Buffer (1 .. End_Path))
then
Path_Buffer
(Reference_Dir'Last + 1 .. Reference_Dir'Length + End_Path) :=
Path_Buffer (1 .. End_Path);
End_Path := Reference_Dir'Length + End_Path;
Path_Buffer (1 .. Reference_Dir'Length) := Reference_Dir;
Last := Reference_Dir'Length;
end if;
-- If name starts with "//", we may have a drive letter on Interix
if Last = 1 and then End_Path >= 3 then
Need_To_Check_Drive_Letter := (Path_Buffer (1 .. 2)) = "//";
end if;
Start := Last + 1;
Finish := Last;
-- If we have traversed the full pathname, return it
if Start > End_Path then
return Final_Value (Path_Buffer (1 .. End_Path));
end if;
-- Remove duplicate directory separators
while Path_Buffer (Start) = Directory_Separator loop
if Start = End_Path then
return Final_Value (Path_Buffer (1 .. End_Path - 1));
else
Path_Buffer (Start .. End_Path - 1) :=
Path_Buffer (Start + 1 .. End_Path);
End_Path := End_Path - 1;
end if;
end loop;
-- Find the end of the current field: last character
-- or the one preceding the next directory separator.
while Finish < End_Path
and then Path_Buffer (Finish + 1) /= Directory_Separator
loop
Finish := Finish + 1;
end loop;
-- Remove "." field
if Start = Finish and then Path_Buffer (Start) = '.' then
if Start = End_Path then
if Last = 1 then
return (1 => Directory_Separator);
else
return Path_Buffer (1 .. Last - 1);
end if;
else
Path_Buffer (Last + 1 .. End_Path - 2) :=
Path_Buffer (Last + 3 .. End_Path);
End_Path := End_Path - 2;
end if;
-- Remove ".." fields
elsif Finish = Start + 1
and then Path_Buffer (Start .. Finish) = ".."
then
Start := Last;
loop
Start := Start - 1;
exit when Start < 1 or else
Path_Buffer (Start) = Directory_Separator;
end loop;
if Start <= 1 then
if Finish = End_Path then
return (1 => Directory_Separator);
else
Path_Buffer (1 .. End_Path - Finish) :=
Path_Buffer (Finish + 1 .. End_Path);
End_Path := End_Path - Finish;
Last := 1;
end if;
else
if Finish = End_Path then
return Final_Value (Path_Buffer (1 .. Start - 1));
else
Path_Buffer (Start + 1 .. Start + End_Path - Finish - 1) :=
Path_Buffer (Finish + 2 .. End_Path);
End_Path := Start + End_Path - Finish - 1;
Last := Start;
end if;
end if;
-- Check if current field is a symbolic link
else
declare
Saved : Character := Path_Buffer (Finish + 1);
begin
Path_Buffer (Finish + 1) := ASCII.NUL;
Status := Readlink (Path_Buffer'Address,
Link_Buffer'Address,
Link_Buffer'Length);
Path_Buffer (Finish + 1) := Saved;
end;
-- Not a symbolic link, move to the next field, if any
if Status <= 0 then
Last := Finish + 1;
-- Replace symbolic link with its value.
else
if Is_Absolute_Path (Link_Buffer (1 .. Status)) then
Path_Buffer (Status + 1 .. End_Path - (Finish - Status)) :=
Path_Buffer (Finish + 1 .. End_Path);
End_Path := End_Path - (Finish - Status);
Path_Buffer (1 .. Status) := Link_Buffer (1 .. Status);
Last := 1;
else
Path_Buffer
(Last + Status + 1 .. End_Path - Finish + Last + Status) :=
Path_Buffer (Finish + 1 .. End_Path);
End_Path := End_Path - Finish + Last + Status;
Path_Buffer (Last + 1 .. Last + Status) :=
Link_Buffer (1 .. Status);
end if;
end if;
end if;
end loop;
-- Too many iterations: give up
-- This can happen when there is a circularity in the symbolic links:
-- A is a symbolic link for B, which itself is a symbolic link, and
-- the target of B or of another symbolic link target of B is A.
-- In this case, we return an empty string to indicate failure to
-- resolve.
return "";
end Normalize_Pathname;
---------------
-- Open_Read --
---------------
function Open_Read
(Name : C_File_Name;
Fmode : Mode)
return File_Descriptor
is
function C_Open_Read
(Name : C_File_Name;
Fmode : Mode)
return File_Descriptor;
pragma Import (C, C_Open_Read, "__gnat_open_read");
begin
return C_Open_Read (Name, Fmode);
end Open_Read;
function Open_Read
(Name : String;
Fmode : Mode)
return File_Descriptor
is
C_Name : String (1 .. Name'Length + 1);
begin
C_Name (1 .. Name'Length) := Name;
C_Name (C_Name'Last) := ASCII.NUL;
return Open_Read (C_Name (C_Name'First)'Address, Fmode);
end Open_Read;
---------------------
-- Open_Read_Write --
---------------------
function Open_Read_Write
(Name : C_File_Name;
Fmode : Mode)
return File_Descriptor
is
function C_Open_Read_Write
(Name : C_File_Name;
Fmode : Mode)
return File_Descriptor;
pragma Import (C, C_Open_Read_Write, "__gnat_open_rw");
begin
return C_Open_Read_Write (Name, Fmode);
end Open_Read_Write;
function Open_Read_Write
(Name : String;
Fmode : Mode)
return File_Descriptor
is
C_Name : String (1 .. Name'Length + 1);
begin
C_Name (1 .. Name'Length) := Name;
C_Name (C_Name'Last) := ASCII.NUL;
return Open_Read_Write (C_Name (C_Name'First)'Address, Fmode);
end Open_Read_Write;
-----------------
-- Rename_File --
-----------------
procedure Rename_File
(Old_Name : C_File_Name;
New_Name : C_File_Name;
Success : out Boolean)
is
function rename (From, To : Address) return Integer;
pragma Import (C, rename, "rename");
R : Integer;
begin
R := rename (Old_Name, New_Name);
Success := (R = 0);
end Rename_File;
procedure Rename_File
(Old_Name : String;
New_Name : String;
Success : out Boolean)
is
C_Old_Name : String (1 .. Old_Name'Length + 1);
C_New_Name : String (1 .. New_Name'Length + 1);
begin
C_Old_Name (1 .. Old_Name'Length) := Old_Name;
C_Old_Name (C_Old_Name'Last) := ASCII.NUL;
C_New_Name (1 .. New_Name'Length) := New_Name;
C_New_Name (C_New_Name'Last) := ASCII.NUL;
Rename_File (C_Old_Name'Address, C_New_Name'Address, Success);
end Rename_File;
------------
-- Setenv --
------------
procedure Setenv (Name : String; Value : String) is
F_Name : String (1 .. Name'Length + 1);
F_Value : String (1 .. Value'Length + 1);
procedure Set_Env_Value (Name, Value : System.Address);
pragma Import (C, Set_Env_Value, "__gnat_set_env_value");
begin
F_Name (1 .. Name'Length) := Name;
F_Name (F_Name'Last) := ASCII.NUL;
F_Value (1 .. Value'Length) := Value;
F_Value (F_Value'Last) := ASCII.NUL;
Set_Env_Value (F_Name'Address, F_Value'Address);
end Setenv;
-----------
-- Spawn --
-----------
function Spawn
(Program_Name : String;
Args : Argument_List)
return Integer
is
Junk : Process_Id;
Result : Integer;
begin
Spawn_Internal (Program_Name, Args, Result, Junk, Blocking => True);
return Result;
end Spawn;
procedure Spawn
(Program_Name : String;
Args : Argument_List;
Success : out Boolean)
is
begin
Success := (Spawn (Program_Name, Args) = 0);
end Spawn;
--------------------
-- Spawn_Internal --
--------------------
procedure Spawn_Internal
(Program_Name : String;
Args : Argument_List;
Result : out Integer;
Pid : out Process_Id;
Blocking : Boolean)
is
type Chars is array (Positive range <>) of aliased Character;
type Char_Ptr is access constant Character;
Command_Len : constant Positive := Program_Name'Length + 1
+ Args_Length (Args);
Command_Last : Natural := 0;
Command : aliased Chars (1 .. Command_Len);
-- Command contains all characters of the Program_Name and Args,
-- all terminated by ASCII.NUL characters
Arg_List_Len : constant Positive := Args'Length + 2;
Arg_List_Last : Natural := 0;
Arg_List : aliased array (1 .. Arg_List_Len) of Char_Ptr;
-- List with pointers to NUL-terminated strings of the
-- Program_Name and the Args and terminated with a null pointer.
-- We rely on the default initialization for the last null pointer.
procedure Add_To_Command (S : String);
-- Add S and a NUL character to Command, updating Last
function Portable_Spawn (Args : Address) return Integer;
pragma Import (C, Portable_Spawn, "__gnat_portable_spawn");
function Portable_No_Block_Spawn (Args : Address) return Process_Id;
pragma Import
(C, Portable_No_Block_Spawn, "__gnat_portable_no_block_spawn");
--------------------
-- Add_To_Command --
--------------------
procedure Add_To_Command (S : String) is
First : constant Natural := Command_Last + 1;
begin
Command_Last := Command_Last + S'Length;
-- Move characters one at a time, because Command has
-- aliased components.
for J in S'Range loop
Command (First + J - S'First) := S (J);
end loop;
Command_Last := Command_Last + 1;
Command (Command_Last) := ASCII.NUL;
Arg_List_Last := Arg_List_Last + 1;
Arg_List (Arg_List_Last) := Command (First)'Access;
end Add_To_Command;
-- Start of processing for Spawn_Internal
begin
Add_To_Command (Program_Name);
for J in Args'Range loop
Add_To_Command (Args (J).all);
end loop;
if Blocking then
Pid := Invalid_Pid;
Result := Portable_Spawn (Arg_List'Address);
else
Pid := Portable_No_Block_Spawn (Arg_List'Address);
Result := Boolean'Pos (Pid /= Invalid_Pid);
end if;
end Spawn_Internal;
---------------------------
-- To_Path_String_Access --
---------------------------
function To_Path_String_Access
(Path_Addr : Address;
Path_Len : Integer)
return String_Access
is
subtype Path_String is String (1 .. Path_Len);
type Path_String_Access is access Path_String;
function Address_To_Access is new
Unchecked_Conversion (Source => Address,
Target => Path_String_Access);
Path_Access : Path_String_Access := Address_To_Access (Path_Addr);
Return_Val : String_Access;
begin
Return_Val := new String (1 .. Path_Len);
for J in 1 .. Path_Len loop
Return_Val (J) := Path_Access (J);
end loop;
return Return_Val;
end To_Path_String_Access;
------------------
-- Wait_Process --
------------------
procedure Wait_Process (Pid : out Process_Id; Success : out Boolean) is
Status : Integer;
function Portable_Wait (S : Address) return Process_Id;
pragma Import (C, Portable_Wait, "__gnat_portable_wait");
begin
Pid := Portable_Wait (Status'Address);
Success := (Status = 0);
end Wait_Process;
end GNAT.OS_Lib;
|
-- part of OpenGLAda, (c) 2017 Felix Krause
-- released under the terms of the MIT license, see the file "COPYING"
with GL.Toggles;
with GL.Low_Level;
private package GL.Enums is
pragma Preelaborate;
type Attribute_Mask is record
Depth_Buffer : Boolean;
Stencil_Buffer : Boolean;
Color_Buffer : Boolean;
end record;
type Blending_Factor_Destination is (Zero, One, Src_Color, One_Minus_Src_Color,
Src_Alpha, One_Minus_Src_Alpha, Dst_Alpha,
One_Minus_Dst_Alpha);
type Blending_Factor_Source is (Dst_Color, One_Minus_Dst_Color,
Src_Alpha_Saturate);
type Front_Face_Direction is (CW, CCW);
type Matrix_Mode is (Modelview, Projection, Texture, Color);
type Light_Model_Parameter is (Local_Viewer, Two_Side,
Ambient, Color_Control);
for Light_Model_Parameter use (Local_Viewer => 16#0B51#,
Two_Side => 16#0B52#,
Ambient => 16#0B53#,
Color_Control => 16#81F8#);
for Light_Model_Parameter'Size use Low_Level.Enum'Size;
subtype Light_Model_Ambient_Parameter is Light_Model_Parameter range
Ambient .. Ambient;
subtype Light_Model_CC_Parameter is Light_Model_Parameter range
Color_Control .. Color_Control;
subtype Light_Model_Toggle_Parameter is Light_Model_Parameter range
Local_Viewer .. Two_Side;
type Light_Param is (Ambient, Diffuse, Specular, Position,
Spot_Direction, Spot_Exponent, Spot_Cutoff,
Constant_Attenduation, Linear_Attenduation,
Quadratic_Attenduation);
subtype Light_Name is Toggles.Toggle range Toggles.Light0 .. Toggles.Light7;
type Shader_Param is (Shader_Type, Delete_Status, Compile_Status,
Info_Log_Length, Shader_Source_Length);
type Program_Param is
(Program_Binary_Length, Geometry_Vertices_Out, Geometry_Input_Type,
Geometry_Output_Type, Active_Uniform_Block_Max_Name_Length,
Active_Uniform_Blocks, Delete_Status, Link_Status, Validate_Status,
Info_Log_Length, Attached_Shaders, Active_Uniforms,
Active_Uniform_Max_Length, Active_Attributes, Active_Attribute_Max_Length,
Transform_Feedback_Varying_Max_Length, Transform_Feedback_Buffer_Mode,
Transform_Feedback_Varyings,
Transform_Feedback_Buffer_Start, Transform_Feedback_Buffer_Size,
Primitives_Generated, Transform_Feedback_Primitives_Written,
Rasterizer_Discard, Max_Transform_Feedback_Interleaved_Components,
Max_Transform_Feedback_Separate_Attribs, Interleaved_Attribs,
Separate_Attribs, Transform_Feedback_Buffer,
Transform_Feedback_Buffer_Binding,
Tess_Control_Output_Vertices, Tess_Gen_Mode,
Tess_Gen_Spacing, Tess_Gen_Vertex_Order, Tess_Gen_Point_Mode);
type Program_Stage_Param is (Active_Subroutines, Active_Subroutine_Uniforms,
Active_Subroutine_Uniform_Locations,
Active_Subroutine_Max_Length,
Active_Subroutine_Uniform_Max_Length);
type Clamp_Color_Param is (Clamp_Read_Color);
type Pixel_Store_Param is (Unpack_Swap_Bytes, Unpack_LSB_First,
Unpack_Row_Length, Unpack_Skip_Rows,
Unpack_Skip_Pixels, Unpack_Alignment,
Pack_Swap_Bytes, Pack_LSB_First, Pack_Row_Length,
Pack_Skip_Rows, Pack_Skip_Pixels,
Pack_Alignment, Pack_Skip_Images, Pack_Image_Height,
Unpack_Skip_Images, Unpack_Image_Height);
type Buffer_Param is (Buffer_Size, Buffer_Usage,
Buffer_Access, Buffer_Mapped);
type Buffer_Pointer_Param is (Buffer_Map_Pointer);
type Framebuffer_Param is (Default_Width, Default_Height, Default_Layers,
Default_Samples, Default_Fixed_Sample_Locations);
type Patch_Parameter_Int is (Vertices);
type Patch_Parameter_Float_Array is
(Default_Inner_Level, Default_Outer_Level);
type Point_Param is (Fade_Threshold_Size);
private
for Attribute_Mask use record
Depth_Buffer at 1 range 0 .. 0;
Stencil_Buffer at 1 range 2 .. 2;
Color_Buffer at 1 range 6 .. 6;
end record;
for Attribute_Mask'Size use Low_Level.Bitfield'Size;
for Blending_Factor_Destination use (Zero => 0,
One => 1,
Src_Color => 16#0300#,
One_Minus_Src_Color => 16#0301#,
Src_Alpha => 16#0302#,
One_Minus_Src_Alpha => 16#0303#,
Dst_Alpha => 16#0304#,
One_Minus_Dst_Alpha => 16#0305#);
for Blending_Factor_Destination'Size use Low_Level.Enum'Size;
for Blending_Factor_Source use (Dst_Color => 16#0306#,
One_Minus_Dst_Color => 16#0307#,
Src_Alpha_Saturate => 16#0308#);
for Blending_Factor_Source'Size use Low_Level.Enum'Size;
for Front_Face_Direction use (CW => 16#0900#,
CCW => 16#0901#);
for Front_Face_Direction'Size use Low_Level.Enum'Size;
for Matrix_Mode use (Modelview => 16#1700#,
Projection => 16#1701#,
Texture => 16#1702#,
Color => 16#1800#);
for Matrix_Mode'Size use Low_Level.Enum'Size;
for Light_Param use (Ambient => 16#1200#,
Diffuse => 16#1201#,
Specular => 16#1202#,
Position => 16#1203#,
Spot_Direction => 16#1204#,
Spot_Exponent => 16#1205#,
Spot_Cutoff => 16#1206#,
Constant_Attenduation => 16#1207#,
Linear_Attenduation => 16#1208#,
Quadratic_Attenduation => 16#1209#);
for Light_Param'Size use Low_Level.Enum'Size;
for Shader_Param use (Shader_Type => 16#8B4F#,
Delete_Status => 16#8B80#,
Compile_Status => 16#8B81#,
Info_Log_Length => 16#8B84#,
Shader_Source_Length => 16#8B88#);
for Shader_Param'Size use Low_Level.Enum'Size;
for Program_Param use (Program_Binary_Length => 16#8741#,
Geometry_Vertices_Out => 16#8916#,
Geometry_Input_Type => 16#8917#,
Geometry_Output_Type => 16#8918#,
Active_Uniform_Block_Max_Name_Length => 16#8A35#,
Active_Uniform_Blocks => 16#8A36#,
Delete_Status => 16#8B4F#,
Link_Status => 16#8B82#,
Validate_Status => 16#8B83#,
Info_Log_Length => 16#8B84#,
Attached_Shaders => 16#8B85#,
Active_Uniforms => 16#8B86#,
Active_Uniform_Max_Length => 16#8B87#,
Active_Attributes => 16#8B89#,
Active_Attribute_Max_Length => 16#8B8A#,
Transform_Feedback_Varying_Max_Length => 16#8C76#,
Transform_Feedback_Buffer_Mode => 16#8C7F#,
Transform_Feedback_Varyings => 16#8C83#,
Transform_Feedback_Buffer_Start => 16#8C84#,
Transform_Feedback_Buffer_Size => 16#8C85#,
Primitives_Generated => 16#8C87#,
Transform_Feedback_Primitives_Written => 16#8C88#,
Rasterizer_Discard => 16#8C89#,
Max_Transform_Feedback_Interleaved_Components => 16#8C8A#,
Max_Transform_Feedback_Separate_Attribs => 16#8C8B#,
Interleaved_Attribs => 16#8C8C#,
Separate_Attribs => 16#8C8D#,
Transform_Feedback_Buffer => 16#8C8E#,
Transform_Feedback_Buffer_Binding => 16#8C8F#,
Tess_Control_Output_Vertices => 16#8E75#,
Tess_Gen_Mode => 16#8E76#,
Tess_Gen_Spacing => 16#8E77#,
Tess_Gen_Vertex_Order => 16#8E78#,
Tess_Gen_Point_Mode => 16#8E79#);
for Program_Param'Size use Low_Level.Enum'Size;
for Program_Stage_Param use (Active_Subroutines => 16#8DE5#,
Active_Subroutine_Uniforms => 16#8DE6#,
Active_Subroutine_Uniform_Locations => 16#8E47#,
Active_Subroutine_Max_Length => 16#8E48#,
Active_Subroutine_Uniform_Max_Length => 16#8E49#);
for Program_Stage_Param'Size use Low_Level.Enum'Size;
for Clamp_Color_Param use (Clamp_Read_Color => 16#891C#);
for Clamp_Color_Param'Size use Low_Level.Enum'Size;
for Pixel_Store_Param use (Unpack_Swap_Bytes => 16#0CF0#,
Unpack_LSB_First => 16#0CF1#,
Unpack_Row_Length => 16#0CF2#,
Unpack_Skip_Rows => 16#0CF3#,
Unpack_Skip_Pixels => 16#0CF4#,
Unpack_Alignment => 16#0CF5#,
Pack_Swap_Bytes => 16#0D00#,
Pack_LSB_First => 16#0D01#,
Pack_Row_Length => 16#0D02#,
Pack_Skip_Rows => 16#0D03#,
Pack_Skip_Pixels => 16#0D04#,
Pack_Alignment => 16#0D05#,
Pack_Skip_Images => 16#806B#,
Pack_Image_Height => 16#806C#,
Unpack_Skip_Images => 16#806D#,
Unpack_Image_Height => 16#806E#);
for Pixel_Store_Param'Size use Low_Level.Enum'Size;
for Buffer_Param use (Buffer_Size => 16#8764#,
Buffer_Usage => 16#8765#,
Buffer_Access => 16#88BB#,
Buffer_Mapped => 16#88BC#);
for Buffer_Param'Size use Low_Level.Enum'Size;
for Buffer_Pointer_Param use (Buffer_Map_Pointer => 16#88BD#);
for Buffer_Pointer_Param'Size use Low_Level.Enum'Size;
for Framebuffer_Param use (Default_Width => 16#9310#,
Default_Height => 16#9311#,
Default_Layers => 16#9312#,
Default_Samples => 16#9313#,
Default_Fixed_Sample_Locations => 16#9314#);
for Framebuffer_Param'Size use Low_Level.Enum'Size;
for Patch_Parameter_Int use (Vertices => 16#8E72#);
for Patch_Parameter_Int'Size use Low_Level.Enum'Size;
for Patch_Parameter_Float_Array use (Default_Inner_Level => 16#8E73#,
Default_Outer_Level => 16#8E74#);
for Patch_Parameter_Float_Array'Size use Low_Level.Enum'Size;
for Point_Param use (Fade_Threshold_Size => 16#8128#);
for Point_Param'Size use Low_Level.Enum'Size;
end GL.Enums;
|
with Ada.Text_IO, Ada.Integer_Text_IO, copia_examenes;
use copia_examenes;
use Ada.Text_Io, Ada.Integer_Text_Io;
procedure Escribir_aula_act(aula_act: in T_Aula) is
begin
New_Line;
Put_line("----------------------------------------------------------------------");
for i in 1..10 loop
for J in 1..10 loop
put("|");
if aula_act(i,j).ocupada=true then
Put(" "); put("T ");Put(aula_act(I, J).ex.num_palabras_diferentes, width => 0); Put(" ");
else Put(" F ");
end if;
end loop;
put("|");
new_line;
for J in 1..10 loop
put("|");
if aula_act(i,j).ocupada=true then
for x in 1..aula_act(I, J).ex.num_palabras_diferentes loop
Put(aula_act(I, J).ex.palabras(x).n_apariciones, width => 0);
end loop;
for z in aula_act(I, J).ex.num_palabras_diferentes+1..6 loop
put(" ");
end loop;
else
for z in 1..6 loop
put(" ");
end loop;
end if;
end loop;
put("|");
new_line;
Put_line("----------------------------------------------------------------------");
end loop;
put_line("Por cuestiones de espacio en este caso de prueba");
put_line("el n_apariciones de una variable no va ha ser mayor que 10");
put("Asi por ejemplo cuando en la casilla tenemos esta informacion: ");
new_line;
Put_line(" ------");
put_line(" | T 4 |");
put_line(" | 2367 |");
Put_line(" ------");
put_line(" Querra decir que la casilla esta ocupada (T de true)");
put_line(" que hay 4 variables, y aparcen 2,3,6,7 veces");
put_line(" el numero de apariciones de la primera es -> 2");
put_line(" el numero de apariciones de la segunda es -> 3");
put_line(" el numero de apariciones de la tercera es -> 6");
put_line(" y el numero de apariciones de la cuarta es -> 7");
end Escribir_aula_act;
|
-- { dg-do run }
-- { dg-options "-O1" }
with TREE_STATIC_Def; use TREE_STATIC_Def;
procedure TREE_STATIC_Use is
I : Int := One;
begin
check (I, 1);
end;
|
-----------------------------------------------------------------------
-- awa-modules-tests - Unit tests for Modules
-- Copyright (C) 2011, 2012 Stephane Carrez
-- Written by Stephane Carrez (Stephane.Carrez@gmail.com)
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-----------------------------------------------------------------------
with Util.Test_Caller;
with Util.Beans.Basic;
with Util.Beans.Objects;
with Ada.Unchecked_Deallocation;
with EL.Contexts.Default;
with ASF.Applications.Main;
with AWA.Modules.Beans;
with AWA.Services.Contexts;
package body AWA.Modules.Tests is
use Util.Tests;
type Test_Module is new AWA.Modules.Module with null record;
type Test_Module_Access is access all Test_Module'Class;
type Test_Bean is new Util.Beans.Basic.Bean with record
Module : Test_Module_Access := null;
Name : Util.Beans.Objects.Object;
Email : Util.Beans.Objects.Object;
end record;
type Test_Bean_Access is access all Test_Bean'Class;
-- 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 Test_Bean;
Name : in String) return Util.Beans.Objects.Object;
-- Set the value identified by the name.
-- If the name cannot be found, the method should raise the No_Value
-- exception.
overriding
procedure Set_Value (From : in out Test_Bean;
Name : in String;
Value : in Util.Beans.Objects.Object);
function Create_Form_Bean (Plugin : in Test_Module_Access)
return Util.Beans.Basic.Readonly_Bean_Access;
package Module_Register is new AWA.Modules.Beans (Test_Module, Test_Module_Access);
package Caller is new Util.Test_Caller (Test, "AWA.Modules");
procedure Add_Tests (Suite : in Util.Tests.Access_Test_Suite) is
begin
Caller.Add_Test (Suite, "Test ASF.Modules.Register",
Test_Create_Module'Access);
Caller.Add_Test (Suite, "Test ASF.Modules.Find_Module",
Test_Find_Module'Access);
Caller.Add_Test (Suite, "Test ASF.Applications.Main.Register",
Test_Create_Application_Module'Access);
Caller.Add_Test (Suite, "Test ASF.Applications.Main.Create",
Test_Create_Application_Module'Access);
Caller.Add_Test (Suite, "Test ASF.Navigations.Mappers",
Test_Module_Navigation'Access);
end Add_Tests;
-- ------------------------------
-- Get the value identified by the name.
-- If the name cannot be found, the method should return the Null object.
-- ------------------------------
function Get_Value (From : in Test_Bean;
Name : in String) return Util.Beans.Objects.Object is
begin
if Name = "module" then
return Util.Beans.Objects.To_Object (From.Module.Get_Name);
elsif Name = "name" then
return From.Name;
elsif Name = "email" then
return From.Email;
else
return Util.Beans.Objects.Null_Object;
end if;
end Get_Value;
-- ------------------------------
-- Set the value identified by the name.
-- If the name cannot be found, the method should raise the No_Value
-- exception.
-- ------------------------------
overriding
procedure Set_Value (From : in out Test_Bean;
Name : in String;
Value : in Util.Beans.Objects.Object) is
begin
if Name = "name" then
From.Name := Value;
elsif Name = "email" then
From.Email := Value;
end if;
end Set_Value;
function Create_Form_Bean (Plugin : in Test_Module_Access)
return Util.Beans.Basic.Readonly_Bean_Access is
Result : constant Test_Bean_Access := new Test_Bean;
begin
Result.Module := Plugin;
return Result.all'Access;
end Create_Form_Bean;
-- ------------------------------
-- Initialize the test application
-- ------------------------------
procedure Set_Up (T : in out Test) is
Fact : ASF.Applications.Main.Application_Factory;
C : ASF.Applications.Config;
begin
Log.Info ("Creating application");
T.App := new AWA.Applications.Application;
C.Copy (Util.Tests.Get_Properties);
C.Set ("app_search_dirs", Util.Tests.Get_Path ("regtests") & ";"
& C.Get ("app_search_dirs", ""));
T.App.Initialize (C, Fact);
T.App.Register ("layoutMsg", "layout");
end Set_Up;
-- ------------------------------
-- Deletes the application object
-- ------------------------------
overriding
procedure Tear_Down (T : in out Test) is
procedure Free is
new Ada.Unchecked_Deallocation (Object => AWA.Applications.Application'Class,
Name => AWA.Applications.Application_Access);
begin
Log.Info ("Releasing application");
Free (T.App);
end Tear_Down;
-- ------------------------------
-- Test creation of module
-- ------------------------------
procedure Test_Create_Module (T : in out Test) is
M : aliased Test_Module;
R : aliased Module_Registry;
Ctx : AWA.Services.Contexts.Service_Context;
begin
Ctx.Set_Context (T.App, null);
R.Config.Copy (Util.Tests.Get_Properties);
M.App := T.App.all'Access;
Register (R'Unchecked_Access, M.App, M'Unchecked_Access, "empty", "uri");
T.Assert_Equals ("empty", M.Get_Name, "Invalid module name");
T.Assert_Equals ("uri", M.Get_URI, "Invalid module uri");
T.Assert (Find_By_Name (R, "empty") = M'Unchecked_Access, "Find_By_Name failed");
T.Assert (Find_By_URI (R, "uri") = M'Unchecked_Access, "Find_By_URI failed");
end Test_Create_Module;
-- ------------------------------
-- Test looking for module
-- ------------------------------
procedure Test_Find_Module (T : in out Test) is
M : aliased Test_Module;
Ctx : AWA.Services.Contexts.Service_Context;
begin
Ctx.Set_Context (T.App, null);
M.App := T.App.all'Access;
T.App.Register (M'Unchecked_Access, "empty", "uri");
T.Assert (M.Find_Module ("empty") /= null, "Find_Module should not return a null value");
T.Assert (M.Find_Module ("toto") = null, "Find_Module should return null");
end Test_Find_Module;
-- ------------------------------
-- Test creation of a module and registration in an application.
-- ------------------------------
procedure Test_Create_Application_Module (T : in out Test) is
use ASF.Beans;
use type Util.Beans.Basic.Readonly_Bean_Access;
procedure Check (Name : in String;
Kind : in ASF.Beans.Scope_Type);
procedure Check (Name : in String;
Kind : in ASF.Beans.Scope_Type) is
Value : Util.Beans.Objects.Object;
Bean : Util.Beans.Basic.Readonly_Bean_Access;
Scope : ASF.Beans.Scope_Type;
Context : EL.Contexts.Default.Default_Context;
begin
T.App.Create (Name => To_Unbounded_String (Name),
Context => Context,
Result => Bean,
Scope => Scope);
T.Assert (Kind = Scope, "Invalid scope for " & Name);
T.Assert (Bean /= null, "Invalid bean object");
Value := Util.Beans.Objects.To_Object (Bean);
T.Assert (not Util.Beans.Objects.Is_Null (Value), "Invalid bean");
T.Assert_Equals ("test-module",
Util.Beans.Objects.To_String (Bean.Get_Value ("module")),
"Bean module name");
-- Special test for the sessionForm bean which is initialized by configuration properties
if Name = "sessionForm" then
T.Assert_Equals ("John.Rambo@gmail.com",
Util.Beans.Objects.To_String (Bean.Get_Value ("email")),
"Session form not initialized");
end if;
end Check;
M : aliased Test_Module;
Ctx : AWA.Services.Contexts.Service_Context;
begin
Ctx.Set_Context (T.App, null);
M.App := T.App.all'Access;
Module_Register.Register (Plugin => M,
Name => "ASF.Applications.Tests.Form_Bean",
Handler => Create_Form_Bean'Access);
T.App.Register (M'Unchecked_Access, "test-module", "uri");
T.Assert (M.Find_Module ("test-module") /= null,
"Find_Module should not return a null value");
T.Assert (M.Find_Module ("toto") = null, "Find_Module should return null");
-- Check the 'regtests/config/test-module.xml' managed bean configuration.
Check ("applicationForm", ASF.Beans.APPLICATION_SCOPE);
Check ("sessionForm", ASF.Beans.SESSION_SCOPE);
Check ("requestForm", ASF.Beans.REQUEST_SCOPE);
end Test_Create_Application_Module;
-- ------------------------------
-- Test module and navigation rules
-- ------------------------------
procedure Test_Module_Navigation (T : in out Test) is
use ASF.Beans;
use type Util.Beans.Basic.Readonly_Bean_Access;
M : aliased Test_Module;
Ctx : AWA.Services.Contexts.Service_Context;
begin
Ctx.Set_Context (T.App, null);
M.App := T.App.all'Access;
Module_Register.Register (Plugin => M,
Name => "ASF.Applications.Tests.Form_Bean",
Handler => Create_Form_Bean'Access);
T.App.Register (M'Unchecked_Access, "test-navigations", "uri");
T.Assert (M.Find_Module ("test-navigations") /= null,
"Find_Module should not return a null value");
end Test_Module_Navigation;
end AWA.Modules.Tests;
|
-- ////////////////////////////////////////////////////////////
-- //
-- // SFML - Simple and Fast Multimedia Library
-- // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
-- //
-- // 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.
-- //
-- ////////////////////////////////////////////////////////////
-- ////////////////////////////////////////////////////////////
-- // Headers
-- ////////////////////////////////////////////////////////////
with Sf.Config;
package Sf.Graphics.Rect is
use Sf.Config;
-- ////////////////////////////////////////////////////////////
-- /// sfFloatRect and sfIntRect are utility classes for
-- /// manipulating rectangles.
-- ////////////////////////////////////////////////////////////
type sfFloatRect is record
Left : aliased Float;
Top : aliased Float;
Right : aliased Float;
Bottom : aliased Float;
end record;
type sfIntRect is record
Left : aliased Integer;
Top : aliased Integer;
Right : aliased Integer;
Bottom : aliased Integer;
end record;
-- ////////////////////////////////////////////////////////////
-- /// Move a rectangle by the given offset
-- ///
-- /// \param Rect : Rectangle to move
-- /// \param OffsetX : Horizontal offset
-- /// \param OffsetY : Vertical offset
-- ///
-- ////////////////////////////////////////////////////////////
procedure sfFloatRect_Offset (Rect : access sfFloatRect; OffsetX, OffsetY : Float);
procedure sfIntRect_Offset (Rect : access sfIntRect; OffsetX, OffsetY : Integer);
-- ////////////////////////////////////////////////////////////
-- /// Check if a point is inside a rectangle's area
-- ///
-- /// \param Rect : Rectangle to test
-- /// \param X : X coordinate of the point to test
-- /// \param Y : Y coordinate of the point to test
-- ///
-- /// \return sfTrue if the point is inside
-- ///
-- ////////////////////////////////////////////////////////////
function sfFloatRect_Contains (Rect : access sfFloatRect; X, Y : Float) return sfBool;
function sfIntRect_Contains (Rect : access sfIntRect; X, Y : Float) return sfBool;
-- ////////////////////////////////////////////////////////////
-- /// Check intersection between two rectangles
-- ///
-- /// \param Rect1 : First rectangle to test
-- /// \param Rect2 : Second rectangle to test
-- /// \param OverlappingRect : Rectangle to be filled with overlapping rect (can be NULL)
-- ///
-- /// \return sfTrue if rectangles overlap
-- ///
-- ////////////////////////////////////////////////////////////
function sfFloatRect_Intersects (Rect1, Rect2, OverlappingRect : access sfFloatRect) return sfBool;
function sfIntRect_Intersects (Rect1, Rect2, OverlappingRect : access sfIntRect) return sfBool;
private
pragma Convention (C_Pass_By_Copy, sfFloatRect);
pragma Convention (C_Pass_By_Copy, sfIntRect);
pragma Import (C, sfFloatRect_Offset, "sfFloatRect_Offset");
pragma Import (C, sfIntRect_Offset, "sfIntRect_Offset");
pragma Import (C, sfFloatRect_Contains, "sfFloatRect_Contains");
pragma Import (C, sfIntRect_Contains, "sfIntRect_Contains");
pragma Import (C, sfFloatRect_Intersects, "sfFloatRect_Intersects");
pragma Import (C, sfIntRect_Intersects, "sfIntRect_Intersects");
end Sf.Graphics.Rect;
|
with Ada.Text_IO; use Ada.Text_IO;
procedure Steps_4 is
task Step_By_Step is
entry Step_One;
entry Step_Two;
entry Step_Three;
entry Finish;
end Step_By_Step;
task body Step_By_Step is
Keep_Looping : Boolean := TRUE;
begin
while Keep_Looping loop
select
accept Step_One do
Put_Line ("1");
end Step_One;
or
accept Step_Two do
Put_Line ("2");
end Step_Two;
or
accept Step_Three do
Put_Line ("3");
end Step_Three;
or
accept Finish do
Keep_Looping := FALSE;
end Finish;
end select;
Put_Line ("Again!");
end loop;
Put_Line ("Here we go");
end Step_By_Step;
begin
delay 1.0;
Put_Line ("Bye?");
Step_By_Step.Step_Three;
delay 1.0;
Step_By_Step.Step_Two;
delay 1.0;
Put_Line ("Bye by me, not by the task!");
delay 1.0;
Step_By_Step.Finish;
end;
|
-- SPDX-License-Identifier: Apache-2.0
--
-- Copyright (c) 2020 onox <denkpadje@gmail.com>
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
with Orka.Behaviors;
with Orka.Cameras;
with Orka.Rendering.Programs.Modules;
with Orka.Resources.Locations;
private with GL.Low_Level.Enums;
private with Orka.Rendering.Programs.Uniforms;
package Orka.Features.Atmosphere.Rendering is
pragma Preelaborate;
Sun_Radius_Meter : constant := 695_700_000.0;
type Model_Parameters is record
Semi_Major_Axis : Cameras.Distance;
Flattening : Cameras.Distance := 0.0;
Axial_Tilt : Cameras.Angle;
Star_Radius : Cameras.Distance := Sun_Radius_Meter;
end record;
-- Semi-major axis and the axial tilt are only used if flattening > 0.0
type Atmosphere is tagged limited private;
function Create_Atmosphere
(Data : aliased Model_Data;
Location : Resources.Locations.Location_Ptr;
Parameters : Model_Parameters := (others => <>)) return Atmosphere;
function Shader_Module (Object : Atmosphere) return Orka.Rendering.Programs.Modules.Module;
-- Return the shader module for use by other features like terrain
-- rendering
procedure Render
(Object : in out Atmosphere;
Camera : Cameras.Camera_Ptr;
Planet : Behaviors.Behavior_Ptr;
Star : Behaviors.Behavior_Ptr);
-- Render the atmosphere on the far plane
--
-- This procedure assumes that the precomputed textures have been
-- binded with procedure Orka.Features.Atmosphere.Bind_Textures.
private
package LE renames GL.Low_Level.Enums;
package Programs renames Orka.Rendering.Programs;
type Atmosphere is tagged limited record
Program : Programs.Program;
Module : Programs.Modules.Module;
Parameters : Model_Parameters;
Bottom_Radius : GL.Types.Double;
Distance_Scale : GL.Types.Double;
Uniform_Ground_Hack : Programs.Uniforms.Uniform (LE.Bool_Type);
Uniform_Camera_Offset : Programs.Uniforms.Uniform (LE.Single_Vec4);
Uniform_Camera_Pos : Programs.Uniforms.Uniform (LE.Single_Vec4);
Uniform_Planet_Pos : Programs.Uniforms.Uniform (LE.Single_Vec4);
Uniform_Star_Dir : Programs.Uniforms.Uniform (LE.Single_Vec4);
Uniform_Star_Size : Programs.Uniforms.Uniform (LE.Single_Type);
Uniform_Sun_Dir : Programs.Uniforms.Uniform (LE.Single_Vec4);
Uniform_View : Programs.Uniforms.Uniform (LE.Single_Matrix4);
Uniform_Proj : Programs.Uniforms.Uniform (LE.Single_Matrix4);
end record;
end Orka.Features.Atmosphere.Rendering;
|
with AdaBase.Results.Sets;
with Connect;
with CommonText;
with Ada.Text_IO;
with Ada.Command_Line;
procedure Memcheck is
package CON renames Connect;
package TIO renames Ada.Text_IO;
package CLI renames Ada.Command_Line;
package AR renames AdaBase.Results;
package CT renames CommonText;
procedure list_hockey_teams3;
procedure list_hockey_teams (row : AR.Sets.Datarow);
procedure list_hockey_teams (row : AR.Sets.Datarow) is
begin
TIO.Put_Line (row.column ("city").as_string & " " &
row.column ("mascot").as_string & " (" &
row.column ("abbreviation").as_string & ")");
end list_hockey_teams;
testnumber : Integer := 1;
cycles : Integer;
Ch : Character;
city, mascot, abbr : aliased AR.Textual;
procedure list_hockey_teams3 is
begin
TIO.Put_Line (CT.USS (abbr) & ": " & CT.USS (city) & " " &
CT.USS (mascot));
end list_hockey_teams3;
begin
if CLI.Argument_Count < 1 then
TIO.Put_Line ("Please input number of times to execute");
return;
else
cycles := Integer'Value (CLI.Argument (1));
end if;
if CLI.Argument_Count >= 2 then
testnumber := Integer'Value (CLI.Argument (2));
end if;
-- PostgreSQL driver keeps track of all the query names waiting for
-- the transaction to end, but it never does so the storage vector
-- keeps building. We can either set autocommit=on or command a
-- commit after each cycle (one prevents memory from getting used,
-- the other constantly reclaims it. The end result is the same)
CON.DR.set_trait_autocommit (True);
CON.connect_database;
for x in Integer range 1 .. cycles loop
if testnumber = 1 then
declare
stmt : CON.Stmt_Type :=
CON.DR.prepare_select
(tables => "nhl_teams",
null_sort => AdaBase.nulls_first,
columns => "*");
begin
if stmt.execute then
stmt.iterate (process => list_hockey_teams'Access);
end if;
TIO.Put_Line ("T1: Finished iteration" & x'Img);
end;
elsif testnumber = 2 then
declare
stmt : CON.Stmt_Type :=
CON.DR.query_select
(tables => "nhl_teams",
null_sort => AdaBase.nulls_first,
columns => "*");
begin
stmt.iterate (process => list_hockey_teams'Access);
TIO.Put_Line ("T2: Finished iteration" & x'Img);
end;
elsif testnumber = 3 then
declare
stmt : CON.Stmt_Type := CON.DR.query ("SELECT * FROM nhl_teams");
begin
stmt.bind (2, abbr'Unchecked_Access);
stmt.bind (3, city'Unchecked_Access);
stmt.bind (4, mascot'Unchecked_Access);
stmt.iterate (process => list_hockey_teams3'Access);
TIO.Put_Line ("T3: Finished iteration" & x'Img);
end;
elsif testnumber = 4 then
declare
stmt : CON.Stmt_Type := CON.DR.prepare ("SELECT * FROM nhl_teams");
begin
if stmt.execute then
stmt.bind (2, abbr'Unchecked_Access);
stmt.bind (3, city'Unchecked_Access);
stmt.bind (4, mascot'Unchecked_Access);
stmt.iterate (process => list_hockey_teams3'Access);
end if;
TIO.Put_Line ("T4: Finished iteration" & x'Img);
end;
end if;
end loop;
TIO.Put_Line ("press any key");
TIO.Get_Immediate (Ch);
CON.DR.disconnect;
end Memcheck;
|
-- This spec has been automatically generated from STM32WB55x.svd
pragma Restrictions (No_Elaboration_Code);
pragma Ada_2012;
pragma Style_Checks (Off);
with HAL;
with System;
package STM32_SVD.LCD is
pragma Preelaborate;
---------------
-- Registers --
---------------
subtype CR_DUTY_Field is HAL.UInt3;
subtype CR_BIAS_Field is HAL.UInt2;
type CR_Register is record
LCDEN : Boolean := False;
VSEL : Boolean := False;
DUTY : CR_DUTY_Field := 16#0#;
BIAS : CR_BIAS_Field := 16#0#;
MUX_SEG : Boolean := False;
BUFEN : Boolean := False;
-- unspecified
Reserved_9_31 : HAL.UInt23 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for CR_Register use record
LCDEN at 0 range 0 .. 0;
VSEL at 0 range 1 .. 1;
DUTY at 0 range 2 .. 4;
BIAS at 0 range 5 .. 6;
MUX_SEG at 0 range 7 .. 7;
BUFEN at 0 range 8 .. 8;
Reserved_9_31 at 0 range 9 .. 31;
end record;
subtype FCR_PON_Field is HAL.UInt3;
subtype FCR_DEAD_Field is HAL.UInt3;
subtype FCR_CC_Field is HAL.UInt3;
subtype FCR_BLINKF_Field is HAL.UInt3;
subtype FCR_BLINK_Field is HAL.UInt2;
subtype FCR_DIV_Field is HAL.UInt4;
subtype FCR_PS_Field is HAL.UInt4;
type FCR_Register is record
HD : Boolean := False;
SOFIE : Boolean := False;
-- unspecified
Reserved_2_2 : HAL.Bit := 16#0#;
UDDIE : Boolean := False;
PON : FCR_PON_Field := 16#0#;
DEAD : FCR_DEAD_Field := 16#0#;
CC : FCR_CC_Field := 16#0#;
BLINKF : FCR_BLINKF_Field := 16#0#;
BLINK : FCR_BLINK_Field := 16#0#;
DIV : FCR_DIV_Field := 16#0#;
PS : FCR_PS_Field := 16#0#;
-- unspecified
Reserved_26_31 : HAL.UInt6 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for FCR_Register use record
HD at 0 range 0 .. 0;
SOFIE at 0 range 1 .. 1;
Reserved_2_2 at 0 range 2 .. 2;
UDDIE at 0 range 3 .. 3;
PON at 0 range 4 .. 6;
DEAD at 0 range 7 .. 9;
CC at 0 range 10 .. 12;
BLINKF at 0 range 13 .. 15;
BLINK at 0 range 16 .. 17;
DIV at 0 range 18 .. 21;
PS at 0 range 22 .. 25;
Reserved_26_31 at 0 range 26 .. 31;
end record;
type SR_Register is record
ENS : Boolean := False;
SOF : Boolean := False;
UDR : Boolean := False;
UDD : Boolean := False;
RDY : Boolean := False;
FCRSF : Boolean := False;
-- unspecified
Reserved_6_31 : HAL.UInt26 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for SR_Register use record
ENS at 0 range 0 .. 0;
SOF at 0 range 1 .. 1;
UDR at 0 range 2 .. 2;
UDD at 0 range 3 .. 3;
RDY at 0 range 4 .. 4;
FCRSF at 0 range 5 .. 5;
Reserved_6_31 at 0 range 6 .. 31;
end record;
type CLR_Register is record
-- unspecified
Reserved_0_0 : HAL.Bit := 16#0#;
SOFC : Boolean := False;
-- unspecified
Reserved_2_2 : HAL.Bit := 16#0#;
UDDC : Boolean := False;
-- unspecified
Reserved_4_31 : HAL.UInt28 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for CLR_Register use record
Reserved_0_0 at 0 range 0 .. 0;
SOFC at 0 range 1 .. 1;
Reserved_2_2 at 0 range 2 .. 2;
UDDC at 0 range 3 .. 3;
Reserved_4_31 at 0 range 4 .. 31;
end record;
-- RAM0A_S array
type RAM0A_S_Field_Array is array (0 .. 31) of Boolean
with Component_Size => 1, Size => 32;
type RAM0A_Register
(As_Array : Boolean := False)
is record
case As_Array is
when False =>
-- S as a value
Val : HAL.UInt32;
when True =>
-- S as an array
Arr : RAM0A_S_Field_Array;
end case;
end record
with Unchecked_Union, Size => 32, Volatile_Full_Access,
Bit_Order => System.Low_Order_First;
for RAM0A_Register use record
Val at 0 range 0 .. 31;
Arr at 0 range 0 .. 31;
end record;
-- RAM0B_S array
type RAM0B_S_Field_Array is array (32 .. 43) of Boolean
with Component_Size => 1, Size => 12;
-- Type definition for RAM0B_S
type RAM0B_S_Field
(As_Array : Boolean := False)
is record
case As_Array is
when False =>
-- S as a value
Val : HAL.UInt12;
when True =>
-- S as an array
Arr : RAM0B_S_Field_Array;
end case;
end record
with Unchecked_Union, Size => 12;
for RAM0B_S_Field use record
Val at 0 range 0 .. 11;
Arr at 0 range 0 .. 11;
end record;
type RAM0B_Register is record
S : RAM0B_S_Field := (As_Array => False, Val => 16#0#);
-- unspecified
Reserved_12_31 : HAL.UInt20 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for RAM0B_Register use record
S at 0 range 0 .. 11;
Reserved_12_31 at 0 range 12 .. 31;
end record;
-- RAM1A_S array
type RAM1A_S_Field_Array is array (0 .. 31) of Boolean
with Component_Size => 1, Size => 32;
type RAM1A_Register
(As_Array : Boolean := False)
is record
case As_Array is
when False =>
-- S as a value
Val : HAL.UInt32;
when True =>
-- S as an array
Arr : RAM1A_S_Field_Array;
end case;
end record
with Unchecked_Union, Size => 32, Volatile_Full_Access,
Bit_Order => System.Low_Order_First;
for RAM1A_Register use record
Val at 0 range 0 .. 31;
Arr at 0 range 0 .. 31;
end record;
-- RAM1B_S array
type RAM1B_S_Field_Array is array (32 .. 43) of Boolean
with Component_Size => 1, Size => 12;
-- Type definition for RAM1B_S
type RAM1B_S_Field
(As_Array : Boolean := False)
is record
case As_Array is
when False =>
-- S as a value
Val : HAL.UInt12;
when True =>
-- S as an array
Arr : RAM1B_S_Field_Array;
end case;
end record
with Unchecked_Union, Size => 12;
for RAM1B_S_Field use record
Val at 0 range 0 .. 11;
Arr at 0 range 0 .. 11;
end record;
type RAM1B_Register is record
S : RAM1B_S_Field := (As_Array => False, Val => 16#0#);
-- unspecified
Reserved_12_31 : HAL.UInt20 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for RAM1B_Register use record
S at 0 range 0 .. 11;
Reserved_12_31 at 0 range 12 .. 31;
end record;
-- RAM2A_S array
type RAM2A_S_Field_Array is array (0 .. 31) of Boolean
with Component_Size => 1, Size => 32;
type RAM2A_Register
(As_Array : Boolean := False)
is record
case As_Array is
when False =>
-- S as a value
Val : HAL.UInt32;
when True =>
-- S as an array
Arr : RAM2A_S_Field_Array;
end case;
end record
with Unchecked_Union, Size => 32, Volatile_Full_Access,
Bit_Order => System.Low_Order_First;
for RAM2A_Register use record
Val at 0 range 0 .. 31;
Arr at 0 range 0 .. 31;
end record;
-- RAM2B_S array
type RAM2B_S_Field_Array is array (32 .. 43) of Boolean
with Component_Size => 1, Size => 12;
-- Type definition for RAM2B_S
type RAM2B_S_Field
(As_Array : Boolean := False)
is record
case As_Array is
when False =>
-- S as a value
Val : HAL.UInt12;
when True =>
-- S as an array
Arr : RAM2B_S_Field_Array;
end case;
end record
with Unchecked_Union, Size => 12;
for RAM2B_S_Field use record
Val at 0 range 0 .. 11;
Arr at 0 range 0 .. 11;
end record;
type RAM2B_Register is record
S : RAM2B_S_Field := (As_Array => False, Val => 16#0#);
-- unspecified
Reserved_12_31 : HAL.UInt20 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for RAM2B_Register use record
S at 0 range 0 .. 11;
Reserved_12_31 at 0 range 12 .. 31;
end record;
-- RAM3A_S array
type RAM3A_S_Field_Array is array (0 .. 31) of Boolean
with Component_Size => 1, Size => 32;
type RAM3A_Register
(As_Array : Boolean := False)
is record
case As_Array is
when False =>
-- S as a value
Val : HAL.UInt32;
when True =>
-- S as an array
Arr : RAM3A_S_Field_Array;
end case;
end record
with Unchecked_Union, Size => 32, Volatile_Full_Access,
Bit_Order => System.Low_Order_First;
for RAM3A_Register use record
Val at 0 range 0 .. 31;
Arr at 0 range 0 .. 31;
end record;
-- RAM3B_S array
type RAM3B_S_Field_Array is array (32 .. 43) of Boolean
with Component_Size => 1, Size => 12;
-- Type definition for RAM3B_S
type RAM3B_S_Field
(As_Array : Boolean := False)
is record
case As_Array is
when False =>
-- S as a value
Val : HAL.UInt12;
when True =>
-- S as an array
Arr : RAM3B_S_Field_Array;
end case;
end record
with Unchecked_Union, Size => 12;
for RAM3B_S_Field use record
Val at 0 range 0 .. 11;
Arr at 0 range 0 .. 11;
end record;
type RAM3B_Register is record
S : RAM3B_S_Field := (As_Array => False, Val => 16#0#);
-- unspecified
Reserved_12_31 : HAL.UInt20 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for RAM3B_Register use record
S at 0 range 0 .. 11;
Reserved_12_31 at 0 range 12 .. 31;
end record;
-- RAM4A_S array
type RAM4A_S_Field_Array is array (0 .. 31) of Boolean
with Component_Size => 1, Size => 32;
type RAM4A_Register
(As_Array : Boolean := False)
is record
case As_Array is
when False =>
-- S as a value
Val : HAL.UInt32;
when True =>
-- S as an array
Arr : RAM4A_S_Field_Array;
end case;
end record
with Unchecked_Union, Size => 32, Volatile_Full_Access,
Bit_Order => System.Low_Order_First;
for RAM4A_Register use record
Val at 0 range 0 .. 31;
Arr at 0 range 0 .. 31;
end record;
-- RAM4B_S array
type RAM4B_S_Field_Array is array (32 .. 39) of Boolean
with Component_Size => 1, Size => 8;
-- Type definition for RAM4B_S
type RAM4B_S_Field
(As_Array : Boolean := False)
is record
case As_Array is
when False =>
-- S as a value
Val : HAL.UInt8;
when True =>
-- S as an array
Arr : RAM4B_S_Field_Array;
end case;
end record
with Unchecked_Union, Size => 8;
for RAM4B_S_Field use record
Val at 0 range 0 .. 7;
Arr at 0 range 0 .. 7;
end record;
type RAM4B_Register is record
S : RAM4B_S_Field := (As_Array => False, Val => 16#0#);
-- unspecified
Reserved_8_31 : HAL.UInt24 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for RAM4B_Register use record
S at 0 range 0 .. 7;
Reserved_8_31 at 0 range 8 .. 31;
end record;
-- RAM5A_S array
type RAM5A_S_Field_Array is array (0 .. 31) of Boolean
with Component_Size => 1, Size => 32;
type RAM5A_Register
(As_Array : Boolean := False)
is record
case As_Array is
when False =>
-- S as a value
Val : HAL.UInt32;
when True =>
-- S as an array
Arr : RAM5A_S_Field_Array;
end case;
end record
with Unchecked_Union, Size => 32, Volatile_Full_Access,
Bit_Order => System.Low_Order_First;
for RAM5A_Register use record
Val at 0 range 0 .. 31;
Arr at 0 range 0 .. 31;
end record;
-- RAM5B_S array
type RAM5B_S_Field_Array is array (32 .. 39) of Boolean
with Component_Size => 1, Size => 8;
-- Type definition for RAM5B_S
type RAM5B_S_Field
(As_Array : Boolean := False)
is record
case As_Array is
when False =>
-- S as a value
Val : HAL.UInt8;
when True =>
-- S as an array
Arr : RAM5B_S_Field_Array;
end case;
end record
with Unchecked_Union, Size => 8;
for RAM5B_S_Field use record
Val at 0 range 0 .. 7;
Arr at 0 range 0 .. 7;
end record;
type RAM5B_Register is record
S : RAM5B_S_Field := (As_Array => False, Val => 16#0#);
-- unspecified
Reserved_8_31 : HAL.UInt24 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for RAM5B_Register use record
S at 0 range 0 .. 7;
Reserved_8_31 at 0 range 8 .. 31;
end record;
-- RAM6A_S array
type RAM6A_S_Field_Array is array (0 .. 31) of Boolean
with Component_Size => 1, Size => 32;
type RAM6A_Register
(As_Array : Boolean := False)
is record
case As_Array is
when False =>
-- S as a value
Val : HAL.UInt32;
when True =>
-- S as an array
Arr : RAM6A_S_Field_Array;
end case;
end record
with Unchecked_Union, Size => 32, Volatile_Full_Access,
Bit_Order => System.Low_Order_First;
for RAM6A_Register use record
Val at 0 range 0 .. 31;
Arr at 0 range 0 .. 31;
end record;
-- RAM6B_S array
type RAM6B_S_Field_Array is array (32 .. 39) of Boolean
with Component_Size => 1, Size => 8;
-- Type definition for RAM6B_S
type RAM6B_S_Field
(As_Array : Boolean := False)
is record
case As_Array is
when False =>
-- S as a value
Val : HAL.UInt8;
when True =>
-- S as an array
Arr : RAM6B_S_Field_Array;
end case;
end record
with Unchecked_Union, Size => 8;
for RAM6B_S_Field use record
Val at 0 range 0 .. 7;
Arr at 0 range 0 .. 7;
end record;
type RAM6B_Register is record
S : RAM6B_S_Field := (As_Array => False, Val => 16#0#);
-- unspecified
Reserved_8_31 : HAL.UInt24 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for RAM6B_Register use record
S at 0 range 0 .. 7;
Reserved_8_31 at 0 range 8 .. 31;
end record;
-- RAM7A_S array
type RAM7A_S_Field_Array is array (0 .. 31) of Boolean
with Component_Size => 1, Size => 32;
type RAM7A_Register
(As_Array : Boolean := False)
is record
case As_Array is
when False =>
-- S as a value
Val : HAL.UInt32;
when True =>
-- S as an array
Arr : RAM7A_S_Field_Array;
end case;
end record
with Unchecked_Union, Size => 32, Volatile_Full_Access,
Bit_Order => System.Low_Order_First;
for RAM7A_Register use record
Val at 0 range 0 .. 31;
Arr at 0 range 0 .. 31;
end record;
-- RAM7B_S array
type RAM7B_S_Field_Array is array (32 .. 39) of Boolean
with Component_Size => 1, Size => 8;
-- Type definition for RAM7B_S
type RAM7B_S_Field
(As_Array : Boolean := False)
is record
case As_Array is
when False =>
-- S as a value
Val : HAL.UInt8;
when True =>
-- S as an array
Arr : RAM7B_S_Field_Array;
end case;
end record
with Unchecked_Union, Size => 8;
for RAM7B_S_Field use record
Val at 0 range 0 .. 7;
Arr at 0 range 0 .. 7;
end record;
type RAM7B_Register is record
S : RAM7B_S_Field := (As_Array => False, Val => 16#0#);
-- unspecified
Reserved_8_31 : HAL.UInt24 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for RAM7B_Register use record
S at 0 range 0 .. 7;
Reserved_8_31 at 0 range 8 .. 31;
end record;
-----------------
-- Peripherals --
-----------------
type LCD_Peripheral is record
CR : aliased CR_Register;
FCR : aliased FCR_Register;
SR : aliased SR_Register;
CLR : aliased CLR_Register;
RAM0A : aliased RAM0A_Register;
RAM0B : aliased RAM0B_Register;
RAM1A : aliased RAM1A_Register;
RAM1B : aliased RAM1B_Register;
RAM2A : aliased RAM2A_Register;
RAM2B : aliased RAM2B_Register;
RAM3A : aliased RAM3A_Register;
RAM3B : aliased RAM3B_Register;
RAM4A : aliased RAM4A_Register;
RAM4B : aliased RAM4B_Register;
RAM5A : aliased RAM5A_Register;
RAM5B : aliased RAM5B_Register;
RAM6A : aliased RAM6A_Register;
RAM6B : aliased RAM6B_Register;
RAM7A : aliased RAM7A_Register;
RAM7B : aliased RAM7B_Register;
end record
with Volatile;
for LCD_Peripheral use record
CR at 16#0# range 0 .. 31;
FCR at 16#4# range 0 .. 31;
SR at 16#8# range 0 .. 31;
CLR at 16#C# range 0 .. 31;
RAM0A at 16#14# range 0 .. 31;
RAM0B at 16#18# range 0 .. 31;
RAM1A at 16#1C# range 0 .. 31;
RAM1B at 16#20# range 0 .. 31;
RAM2A at 16#24# range 0 .. 31;
RAM2B at 16#28# range 0 .. 31;
RAM3A at 16#2C# range 0 .. 31;
RAM3B at 16#30# range 0 .. 31;
RAM4A at 16#34# range 0 .. 31;
RAM4B at 16#38# range 0 .. 31;
RAM5A at 16#3C# range 0 .. 31;
RAM5B at 16#40# range 0 .. 31;
RAM6A at 16#44# range 0 .. 31;
RAM6B at 16#48# range 0 .. 31;
RAM7A at 16#4C# range 0 .. 31;
RAM7B at 16#50# range 0 .. 31;
end record;
LCD_Periph : aliased LCD_Peripheral
with Import, Address => System'To_Address (16#40002400#);
end STM32_SVD.LCD;
|
-----------------------------------------------------------------------
-- util-encoders-hmac-sha1 -- Compute HMAC-SHA1 authentication code
-- Copyright (C) 2011, 2017, 2019 Stephane Carrez
-- Written by Stephane Carrez (Stephane.Carrez@gmail.com)
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-----------------------------------------------------------------------
with Util.Encoders.Base16;
with Util.Encoders.Base64;
-- The <b>Util.Encodes.HMAC.SHA1</b> package generates HMAC-SHA1 authentication
-- (See RFC 2104 - HMAC: Keyed-Hashing for Message Authentication).
package body Util.Encoders.HMAC.SHA1 is
-- ------------------------------
-- Sign the data string with the key and return the HMAC-SHA1 code in binary.
-- ------------------------------
function Sign (Key : in String;
Data : in String) return Util.Encoders.SHA1.Hash_Array is
Ctx : Context;
Result : Util.Encoders.SHA1.Hash_Array;
begin
Set_Key (Ctx, Key);
Update (Ctx, Data);
Finish (Ctx, Result);
return Result;
end Sign;
-- ------------------------------
-- Sign the data string with the key and return the HMAC-SHA1 code as hexadecimal string.
-- ------------------------------
function Sign (Key : in String;
Data : in String) return Util.Encoders.SHA1.Digest is
Ctx : Context;
Result : Util.Encoders.SHA1.Digest;
begin
Set_Key (Ctx, Key);
Update (Ctx, Data);
Finish (Ctx, Result);
return Result;
end Sign;
-- ------------------------------
-- Sign the data array with the key and return the HMAC-SHA256 code in the result.
-- ------------------------------
procedure Sign (Key : in Ada.Streams.Stream_Element_Array;
Data : in Ada.Streams.Stream_Element_Array;
Result : out Util.Encoders.SHA1.Hash_Array) is
Ctx : Context;
begin
Set_Key (Ctx, Key);
Update (Ctx, Data);
Finish (Ctx, Result);
end Sign;
-- ------------------------------
-- Sign the data string with the key and return the HMAC-SHA1 code as base64 string.
-- When <b>URL</b> is True, use the base64 URL alphabet to encode in base64.
-- ------------------------------
function Sign_Base64 (Key : in String;
Data : in String;
URL : in Boolean := False) return Util.Encoders.SHA1.Base64_Digest is
Ctx : Context;
Result : Util.Encoders.SHA1.Base64_Digest;
begin
Set_Key (Ctx, Key);
Update (Ctx, Data);
Finish_Base64 (Ctx, Result, URL);
return Result;
end Sign_Base64;
-- ------------------------------
-- Set the hmac private key. The key must be set before calling any <b>Update</b>
-- procedure.
-- ------------------------------
procedure Set_Key (E : in out Context;
Key : in String) is
Buf : Ada.Streams.Stream_Element_Array (1 .. Key'Length);
for Buf'Address use Key'Address;
pragma Import (Ada, Buf);
begin
Set_Key (E, Buf);
end Set_Key;
IPAD : constant Ada.Streams.Stream_Element := 16#36#;
OPAD : constant Ada.Streams.Stream_Element := 16#5c#;
-- ------------------------------
-- Set the hmac private key. The key must be set before calling any <b>Update</b>
-- procedure.
-- ------------------------------
procedure Set_Key (E : in out Context;
Key : in Ada.Streams.Stream_Element_Array) is
begin
-- Reduce the key
if Key'Length > 64 then
Util.Encoders.SHA1.Update (E.SHA, Key);
Util.Encoders.SHA1.Finish (E.SHA, E.Key (0 .. 19));
E.Key_Len := 19;
else
E.Key_Len := Key'Length - 1;
E.Key (0 .. E.Key_Len) := Key;
end if;
-- Hash the key in the SHA1 context.
declare
Block : Ada.Streams.Stream_Element_Array (0 .. 63);
begin
for I in 0 .. E.Key_Len loop
Block (I) := IPAD xor E.Key (I);
end loop;
for I in E.Key_Len + 1 .. 63 loop
Block (I) := IPAD;
end loop;
Util.Encoders.SHA1.Update (E.SHA, Block);
end;
end Set_Key;
-- ------------------------------
-- Update the hash with the string.
-- ------------------------------
procedure Update (E : in out Context;
S : in String) is
begin
Util.Encoders.SHA1.Update (E.SHA, S);
end Update;
-- ------------------------------
-- Update the hash with the string.
-- ------------------------------
procedure Update (E : in out Context;
S : in Ada.Streams.Stream_Element_Array) is
begin
Util.Encoders.SHA1.Update (E.SHA, S);
end Update;
-- ------------------------------
-- Computes the HMAC-SHA1 with the private key and the data collected by
-- the <b>Update</b> procedures. Returns the raw binary hash in <b>Hash</b>.
-- ------------------------------
procedure Finish (E : in out Context;
Hash : out Util.Encoders.SHA1.Hash_Array) is
begin
Util.Encoders.SHA1.Finish (E.SHA, Hash);
-- Hash the key in the SHA1 context.
declare
Block : Ada.Streams.Stream_Element_Array (0 .. 63);
begin
for I in 0 .. E.Key_Len loop
Block (I) := OPAD xor E.Key (I);
end loop;
if E.Key_Len < 63 then
for I in E.Key_Len + 1 .. 63 loop
Block (I) := OPAD;
end loop;
end if;
Util.Encoders.SHA1.Update (E.SHA, Block);
end;
Util.Encoders.SHA1.Update (E.SHA, Hash);
Util.Encoders.SHA1.Finish (E.SHA, Hash);
end Finish;
-- ------------------------------
-- Computes the HMAC-SHA1 with the private key and the data collected by
-- the <b>Update</b> procedures. Returns the hexadecimal hash in <b>Hash</b>.
-- ------------------------------
procedure Finish (E : in out Context;
Hash : out Util.Encoders.SHA1.Digest) is
H : Util.Encoders.SHA1.Hash_Array;
B : Util.Encoders.Base16.Encoder;
begin
Finish (E, H);
B.Convert (H, Hash);
end Finish;
-- ------------------------------
-- Computes the HMAC-SHA1 with the private key and the data collected by
-- the <b>Update</b> procedures. Returns the base64 hash in <b>Hash</b>.
-- When <b>URL</b> is True, use the base64 URL alphabet to encode in base64.
-- ------------------------------
procedure Finish_Base64 (E : in out Context;
Hash : out Util.Encoders.SHA1.Base64_Digest;
URL : in Boolean := False) is
H : Util.Encoders.SHA1.Hash_Array;
B : Util.Encoders.Base64.Encoder;
begin
Finish (E, H);
B.Set_URL_Mode (URL);
B.Convert (H, Hash);
end Finish_Base64;
-- Encodes the binary input stream represented by <b>Data</b> into
-- an SHA-1 hash output stream <b>Into</b>.
--
-- If the transformer does not have enough room to write the result,
-- it must return in <b>Encoded</b> the index of the last encoded
-- position in the <b>Data</b> stream.
--
-- The transformer returns in <b>Last</b> the last valid position
-- in the output stream <b>Into</b>.
--
-- The <b>Encoding_Error</b> exception is raised if the input
-- stream cannot be transformed.
overriding
procedure Transform (E : in out Encoder;
Data : in Ada.Streams.Stream_Element_Array;
Into : out Ada.Streams.Stream_Element_Array;
Last : out Ada.Streams.Stream_Element_Offset;
Encoded : out Ada.Streams.Stream_Element_Offset) is
begin
null;
end Transform;
-- Initialize the SHA-1 context.
overriding
procedure Initialize (E : in out Context) is
begin
null;
end Initialize;
end Util.Encoders.HMAC.SHA1;
|
-- Copyright 2021 S.Merrony
-- Permission is hereby granted, free of charge, to any person obtaining a copy of this software
-- and associated documentation files (the "Software"), to deal in the Software without restriction,
-- including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
-- and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
-- subject to the following conditions:
-- The above copyright notice and this permission notice shall be included in all copies or substantial
-- portions of the Software.
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
-- LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-- IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-- WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
-- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
with Ada.Streams.Stream_IO; use Ada.Streams.Stream_IO;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
with Interfaces; use Interfaces;
package Aosvs_Dump is
Start_Dump_Byte : constant Unsigned_8 := 0;
FSB_Byte : constant Unsigned_8 := 1;
Name_Block_Byte : constant Unsigned_8 := 2;
UDA_Byte : constant Unsigned_8 := 3;
ACL_Byte : constant Unsigned_8 := 4;
Link_Byte : constant Unsigned_8 := 5;
Data_Start_Byte : constant Unsigned_8 := 6;
Data_Block_Byte : constant Unsigned_8 := 7;
Data_End_Byte : constant Unsigned_8 := 8;
End_Dump_Byte : constant Unsigned_8 := 9;
MaxBlockSize : constant Integer := 32_768;
type Fstat_Entry_Rec is record
DG_Mnemonic : String (1 .. 4);
Desc : Unbounded_String;
Is_Dir : Boolean;
Has_Payload : Boolean;
end record;
type Known_Types is array (0 .. 87) of Fstat_Entry_Rec;
Known_Fstat_Entry_Types : constant Known_Types :=
(0 => ("FLNK", To_Unbounded_String ("=>Link=>"), False, False),
1 => ("FDSF", To_Unbounded_String ("System Data File"), False, True),
2 => ("FMTF", To_Unbounded_String ("Mag Tape File"), False, True),
3 => ("FGFN", To_Unbounded_String ("Generic File"), False, True),
10 => ("FDIR", To_Unbounded_String ("<Directory>"), True, False),
11 => ("FLDU", To_Unbounded_String ("<LDU Directory>"), True, False),
12 => ("FCPD", To_Unbounded_String ("<Control Point Dir>"), True, False),
64 => ("FUDF", To_Unbounded_String ("User Data File"), False, True),
66 => ("FUPD", To_Unbounded_String ("User Profile"), False, True),
67 => ("FSTF", To_Unbounded_String ("Symbol Table"), False, True),
68 => ("FTXT", To_Unbounded_String ("Text File"), False, True),
69 => ("FLOG", To_Unbounded_String ("System Log File"), False, True),
74 => ("FPRV", To_Unbounded_String ("Program File"), False, True),
87 => ("FPRG", To_Unbounded_String ("Program File"), False, True),
others => ("UNKN", To_Unbounded_String ("Unknown"), False, True));
type Record_Header_Type is record
Record_Type : Unsigned_8;
Record_Length : Natural;
end record;
type Data_Header_Type is record
Header : Record_Header_Type;
Byte_Address : Unsigned_32;
Byte_Length : Unsigned_32;
Alighnment_Count : Unsigned_16;
end record;
type SOD_Type is record
Header : Record_Header_Type;
Dump_Format_Version : Unsigned_16;
Dump_Time_Secs : Unsigned_16;
Dump_Time_Mins : Unsigned_16;
Dump_Time_Hours : Unsigned_16;
Dump_Time_Day : Unsigned_16;
Dump_Time_Month : Unsigned_16;
Dump_Time_Year : Unsigned_16;
end record;
type Blob_Type is array (Positive range <>) of Unsigned_8;
function Read_Word (Dump_Stream : Stream_Access) return Unsigned_16;
function Read_Blob
(Num_Bytes : in Positive; Dump_Stream : Stream_Access;
Reason : in Unbounded_String) return Blob_Type;
function Extract_First_String(Blob : Blob_Type) return Unbounded_String;
function Read_Header
(Dump_Stream : Stream_Access) return Record_Header_Type;
function Read_SOD (Dump_Stream : Stream_Access) return SOD_Type;
function To_Linux_Filename (Aosvs_Filename : Unbounded_String) return Unbounded_String;
end Aosvs_Dump;
|
------------------------------------------------------------------------------
-- Copyright (c) 2011, Natacha Porté --
-- --
-- Permission to use, copy, modify, and distribute this software for any --
-- purpose with or without fee is hereby granted, provided that the above --
-- copyright notice and this permission notice appear in all copies. --
-- --
-- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES --
-- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF --
-- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR --
-- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES --
-- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN --
-- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF --
-- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. --
------------------------------------------------------------------------------
------------------------------------------------------------------------------
-- Natools.Accumulators is a collection of interfaces for data structures --
-- that allow efficient accumulation of data. --
-- --
-- String_Accumulator is meant for creation of long strings through --
-- repeated calls of Append, and later retrieval of the full buffer through --
-- one of the To_String subprograms. Length, Tail and Unappend are --
-- helper utilities that might not be very efficient but can occasionnally --
-- be useful. Hard_Reset and Soft_Reset both clear the internal state, with --
-- Soft_Reset aimed for speed while Hard_Reset aims for best memory release --
-- --
-- String_Accumulator_Stack adds a stack structure on top of --
-- String_Accumulator, to allow temporary substrings to be created using --
-- similar facilities. All operations on String_Accumulator except --
-- Hard_Reset and Soft_Reset, when applied to String_Accumulator_Stack, are --
-- meant to be forwarded to the top accumulator of the stack. Push and Pop --
-- change the stack state, while Hard_Reset and Soft_Reset apply to the --
-- whole stack, with the same semantics as for String_Accumulator. --
------------------------------------------------------------------------------
package Natools.Accumulators is
pragma Pure (Accumulators);
type String_Accumulator is interface;
procedure Append (To : in out String_Accumulator; Text : String)
is abstract;
-- Append the given String to the internal buffer
procedure Hard_Reset (Acc : in out String_Accumulator)
is abstract;
-- Empty the internal buffer and free all possible memory
function Length (Acc : String_Accumulator) return Natural
is abstract;
-- Return the length of the internal buffer
procedure Soft_Reset (Acc : in out String_Accumulator)
is abstract;
-- Empty the internal buffer for reuse
function Tail (Acc : String_Accumulator; Size : Natural) return String
is abstract;
-- Return the last characters from the internal buffer
function To_String (Acc : String_Accumulator) return String
is abstract;
-- Output the whole internal buffer as a String
procedure To_String (Acc : String_Accumulator; Output : out String)
is abstract;
-- Write the whole internal buffer into the String, which must be
-- large enough.
procedure Unappend (From : in out String_Accumulator; Text : String)
is abstract;
-- Remove the given suffix from the internal buffer
-- Do nothing if the given text is not a prefix the internal buffer
type String_Accumulator_Stack is interface and String_Accumulator;
procedure Push (Acc : in out String_Accumulator_Stack)
is abstract;
-- Push the current internal buffer and start with an empty one
procedure Pop (Acc : in out String_Accumulator_Stack)
is abstract;
-- Drop the current internal buffer and use the previsouly pushed one
-- instead
-- Raise Program_Error when trying to pop the last internal buffer
end Natools.Accumulators;
|
procedure While_Loop_Statement is
begin
while True loop
null;
end loop;
end While_Loop_Statement;
|
-----------------------------------------------------------------------
-- jobs-tests -- Unit tests for AWA jobs
-- Copyright (C) 2012, 2014 Stephane Carrez
-- Written by Stephane Carrez (Stephane.Carrez@gmail.com)
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-----------------------------------------------------------------------
with Util.Tests;
with AWA.Tests;
package AWA.Jobs.Services.Tests is
procedure Work_1 (Job : in out AWA.Jobs.Services.Abstract_Job_Type'Class);
procedure Work_2 (Job : in out AWA.Jobs.Services.Abstract_Job_Type'Class);
-- Check the job status while the job is running.
procedure Work_Check_Status (Job : in out AWA.Jobs.Services.Abstract_Job_Type'Class);
-- Check the job parameter while the job is running.
procedure Work_Check_Parameter (Job : in out AWA.Jobs.Services.Abstract_Job_Type'Class);
-- Check the job raising an exception.
procedure Work_Check_Exception (Job : in out AWA.Jobs.Services.Abstract_Job_Type'Class);
-- Check the job is executed under the context of the user.
procedure Work_Check_User (Job : in out AWA.Jobs.Services.Abstract_Job_Type'Class);
package Work_1_Definition is new Work_Definition (Work_1'Access);
package Work_2_Definition is new Work_Definition (Work_2'Access);
package Work_Check_Status_Definition is new Work_Definition (Work_Check_Status'Access);
package Work_Check_Parameter_Definition is new Work_Definition (Work_Check_Parameter'Access);
package Work_Check_Exception_Definition is new Work_Definition (Work_Check_Exception'Access);
package Work_Check_User_Definition is new Work_Definition (Work_Check_User'Access);
procedure Add_Tests (Suite : in Util.Tests.Access_Test_Suite);
type Test is new AWA.Tests.Test with null record;
-- Test the job schedule.
procedure Test_Job_Schedule (T : in out Test);
-- Test the Get_Status operation within a job.
procedure Test_Job_Execute_Get_Status (T : in out Test);
-- Test the Get_Parameter operation within a job.
procedure Test_Job_Execute_Get_Parameter (T : in out Test);
-- Test the job that raise some exception.
procedure Test_Job_Execute_Exception (T : in out Test);
-- Test the job and verify that the job is executed under the user who created the job.
procedure Test_Job_Execute_Get_User (T : in out Test);
-- Wait for the job to be executed and verify its stats.
procedure Wait_Job (T : in out Test;
Id : in ADO.Identifier;
Expect : in AWA.Jobs.Models.Job_Status_Type);
procedure Run_Job (T : in out Test;
Factory : in Job_Factory_Access;
Id : out ADO.Identifier);
type Test_Job is new AWA.Jobs.Services.Abstract_Job_Type with null record;
-- Execute the job. This operation must be implemented and should perform the work
-- represented by the job. It should use the <tt>Get_Parameter</tt> function to retrieve
-- the job parameter and it can use the <tt>Set_Result</tt> operation to save the result.
overriding
procedure Execute (Job : in out Test_Job);
package Test_Definition is new AWA.Jobs.Services.Definition (Test_Job);
end AWA.Jobs.Services.Tests;
|
with Ada.Integer_Text_IO;
-- Copyright 2021 Melwyn Francis Carlo
procedure A019 is
use Ada.Integer_Text_IO;
-- The first element is a dummy element.
Month_Constant : constant array (Integer range 1 .. 13) of Integer :=
(0, 1, -1, 0, 0, 1, 1, 2, 3, 3, 4, 4, 5);
N : Integer := 0;
Day_Val : Integer;
begin
for I in 1901 .. 2000 loop
for J in 1 .. 12 loop
Day_Val := (((I - 1) * 365)
+ Integer (Float'Floor (Float (I - 1) / 400.0))
+ Integer (Float'Floor (Float (I - 1) / 4.0))
- Integer (Float'Floor (Float (I - 1) / 100.0))
+ ((J - 1) * 30)
+ Month_Constant (J)
+ 1);
if (I mod 4) = 0 and J > 2 then
Day_Val := Day_Val + 1;
end if;
Day_Val := Day_Val mod 7;
if Day_Val = 0 then
N := N + 1;
end if;
end loop;
end loop;
Put (N, Width => 0);
end A019;
|
with Kernel.Serial_Output; use Kernel.Serial_Output;
with System; use System;
with Force_External_Interrupt_2;
--with Registro; use Registro;
with tools; use tools;
package body pulse_interrupt is
--------------------------------------------------------------------------
-- Tarea que fuerza la interrupcion externa 2 en los instantes indicados --
--------------------------------------------------------------------------
task body Interrupt is
Next_Time : Ada.Real_Time.Time := Big_Bang;
Tamanio_Tabla_Retardos : constant Integer := 10;
type Indice_Retardos is mod Tamanio_Tabla_Retardos;
type Tabla_Retardos is array (Indice_Retardos) of Ada.Real_Time.Time_Span;
periodoInterrupcion: Tabla_Retardos := (Interr_1,Interr_2,Interr_3,Interr_4,Interr_5,
Interr_6,Interr_7,Interr_8,Interr_9,Interr_10);
j : Indice_Retardos := Indice_Retardos'First;
begin
loop
Next_Time := Next_Time + PeriodoInterrupcion(j);
delay until Next_Time;
Force_External_Interrupt_2;
j := j + 1;
--Hora_Actual (Big_Bang);
Put ("======> Interrupcion Externa 2 ");
end loop;
end Interrupt;
---------------------------------------------------------------------
begin
null;
end pulse_interrupt; |
with Extraction.Node_Edge_Types;
with Extraction.Utilities;
package body Extraction.Derived_Type_Defs is
use type LALCO.Ada_Node_Kind_Type;
function Has_Interfaces (Node : LAL.Ada_Node'Class) return Boolean is
(Node.Kind in LALCO.Ada_Derived_Type_Def | LALCO.Ada_Task_Def |
LALCO.Ada_Protected_Type_Decl | LALCO.Ada_Single_Protected_Decl);
function Get_Interfaces (Node : LAL.Ada_Node'Class) return LAL.Parent_List;
function Get_Interfaces (Node : LAL.Ada_Node'Class) return LAL.Parent_List
is
begin
case Node.Kind is
when LALCO.Ada_Derived_Type_Def =>
return Node.As_Derived_Type_Def.F_Interfaces;
when LALCO.Ada_Task_Def =>
return Node.As_Task_Def.F_Interfaces;
when LALCO.Ada_Protected_Type_Decl =>
return Node.As_Protected_Type_Decl.F_Interfaces;
when LALCO.Ada_Single_Protected_Decl =>
return Node.As_Single_Protected_Decl.F_Interfaces;
when others =>
raise Internal_Extraction_Error
with "Cases in Has_Interfaces and Get_Interfaces do not match";
end case;
end Get_Interfaces;
procedure Extract_Edges
(Node : LAL.Ada_Node'Class; Graph : Graph_Operations.Graph_Context)
is
begin
if Node.Kind = LALCO.Ada_Derived_Type_Def then
declare
Derived_Type_Def : constant LAL.Derived_Type_Def :=
Node.As_Derived_Type_Def;
Type_Decl : constant LAL.Basic_Decl :=
Utilities.Get_Parent_Basic_Decl (Derived_Type_Def);
Subtype_Indication : constant LAL.Subtype_Indication :=
Derived_Type_Def.F_Subtype_Indication;
begin
if not Subtype_Indication.Is_Null then
declare
Parent : constant LAL.Basic_Decl :=
Utilities.Get_Referenced_Decl (Subtype_Indication.F_Name);
begin
Graph.Write_Edge
(Type_Decl, Parent,
Node_Edge_Types.Edge_Type_Derives_From);
end;
end if;
end;
end if;
if Has_Interfaces (Node) then
declare
Decl : constant LAL.Basic_Decl :=
Utilities.Get_Parent_Basic_Decl (Node);
begin
for Interface_Ref of Get_Interfaces (Node) loop
declare
Parent : constant LAL.Basic_Decl :=
Utilities.Get_Referenced_Decl (Interface_Ref);
begin
Graph.Write_Edge
(Decl, Parent, Node_Edge_Types.Edge_Type_Derives_From);
end;
end loop;
end;
end if;
end Extract_Edges;
end Extraction.Derived_Type_Defs;
|
with Ada.Text_IO;
with Ada.Float_Text_IO;
with Ada.IO_Exceptions;
with Ada.Integer_Text_IO;
use Ada;
procedure Change_Calculator is
type Money is delta 0.01 digits 10;
Input_Amount : Money := 0.0;
package Money_IO is new Text_IO.Decimal_IO(Money);
type Currency_Denomination is record
Name : String(1..10);
Value : Money;
end record;
Currency_Names : array (1..10) of Currency_Denomination;
Currency_Counts : array (1..10) of Integer := (others=>0);
Currency_Index : Integer range 1..10;
procedure Get_Money_Prompt(Amount: out Money) is
Response : String(1..20);
Last : Natural;
begin
loop
declare
begin
Text_IO.Put("amount: ");
Text_IO.Flush;
Text_IO.Get_Line(Response, Last);
-- try to convert string input to money type
Amount := Money'Value(Response(1 .. Last));
-- quit the loop if the money converted
exit;
exception
when Constraint_Error =>
Text_IO.Put_Line("ERROR: bad money format");
end;
end loop;
end Get_Money_Prompt;
begin
Currency_Names := (("Penny ", 0.01),
("Nickle ", 0.05),
("Dime ", 0.10),
("Quarter ", 0.25),
("Dollar ", 1.00),
("5 Dollar ", 5.00),
("10 Dollar ", 10.00),
("20 Dollar ", 20.00),
("50 Dollar ", 50.00),
("100 Dollar", 100.00));
loop
-- read money amount from the user
Get_Money_Prompt(Input_Amount);
-- calculate needed currency
for I in Currency_Names'Range loop
-- calculate inverse of index to count backwords
Currency_Index := (Currency_Names'Length-I)+1;
while Input_Amount >= Currency_Names(Currency_Index).Value loop
Input_Amount := Input_Amount - Currency_Names(Currency_Index).Value;
-- increment currency useage in array
Currency_Counts(I) := Currency_Counts(I) + 1;
end loop;
end loop;
-- display needed currency
for I in Currency_Counts'Range loop
Currency_Index := (Currency_Names'Length-I)+1;
-- do not display unused currency
if Currency_Counts(Currency_Index) /= 0 then
Text_IO.Put(Currency_Names(I).Name & " ");
Integer_Text_IO.Put(Currency_Counts(Currency_Index));
Text_IO.New_Line;
end if;
end loop;
end loop;
end Change_Calculator;
|
with HAL;
with BBQ10KBD;
package BB_Pico_Bsp.Keyboard is
function Key_FIFO_Pop return BBQ10KBD.Key_State;
-- When the FIFO is empty a Key_State with Kind = Error is returned
function Status return BBQ10KBD.KBD_Status;
procedure Set_Backlight (Lvl : HAL.UInt8);
function Version return HAL.UInt8;
KEY_JOY_UP : constant HAL.UInt8 := 16#01#;
KEY_JOY_DOWN : constant HAL.UInt8 := 16#02#;
KEY_JOY_LEFT : constant HAL.UInt8 := 16#03#;
KEY_JOY_RIGHT : constant HAL.UInt8 := 16#04#;
KEY_JOY_CENTER : constant HAL.UInt8 := 16#05#;
KEY_BTN_LEFT1 : constant HAL.UInt8 := 16#06#;
KEY_BTN_RIGHT1 : constant HAL.UInt8 := 16#07#;
KEY_BTN_LEFT2 : constant HAL.UInt8 := 16#11#;
KEY_BTN_RIGHT2 : constant HAL.UInt8 := 16#12#;
end BB_Pico_Bsp.Keyboard;
|
with agar.core;
with interfaces.c;
package agar.gui is
package c renames interfaces.c;
-- Flags for init_video
type video_flags_t is new c.unsigned;
HWSURFACE : constant video_flags_t := 16#001#;
ASYNCBLIT : constant video_flags_t := 16#002#;
ANYFORMAT : constant video_flags_t := 16#004#;
HWPALETTE : constant video_flags_t := 16#008#;
DOUBLEBUF : constant video_flags_t := 16#010#;
FULLSCREEN : constant video_flags_t := 16#020#;
RESIZABLE : constant video_flags_t := 16#040#;
NOFRAME : constant video_flags_t := 16#080#;
BGPOPUPMENU : constant video_flags_t := 16#100#;
OPENGL : constant video_flags_t := 16#200#;
OPENGL_OR_SDL : constant video_flags_t := 16#400#;
NOBGCLEAR : constant video_flags_t := 16#800#;
SDL : constant video_flags_t := 16#2000#;
function init (flags : agar.core.init_flags_t := 0) return boolean;
pragma inline (init);
function init_video
(width : positive;
height : positive;
bpp : natural;
flags : video_flags_t := 0) return boolean;
pragma inline (init_video);
procedure destroy;
pragma import (c, destroy, "AG_DestroyGUI");
procedure event_loop;
pragma import (c, event_loop, "agar_event_loop");
procedure event_loop_fixed_fps;
pragma import (c, event_loop_fixed_fps, "AG_EventLoop_FixedFPS");
end agar.gui;
|
-- { dg-do compile }
-- { dg-options "-O" }
with Opt25_Pkg1;
with Opt25_Pkg2;
procedure Opt25 (B1, B2 : in out Boolean) is
package Local_Pack_Instance is new Opt25_Pkg1 (Boolean, True);
package Local_Stack is new Opt25_Pkg2 (Integer, 0);
S : Local_Stack.Stack := Local_Stack.Default_Stack;
begin
Local_Pack_Instance.Swap (B1, B2);
end;
|
pragma License (Unrestricted);
private with System.Synchronous_Control;
package Ada.Dispatching is
pragma Preelaborate;
procedure Yield;
pragma Inline (Yield); -- renamed
Dispatching_Policy_Error : exception;
private
procedure Yield
renames System.Synchronous_Control.Yield;
end Ada.Dispatching;
|
with
glx.Pointers,
interfaces.C;
package glx.Binding
is
function getCurrentContext return access ContextRec;
function getCurrentDrawable return Drawable;
procedure waitGL;
procedure waitX;
procedure useXFont (Font : in GLX.Font;
First : in C.int;
Count : in C.int;
List : in C.int);
function getCurrentReadDrawable return Drawable;
function get_visualid (Self : in Pointers.XVisualInfo_Pointer) return VisualID;
private
pragma Import (C, getCurrentContext, "glXGetCurrentContext");
pragma Import (C, getCurrentDrawable, "glXGetCurrentDrawable");
pragma Import (C, waitGL, "glXWaitGL");
pragma Import (C, waitX, "glXWaitX");
pragma Import (C, useXFont, "glXUseXFont");
pragma Import (C, getCurrentReadDrawable, "glXGetCurrentReadDrawable");
pragma Import (C, get_visualid, "Ada_get_visualid");
end glx.Binding;
|
with Ada.Finalization;
with ACO.CANopen;
with ACO.States;
with ACO.Messages;
with ACO.OD;
with ACO.OD_Types;
private with Ada.Real_Time;
private with ACO.Events;
package ACO.Nodes is
type Node_Base
(Id : ACO.Messages.Node_Nr;
Handler : not null access ACO.CANopen.Handler;
Od : not null access ACO.OD.Object_Dictionary'Class)
is abstract new Ada.Finalization.Limited_Controlled with private;
procedure Set_State
(This : in out Node_Base;
State : in ACO.States.State) is abstract;
-- Local: Set state in OD, maybe send boot
-- Remote: Set state in OD, send nmt command to node id of remote
function Get_State
(This : Node_Base)
return ACO.States.State is abstract;
-- Local: Get state from OD
-- Remote: Get state from OD
procedure Start
(This : in out Node_Base) is abstract;
procedure Write
(This : in out Node_Base;
Index : in ACO.OD_Types.Object_Index;
Subindex : in ACO.OD_Types.Object_Subindex;
An_Entry : in ACO.OD_Types.Entry_Base'Class) is abstract;
procedure Read
(This : in out Node_Base;
Index : in ACO.OD_Types.Object_Index;
Subindex : in ACO.OD_Types.Object_Subindex;
To_Entry : out ACO.OD_Types.Entry_Base'Class) is abstract;
private
procedure On_Message_Dispatch
(This : in out Node_Base;
Msg : in ACO.Messages.Message) is null;
procedure Periodic_Actions
(This : in out Node_Base;
T_Now : in Ada.Real_Time.Time) is null;
type Tick_Subscriber
(Node_Ref : not null access Node_Base'Class)
is new ACO.Events.Handler_Event_Listener (ACO.Events.Tick) with null record;
overriding
procedure On_Event
(This : in out Tick_Subscriber;
Data : in ACO.Events.Handler_Event_Data);
type Message_Subscriber
(Node_Ref : not null access Node_Base'Class)
is new ACO.Events.Handler_Event_Listener (ACO.Events.Received_Message)
with null record;
overriding
procedure On_Event
(This : in out Message_Subscriber;
Data : in ACO.Events.Handler_Event_Data);
type Node_Base
(Id : ACO.Messages.Node_Nr;
Handler : not null access ACO.CANopen.Handler;
Od : not null access ACO.OD.Object_Dictionary'Class)
is abstract new Ada.Finalization.Limited_Controlled with record
Periodic_Action_Indication : aliased Tick_Subscriber (Node_Base'Access);
New_Message_Indication : aliased Message_Subscriber (Node_Base'Access);
end record;
overriding
procedure Initialize (This : in out Node_Base);
overriding
procedure Finalize (This : in out Node_Base);
end ACO.Nodes;
|
--with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
with Ada.Text_IO;
--with Ada.Text_IO.Unbounded_IO; use Ada.Text_IO.Unbounded_IO;
--with Interfaces; use Interfaces;
--with assembler; use assembler;
--with callbacks; use callbacks;
with gui;
--with util; use util;
--with vm; use vm;
procedure Main is
begin
gui.load;
Ada.Text_IO.Put_Line("exited.");
end Main;
|
--
-- Copyright 2018 The wookey project team <wookey@ssi.gouv.fr>
-- - 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.
--
--
package body soc.usart.interfaces
with spark_mode => off
is
procedure configure
(usart_id : in unsigned_8;
baudrate : in unsigned_32;
data_len : in t_data_len;
parity : in t_parity;
stop : in t_stop_bits;
success : out boolean)
is
usart : t_USART_peripheral_access;
begin
case usart_id is
when 1 => usart := USART1'access;
when 4 => usart := UART4'access;
when 6 => usart := USART6'access;
when others =>
success := false;
return;
end case;
usart.all.CR1.UE := true; -- USART enable
usart.all.CR1.TE := true; -- Transmitter enable
-- The kernel does not attempt to receive any char from its
-- console
usart.all.CR1.RE := false; -- Receiver enable
set_baudrate (usart, baudrate);
usart.all.CR1.M := data_len;
usart.all.CR2.STOP := stop;
usart.all.CR1.PCE := true; -- Parity control enable
usart.all.CR1.PS := parity;
-- No flow control
usart.all.CR3.RTSE := false;
usart.all.CR3.CTSE := false;
success := true;
return;
end configure;
procedure transmit
(usart_id : in unsigned_8;
data : in t_USART_DR)
is
begin
case usart_id is
when 1 => soc.usart.transmit (USART1'access, data);
when 4 => soc.usart.transmit (UART4'access, data);
when 6 => soc.usart.transmit (USART6'access, data);
when others =>
raise program_error;
end case;
end transmit;
end soc.usart.interfaces;
|
with Ada.Characters,
Ada.Containers.Hashed_Maps,
Ada.Containers.Vectors,
Ada.Execution_Time,
Ada.Long_Long_Integer_Text_IO,
Ada.Real_Time,
Ada.Text_IO;
with Utils;
procedure Main is
use Ada.Execution_Time,
Ada.Real_Time,
Ada.Text_IO;
use Utils;
subtype Chunks is Character
with Static_Predicate => Chunks in
'(' .. '('
| '{' .. '{'
| '[' .. '['
| '<' .. '<'
| ')' .. ')'
| '}' .. '}'
| ']' .. ']'
| '>' .. '>';
subtype Open_Chunks is Chunks
with Static_Predicate => Open_Chunks in
'(' .. '('
| '{' .. '{'
| '[' .. '['
| '<' .. '<';
subtype Close_Chunks is Chunks
with Static_Predicate => Close_Chunks in
')' .. ')'
| '}' .. '}'
| ']' .. ']'
| '>' .. '>';
function ID_Hashed (Id : Open_Chunks) return Ada.Containers.Hash_Type is
(Ada.Containers.Hash_Type (Open_Chunks'Pos (Id)));
package Corresponding_Chunk_Maps is new Ada.Containers.Hashed_Maps (Key_Type => Open_Chunks,
Element_Type => Close_Chunks,
Hash => ID_Hashed,
Equivalent_Keys => "=");
package Chunks_Vectors is new Ada.Containers.Vectors (Natural, Chunks);
subtype Long_Long_Natural is Long_Long_Integer range 0 .. Long_Long_Integer'Last;
package Natural_Vectors is new Ada.Containers.Vectors (Natural, Long_Long_Natural);
package Natural_Vectors_Sorting is new Natural_Vectors.Generic_Sorting;
package Chunks_Vectors_Vectors is new Ada.Containers.Vectors (Natural, Chunks_Vectors.Vector, Chunks_Vectors."=");
Corresponding_Chunk : Corresponding_Chunk_Maps.Map;
File : File_Type;
Start_Time, End_Time : CPU_Time;
Execution_Duration : Time_Span;
Values : Chunks_Vectors_Vectors.Vector := Chunks_Vectors_Vectors.Empty_Vector;
Result : Long_Long_Natural := 0;
begin
Get_File (File);
-- Get all values
while not End_Of_File (File) loop
declare
use Chunks_Vectors;
Str : constant String := Get_Line (File);
Row : Vector := Empty_Vector;
begin
for Char of Str loop
Row.Append (Char);
end loop;
Values.Append (Row);
end;
end loop;
-- Exit the program if there is no values
if Values.Is_Empty then
Close_If_Open (File);
Put_Line ("The input file is empty.");
return;
end if;
Corresponding_Chunk_Maps.Insert (Corresponding_Chunk, '(', ')');
Corresponding_Chunk_Maps.Insert (Corresponding_Chunk, '{', '}');
Corresponding_Chunk_Maps.Insert (Corresponding_Chunk, '[', ']');
Corresponding_Chunk_Maps.Insert (Corresponding_Chunk, '<', '>');
-- Do the puzzle
Start_Time := Ada.Execution_Time.Clock;
Solve_Puzzle : declare
Solutions : Natural_Vectors.Vector;
begin
for Row of Values loop
declare
use Chunks_Vectors;
Open_Chunk : Vector;
Current_Open_Chunk : Open_Chunks;
Current_Close_Chunck : Close_Chunks;
Is_Valid : Boolean := True;
begin
Check_Line : for Char of Row loop
if Char in Open_Chunks then
Open_Chunk.Append (Char);
else
Current_Open_Chunk := Open_Chunk.Last_Element;
Open_Chunk.Delete_Last;
Current_Close_Chunck := Char;
if Corresponding_Chunk.Element (Current_Open_Chunk) /= Current_Close_Chunck then
Is_Valid := False;
exit Check_Line;
end if;
end if;
end loop Check_Line;
if Is_Valid then
while not Open_Chunk.Is_Empty loop
Current_Open_Chunk := Open_Chunk.Last_Element;
Open_Chunk.Delete_Last;
Current_Close_Chunck := Corresponding_Chunk.Element (Current_Open_Chunk);
case Current_Close_Chunck is
when ')' =>
Result := Result * 5 + 1;
when ']' =>
Result := Result * 5 + 2;
when '}' =>
Result := Result * 5 + 3;
when '>' =>
Result := Result * 5 + 4;
end case;
end loop;
Natural_Vectors.Append (Solutions, Result);
Result := Long_Long_Natural'First;
end if;
end;
end loop;
Natural_Vectors_Sorting.Sort (Solutions);
declare
use Natural_Vectors, Ada.Containers;
Index : constant Count_Type := Solutions.Length / Count_Type (2);
begin
Result := Solutions.Element (Integer (Index));
end;
end Solve_Puzzle;
End_Time := Ada.Execution_Time.Clock;
Execution_Duration := End_Time - Start_Time;
Put ("Result: ");
Ada.Long_Long_Integer_Text_IO.Put (Item => Result,
Width => 0);
New_Line;
Put_Line ("(Took " & Duration'Image (To_Duration (Execution_Duration) * 1_000_000) & "µs)");
Close_If_Open (File);
exception
when others =>
Close_If_Open (File);
raise;
end Main;
|
------------------------------------------------------------------------------
-- --
-- GNAT ncurses Binding Samples --
-- --
-- ncurses --
-- --
-- B O D Y --
-- --
------------------------------------------------------------------------------
-- Copyright 2020 Thomas E. Dickey --
-- Copyright 2000-2008,2009 Free Software Foundation, Inc. --
-- --
-- Permission is hereby granted, free of charge, to any person obtaining a --
-- copy of this software and associated documentation files (the --
-- "Software"), to deal in the Software without restriction, including --
-- without limitation the rights to use, copy, modify, merge, publish, --
-- distribute, distribute with modifications, sublicense, and/or sell --
-- copies of the Software, and to permit persons to whom the Software is --
-- furnished to do so, subject to the following conditions: --
-- --
-- The above copyright notice and this permission notice shall be included --
-- in all copies or substantial portions of the Software. --
-- --
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS --
-- OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF --
-- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. --
-- IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, --
-- DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR --
-- OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR --
-- THE USE OR OTHER DEALINGS IN THE SOFTWARE. --
-- --
-- Except as contained in this notice, the name(s) of the above copyright --
-- holders shall not be used in advertising or otherwise to promote the --
-- sale, use or other dealings in this Software without prior written --
-- authorization. --
------------------------------------------------------------------------------
-- Author: Eugene V. Melaragno <aldomel@ix.netcom.com> 2000
-- Version Control
-- $Revision: 1.5 $
-- $Date: 2020/02/02 23:34:34 $
-- Binding Version 01.00
------------------------------------------------------------------------------
with Terminal_Interface.Curses; use Terminal_Interface.Curses;
with Terminal_Interface.Curses.Aux; use Terminal_Interface.Curses.Aux;
package body ncurses2.genericPuts is
procedure myGet (Win : Window := Standard_Window;
Str : out BS.Bounded_String;
Len : Integer := -1)
is
function Wgetnstr (Win : Window;
Str : char_array;
Len : int) return int;
pragma Import (C, Wgetnstr, "wgetnstr");
N : Integer := Len;
Txt : char_array (0 .. size_t (Max_Length));
xStr : String (1 .. Max_Length);
Cnt : Natural;
begin
if N < 0 then
N := Max_Length;
end if;
if N > Max_Length then
raise Constraint_Error;
end if;
Txt (0) := Interfaces.C.char'First;
if Wgetnstr (Win, Txt, C_Int (N)) = Curses_Err then
raise Curses_Exception;
end if;
To_Ada (Txt, xStr, Cnt, True);
Str := To_Bounded_String (xStr (1 .. Cnt));
end myGet;
procedure myPut (Str : out BS.Bounded_String;
i : Integer;
Base : Number_Base := 10) is
package Int_IO is new Integer_IO (Integer); use Int_IO;
tmp : String (1 .. BS.Max_Length);
begin
Put (tmp, i, Base);
Str := To_Bounded_String (tmp);
Trim (Str, Ada.Strings.Trim_End'(Ada.Strings.Left));
end myPut;
procedure myAdd (Str : BS.Bounded_String) is
begin
Add (Str => To_String (Str));
end myAdd;
-- from ncurses-aux
procedure Fill_String (Cp : chars_ptr;
Str : out BS.Bounded_String)
is
-- Fill the string with the characters referenced by the
-- chars_ptr.
--
Len : Natural;
begin
if Cp /= Null_Ptr then
Len := Natural (Strlen (Cp));
if Max_Length < Len then
raise Constraint_Error;
end if;
declare
S : String (1 .. Len);
begin
S := Value (Cp);
Str := To_Bounded_String (S);
end;
else
Str := Null_Bounded_String;
end if;
end Fill_String;
end ncurses2.genericPuts;
|
-- { dg-do run }
with Aggr19_Pkg; use Aggr19_Pkg;
procedure Aggr19 is
C : Rec5
:= (Ent => (Kind => Two, Node => (L => (D => True, Pos => 1 )), I => 0));
A : Rec5 := C;
begin
Proc (A);
if A /= C then
raise Program_Error;
end if;
end;
|
------------------------------------------------------------------------------
-- --
-- GNAT EXAMPLE --
-- --
-- Copyright (C) 2013, AdaCore --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 2, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
-- for more details. You should have received a copy of the GNU General --
-- Public License distributed with GNAT; see file COPYING. If not, write --
-- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
-- Boston, MA 02110-1301, USA. --
-- --
-- As a special exception, if other files instantiate generics from this --
-- unit, or you link this unit with other files to produce an executable, --
-- this unit does not by itself cause the resulting executable to be --
-- covered by the GNU General Public License. This exception does not --
-- however invalidate any other reasons why the executable file might be --
-- covered by the GNU Public License. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
with Ada.Text_IO; use Ada.Text_IO;
with Netcfg; use Netcfg;
with Ethdrv; use Ethdrv;
with Clkdrv; use Clkdrv;
with Netutils; use Netutils;
package body Netproto is
procedure Dump_Pkt (Off : Natural := 0) is
begin
-- Display the packet
Put ("Pkt:");
for I in Off .. Packet_Len - 1 loop
Put (' ');
Put_Hex (Packet (I));
end loop;
New_Line;
end Dump_Pkt;
function In_My_Network (Ip : In_Addr) return Boolean;
-- Return true if IP is in my network
function In_My_Network (Ip : In_Addr) return Boolean is
begin
return (Ip and My_Netmask) = (My_Ip_Addr and My_Netmask);
end In_My_Network;
-- ARP constants
Arp_Htype : constant := 1;
Arp_Ptype : constant := 16#800#;
-- ARP operation
Arp_Request : constant := 1;
Arp_Reply : constant := 2;
function Handle_Arp return Rcv_Status
is
Htype : Unsigned_16;
Ptype : Unsigned_16;
Hlen : Unsigned_8;
Plen : Unsigned_8;
Oper : Unsigned_16;
begin
-- Check length
if Packet_Len - Packet_Off < 8 then
return Rcv_Err;
end if;
-- Extract header
Htype := Read_BE2 (Packet_Off);
Ptype := Read_BE2 (Packet_Off + 2);
Hlen := Read_BE1 (Packet_Off + 4);
Plen := Read_BE1 (Packet_Off + 5);
Oper := Read_BE2 (Packet_Off + 6);
Packet_Off := Packet_Off + 8;
-- Sanity check
if Htype /= Arp_Htype or else Ptype /= Arp_Ptype
or else Hlen /= 6 or else Plen /= 4
then
return Rcv_Err;
end if;
if Packet_Len - Packet_Off < 2 * (6 + 4) then
return Rcv_Err;
end if;
case Oper is
when Arp_Request =>
if Read_BE4 (Packet_Off + 6 + 4 + 6) = My_Ip_Addr then
Put_Line ("Got ARP request for me");
-- Dump_Pkt;
-- Create a reply
declare
Sender_Ip : constant In_Addr := Read_BE4 (Packet_Off);
Sender_Eth : constant Eth_Addr := Read_Eth (Packet_Off);
begin
Eth_Send_Init;
-- Eth frame
Write_Eth (Sender_Eth);
Write_Eth (My_Eth_Addr);
Write_BE2 (Eth_Type_Arp);
-- Arp frame
Write_BE2 (Arp_Htype);
Write_BE2 (Arp_Ptype);
Write_BE1 (Eth_Addr'Length);
Write_BE1 (Ip_Addr'Length);
Write_BE2 (Arp_Reply);
Write_Eth (My_Eth_Addr);
Write_BE4 (My_Ip_Addr);
Write_Eth (Sender_Eth);
Write_BE4 (Sender_Ip);
Packet_Len := Packet_Off;
-- Dump_Pkt;
Eth_Send_Packet;
end;
end if;
return Rcv_None;
when Arp_Reply =>
if Srv_Ip_Addr = Null_Ip_Addr then
-- We don't care about ARP unless we have a server address
return Rcv_Ign;
end if;
declare
Ip : constant In_Addr := Read_BE4 (Packet_Off + 6);
begin
-- Put_Line ("Got ARP reply");
-- Dump_Pkt;
if Ip = Srv_Ip_Addr
or else (Ip = Gw_Ip_Addr
and then not In_My_Network (Srv_Ip_Addr))
then
Srv_Eth_Addr := Read_Eth (Packet_Off);
end if;
end;
return Rcv_Arp;
when others =>
return Rcv_Err;
end case;
end Handle_Arp;
function Ip_Chksum (Length : Natural;
Offset : Natural := Packet_Off;
Seed : Unsigned_16 := 0)
return Unsigned_16
is
Sum : Unsigned_32 := Unsigned_32 (Seed);
pragma Assert (Offset mod 2 = 0);
-- Assume the packet is correctly aligned.
Raw_Buf : array (1 .. Length / 2) of Unsigned_16;
pragma Warnings (Off);
for Raw_Buf'Address use Packet (Offset)'Address;
pragma Warnings (On);
begin
for I in Raw_Buf'Range loop
Sum := Sum + Unsigned_32 (Raw_Buf (I));
end loop;
if Length mod 2 = 1 then
declare
Tmp : Netbuf (0 .. 1);
for Tmp'Alignment use 2;
Raw_Tmp : Unsigned_16;
for Raw_Tmp'Address use Tmp'Address;
begin
Tmp (0) := Packet (Offset + Length - 1);
Tmp (1) := 0;
Sum := Sum + Unsigned_32 (Raw_Tmp);
end;
end if;
-- One complement addition
Sum := (Sum and 16#ffff#) + Shift_Right (Sum, 16);
Sum := (Sum and 16#ffff#) + Shift_Right (Sum, 16);
return Unsigned_16 (Sum and 16#ffff#);
end Ip_Chksum;
Mf_Flag : constant := 16#2000#;
Frag_Off_Mask : constant := 16#1fff#;
function Udp_Checksum (Ip_Off : Natural; Udp_Off : Natural; Len : Natural)
return Unsigned_16
is
Tmp : Netbuf (0 .. 1);
for Tmp'Alignment use 2;
Raw_Tmp : Unsigned_16;
for Raw_Tmp'Address use Tmp'Address;
Csum : Unsigned_16;
begin
Tmp (0) := 0;
Tmp (1) := Ip_Proto_Udp;
Csum := Ip_Chksum (8, Ip_Off + 12, Raw_Tmp);
Csum := Ip_Chksum (2, Udp_Off + 4, Csum);
Csum := Ip_Chksum (Len, Udp_Off, Csum);
return Csum;
end Udp_Checksum;
function Handle_Udp (Ip_Off : Natural) return Rcv_Status
is
Sport, Dport : Unsigned_16;
Len : Unsigned_16;
begin
-- Sanity check
if Packet_Len - Packet_Off < 8 then
return Rcv_Err;
end if;
Sport := Read_BE2 (Packet_Off + 0);
Dport := Read_BE2 (Packet_Off + 2);
Len := Read_BE2 (Packet_Off + 4);
if Packet_Len - Packet_Off < Natural (Len) then
return Rcv_Err;
end if;
-- Checksum
if Udp_Checksum (Ip_Off, Packet_Off, Natural (Len)) /= 16#ffff# then
Put_Line ("Bad UDP checksum");
Dump_Pkt (Ip_Off);
return Rcv_Err;
end if;
if False then
Put (" UDP ");
Put_Dec (Sport);
Put (" -> ");
Put_Dec (Dport);
New_Line;
end if;
-- Filter
if Dport /= My_Udp_Port then
return Rcv_Ign;
end if;
if Srv_Udp_Port = 0 then
Srv_Udp_Port := Sport;
elsif Sport /= Srv_Udp_Port then
return Rcv_Ign;
end if;
Packet_Off := Packet_Off + 8;
return Rcv_Udp;
end Handle_Udp;
function Ip_Hdr_Len (Off : Natural) return Natural is
Ihl : Unsigned_8;
begin
Ihl := Read_BE1 (Off);
if (Ihl and 16#f0#) /= 16#40# then
return 0;
end if;
return Natural (Ihl and 16#0f#) * 4;
end Ip_Hdr_Len;
function Handle_Ip return Rcv_Status
is
Hdr_Len : Natural;
Ip_Src : In_Addr;
Ip_Dst : In_Addr;
Frag : Unsigned_16;
Len : Unsigned_16;
Proto : Unsigned_8;
Chksum : Unsigned_16;
Ip_Off : constant Natural := Packet_Off;
begin
-- Sanity check
if Packet_Len - Packet_Off < 20 then
return Rcv_Err;
end if;
-- Check version and compute header length
Hdr_Len := Ip_Hdr_Len (Packet_Off);
if Hdr_Len = 0
or else Packet_Len - Packet_Off < Hdr_Len
then
return Rcv_Err;
end if;
Chksum := Ip_Chksum (Hdr_Len);
if Chksum /= 16#ffff# then
Put ("IPv4 chksum error, got: ");
Put_Hex (Chksum);
New_Line;
Dump_Pkt (Ip_Off);
return Rcv_Err;
end if;
-- Check if this packet is for me
Ip_Dst := Read_BE4 (Packet_Off + 16);
if Ip_Dst /= My_Ip_Addr then
-- Broadcast are ignored
return Rcv_Ign;
end if;
-- Check if this packet comes from known peer
Ip_Src := Read_BE4 (Packet_Off + 12);
if Srv_Ip_Addr = Null_Ip_Addr then
Srv_Ip_Addr := Ip_Src;
Srv_Eth_Addr := Null_Eth_Addr;
elsif Ip_Src /= Srv_Ip_Addr then
return Rcv_Ign;
end if;
-- Check fragment offset
Frag := Read_BE2 (Packet_Off + 6);
if (Frag and (Mf_Flag or Frag_Off_Mask)) /= 0 then
return Rcv_Err;
end if;
-- Check length
Len := Read_BE2 (Packet_Off + 2);
if Packet_Len - Packet_Off < Natural (Len) then
return Rcv_Err;
end if;
Proto := Read_BE1 (Packet_Off + 9);
if False then
Put ("IPv4: ");
Disp_Ip_Addr (To_Ip_Addr (Ip_Src));
Put (" -> ");
Disp_Ip_Addr (To_Ip_Addr (Ip_Dst));
Put (", proto: ");
Put_Dec (Proto);
New_Line;
end if;
Packet_Off := Packet_Off + Hdr_Len;
case Proto is
when Ip_Proto_Udp =>
return Handle_Udp (Ip_Off);
when others =>
return Rcv_Ign;
end case;
end Handle_Ip;
function Handle_Eth_Packet return Rcv_Status is
Eth_Type : Unsigned_16;
begin
-- Sanity check packet size
if Packet_Len - Packet_Off < 14 then
return Rcv_Err;
end if;
-- if Eth_Addr (Packet (Packet_Off .. Packet_Off + 5)) = Eth_Broadcast then
-- return;
-- end if;
-- Skip DA and SA.
Packet_Off := Packet_Off + 12;
Eth_Type := Read_BE2 (Packet_Off);
Packet_Off := Packet_Off + 2;
case Eth_Type is
when Eth_Type_Ip =>
-- Put_Line ("IPv4");
return Handle_Ip;
when Eth_Type_Arp =>
-- Put_Line ("Arp");
return Handle_Arp;
when others =>
-- Put ("Unknown: ");
-- Put_Hex (Eth_Type);
-- New_Line;
return Rcv_None;
end case;
end Handle_Eth_Packet;
procedure Resolve_Eth (Ip : In_Addr)
is
Time : Unsigned_32;
begin
for I in 1 .. 3 loop
exit when Srv_Eth_Addr /= Null_Eth_Addr;
-- Send ARP request
Eth_Send_Init;
-- Eth frame
Write_Eth (Broadcast_Eth_Addr);
Write_Eth (My_Eth_Addr);
Write_BE2 (Eth_Type_Arp);
-- Arp header
Write_BE2 (Arp_Htype);
Write_BE2 (Arp_Ptype);
Write_BE1 (Eth_Addr'Length);
Write_BE1 (Ip_Addr'Length);
Write_BE2 (Arp_Request);
-- Arp sender
Write_Eth (My_Eth_Addr);
Write_BE4 (My_Ip_Addr);
-- Arp target
Write_Eth (Null_Eth_Addr);
Write_BE4 (Ip);
Packet_Len := Packet_Off;
-- Dump_Pkt;
Eth_Send_Packet;
-- Wait 1 sec
Time := Get_Clock + 10;
loop
Eth_Rcv_Wait (Time);
exit when Packet_Len = 0; -- Timeout
exit when Handle_Eth_Packet = Rcv_Arp; -- Got answer
end loop;
end loop;
end Resolve_Eth;
procedure Route_To_Server is
begin
if In_My_Network (Srv_Ip_Addr) then
Resolve_Eth (Srv_Ip_Addr);
elsif Gw_Ip_Addr /= Null_Ip_Addr then
Resolve_Eth (Gw_Ip_Addr);
else
Srv_Eth_Addr := Null_Eth_Addr;
end if;
end Route_To_Server;
procedure Prepare_Ip (Proto : Unsigned_8; Off : out Natural) is
begin
-- Send ARP request
Eth_Send_Init;
-- Eth frame
Write_Eth (Srv_Eth_Addr);
Write_Eth (My_Eth_Addr);
Write_BE2 (Eth_Type_Ip);
-- Ip frame
Off := Packet_Off;
Write_BE1 (16#45#); -- IHL
Write_BE1 (0); -- TOS
Write_BE2 (20); -- Total length
Write_BE2 (0); -- Id
Write_BE2 (0); -- Flags + frag
Write_BE1 (64); -- TTL
Write_BE1 (Proto);
Write_BE2 (0); -- Checksum
Write_BE4 (My_Ip_Addr);
Write_BE4 (Srv_Ip_Addr);
end Prepare_Ip;
procedure Prepare_Udp (Ip_Off : out Natural) is
begin
Prepare_Ip (Ip_Proto_Udp, Ip_Off);
Write_BE2 (My_Udp_Port);
Write_BE2 (Srv_Udp_Port);
Write_BE2 (8); -- Length
Write_BE2 (0); -- Checksum
end Prepare_Udp;
procedure Send_Udp (Ip_Off : Natural)
is
Ip_Len : constant Natural := Ip_Hdr_Len (Ip_Off);
Udp_Off : constant Natural := Ip_Off + Ip_Len;
Udp_Len : constant Natural := Packet_Off - (Ip_Off + Ip_Len);
begin
-- Write UDP length
Write_BE2 (Unsigned_16 (Udp_Len), Udp_Off + 4);
-- Write UDP checksum
Write_2 (not Udp_Checksum (Ip_Off, Udp_Off, Udp_Len), Udp_Off + 6);
-- Write Ip length
Write_BE2 (Unsigned_16 (Ip_Len + Udp_Len), Ip_Off + 2);
-- Write Ip checksum
Write_2 (not Ip_Chksum (Ip_Len, Ip_Off), Ip_Off + 10);
Packet_Len := Packet_Off;
-- Dump_Pkt;
Eth_Send_Packet;
end Send_Udp;
end Netproto;
|
with Utils;
package body STM32GD.I2C.Peripheral is
Default_Timeout : constant Natural := 10000;
Count_Down : Natural;
procedure Start (Duration : Natural := Default_Timeout) is
begin
Count_Down := Duration;
end Start;
function Timed_Out return Boolean is
begin
return (Count_Down = 0);
end Timed_Out;
procedure Pause is
begin
if not Timed_Out then Count_Down := Count_Down - 1; end if;
end Pause;
procedure Init is
begin
I2C.CR1.PE := 0;
I2C.TIMINGR.SCLH := 3;
I2C.TIMINGR.SCLL := 4;
I2C.TIMINGR.SDADEL := 0;
I2C.TIMINGR.SCLDEL := 0;
I2C.TIMINGR.PRESC := 1;
I2C.CR1.PE := 1;
end Init;
function Received_Ack return Boolean is
begin
Start;
while I2C.ISR.TXIS = 0 and I2C.ISR.NACKF = 0 and not Timed_Out
loop
Pause;
end loop;
return (I2C.ISR.TXIS = 1 and I2C.ISR.NACKF = 0);
end Received_Ack;
function Wait_For_TXDR_Empty return Boolean is
begin
Start;
while I2C.ISR.TXIS = 0 and not Timed_Out loop
Pause;
end loop;
return (I2C.ISR.TXIS = 1);
end Wait_For_TXDR_Empty;
function Wait_For_TX_Complete return Boolean is
begin
Start;
while I2C.ISR.TC = 0 and not Timed_Out loop
Pause;
end loop;
return not Timed_Out;
end Wait_For_TX_Complete;
function Wait_For_RX_Not_Empty return Boolean is
begin
Start;
while I2C.ISR.RXNE = 0 and not Timed_Out loop
Pause;
end loop;
return not Timed_Out;
end Wait_For_RX_Not_Empty;
function Wait_For_Idle return Boolean is
begin
Start;
while I2C.ISR.BUSY = 1 and not Timed_Out loop
Pause;
end loop;
return not Timed_Out;
end Wait_For_Idle;
function Wait_For_Stop return Boolean is
begin
Start;
while I2C.ISR.STOPF = 1 and not Timed_Out loop
Pause;
end loop;
return not Timed_Out;
end Wait_For_Stop;
function Test (Address : I2C_Address) return Boolean is
Present : Boolean;
begin
I2C.ICR.NACKCF := 1;
if not Wait_For_Idle then return False; end if;
I2C.CR2.NBYTES := 0;
I2C.CR2.SADD := Address * 2;
I2C.CR2.RD_WRN := 0;
I2C.CR2.AUTOEND := 0;
I2C.CR2.START := 1;
Present := I2C.ISR.NACKF = 0;
I2C.CR2.STOP := 1;
I2C.ICR.NACKCF := 1;
return Present;
end Test;
function Master_Transmit (Address : I2C_Address; Data : Byte;
Restart : Boolean := False) return Boolean is
begin
if not Wait_For_Idle then return False; end if;
I2C.CR2.NBYTES := 1;
I2C.CR2.SADD := Address * 2;
I2C.CR2.RD_WRN := 0;
I2C.CR2.AUTOEND := (if not Restart then 1 else 0);
I2C.CR2.START := 1;
if not Wait_For_TXDR_Empty then return False; end if;
I2C.TXDR.TXDATA := Data;
return True;
end Master_Transmit;
function Master_Receive (Address : I2C_Address; Data : out Byte)
return Boolean is
begin
if not Wait_For_Idle then return False; end if;
I2C.CR2.NBYTES := 1;
I2C.CR2.SADD := Address * 2;
I2C.CR2.AUTOEND := 1;
I2C.CR2.RD_WRN := 1;
I2C.CR2.START := 1;
if not Wait_For_RX_Not_Empty then return False; end if;
Data := I2C.RXDR.RXDATA;
return True;
end Master_Receive;
function Master_Receive (Address : I2C_Address; Data : out I2C_Data)
return Boolean
is
begin
I2C.CR2.NBYTES := Data'Length;
I2C.CR2.SADD := Address * 2;
I2C.CR2.RD_WRN := 1;
I2C.CR2.AUTOEND := 1;
I2C.CR2.START := 1;
for D of Data loop
if Wait_For_RX_Not_Empty then
D := I2C.RXDR.RXDATA;
end if;
end loop;
return True;
end Master_Receive;
function Write_Register (Address : I2C_Address; Register : Byte;
Data : Byte) return Boolean is
begin
if not Wait_For_Idle then return False; end if;
I2C.CR2.NBYTES := 2;
I2C.CR2.SADD := Address * 2;
I2C.CR2.AUTOEND := 1;
I2C.CR2.RD_WRN := 0;
I2C.CR2.START := 1;
if not Wait_For_TXDR_Empty then return False; end if;
I2C.TXDR.TXDATA := Register;
if not Wait_For_TXDR_Empty then return False; end if;
I2C.TXDR.TXDATA := Data;
return True;
end Write_Register;
function Read_Register (Address : I2C_Address; Register : Byte;
Data : out Byte) return Boolean is
begin
if not Wait_For_Idle then return False; end if;
I2C.CR2.NBYTES := 1;
I2C.CR2.SADD := Address * 2;
I2C.CR2.AUTOEND := 1;
I2C.CR2.RD_WRN := 0;
I2C.CR2.START := 1;
if not Wait_For_TXDR_Empty then return False; end if;
I2C.TXDR.TXDATA := Register;
-- if not Wait_For_TX_Complete then return False; end if;
I2C.CR2.NBYTES := 1;
I2C.CR2.RD_WRN := 1;
I2C.CR2.SADD := Address * 2;
I2C.CR2.START := 1;
if not Wait_For_RX_Not_Empty then return False; end if;
Data := I2C.RXDR.RXDATA;
return True;
end Read_Register;
end STM32GD.I2C.Peripheral;
|
-- The Village of Vampire by YT, このソースコードはNYSLです
with Ada.Containers.Indefinite_Ordered_Maps;
private with Ada.Containers.Ordered_Maps;
private with Ada.Strings.Unbounded;
package Tabula.Users.Lists is
type User_List (<>) is limited private;
function Create (
Directory : not null Static_String_Access;
Log_File_Name : not null Static_String_Access)
return User_List;
-- 問い合わせ
function Exists (List : User_List; Id : String) return Boolean;
type User_State is (Unknown, Invalid, Log_Off, Valid);
procedure Query (
List : in out User_List;
Id : in String;
Password : in String;
Remote_Addr : in String;
Remote_Host : in String;
Now : in Ada.Calendar.Time;
Info : out User_Info;
State : out User_State);
procedure New_User (
List : in out User_List;
Id : in String;
Password : in String;
Remote_Addr : in String;
Remote_Host : in String;
Now : in Ada.Calendar.Time;
Result : out Boolean);
procedure Update (
List : in out User_List;
Id : in String;
Remote_Addr : in String;
Remote_Host : in String;
Now : in Ada.Calendar.Time;
Info : in out User_Info);
-- 全ユーザーのリスト
package User_Info_Maps is
new Ada.Containers.Indefinite_Ordered_Maps (String, User_Info);
function All_Users (List : User_List) return User_Info_Maps.Map;
-- ムラムラスカウター(仮)
procedure Muramura_Count (
List : in out User_List;
Now : Ada.Calendar.Time;
Muramura_Duration : Duration;
Result : out Natural);
private
use type Ada.Calendar.Time;
type User_Log_Item is record
Id : aliased Ada.Strings.Unbounded.Unbounded_String;
Remote_Addr : aliased Ada.Strings.Unbounded.Unbounded_String;
Remote_Host : aliased Ada.Strings.Unbounded.Unbounded_String;
end record;
function "<" (Left, Right : User_Log_Item) return Boolean;
package Users_Log is
new Ada.Containers.Ordered_Maps (User_Log_Item, Ada.Calendar.Time);
type User_List is limited record
Directory : not null Static_String_Access;
Log_File_Name : not null Static_String_Access;
Log_Read : Boolean;
Log : aliased Users_Log.Map;
end record;
-- log
procedure Iterate_Log (
List : in out User_List;
Process : not null access procedure (
Id : in String;
Remote_Addr : in String;
Remote_Host : in String;
Time : in Ada.Calendar.Time));
end Tabula.Users.Lists;
|
-- Ada_GUI implementation based on Gnoga. Adapted 2021
-- --
-- GNOGA - The GNU Omnificent GUI for Ada --
-- --
-- G N O G A . G U I . E L E M E N T --
-- --
-- S p e c --
-- --
-- --
-- Copyright (C) 2014 David Botton --
-- --
-- This library is free software; you can redistribute it and/or modify --
-- it under terms of the GNU General Public License as published by the --
-- Free Software Foundation; either version 3, or (at your option) any --
-- later version. This 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. --
-- --
-- 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/>. --
-- --
-- As a special exception, if other files instantiate generics from this --
-- unit, or you link this unit with other files to produce an executable, --
-- this unit does not by itself cause the resulting executable to be --
-- covered by the GNU General Public License. This exception does not --
-- however invalidate any other reasons why the executable file might be --
-- covered by the GNU Public License. --
-- --
-- For more information please go to http://www.gnoga.com --
------------------------------------------------------------------------------
with Ada.Containers.Vectors;
with Ada.Containers.Indefinite_Hashed_Maps;
with Ada.Strings.Hash;
with Ada_GUI.Gnoga.Colors;
package Ada_GUI.Gnoga.Gui.Element is
-------------------------------------------------------------------------
-- Element_Type
-------------------------------------------------------------------------
type Element_Type is new Gnoga.Gui.Base_Type with private;
type Element_Access is access all Element_Type;
type Pointer_To_Element_Class is access all Element_Type'Class;
-- Element_Type is the parent class of all Gnoga GUI elements.
-- It is generally used internally to create and bind Gnoga elements to
-- HTML5 DOM elements.
package Element_Type_Arrays is
new Ada.Containers.Vectors
(Index_Type => Positive,
Element_Type => Pointer_To_Element_Class,
"=" => Element."=");
package Element_Type_Maps is
new Ada.Containers.Indefinite_Hashed_Maps (String,
Pointer_To_Element_Class,
Ada.Strings.Hash,
Equivalent_Keys => "=");
subtype Element_Type_Array is Element_Type_Arrays.Vector;
-- Arrays of Base_Types
subtype Element_Type_Map is Element_Type_Maps.Map;
-- String to Base_Type associative array
-------------------------------------------------------------------------
-- Element_Type - Creation Methods
-------------------------------------------------------------------------
procedure Create_From_HTML (Element : in out Element_Type;
Parent : in out Gnoga.Gui.Base_Type'Class;
HTML : in String;
ID : in String := "");
-- Create a Gnoga element with HTML not attached to the DOM. If ID is blank
-- Gnoga will generate a unique one for it. The created object will be
-- stored on the browser but will not be inserted in to the DOM until
-- Place_Inside_Top_Of, Place_Inside_Bottom_Of, Place_Before, Place_After
-- is called. This is done automatically if Parent is a child type of
-- Gnoga_Gui.View.View_Base_Type unless the Auto_Place property is
-- set to False _before_ any creation method is called.
-- Quotes in HTML have to be escaped if any.
--
-- Note: All IDs _must_ be unique for use in Gnoga.
HTML_Namespace : constant String := "http://www.w3.org/1999/xhtml";
MathML_Namespace : constant String := "http://www.w3.org/1998/Math/MathML";
SVG_Namespace : constant String := "http://www.w3.org/2000/svg";
XLink_Namespace : constant String := "http://www.w3.org/1999/xlink";
XMLNS_Namespace : constant String := "http://www.w3.org/2000/xmlns/";
XML_Namespace : constant String :=
"http://www.w3.org/XML/1998/namespace";
procedure Create_XML_Element
(Element : in out Element_Type;
Parent : in out Gnoga.Gui.Base_Type'Class;
Namespace : in String;
Element_Type : in String;
ID : in String := "");
-- Create an XML element using XML Namespace.
-------------------------------------------------------------------------
-- Element_Type - Properties
-------------------------------------------------------------------------
-- Element Properties --
procedure Access_Key (Element : in out Element_Type; Value : String);
function Access_Key (Element : Element_Type) return String;
-- Used for hot key access to element. [special key] + Access_Key
-- The [special key] per browser and platform is:
--
-- Browser Windows Linux Mac
-- ----------------- ------- ----- ---
-- Internet Explorer [Alt] N/A N/A
-- Chrome [Alt] [Alt] [Control][Alt]
-- Firefox [Alt][Shift] [Alt][Shift] [Control][Alt]
-- Safari [Alt] N/A [Control][Alt]
-- Opera 15+ [Alt] [Alt] [Alt]
procedure Advisory_Title (Element : in out Element_Type; Value : in String);
function Advisory_Title (Element : Element_Type) return String;
-- Advisory_Title of Element, usually used for body and image maps
procedure Class_Name (Element : in out Element_Type; Value : in String);
function Class_Name (Element : Element_Type) return String;
-- CSS Class name, can be multiple separated by <space>
-- See Add_Class, Remove_Class and Toggle_Class Methods for adding and
-- removing individual or groups of classes in an easier way.
procedure Editable (Element : in out Element_Type;
Value : in Boolean := True);
function Editable (Element : Element_Type) return Boolean;
-- Note: This will make almost any element with content editable, even
-- non form types in most browsers.
procedure Draggable (Element : in out Element_Type;
Value : in Boolean := True);
function Draggable (Element : Element_Type) return Boolean;
-- In order to make an object draggable in addition to Draggable being true
-- the On_Drag_Start event _must_ be bound as well to set the Drag_Text.
-- To receive a drop, you need to bind On_Drop. See Gnoga.Gui
procedure Inner_HTML (Element : in out Element_Type; Value : in String);
function Inner_HTML (Element : Element_Type) return String;
-- This will completely replace the inner html of an element. This will
-- remove any Elements within Element from the DOM. If those elements
-- have ID_Types of Gnoga_ID they are still available and can be placed
-- in the DOM again using the Element.Place_* methods. However if they
-- were of ID_Type DOM_ID they are lost forever.
function Outer_HTML (Element : Element_Type) return String;
-- Returns the HTML for Element and all its contents.
-- Text Content Properties --
-- <tag>Text Content</tag> - Text content is the content contained by the
-- tag. This should not be confused with the
-- "Value" of a Form Tag.
-- (See. Gnoga.Gui.Element.Form.Value)
procedure Language_Code (Element : in out Element_Type; Value : in String);
function Language_Code (Element : Element_Type) return String;
procedure Tab_Index (Element : in out Element_Type; Value : in Natural);
function Tab_Index (Element : Element_Type) return Natural;
procedure Spell_Check (Element : in out Element_Type;
Value : in Boolean := True);
function Spell_Check (Element : Element_Type) return Boolean;
-- If true Element is subject to browser spell checking if Editable is
-- also true.
procedure Text (Element : in out Element_Type; Value : in String);
function Text (Element : Element_Type) return String;
-- Text content of element.
type Text_Direction_Type is (Left_To_Right, Right_To_Left);
procedure Text_Direction (Element : in out Element_Type;
Value : in Text_Direction_Type);
function Text_Direction (Element : Element_Type) return Text_Direction_Type;
-- BiDi text direction
-- Visibility and Layout Properties --
procedure Hidden (Element : in out Element_Type;
Value : in Boolean := True);
function Hidden (Element : Element_Type) return Boolean;
-- The hidden property will make an element invisible, however unlike
-- the property Visible which uses CSS to hide the Element, Hidden implies
-- the element is semantically not relevant not just visually and will
-- _also_ remove it from layout similar to setting Element.Display (None).
procedure Visible (Element : in out Element_Type;
Value : in Boolean := True);
function Visible (Element : Element_Type) return Boolean;
-- This will cause the Element to no longer be visible but it will still
-- take up space where it was in the layout. Use Element.Hidden to also
-- remove from layout.
-- Note: that each property, Visible, Hidden and Display (None) all work
-- independently and do not reflect the actual client side visual state
-- but the property state. To check if an object is for sure not visible
-- would require checking all three properties.
procedure Display (Element : in out Element_Type;
Value : in String);
function Display (Element : Element_Type) return String;
-- Display sets the CSS Display property that handles how elements are
-- treated by the browser layout engine.
--
-- Common Values:
--
-- none - Remove Element from layout but remain in the DOM this is
-- similar to Element.Hidden, but not like Element.Visible
-- that makes the element not visible but still take up
-- space in layout.
--
-- block - Displays an element starting on a new line and stretches
-- out to the left and right as far as it can. e.g. <div> by
-- default
--
-- inline - Wraps with text in a paragraph. e.g. <span> by default
--
-- inline-block - Flows with paragraph but will always fill from left to
-- right.
--
-- flex - Use the "flexbox" model
-- Box Properties --
type Clear_Side_Type is (Left, Right, Both);
procedure Clear_Side (Element : in out Element_Type;
Value : in Clear_Side_Type);
-- When using "float" for layout sets if the right or left side
-- of Block should be clear of any "floated" Element.
type Float_Type is (None, Left, Right);
procedure Layout_Float (Element : in out Element_Type;
Value : in Float_Type);
-- Sets if Element should "float" to the left or right until touching
-- the closest element.
type Overflow_Type is (Visible, Hidden, Scroll, Auto);
procedure Overflow (Element : in out Element_Type;
Value : in Overflow_Type);
function Overflow (Element : Element_Type) return Overflow_Type;
-- How to handle overflow of contents of an element's box
-- The default is Visible - no clipping.
procedure Overflow_X (Element : in out Element_Type;
Value : in Overflow_Type);
procedure Overflow_Y (Element : in out Element_Type;
Value : in Overflow_Type);
-- How to handle overflow of contents of an element's box for X or Y
-- The default is Visible - no clipping.
type Resizable_Type is (None, Both, Horizontal, Vertical);
procedure Resizable (Element : in out Element_Type;
Value : in Resizable_Type);
function Resizable (Element : Element_Type) return Resizable_Type;
-- If overflow is not set to visible, sets if element can be resized
-- by user.
type Position_Type is (Static, Absolute, Fixed, Relative);
procedure Position (Element : in out Element_Type;
Value : in Position_Type);
function Position (Element : Element_Type) return Position_Type;
-- Determines how the properties left, right, top and bottom are
-- interpreted.
--
-- Static - According to document flow, position properties have no
-- affect.
-- Absolute - Position properties are relative to the first non-static
-- element in the DOM before Element
-- Fixed - Position properties are relative to browser window
-- Relative - Position properties are relative to where the static position
-- of the element would in the normal document flow.
type Vertical_Align_Type is (Baseline, Sub, Super, Top, Middle, Bottom,
Text_Top, Text_Bottom);
procedure Vertical_Align (Element : in out Element_Type;
Value : in Vertical_Align_Type);
-- Vertical alignment of Element
type Box_Sizing_Type is (Content_Box, Border_Box);
procedure Box_Sizing (Element : in out Element_Type;
Value : in Box_Sizing_Type);
function Box_Sizing (Element : Element_Type) return Box_Sizing_Type;
-- Affects if height and width properties represent just the content or
-- the border, margin, padding, scroll and content area as a whole.
-- The default is Content_Box
procedure Z_Index (Element : in out Element_Type;
Value : in Integer);
-- Set stack order of element
-- Note: Z_Index only works on Elements with Position Type of absolute,
-- relative and fixed.
procedure Margin (Element : in out Element_Type;
Top : in String := "0";
Right : in String := "0";
Bottom : in String := "0";
Left : in String := "0");
-- Each can be - length|auto|initial|inherit
procedure Padding (Element : in out Element_Type;
Top : in String := "0";
Right : in String := "0";
Bottom : in String := "0";
Left : in String := "0");
-- Each can be - length|initial|inherit
function Position_Top (Element : Element_Type) return Integer;
function Position_Left (Element : Element_Type) return Integer;
-- Position in pixels relative to Element's parent in the DOM
function Offset_From_Top (Element : Element_Type) return Integer;
function Offset_From_Left (Element : Element_Type) return Integer;
-- Position in pixels relative to the document
procedure Left (Element : in out Element_Type;
Value : in Integer;
Unit : in String := "px");
procedure Left (Element : in out Element_Type;
Value : in String);
function Left (Element : Element_Type) return String;
procedure Right (Element : in out Element_Type;
Value : in Integer;
Unit : in String := "px");
procedure Right (Element : in out Element_Type;
Value : in String);
function Right (Element : Element_Type) return String;
procedure Top (Element : in out Element_Type;
Value : in Integer;
Unit : in String := "px");
procedure Top (Element : in out Element_Type;
Value : in String);
function Top (Element : Element_Type) return String;
procedure Bottom (Element : in out Element_Type;
Value : in Integer;
Unit : in String := "px");
procedure Bottom (Element : in out Element_Type;
Value : in String);
function Bottom (Element : Element_Type) return String;
procedure Box_Height (Element : in out Element_Type;
Value : in Integer;
Unit : in String := "px");
procedure Box_Height (Element : in out Element_Type;
Value : in String);
function Box_Height (Element : Element_Type) return String;
-- Box height based on Box_Sizing
procedure Box_Width (Element : in out Element_Type;
Value : in Integer;
Unit : in String := "px");
procedure Box_Width (Element : in out Element_Type;
Value : in String);
function Box_Width (Element : Element_Type) return String;
-- Box with based on Box_Sizing
procedure Minimum_Height (Element : in out Element_Type;
Value : in Integer;
Unit : in String := "px");
procedure Minimum_Height (Element : in out Element_Type;
Value : in String);
function Minimum_Height (Element : Element_Type) return String;
procedure Maximum_Height (Element : in out Element_Type;
Value : in Integer;
Unit : in String := "px");
procedure Maximum_Height (Element : in out Element_Type;
Value : in String);
function Maximum_Height (Element : Element_Type) return String;
procedure Minimum_Width (Element : in out Element_Type;
Value : in Integer;
Unit : in String := "px");
procedure Minimum_Width (Element : in out Element_Type;
Value : in String);
function Minimum_Width (Element : Element_Type) return String;
procedure Maximum_Width (Element : in out Element_Type;
Value : in Integer;
Unit : in String := "px");
procedure Maximum_Width (Element : in out Element_Type;
Value : in String);
function Maximum_Width (Element : Element_Type) return String;
-- For reference:
-- | Margin | Border | Padding | Scroll | [Element] | Scroll | Padding ...
-- Height and Width of Element are in Base_Type
-- All the following have the advantage of the CSS related size properties
-- in that the results are always pixels and numeric.
procedure Inner_Height (Element : in out Element_Type; Value : in Integer);
function Inner_Height (Element : Element_Type) return Integer;
-- Includes padding but not border
procedure Inner_Width (Element : in out Element_Type; Value : in Integer);
function Inner_Width (Element : Element_Type) return Integer;
-- Includes padding but not border
function Outer_Height (Element : Element_Type) return Integer;
-- Includes padding and border but not margin
function Outer_Width (Element : Element_Type) return Integer;
-- Includes padding and border but not margin
function Outer_Height_To_Margin (Element : Element_Type) return Integer;
-- Includes padding and border and margin
function Outer_Width_To_Margin
(Element : Element_Type) return Integer;
-- Includes padding and border and margin
function Client_Width (Element : Element_Type) return Natural;
-- Inner width of an element in pixels.
-- CSS width + CSS padding - width of vertical scrollbar (if present)
-- Does not include the border or margin.
function Client_Height (Element : Element_Type) return Natural;
-- Inner height of an element in pixels.
-- CSS height + CSS padding - height of horizontal scrollbar (if present)
-- Does not include the border or margin.
function Client_Left (Element : Element_Type) return Natural;
-- The width of the left border of an element in pixels.
--. It does not include the margin or padding.
function Client_Top (Element : Element_Type) return Natural;
-- The width of the top border of an element in pixels.
--. It does not include the margin or padding.
function Offset_Width (Element : Element_Type) return Integer;
-- CSS width + CSS padding + width of vertical scrollbar (if present) +
-- Border
function Offset_Height (Element : Element_Type) return Integer;
-- CSS height + CSS padding + height of horizontal scrollbar (if present) +
-- Border
function Offset_Left (Element : Element_Type) return Integer;
-- The width from parent element border to child border left
function Offset_Top (Element : Element_Type) return Integer;
-- The width from parent element border to child border top
function Scroll_Width (Element : Element_Type) return Natural;
-- Either the width in pixels of the content of an element or the width of
-- the element itself, whichever is greater
function Scroll_Height (Element : Element_Type) return Natural;
-- Height of an element's content, including content not visible on the
-- screen due to overflow.
procedure Scroll_Left (Element : in out Element_Type; Value : Integer);
function Scroll_Left (Element : Element_Type) return Integer;
-- The number of pixels that an element's content is scrolled to the left.
-- For RTL languages is negative.
procedure Scroll_Top (Element : in out Element_Type; Value : Integer);
function Scroll_Top (Element : Element_Type) return Integer;
-- The number of pixels that an element's content has been scrolled
-- upward.
-- Style Properties --
-- Color --
procedure Color (Element : in out Element_Type; Value : String);
procedure Color (Element : in out Element_Type;
RGBA : in Gnoga.RGBA_Type);
procedure Color (Element : in out Element_Type;
Enum : Gnoga.Colors.Color_Enumeration);
function Color (Element : Element_Type) return Gnoga.RGBA_Type;
procedure Opacity (Element : in out Element_Type;
Alpha : in Gnoga.Alpha_Type);
function Opacity (Element : Element_Type) return Gnoga.Alpha_Type;
-- Background --
type Background_Attachment_Type is (Scroll, Fixed, Local);
procedure Background_Attachment
(Element : in out Element_Type;
Value : in Background_Attachment_Type);
function Background_Attachment (Element : Element_Type)
return Background_Attachment_Type;
procedure Background_Color (Element : in out Element_Type;
Value : in String);
procedure Background_Color (Element : in out Element_Type;
RGBA : in Gnoga.RGBA_Type);
procedure Background_Color
(Element : in out Element_Type;
Enum : in Gnoga.Colors.Color_Enumeration);
function Background_Color (Element : Element_Type)
return Gnoga.RGBA_Type;
procedure Background_Image (Element : in out Element_Type;
Value : in String);
function Background_Image (Element : Element_Type) return String;
-- proper syntax is "url(...)" | "" to clear
procedure Background_Position (Element : in out Element_Type;
Value : in String);
function Background_Position (Element : Element_Type) return String;
-- combination of 2 - left/right/center/top/bottom | %x %y | x y
procedure Background_Origin (Element : in out Element_Type;
Value : in String);
function Background_Origin (Element : Element_Type) return String;
-- Background position property is relative to origin of:
-- padding-box|border-box|content-box
procedure Background_Repeat (Element : in out Element_Type;
Value : in String);
function Background_Repeat (Element : Element_Type) return String;
-- repeat|repeat-x|repeat-y|no-repeat
procedure Background_Clip (Element : in out Element_Type;
Value : in String);
function Background_Clip (Element : Element_Type) return String;
-- border-box|padding-box|content-box
procedure Background_Size (Element : in out Element_Type;
Value : in String);
function Background_Size (Element : Element_Type) return String;
-- auto| w h | % = cover of parent | contain
-- Border --
type Border_Style is (None, Hidden, Dotted, Dashed, Solid, Double, Groove,
Ridge, Inset, Outset);
procedure Border (Element : in out Element_Type;
Width : in String := "medium";
Style : in Border_Style := Solid;
Color : in Gnoga.Colors.Color_Enumeration :=
Gnoga.Colors.Black);
-- Width = medium|thin|thick|length|initial|inherit;
-- If Color is "" then border is same as Element.Color
procedure Border_Radius (Element : in out Element_Type;
Radius : in String := "0");
-- Curve of borders
-- Radius = length|%|initial|inherit
procedure Shadow (Element : in out Element_Type;
Horizontal_Position : in String;
Vertical_Position : in String;
Blur : in String := "";
Spread : in String := "";
Color : in Gnoga.Colors.Color_Enumeration := Gnoga.Colors.Black;
Inset_Shadow : in Boolean := False);
procedure Shadow_None (Element : in out Element_Type);
type Outline_Style_Type is (None, Hidden, Dotted, Dashed, Solid, Double,
Groove, Ridge, Inset, Outset);
procedure Outline (Element : in out Element_Type;
Color : in String := "invert";
Style : in Outline_Style_Type := None;
Width : in String := "medium");
procedure Cursor (Element : in out Element_Type;
Value : in String);
function Cursor (Element : Element_Type) return String;
-- Sets the cursor to a standard type or an image
-- if set to url(url_to_image). When using a url is best
-- to suggest an alternate cursor, e.g. "url(url_to_image),auto"
-- A list of standard cursor types can be found at:
-- http://www.w3schools.com/cssref/pr_class_cursor.asp
-- Text --
type Font_Style_Type is (Normal, Italic, Oblique);
type Font_Weight_Type is (Weight_Normal, Weight_Bold,
Weight_Bolder, Weight_Lighter,
Weight_100, Weight_200, Weight_300,
Weight_400, Weight_500, Weight_600,
Weight_700, Weight_800, Weight_900);
function Image (Value : in Gnoga.Gui.Element.Font_Weight_Type) return String;
function Value (Value : in String) return Gnoga.Gui.Element.Font_Weight_Type;
type Font_Variant_Type is (Normal, Small_Caps);
type System_Font_Type is (Caption, Icon, Menu, Message_Box, Small_Caption,
Status_Bar);
procedure Font (Element : in out Element_Type;
Family : in String := "sans-serif";
Height : in String := "medium";
Style : in Font_Style_Type := Normal;
Weight : in Font_Weight_Type := Weight_Normal;
Variant : in Font_Variant_Type := Normal);
procedure Font (Element : in out Element_Type;
System_Font : in System_Font_Type);
-- Sets or returns the current font properties for text content
type Alignment_Type is (Left, Right, Center, At_Start, To_End);
procedure Text_Alignment (Element : in out Element_Type;
Value : in Alignment_Type);
-- Text Alignment, At_Start = Left, and To_End = Right in ltr languages
-- in rtl languages At_Start = Right, and To_End = Left.
-- Framework Properties --
procedure Auto_Place (Element : in out Element_Type; Value : Boolean);
function Auto_Place (Element : Element_Type) return Boolean;
-- Elements by default are created outside the DOM and therefore not
-- visible. If Auto_Place is set to false _before_ Create is called on
-- an Element, View's will not place the Element in to the DOM as is
-- the View's default behavior. Custom widgets that have child widgets
-- should be designed to respect this property. Auto_Place if set to
-- False will also prevent Auto_Set_View if Element's Parent is a Window
-- General Access to Element --
procedure Style (Element : in out Element_Type;
Name : in String;
Value : in String);
procedure Style (Element : in out Element_Type;
Name : in String;
Value : in Integer);
function Style (Element : Element_Type; Name : String) return String;
function Style (Element : Element_Type; Name : String) return Integer;
-- General access to style Name
procedure Attribute (Element : in out Element_Type;
Name : in String;
Value : in String);
function Attribute (Element : Element_Type; Name : String) return String;
-- General access to attribute Name
-- Traversal Properties --
procedure First_Child (Element : in out Element_Type;
Child : in out Element_Type'Class);
-- If Child does not have an html id than Element_Type will have an
-- ID of undefined and therefore attached to no actual HTML element.
procedure Next_Sibling (Element : in out Element_Type;
Sibling : in out Element_Type'Class);
-- If Sibling does not have an html id than Element_Type will have an
-- ID of undefined and therefore attached to no actual HTML element.
-- Internal Properties --
function HTML_Tag (Element : Element_Type) return String;
-------------------------------------------------------------------------
-- Element_Type - Methods
-------------------------------------------------------------------------
-- Element Methods --
procedure Click (Element : in out Element_Type);
-- Simulate click on element
procedure Add_Class (Element : in out Element_Type; Class_Name : in String);
-- Adds one or more Class_Name(s) to Element
procedure Remove_Class (Element : in out Element_Type;
Class_Name : in String);
-- Removes one or more Class_Name(s) to Element
procedure Toggle_Class (Element : in out Element_Type;
Class_Name : in String);
-- Toggles on and off one or more Class_Name(s) to Element
-- DOM Placement Methods --
procedure Place_Inside_Top_Of (Element : in out Element_Type;
Target : in out Element_Type'Class);
procedure Place_Inside_Bottom_Of (Element : in out Element_Type;
Target : in out Element_Type'Class);
procedure Place_Before (Element : in out Element_Type;
Target : in out Element_Type'Class);
procedure Place_After (Element : in out Element_Type;
Target : in out Element_Type'Class);
procedure Remove (Element : in out Element_Type);
-- Removes an element from the DOM, if the ID_Type is DOM_ID, the ID
-- will be changed to a unique Gnoga_ID before removal.
private
type Element_Type is new Gnoga.Gui.Base_Type with
record
Auto_Place : Boolean := True;
end record;
end Ada_GUI.Gnoga.Gui.Element;
|
package body cached_Rotation
is
use ada.Numerics,
float_elementary_Functions;
the_Cache : array (0 .. slot_Count - 1) of aliased Matrix_2x2_type;
Pi_x_2 : constant := Pi * 2.0;
last_slot_Index : constant Float_type := Float_type (slot_Count - 1);
index_Factor : constant Float_type := last_slot_Index / Pi_x_2;
function to_Rotation (Angle : in Float_type) return access constant Matrix_2x2_type
is
the_Index : standard.Integer := standard.Integer (Angle * index_Factor) mod slot_Count;
begin
if the_Index < 0
then
the_index := the_Index + slot_Count;
end if;
return the_Cache (the_Index)'Access;
end to_Rotation;
begin
for Each in the_Cache'Range
loop
declare
Angle : constant Float_type := ( Float_type (Each) / Float_type (slot_Count - 1)
* Pi_x_2);
C : constant Float_type := Cos (Angle);
S : constant Float_type := Sin (Angle);
begin
the_Cache (Each) := to_Matrix_2x2 (C, -S,
S, C);
end;
end loop;
end cached_Rotation;
|
package Hello is
type Printer is abstract tagged null record;
procedure Print_On_Console (P : Printer; V : String) is abstract;
type Ada_Printer is new Printer with null record;
procedure Print_On_Console (P : Ada_Printer; V : String);
procedure Print_Messages (P : Printer'Class);
end Hello;
|
-- An example of using low-level convertor API (fixed string procedures)
-- Program reads standard input, adds cr before lf, then writes to standard output
with Ada.Streams;
use Ada.Streams;
with Ada.Text_IO;
use Ada.Text_IO;
with Ada.Text_IO.Text_Streams;
use Ada.Text_IO.Text_Streams;
with Ada.Unchecked_Conversion;
with Encodings.Line_Endings.Strip_CR;
with Encodings.Utility;
use Encodings.Utility;
procedure Strip_CR is
Input_Stream: Stream_Access := Stream(Standard_Input);
Output_Stream: Stream_Access := Stream(Standard_Output);
Input_Buffer: String(1 .. 100);
Output_Buffer: String(1 .. 100);
Input_Last, Input_Read_Last: Natural;
Output_Last: Natural;
Coder: Encodings.Line_Endings.Strip_CR.Coder;
begin
while not End_Of_File(Standard_Input) loop
Read_String(Input_Stream.all, Input_Buffer, Input_Read_Last);
Input_Last := Input_Buffer'First - 1;
while Input_Last < Input_Read_Last loop
Coder.Convert(Input_Buffer(Input_Last + 1 .. Input_Read_Last), Input_Last, Output_Buffer, Output_Last);
String'Write(Output_Stream, Output_Buffer(Output_Buffer'First .. Output_Last));
end loop;
end loop;
end Strip_CR;
|
-- Copyright (c) 2021 Bartek thindil Jasicki <thindil@laeran.pl>
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
with Ada.Characters.Handling; use Ada.Characters.Handling;
with Ada.Strings;
with Tcl.Lists; use Tcl.Lists;
package body Tk.TtkWidget is
procedure Option_Image
(Name: String; Value: Compound_Type;
Options_String: in out Unbounded_String) is
begin
if Value /= EMPTY then
Append
(Source => Options_String,
New_Item =>
" -" & Name & " " &
To_Lower(Item => Compound_Type'Image(Value)));
end if;
end Option_Image;
procedure Option_Image
(Name: String; Value: Disabled_State_Type;
Options_String: in out Unbounded_String) is
begin
if Value /= NONE then
Append
(Source => Options_String,
New_Item =>
" -" & Name & " " &
To_Lower(Item => Disabled_State_Type'Image(Value)));
end if;
end Option_Image;
procedure Option_Image
(Name: String; Value: Ttk_Image_Option;
Options_String: in out Unbounded_String) is
begin
if Value = Default_Ttk_Image_Option then
return;
end if;
Append
(Source => Options_String,
New_Item => " -" & Name & " {" & To_String(Source => Value.Default));
if Value.Active /= Tcl_String(Null_Unbounded_String) then
Append
(Source => Options_String,
New_Item => " active " & To_String(Source => Value.Active));
end if;
if Value.Disabled /= Tcl_String(Null_Unbounded_String) then
Append
(Source => Options_String,
New_Item => " disabled " & To_String(Source => Value.Disabled));
end if;
if Value.Focus /= Tcl_String(Null_Unbounded_String) then
Append
(Source => Options_String,
New_Item => " focus " & To_String(Source => Value.Focus));
end if;
if Value.Pressed /= Tcl_String(Null_Unbounded_String) then
Append
(Source => Options_String,
New_Item => " pressed " & To_String(Source => Value.Pressed));
end if;
if Value.Selected /= Tcl_String(Null_Unbounded_String) then
Append
(Source => Options_String,
New_Item => " selected " & To_String(Source => Value.Selected));
end if;
if Value.Background /= Tcl_String(Null_Unbounded_String) then
Append
(Source => Options_String,
New_Item =>
" background " & To_String(Source => Value.Background));
end if;
if Value.Readonly /= Tcl_String(Null_Unbounded_String) then
Append
(Source => Options_String,
New_Item => " readonly " & To_String(Source => Value.Readonly));
end if;
if Value.Alternate /= Tcl_String(Null_Unbounded_String) then
Append
(Source => Options_String,
New_Item => " alternate " & To_String(Source => Value.Alternate));
end if;
if Value.Invalid /= Tcl_String(Null_Unbounded_String) then
Append
(Source => Options_String,
New_Item => " invalid " & To_String(Source => Value.Invalid));
end if;
if Value.Hover /= Tcl_String(Null_Unbounded_String) then
Append
(Source => Options_String,
New_Item => " hover " & To_String(Source => Value.Hover));
end if;
Append(Source => Options_String, New_Item => "}");
end Option_Image;
procedure Option_Image
(Name: String; Value: Padding_Data;
Options_String: in out Unbounded_String) is
use Ada.Strings;
First: Boolean := True;
procedure Append_Value
(New_Value: Pixel_Data; Is_First: in out Boolean) is
begin
if New_Value.Value > -1.0 then
if Is_First then
Append
(Source => Options_String, New_Item => " -" & Name & " {");
Is_First := False;
end if;
Append
(Source => Options_String,
New_Item => Pixel_Data_Image(Value => New_Value) & " ");
end if;
end Append_Value;
begin
Append_Value(New_Value => Value.Left, Is_First => First);
Append_Value(New_Value => Value.Top, Is_First => First);
Append_Value(New_Value => Value.Right, Is_First => First);
Append_Value(New_Value => Value.Bottom, Is_First => First);
if not First then
Trim(Source => Options_String, Side => Right);
Append(Source => Options_String, New_Item => "}");
end if;
end Option_Image;
function Option_Value
(Ttk_Widgt: Ttk_Widget; Name: String) return Compound_Type is
Result: constant String :=
Execute_Widget_Command
(Widgt => Ttk_Widgt, Command_Name => "cget", Options => "-" & Name)
.Result;
begin
if Result'Length = 0 then
return EMPTY;
end if;
return Compound_Type'Value(Result);
end Option_Value;
function Option_Value
(Ttk_Widgt: Ttk_Widget; Name: String) return Disabled_State_Type is
begin
return
Disabled_State_Type'Value
(Execute_Widget_Command
(Widgt => Ttk_Widgt, Command_Name => "cget",
Options => "-" & Name)
.Result);
end Option_Value;
function Option_Value
(Ttk_Widgt: Ttk_Widget; Name: String) return Ttk_Image_Option is
Options: Ttk_Image_Option := Default_Ttk_Image_Option;
Options_Array: constant Array_List :=
Split_List
(List =>
Execute_Widget_Command
(Widgt => Ttk_Widgt, Command_Name => "cget",
Options => "-" & Name)
.Result,
Interpreter => Tk_Interp(Widgt => Ttk_Widgt));
Index: Positive := 2;
begin
if Options_Array'Length < 1 then
return Options;
end if;
Options.Default :=
To_Tcl_String(Source => To_String(Source => Options_Array(1)));
Set_Options_Loop :
while Index <= Options_Array'Length loop
if Options_Array(Index) = To_Tcl_String(Source => "active") then
Options.Active := Options_Array(Index + 1);
elsif Options_Array(Index) = To_Tcl_String(Source => "disabled") then
Options.Disabled := Options_Array(Index + 1);
elsif Options_Array(Index) = To_Tcl_String(Source => "focus") then
Options.Focus := Options_Array(Index + 1);
elsif Options_Array(Index) = To_Tcl_String(Source => "pressed") then
Options.Pressed := Options_Array(Index + 1);
elsif Options_Array(Index) = To_Tcl_String(Source => "selected") then
Options.Selected := Options_Array(Index + 1);
elsif Options_Array(Index) =
To_Tcl_String(Source => "background") then
Options.Background := Options_Array(Index + 1);
elsif Options_Array(Index) = To_Tcl_String(Source => "readonly") then
Options.Readonly := Options_Array(Index + 1);
elsif Options_Array(Index) = To_Tcl_String(Source => "alternate") then
Options.Alternate := Options_Array(Index + 1);
elsif Options_Array(Index) = To_Tcl_String(Source => "invalid") then
Options.Invalid := Options_Array(Index + 1);
elsif Options_Array(Index) = To_Tcl_String(Source => "hover") then
Options.Hover := Options_Array(Index + 1);
end if;
Index := Index + 2;
end loop Set_Options_Loop;
return Options;
end Option_Value;
function Option_Value
(Ttk_Widgt: Ttk_Widget; Name: String) return Padding_Data is
Result_List: constant Array_List :=
Split_List
(List =>
Execute_Widget_Command
(Widgt => Ttk_Widgt, Command_Name => "cget",
Options => "-" & Name)
.Result,
Interpreter => Tk_Interp(Widgt => Ttk_Widgt));
begin
if Result_List'Length = 0 then
return Empty_Padding_Data;
end if;
return Padding: Padding_Data := Empty_Padding_Data do
Padding.Left :=
Pixel_Data_Value(Value => To_Ada_String(Source => Result_List(1)));
if Result_List'Length > 1 then
Padding.Top :=
Pixel_Data_Value
(Value => To_Ada_String(Source => Result_List(2)));
end if;
if Result_List'Length > 2 then
Padding.Right :=
Pixel_Data_Value
(Value => To_Ada_String(Source => Result_List(3)));
end if;
if Result_List'Length = 4 then
Padding.Bottom :=
Pixel_Data_Value
(Value => To_Ada_String(Source => Result_List(4)));
end if;
end return;
end Option_Value;
function In_State
(Ttk_Widgt: Ttk_Widget; State_Ttk: Ttk_State_Type) return Boolean is
begin
Execute_Widget_Command
(Widgt => Ttk_Widgt, Command_Name => "instate",
Options => To_Lower(Item => Ttk_State_Type'Image(State_Ttk)));
if Tcl_Get_Result(Interpreter => Tk_Interp(Widgt => Ttk_Widgt)) = 1 then
return True;
end if;
return False;
end In_State;
procedure In_State
(Ttk_Widgt: Ttk_Widget; State_Type: Ttk_State_Type;
Tcl_Script: Tcl_String) is
begin
Execute_Widget_Command
(Widgt => Ttk_Widgt, Command_Name => "instate",
Options =>
To_Lower(Item => Ttk_State_Type'Image(State_Type)) & " " &
To_String(Source => Tcl_Script));
end In_State;
procedure Set_State
(Ttk_Widgt: Ttk_Widget; Widget_State: Ttk_State_Type;
Disable: Boolean := False) is
begin
if Disable then
Execute_Widget_Command
(Widgt => Ttk_Widgt, Command_Name => "state",
Options =>
"!" & To_Lower(Item => Ttk_State_Type'Image(Widget_State)));
else
Execute_Widget_Command
(Widgt => Ttk_Widgt, Command_Name => "state",
Options => To_Lower(Item => Ttk_State_Type'Image(Widget_State)));
end if;
end Set_State;
function Get_States(Ttk_Widgt: Ttk_Widget) return Ttk_State_Array is
Result_List: constant Array_List :=
Split_List
(List =>
Execute_Widget_Command
(Widgt => Ttk_Widgt, Command_Name => "state")
.Result,
Interpreter => Tk_Interp(Widgt => Ttk_Widgt));
begin
return
States: Ttk_State_Array(1 .. Result_List'Last) :=
(others => Default_Ttk_State) do
Fill_Return_Value_Loop :
for I in 1 .. Result_List'Last loop
States(I) :=
Ttk_State_Type'Value(To_Ada_String(Source => Result_List(I)));
end loop Fill_Return_Value_Loop;
end return;
end Get_States;
end Tk.TtkWidget;
|
with Ada.Text_IO; use Ada.Text_IO;
with C3GA;
with GA_Utilities;
with Multivectors; use Multivectors;
procedure Line1 is
Point1 : constant Normalized_Point := C3GA.Set_Normalized_Point (0.0, 1.0, 0.0);
Point2 : constant Normalized_Point := C3GA.Set_Normalized_Point (1.0, 0.0, 0.0);
Point3 : constant Normalized_Point := C3GA.Set_Normalized_Point (-2.0, 0.0, 0.0);
Point4 : constant Normalized_Point := C3GA.Set_Normalized_Point (0.0, 0.0, 987.789);
Point5 : constant Normalized_Point := C3GA.Set_Normalized_Point (0.068, 1190.0, -10.567);
Line1 : constant Multivectors.Line := C3GA.Set_Line (Point1, Point2);
Line2 : constant Multivectors.Line := C3GA.Set_Line (Point2, Point3);
Line3 : constant Multivectors.Line := C3GA.Set_Line (Point4, Point5);
begin
GA_Utilities.Print_Multivector ("line 1", Line1);
GA_Utilities.Print_Multivector ("line 2", Line2);
GA_Utilities.Print_Multivector ("line 3", Line3);
Put_Line (Float'Image (5.77350E-01 ** 2 + 5.77350E-01 ** 2 + 5.77350E-01 ** 2));
end Line1;
|
------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- X R _ T A B L S --
-- --
-- S p e c --
-- --
-- Copyright (C) 1998-2014, 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. --
-- --
------------------------------------------------------------------------------
-- We need comment here saying what this package is???
with GNAT.OS_Lib;
package Xr_Tabls is
-------------------
-- Project files --
-------------------
function ALI_File_Name (Ada_File_Name : String) return String;
-- Returns the ali file name corresponding to Ada_File_Name
procedure Create_Project_File (Name : String);
-- Open and parse a new project file. If the file Name could not be
-- opened or is not a valid project file, then a project file associated
-- with the standard default directories is returned
function Next_Obj_Dir return String;
-- Returns the next directory to visit to find related ali files
-- If there are no more such directories, returns a null string.
function Current_Obj_Dir return String;
-- Returns the obj_dir which was returned by the last Next_Obj_Dir call
procedure Reset_Obj_Dir;
-- Reset the iterator for Obj_Dir
------------
-- Tables --
------------
type Declaration_Reference is private;
Empty_Declaration : constant Declaration_Reference;
type Declaration_Array is array (Natural range <>) of Declaration_Reference;
type Declaration_Array_Access is access Declaration_Array;
type File_Reference is private;
Empty_File : constant File_Reference;
type Reference is private;
Empty_Reference : constant Reference;
type Reference_Array is array (Natural range <>) of Reference;
type Reference_Array_Access is access Reference_Array;
procedure Free (Arr : in out Reference_Array_Access);
function Add_Declaration
(File_Ref : File_Reference;
Symbol : String;
Line : Natural;
Column : Natural;
Decl_Type : Character;
Is_Parameter : Boolean := False;
Remove_Only : Boolean := False;
Symbol_Match : Boolean := True)
return Declaration_Reference;
-- Add a new declaration in the table and return the index to it. Decl_Type
-- is the type of the entity Any previous instance of this entity in the
-- htable is removed. If Remove_Only is True, then any previous instance is
-- removed, but the new entity is never inserted. Symbol_Match should be
-- set to False if the name of the symbol doesn't match the pattern from
-- the command line. In that case, the entity will not be output by
-- gnatfind. If Symbol_Match is True, the entity will only be output if
-- the file name itself matches. Is_Parameter should be set to True if
-- the entity is known to be a subprogram parameter.
procedure Add_Parent
(Declaration : in out Declaration_Reference;
Symbol : String;
Line : Natural;
Column : Natural;
File_Ref : File_Reference);
-- The parent declaration (Symbol in file File_Ref at position Line and
-- Column) information is added to Declaration.
function Add_To_Xref_File
(File_Name : String;
Visited : Boolean := True;
Emit_Warning : Boolean := False;
Gnatchop_File : String := "";
Gnatchop_Offset : Integer := 0)
return File_Reference;
-- Add a new reference to a file in the table. Ref is used to return the
-- index in the table where this file is stored. Visited is the value which
-- will be used in the table (if True, the file will not be returned by
-- Next_Unvisited_File). If Emit_Warning is True and the ali file does
-- not exist or does not have cross-referencing information, then a
-- warning will be emitted. Gnatchop_File is the name of the file that
-- File_Name was extracted from through a call to "gnatchop -r" (using
-- pragma Source_Reference). Gnatchop_Offset should be the index of the
-- first line of File_Name within the Gnatchop_File.
procedure Add_Line
(File : File_Reference;
Line : Natural;
Column : Natural);
-- Add a new reference in a file, which the user has provided on the
-- command line. This is used for an optimized matching algorithm.
procedure Add_Reference
(Declaration : Declaration_Reference;
File_Ref : File_Reference;
Line : Natural;
Column : Natural;
Ref_Type : Character;
Labels_As_Ref : Boolean);
-- Add a new reference (Ref_Type = 'r'), body (Ref_Type = 'b') or
-- modification (Ref_Type = 'm') to an entity. If Labels_As_Ref is True,
-- then the references to the entity after the end statements ("end Foo")
-- are counted as actual references. This means that the entity will never
-- be reported as unreferenced (for instance in the case of gnatxref -u).
function Get_Declarations
(Sorted : Boolean := True)
return Declaration_Array_Access;
-- Return a sorted list of all the declarations in the application.
-- Freeing this array is the responsibility of the caller, however it
-- shouldn't free the actual contents of the array, which are pointers
-- to internal data
function References_Count
(Decl : Declaration_Reference;
Get_Reads : Boolean := False;
Get_Writes : Boolean := False;
Get_Bodies : Boolean := False)
return Natural;
-- Return the number of references in Decl for the categories specified
-- by the Get_* parameters (read-only accesses, write accesses and bodies)
function Get_References
(Decl : Declaration_Reference;
Get_Reads : Boolean := False;
Get_Writes : Boolean := False;
Get_Bodies : Boolean := False)
return Reference_Array_Access;
-- Return a sorted list of all references to the entity in decl. The
-- parameters Get_* are used to specify what kind of references should be
-- merged and returned (read-only accesses, write accesses and bodies).
function Get_Column (Decl : Declaration_Reference) return String;
function Get_Column (Ref : Reference) return String;
function Get_Declaration
(File_Ref : File_Reference;
Line : Natural;
Column : Natural)
return Declaration_Reference;
-- Returns reference to the declaration found in file File_Ref at the
-- given Line and Column
function Get_Parent
(Decl : Declaration_Reference)
return Declaration_Reference;
-- Returns reference to Decl's parent declaration
function Get_Emit_Warning (File : File_Reference) return Boolean;
-- Returns the Emit_Warning field of the structure
function Get_Gnatchop_File
(File : File_Reference;
With_Dir : Boolean := False)
return String;
function Get_Gnatchop_File
(Ref : Reference;
With_Dir : Boolean := False)
return String;
function Get_Gnatchop_File
(Decl : Declaration_Reference;
With_Dir : Boolean := False)
return String;
-- Return the name of the file that File was extracted from through a
-- call to "gnatchop -r". The file name for File is returned if File
-- was not extracted from such a file. The directory will be given only
-- if With_Dir is True.
function Get_File
(Decl : Declaration_Reference;
With_Dir : Boolean := False) return String;
pragma Inline (Get_File);
-- Extract column number or file name from reference
function Get_File
(Ref : Reference;
With_Dir : Boolean := False) return String;
pragma Inline (Get_File);
function Get_File
(File : File_Reference;
With_Dir : Boolean := False;
Strip : Natural := 0) return String;
-- Returns the file name (and its directory if With_Dir is True or the user
-- has used the -f switch on the command line. If Strip is not 0, then the
-- last Strip-th "-..." substrings are removed first. For instance, with
-- Strip=2, a file name "parent-child1-child2-child3.ali" would be returned
-- as "parent-child1.ali". This is used when looking for the ALI file to
-- use for a package, since for separates with have to use the parent's
-- ALI. The null string is returned if there is no such parent unit.
--
-- Note that this version of Get_File is not inlined
function Get_File_Ref (Ref : Reference) return File_Reference;
function Get_Line (Decl : Declaration_Reference) return String;
function Get_Line (Ref : Reference) return String;
function Get_Symbol (Decl : Declaration_Reference) return String;
function Get_Type (Decl : Declaration_Reference) return Character;
function Is_Parameter (Decl : Declaration_Reference) return Boolean;
-- Functions that return the contents of a declaration
function Get_Source_Line (Ref : Reference) return String;
function Get_Source_Line (Decl : Declaration_Reference) return String;
-- Return the source line associated with the reference
procedure Grep_Source_Files;
-- Parse all the source files which have at least one reference, and grep
-- the appropriate source lines so that we'll be able to display them. This
-- function should be called once all the .ali files have been parsed, and
-- only if the appropriate user switch
-- has been used (gnatfind -s).
--
-- Note: To save memory, the strings for the source lines are shared. Thus
-- it is no longer possible to free the references, or we would free the
-- same chunk multiple times. It doesn't matter, though, since this is only
-- called once, prior to exiting gnatfind.
function Longest_File_Name return Natural;
-- Returns the longest file name found
function Match (Decl : Declaration_Reference) return Boolean;
-- Return True if the declaration matches
function Match
(File : File_Reference;
Line : Natural;
Column : Natural)
return Boolean;
-- Returns True if File:Line:Column was given on the command line
-- by the user
function Next_Unvisited_File return File_Reference;
-- Returns the next unvisited library file in the list If there is no more
-- unvisited file, return Empty_File. Two calls to this subprogram will
-- return different files.
procedure Set_Default_Match (Value : Boolean);
-- Set the default value for match in declarations.
-- This is used so that if no file was provided in the
-- command line, then every file match
procedure Reset_Directory (File : File_Reference);
-- Reset the cached directory for file. Next time Get_File is called, the
-- directory will be recomputed.
procedure Set_Unvisited (File_Ref : File_Reference);
-- Set File_Ref as unvisited. So Next_Unvisited_File will return it
procedure Read_File
(File_Name : String;
Contents : out GNAT.OS_Lib.String_Access);
-- Reads File_Name into the newly allocated string Contents. Types.EOF
-- character will be added to the returned Contents to simplify parsing.
-- Name_Error is raised if the file was not found. End_Error is raised if
-- the file could not be read correctly. For most systems correct reading
-- means that the number of bytes read is equal to the file size.
private
type Project_File (Src_Dir_Length, Obj_Dir_Length : Natural) is record
Src_Dir : String (1 .. Src_Dir_Length);
Src_Dir_Index : Integer;
Obj_Dir : String (1 .. Obj_Dir_Length);
Obj_Dir_Index : Integer;
Last_Obj_Dir_Start : Natural;
end record;
type Project_File_Ptr is access all Project_File;
-- This is actually a list of all the directories to be searched,
-- either for source files or for library files
type Ref_In_File;
type Ref_In_File_Ptr is access all Ref_In_File;
type Ref_In_File is record
Line : Natural;
Column : Natural;
Next : Ref_In_File_Ptr := null;
end record;
type File_Record;
type File_Reference is access all File_Record;
Empty_File : constant File_Reference := null;
type Cst_String_Access is access constant String;
procedure Free (Str : in out Cst_String_Access);
type File_Record is record
File : Cst_String_Access;
Dir : GNAT.OS_Lib.String_Access;
Lines : Ref_In_File_Ptr := null;
Visited : Boolean := False;
Emit_Warning : Boolean := False;
Gnatchop_File : GNAT.OS_Lib.String_Access := null;
Gnatchop_Offset : Integer := 0;
Next : File_Reference := null;
end record;
-- Holds a reference to a source file, that was referenced in at least one
-- ALI file. Gnatchop_File will contain the name of the file that File was
-- extracted From. Gnatchop_Offset contains the index of the first line of
-- File within Gnatchop_File. These two fields are used to properly support
-- gnatchop files and pragma Source_Reference.
--
-- Lines is used for files that were given on the command line, to
-- memorize the lines and columns that the user specified.
type Reference_Record;
type Reference is access all Reference_Record;
Empty_Reference : constant Reference := null;
type Reference_Record is record
File : File_Reference;
Line : Natural;
Column : Natural;
Source_Line : Cst_String_Access;
Next : Reference := null;
end record;
-- File is a reference to the Ada source file
-- Source_Line is the Line as it appears in the source file. This
-- field is only used when the switch is set on the command line of
-- gnatfind.
type Declaration_Record;
type Declaration_Reference is access all Declaration_Record;
Empty_Declaration : constant Declaration_Reference := null;
type Declaration_Record (Symbol_Length : Natural) is record
Key : Cst_String_Access;
Symbol : String (1 .. Symbol_Length);
Decl : Reference;
Is_Parameter : Boolean := False; -- True if entity is subprog param
Decl_Type : Character;
Body_Ref : Reference := null;
Ref_Ref : Reference := null;
Modif_Ref : Reference := null;
Match : Boolean := False;
Par_Symbol : Declaration_Reference := null;
Next : Declaration_Reference := null;
end record;
-- The lists of referenced (Body_Ref, Ref_Ref and Modif_Ref) are
-- kept unsorted until the results needs to be printed. This saves
-- lots of time while the internal tables are created.
pragma Inline (Get_Column);
pragma Inline (Get_Emit_Warning);
pragma Inline (Get_File_Ref);
pragma Inline (Get_Line);
pragma Inline (Get_Symbol);
pragma Inline (Get_Type);
pragma Inline (Longest_File_Name);
end Xr_Tabls;
|
-- Copyright (c) 2020-2021 Bartek thindil Jasicki <thindil@laeran.pl>
--
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
with Ada.Strings.Fixed; use Ada.Strings.Fixed;
with Ada.Strings.UTF_Encoding.Wide_Strings;
use Ada.Strings.UTF_Encoding.Wide_Strings;
with Interfaces.C; use Interfaces.C;
with Interfaces.C.Strings; use Interfaces.C.Strings;
with CArgv; use CArgv;
with Tcl; use Tcl;
with Tcl.Ada; use Tcl.Ada;
with Tcl.Tk.Ada.Event; use Tcl.Tk.Ada.Event;
with Tcl.Tk.Ada.Grid;
with Tcl.Tk.Ada.Widgets; use Tcl.Tk.Ada.Widgets;
with Tcl.Tk.Ada.Widgets.Menu; use Tcl.Tk.Ada.Widgets.Menu;
with Tcl.Tk.Ada.Widgets.Text; use Tcl.Tk.Ada.Widgets.Text;
with Tcl.Tk.Ada.Widgets.Toplevel.MainWindow;
use Tcl.Tk.Ada.Widgets.Toplevel.MainWindow;
with Tcl.Tk.Ada.Widgets.TtkButton; use Tcl.Tk.Ada.Widgets.TtkButton;
with Tcl.Tk.Ada.Widgets.TtkFrame; use Tcl.Tk.Ada.Widgets.TtkFrame;
with Tcl.Tk.Ada.Widgets.TtkEntry.TtkSpinBox;
use Tcl.Tk.Ada.Widgets.TtkEntry.TtkSpinBox;
with Tcl.Tk.Ada.Widgets.TtkPanedWindow; use Tcl.Tk.Ada.Widgets.TtkPanedWindow;
with Tcl.Tk.Ada.Winfo; use Tcl.Tk.Ada.Winfo;
with Tcl.Tk.Ada.Wm; use Tcl.Tk.Ada.Wm;
with Bases; use Bases;
with Combat.UI; use Combat.UI;
with Config; use Config;
with CoreUI; use CoreUI;
with Crew; use Crew;
with Dialogs; use Dialogs;
with Factions; use Factions;
with Messages; use Messages;
with OrdersMenu; use OrdersMenu;
with Ships.Cargo; use Ships.Cargo;
with Ships.Crew; use Ships.Crew;
with Ships.Movement; use Ships.Movement;
with Statistics.UI; use Statistics.UI;
with Themes; use Themes;
with Utils.UI; use Utils.UI;
package body Maps.UI.Commands is
ButtonNames: constant array(1 .. 13) of Unbounded_String :=
(To_Unbounded_String("show"), To_Unbounded_String("nw"),
To_Unbounded_String("n"), To_Unbounded_String("ne"),
To_Unbounded_String("w"), To_Unbounded_String("wait"),
To_Unbounded_String("e"), To_Unbounded_String("sw"),
To_Unbounded_String("s"), To_Unbounded_String("se"),
To_Unbounded_String("hide"), To_Unbounded_String("left"),
To_Unbounded_String("right"));
-- ****o* MapCommands/MapCommands.Hide_Map_Buttons_Command
-- FUNCTION
-- Hide map movement buttons
-- PARAMETERS
-- ClientData - Custom data send to the command. Unused
-- Interp - Tcl interpreter in which command was executed.
-- Argc - Number of arguments passed to the command. Unused
-- Argv - Values of arguments passed to the command. Unused
-- RESULT
-- This function always return TCL_OK
-- COMMANDS
-- HideMapButtons
-- SOURCE
function Hide_Map_Buttons_Command
(ClientData: Integer; Interp: Tcl.Tcl_Interp; Argc: Interfaces.C.int;
Argv: CArgv.Chars_Ptr_Ptr) return Interfaces.C.int with
Convention => C;
-- ****
function Hide_Map_Buttons_Command
(ClientData: Integer; Interp: Tcl.Tcl_Interp; Argc: Interfaces.C.int;
Argv: CArgv.Chars_Ptr_Ptr) return Interfaces.C.int is
pragma Unreferenced(ClientData, Argc, Argv);
Button: Ttk_Button;
begin
Button.Interp := Interp;
Hide_Buttons_Loop :
for I in 2 .. 13 loop
Button.Name :=
New_String
(Main_Paned & ".mapframe.buttons." & To_String(ButtonNames(I)));
Tcl.Tk.Ada.Grid.Grid_Remove(Button);
end loop Hide_Buttons_Loop;
Button.Name := New_String(Main_Paned & ".mapframe.buttons.show");
Tcl.Tk.Ada.Grid.Grid(Button);
return TCL_OK;
end Hide_Map_Buttons_Command;
-- ****o* MapCommands/MapCommands.Show_Map_Buttons_Command
-- FUNCTION
-- Show map movement buttons
-- PARAMETERS
-- ClientData - Custom data send to the command. Unused
-- Interp - Tcl interpreter in which command was executed.
-- Argc - Number of arguments passed to the command. Unused
-- Argv - Values of arguments passed to the command. Unused
-- RESULT
-- This function always return TCL_OK
-- COMMANDS
-- ShowMapButtons
-- SOURCE
function Show_Map_Buttons_Command
(ClientData: Integer; Interp: Tcl.Tcl_Interp; Argc: Interfaces.C.int;
Argv: CArgv.Chars_Ptr_Ptr) return Interfaces.C.int with
Convention => C;
-- ****
function Show_Map_Buttons_Command
(ClientData: Integer; Interp: Tcl.Tcl_Interp; Argc: Interfaces.C.int;
Argv: CArgv.Chars_Ptr_Ptr) return Interfaces.C.int is
pragma Unreferenced(ClientData, Argc, Argv);
Button: Ttk_Button;
ButtonsBox: constant Ttk_Frame :=
Get_Widget(Main_Paned & ".mapframe.buttons", Interp);
begin
Button.Interp := Interp;
Show_Buttons_Loop :
for I in 2 .. 11 loop
Button.Name :=
New_String
(Widget_Image(ButtonsBox) & "." & To_String(ButtonNames(I)));
Tcl.Tk.Ada.Grid.Grid(Button);
end loop Show_Buttons_Loop;
Button.Name := New_String(Widget_Image(ButtonsBox) & ".show");
Tcl.Tk.Ada.Grid.Grid_Remove(Button);
Button.Name :=
(if Index(Tcl.Tk.Ada.Grid.Grid_Info(ButtonsBox), "-sticky es") = 0 then
New_String(Widget_Image(ButtonsBox) & ".right")
else New_String(Widget_Image(ButtonsBox) & ".left"));
Tcl.Tk.Ada.Grid.Grid(Button);
return TCL_OK;
end Show_Map_Buttons_Command;
-- ****o* MapCommands/MapCommands.Move_Map_Buttons_Command
-- FUNCTION
-- Move map movement buttons left of right
-- PARAMETERS
-- ClientData - Custom data send to the command. Unused
-- Interp - Tcl interpreter in which command was executed.
-- Argc - Number of arguments passed to the command. Unused
-- Argv - Values of arguments passed to the command.
-- RESULT
-- This function always return TCL_OK
-- COMMANDS
-- MoveMapButtons buttonname
-- Buttonname is the name of the button which was clicked
-- SOURCE
function Move_Map_Buttons_Command
(ClientData: Integer; Interp: Tcl.Tcl_Interp; Argc: Interfaces.C.int;
Argv: CArgv.Chars_Ptr_Ptr) return Interfaces.C.int with
Convention => C;
-- ****
function Move_Map_Buttons_Command
(ClientData: Integer; Interp: Tcl.Tcl_Interp; Argc: Interfaces.C.int;
Argv: CArgv.Chars_Ptr_Ptr) return Interfaces.C.int is
pragma Unreferenced(ClientData, Argc);
ButtonsBox: constant Ttk_Frame :=
Get_Widget(Main_Paned & ".mapframe.buttons", Interp);
Button: Ttk_Button :=
Get_Widget(ButtonsBox & "." & CArgv.Arg(Argv, 1), Interp);
begin
Tcl.Tk.Ada.Grid.Grid_Remove(Button);
if CArgv.Arg(Argv, 1) = "left" then
Button.Name := New_String(Widget_Image(ButtonsBox) & ".right");
Tcl.Tk.Ada.Grid.Grid_Configure(ButtonsBox, "-sticky sw");
else
Button.Name := New_String(Widget_Image(ButtonsBox) & ".left");
Tcl.Tk.Ada.Grid.Grid_Configure(ButtonsBox, "-sticky se");
end if;
Tcl.Tk.Ada.Grid.Grid(Button);
return TCL_OK;
end Move_Map_Buttons_Command;
-- ****o* MapCommands/MapCommands.Draw_Map_Command
-- FUNCTION
-- Draw the sky map
-- PARAMETERS
-- ClientData - Custom data send to the command. Unused
-- Interp - Tcl interpreter in which command was executed.
-- Argc - Number of arguments passed to the command. Unused
-- Argv - Values of arguments passed to the command. Unused
-- RESULT
-- This function always return TCL_OK
-- COMMANDS
-- DrawMap
-- SOURCE
function Draw_Map_Command
(ClientData: Integer; Interp: Tcl.Tcl_Interp; Argc: Interfaces.C.int;
Argv: CArgv.Chars_Ptr_Ptr) return Interfaces.C.int with
Convention => C;
-- ****
function Draw_Map_Command
(ClientData: Integer; Interp: Tcl.Tcl_Interp; Argc: Interfaces.C.int;
Argv: CArgv.Chars_Ptr_Ptr) return Interfaces.C.int is
pragma Unreferenced(ClientData, Argc, Argv);
MapView: constant Tk_Text :=
Get_Widget(Main_Paned & ".mapframe.map", Interp);
begin
configure
(MapView,
"-width [expr [winfo width $mapview] / [font measure MapFont {" &
Encode
("" &
Themes_List(To_String(Game_Settings.Interface_Theme))
.Empty_Map_Icon) &
"}]]");
configure
(MapView,
"-height [expr [winfo height $mapview] / [font metrics MapFont -linespace]]");
DrawMap;
return TCL_OK;
end Draw_Map_Command;
-- ****iv* MapCommands/MapCommands.MapX
-- FUNCTION
-- Current map cell X coordinate (where mouse is hovering)
-- SOURCE
MapX: Natural := 0;
-- ****
-- ****iv* MapCommands/MapCommands.MapY
-- FUNCTION
-- Current map cell Y coordinate (where mouse is hovering)
-- SOURCE
MapY: Natural := 0;
-- ****
-- ****o* MapCommands/MapCommands.Update_Map_Info_Command
-- FUNCTION
-- Update map cell info
-- PARAMETERS
-- ClientData - Custom data send to the command. Unused
-- Interp - Tcl interpreter in which command was executed.
-- Argc - Number of arguments passed to the command. Unused
-- Argv - Values of arguments passed to the command.
-- RESULT
-- This function always return TCL_OK
-- COMMANDS
-- UpdateMapInfo x y
-- X and Y are coordinates of the map cell which info will be show
-- SOURCE
function Update_Map_Info_Command
(ClientData: Integer; Interp: Tcl.Tcl_Interp; Argc: Interfaces.C.int;
Argv: CArgv.Chars_Ptr_Ptr) return Interfaces.C.int with
Convention => C;
-- ****
function Update_Map_Info_Command
(ClientData: Integer; Interp: Tcl.Tcl_Interp; Argc: Interfaces.C.int;
Argv: CArgv.Chars_Ptr_Ptr) return Interfaces.C.int is
pragma Unreferenced(ClientData, Argc);
MapView: constant Tk_Text :=
Get_Widget(Main_Paned & ".mapframe.map", Interp);
MapIndex: Unbounded_String;
begin
MapIndex :=
To_Unbounded_String
(Index
(MapView, "@" & CArgv.Arg(Argv, 1) & "," & CArgv.Arg(Argv, 2)));
if StartY + Integer'Value(Slice(MapIndex, 1, Index(MapIndex, ".") - 1)) -
1 <
1 then
return TCL_OK;
end if;
MapY :=
StartY + Integer'Value(Slice(MapIndex, 1, Index(MapIndex, ".") - 1)) -
1;
if MapY > 1_024 then
return TCL_OK;
end if;
if StartX +
Integer'Value
(Slice(MapIndex, Index(MapIndex, ".") + 1, Length(MapIndex))) <
1 then
return TCL_OK;
end if;
MapX :=
StartX +
Integer'Value
(Slice(MapIndex, Index(MapIndex, ".") + 1, Length(MapIndex)));
if MapX > 1_024 then
return TCL_OK;
end if;
UpdateMapInfo(MapX, MapY);
return TCL_OK;
end Update_Map_Info_Command;
-- ****o* MapCommands/MapCommands.Move_Map_Info_Command
-- FUNCTION
-- Move map info frame when mouse enter it
-- PARAMETERS
-- ClientData - Custom data send to the command. Unused
-- Interp - Tcl interpreter in which command was executed.
-- Argc - Number of arguments passed to the command. Unused
-- Argv - Values of arguments passed to the command. Unused
-- RESULT
-- This function always return TCL_OK
-- COMMANDS
-- MoveMapInfo
-- SOURCE
function Move_Map_Info_Command
(ClientData: Integer; Interp: Tcl.Tcl_Interp; Argc: Interfaces.C.int;
Argv: CArgv.Chars_Ptr_Ptr) return Interfaces.C.int with
Convention => C;
-- ****
function Move_Map_Info_Command
(ClientData: Integer; Interp: Tcl.Tcl_Interp; Argc: Interfaces.C.int;
Argv: CArgv.Chars_Ptr_Ptr) return Interfaces.C.int is
pragma Unreferenced(ClientData, Argc, Argv);
MapInfoFrame: constant Ttk_Frame :=
Get_Widget(Main_Paned & ".mapframe.info", Interp);
begin
Tcl.Tk.Ada.Grid.Grid_Configure
(MapInfoFrame,
"-sticky " &
(if Index(Tcl.Tk.Ada.Grid.Grid_Info(MapInfoFrame), "-sticky ne") = 0
then "ne"
else "wn"));
return TCL_OK;
end Move_Map_Info_Command;
-- ****o* MapCommands/MapCommands.Show_Destination_Menu_Command
-- FUNCTION
-- Create and show destination menu
-- PARAMETERS
-- ClientData - Custom data send to the command.
-- Interp - Tcl interpreter in which command was executed.
-- Argc - Number of arguments passed to the command.
-- Argv - Values of arguments passed to the command.
-- RESULT
-- This function always return TCL_OK
-- COMMANDS
-- ShowDestinationMenu x y
-- X and Y are mouse coordinates on which the destination menu will be show
-- SOURCE
function Show_Destination_Menu_Command
(ClientData: Integer; Interp: Tcl.Tcl_Interp; Argc: Interfaces.C.int;
Argv: CArgv.Chars_Ptr_Ptr) return Interfaces.C.int with
Convention => C;
-- ****
function Show_Destination_Menu_Command
(ClientData: Integer; Interp: Tcl.Tcl_Interp; Argc: Interfaces.C.int;
Argv: CArgv.Chars_Ptr_Ptr) return Interfaces.C.int is
DestinationMenu: constant Tk_Menu := Get_Widget(".destination", Interp);
begin
if (MapX = 0 or MapY = 0)
and then Update_Map_Info_Command(ClientData, Interp, Argc, Argv) /=
TCL_OK then
return TCL_ERROR;
end if;
if Player_Ship.Sky_X = MapX and Player_Ship.Sky_Y = MapY then
return Show_Orders_Command(ClientData, Interp, Argc, Argv);
end if;
Delete(DestinationMenu, "0", "end");
Add
(DestinationMenu, "command",
"-label {Set destination} -command SetDestination");
if Player_Ship.Speed /= DOCKED then
Add
(DestinationMenu, "command",
"-label {Set destination and move} -command {SetDestination;MoveShip moveto}");
if Player_Ship.Destination_X > 0 and
Player_Ship.Destination_Y > 0 then
Add
(DestinationMenu, "command",
"-label {Move to} -command {MoveShip moveto}");
end if;
end if;
Add(DestinationMenu, "command", "-label {Close}");
Tk_Popup
(DestinationMenu, Winfo_Get(Get_Main_Window(Interp), "pointerx"),
Winfo_Get(Get_Main_Window(Interp), "pointery"));
return TCL_OK;
end Show_Destination_Menu_Command;
-- ****o* MapCommands/MapCommands.Set_Ship_Destination_Command
-- FUNCTION
-- Set current map cell as destination for the player's ship
-- PARAMETERS
-- ClientData - Custom data send to the command. Unused
-- Interp - Tcl interpreter in which command was executed. Unused
-- Argc - Number of arguments passed to the command. Unused
-- Argv - Values of arguments passed to the command. Unused
-- RESULT
-- This function always return TCL_OK
-- COMMANDS
-- SetDestination
-- SOURCE
function Set_Ship_Destination_Command
(ClientData: Integer; Interp: Tcl.Tcl_Interp; Argc: Interfaces.C.int;
Argv: CArgv.Chars_Ptr_Ptr) return Interfaces.C.int with
Convention => C;
-- ****
function Set_Ship_Destination_Command
(ClientData: Integer; Interp: Tcl.Tcl_Interp; Argc: Interfaces.C.int;
Argv: CArgv.Chars_Ptr_Ptr) return Interfaces.C.int is
pragma Unreferenced(ClientData, Interp, Argc, Argv);
begin
Player_Ship.Destination_X := MapX;
Player_Ship.Destination_Y := MapY;
AddMessage
("You set the travel destination for your ship.", OrderMessage);
if Game_Settings.Auto_Center then
CenterX := Player_Ship.Sky_X;
CenterY := Player_Ship.Sky_Y;
end if;
DrawMap;
UpdateMoveButtons;
return TCL_OK;
end Set_Ship_Destination_Command;
-- ****o* MapCommands/MapCommands.Move_Map_Command
-- FUNCTION
-- Move map in the selected direction
-- PARAMETERS
-- ClientData - Custom data send to the command.
-- Interp - Tcl interpreter in which command was executed.
-- Argc - Number of arguments passed to the command. Unused
-- Argv - Values of arguments passed to the command.
-- RESULT
-- This function always return TCL_OK
-- COMMANDS
-- MoveMap direction
-- Direction in which the map will be moved
-- SOURCE
function Move_Map_Command
(ClientData: Integer; Interp: Tcl.Tcl_Interp; Argc: Interfaces.C.int;
Argv: CArgv.Chars_Ptr_Ptr) return Interfaces.C.int with
Convention => C;
-- ****
function Move_Map_Command
(ClientData: Integer; Interp: Tcl.Tcl_Interp; Argc: Interfaces.C.int;
Argv: CArgv.Chars_Ptr_Ptr) return Interfaces.C.int is
pragma Unreferenced(Argc);
MapView: constant Tk_Text :=
Get_Widget(Main_Paned & ".mapframe.map", Interp);
MapHeight, MapWidth: Positive;
DialogName: constant String := ".gameframe.movemapdialog";
SpinBox: Ttk_SpinBox := Get_Widget(DialogName & ".x", Interp);
begin
if Winfo_Get(MapView, "ismapped") = "0" then
return TCL_OK;
end if;
MapHeight := Positive'Value(cget(MapView, "-height"));
MapWidth := Positive'Value(cget(MapView, "-width"));
if CArgv.Arg(Argv, 1) = "centeronship" then
CenterX := Player_Ship.Sky_X;
CenterY := Player_Ship.Sky_Y;
elsif CArgv.Arg(Argv, 1) = "movemapto" then
CenterX := Positive'Value(Get(SpinBox));
SpinBox.Name := New_String(DialogName & ".y");
CenterY := Positive'Value(Get(SpinBox));
elsif CArgv.Arg(Argv, 1) = "n" then
CenterY :=
(if CenterY - (MapHeight / 3) < 1 then MapHeight / 3
else CenterY - (MapHeight / 3));
elsif CArgv.Arg(Argv, 1) = "s" then
CenterY :=
(if CenterY + (MapHeight / 3) > 1_024 then 1_024 - (MapHeight / 3)
else CenterY + (MapHeight / 3));
elsif CArgv.Arg(Argv, 1) = "w" then
CenterX :=
(if CenterX - (MapWidth / 3) < 1 then MapWidth / 3
else CenterX - (MapWidth / 3));
elsif CArgv.Arg(Argv, 1) = "e" then
CenterX :=
(if CenterX + (MapWidth / 3) > 1_024 then 1_024 - (MapWidth / 3)
else CenterX + (MapWidth / 3));
elsif CArgv.Arg(Argv, 1) = "nw" then
CenterY :=
(if CenterY - (MapHeight / 3) < 1 then MapHeight / 3
else CenterY - (MapHeight / 3));
CenterX :=
(if CenterX - (MapWidth / 3) < 1 then MapWidth / 3
else CenterX - (MapWidth / 3));
elsif CArgv.Arg(Argv, 1) = "ne" then
CenterY :=
(if CenterY - (MapHeight / 3) < 1 then MapHeight / 3
else CenterY - (MapHeight / 3));
CenterX :=
(if CenterX + (MapWidth / 3) > 1_024 then 1_024 - (MapWidth / 3)
else CenterX + (MapWidth / 3));
elsif CArgv.Arg(Argv, 1) = "sw" then
CenterY :=
(if CenterY + (MapHeight / 3) > 1_024 then 1_024 - (MapHeight / 3)
else CenterY + (MapHeight / 3));
CenterX :=
(if CenterX - (MapWidth / 3) < 1 then MapWidth / 3
else CenterX - (MapWidth / 3));
elsif CArgv.Arg(Argv, 1) = "se" then
CenterY :=
(if CenterY + (MapHeight / 3) > 1_024 then 1_024 - (MapHeight / 3)
else CenterY + (MapHeight / 3));
CenterX :=
(if CenterX + (MapWidth / 3) > 1_024 then 1_024 - (MapWidth / 3)
else CenterX + (MapWidth / 3));
elsif CArgv.Arg(Argv, 1) = "centeronhome" then
CenterX := Sky_Bases(Player_Ship.Home_Base).Sky_X;
CenterY := Sky_Bases(Player_Ship.Home_Base).Sky_Y;
end if;
DrawMap;
return
Close_Dialog_Command
(ClientData, Interp, 2, Empty & "CloseDialog" & DialogName);
end Move_Map_Command;
-- ****o* MapCommands/MapCommands.Zoom_Map_Command
-- FUNCTION
-- Zoom the sky map
-- PARAMETERS
-- ClientData - Custom data send to the command.
-- Interp - Tcl interpreter in which command was executed.
-- Argc - Number of arguments passed to the command.
-- Argv - Values of arguments passed to the command.
-- RESULT
-- This function always return TCL_OK
-- COMMANDS
-- ZoomMap
-- SOURCE
function Zoom_Map_Command
(ClientData: Integer; Interp: Tcl.Tcl_Interp; Argc: Interfaces.C.int;
Argv: CArgv.Chars_Ptr_Ptr) return Interfaces.C.int with
Convention => C;
-- ****
function Zoom_Map_Command
(ClientData: Integer; Interp: Tcl.Tcl_Interp; Argc: Interfaces.C.int;
Argv: CArgv.Chars_Ptr_Ptr) return Interfaces.C.int is
begin
Game_Settings.Map_Font_Size :=
(if CArgv.Arg(Argv, 1) = "raise" then Game_Settings.Map_Font_Size + 1
else Game_Settings.Map_Font_Size - 1);
if Game_Settings.Map_Font_Size < 3 then
Game_Settings.Map_Font_Size := 3;
elsif Game_Settings.Map_Font_Size > 50 then
Game_Settings.Map_Font_Size := 50;
end if;
Tcl_Eval
(Interp,
"font configure MapFont -size" &
Positive'Image(Game_Settings.Map_Font_Size));
return Draw_Map_Command(ClientData, Interp, Argc, Argv);
end Zoom_Map_Command;
-- ****o* MapCommands/MapCommands.Move_Command
-- FUNCTION
-- Move the player ship in the selected location and check what happens
-- PARAMETERS
-- ClientData - Custom data send to the command. Unused
-- Interp - Tcl interpreter in which command was executed.
-- Argc - Number of arguments passed to the command. Unused
-- Argv - Values of arguments passed to the command.
-- RESULT
-- This function always return TCL_OK
-- COMMANDS
-- MoveShip direction
-- Direction in which the player's ship will be moved
-- SOURCE
function Move_Ship_Command
(ClientData: Integer; Interp: Tcl.Tcl_Interp; Argc: Interfaces.C.int;
Argv: CArgv.Chars_Ptr_Ptr) return Interfaces.C.int with
Convention => C;
-- ****
function Move_Ship_Command
(ClientData: Integer; Interp: Tcl.Tcl_Interp; Argc: Interfaces.C.int;
Argv: CArgv.Chars_Ptr_Ptr) return Interfaces.C.int is
pragma Unreferenced(ClientData, Argc);
Message: Unbounded_String;
Result: Natural;
StartsCombat: Boolean := False;
NewX, NewY: Integer := 0;
procedure Update_Coordinates is
begin
if Player_Ship.Destination_X > Player_Ship.Sky_X then
NewX := 1;
elsif Player_Ship.Destination_X < Player_Ship.Sky_X then
NewX := -1;
end if;
if Player_Ship.Destination_Y > Player_Ship.Sky_Y then
NewY := 1;
elsif Player_Ship.Destination_Y < Player_Ship.Sky_Y then
NewY := -1;
end if;
end Update_Coordinates;
begin
if CArgv.Arg(Argv, 1) = "n" then -- Move up
Result := MoveShip(0, -1, Message);
elsif CArgv.Arg(Argv, 1) = "s" then -- Move down
Result := MoveShip(0, 1, Message);
elsif CArgv.Arg(Argv, 1) = "e" then -- Move right
Result := MoveShip(1, 0, Message);
elsif CArgv.Arg(Argv, 1) = "w" then -- Move left
Result := MoveShip(-1, 0, Message);
elsif CArgv.Arg(Argv, 1) = "sw" then -- Move down/left
Result := MoveShip(-1, 1, Message);
elsif CArgv.Arg(Argv, 1) = "se" then -- Move down/right
Result := MoveShip(1, 1, Message);
elsif CArgv.Arg(Argv, 1) = "nw" then -- Move up/left
Result := MoveShip(-1, -1, Message);
elsif CArgv.Arg(Argv, 1) = "ne" then -- Move up/right
Result := MoveShip(1, -1, Message);
elsif CArgv.Arg(Argv, 1) =
"waitormove" then -- Move to destination or wait 1 game minute
if Player_Ship.Destination_X = 0 and
Player_Ship.Destination_Y = 0 then
Result := 1;
Update_Game(1);
WaitInPlace(1);
else
Update_Coordinates;
Result := MoveShip(NewX, NewY, Message);
if Player_Ship.Destination_X = Player_Ship.Sky_X and
Player_Ship.Destination_Y = Player_Ship.Sky_Y then
AddMessage
("You reached your travel destination.", OrderMessage);
Player_Ship.Destination_X := 0;
Player_Ship.Destination_Y := 0;
if Game_Settings.Auto_Finish then
Message := To_Unbounded_String(AutoFinishMissions);
end if;
Result := 4;
end if;
end if;
elsif CArgv.Arg(Argv, 1) = "moveto" then -- Move to destination
Move_Loop :
loop
NewX := 0;
NewY := 0;
Update_Coordinates;
Result := MoveShip(NewX, NewY, Message);
exit Move_Loop when Result = 0;
StartsCombat := CheckForEvent;
if StartsCombat then
Result := 4;
exit Move_Loop;
end if;
if Result = 8 then
WaitForRest;
if not Factions_List(Player_Ship.Crew(1).Faction).Flags.Contains
(To_Unbounded_String("sentientships"))
and then
(FindMember(Pilot) = 0 or FindMember(Engineer) = 0) then
WaitForRest;
end if;
Result := 1;
StartsCombat := CheckForEvent;
if StartsCombat then
Result := 4;
exit Move_Loop;
end if;
end if;
if Game_Settings.Auto_Move_Stop /= NEVER and
SkyMap(Player_Ship.Sky_X, Player_Ship.Sky_Y).EventIndex > 0 then
declare
EventIndex: constant Positive :=
SkyMap(Player_Ship.Sky_X, Player_Ship.Sky_Y).EventIndex;
begin
case Game_Settings.Auto_Move_Stop is
when ANY =>
if Events_List(EventIndex).EType in EnemyShip |
Trader | FriendlyShip | EnemyPatrol then
Result := 0;
exit Move_Loop;
end if;
when FRIENDLY =>
if Events_List(EventIndex).EType in Trader |
FriendlyShip then
Result := 0;
exit Move_Loop;
end if;
when Config.ENEMY =>
if Events_List(EventIndex).EType in EnemyShip |
EnemyPatrol then
Result := 0;
exit Move_Loop;
end if;
when NEVER =>
null;
end case;
end;
end if;
declare
MessageDialog: constant Ttk_Frame :=
Get_Widget(".message", Interp);
begin
if Winfo_Get(MessageDialog, "exists") = "0" then
if GetItemAmount(Fuel_Type) <= Game_Settings.Low_Fuel then
ShowMessage
(Text => "Your fuel level is dangerously low.",
Title => "Low fuel level");
Result := 4;
exit Move_Loop;
elsif GetItemsAmount("Food") <= Game_Settings.Low_Food then
ShowMessage
(Text => "Your food level is dangerously low.",
Title => "Low amount of food");
Result := 4;
exit Move_Loop;
elsif GetItemsAmount("Drinks") <=
Game_Settings.Low_Drinks then
ShowMessage
(Text => "Your drinks level is dangerously low.",
Title => "Low level of drinks");
Result := 4;
exit Move_Loop;
end if;
end if;
end;
if Player_Ship.Destination_X = Player_Ship.Sky_X and
Player_Ship.Destination_Y = Player_Ship.Sky_Y then
AddMessage
("You reached your travel destination.", OrderMessage);
Player_Ship.Destination_X := 0;
Player_Ship.Destination_Y := 0;
if Game_Settings.Auto_Finish then
Message := To_Unbounded_String(AutoFinishMissions);
end if;
Result := 4;
exit Move_Loop;
end if;
exit Move_Loop when Result = 6 or Result = 7;
end loop Move_Loop;
end if;
case Result is
when 1 => -- Ship moved, check for events
StartsCombat := CheckForEvent;
if not StartsCombat and Game_Settings.Auto_Finish then
Message := To_Unbounded_String(AutoFinishMissions);
end if;
when 6 => -- Ship moved, but pilot needs rest, confirm
ShowQuestion
("You don't have pilot on duty. Do you want to wait until your pilot rest?",
"nopilot");
return TCL_OK;
when 7 => -- Ship moved, but engineer needs rest, confirm
ShowQuestion
("You don't have engineer on duty. Do you want to wait until your engineer rest?",
"nopilot");
return TCL_OK;
when 8 => -- Ship moved, but crew needs rest, autorest
StartsCombat := CheckForEvent;
if not StartsCombat then
WaitForRest;
if not Factions_List(Player_Ship.Crew(1).Faction).Flags.Contains
(To_Unbounded_String("sentientships"))
and then
(FindMember(Pilot) = 0 or FindMember(Engineer) = 0) then
WaitForRest;
end if;
StartsCombat := CheckForEvent;
end if;
if not StartsCombat and Game_Settings.Auto_Finish then
Message := To_Unbounded_String(AutoFinishMissions);
end if;
when others =>
null;
end case;
if Message /= Null_Unbounded_String then
ShowMessage(Text => To_String(Message), Title => "Message");
end if;
CenterX := Player_Ship.Sky_X;
CenterY := Player_Ship.Sky_Y;
if StartsCombat then
ShowCombatUI;
else
ShowSkyMap;
end if;
return TCL_OK;
end Move_Ship_Command;
-- ****o* MapCommands/MapCommands.Quit_Game_Command
-- FUNCTION
-- Ask player if he/she wants to quit from the game and if yes, save it and
-- show main menu
-- PARAMETERS
-- ClientData - Custom data send to the command. Unused
-- Interp - Tcl interpreter in which command was executed. Unused
-- Argc - Number of arguments passed to the command. Unused
-- Argv - Values of arguments passed to the command. Unused
-- RESULT
-- This function always return TCL_OK
-- COMMANDS
-- QuitGame
-- SOURCE
function Quit_Game_Command
(ClientData: Integer; Interp: Tcl.Tcl_Interp; Argc: Interfaces.C.int;
Argv: CArgv.Chars_Ptr_Ptr) return Interfaces.C.int with
Convention => C;
-- ****
function Quit_Game_Command
(ClientData: Integer; Interp: Tcl.Tcl_Interp; Argc: Interfaces.C.int;
Argv: CArgv.Chars_Ptr_Ptr) return Interfaces.C.int is
pragma Unreferenced(ClientData, Interp, Argc, Argv);
begin
ShowQuestion("Are you sure want to quit?", "quit");
return TCL_OK;
end Quit_Game_Command;
-- ****o* MapCommands/MapCommands.Resign_Game_Command
-- FUNCTION
-- Resing from the game - if player resigned, kill he/she character and
-- follow as for death of the player's character
-- PARAMETERS
-- ClientData - Custom data send to the command. Unused
-- Interp - Tcl interpreter in which command was executed. Unused
-- Argc - Number of arguments passed to the command. Unused
-- Argv - Values of arguments passed to the command. Unused
-- RESULT
-- This function always return TCL_OK
-- COMMANDS
-- ResignGame
-- SOURCE
function Resign_Game_Command
(ClientData: Integer; Interp: Tcl.Tcl_Interp; Argc: Interfaces.C.int;
Argv: CArgv.Chars_Ptr_Ptr) return Interfaces.C.int with
Convention => C;
-- ****
function Resign_Game_Command
(ClientData: Integer; Interp: Tcl.Tcl_Interp; Argc: Interfaces.C.int;
Argv: CArgv.Chars_Ptr_Ptr) return Interfaces.C.int is
pragma Unreferenced(ClientData, Interp, Argc, Argv);
begin
ShowQuestion("Are you sure want to resign from game?", "resign");
return TCL_OK;
end Resign_Game_Command;
-- ****o* MapCommands/MapCommands.Show_Stats_Command
-- FUNCTION
-- Show the player's game statistics
-- PARAMETERS
-- ClientData - Custom data send to the command. Unused
-- Interp - Tcl interpreter in which command was executed. Unused
-- Argc - Number of arguments passed to the command. Unused
-- Argv - Values of arguments passed to the command. Unused
-- RESULT
-- This function always return TCL_OK
-- COMMANDS
-- ShowStats
-- SOURCE
function Show_Stats_Command
(ClientData: Integer; Interp: Tcl.Tcl_Interp; Argc: Interfaces.C.int;
Argv: CArgv.Chars_Ptr_Ptr) return Interfaces.C.int with
Convention => C;
-- ****
function Show_Stats_Command
(ClientData: Integer; Interp: Tcl.Tcl_Interp; Argc: Interfaces.C.int;
Argv: CArgv.Chars_Ptr_Ptr) return Interfaces.C.int is
pragma Unreferenced(ClientData, Interp, Argc, Argv);
begin
Tcl.Tk.Ada.Grid.Grid(Close_Button, "-row 0 -column 1");
ShowStatistics;
return TCL_OK;
end Show_Stats_Command;
-- ****o* MapCommands/MapCommands.Show_Sky_Map_Command
-- FUNCTION
-- Show sky map
-- PARAMETERS
-- ClientData - Custom data send to the command. Unused
-- Interp - Tcl interpreter in which command was executed. Unused
-- Argc - Number of arguments passed to the command. Unused
-- Argv - Values of arguments passed to the command. Unused
-- RESULT
-- This function always return TCL_OK
-- COMMANDS
-- ShowSkyMap ?previouscommand?
-- Previouscommand is command to show previous screen. Some screens require
-- to do special actions when closing them
-- SOURCE
function Show_Sky_Map_Command
(ClientData: Integer; Interp: Tcl.Tcl_Interp; Argc: Interfaces.C.int;
Argv: CArgv.Chars_Ptr_Ptr) return Interfaces.C.int with
Convention => C;
-- ****
function Show_Sky_Map_Command
(ClientData: Integer; Interp: Tcl.Tcl_Interp; Argc: Interfaces.C.int;
Argv: CArgv.Chars_Ptr_Ptr) return Interfaces.C.int is
pragma Unreferenced(ClientData);
begin
if Argc = 1 then
Tcl.Tk.Ada.Grid.Grid_Remove(Close_Button);
ShowSkyMap(True);
else
Tcl_Eval(Interp, CArgv.Arg(Argv, 1));
end if;
Focus(Get_Main_Window(Interp));
return TCL_OK;
end Show_Sky_Map_Command;
-- ****o* MapCommands/MapCommands.Move_Mouse_Command
-- FUNCTION
-- Move mouse cursor with keyboard
-- PARAMETERS
-- ClientData - Custom data send to the command. Unused
-- Interp - Tcl interpreter in which command was executed.
-- Argc - Number of arguments passed to the command. Unused
-- Argv - Values of arguments passed to the command.
-- RESULT
-- This function always return TCL_OK
-- COMMANDS
-- MoveCursor direction
-- Direction is the direction in which the mouse cursor should be moves or
-- click if emulate clicking with the left or right button
-- SOURCE
function Move_Mouse_Command
(ClientData: Integer; Interp: Tcl.Tcl_Interp; Argc: Interfaces.C.int;
Argv: CArgv.Chars_Ptr_Ptr) return Interfaces.C.int with
Convention => C;
-- ****
function Move_Mouse_Command
(ClientData: Integer; Interp: Tcl.Tcl_Interp; Argc: Interfaces.C.int;
Argv: CArgv.Chars_Ptr_Ptr) return Interfaces.C.int is
pragma Unreferenced(ClientData, Argc);
MapView: constant Tk_Text :=
Get_Widget(Main_Paned & ".mapframe.map", Interp);
begin
if Focus /= Widget_Image(MapView) then
Focus(MapView, "-force");
return TCL_OK;
end if;
if CArgv.Arg(Argv, 1) = "click" then
Generate
(MapView,
"<Button-" & (if Game_Settings.Right_Button then "3" else "1") &
">",
"-x " & CArgv.Arg(Argv, 2) & " -y " & CArgv.Arg(Argv, 3));
elsif CArgv.Arg(Argv, 1) = "nw" then
Generate
(MapView, "<Motion>",
"-warp 1 -x [expr " & CArgv.Arg(Argv, 2) & "-5] -y [expr " &
CArgv.Arg(Argv, 3) & "-5]");
elsif CArgv.Arg(Argv, 1) = "n" then
Generate
(MapView, "<Motion>",
"-warp 1 -x " & CArgv.Arg(Argv, 2) & " -y [expr " &
CArgv.Arg(Argv, 3) & "-5]");
elsif CArgv.Arg(Argv, 1) = "ne" then
Generate
(MapView, "<Motion>",
"-warp 1 -x [expr " & CArgv.Arg(Argv, 2) & "+5] -y [expr " &
CArgv.Arg(Argv, 3) & "-5]");
elsif CArgv.Arg(Argv, 1) = "w" then
Generate
(MapView, "<Motion>",
"-warp 1 -x [expr " & CArgv.Arg(Argv, 2) & "-5] -y " &
CArgv.Arg(Argv, 3));
elsif CArgv.Arg(Argv, 1) = "e" then
Generate
(MapView, "<Motion>",
"-warp 1 -x [expr " & CArgv.Arg(Argv, 2) & "+5] -y " &
CArgv.Arg(Argv, 3));
elsif CArgv.Arg(Argv, 1) = "sw" then
Generate
(MapView, "<Motion>",
"-warp 1 -x [expr " & CArgv.Arg(Argv, 2) & "-5] -y [expr " &
CArgv.Arg(Argv, 3) & "+5]");
elsif CArgv.Arg(Argv, 1) = "s" then
Generate
(MapView, "<Motion>",
"-warp 1 -x " & CArgv.Arg(Argv, 2) & " -y [expr " &
CArgv.Arg(Argv, 3) & "+5]");
elsif CArgv.Arg(Argv, 1) = "se" then
Generate
(MapView, "<Motion>",
"-warp 1 -x [expr " & CArgv.Arg(Argv, 2) & "+5] -y [expr " &
CArgv.Arg(Argv, 3) & "+5]");
end if;
return TCL_OK;
end Move_Mouse_Command;
-- ****o* MapCommands/MapCommands.Toggle_Full_Screen_Command
-- FUNCTION
-- Toggle the game full screen mode
-- PARAMETERS
-- ClientData - Custom data send to the command. Unused
-- Interp - Tcl interpreter in which command was executed.
-- Argc - Number of arguments passed to the command. Unused
-- Argv - Values of arguments passed to the command. Unused
-- RESULT
-- This function always return TCL_OK
-- COMMANDS
-- ToggleFullScreen
-- SOURCE
function Toggle_Full_Screen_Command
(ClientData: Integer; Interp: Tcl.Tcl_Interp; Argc: Interfaces.C.int;
Argv: CArgv.Chars_Ptr_Ptr) return Interfaces.C.int with
Convention => C;
-- ****
function Toggle_Full_Screen_Command
(ClientData: Integer; Interp: Tcl.Tcl_Interp; Argc: Interfaces.C.int;
Argv: CArgv.Chars_Ptr_Ptr) return Interfaces.C.int is
pragma Unreferenced(ClientData, Argc, Argv);
begin
Tcl_Eval(Interp, "wm attributes . -fullscreen");
if Tcl_GetResult(Interp) = "0" then
Wm_Set(Get_Main_Window(Interp), "attributes", "-fullscreen 1");
Game_Settings.Full_Screen := True;
else
Wm_Set(Get_Main_Window(Interp), "attributes", "-fullscreen 0");
Game_Settings.Full_Screen := False;
end if;
return TCL_OK;
end Toggle_Full_Screen_Command;
-- ****o* MapCommands/MapCommands.Resize_Last_Messages_Command
-- FUNCTION
-- Resize the last messages window
-- PARAMETERS
-- ClientData - Custom data send to the command. Unused
-- Interp - Tcl interpreter in which command was executed.
-- Argc - Number of arguments passed to the command. Unused
-- Argv - Values of arguments passed to the command. Unused
-- RESULT
-- This function always return TCL_OK
-- COMMANDS
-- ResizeLastMessages
-- SOURCE
function Resize_Last_Messages_Command
(ClientData: Integer; Interp: Tcl.Tcl_Interp; Argc: Interfaces.C.int;
Argv: CArgv.Chars_Ptr_Ptr) return Interfaces.C.int with
Convention => C;
-- ****
function Resize_Last_Messages_Command
(ClientData: Integer; Interp: Tcl.Tcl_Interp; Argc: Interfaces.C.int;
Argv: CArgv.Chars_Ptr_Ptr) return Interfaces.C.int is
pragma Unreferenced(ClientData, Argc, Argv);
PanedPosition: Positive;
SashPosition: constant Natural :=
Natural'Value(SashPos(Main_Paned, "0"));
begin
Game_Settings.Window_Width :=
Positive'Value(Winfo_Get(Get_Main_Window(Interp), "width"));
Game_Settings.Window_Height :=
Positive'Value(Winfo_Get(Get_Main_Window(Interp), "height"));
PanedPosition :=
(if Game_Settings.Window_Height - Game_Settings.Messages_Position < 0
then Game_Settings.Window_Height
else Game_Settings.Window_Height - Game_Settings.Messages_Position);
if SashPosition > 0 and then SashPosition /= PanedPosition then
if Game_Settings.Window_Height - SashPosition > -1 then
Game_Settings.Messages_Position :=
Game_Settings.Window_Height - SashPosition;
end if;
PanedPosition := SashPosition;
end if;
return TCL_OK;
end Resize_Last_Messages_Command;
procedure AddCommands is
begin
Add_Command("HideMapButtons", Hide_Map_Buttons_Command'Access);
Add_Command("ShowMapButtons", Show_Map_Buttons_Command'Access);
Add_Command("MoveMapButtons", Move_Map_Buttons_Command'Access);
Add_Command("DrawMap", Draw_Map_Command'Access);
Add_Command("UpdateMapInfo", Update_Map_Info_Command'Access);
Add_Command("MoveMapInfo", Move_Map_Info_Command'Access);
Add_Command("ShowDestinationMenu", Show_Destination_Menu_Command'Access);
Add_Command("SetDestination", Set_Ship_Destination_Command'Access);
Add_Command("MoveMap", Move_Map_Command'Access);
Add_Command("ZoomMap", Zoom_Map_Command'Access);
Add_Command("MoveShip", Move_Ship_Command'Access);
Add_Command("QuitGame", Quit_Game_Command'Access);
Add_Command("ResignGame", Resign_Game_Command'Access);
Add_Command("ShowStats", Show_Stats_Command'Access);
Add_Command("ShowSkyMap", Show_Sky_Map_Command'Access);
Add_Command("MoveCursor", Move_Mouse_Command'Access);
Add_Command("ToggleFullScreen", Toggle_Full_Screen_Command'Access);
Add_Command("ResizeLastMessages", Resize_Last_Messages_Command'Access);
end AddCommands;
end Maps.UI.Commands;
|
generic
type Output_Stream (<>) is limited private;
-- Stream of bytes
with procedure Put (Stream : in out Output_Stream; Bytes : String) is <>;
-- Write all Bytes in Stream
procedure TOML.Generic_Dump
(Stream : in out Output_Stream;
Value : TOML_Value)
with Preelaborate, Pre => Value.Kind = TOML_Table;
-- Turn the given Value into a valid TOML document and write it to Stream
|
------------------------------------------------------------------------------
-- --
-- GNAT RUN-TIME LIBRARY (GNARL) COMPONENTS --
-- --
-- S Y S T E M . O S _ I N T E R F A C E --
-- --
-- S p e c --
-- --
-- Copyright (C) 1991-1994, Florida State University --
-- Copyright (C) 1995-2016, Free Software Foundation, Inc. --
-- --
-- GNARL is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. GNARL is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. --
-- --
-- --
-- --
-- --
-- --
-- You should have received a copy of the GNU General Public License and --
-- a copy of the GCC Runtime Library Exception along with this program; --
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
-- <http://www.gnu.org/licenses/>. --
-- --
-- GNARL was developed by the GNARL team at Florida State University. --
-- Extensive contributions were provided by Ada Core Technologies, Inc. --
-- --
------------------------------------------------------------------------------
-- Ravenscar version of this package for bare board targets
-- This package encapsulates all direct interfaces to OS services that are
-- needed by the tasking run-time (libgnarl).
pragma Restrictions (No_Elaboration_Code);
-- This could use a comment, why is it here???
with System.Multiprocessors;
with System.Storage_Elements;
with System.BB.Threads.Queues;
with System.BB.Time;
with System.BB.Interrupts;
with System.BB.Board_Support;
with System.BB.Parameters;
with System.BB.CPU_Primitives.Multiprocessors;
package System.OS_Interface with SPARK_Mode => Off is
pragma Preelaborate;
----------------
-- Interrupts --
----------------
Max_Interrupt : constant := System.BB.Interrupts.Max_Interrupt;
-- Number of asynchronous interrupts
subtype Interrupt_ID is System.BB.Interrupts.Interrupt_ID;
-- Interrupt identifiers
No_Interrupt : constant Interrupt_ID := System.BB.Interrupts.No_Interrupt;
-- Special value indicating no interrupt
subtype Interrupt_Handler is System.BB.Interrupts.Interrupt_Handler;
-- Interrupt handlers
--------------------------
-- Interrupt processing --
--------------------------
function Current_Interrupt return Interrupt_ID
renames System.BB.Interrupts.Current_Interrupt;
-- Function that returns the hardware interrupt currently being
-- handled (if any). In case no hardware interrupt is being handled
-- the returned value is No_Interrupt.
procedure Attach_Handler
(Handler : Interrupt_Handler;
Id : Interrupt_ID;
PO_Prio : Interrupt_Priority)
renames System.BB.Interrupts.Attach_Handler;
-- Attach a handler to a hardware interrupt
procedure Power_Down renames System.BB.Board_Support.Power_Down;
-- Put current CPU in power-down mode
----------
-- Time --
----------
subtype Time is System.BB.Time.Time;
-- Representation of the time in the underlying tasking system
subtype Time_Span is System.BB.Time.Time_Span;
-- Represents the length of time intervals in the underlying tasking
-- system.
Ticks_Per_Second : constant := System.BB.Parameters.Ticks_Per_Second;
-- Number of clock ticks per second
function Clock return Time renames System.BB.Time.Clock;
-- Get the number of ticks elapsed since startup
procedure Delay_Until (T : Time) renames System.BB.Time.Delay_Until;
-- Suspend the calling task until the absolute time specified by T
-------------
-- Threads --
-------------
subtype Thread_Descriptor is System.BB.Threads.Thread_Descriptor;
-- Type that contains the information about a thread (registers,
-- priority, etc.).
subtype Thread_Id is System.BB.Threads.Thread_Id;
-- Identifiers for the underlying threads
Null_Thread_Id : constant Thread_Id :=
System.BB.Threads.Null_Thread_Id;
-- Identifier for a non valid thread
Lwp_Self : constant System.Address := Null_Address;
-- LWP is not used by gdb on ravenscar
procedure Initialize
(Environment_Thread : Thread_Id;
Main_Priority : System.Any_Priority)
renames System.BB.Threads.Initialize;
-- Procedure for initializing the underlying tasking system
procedure Initialize_Slave
(Idle_Thread : Thread_Id;
Idle_Priority : Integer;
Stack_Address : System.Address;
Stack_Size : System.Storage_Elements.Storage_Offset)
renames System.BB.Threads.Initialize_Slave;
-- Procedure to initialize the idle thread
procedure Thread_Create
(Id : Thread_Id;
Code : System.Address;
Arg : System.Address;
Priority : Integer;
Base_CPU : System.Multiprocessors.CPU_Range;
Stack_Address : System.Address;
Stack_Size : System.Storage_Elements.Storage_Offset)
renames System.BB.Threads.Thread_Create;
-- Create a new thread
function Thread_Self return Thread_Id renames System.BB.Threads.Thread_Self;
-- Return the thread identifier for the calling task
----------
-- ATCB --
----------
procedure Set_ATCB (Id : Thread_Id; ATCB : System.Address)
renames System.BB.Threads.Set_ATCB;
-- Associate the specified ATCB to the thread ID
function Get_ATCB return System.Address renames System.BB.Threads.Get_ATCB;
-- Get the ATCB associated to the currently running thread
----------------
-- Scheduling --
----------------
procedure Set_Priority (Priority : Integer)
renames System.BB.Threads.Set_Priority;
-- Set the active priority of the executing thread to the given value
function Get_Priority (Id : Thread_Id) return Integer
renames System.BB.Threads.Get_Priority;
-- Get the current base priority of a thread
procedure Sleep renames System.BB.Threads.Sleep;
-- The calling thread is unconditionally suspended
procedure Wakeup (Id : Thread_Id) renames System.BB.Threads.Wakeup;
-- The referred thread becomes ready (the thread must be suspended)
---------------------
-- Multiprocessors --
---------------------
function Get_Affinity (Id : Thread_Id) return Multiprocessors.CPU_Range
renames System.BB.Threads.Get_Affinity;
-- Return CPU affinity of the given thread (maybe Not_A_Specific_CPU)
function Get_CPU (Id : Thread_Id) return Multiprocessors.CPU
renames System.BB.Threads.Get_CPU;
-- Return the CPU in charge of the given thread (always a valid CPU)
function Current_Priority
(CPU_Id : Multiprocessors.CPU) return System.Any_Priority
renames System.BB.Threads.Queues.Current_Priority;
-- Return the active priority of the current thread or
-- System.Any_Priority'First if no threads are running.
function Current_CPU return Multiprocessors.CPU
renames System.BB.CPU_Primitives.Multiprocessors.Current_CPU;
-- Return the id of the current CPU
end System.OS_Interface;
|
-----------------------------------------------------------------------
-- gen-integration-tests -- Tests for integration
-- Copyright (C) 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2020 Stephane Carrez
-- Written by Stephane Carrez (Stephane.Carrez@gmail.com)
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-----------------------------------------------------------------------
with Ada.Directories;
with Ada.Text_IO;
with Util.Log.Loggers;
with Util.Test_Caller;
with Util.Streams.Pipes;
with Util.Streams.Buffered;
with Util.Processes;
with Util.Files;
with Util.Systems.Os;
with Gen.Testsuite;
package body Gen.Integration.Tests is
Log : constant Util.Log.Loggers.Logger := Util.Log.Loggers.Create ("Gen.Integration.Tests");
-- Get the dynamo executable path.
function Dynamo return String;
-- Clean the directory if it exists.
procedure Clean_Directory (Path : in String);
package Caller is new Util.Test_Caller (Test, "Dynamo");
-- ------------------------------
-- Clean the directory if it exists.
-- ------------------------------
procedure Clean_Directory (Path : in String) is
begin
if Ada.Directories.Exists (Path) then
Ada.Directories.Delete_Tree (Path);
end if;
end Clean_Directory;
procedure Add_Tests (Suite : in Util.Tests.Access_Test_Suite) is
begin
Caller.Add_Test (Suite, "Create AWA project",
Test_Create_Project'Access);
Caller.Add_Test (Suite, "Create ADO project",
Test_Create_ADO_Project'Access);
Caller.Add_Test (Suite, "Create GTK project",
Test_Create_GTK_Project'Access);
Caller.Add_Test (Suite, "Create Lib project",
Test_Create_Lib_Project'Access);
Caller.Add_Test (Suite, "Configure",
Test_Configure'Access);
Caller.Add_Test (Suite, "Propset",
Test_Change_Property'Access);
Caller.Add_Test (Suite, "Add Module",
Test_Add_Module'Access);
Caller.Add_Test (Suite, "Add Model",
Test_Add_Model'Access);
Caller.Add_Test (Suite, "Add Module Operation",
Test_Add_Module_Operation'Access);
Caller.Add_Test (Suite, "Add Service",
Test_Add_Service'Access);
Caller.Add_Test (Suite, "Add Query",
Test_Add_Query'Access);
Caller.Add_Test (Suite, "Add Page",
Test_Add_Page'Access);
Caller.Add_Test (Suite, "Add Layout",
Test_Add_Layout'Access);
Caller.Add_Test (Suite, "Add Ajax Form",
Test_Add_Ajax_Form'Access);
Caller.Add_Test (Suite, "Generate",
Test_Generate'Access);
Caller.Add_Test (Suite, "Help",
Test_Help'Access);
Caller.Add_Test (Suite, "Dist",
Test_Dist'Access);
Caller.Add_Test (Suite, "Dist with exclude",
Test_Dist_Exclude'Access);
Caller.Add_Test (Suite, "Info",
Test_Info'Access);
Caller.Add_Test (Suite, "Build Doc",
Test_Build_Doc'Access);
Caller.Add_Test (Suite, "Generate from Hibernate XML model",
Test_Generate_Hibernate'Access);
Caller.Add_Test (Suite, "Generate XMI Enum",
Test_Generate_XMI_Enum'Access);
Caller.Add_Test (Suite, "Generate XMI Bean",
Test_Generate_XMI_Bean_Table'Access);
Caller.Add_Test (Suite, "Generate XMI Bean with table inheritance",
Test_Generate_XMI_Bean'Access);
Caller.Add_Test (Suite, "Generate XMI Table",
Test_Generate_XMI_Table'Access);
Caller.Add_Test (Suite, "Generate XMI Association",
Test_Generate_XMI_Association'Access);
Caller.Add_Test (Suite, "Generate ArgoUML Association",
Test_Generate_Zargo_Association'Access);
Caller.Add_Test (Suite, "Generate ArgoUML Association (dependencies)",
Test_Generate_Zargo_Dependencies'Access);
Caller.Add_Test (Suite, "Generate ArgoUML several packages",
Test_Generate_Zargo_Packages'Access);
Caller.Add_Test (Suite, "Generate ArgoUML serialization",
Test_Generate_Zargo_Serialization'Access);
Caller.Add_Test (Suite, "Generate ArgoUML with several UML errors",
Test_Generate_Zargo_Errors'Access);
Caller.Add_Test (Suite, "Build generated project",
Test_Build'Access);
Caller.Add_Test (Suite, "Build generated model files (UML)",
Test_Build_Model'Access);
-- Delete the previous test application if it exists.
Clean_Directory ("test-app");
end Add_Tests;
-- ------------------------------
-- Get the dynamo executable path.
-- ------------------------------
function Dynamo return String is
begin
return Util.Files.Compose (Gen.Testsuite.Get_Test_Directory, "bin/dynamo");
end Dynamo;
-- ------------------------------
-- Execute the command and get the output in a string.
-- ------------------------------
procedure Execute (T : in out Test;
Command : in String;
Result : out Ada.Strings.Unbounded.Unbounded_String;
Status : in Natural := 0) is
P : aliased Util.Streams.Pipes.Pipe_Stream;
Buffer : Util.Streams.Buffered.Input_Buffer_Stream;
Test_Dir : constant String := Gen.Testsuite.Get_Test_Directory;
Dir : constant String := Util.Files.Compose (Test_Dir, "test-app");
begin
Log.Info ("Execute: {0}", Command);
if Ada.Directories.Exists (Dir) then
P.Set_Working_Directory (Dir);
Ada.Text_IO.Put_Line ("Set dir: " & Dir);
end if;
P.Open (Command, Util.Processes.READ_ALL);
-- Write on the process input stream.
Result := Ada.Strings.Unbounded.Null_Unbounded_String;
Buffer.Initialize (P'Unchecked_Access, 8192);
Buffer.Read (Result);
P.Close;
Ada.Text_IO.Put_Line (Ada.Strings.Unbounded.To_String (Result));
Log.Info ("Command result: {0}", Result);
Util.Tests.Assert_Equals (T, Status, P.Get_Exit_Status, "Command '" & Command & "' failed");
end Execute;
-- ------------------------------
-- Test dynamo create-project command.
-- ------------------------------
procedure Test_Create_Project (T : in out Test) is
Result : Ada.Strings.Unbounded.Unbounded_String;
begin
T.Execute (Dynamo & " -o test-app create-project -l apache test", Result);
Util.Tests.Assert_Matches (T, ".*Generating file.*test.properties", Result,
"Invalid generation");
Util.Tests.Assert_Matches (T, ".*Generating file.*src/test.ads", Result,
"Invalid generation");
end Test_Create_Project;
-- ------------------------------
-- Test dynamo create-project command --ado.
-- ------------------------------
procedure Test_Create_ADO_Project (T : in out Test) is
Result : Ada.Strings.Unbounded.Unbounded_String;
begin
T.Execute (Dynamo & " -o test-ado create-project -l apache --ado test", Result);
Util.Tests.Assert_Matches (T, ".*Generating file.*test.properties", Result,
"Invalid generation");
Util.Tests.Assert_Matches (T, ".*Generating file.*src/test.ads", Result,
"Invalid generation");
end Test_Create_ADO_Project;
-- ------------------------------
-- Test dynamo create-project command --gtk.
-- ------------------------------
procedure Test_Create_GTK_Project (T : in out Test) is
Result : Ada.Strings.Unbounded.Unbounded_String;
begin
T.Execute (Dynamo & " -o test-gtk create-project -l gpl3 --gtk test", Result);
Util.Tests.Assert_Matches (T, ".*Generating file.*COPYING3", Result,
"Invalid generation");
Util.Tests.Assert_Matches (T, ".*Generating file.*src/test-main.adb", Result,
"Invalid generation");
end Test_Create_GTK_Project;
-- ------------------------------
-- Test dynamo create-project command --lib.
-- ------------------------------
procedure Test_Create_Lib_Project (T : in out Test) is
Result : Ada.Strings.Unbounded.Unbounded_String;
begin
T.Execute (Dynamo & " -o test-lib create-project -l gpl3 --lib test", Result);
Util.Tests.Assert_Matches (T, ".*Generating file.*Makefile", Result,
"Invalid generation");
Util.Tests.Assert_Matches (T, ".*Generating file.*src/test.ads", Result,
"Invalid generation");
end Test_Create_Lib_Project;
-- ------------------------------
-- Test project configure.
-- ------------------------------
procedure Test_Configure (T : in out Test) is
Result : Ada.Strings.Unbounded.Unbounded_String;
begin
T.Execute ("./configure --enable-coverage", Result);
Util.Tests.Assert_Matches (T, ".*checking build system.*", Result,
"Invalid configure");
Util.Tests.Assert_Matches (T, ".*config.status: creating Makefile.*", Result,
"Invalid configure");
end Test_Configure;
-- ------------------------------
-- Test propset command.
-- ------------------------------
procedure Test_Change_Property (T : in out Test) is
Result : Ada.Strings.Unbounded.Unbounded_String;
begin
T.Execute (Dynamo & " propset author Druss", Result);
Util.Tests.Assert_Equals (T, "", Result, "Invalid propset command");
T.Execute (Dynamo & " propset author_email Druss@drenai.com", Result);
Util.Tests.Assert_Equals (T, "", Result, "Invalid propset command");
T.Execute (Dynamo & " propset license Apache", Result);
Util.Tests.Assert_Equals (T, "", Result, "Invalid propset command");
end Test_Change_Property;
-- ------------------------------
-- Test add-module command.
-- ------------------------------
procedure Test_Add_Module (T : in out Test) is
Result : Ada.Strings.Unbounded.Unbounded_String;
begin
T.Execute (Dynamo & " add-module tblog", Result);
Util.Tests.Assert_Matches (T, ".*Generating file.*test-tblog-beans.ads.*", Result,
"Invalid add-module");
T.Execute (Dynamo & " add-module tuser", Result);
Util.Tests.Assert_Matches (T, ".*Generating file.*test-tuser-beans.ads.*", Result,
"Invalid add-module");
end Test_Add_Module;
-- ------------------------------
-- Test add-model command.
-- ------------------------------
procedure Test_Add_Model (T : in out Test) is
Result : Ada.Strings.Unbounded.Unbounded_String;
begin
T.Execute (Dynamo & " add-model tblog test_model", Result);
Util.Tests.Assert_Matches (T, ".*Generating file.*test-tblog-models.ads.*", Result,
"Invalid add-model");
T.Execute (Dynamo & " add-model tblog test_second_model", Result);
Util.Tests.Assert_Matches (T, ".*Generating file.*test-tblog-models.ads.*", Result,
"Invalid add-model");
end Test_Add_Model;
-- ------------------------------
-- Test add-module-operation command.
-- ------------------------------
procedure Test_Add_Module_Operation (T : in out Test) is
Result : Ada.Strings.Unbounded.Unbounded_String;
begin
T.Execute (Dynamo & " add-module-operation tblog test_model Save", Result);
Util.Tests.Assert_Matches (T, ".*Patching file.*tblog-modules.ads.*", Result,
"Invalid add-module-operation");
Util.Tests.Assert_Matches (T, ".*Patching file.*tblog.*procedure implementation.*", Result,
"Invalid add-module-operation");
T.Execute (Dynamo & " add-module-operation tblog test_model Delete", Result);
Util.Tests.Assert_Matches (T, ".*Patching file.*test-tblog-modules.adb.*", Result,
"Invalid add-module-operation");
T.Execute (Dynamo & " add-module-operation tblog test_second_model Delete", Result);
Util.Tests.Assert_Matches (T, ".*Patching file.*test-tblog-modules.adb.*", Result,
"Invalid add-module-operation");
end Test_Add_Module_Operation;
-- ------------------------------
-- Test add-service command.
-- ------------------------------
procedure Test_Add_Service (T : in out Test) is
Result : Ada.Strings.Unbounded.Unbounded_String;
begin
T.Execute (Dynamo & " add-service tblog blogging", Result);
Util.Tests.Assert_Matches (T, ".*Generating file.*test-tblog-services.ads.*", Result,
"Invalid add-module");
T.Execute (Dynamo & " add-service tuser admin", Result);
Util.Tests.Assert_Matches (T, ".*Generating file.*test-tuser-services.ads.*", Result,
"Invalid add-module");
end Test_Add_Service;
-- ------------------------------
-- Test add-query command.
-- ------------------------------
procedure Test_Add_Query (T : in out Test) is
Result : Ada.Strings.Unbounded.Unbounded_String;
begin
T.Execute (Dynamo & " add-query tuser user_query", Result);
Util.Tests.Assert_Matches (T, ".*Generating file.*db/tuser-user_query.xml*", Result,
"Invalid add-query");
T.Execute (Dynamo & " add-query tblog blog_query", Result);
Util.Tests.Assert_Matches (T, ".*Generating file.*db/tblog-blog_query.xml.*", Result,
"Invalid add-query");
end Test_Add_Query;
-- ------------------------------
-- Test add-page command.
-- ------------------------------
procedure Test_Add_Page (T : in out Test) is
Result : Ada.Strings.Unbounded.Unbounded_String;
begin
T.Execute (Dynamo & " add-page main_page", Result);
Util.Tests.Assert_Matches (T, ".*Generating file.*web/main_page.xhtml.*", Result,
"Invalid add-page");
end Test_Add_Page;
-- ------------------------------
-- Test add-layout command.
-- ------------------------------
procedure Test_Add_Layout (T : in out Test) is
Result : Ada.Strings.Unbounded.Unbounded_String;
begin
T.Execute (Dynamo & " add-layout my-layout", Result);
Util.Tests.Assert_Matches (T, ".*Generating file.*web/WEB-INF/layouts/my-layout.xhtml.*",
Result,
"Invalid add-layout");
end Test_Add_Layout;
-- ------------------------------
-- Test add-ajax-form command.
-- ------------------------------
procedure Test_Add_Ajax_Form (T : in out Test) is
Result : Ada.Strings.Unbounded.Unbounded_String;
begin
T.Execute (Dynamo & " add-ajax-form tuser create-user", Result);
Util.Tests.Assert_Matches (T,
".*Generating file.*web/tuser/forms/create-user-response.xhtml.*",
Result,
"Invalid add-ajax-form");
end Test_Add_Ajax_Form;
-- ------------------------------
-- Test generate command.
-- ------------------------------
procedure Test_Generate (T : in out Test) is
Result : Ada.Strings.Unbounded.Unbounded_String;
begin
T.Execute (Dynamo & " propset is_plugin true", Result);
T.Execute (Dynamo & " generate db", Result);
Util.Tests.Assert_Matches (T,
".*Reading model file stored in .db.*",
Result,
"Invalid generate");
Util.Tests.Assert_Matches (T,
".*Generating file.*src/model/test-tuser-models.*",
Result,
"Invalid generate");
T.Execute (Dynamo & " propset is_plugin false", Result);
T.Execute (Dynamo & " generate db", Result);
Util.Tests.Assert_Matches (T,
".*Reading model file stored in .db.*",
Result,
"Invalid generate");
Util.Tests.Assert_Matches (T,
".*Generating file.*src/model/test-tuser-models.*",
Result,
"Invalid generate");
Util.Tests.Assert_Matches (T,
".*Generating file.*db/mysql/test-mysql.sql.*",
Result,
"Invalid generate");
Util.Tests.Assert_Matches (T,
".*Generating mysql.*db/mysql/create-test-mysql.sql.*",
Result,
"Invalid generate");
end Test_Generate;
-- ------------------------------
-- Test help command.
-- ------------------------------
procedure Test_Help (T : in out Test) is
Result : Ada.Strings.Unbounded.Unbounded_String;
begin
T.Execute (Dynamo & " help", Result);
Util.Tests.Assert_Matches (T,
".*Usage.*dynamo.*",
Result,
"Invalid help");
Util.Tests.Assert_Matches (T,
".*add.*module.*",
Result,
"Invalid help");
end Test_Help;
-- ------------------------------
-- Test dist command.
-- ------------------------------
procedure Test_Dist (T : in out Test) is
Result : Ada.Strings.Unbounded.Unbounded_String;
begin
Clean_Directory ("test-dist");
T.Execute (Dynamo & " dist ../test-dist", Result);
Util.Tests.Assert_Matches (T,
".*Installing.*files with copy.*",
Result,
"Invalid dist");
Util.Tests.Assert_Matches (T,
".*Installing.*compressor.*",
Result,
"Invalid dist");
Util.Tests.Assert_Exists (T, "test-dist/bundles/test.properties");
Util.Tests.Assert_Exists (T, "test-dist/bundles/tuser.properties");
end Test_Dist;
-- ------------------------------
-- Test dist with exclude support command.
-- ------------------------------
procedure Test_Dist_Exclude (T : in out Test) is
Result : Ada.Strings.Unbounded.Unbounded_String;
begin
Clean_Directory ("test-dist");
T.Execute (Dynamo & " dist ../test-dist ../regtests/files/package.xml", Result);
Util.Tests.Assert_Matches (T,
".*Installing.*files with copy.*",
Result,
"Invalid dist");
Util.Tests.Assert_Matches (T,
".*Installing.*compressor.*",
Result,
"Invalid dist");
Util.Tests.Assert_Exists (T, "test-dist/bundles/test.properties");
T.Assert (not Ada.Directories.Exists ("test-dir/bundles/tuser.properties"),
"File should not be copied");
end Test_Dist_Exclude;
-- ------------------------------
-- Test dist command.
-- ------------------------------
procedure Test_Info (T : in out Test) is
Result : Ada.Strings.Unbounded.Unbounded_String;
begin
T.Execute (Dynamo & " info", Result);
Util.Tests.Assert_Matches (T,
".*GNAT project files.*",
Result,
"Invalid info");
Util.Tests.Assert_Matches (T,
".*Dynamo project files.*",
Result,
"Invalid info");
end Test_Info;
-- ------------------------------
-- Test build-doc command.
-- ------------------------------
procedure Test_Build_Doc (T : in out Test) is
Result : Ada.Strings.Unbounded.Unbounded_String;
begin
T.Execute (Dynamo & " build-doc wiki", Result);
Util.Tests.Assert_Equals (T, "", Result, "Invalid build-doc command");
Util.Tests.Assert_Exists (T, "test-app/wiki/tblog.wiki");
Util.Tests.Assert_Exists (T, "test-app/wiki/tuser-user_query.wiki");
end Test_Build_Doc;
-- ------------------------------
-- Test generate command with Hibernate XML mapping files.
-- ------------------------------
procedure Test_Generate_Hibernate (T : in out Test) is
Result : Ada.Strings.Unbounded.Unbounded_String;
begin
Ada.Directories.Copy_File (Source_Name => "regtests/files/User.hbm.xml",
Target_Name => "test-app/db/User.hbm.xml");
Ada.Directories.Copy_File (Source_Name => "regtests/files/Queues.hbm.xml",
Target_Name => "test-app/db/Queues.hbm.xml");
Ada.Directories.Copy_File (Source_Name => "regtests/files/Permission.hbm.xml",
Target_Name => "test-app/db/Permission.hbm.xml");
Ada.Directories.Copy_File (Source_Name => "regtests/files/permissions.xml",
Target_Name => "test-app/db/permissions.xml");
Ada.Directories.Copy_File (Source_Name => "regtests/files/queue-messages.xml",
Target_Name => "test-app/db/queue-messages.xml");
Ada.Directories.Copy_File (Source_Name => "regtests/files/serialize.xml",
Target_Name => "test-app/db/serialize.xml");
T.Execute (Dynamo & " generate db", Result);
Util.Tests.Assert_Matches (T,
".*Reading model file stored in .db.*",
Result,
"Invalid generate");
Util.Tests.Assert_Matches (T,
".*Generating file.*src/model/test-tuser-models.*",
Result,
"Invalid generate");
Util.Tests.Assert_Matches (T,
".*Generating file.*db/mysql/test-mysql.sql.*",
Result,
"Invalid generate");
Util.Tests.Assert_Exists (T, "test-app/src/model/gen-permissions-models.ads");
Util.Tests.Assert_Exists (T, "test-app/src/model/gen-permissions-models.adb");
Util.Tests.Assert_Exists (T, "test-app/src/model/gen-users-models.ads");
Util.Tests.Assert_Exists (T, "test-app/src/model/gen-users-models.adb");
Util.Tests.Assert_Exists (T, "test-app/src/model/gen-events-models.ads");
Util.Tests.Assert_Exists (T, "test-app/src/model/gen-events-models.adb");
Util.Tests.Assert_Exists (T, "test-app/src/model/gen-events-serialize.ads");
Util.Tests.Assert_Exists (T, "test-app/src/model/gen-events-serialize.adb");
end Test_Generate_Hibernate;
-- ------------------------------
-- Test generate command (XMI enum).
-- ------------------------------
procedure Test_Generate_XMI_Enum (T : in out Test) is
Result : Ada.Strings.Unbounded.Unbounded_String;
begin
T.Execute (Dynamo & " generate ../regtests/uml/dynamo-test-enum.xmi", Result);
Util.Tests.Assert_Exists (T, "test-app/src/model/gen-tests-enums.ads");
end Test_Generate_XMI_Enum;
-- ------------------------------
-- Test generate command (XMI Ada Bean).
-- ------------------------------
procedure Test_Generate_XMI_Bean (T : in out Test) is
Result : Ada.Strings.Unbounded.Unbounded_String;
begin
T.Execute (Dynamo & " generate ../regtests/uml/dynamo-test-beans.xmi", Result);
Util.Tests.Assert_Exists (T, "test-app/src/model/gen-tests-beans.ads");
end Test_Generate_XMI_Bean;
-- ------------------------------
-- Test generate command (XMI Ada Bean with inheritance).
-- ------------------------------
procedure Test_Generate_XMI_Bean_Table (T : in out Test) is
Result : Ada.Strings.Unbounded.Unbounded_String;
begin
T.Execute (Dynamo & " generate ../regtests/uml/dynamo-test-table-beans.zargo", Result);
Util.Tests.Assert_Exists (T, "test-app/src/model/gen-tests-table_beans.ads");
Util.Tests.Assert_Exists (T, "test-app/src/model/gen-tests-table_beans.adb");
end Test_Generate_XMI_Bean_Table;
-- ------------------------------
-- Test generate command (XMI Ada Table).
-- ------------------------------
procedure Test_Generate_XMI_Table (T : in out Test) is
Result : Ada.Strings.Unbounded.Unbounded_String;
begin
T.Execute (Dynamo & " generate ../regtests/uml/dynamo-test-table.xmi", Result);
Util.Tests.Assert_Exists (T, "test-app/src/model/gen-tests-tables.ads");
Util.Tests.Assert_Exists (T, "test-app/src/model/gen-tests-tables.adb");
end Test_Generate_XMI_Table;
-- ------------------------------
-- Test generate command (XMI Associations between Tables).
-- ------------------------------
procedure Test_Generate_XMI_Association (T : in out Test) is
Result : Ada.Strings.Unbounded.Unbounded_String;
begin
T.Execute (Dynamo & " generate ../regtests/uml/dynamo-test-associations.xmi", Result);
Util.Tests.Assert_Exists (T, "test-app/src/model/gen-tests-associations.ads");
Util.Tests.Assert_Exists (T, "test-app/src/model/gen-tests-associations.adb");
end Test_Generate_XMI_Association;
-- ------------------------------
-- Test generate command using the ArgoUML file directly (runs unzip -cq and parse the output).
-- ------------------------------
procedure Test_Generate_Zargo_Association (T : in out Test) is
Result : Ada.Strings.Unbounded.Unbounded_String;
begin
T.Execute (Dynamo & " generate ../regtests/uml/dynamo-test-associations.zargo", Result);
Util.Tests.Assert_Exists (T, "test-app/src/model/gen-tests-associations.ads");
Util.Tests.Assert_Exists (T, "test-app/src/model/gen-tests-associations.adb");
end Test_Generate_Zargo_Association;
-- ------------------------------
-- Test UML with several tables that have dependencies between each of them (non circular).
-- ------------------------------
procedure Test_Generate_Zargo_Dependencies (T : in out Test) is
Result : Ada.Strings.Unbounded.Unbounded_String;
begin
T.Execute (Dynamo & " generate ../regtests/uml/dynamo-test-dependencies.zargo", Result);
Util.Tests.Assert_Exists (T, "test-app/src/model/gen-tests-dependencies.ads");
Util.Tests.Assert_Exists (T, "test-app/src/model/gen-tests-dependencies.adb");
end Test_Generate_Zargo_Dependencies;
-- ------------------------------
-- Test UML with several tables in several packages (non circular).
-- ------------------------------
procedure Test_Generate_Zargo_Packages (T : in out Test) is
Result : Ada.Strings.Unbounded.Unbounded_String;
begin
T.Execute (Dynamo & " generate ../regtests/uml/dynamo-test-packages.zargo", Result);
Util.Tests.Assert_Exists (T, "test-app/src/model/gen-tests-packages-a.ads");
Util.Tests.Assert_Exists (T, "test-app/src/model/gen-tests-packages-a.adb");
Util.Tests.Assert_Exists (T, "test-app/src/model/gen-tests-packages-b.ads");
Util.Tests.Assert_Exists (T, "test-app/src/model/gen-tests-packages-b.adb");
Util.Tests.Assert_Exists (T, "test-app/src/model/gen-tests-packages-c.ads");
Util.Tests.Assert_Exists (T, "test-app/src/model/gen-tests-packages-c.adb");
Util.Tests.Assert_Exists (T, "test-app/src/model/gen-tests-packages-e.ads");
Util.Tests.Assert_Exists (T, "test-app/src/model/gen-tests-packages-e.adb");
end Test_Generate_Zargo_Packages;
-- ------------------------------
-- Test UML with serialization code.
-- ------------------------------
procedure Test_Generate_Zargo_Serialization (T : in out Test) is
Result : Ada.Strings.Unbounded.Unbounded_String;
begin
T.Execute (Dynamo & " generate ../regtests/uml/dynamo-test-serialize.zargo", Result);
Util.Tests.Assert_Exists (T, "test-app/src/model/gen-tests-serialize.ads");
Util.Tests.Assert_Exists (T, "test-app/src/model/gen-tests-serialize.adb");
end Test_Generate_Zargo_Serialization;
-- ------------------------------
-- Test UML with several errors in the UML model.
-- ------------------------------
procedure Test_Generate_Zargo_Errors (T : in out Test) is
Result : Ada.Strings.Unbounded.Unbounded_String;
begin
T.Execute (Dynamo & " -o tmp generate ../regtests/uml/dynamo-test-errors.zargo", Result, 1);
Util.Tests.Assert_Matches (T, ".*attribute .name. in table .Table_A. has no type.*",
Result,
"attribute with no type error not detected");
Util.Tests.Assert_Matches (T, ".*attribute .count. in table .Table_A. has no type.*",
Result,
"attribute with no type error not detected");
Util.Tests.Assert_Matches (T, ".*attribute .name. in table .Table_C. has no type.*",
Result,
"attribute with no type error not detected");
Util.Tests.Assert_Matches (T, ".*the enum 'Test_Import_Enum' is empty.*",
Result,
"empty enum error not detected");
Util.Tests.Assert_Matches (T, ".*multiple association 'properties' for table.*",
Result,
"multiple association not detected");
end Test_Generate_Zargo_Errors;
-- ------------------------------
-- Test GNAT compilation of the final project.
-- ------------------------------
procedure Test_Build (T : in out Test) is
Result : Ada.Strings.Unbounded.Unbounded_String;
begin
T.Test_Configure;
T.Execute ("make", Result);
pragma Warnings (Off, "condition is always False");
if Util.Systems.Os.Directory_Separator = '\' then
Util.Tests.Assert_Exists (T, "test-app/bin/test-server.exe");
else
Util.Tests.Assert_Exists (T, "test-app/bin/test-server");
end if;
pragma Warnings (On, "condition is always False");
end Test_Build;
-- ------------------------------
-- Test GNAT compilation of the generated model files.
-- ------------------------------
procedure Test_Build_Model (T : in out Test) is
Result : Ada.Strings.Unbounded.Unbounded_String;
begin
Ada.Directories.Copy_File (Source_Name => "regtests/check_build/check_build.gpr",
Target_Name => "test-app//check_build.gpr");
T.Execute ("gprbuild -p -Pcheck_build", Result);
pragma Warnings (Off, "condition is always False");
if Util.Systems.Os.Directory_Separator = '\' then
Util.Tests.Assert_Exists (T, "test-app/bin/test-server.exe");
else
Util.Tests.Assert_Exists (T, "test-app/bin/test-server");
end if;
pragma Warnings (On, "condition is always False");
end Test_Build_Model;
end Gen.Integration.Tests;
|
with SDL;
with SDL.Error;
with SDL.Log;
with SDL.Versions;
procedure Version is
Linked_Version : SDL.Versions.Version;
begin
SDL.Log.Set (Category => SDL.Log.Application, Priority => SDL.Log.Debug);
SDL.Versions.Linked_With (Info => Linked_Version);
SDL.Log.Put_Debug ("Revision : " & SDL.Versions.Revision);
SDL.Log.Put_Debug ("Linked with : " & SDL.Versions.Version_Level'Image (Linked_Version.Major) &
"." & SDL.Versions.Version_Level'Image (Linked_Version.Minor) &
"." & SDL.Versions.Version_Level'Image (Linked_Version.Patch));
SDL.Log.Put_Debug ("Compiled with : " & SDL.Versions.Version_Level'Image (SDL.Versions.Compiled_Major) &
"." & SDL.Versions.Version_Level'Image (SDL.Versions.Compiled_Minor) &
"." & SDL.Versions.Version_Level'Image (SDL.Versions.Compiled_Patch));
SDL.Finalise;
end Version;
|
-- Copyright 2019 Simon Symeonidis (psyomn)
--
-- 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.Assertions; use AUnit.Assertions;
with Common_Utils; use Common_Utils;
with Ada.Strings.Maps;
with Ada.Strings.Fixed;
package body Common_Utils_Test is
procedure Test_Integer_To_Trimmed_String (T : in out Test) is
pragma Unreferenced (T);
Actual : constant String := Integer_To_Trimmed_String (123);
Expected : constant String := "123";
Result : constant Boolean := Actual = Expected;
begin
Assert (Result, "expected: " & Expected & " actual: " & Actual);
end Test_Integer_To_Trimmed_String;
procedure Test_Header_String (T : in out Test) is
pragma Unreferenced (T);
Field : constant String := "Server";
Value : constant String := "ash";
Actual : constant String := Header_String (Field, Value);
Expected : constant String := "Server: ash";
Result : constant Boolean := Actual = Expected;
begin
Assert (Result, "expected: " & Expected & ", actual: " & Actual);
end Test_Header_String;
procedure Test_Header_String_Integer (T : in out Test) is
pragma Unreferenced (T);
Field : constant String := "Processor";
Value : constant Integer := 6502;
Actual : constant String := Header_String (Field, Value);
Expected : constant String := "Processor: 6502";
Result : constant Boolean := Actual = Expected;
begin
Assert (Result, "expected header: " & Expected & ", actual: " & Actual);
end Test_Header_String_Integer;
procedure Test_Empty_String (T : in out Test) is
pragma Unreferenced (T);
S : String := "notempty";
Count : Integer := 0;
begin
for I in Positive range S'First .. S'Last loop
if S (I) = Character'Val (0) then
Count := Count + 1;
end if;
end loop;
Assert (Count = 0, "should not have null chars");
Empty_String (S);
for I in Positive range S'First .. S'Last loop
if S (I) = Character'Val (0) then
Count := Count + 1;
end if;
end loop;
Assert (Count = S'Length, "should be all null chars");
end Test_Empty_String;
procedure Test_Empty_String_Range (T : in out Test) is
pragma Unreferenced (T);
use Ada.Strings.Maps;
use Ada.Strings.Fixed;
type Test_Case is record
Data : String (1 .. 9);
First : Positive;
Last : Positive;
end record;
type Tca is array (Positive range <>) of Test_Case;
Null_Map : constant Character_Mapping :=
To_Mapping (From => " ", To => "" & Character'Val (0));
Tc1 : constant Test_Case := (Translate ("hello ", Null_Map), 5, 5);
Tc2 : constant Test_Case := (Translate (" hello", Null_Map), 1, 5);
Tc3 : constant Test_Case := (Translate (" hello ", Null_Map), 1, 3);
Tcs : constant Tca := (Tc1, Tc2, Tc3);
F, L : Positive := 1;
begin
for I in Positive range Tcs'First .. Tcs'Last loop
Empty_String_Range
(S => Tcs (I).Data, First => F, Last => L);
Assert (Tcs (I).First = F and Tcs (I).Last = L,
"expected first,last:" &
Tcs (I).First'Image & "," & Tcs (I).Last'Image & " " &
"got first,last:" & F'Image & "," & F'Image & " " &
"with data: ." & Tcs (I).Data & ".");
end loop;
end Test_Empty_String_Range;
procedure Test_Concat_Null_String (T : in out Test) is
pragma Unreferenced (T);
Buff1, Buff2 : String (1 .. 1024) := (others => Character'Val (0));
Expected : constant String := "hellolle";
begin
Buff1 (1 .. 4) := "hell";
Buff2 (1 .. 4) := "olle";
declare
Actual : constant String :=
Concat_Null_Strings (Buff1, Buff2);
begin
Assert
(Actual = Expected,
"actual: " & Actual & " expected: " & Expected);
end;
end Test_Concat_Null_String;
end Common_Utils_Test;
|
-- SPDX-License-Identifier: Apache-2.0
--
-- Copyright (c) 2016 onox <denkpadje@gmail.com>
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
package body Orka.SIMD.SSE.Singles.Swizzle is
Mask_1_0_1_0 : constant Unsigned_32 := 1 * 64 or 0 * 16 or 1 * 4 or 0;
Mask_3_2_3_2 : constant Unsigned_32 := 3 * 64 or 2 * 16 or 3 * 4 or 2;
Mask_2_0_2_0 : constant Unsigned_32 := 2 * 64 or 0 * 16 or 2 * 4 or 0;
Mask_3_1_3_1 : constant Unsigned_32 := 3 * 64 or 1 * 16 or 3 * 4 or 1;
procedure Transpose (Matrix : in out m128_Array) is
M0 : constant m128 := Unpack_Low (Matrix (X), Matrix (Y));
M1 : constant m128 := Unpack_Low (Matrix (Z), Matrix (W));
M2 : constant m128 := Unpack_High (Matrix (X), Matrix (Y));
M3 : constant m128 := Unpack_High (Matrix (Z), Matrix (W));
begin
Matrix (X) := Move_LH (M0, M1);
Matrix (Y) := Move_HL (M1, M0);
Matrix (Z) := Move_LH (M2, M3);
Matrix (W) := Move_HL (M3, M2);
end Transpose;
function Transpose (Matrix : m128_Array) return m128_Array is
Result : m128_Array;
M0 : constant m128 := Shuffle (Matrix (X), Matrix (Y), Mask_1_0_1_0);
M1 : constant m128 := Shuffle (Matrix (Z), Matrix (W), Mask_1_0_1_0);
M2 : constant m128 := Shuffle (Matrix (X), Matrix (Y), Mask_3_2_3_2);
M3 : constant m128 := Shuffle (Matrix (Z), Matrix (W), Mask_3_2_3_2);
begin
Result (X) := Shuffle (M0, M1, Mask_2_0_2_0);
Result (Y) := Shuffle (M0, M1, Mask_3_1_3_1);
Result (Z) := Shuffle (M2, M3, Mask_2_0_2_0);
Result (W) := Shuffle (M2, M3, Mask_3_1_3_1);
return Result;
end Transpose;
end Orka.SIMD.SSE.Singles.Swizzle;
|
-- see OpenUxAS\src\Includes\Constants\UxAS_String.h
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
package UxAS.Common.String_Constant.Lmcp_Network_Socket_Address is
-- NOTE: we are modifying the actual socket addresses used in the full C++
-- version so that the Ada demo, running as a separate process, can listen
-- for the required LMCP messages. Therefore, since it is a separate
-- process, we don't use the "inproc" addresses. Instead we use the
-- addresses used by the LmcpObjectNetworkPublishPullBridge bridge, which
-- are specified in the XML configuration files. We want to retain use of
-- this package spec though, so we change the two necessary declarations
-- so that they are not constant, and for the sake of easily changing them
-- at run-time (from the XML file), we use Unbounded_String. In a full Ada
-- version of UxAs, with everything in the same process, we would not need
-- these changes because the "inproc" addresses would be appropriate.
InProc_ThreadControl : constant String := "inproc://thread_control";
InProc_From_MessageHub : Unbounded_String := To_Unbounded_String ("inproc://from_message_hub"); -- "tcp://127.0.0.1:5560" -- the Pub address
InProc_To_MessageHub : Unbounded_String := To_Unbounded_String ("inproc://to_message_hub"); -- "tcp://127.0.0.1:5561" -- the Pull address
InProc_ConfigurationHub : constant String := "inproc://configuration_hub";
InProc_ManagerThreadControl : constant String := "inproc://manager_thread_control";
end UxAS.Common.String_Constant.Lmcp_Network_Socket_Address;
|
-- part of OpenGLAda, (c) 2017 Felix Krause
-- released under the terms of the MIT license, see the file "COPYING"
with Glfw.API;
with Glfw.Enums;
package body Glfw.Windows.Hints is
procedure Reset_To_Defaults renames API.Default_Window_Hints;
procedure Set_Resizable (Value : Boolean) is
begin
API.Window_Hint (Enums.Resizable, Bool (Value));
end Set_Resizable;
procedure Set_Visible (Value : Boolean) is
begin
API.Window_Hint (Enums.Visible, Bool (Value));
end Set_Visible;
procedure Set_Decorated (Value : Boolean) is
begin
API.Window_Hint (Enums.Decorated, Bool (Value));
end Set_Decorated;
procedure Set_Color_Bits (Red, Green, Blue, Alpha : Natural) is
begin
API.Window_Hint (Enums.Red_Bits, Interfaces.C.int (Red));
API.Window_Hint (Enums.Green_Bits, Interfaces.C.int (Green));
API.Window_Hint (Enums.Blue_Bits, Interfaces.C.int (Blue));
API.Window_Hint (Enums.Alpha_Bits, Interfaces.C.int (Alpha));
end Set_Color_Bits;
procedure Set_Depth_Bits (Value : Natural) is
begin
API.Window_Hint (Enums.Depth_Bits, Interfaces.C.int (Value));
end Set_Depth_Bits;
procedure Set_Stencil_Bits (Value : Natural) is
begin
API.Window_Hint (Enums.Stencil_Bits, Interfaces.C.int (Value));
end Set_Stencil_Bits;
procedure Set_Accumulation_Bits (Red, Green, Blue, Alpha : Natural) is
begin
API.Window_Hint (Enums.Accum_Red_Bits, Interfaces.C.int (Red));
API.Window_Hint (Enums.Accum_Green_Bits, Interfaces.C.int (Green));
API.Window_Hint (Enums.Accum_Blue_Bits, Interfaces.C.int (Blue));
API.Window_Hint (Enums.Accum_Alpha_Bits, Interfaces.C.int (Alpha));
end Set_Accumulation_Bits;
procedure Set_Aux_Buffers (Value : Natural) is
begin
API.Window_Hint (Enums.Aux_Buffers, Interfaces.C.int (Value));
end Set_Aux_Buffers;
procedure Set_Stereo (Value : Boolean) is
begin
API.Window_Hint (Enums.Stereo, Bool (Value));
end Set_Stereo;
procedure Set_Samples (Value : Natural) is
begin
API.Window_Hint (Enums.Samples, Interfaces.C.int (Value));
end Set_Samples;
procedure Set_SRGB_Capable (Value : Boolean) is
begin
API.Window_Hint (Enums.SRGB_Capable, Bool (Value));
end Set_SRGB_Capable;
procedure Set_Refresh_Rate (Value : Natural) is
begin
API.Window_Hint (Enums.Refresh_Rate, Interfaces.C.int (Value));
end Set_Refresh_Rate;
procedure Set_Client_API (Value : Context.API_Kind) is
begin
API.Window_Hint (Enums.Client_API, Value);
end Set_Client_API;
procedure Set_Minimum_OpenGL_Version (Major : Positive; Minor : Natural) is
begin
API.Window_Hint (Enums.Context_Version_Major, Interfaces.C.int (Major));
API.Window_Hint (Enums.Context_Version_Minor, Interfaces.C.int (Minor));
end Set_Minimum_OpenGL_Version;
procedure Set_Robustness (Value : Context.Robustness_Kind) is
begin
API.Window_Hint (Enums.Context_Robustness, Value);
end Set_Robustness;
procedure Set_Forward_Compat (Value : Boolean) is
begin
API.Window_Hint (Enums.OpenGL_Forward_Compat, Bool (Value));
end Set_Forward_Compat;
procedure Set_Debug_Context (Value : Boolean) is
begin
API.Window_Hint (Enums.OpenGL_Debug_Context, Bool (Value));
end Set_Debug_Context;
procedure Set_Profile (Value : Context.OpenGL_Profile_Kind) is
begin
API.Window_Hint (Enums.OpenGL_Profile, Value);
end Set_Profile;
end Glfw.Windows.Hints;
|
-- part of AdaYaml, (c) 2017 Felix Krause
-- released under the terms of the MIT license, see the file "copying.txt"
with AUnit; use AUnit;
with AUnit.Test_Cases; use AUnit.Test_Cases;
with Ada.Containers.Indefinite_Vectors;
package Yaml.Parser.Event_Test is
subtype Test_Case_Name is String (1 .. 4);
package Test_Case_Vectors is new Ada.Containers.Indefinite_Vectors (Positive, Test_Case_Name);
type TC is new Test_Cases.Test_Case with record
Test_Cases : Test_Case_Vectors.Vector;
Cur : Positive;
end record;
overriding procedure Register_Tests (T : in out TC);
function Name (T : TC) return Message_String;
procedure Execute_Next_Test (T : in out Test_Cases.Test_Case'Class);
procedure Execute_Error_Test (T : in out Test_Cases.Test_Case'Class);
end Yaml.Parser.Event_Test;
|
with Ada.Real_Time; use Ada.Real_Time;
with STM32F4; use STM32F4;
with STM32F4.GPIO; use STM32F4.GPIO;
with STM32F4.RCC; use STM32F4.RCC;
with STM32F429_Discovery; use STM32F429_Discovery;
package body STM32F4.SDRAM is
--------------------
-- Configure_GPIO --
--------------------
procedure Configure_GPIO is
Conf : GPIO_Port_Configuration;
begin
Enable_Clock (GPIO_B);
Enable_Clock (GPIO_C);
Enable_Clock (GPIO_D);
Enable_Clock (GPIO_E);
Enable_Clock (GPIO_F);
Enable_Clock (GPIO_G);
Conf.Speed := Speed_50MHz;
Conf.Mode := Mode_AF;
Conf.Output_Type := Push_Pull;
Conf.Resistors := Floating;
Conf.Locked := True;
Configure_Alternate_Function (GPIO_B, (Pin_5, Pin_6), GPIO_AF_FMC);
Configure_IO (GPIO_B, (Pin_5, Pin_6), Conf);
Configure_Alternate_Function (GPIO_C, Pin_0, GPIO_AF_FMC);
Configure_IO (GPIO_C, Pin_0, Conf);
Configure_Alternate_Function (GPIO_D,
(Pin_0, Pin_1, Pin_8, Pin_9, Pin_10,
Pin_14, Pin_15),
GPIO_AF_FMC);
Configure_IO (GPIO_D, (Pin_0, Pin_1, Pin_8, Pin_9, Pin_10, Pin_14,
Pin_15), Conf);
Configure_Alternate_Function (GPIO_E, (Pin_0, Pin_1, Pin_7, Pin_8, Pin_9,
Pin_10, Pin_11, Pin_12, Pin_13,
Pin_14, Pin_15), GPIO_AF_FMC);
Configure_IO (GPIO_E, (Pin_0, Pin_1, Pin_7, Pin_8, Pin_9, Pin_10, Pin_11,
Pin_12, Pin_13, Pin_14, Pin_15), Conf);
Configure_Alternate_Function (GPIO_F,
(Pin_0, Pin_1, Pin_2, Pin_3, Pin_4, Pin_5,
Pin_11, Pin_12, Pin_13, Pin_14, Pin_15),
GPIO_AF_FMC);
Configure_IO (GPIO_F, (Pin_0, Pin_1, Pin_2, Pin_3, Pin_4, Pin_5,
Pin_11, Pin_12, Pin_13, Pin_14, Pin_15), Conf);
Configure_Alternate_Function (GPIO_G,
(Pin_0, Pin_1, Pin_4, Pin_5,
Pin_8, Pin_15),
GPIO_AF_FMC);
Configure_IO (GPIO_G, (Pin_0, Pin_1, Pin_4, Pin_5, Pin_8, Pin_15), Conf);
end Configure_GPIO;
--------------------
-- Relative_Delay --
--------------------
procedure Relative_Delay (Ms : Integer) is
Next_Start : Time := Clock;
Period : constant Time_Span := Milliseconds (Ms);
begin
Next_Start := Next_Start + Period;
delay until Next_Start;
end Relative_Delay;
------------------------
-- SDRAM_InitSequence --
------------------------
procedure SDRAM_InitSequence is
Cmd : FMC_SDRAM_Cmd_Conf;
begin
Cmd.CommandMode := FMC_Command_Mode_CLK_Enabled;
Cmd.CommandTarget := FMC_Command_Target_bank2;
Cmd.AutoRefreshNumber := 1;
Cmd.ModeRegisterDefinition := 0;
loop
exit when not FMC_Get_Flag (FMC_Bank2_SDRAM, FMC_FLAG_Busy);
end loop;
FMC_SDRAM_Cmd (Cmd);
Relative_Delay (100);
Cmd.CommandMode := FMC_Command_Mode_PALL;
Cmd.CommandTarget := FMC_Command_Target_bank2;
Cmd.AutoRefreshNumber := 1;
Cmd.ModeRegisterDefinition := 0;
loop
exit when not FMC_Get_Flag (FMC_Bank2_SDRAM, FMC_FLAG_Busy);
end loop;
FMC_SDRAM_Cmd (Cmd);
Cmd.CommandMode := FMC_Command_Mode_AutoRefresh;
Cmd.CommandTarget := FMC_Command_Target_bank2;
Cmd.AutoRefreshNumber := 4;
Cmd.ModeRegisterDefinition := 0;
loop
exit when not FMC_Get_Flag (FMC_Bank2_SDRAM, FMC_FLAG_Busy);
end loop;
FMC_SDRAM_Cmd (Cmd);
loop
exit when not FMC_Get_Flag (FMC_Bank2_SDRAM, FMC_FLAG_Busy);
end loop;
FMC_SDRAM_Cmd (Cmd);
Cmd.CommandMode := FMC_Command_Mode_LoadMode;
Cmd.CommandTarget := FMC_Command_Target_bank2;
Cmd.AutoRefreshNumber := 1;
Cmd.ModeRegisterDefinition := SDRAM_MODEREG_BURST_LENGTH_2 or
SDRAM_MODEREG_BURST_TYPE_SEQUENTIAL or
SDRAM_MODEREG_CAS_LATENCY_3 or
SDRAM_MODEREG_OPERATING_MODE_STANDARD or
SDRAM_MODEREG_WRITEBURST_MODE_SINGLE;
loop
exit when not FMC_Get_Flag (FMC_Bank2_SDRAM, FMC_FLAG_Busy);
end loop;
FMC_SDRAM_Cmd (Cmd);
FMC_Set_Refresh_Count (1386);
loop
exit when not FMC_Get_Flag (FMC_Bank2_SDRAM, FMC_FLAG_Busy);
end loop;
end SDRAM_InitSequence;
----------------
-- Initialize --
----------------
procedure Initialize is
Timing_Conf : FMC_SDRAM_TimingInit_Config;
SDRAM_Conf : FMC_SDRAM_Init_Config;
begin
Configure_GPIO;
FSMC_Clock_Enable;
Timing_Conf.LoadToActiveDelay := 2;
Timing_Conf.ExitSelfRefreshDelay := 7;
Timing_Conf.SelfRefreshTime := 4;
Timing_Conf.RowCycleDelay := 7;
Timing_Conf.WriteRecoveryTime := 2;
Timing_Conf.RPDelay := 2;
Timing_Conf.RCDDelay := 2;
SDRAM_Conf.Bank := FMC_Bank2_SDRAM;
SDRAM_Conf.ColumnBitsNumber := FMC_ColumnBits_Number_8b;
SDRAM_Conf.RowBitsNumber := FMC_RowBits_Number_12b;
SDRAM_Conf.SDMemoryDataWidth := SDRAM_MEMORY_WIDTH;
SDRAM_Conf.InternalBankNumber := FMC_InternalBank_Number_4;
SDRAM_Conf.CASLatency := SDRAM_CAS_LATENCY;
SDRAM_Conf.WriteProtection := FMC_Write_Protection_Disable;
SDRAM_Conf.SDClockPeriod := SDCLOCK_PERIOD;
SDRAM_Conf.ReadBurst := SDRAM_READBURST;
SDRAM_Conf.ReadPipeDelay := FMC_ReadPipe_Delay_1;
SDRAM_Conf.Timing_Conf := Timing_Conf;
FMC_SDRAM_Init (SDRAM_Conf);
SDRAM_InitSequence;
end Initialize;
end STM32F4.SDRAM;
|
with Ada.Strings,
Ada.Strings.UTF_Encoding,
Ada.Strings.UTF_Encoding.Wide_Strings,
Ada.Command_Line,
Ada.Directories,
Ada.Sequential_IO,
Interfaces.C_Streams,
Password_Encode;
use Ada.Strings.UTF_Encoding;
package body PassEncrypt is
use IO;
procedure Main is
use Password_Encode;
use Ada.Command_Line;
encryption: Password_Encode.Password;
cmd_i: Positive:= 1;
DecodeMode: Boolean:= False;
In_Attachment : IO_Attachment := Null_IO;
Out_Attachment : IO_Attachment := Null_IO;
-- Write to StdErr Message.
procedure WriteErr(Message: in String) is
use Ada.Strings.UTF_Encoding.Wide_Strings;
begin
Password_Encode.PutError(Message =>
Encode(
Decode(
UTF_8_String(Message))));
end WriteErr;
-- for processing '-f'. Provide the filename and this procedure
-- will take care of the opening, reading all of the contents, then
-- closing. Contents read in this fashion will read all contents
function Get_PasswordFile_Data(Filename: in String) return String is
use Ada.Strings.UTF_Encoding.Wide_Strings;
File_Size: Natural:= Natural(Ada.Directories.Size(Name => Filename));
subtype File_Data is String(1 .. File_Size);
package IO is new Ada.Sequential_IO(File_Data);
File: IO.File_Type;
Return_Data: File_Data;
begin
IO.Open(File => File,
Mode => IO.In_File,
Name => Filename);
IO.Read(File => File,
Item => Return_Data);
IO.Close(File => File);
return String(Return_Data);
end Get_PasswordFile_Data;
begin
for CL_Iteration in 1 .. Command_Line.Argument_Count
loop
case Command_Line.Argument(1) is
when "-k" =>
encryption.Set(S => UTF_8_String(Command_Line.Argument(1)));
when "-c" =>
WriteErr( "No Password/Key given with ""-k"" option");
exit;
PasswordEncode.set(password1,Argument(cmd_i));
PasswordEncode.set(password2,Argument(cmd_i));
PasswordEncode.set(password3,Argument(cmd_i));
end case;
if Argument(cmd_i) = "-f" then
cmd_i:= cmd_i + 1;
if cmd_i > Argument_Count then
WriteErr( "No Password/Key file given with " & '"' & "-f" & '"' & " option");
exit;
end if;
if not password1.IsSet then
PasswordEncode.set(password1,GetPasswordFileData(Argument(cmd_i)));
elsif not password2.is_set then
PasswordEncode.set(password2,GetPasswordFileData(Argument(cmd_i)));
elsif not password3.is_set then
PasswordEncode.set(password3,GetPasswordFileData(Argument(cmd_i)));
end if;
end if;
cmd_i:= cmd_i + 1;
end loop;
if not password1.is_set then
PasswordEncode.set(password1,Character'Image(Ada.Strings.Space));
end if;
end Main;
end PassEncrypt;
|
-- RUN: %llvmgcc -c %s
package Init_Size is
type T (B : Boolean := False) is record
case B is
when False =>
I : Integer;
when True =>
J : Long_Long_Integer; -- Bigger than I
end case;
end record;
A_T : constant T := (False, 0);
end;
|
------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- V A L I D S W --
-- --
-- S p e c --
-- --
-- Copyright (C) 2001-2020, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. 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. --
-- --
------------------------------------------------------------------------------
-- This unit contains the routines used to handle setting of validity
-- checking options.
package Validsw is
-----------------------------
-- Validity Check Switches --
-----------------------------
-- The following flags determine the specific set of validity checks
-- to be made if validity checking is active (Validity_Checks_On = True)
-- See GNAT users guide for an exact description of each option. The letter
-- given in the comment is the letter used in the -gnatV compiler switch
-- or in the argument of a Validity_Checks pragma to activate the option.
-- The corresponding upper case letter deactivates the option.
Validity_Check_Components : Boolean := False;
-- Controls validity checking for assignment to elementary components of
-- records. If this switch is set to True using -gnatVe, or an 'e' in the
-- argument of Validity_Checks pragma, then the right-hand side of an
-- assignment to such a component is checked for validity.
Validity_Check_Copies : Boolean := False;
-- Controls the validity checking of copies. If this switch is set to
-- True using -gnatVc, or a 'c' in the argument of a Validity_Checks
-- pragma, then the right-hand side of assignments and also initializing
-- expressions in object declarations are checked for validity.
Validity_Check_Default : Boolean := True;
-- Controls default (reference manual) validity checking. If this switch is
-- set to True using -gnatVd or a 'd' in the argument of a Validity_Checks
-- pragma (or the initial default value is used, set True), then left-hand
-- side subscripts and case statement arguments are checked for validity.
-- This switch is also set by default if no -gnatV switch is used and no
-- Validity_Checks pragma is processed.
Validity_Check_Floating_Point : Boolean := False;
-- Normally validity checking applies only to discrete values (integer and
-- enumeration types). If this switch is set to True using -gnatVf or an
-- 'f' in the argument of a Validity_Checks pragma, then floating-point
-- values are also checked. If the context in which such checks occur
-- depends on other flags, e.g. if Validity_Check_Copies is also set,
-- then floating-point values on the right-hand side of an assignment
-- will be validity checked.
Validity_Check_In_Out_Params : Boolean := False;
-- Controls the validity checking of IN OUT parameters. If this switch
-- is set to True using -gnatVm or a 'm' in the argument of a pragma
-- Validity_Checks, then the initial value of all IN OUT parameters
-- will be checked at the point of call of a procedure. Note that the
-- character 'm' here stands for modified (parameters).
Validity_Check_In_Params : Boolean := False;
-- Controls the validity checking of IN parameters. If this switch is
-- set to True using -gnatVi or an 'i' in the argument of a pragma
-- Validity_Checks, then the initial value of all IN parameters
-- will be checked at the point of call of a procedure or function.
Validity_Check_Operands : Boolean := False;
-- Controls validity checking of operands. If this switch is set to
-- True using -gnatVo or an 'o' in the argument of a Validity_Checks
-- pragma, then operands of all predefined operators and attributes
-- will be validity checked.
Validity_Check_Parameters : Boolean := False;
-- This controls validity treatment for parameters within a subprogram.
-- Normally if validity checking is enabled for parameters on a call
-- (Validity_Check_In[_Out]_Params) then an assumption is made that the
-- parameter values are valid on entry and not checked again within a
-- procedure. Setting Validity_Check_Parameters removes this assumption
-- and ensures that no assumptions are made about parameters, so that
-- they will always be checked.
Validity_Check_Returns : Boolean := False;
-- Controls validity checking of returned values. If this switch is set
-- to True using -gnatVr, or an 'r' in the argument of a Validity_Checks
-- pragma, then the expression in a RETURN statement is validity checked.
Validity_Check_Subscripts : Boolean := False;
-- Controls validity checking of subscripts. If this switch is set to True
-- using -gnatVs, or an 's' in the argument of a Validity_Checks pragma,
-- then all subscripts are checked for validity. Note that left-hand side
-- subscript checking is also controlled by Validity_Check_Default. If
-- Validity_Check_Subscripts is True, then all subscripts are checked,
-- otherwise if Validity_Check_Default is True, then left-hand side
-- subscripts are checked; otherwise no subscripts are checked.
Validity_Check_Tests : Boolean := False;
-- Controls validity checking of tests that occur in conditions (i.e. the
-- tests in IF, WHILE, and EXIT statements, and in entry guards). If this
-- switch is set to True using -gnatVt, or a 't' in the argument of a
-- Validity_Checks pragma, then all such conditions are validity checked.
Force_Validity_Checks : Boolean := False;
-- Normally, operands that do not come from source (i.e. cases of expander
-- generated code) are not checked, if this flag is set True, then checking
-- of such operands is forced (if Validity_Check_Operands is set).
-----------------
-- Subprograms --
-----------------
procedure Set_Default_Validity_Check_Options;
-- This procedure is called to set the default validity checking options
-- that apply if no Validity_Check switches or pragma is given.
procedure Set_Validity_Check_Options
(Options : String;
OK : out Boolean;
Err_Col : out Natural);
-- This procedure is called to set the validity check options that
-- correspond to the characters in the given Options string. If
-- all options are valid, then Set_Default_Validity_Check_Options
-- is first called to set the defaults, and then the options in the
-- given string are set in an additive manner. If any invalid character
-- is found, then OK is False on exit, and Err_Col is the index in
-- in options of the bad character. If all options are valid, then
-- OK is True on return, and Err_Col is set to options'Last + 1.
procedure Set_Validity_Check_Options (Options : String);
-- Like the above procedure, except that the call is simply ignored if
-- there are any error conditions, this is for example appropriate for
-- calls where the string is known to be valid, e.g. because it was
-- obtained by Save_Validity_Check_Options.
procedure Reset_Validity_Check_Options;
-- Sets all validity check options to off
subtype Validity_Check_Options is String (1 .. 16);
-- Long enough string to hold all options from Save call below
procedure Save_Validity_Check_Options
(Options : out Validity_Check_Options);
-- Sets Options to represent current selection of options. This
-- set can be restored by first calling Reset_Validity_Check_Options,
-- and then calling Set_Validity_Check_Options with the Options string.
end Validsw;
|
with Ada.Text_IO;
procedure Hello is
package IO renames Ada.Text_IO;
begin
loop
foo();
exit when 2 > 3;
bar();
exit when 2 > 3 and 3 > 4;
end loop;
end Hello;
|
--
-- Intentionally not providing a Copyright header to verify that
-- having -copyright in the config for our module does indeed turn
-- this check off.
--
package Pck is
end Pck;
|
with System.Storage_Barriers;
with System.Synchronous_Control;
package body System.Once is
pragma Suppress (All_Checks);
Yet : constant := 0;
Start : constant := 1;
Done : constant := 2;
function atomic_load (
ptr : not null access constant Flag;
memorder : Integer := Storage_Barriers.ATOMIC_ACQUIRE)
return Flag
with Import, Convention => Intrinsic, External_Name => "__atomic_load_1";
procedure atomic_store (
ptr : not null access Flag;
val : Flag;
memorder : Integer := Storage_Barriers.ATOMIC_RELEASE)
with Import,
Convention => Intrinsic, External_Name => "__atomic_store_1";
function atomic_compare_exchange (
ptr : not null access Flag;
expected : not null access Flag;
desired : Flag;
weak : Boolean := False;
success_memorder : Integer := Storage_Barriers.ATOMIC_ACQ_REL;
failure_memorder : Integer := Storage_Barriers.ATOMIC_ACQUIRE)
return Boolean
with Import,
Convention => Intrinsic,
External_Name => "__atomic_compare_exchange_1";
-- implementation
procedure Initialize (
Flag : not null access Once.Flag;
Process : not null access procedure)
is
Expected : aliased Once.Flag := Yet;
begin
if atomic_compare_exchange (Flag, Expected'Access, Start) then
-- succeeded to swap
Process.all;
atomic_store (Flag, Done);
elsif Expected = Start then
-- wait until Flag = Done
loop
Synchronous_Control.Yield;
exit when atomic_load (Flag) = Done;
end loop;
end if;
-- Flag = Done
end Initialize;
end System.Once;
|
package impact.d2.orbs.Joint.mouse
--
--
--
is
-- #ifndef B2_MOUSE_JOINT_H
-- #define B2_MOUSE_JOINT_H
--
-- #include <Box2D/Dynamics/Joints/b2Joint.h>
--
-- /// Mouse joint definition. This requires a world target point,
-- /// tuning parameters, and the time step.
-- struct b2MouseJointDef : public b2JointDef
-- {
-- b2MouseJointDef()
-- {
-- type = e_mouseJoint;
-- target.Set(0.0f, 0.0f);
-- maxForce = 0.0f;
-- frequencyHz = 5.0f;
-- dampingRatio = 0.7f;
-- }
--
-- /// The initial world target point. This is assumed
-- /// to coincide with the body anchor initially.
-- b2Vec2 target;
--
-- /// The maximum constraint force that can be exerted
-- /// to move the candidate body. Usually you will express
-- /// as some multiple of the weight (multiplier * mass * gravity).
-- float32 maxForce;
--
-- /// The response speed.
-- float32 frequencyHz;
--
-- /// The damping ratio. 0 = no damping, 1 = critical damping.
-- float32 dampingRatio;
-- };
--
-- /// A mouse joint is used to make a point on a body track a
-- /// specified world point. This a soft constraint with a maximum
-- /// force. This allows the constraint to stretch and without
-- /// applying huge forces.
-- /// NOTE: this joint is not documented in the manual because it was
-- /// developed to be used in the testbed. If you want to learn how to
-- /// use the mouse joint, look at the testbed.
-- class b2MouseJoint : public b2Joint
-- {
-- public:
--
-- /// Implements b2Joint.
-- b2Vec2 GetAnchorA() const;
--
-- /// Implements b2Joint.
-- b2Vec2 GetAnchorB() const;
--
-- /// Implements b2Joint.
-- b2Vec2 GetReactionForce(float32 inv_dt) const;
--
-- /// Implements b2Joint.
-- float32 GetReactionTorque(float32 inv_dt) const;
--
-- /// Use this to update the target point.
-- void SetTarget(const b2Vec2& target);
-- const b2Vec2& GetTarget() const;
--
-- /// Set/get the maximum force in Newtons.
-- void SetMaxForce(float32 force);
-- float32 GetMaxForce() const;
--
-- /// Set/get the frequency in Hertz.
-- void SetFrequency(float32 hz);
-- float32 GetFrequency() const;
--
-- /// Set/get the damping ratio (dimensionless).
-- void SetDampingRatio(float32 ratio);
-- float32 GetDampingRatio() const;
--
-- protected:
-- friend class b2Joint;
--
-- b2MouseJoint(const b2MouseJointDef* def);
--
-- void InitVelocityConstraints(const b2TimeStep& step);
-- void SolveVelocityConstraints(const b2TimeStep& step);
-- bool SolvePositionConstraints(float32 baumgarte) { B2_NOT_USED(baumgarte); return true; }
--
-- b2Vec2 m_localAnchor;
-- b2Vec2 m_target;
-- b2Vec2 m_impulse;
--
-- b2Mat22 m_mass; // effective mass for point-to-point constraint.
-- b2Vec2 m_C; // position error
-- float32 m_maxForce;
-- float32 m_frequencyHz;
-- float32 m_dampingRatio;
-- float32 m_beta;
-- float32 m_gamma;
-- };
--
-- #endif
procedure dummy;
end impact.d2.orbs.Joint.mouse;
|
separate(Practica4)
function Tratar_Fichero(Nom_F_Ent: in Unbounded_String;
Nom_F_Let: in Unbounded_String;
Nom_F_Num: in Unbounded_String) return Natural is
Fich1,fichL,fichN:file_type;
letra,Numero:Unbounded_string;
linea:string(1..125);
nume:natural;
begin
open(fich1,in_file,name=>to_string(Nom_F_Ent));
--Abro el fichero de que se van ha leer las lineas.
create(fichL,out_file,to_string(Nom_f_let));
--creo el fichero en modo escritura , de letras.
create(fichN,out_file,to_string(Nom_f_num));
--creo el fichero en modo lectura de numeros.
loop
letra:=null_unbounded_string;
numero:=Null_unbounded_string;--vacio las ristras
get_line(fich1,linea,nume);--leo una linea en el fichero
separar(to_unbounded_string(linea(1..nume)),Letra,Numero);
--los separo con la funcion separar
put_line(fichL,to_string(Letra));--Y guardo las lineas en sus ficheros
--correspondientes
put_line(fichN,to_string(Numero));
exit when end_of_file(fich1);
end loop;
close(fich1);
close(fichL);
close(fichN);
return 0;
exception
when Name_error =>
--salta cuando el nombre del fichero que se va a leer no existe
return 1;
when Mode_error =>
-- si no puede crear los ficheros
return 2;
when others =>
-- en otros casos retorna 3
return 3;
end Tratar_fichero;
|
with Ada.Calendar.Formatting;
with Ada.Characters.Latin_1;
with Ada.Environment_Variables;
with Ada.Exceptions.Finally;
with Ada.Directories.Temporary;
with Ada.Directories.Volumes;
with Ada.IO_Modes;
with Ada.Streams;
with System.Native_IO.Names; -- implementation unit
with C.errno;
with C.stdlib;
with C.string;
package body GNAT.OS_Lib is
use type Ada.Directories.File_Kind;
use type System.Native_IO.File_Mode;
-- (adaint.c)
function gnat_is_directory (Name : not null C.char_const_ptr)
return C.signed_int
with Export, Convention => C, External_Name => "__gnat_is_directory";
function gnat_is_directory (Name : not null C.char_const_ptr)
return C.signed_int
is
Length : constant Natural := Natural (C.string.strlen (Name));
Name_As_Ada : String (1 .. Length);
for Name_As_Ada'Address use Name.all'Address;
begin
return Boolean'Pos (Is_Directory (Name_As_Ada));
end gnat_is_directory;
function Get_File_Names_Case_Sensitive return C.signed_int
with Export,
Convention => C,
External_Name => "__gnat_get_file_names_case_sensitive";
function Get_File_Names_Case_Sensitive return C.signed_int is
FS : constant Ada.Directories.Volumes.File_System :=
Ada.Directories.Volumes.Where (Ada.Directories.Current_Directory);
begin
return Boolean'Pos (Ada.Directories.Volumes.Case_Sensitive (FS));
end Get_File_Names_Case_Sensitive;
-- Time/Date Stuff
procedure GM_Split (
Date : OS_Time;
Year : out Year_Type;
Month : out Month_Type;
Day : out Day_Type;
Hour : out Hour_Type;
Minute : out Minute_Type;
Second : out Second_Type)
is
Sub_Second : Ada.Calendar.Formatting.Second_Duration;
begin
Ada.Calendar.Formatting.Split (
Date,
Year => Year,
Month => Month,
Day => Day,
Hour => Hour,
Minute => Minute,
Second => Second,
Sub_Second => Sub_Second,
Time_Zone => 0); -- GMT
end GM_Split;
-- File Stuff
To_Native_Mode : constant
array (Ada.IO_Modes.File_Mode) of System.Native_IO.File_Mode := (
Ada.IO_Modes.In_File => System.Native_IO.Read_Only_Mode,
Ada.IO_Modes.Out_File => System.Native_IO.Write_Only_Mode,
Ada.IO_Modes.Append_File =>
System.Native_IO.Write_Only_Mode or System.Native_IO.Append_Mode);
procedure Do_Open (
Method : System.Native_IO.Open_Method;
FD : out File_Descriptor;
Mode : Ada.IO_Modes.File_Mode;
Name : String);
procedure Do_Open (
Method : System.Native_IO.Open_Method;
FD : out File_Descriptor;
Mode : Ada.IO_Modes.File_Mode;
Name : String)
is
package Holder is
new Ada.Exceptions.Finally.Scoped_Holder (
System.Native_IO.Name_Pointer,
System.Native_IO.Free);
X_Name : aliased System.Native_IO.Name_Pointer;
Handle : aliased System.Native_IO.Handle_Type;
begin
Holder.Assign (X_Name);
System.Native_IO.Names.Open_Ordinary (
Method => Method,
Handle => Handle,
Mode => To_Native_Mode (Mode),
Name => Name,
Out_Name => X_Name,
Form => (
Shared => Ada.IO_Modes.Allow, -- ???
Wait => False,
Overwrite => True));
FD := File_Descriptor (Handle);
end Do_Open;
procedure Close (FD : File_Descriptor) is
begin
System.Native_IO.Close_Ordinary (
System.Native_IO.Handle_Type (FD),
null,
Raise_On_Error => True);
end Close;
procedure Copy_File (
Name : String;
Pathname : String;
Success : out Boolean;
Mode : Copy_Mode := Copy;
Preserve : Attribute := Time_Stamps)
is
pragma Unreferenced (Preserve);
begin
Ada.Directories.Copy_File (
Name,
Pathname,
Overwrite => Mode = Overwrite);
Success := True;
exception
when Ada.Directories.Name_Error | Ada.Directories.Use_Error =>
Success := False;
end Copy_File;
procedure Copy_File_Attributes (
From : String;
To : String;
Success : out Boolean;
Copy_Timestamp : Boolean := True;
Copy_Permissions : Boolean := True) is
begin
raise Program_Error; -- unimplemented
end Copy_File_Attributes;
function Create_File (Name : String; Fmode : Mode) return File_Descriptor is
pragma Unreferenced (Fmode);
Result : File_Descriptor;
begin
Do_Open (System.Native_IO.Create, Result, Ada.IO_Modes.Out_File, Name);
return Result;
end Create_File;
procedure Create_Temp_File (
FD : out File_Descriptor;
Name : out Temp_File_Name)
is
Full_Name : constant String :=
Ada.Directories.Temporary.Create_Temporary_File (
Ada.Directories.Current_Directory);
S_First : Positive;
S_Last : Natural;
begin
Ada.Hierarchical_File_Names.Simple_Name (Full_Name,
First => S_First, Last => S_Last);
Name (1 .. S_Last - S_First + 1) := Full_Name (S_First .. S_Last);
for I in S_Last - S_First + 2 .. Name'Last loop
Name (I) := Ada.Characters.Latin_1.NUL;
end loop;
Do_Open (System.Native_IO.Create, FD, Ada.IO_Modes.Out_File, Name);
end Create_Temp_File;
procedure Create_Temp_File (
FD : out File_Descriptor;
Name : out String_Access)
is
package Holder is
new Ada.Exceptions.Finally.Scoped_Holder (
System.Native_IO.Name_Pointer,
System.Native_IO.Free);
X_Name : aliased System.Native_IO.Name_Pointer;
Handle : aliased System.Native_IO.Handle_Type;
begin
Holder.Assign (X_Name);
System.Native_IO.Open_Temporary (Handle, X_Name);
FD := File_Descriptor (Handle);
Name := new String'(System.Native_IO.Value (X_Name));
end Create_Temp_File;
procedure Delete_File (Name : String; Success : out Boolean) is
begin
Ada.Directories.Delete_File (Name);
exception
when Ada.Directories.Name_Error | Ada.Directories.Use_Error =>
Success := False;
end Delete_File;
function File_Length (FD : File_Descriptor) return Long_Integer is
begin
return Long_Integer (
System.Native_IO.Size (System.Native_IO.Handle_Type (FD)));
end File_Length;
function File_Time_Stamp (Name : String) return OS_Time is
begin
return Ada.Directories.Modification_Time (Name);
end File_Time_Stamp;
function Is_Directory (Name : String) return Boolean is
begin
return Ada.Directories.Exists (Name)
and then Ada.Directories.Kind (Name) = Ada.Directories.Directory;
end Is_Directory;
function Is_Regular_File (Name : String) return Boolean is
begin
return Ada.Directories.Exists (Name)
and then Ada.Directories.Kind (Name) = Ada.Directories.Ordinary_File;
end Is_Regular_File;
function Is_Writable_File (Name : String) return Boolean is
begin
return Ada.Directories.Information.User_Permission_Set (Name)
(Ada.Directories.Information.User_Write);
end Is_Writable_File;
function Locate_Exec_On_Path (Exec_Name : String) return String_Access is
begin
raise Program_Error; -- unimplemented
return Locate_Exec_On_Path (Exec_Name);
end Locate_Exec_On_Path;
function Locate_Regular_File (File_Name : String; Path : String)
return String_Access is
begin
raise Program_Error; -- unimplemented
return Locate_Regular_File (File_Name, Path);
end Locate_Regular_File;
procedure Lseek (
FD : File_Descriptor;
offset : Long_Integer;
origin : Integer)
is
Whence : System.Native_IO.Whence_Type;
Dummy : Ada.Streams.Stream_Element_Offset;
begin
case origin is
when Seek_Set =>
Whence := System.Native_IO.From_Begin;
when Seek_Cur =>
Whence := System.Native_IO.From_Current;
when Seek_End =>
Whence := System.Native_IO.From_End;
when others =>
raise Constraint_Error;
end case;
System.Native_IO.Set_Relative_Index (
System.Native_IO.Handle_Type (FD),
Ada.Streams.Stream_Element_Offset (offset),
Whence,
Dummy);
end Lseek;
function Normalize_Pathname (
Name : String;
Directory : String := "";
Resolve_Links : Boolean := True;
Case_Sensitive : Boolean := True)
return String
is
pragma Unreferenced (Case_Sensitive);
pragma Unreferenced (Resolve_Links);
begin
if Ada.Hierarchical_File_Names.Is_Full_Name (Name) then
return Name;
elsif Directory'Length = 0 then
return Ada.Hierarchical_File_Names.Normalized_Compose (
Ada.Directories.Current_Directory,
Name);
else
return Ada.Hierarchical_File_Names.Normalized_Compose (
Directory,
Name);
end if;
end Normalize_Pathname;
function Open_Read (Name : String; Fmode : Mode) return File_Descriptor is
pragma Unreferenced (Fmode);
Result : File_Descriptor;
begin
Do_Open (System.Native_IO.Open, Result, Ada.IO_Modes.In_File, Name);
return Result;
end Open_Read;
function Open_Read_Write (Name : String; Fmode : Mode)
return File_Descriptor
is
pragma Unreferenced (Fmode);
Result : File_Descriptor;
begin
Do_Open (
System.Native_IO.Open,
Result,
Ada.IO_Modes.Append_File, -- Inout_File
Name);
return Result;
end Open_Read_Write;
function Read (FD : File_Descriptor; A : System.Address; N : Integer)
return Integer
is
Result : Ada.Streams.Stream_Element_Offset;
begin
System.Native_IO.Read (
System.Native_IO.Handle_Type (FD),
A,
Ada.Streams.Stream_Element_Offset (N),
Out_Length => Result);
return Integer (Result);
end Read;
procedure Rename_File (
Old_Name : String;
New_Name : String;
Success : out Boolean) is
begin
Ada.Directories.Rename (Old_Name => Old_Name, New_Name => New_Name);
Success := True;
exception
when Ada.Directories.Name_Error | Ada.Directories.Use_Error =>
Success := False;
end Rename_File;
procedure Set_Non_Readable (Name : String) is
begin
raise Program_Error; -- unimplemented
end Set_Non_Readable;
procedure Set_Non_Writable (Name : String) is
begin
raise Program_Error; -- unimplemented
end Set_Non_Writable;
procedure Set_Readable (Name : String) is
begin
raise Program_Error; -- unimplemented
end Set_Readable;
procedure Set_Writable (Name : String) is
begin
raise Program_Error; -- unimplemented
end Set_Writable;
function Write (FD : File_Descriptor; A : System.Address; N : Integer)
return Integer
is
Result : Ada.Streams.Stream_Element_Offset;
begin
System.Native_IO.Write (
System.Native_IO.Handle_Type (FD),
A,
Ada.Streams.Stream_Element_Offset (N),
Out_Length => Result);
return Integer (Result);
end Write;
-- Miscellaneous
function Errno return Integer is
begin
return Integer (C.errno.errno);
end Errno;
function Getenv (Name : String) return String_Access is
begin
return new String'(Ada.Environment_Variables.Value (Name, ""));
end Getenv;
procedure OS_Exit (Status : Integer) is
begin
C.stdlib.C_exit (C.signed_int (Status));
end OS_Exit;
end GNAT.OS_Lib;
|
with AdaBase;
with Connect;
with CommonText;
with Ada.Text_IO;
with AdaBase.Results.Sets;
procedure Query_Select is
package CON renames Connect;
package TIO renames Ada.Text_IO;
package ARS renames AdaBase.Results.Sets;
package AR renames AdaBase.Results;
package CT renames CommonText;
begin
CON.connect_database;
CON.DR.set_trait_column_case (AdaBase.upper_case);
declare
stmt : CON.Stmt_Type := CON.DR.query_select
(tables => "nhl_schedule as S " &
"JOIN nhl_teams T1 ON S.home_team = T1.team_id " &
"JOIN nhl_teams T2 ON S.away_team = T2.team_id",
columns => "S.event_code, " &
"T1.city as home_city, " &
"T1.mascot as home_mascot, " &
"T1.abbreviation as home_short, " &
"S.home_score, " &
"T2.city as away_city, " &
"T2.mascot as away_mascot, " &
"T2.abbreviation as away_short, " &
"S.away_score",
conditions => "S.yyyswww < 1085011",
order => "S.yyyswww ASC",
limit => 10,
offset => 20);
begin
if not stmt.successful then
TIO.Put_Line (" Driver message: " & stmt.last_driver_message);
TIO.Put_Line (" Driver code: " & stmt.last_driver_code'Img);
TIO.Put_Line (" SQL State: " & stmt.last_sql_state);
else
for c in Natural range 1 .. stmt.column_count loop
TIO.Put_Line ("Column" & c'Img & " heading: " &
stmt.column_name (c));
end loop;
TIO.Put_Line ("");
end if;
-- Demonstrate bind/fetch_bound
declare
event_code : aliased AR.NByte2;
home_town, home_mascot : aliased AR.Textual;
away_town, away_mascot : aliased AR.Textual;
home_score, away_score : aliased AR.NByte1;
begin
stmt.bind (1, event_code'Unchecked_Access);
stmt.bind ("HOME_CITY", home_town'Unchecked_Access);
stmt.bind ("AWAY_CITY", away_town'Unchecked_Access);
stmt.bind (3, home_mascot'Unchecked_Access);
stmt.bind ("AWAY_MASCOT", away_mascot'Unchecked_Access);
stmt.bind ("HOME_SCORE", home_score'Unchecked_Access);
stmt.bind ("AWAY_SCORE", away_score'Unchecked_Access);
loop
exit when not stmt.fetch_bound;
TIO.Put ("In event" & event_code'Img & ", the " &
CT.USS (away_town) & " " & CT.USS (away_mascot) &
" visited the " &
CT.USS (home_town) & " " & CT.USS (home_mascot) &
" and ");
if Integer (away_score) > Integer (home_score) then
TIO.Put ("won");
elsif Integer (away_score) < Integer (home_score) then
TIO.Put ("lost");
else
TIO.Put ("tied");
end if;
TIO.Put_Line (away_score'Img & " to" & home_score'Img);
end loop;
TIO.Put_Line ("");
end;
end;
declare
-- demonstrate fetch_all
stmt : CON.Stmt_Type := CON.DR.query_select
(tables => "fruits",
columns => "fruit, calories, color",
conditions => "calories > 50",
order => "calories",
limit => 10);
rowset : ARS.Datarow_Set := stmt.fetch_all;
begin
for row in Natural range 1 .. rowset'Length loop
TIO.Put_Line (rowset (row).column (1).as_string & ":" &
rowset (row).column ("calories").as_nbyte2'Img &
" calories, " & rowset (row).column (3).as_string);
end loop;
end;
CON.DR.disconnect;
end Query_Select;
|
with Ada.Strings; use Ada.Strings;
with Ada.Strings.Fixed; use Ada.Strings.Fixed;
with Langkit_Support.Text; use Langkit_Support.Text;
package body Rejuvenation.Node_Locations is
-- We postulate that a ghost node is not surrounded by trivia.
-- A ghost node has a range from X to X-1,
-- where X is the start position of the next token.
-- The Text corresponding to a ghost node is, of couse, the empty string.
-- See also https://gt3-prod-2.adacore.com/#/tickets/UA12-003
function Node_Start_Offset (Node : Ada_Node'Class) return Positive with
Pre => not Is_Ghost (Node);
function Node_Start_Offset (Node : Ada_Node'Class) return Positive is
begin
return Raw_Data (Node.Token_Start).Source_First;
end Node_Start_Offset;
function Line_Start_Offset (Node : Ada_Node'Class) return Positive with
Pre => not Is_Ghost (Node);
function Line_Start_Offset (Node : Ada_Node'Class) return Positive is
function Line_Start_Offset
(Token : Token_Reference; Offset : Integer) return Integer;
-- In Ada comment is ended by a line feed
-- So a token cannot be preceeded by a comment on the same line
function Line_Start_Offset
(Token : Token_Reference; Offset : Integer) return Integer
is
begin
if Token /= No_Token and then Kind (Data (Token)) = Ada_Whitespace
then
declare
Token_Text : constant String :=
Encode (Text (Token), Node.Unit.Get_Charset);
Pos : constant Natural :=
Index (Token_Text, (1 => ASCII.LF), Going => Backward);
begin
if Pos = 0 then
return
Line_Start_Offset
(Previous (Token), Offset - Token_Text'Length);
else
return
Raw_Data (Token).Source_First + Pos + 1 - Token_Text'First;
end if;
end;
else
return Offset;
end if;
end Line_Start_Offset;
begin
return
Line_Start_Offset
(Previous (Node.Token_Start), Node_Start_Offset (Node));
end Line_Start_Offset;
function Trivia_Start_Offset (Node : Ada_Node'Class) return Positive with
Pre => not Is_Ghost (Node);
function Trivia_Start_Offset (Node : Ada_Node'Class) return Positive is
function Trivia_Start_Offset
(Token : Token_Reference; Nr : Integer) return Integer;
function Trivia_Start_Offset
(Token : Token_Reference; Nr : Integer) return Integer
is
begin
if Token /= No_Token
and then Kind (Data (Token)) in Ada_Whitespace | Ada_Comment
then
return
Trivia_Start_Offset
(Previous (Token), Raw_Data (Token).Source_First);
else
return Nr;
end if;
end Trivia_Start_Offset;
begin
return
Trivia_Start_Offset
(Previous (Node.Token_Start), Node_Start_Offset (Node));
end Trivia_Start_Offset;
function Start_Offset
(Node : Ada_Node'Class; Before : Node_Location := No_Trivia)
return Positive
is
begin
if Is_Ghost (Node) then
return Raw_Data (Node.Token_Start).Source_First;
else
case Before is
when No_Trivia =>
return Node_Start_Offset (Node);
when Trivia_On_Same_Line =>
return Line_Start_Offset (Node);
when All_Trivia =>
return Trivia_Start_Offset (Node);
end case;
end if;
end Start_Offset;
function Node_End_Offset (Node : Ada_Node'Class) return Natural with
Pre => not Is_Ghost (Node);
function Node_End_Offset (Node : Ada_Node'Class) return Natural is
begin
return Raw_Data (Node.Token_End).Source_Last;
end Node_End_Offset;
function Line_End_Offset (Node : Ada_Node'Class) return Natural with
Pre => not Is_Ghost (Node);
function Line_End_Offset (Node : Ada_Node'Class) return Natural is
function Line_End_Offset
(Token : Token_Reference; Offset : Integer) return Integer;
function Line_End_Offset
(Token : Token_Reference; Offset : Integer) return Integer
is
begin
if Token /= No_Token
and then Kind (Data (Token)) in Ada_Whitespace | Ada_Comment
then
declare
Token_Text : constant String :=
Encode (Text (Token), Node.Unit.Get_Charset);
Pos : constant Natural := Index (Token_Text, (1 => ASCII.LF));
begin
if Pos = 0 then
return
Line_End_Offset (Next (Token), Offset + Token_Text'Length);
else
return
Raw_Data (Token).Source_First + Pos - Token_Text'First;
end if;
end;
else
return Offset;
end if;
end Line_End_Offset;
begin
return Line_End_Offset (Next (Node.Token_End), Node_End_Offset (Node));
end Line_End_Offset;
function Trivia_End_Offset (Node : Ada_Node'Class) return Natural with
Pre => not Is_Ghost (Node);
function Trivia_End_Offset (Node : Ada_Node'Class) return Natural
is
function Trivia_End_Offset
(Token : Token_Reference; Nr : Natural) return Natural;
function Trivia_End_Offset
(Token : Token_Reference; Nr : Natural) return Natural
is
begin
if Token /= No_Token
and then Kind (Data (Token)) in Ada_Whitespace | Ada_Comment
then
return
Trivia_End_Offset (Next (Token), Raw_Data (Token).Source_Last);
else
return Nr;
end if;
end Trivia_End_Offset;
begin
return Trivia_End_Offset (Next (Node.Token_End), Node_End_Offset (Node));
end Trivia_End_Offset;
function End_Offset
(Node : Ada_Node'Class; After : Node_Location := No_Trivia) return Natural
is
begin
if Is_Ghost (Node) then
return Raw_Data (Node.Token_Start).Source_First - 1;
else
case After is
when No_Trivia =>
return Node_End_Offset (Node);
when Trivia_On_Same_Line =>
return Line_End_Offset (Node);
when All_Trivia =>
return Trivia_End_Offset (Node);
end case;
end if;
end End_Offset;
end Rejuvenation.Node_Locations;
|
------------------------------------------------------------------------------
-- --
-- GNAT LIBRARY COMPONENTS --
-- --
-- A D A . C O N T A I N E R S . H E L P E R S --
-- --
-- B o d y --
-- --
-- Copyright (C) 2015-2020, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. --
-- --
-- As a special exception under Section 7 of GPL version 3, you are granted --
-- additional permissions described in the GCC Runtime Library Exception, --
-- version 3.1, as published by the Free Software Foundation. --
-- --
-- You should have received a copy of the GNU General Public License and --
-- a copy of the GCC Runtime Library Exception along with this program; --
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
-- <http://www.gnu.org/licenses/>. --
------------------------------------------------------------------------------
package body Ada.Containers.Helpers is
package body Generic_Implementation is
use type SAC.Atomic_Unsigned;
------------
-- Adjust --
------------
procedure Adjust (Control : in out Reference_Control_Type) is
begin
if Control.T_Counts /= null then
Busy (Control.T_Counts.all);
end if;
end Adjust;
----------
-- Busy --
----------
procedure Busy (T_Counts : in out Tamper_Counts) is
begin
if T_Check then
SAC.Increment (T_Counts.Busy);
end if;
end Busy;
--------------
-- Finalize --
--------------
procedure Finalize (Control : in out Reference_Control_Type) is
begin
if Control.T_Counts /= null then
Unbusy (Control.T_Counts.all);
Control.T_Counts := null;
end if;
end Finalize;
-- No need to protect against double Finalize here, because these types
-- are limited.
procedure Finalize (Busy : in out With_Busy) is
pragma Warnings (Off);
pragma Assert (T_Check); -- not called if check suppressed
pragma Warnings (On);
begin
Unbusy (Busy.T_Counts.all);
end Finalize;
procedure Finalize (Lock : in out With_Lock) is
pragma Warnings (Off);
pragma Assert (T_Check); -- not called if check suppressed
pragma Warnings (On);
begin
Unlock (Lock.T_Counts.all);
end Finalize;
----------------
-- Initialize --
----------------
procedure Initialize (Busy : in out With_Busy) is
pragma Warnings (Off);
pragma Assert (T_Check); -- not called if check suppressed
pragma Warnings (On);
begin
Generic_Implementation.Busy (Busy.T_Counts.all);
end Initialize;
procedure Initialize (Lock : in out With_Lock) is
pragma Warnings (Off);
pragma Assert (T_Check); -- not called if check suppressed
pragma Warnings (On);
begin
Generic_Implementation.Lock (Lock.T_Counts.all);
end Initialize;
----------
-- Lock --
----------
procedure Lock (T_Counts : in out Tamper_Counts) is
begin
if T_Check then
SAC.Increment (T_Counts.Lock);
SAC.Increment (T_Counts.Busy);
end if;
end Lock;
--------------
-- TC_Check --
--------------
procedure TC_Check (T_Counts : Tamper_Counts) is
begin
if T_Check and then T_Counts.Busy > 0 then
raise Program_Error with
"attempt to tamper with cursors";
end if;
-- The lock status (which monitors "element tampering") always
-- implies that the busy status (which monitors "cursor tampering")
-- is set too; this is a representation invariant. Thus if the busy
-- bit is not set, then the lock bit must not be set either.
pragma Assert (T_Counts.Lock = 0);
end TC_Check;
--------------
-- TE_Check --
--------------
procedure TE_Check (T_Counts : Tamper_Counts) is
begin
if T_Check and then T_Counts.Lock > 0 then
raise Program_Error with
"attempt to tamper with elements";
end if;
end TE_Check;
------------
-- Unbusy --
------------
procedure Unbusy (T_Counts : in out Tamper_Counts) is
begin
if T_Check then
SAC.Decrement (T_Counts.Busy);
end if;
end Unbusy;
------------
-- Unlock --
------------
procedure Unlock (T_Counts : in out Tamper_Counts) is
begin
if T_Check then
SAC.Decrement (T_Counts.Lock);
SAC.Decrement (T_Counts.Busy);
end if;
end Unlock;
-----------------
-- Zero_Counts --
-----------------
procedure Zero_Counts (T_Counts : out Tamper_Counts) is
begin
if T_Check then
T_Counts := (others => <>);
end if;
end Zero_Counts;
end Generic_Implementation;
end Ada.Containers.Helpers;
|
with Interfaces; use Interfaces;
with STM32_SVD; use STM32_SVD;
with Drivers.Text_IO;
with STM32GD.Board;
with Drivers.Si7060;
procedure Main is
package Temp_Sensor is new Drivers.Si7060 (Address => 16#32#, I2C => STM32GD.Board.I2C);
package Text_IO is new Drivers.Text_IO (USART => STM32GD.Board.USART);
Line : String (1 .. 8);
Len : Natural;
Temperature : Integer;
begin
STM32GD.Board.Init;
STM32GD.Board.LED.Set;
if not Temp_Sensor.Init then
Text_IO.Put_Line ("Sensor not found");
loop STM32GD.Wait_For_Interrupt; end loop;
end if;
loop
Text_IO.Put_Line ("Press <enter> to measure");
Text_IO.Get_Line (Line, Len);
STM32GD.Board.LED.Toggle;
if Temp_Sensor.Temperature_x100 (Temperature) then
Text_IO.Put_Integer (Temperature);
Text_IO.New_Line;
end if;
end loop;
end Main;
|
pragma Ada_2012;
with Ada.Unchecked_Deallocation;
package body Dsp.Ring_Filters is
procedure Free is
new Ada.Unchecked_Deallocation (Object => Sample_Array,
Name => Sample_Array_Access);
procedure Free is
new Ada.Unchecked_Deallocation (Object => Coefficient_Array,
Name => Coefficient_Array_Access);
-----------
-- Apply --
-----------
function Apply
(F : Signal;
From, To : Integer)
return Sample_Array
is
Result : Sample_Array (From .. To);
begin
for T in Result'Range loop
Result (T) := F (T);
end loop;
return Result;
end Apply;
------------
-- Filter --
------------
function Filter
(Item : in out Ring_Filter_Interface'Class;
Input : Sample_Array;
Keep_Status : Boolean := False)
return Sample_Array
is
Result : Sample_Array (Input'Range);
begin
if not Keep_Status then
Item.Reset;
end if;
for T in Input'Range loop
Result (T) := Item.Filter (Input (T));
end loop;
return Result;
end Filter;
-----------
-- Reset --
-----------
procedure Reset (Item : in out Ring_FIR) is
begin
pragma Assert (Item.Status /= Unready);
Item.Buffer.all := (others => Zero);
Item.Current_Status := Ready;
end Reset;
------------
-- Filter --
------------
function Filter
(Item : in out Ring_FIR;
Input : Sample_Type)
return Sample_Type
is
Result : constant Sample_Type := Item.Spec (0) * Input + Item.Buffer (1);
Len : constant Positive := Item.Buffer'Last;
begin
pragma Assert (Item.Spec.all'First = 0
and Item.Buffer.all'First = 1
and Item.Buffer.all'Last = Item.Spec.all'Last);
for K in 1 .. Len - 1 loop
Item.Buffer (K) := Item.Buffer (K + 1) + Item.Spec (K) * Input;
end loop;
Item.Buffer (Len) := Item.Spec (Len) * Input;
Item.Current_Status := Running;
return Result;
end Filter;
---------
-- Set --
---------
procedure Set
(Filter : in out Ring_FIR;
Impulse_Response : Coefficient_Array)
is
begin
Filter.Buffer := new Sample_Array (1 .. Impulse_Response'Last);
Filter.Buffer.all := (others => Zero);
Filter.Spec := new Coefficient_Array (0 .. Impulse_Response'Last);
Filter.Spec.all := (others => Zero_Coeff);
for K in Impulse_Response'Range loop
Filter.Spec (K) := Impulse_Response (K);
end loop;
Filter.Current_Status := Ready;
end Set;
-----------
-- Reset --
-----------
procedure Reset (Item : in out Ring_IIR) is
begin
pragma Assert (Item.Status /= Unready);
Item.Buffer.all := (others => Zero);
Item.Current_Status := Ready;
end Reset;
------------
-- Filter --
------------
function Filter
(Item : in out Ring_IIR;
Input : Sample_Type)
return Sample_Type
is
Result : constant Sample_Type := Item.Num (0) * Input + Item.Buffer (1);
Len : constant Positive := Item.Buffer'Last;
begin
pragma Assert (Item.Num.all'First = 0
and Item.Den.all'First = 1
and Item.Buffer.all'First = 1
and Item.Buffer.all'Last = Item.Num.all'Last
and Item.Buffer.all'Last = Item.Den.all'Last);
for K in 1 .. Len - 1 loop
Item.Buffer (K) := Item.Buffer (K + 1)
+ Item.Num (K) * Input
- Item.Den (K) * Result;
end loop;
Item.Buffer (Len) := Item.Num (Len) * Input - Item.Den (Len) * Result;
Item.Current_Status := Running;
return Result;
end Filter;
---------
-- Set --
---------
procedure Set
(Filter : in out Ring_IIR;
Specs : Ring_IIR_Spec)
is
Last : constant Positive := Positive'Max (Specs.Num_Deg, Specs.Den_Deg);
begin
Filter.Buffer := new Sample_Array (1 .. Last);
Filter.Buffer.all := (others => Zero);
Filter.Num := new Coefficient_Array (0 .. Last);
Filter.Num.all := (others => Zero_Coeff);
for K in Specs.Numerator'Range loop
Filter.Num (K) := Specs.Numerator (K);
end loop;
Filter.Den := new Coefficient_Array (1 .. Last);
Filter.Den.all := (others => Zero_Coeff);
for K in Specs.Denominator'Range loop
Filter.Den (K) := Specs.Denominator (K);
end loop;
filter.Current_Status := Ready;
end Set;
---------
-- Set --
---------
procedure Set
(Filter : in out Ring_IIR;
Numerator : Coefficient_Array;
Denominator : Coefficient_Array)
is
Tmp : Ring_IIR_Spec := (Num_Deg => Numerator'Last,
Den_Deg => Denominator'Last,
Numerator => (others => Zero_Coeff),
Denominator => (others => Zero_Coeff));
begin
for K in Integer'Max (Tmp.Numerator'First, Numerator'First) .. Numerator'Last loop
Tmp.Numerator (K) := Numerator (K);
end loop;
for K in Integer'Max (Tmp.Denominator'First, Denominator'First) .. Denominator'Last loop
Tmp.Denominator (K) := Denominator (K);
end loop;
Filter.Set (Tmp);
end Set;
--------------
-- Finalize --
--------------
overriding procedure Finalize (Object : in out Ring_FIR) is
begin
if Object.Spec /= null then
pragma Assert (Object.Buffer /= null);
Free (Object.Spec);
Free (Object.Buffer);
end if;
end Finalize;
--------------
-- Finalize --
--------------
overriding procedure Finalize (Object : in out Ring_IIR) is
begin
if Object.Num /= null then
pragma Assert (Object.Buffer /= null);
Free (Object.Num);
Free (Object.Den);
Free (Object.Buffer);
end if;
end Finalize;
end Dsp.Ring_Filters;
|
separate (Numerics.Sparse_Matrices)
function Permute_By_Col (Mat : in Sparse_Matrix;
P : in Int_Array) return Sparse_Matrix is
Result : Sparse_Matrix;
Tmp : Nat := 1;
use Ada.Text_IO;
begin
pragma Assert (Mat.Format = CSC);
pragma Assert (P'Length = Integer (Mat.P.Length) - 1);
Result.Format := CSC;
Result.N_Row := Mat.N_Row;
Result.N_Col := Mat.N_Col;
Result.X.Reserve_Capacity (Mat.X.Length);
Result.I.Reserve_Capacity (Mat.I.Length);
Result.P.Reserve_Capacity (Mat.P.Length);
for J of P loop
for K in Mat.P (J) .. Mat.P (J + 1) - 1 loop
Result.X.Append (Mat.X (K));
Result.I.Append (Mat.I (K));
end loop;
Result.P.Append (Tmp);
Tmp := Tmp + Mat.P (J + 1) - Mat.P (J);
end loop;
Result.P.Append (Tmp);
return Result;
end Permute_By_Col;
|
with Plop;
procedure Hello is
B : Plop.B;
C : Plop.C;
begin
Plop.Print (B);
Plop.Print (C);
end Hello;
|
-----------------------------------------------------------------------
-- search-tokenizers -- Search engine tokenizers
-- Copyright (C) 2020 Stephane Carrez
-- Written by Stephane Carrez (Stephane.Carrez@gmail.com)
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-----------------------------------------------------------------------
with Ada.Finalization;
with Util.Streams;
private with Util.Strings.Builders;
private with Ada.Streams;
-- == Tokenizers ==
-- Tokenizers read the input stream to identify the token string and give them
-- to the analyzer.
package Search.Tokenizers is
type Consumer_Type is limited Interface;
procedure Push_Token (Filter : in out Consumer_Type;
Token : in String;
Consumer : not null
access procedure (Token : in String)) is abstract;
type Tokenizer_Type is limited new Ada.Finalization.Limited_Controlled with private;
overriding
procedure Initialize (Lexer : in out Tokenizer_Type);
procedure Parse (Lexer : in out Tokenizer_Type;
Stream : in out Util.Streams.Input_Stream'Class;
Filter : in out Consumer_Type'Class;
Consumer : not null
access procedure (Token : in String));
procedure Fill (Lexer : in out Tokenizer_Type;
Stream : in out Util.Streams.Input_Stream'Class);
procedure Skip_Spaces (Lexer : in out Tokenizer_Type;
Stream : in out Util.Streams.Input_Stream'Class);
procedure Read_Token (Lexer : in out Tokenizer_Type;
Stream : in out Util.Streams.Input_Stream'Class);
private
subtype Lexer_Offset is Ada.Streams.Stream_Element_Offset;
type Element_Bitmap is array (Ada.Streams.Stream_Element) of Boolean with Pack;
type Element_Bitmap_Access is access all Element_Bitmap;
type Tokenizer_Type is limited new Ada.Finalization.Limited_Controlled with record
Separators : Element_Bitmap;
Pos : Lexer_Offset := 0;
Last : Lexer_Offset := 0;
Buffer : Ada.Streams.Stream_Element_Array (1 .. 1024);
Text : Util.Strings.Builders.Builder (128);
end record;
end Search.Tokenizers;
|
-- Copyright 2017 Steven Stewart-Gallus
--
-- 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.
-- Memory ordering stuff isn't understood by SPARK and can be used to
-- produce unsafe code.
package Linted.GCC_Atomics with
Spark_Mode => Off is
pragma Pure;
type Memory_Order is
(Memory_Order_Relaxed,
Memory_Order_Consume,
Memory_Order_Acquire,
Memory_Order_Release,
Memory_Order_Acq_Rel,
Memory_Order_Seq_Cst);
procedure Thread_Fence (Order : Memory_Order) with
Inline_Always;
procedure Signal_Fence (Order : Memory_Order) with
Inline_Always;
generic
type Element_T is private;
package Atomic_Ts with
Spark_Mode => Off is
type Atomic is limited private;
procedure Store
(A : in out Atomic;
Element : Element_T;
Order : Memory_Order := Memory_Order_Seq_Cst) with
Inline_Always;
function Load
(A : Atomic;
Order : Memory_Order := Memory_Order_Seq_Cst) return Element_T with
Inline_Always;
function Compare_Exchange_Strong
(A : in out Atomic;
Old_Element : Element_T;
New_Element : Element_T;
Success_Order : Memory_Order := Memory_Order_Seq_Cst;
Failure_Order : Memory_Order :=
Memory_Order_Seq_Cst)
return Boolean with
Inline_Always;
function Compare_Exchange_Weak
(A : in out Atomic;
Old_Element : Element_T;
New_Element : Element_T;
Success_Order : Memory_Order := Memory_Order_Seq_Cst;
Failure_Order : Memory_Order :=
Memory_Order_Seq_Cst)
return Boolean with
Inline_Always;
function Exchange
(A : in out Atomic;
New_Element : Element_T;
Order : Memory_Order := Memory_Order_Seq_Cst) return Element_T with
Inline_Always;
private
-- A record has to be used so that it is passed by pointer
type Atomic is record
Value : Element_T;
end record;
pragma Convention (C, Atomic);
end Atomic_Ts;
end Linted.GCC_Atomics;
|
-- Copyright (c) 2019 Maxim Reznik <reznikmm@gmail.com>
--
-- SPDX-License-Identifier: MIT
-- License-Filename: LICENSE
-------------------------------------------------------------
package body Slim.Menu_Commands.Play_File_Commands is
---------
-- Run --
---------
overriding procedure Run (Self : Play_File_Command) is
Value : Slim.Players.Song_Array (1 .. Self.Title_List.Length);
begin
for J in Value'Range loop
Value (J) := (Self.Relative_Path_List (J), Self.Title_List (J));
end loop;
Self.Player.Play_Files
(Self.Root, Self.M3U_Name, Value, Self.Start, Skip => Self.Skip);
end Run;
end Slim.Menu_Commands.Play_File_Commands;
|
pragma Ada_2005;
pragma Style_Checks (Off);
with Interfaces.C; use Interfaces.C;
with asm_generic_int_ll64_h;
package linux_ptrace_h is
PTRACE_TRACEME : constant := 0; -- /usr/include/linux/ptrace.h:11
PTRACE_PEEKTEXT : constant := 1; -- /usr/include/linux/ptrace.h:12
PTRACE_PEEKDATA : constant := 2; -- /usr/include/linux/ptrace.h:13
PTRACE_PEEKUSR : constant := 3; -- /usr/include/linux/ptrace.h:14
PTRACE_POKETEXT : constant := 4; -- /usr/include/linux/ptrace.h:15
PTRACE_POKEDATA : constant := 5; -- /usr/include/linux/ptrace.h:16
PTRACE_POKEUSR : constant := 6; -- /usr/include/linux/ptrace.h:17
PTRACE_CONT : constant := 7; -- /usr/include/linux/ptrace.h:18
PTRACE_KILL : constant := 8; -- /usr/include/linux/ptrace.h:19
PTRACE_SINGLESTEP : constant := 9; -- /usr/include/linux/ptrace.h:20
PTRACE_ATTACH : constant := 16; -- /usr/include/linux/ptrace.h:22
PTRACE_DETACH : constant := 17; -- /usr/include/linux/ptrace.h:23
PTRACE_SYSCALL : constant := 24; -- /usr/include/linux/ptrace.h:25
PTRACE_SETOPTIONS : constant := 16#4200#; -- /usr/include/linux/ptrace.h:28
PTRACE_GETEVENTMSG : constant := 16#4201#; -- /usr/include/linux/ptrace.h:29
PTRACE_GETSIGINFO : constant := 16#4202#; -- /usr/include/linux/ptrace.h:30
PTRACE_SETSIGINFO : constant := 16#4203#; -- /usr/include/linux/ptrace.h:31
PTRACE_GETREGSET : constant := 16#4204#; -- /usr/include/linux/ptrace.h:50
PTRACE_SETREGSET : constant := 16#4205#; -- /usr/include/linux/ptrace.h:51
PTRACE_SEIZE : constant := 16#4206#; -- /usr/include/linux/ptrace.h:53
PTRACE_INTERRUPT : constant := 16#4207#; -- /usr/include/linux/ptrace.h:54
PTRACE_LISTEN : constant := 16#4208#; -- /usr/include/linux/ptrace.h:55
PTRACE_PEEKSIGINFO : constant := 16#4209#; -- /usr/include/linux/ptrace.h:57
PTRACE_GETSIGMASK : constant := 16#420a#; -- /usr/include/linux/ptrace.h:65
PTRACE_SETSIGMASK : constant := 16#420b#; -- /usr/include/linux/ptrace.h:66
PTRACE_SECCOMP_GET_FILTER : constant := 16#420c#; -- /usr/include/linux/ptrace.h:68
PTRACE_SECCOMP_GET_METADATA : constant := 16#420d#; -- /usr/include/linux/ptrace.h:69
PTRACE_PEEKSIGINFO_SHARED : constant := (2 ** 0); -- /usr/include/linux/ptrace.h:77
PTRACE_EVENT_FORK : constant := 1; -- /usr/include/linux/ptrace.h:80
PTRACE_EVENT_VFORK : constant := 2; -- /usr/include/linux/ptrace.h:81
PTRACE_EVENT_CLONE : constant := 3; -- /usr/include/linux/ptrace.h:82
PTRACE_EVENT_EXEC : constant := 4; -- /usr/include/linux/ptrace.h:83
PTRACE_EVENT_VFORK_DONE : constant := 5; -- /usr/include/linux/ptrace.h:84
PTRACE_EVENT_EXIT : constant := 6; -- /usr/include/linux/ptrace.h:85
PTRACE_EVENT_SECCOMP : constant := 7; -- /usr/include/linux/ptrace.h:86
PTRACE_EVENT_STOP : constant := 128; -- /usr/include/linux/ptrace.h:88
PTRACE_O_TRACESYSGOOD : constant := 1; -- /usr/include/linux/ptrace.h:91
-- unsupported macro: PTRACE_O_TRACEFORK (1 << PTRACE_EVENT_FORK)
-- unsupported macro: PTRACE_O_TRACEVFORK (1 << PTRACE_EVENT_VFORK)
-- unsupported macro: PTRACE_O_TRACECLONE (1 << PTRACE_EVENT_CLONE)
-- unsupported macro: PTRACE_O_TRACEEXEC (1 << PTRACE_EVENT_EXEC)
-- unsupported macro: PTRACE_O_TRACEVFORKDONE (1 << PTRACE_EVENT_VFORK_DONE)
-- unsupported macro: PTRACE_O_TRACEEXIT (1 << PTRACE_EVENT_EXIT)
-- unsupported macro: PTRACE_O_TRACESECCOMP (1 << PTRACE_EVENT_SECCOMP)
PTRACE_O_EXITKILL : constant := (2 ** 20); -- /usr/include/linux/ptrace.h:101
PTRACE_O_SUSPEND_SECCOMP : constant := (2 ** 21); -- /usr/include/linux/ptrace.h:102
-- unsupported macro: PTRACE_O_MASK ( 0x000000ff | PTRACE_O_EXITKILL | PTRACE_O_SUSPEND_SECCOMP)
-- SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note
-- ptrace.h
-- structs and defines to help the user use the ptrace system call.
-- has the defines to get at the registers.
-- 0x4200-0x4300 are reserved for architecture-independent additions.
-- * Generic ptrace interface that exports the architecture specific regsets
-- * using the corresponding NT_* types (which are also used in the core dump).
-- * Please note that the NT_PRSTATUS note type in a core dump contains a full
-- * 'struct elf_prstatus'. But the user_regset for NT_PRSTATUS contains just the
-- * elf_gregset_t that is the pr_reg field of 'struct elf_prstatus'. For all the
-- * other user_regset flavors, the user_regset layout and the ELF core dump note
-- * payload are exactly the same layout.
-- *
-- * This interface usage is as follows:
-- * struct iovec iov = { buf, len};
-- *
-- * ret = ptrace(PTRACE_GETREGSET/PTRACE_SETREGSET, pid, NT_XXX_TYPE, &iov);
-- *
-- * On the successful completion, iov.len will be updated by the kernel,
-- * specifying how much the kernel has written/read to/from the user's iov.buf.
--
-- from which siginfo to start
type ptrace_peeksiginfo_args is record
off : aliased asm_generic_int_ll64_h.uu_u64; -- /usr/include/linux/ptrace.h:60
flags : aliased asm_generic_int_ll64_h.uu_u32; -- /usr/include/linux/ptrace.h:61
nr : aliased asm_generic_int_ll64_h.uu_s32; -- /usr/include/linux/ptrace.h:62
end record;
pragma Convention (C_Pass_By_Copy, ptrace_peeksiginfo_args); -- /usr/include/linux/ptrace.h:59
-- how may siginfos to take
-- Input: which filter
type seccomp_metadata is record
filter_off : aliased asm_generic_int_ll64_h.uu_u64; -- /usr/include/linux/ptrace.h:72
flags : aliased asm_generic_int_ll64_h.uu_u64; -- /usr/include/linux/ptrace.h:73
end record;
pragma Convention (C_Pass_By_Copy, seccomp_metadata); -- /usr/include/linux/ptrace.h:71
-- Output: filter's flags
-- Read signals from a shared (process wide) queue
-- Wait extended result codes for the above trace options.
-- Extended result codes which enabled by means other than options.
-- Options set using PTRACE_SETOPTIONS or using PTRACE_SEIZE @data param
-- eventless options
end linux_ptrace_h;
|
with Ada.Characters.Latin_1;
with Ada.Streams.Stream_IO; use Ada.Streams.Stream_IO;
procedure Put_PPM (File : File_Type; Picture : Image) is
use Ada.Characters.Latin_1;
Size : constant String := Integer'Image (Picture'Length (2)) & Integer'Image (Picture'Length (1));
Buffer : String (1..Picture'Length (2) * 3);
Color : Pixel;
Index : Positive;
begin
String'Write (Stream (File), "P6" & LF);
String'Write (Stream (File), Size (2..Size'Last) & LF);
String'Write (Stream (File), "255" & LF);
for I in Picture'Range (1) loop
Index := Buffer'First;
for J in Picture'Range (2) loop
Color := Picture (I, J);
Buffer (Index) := Character'Val (Color.R);
Buffer (Index + 1) := Character'Val (Color.G);
Buffer (Index + 2) := Character'Val (Color.B);
Index := Index + 3;
end loop;
String'Write (Stream (File), Buffer);
end loop;
Character'Write (Stream (File), LF);
end Put_PPM;
|
-- { dg-do compile }
with Rational_Arithmetic;
use Rational_Arithmetic;
procedure Test_Rational_Arithmetic is
R: Rational := 10/2;
B: Boolean := R = 5/1; -- RHS cannot be a Whole
-- ("/" has been "undefined")
C: Boolean := R = Rational' (5/1);
D: Boolean := (6/3) = R;
E: Boolean := (2/1 = 4/2);
begin
R := 1+1/(4/8);
R := 2*(3/2)-(7/3)*3;
end Test_Rational_Arithmetic;
|
with HAL.Bitmap;
package HAL.Framebuffer is
subtype FB_Color_Mode is HAL.Bitmap.Bitmap_Color_Mode range
HAL.Bitmap.ARGB_8888 .. HAL.Bitmap.AL_88;
type Display_Orientation is
(Default, Landscape, Portrait);
type Wait_Mode is (Polling, Interrupt);
type Frame_Buffer_Display is limited interface;
type Frame_Buffer_Display_Access is access all Frame_Buffer_Display'Class;
function Get_Max_Layers
(Display : Frame_Buffer_Display) return Positive
is abstract;
function Is_Supported
(Display : Frame_Buffer_Display;
Mode : FB_Color_Mode) return Boolean
is abstract;
procedure Initialize
(Display : in out Frame_Buffer_Display;
Orientation : Display_Orientation := Default;
Mode : Wait_Mode := Interrupt) is abstract;
procedure Set_Orientation
(Display : in out Frame_Buffer_Display;
Orientation : Display_Orientation) is abstract;
procedure Set_Mode
(Display : in out Frame_Buffer_Display;
Mode : Wait_Mode) is abstract;
function Initialized
(Display : Frame_Buffer_Display) return Boolean is abstract;
function Get_Width
(Display : Frame_Buffer_Display) return Positive is abstract;
function Get_Height
(Display : Frame_Buffer_Display) return Positive is abstract;
function Is_Swapped
(Display : Frame_Buffer_Display) return Boolean is abstract;
-- Whether X/Y coordinates are considered Swapped by the drawing primitives
-- This simulates Landscape/Portrait orientation on displays not supporting
-- hardware orientation change
procedure Set_Background
(Display : Frame_Buffer_Display; R, G, B : Byte) is abstract;
procedure Initialize_Layer
(Display : in out Frame_Buffer_Display;
Layer : Positive;
Mode : FB_Color_Mode;
X : Natural := 0;
Y : Natural := 0;
Width : Positive := Positive'Last;
Height : Positive := Positive'Last) is abstract;
-- All layers are double buffered, so an explicit call to Update_Layer
-- needs to be performed to actually display the current buffer attached
-- to the layer.
-- Alloc is called to create the actual buffer.
function Initialized
(Display : Frame_Buffer_Display;
Layer : Positive) return Boolean is abstract;
procedure Update_Layer
(Display : in out Frame_Buffer_Display;
Layer : Positive;
Copy_Back : Boolean := False) is abstract;
-- Updates the layer so that the hidden buffer is displayed.
procedure Update_Layers
(Display : in out Frame_Buffer_Display) is abstract;
-- Updates all initialized layers at once with their respective hidden
-- buffer
function Get_Color_Mode
(Display : Frame_Buffer_Display;
Layer : Positive) return FB_Color_Mode is abstract;
-- Retrieves the current color mode for the layer.
function Get_Hidden_Buffer
(Display : Frame_Buffer_Display;
Layer : Positive) return HAL.Bitmap.Bitmap_Buffer'Class is abstract;
-- Retrieves the current hidden buffer for the layer.
function Get_Pixel_Size
(Display : Frame_Buffer_Display;
Layer : Positive) return Positive is abstract;
-- Retrieves the current hidden buffer for the layer.
end HAL.Framebuffer;
|
with agar.gui.widget.box;
package agar.gui.widget.mpane is
use type c.unsigned;
type layout_t is (
MPANE1,
MPANE2V,
MPANE2H,
MPANE2L1R,
MPANE1L2R,
MPANE2T1B,
MPANE1T2B,
MPANE3L1R,
MPANE1L3R,
MPANE3T1B,
MPANE1T3B,
MPANE4
);
for layout_t use (
MPANE1 => 0,
MPANE2V => 1,
MPANE2H => 2,
MPANE2L1R => 3,
MPANE1L2R => 4,
MPANE2T1B => 5,
MPANE1T2B => 6,
MPANE3L1R => 7,
MPANE1L3R => 8,
MPANE3T1B => 9,
MPANE1T3B => 10,
MPANE4 => 11
);
for layout_t'size use c.unsigned'size;
pragma convention (c, layout_t);
type flags_t is new c.unsigned;
MPANE_HFILL : constant flags_t := 16#01#;
MPANE_VFILL : constant flags_t := 16#02#;
MPANE_FRAMES : constant flags_t := 16#04#;
MPANE_FORCE_DIV : constant flags_t := 16#08#;
MPANE_EXPAND : constant flags_t := MPANE_HFILL or MPANE_VFILL;
type panes_t is array (1 .. 4) of aliased agar.gui.widget.box.box_access_t;
pragma convention (c, panes_t);
type mpane_t is record
box : aliased agar.gui.widget.box.box_t;
layout : layout_t;
flags : flags_t;
panes : panes_t;
npanes : c.unsigned;
end record;
type mpane_access_t is access all mpane_t;
pragma convention (c, mpane_t);
pragma convention (c, mpane_access_t);
-- API
function allocate
(parent : widget_access_t;
layout : layout_t;
flags : flags_t) return mpane_access_t;
pragma import (c, allocate, "AG_MPaneNew");
procedure set_layout
(mpane : mpane_access_t;
layout : layout_t);
pragma import (c, set_layout, "AG_MPaneSetLayout");
function widget (mpane : mpane_access_t) return widget_access_t;
pragma inline (widget);
end agar.gui.widget.mpane;
|
------------------------------------------------------------------------------
-- --
-- Copyright (C) 2019, 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 System;
with HAL;
package SAM.SERCOM is
type Pad_Id is new HAL.UInt2;
-- Identifier for the pads (IO line) of SERCOM devices
type SERCOM_Internal is private;
-- Register mapping for internal use only
type SERCOM_Device
(Periph : not null access SERCOM_Internal)
is abstract tagged limited
private;
function Configured (This : SERCOM_Device) return Boolean;
-- Return True if the device is configure for one of its operation mode
-- (I2C, SPI, UART).
--
-- Configuration can only be done by one of the specific mode drivers, see
-- SAM.SERCOM.SPI, SAM.SERCOM.I2C, etc.
function Enabled (This : SERCOM_Device) return Boolean;
-- Return True if the device is enableds
procedure Enable (This : in out SERCOM_Device)
with Pre => This.Configured and then not This.Enabled,
Post => This.Configured and then This.Enabled;
-- Enable the device that was previously configured for a specific mode
procedure Disable (This : in out SERCOM_Device)
with Pre => This.Enabled,
Post => not This.Enabled;
-- Disable the device
procedure Reset (This : in out SERCOM_Device)
with Post => not This.Configured;
-- Reset the device and its configuration
procedure Debug_Stop_Mode (This : in out SERCOM_Device;
Enabled : Boolean := True);
-- Stop the device when the CPU is halted by an external debugger.
-- This mode is disabled by default.
--
-- When this mdoe is disabled, the device will continue to send and receive
-- data when the CPU is halted which may lead to data loss.
private
type SERCOM_Device
(Periph : not null access SERCOM_Internal)
is abstract tagged limited
record
Config_Done : Boolean := False;
end record;
---------------
-- Registers --
---------------
------------------------------------
-- SercomI2cm cluster's Registers --
------------------------------------
subtype SERCOM_CTRLA_SERCOM_I2CM_MODE_Field is HAL.UInt3;
subtype SERCOM_CTRLA_SERCOM_I2CM_SDAHOLD_Field is HAL.UInt2;
subtype SERCOM_CTRLA_SERCOM_I2CM_SPEED_Field is HAL.UInt2;
subtype SERCOM_CTRLA_SERCOM_I2CM_INACTOUT_Field is HAL.UInt2;
-- I2CM Control A
type SERCOM_CTRLA_SERCOM_I2CM_Register is record
-- Software Reset
SWRST : Boolean := False;
-- Enable
ENABLE : Boolean := False;
-- Operating Mode
MODE : SERCOM_CTRLA_SERCOM_I2CM_MODE_Field := 16#0#;
-- unspecified
Reserved_5_6 : HAL.UInt2 := 16#0#;
-- Run in Standby
RUNSTDBY : Boolean := False;
-- unspecified
Reserved_8_15 : HAL.UInt8 := 16#0#;
-- Pin Usage
PINOUT : Boolean := False;
-- unspecified
Reserved_17_19 : HAL.UInt3 := 16#0#;
-- SDA Hold Time
SDAHOLD : SERCOM_CTRLA_SERCOM_I2CM_SDAHOLD_Field := 16#0#;
-- Master SCL Low Extend Timeout
MEXTTOEN : Boolean := False;
-- Slave SCL Low Extend Timeout
SEXTTOEN : Boolean := False;
-- Transfer Speed
SPEED : SERCOM_CTRLA_SERCOM_I2CM_SPEED_Field := 16#0#;
-- unspecified
Reserved_26_26 : HAL.Bit := 16#0#;
-- SCL Clock Stretch Mode
SCLSM : Boolean := False;
-- Inactive Time-Out
INACTOUT : SERCOM_CTRLA_SERCOM_I2CM_INACTOUT_Field := 16#0#;
-- SCL Low Timeout Enable
LOWTOUTEN : Boolean := False;
-- unspecified
Reserved_31_31 : HAL.Bit := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for SERCOM_CTRLA_SERCOM_I2CM_Register use record
SWRST at 0 range 0 .. 0;
ENABLE at 0 range 1 .. 1;
MODE at 0 range 2 .. 4;
Reserved_5_6 at 0 range 5 .. 6;
RUNSTDBY at 0 range 7 .. 7;
Reserved_8_15 at 0 range 8 .. 15;
PINOUT at 0 range 16 .. 16;
Reserved_17_19 at 0 range 17 .. 19;
SDAHOLD at 0 range 20 .. 21;
MEXTTOEN at 0 range 22 .. 22;
SEXTTOEN at 0 range 23 .. 23;
SPEED at 0 range 24 .. 25;
Reserved_26_26 at 0 range 26 .. 26;
SCLSM at 0 range 27 .. 27;
INACTOUT at 0 range 28 .. 29;
LOWTOUTEN at 0 range 30 .. 30;
Reserved_31_31 at 0 range 31 .. 31;
end record;
subtype SERCOM_CTRLB_SERCOM_I2CM_CMD_Field is HAL.UInt2;
-- I2CM Control B
type SERCOM_CTRLB_SERCOM_I2CM_Register is record
-- unspecified
Reserved_0_7 : HAL.UInt8 := 16#0#;
-- Smart Mode Enable
SMEN : Boolean := False;
-- Quick Command Enable
QCEN : Boolean := False;
-- unspecified
Reserved_10_15 : HAL.UInt6 := 16#0#;
-- Write-only. Command
CMD : SERCOM_CTRLB_SERCOM_I2CM_CMD_Field := 16#0#;
-- Acknowledge Action
ACKACT : Boolean := False;
-- unspecified
Reserved_19_31 : HAL.UInt13 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for SERCOM_CTRLB_SERCOM_I2CM_Register use record
Reserved_0_7 at 0 range 0 .. 7;
SMEN at 0 range 8 .. 8;
QCEN at 0 range 9 .. 9;
Reserved_10_15 at 0 range 10 .. 15;
CMD at 0 range 16 .. 17;
ACKACT at 0 range 18 .. 18;
Reserved_19_31 at 0 range 19 .. 31;
end record;
-- I2CM Control C
type SERCOM_CTRLC_SERCOM_I2CM_Register is record
-- unspecified
Reserved_0_23 : HAL.UInt24 := 16#0#;
-- Data 32 Bit
DATA32B : Boolean := False;
-- unspecified
Reserved_25_31 : HAL.UInt7 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for SERCOM_CTRLC_SERCOM_I2CM_Register use record
Reserved_0_23 at 0 range 0 .. 23;
DATA32B at 0 range 24 .. 24;
Reserved_25_31 at 0 range 25 .. 31;
end record;
subtype SERCOM_BAUD_SERCOM_I2CM_BAUD_Field is HAL.UInt8;
subtype SERCOM_BAUD_SERCOM_I2CM_BAUDLOW_Field is HAL.UInt8;
subtype SERCOM_BAUD_SERCOM_I2CM_HSBAUD_Field is HAL.UInt8;
subtype SERCOM_BAUD_SERCOM_I2CM_HSBAUDLOW_Field is HAL.UInt8;
-- I2CM Baud Rate
type SERCOM_BAUD_SERCOM_I2CM_Register is record
-- Baud Rate Value
BAUD : SERCOM_BAUD_SERCOM_I2CM_BAUD_Field := 16#0#;
-- Baud Rate Value Low
BAUDLOW : SERCOM_BAUD_SERCOM_I2CM_BAUDLOW_Field := 16#0#;
-- High Speed Baud Rate Value
HSBAUD : SERCOM_BAUD_SERCOM_I2CM_HSBAUD_Field := 16#0#;
-- High Speed Baud Rate Value Low
HSBAUDLOW : SERCOM_BAUD_SERCOM_I2CM_HSBAUDLOW_Field := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for SERCOM_BAUD_SERCOM_I2CM_Register use record
BAUD at 0 range 0 .. 7;
BAUDLOW at 0 range 8 .. 15;
HSBAUD at 0 range 16 .. 23;
HSBAUDLOW at 0 range 24 .. 31;
end record;
-- I2CM Interrupt Enable Clear
type SERCOM_INTENCLR_SERCOM_I2CM_Register is record
-- Master On Bus Interrupt Disable
MB : Boolean := False;
-- Slave On Bus Interrupt Disable
SB : Boolean := False;
-- unspecified
Reserved_2_6 : HAL.UInt5 := 16#0#;
-- Combined Error Interrupt Disable
ERROR : Boolean := False;
end record
with Volatile_Full_Access, Size => 8, Bit_Order => System.Low_Order_First;
for SERCOM_INTENCLR_SERCOM_I2CM_Register use record
MB at 0 range 0 .. 0;
SB at 0 range 1 .. 1;
Reserved_2_6 at 0 range 2 .. 6;
ERROR at 0 range 7 .. 7;
end record;
-- I2CM Interrupt Enable Set
type SERCOM_INTENSET_SERCOM_I2CM_Register is record
-- Master On Bus Interrupt Enable
MB : Boolean := False;
-- Slave On Bus Interrupt Enable
SB : Boolean := False;
-- unspecified
Reserved_2_6 : HAL.UInt5 := 16#0#;
-- Combined Error Interrupt Enable
ERROR : Boolean := False;
end record
with Volatile_Full_Access, Size => 8, Bit_Order => System.Low_Order_First;
for SERCOM_INTENSET_SERCOM_I2CM_Register use record
MB at 0 range 0 .. 0;
SB at 0 range 1 .. 1;
Reserved_2_6 at 0 range 2 .. 6;
ERROR at 0 range 7 .. 7;
end record;
-- I2CM Interrupt Flag Status and Clear
type SERCOM_INTFLAG_SERCOM_I2CM_Register is record
-- Master On Bus Interrupt
MB : Boolean := False;
-- Slave On Bus Interrupt
SB : Boolean := False;
-- unspecified
Reserved_2_6 : HAL.UInt5 := 16#0#;
-- Combined Error Interrupt
ERROR : Boolean := False;
end record
with Volatile_Full_Access, Size => 8, Bit_Order => System.Low_Order_First;
for SERCOM_INTFLAG_SERCOM_I2CM_Register use record
MB at 0 range 0 .. 0;
SB at 0 range 1 .. 1;
Reserved_2_6 at 0 range 2 .. 6;
ERROR at 0 range 7 .. 7;
end record;
subtype SERCOM_STATUS_SERCOM_I2CM_BUSSTATE_Field is HAL.UInt2;
-- I2CM Status
type SERCOM_STATUS_SERCOM_I2CM_Register is record
-- Bus Error
BUSERR : Boolean := False;
-- Arbitration Lost
ARBLOST : Boolean := False;
-- Read-only. Received Not Acknowledge
RXNACK : Boolean := False;
-- unspecified
Reserved_3_3 : HAL.Bit := 16#0#;
-- Bus State
BUSSTATE : SERCOM_STATUS_SERCOM_I2CM_BUSSTATE_Field := 16#0#;
-- SCL Low Timeout
LOWTOUT : Boolean := False;
-- Read-only. Clock Hold
CLKHOLD : Boolean := False;
-- Master SCL Low Extend Timeout
MEXTTOUT : Boolean := False;
-- Slave SCL Low Extend Timeout
SEXTTOUT : Boolean := False;
-- Length Error
LENERR : Boolean := False;
-- unspecified
Reserved_11_15 : HAL.UInt5 := 16#0#;
end record
with Volatile_Full_Access, Size => 16,
Bit_Order => System.Low_Order_First;
for SERCOM_STATUS_SERCOM_I2CM_Register use record
BUSERR at 0 range 0 .. 0;
ARBLOST at 0 range 1 .. 1;
RXNACK at 0 range 2 .. 2;
Reserved_3_3 at 0 range 3 .. 3;
BUSSTATE at 0 range 4 .. 5;
LOWTOUT at 0 range 6 .. 6;
CLKHOLD at 0 range 7 .. 7;
MEXTTOUT at 0 range 8 .. 8;
SEXTTOUT at 0 range 9 .. 9;
LENERR at 0 range 10 .. 10;
Reserved_11_15 at 0 range 11 .. 15;
end record;
-- I2CM Synchronization Busy
type SERCOM_SYNCBUSY_SERCOM_I2CM_Register is record
-- Read-only. Software Reset Synchronization Busy
SWRST : Boolean;
-- Read-only. SERCOM Enable Synchronization Busy
ENABLE : Boolean;
-- Read-only. System Operation Synchronization Busy
SYSOP : Boolean;
-- unspecified
Reserved_3_3 : HAL.Bit;
-- Read-only. Length Synchronization Busy
LENGTH : Boolean;
-- unspecified
Reserved_5_31 : HAL.UInt27;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for SERCOM_SYNCBUSY_SERCOM_I2CM_Register use record
SWRST at 0 range 0 .. 0;
ENABLE at 0 range 1 .. 1;
SYSOP at 0 range 2 .. 2;
Reserved_3_3 at 0 range 3 .. 3;
LENGTH at 0 range 4 .. 4;
Reserved_5_31 at 0 range 5 .. 31;
end record;
subtype SERCOM_ADDR_SERCOM_I2CM_ADDR_Field is HAL.UInt11;
subtype SERCOM_ADDR_SERCOM_I2CM_LEN_Field is HAL.UInt8;
-- I2CM Address
type SERCOM_ADDR_SERCOM_I2CM_Register is record
-- Address Value
ADDR : SERCOM_ADDR_SERCOM_I2CM_ADDR_Field := 16#0#;
-- unspecified
Reserved_11_12 : HAL.UInt2 := 16#0#;
-- Length Enable
LENEN : Boolean := False;
-- High Speed Mode
HS : Boolean := False;
-- Ten Bit Addressing Enable
TENBITEN : Boolean := False;
-- Length
LEN : SERCOM_ADDR_SERCOM_I2CM_LEN_Field := 16#0#;
-- unspecified
Reserved_24_31 : HAL.UInt8 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for SERCOM_ADDR_SERCOM_I2CM_Register use record
ADDR at 0 range 0 .. 10;
Reserved_11_12 at 0 range 11 .. 12;
LENEN at 0 range 13 .. 13;
HS at 0 range 14 .. 14;
TENBITEN at 0 range 15 .. 15;
LEN at 0 range 16 .. 23;
Reserved_24_31 at 0 range 24 .. 31;
end record;
-- I2CM Debug Control
type SERCOM_DBGCTRL_SERCOM_I2CM_Register is record
-- Debug Mode
DBGSTOP : Boolean := False;
-- unspecified
Reserved_1_7 : HAL.UInt7 := 16#0#;
end record
with Volatile_Full_Access, Size => 8, Bit_Order => System.Low_Order_First;
for SERCOM_DBGCTRL_SERCOM_I2CM_Register use record
DBGSTOP at 0 range 0 .. 0;
Reserved_1_7 at 0 range 1 .. 7;
end record;
-- I2C Master Mode
type SercomI2cm_Cluster is record
-- I2CM Control A
CTRLA : aliased SERCOM_CTRLA_SERCOM_I2CM_Register;
-- I2CM Control B
CTRLB : aliased SERCOM_CTRLB_SERCOM_I2CM_Register;
-- I2CM Control C
CTRLC : aliased SERCOM_CTRLC_SERCOM_I2CM_Register;
-- I2CM Baud Rate
BAUD : aliased SERCOM_BAUD_SERCOM_I2CM_Register;
-- I2CM Interrupt Enable Clear
INTENCLR : aliased SERCOM_INTENCLR_SERCOM_I2CM_Register;
-- I2CM Interrupt Enable Set
INTENSET : aliased SERCOM_INTENSET_SERCOM_I2CM_Register;
-- I2CM Interrupt Flag Status and Clear
INTFLAG : aliased SERCOM_INTFLAG_SERCOM_I2CM_Register;
-- I2CM Status
STATUS : aliased SERCOM_STATUS_SERCOM_I2CM_Register;
-- I2CM Synchronization Busy
SYNCBUSY : aliased SERCOM_SYNCBUSY_SERCOM_I2CM_Register;
-- I2CM Address
ADDR : aliased SERCOM_ADDR_SERCOM_I2CM_Register;
-- I2CM Data
DATA : aliased HAL.UInt32;
-- I2CM Debug Control
DBGCTRL : aliased SERCOM_DBGCTRL_SERCOM_I2CM_Register;
end record
with Size => 416;
for SercomI2cm_Cluster use record
CTRLA at 16#0# range 0 .. 31;
CTRLB at 16#4# range 0 .. 31;
CTRLC at 16#8# range 0 .. 31;
BAUD at 16#C# range 0 .. 31;
INTENCLR at 16#14# range 0 .. 7;
INTENSET at 16#16# range 0 .. 7;
INTFLAG at 16#18# range 0 .. 7;
STATUS at 16#1A# range 0 .. 15;
SYNCBUSY at 16#1C# range 0 .. 31;
ADDR at 16#24# range 0 .. 31;
DATA at 16#28# range 0 .. 31;
DBGCTRL at 16#30# range 0 .. 7;
end record;
------------------------------------
-- SercomI2cs cluster's Registers --
------------------------------------
subtype SERCOM_CTRLA_SERCOM_I2CS_MODE_Field is HAL.UInt3;
subtype SERCOM_CTRLA_SERCOM_I2CS_SDAHOLD_Field is HAL.UInt2;
subtype SERCOM_CTRLA_SERCOM_I2CS_SPEED_Field is HAL.UInt2;
-- I2CS Control A
type SERCOM_CTRLA_SERCOM_I2CS_Register is record
-- Software Reset
SWRST : Boolean := False;
-- Enable
ENABLE : Boolean := False;
-- Operating Mode
MODE : SERCOM_CTRLA_SERCOM_I2CS_MODE_Field := 16#0#;
-- unspecified
Reserved_5_6 : HAL.UInt2 := 16#0#;
-- Run during Standby
RUNSTDBY : Boolean := False;
-- unspecified
Reserved_8_15 : HAL.UInt8 := 16#0#;
-- Pin Usage
PINOUT : Boolean := False;
-- unspecified
Reserved_17_19 : HAL.UInt3 := 16#0#;
-- SDA Hold Time
SDAHOLD : SERCOM_CTRLA_SERCOM_I2CS_SDAHOLD_Field := 16#0#;
-- unspecified
Reserved_22_22 : HAL.Bit := 16#0#;
-- Slave SCL Low Extend Timeout
SEXTTOEN : Boolean := False;
-- Transfer Speed
SPEED : SERCOM_CTRLA_SERCOM_I2CS_SPEED_Field := 16#0#;
-- unspecified
Reserved_26_26 : HAL.Bit := 16#0#;
-- SCL Clock Stretch Mode
SCLSM : Boolean := False;
-- unspecified
Reserved_28_29 : HAL.UInt2 := 16#0#;
-- SCL Low Timeout Enable
LOWTOUTEN : Boolean := False;
-- unspecified
Reserved_31_31 : HAL.Bit := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for SERCOM_CTRLA_SERCOM_I2CS_Register use record
SWRST at 0 range 0 .. 0;
ENABLE at 0 range 1 .. 1;
MODE at 0 range 2 .. 4;
Reserved_5_6 at 0 range 5 .. 6;
RUNSTDBY at 0 range 7 .. 7;
Reserved_8_15 at 0 range 8 .. 15;
PINOUT at 0 range 16 .. 16;
Reserved_17_19 at 0 range 17 .. 19;
SDAHOLD at 0 range 20 .. 21;
Reserved_22_22 at 0 range 22 .. 22;
SEXTTOEN at 0 range 23 .. 23;
SPEED at 0 range 24 .. 25;
Reserved_26_26 at 0 range 26 .. 26;
SCLSM at 0 range 27 .. 27;
Reserved_28_29 at 0 range 28 .. 29;
LOWTOUTEN at 0 range 30 .. 30;
Reserved_31_31 at 0 range 31 .. 31;
end record;
subtype SERCOM_CTRLB_SERCOM_I2CS_AMODE_Field is HAL.UInt2;
subtype SERCOM_CTRLB_SERCOM_I2CS_CMD_Field is HAL.UInt2;
-- I2CS Control B
type SERCOM_CTRLB_SERCOM_I2CS_Register is record
-- unspecified
Reserved_0_7 : HAL.UInt8 := 16#0#;
-- Smart Mode Enable
SMEN : Boolean := False;
-- PMBus Group Command
GCMD : Boolean := False;
-- Automatic Address Acknowledge
AACKEN : Boolean := False;
-- unspecified
Reserved_11_13 : HAL.UInt3 := 16#0#;
-- Address Mode
AMODE : SERCOM_CTRLB_SERCOM_I2CS_AMODE_Field := 16#0#;
-- Write-only. Command
CMD : SERCOM_CTRLB_SERCOM_I2CS_CMD_Field := 16#0#;
-- Acknowledge Action
ACKACT : Boolean := False;
-- unspecified
Reserved_19_31 : HAL.UInt13 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for SERCOM_CTRLB_SERCOM_I2CS_Register use record
Reserved_0_7 at 0 range 0 .. 7;
SMEN at 0 range 8 .. 8;
GCMD at 0 range 9 .. 9;
AACKEN at 0 range 10 .. 10;
Reserved_11_13 at 0 range 11 .. 13;
AMODE at 0 range 14 .. 15;
CMD at 0 range 16 .. 17;
ACKACT at 0 range 18 .. 18;
Reserved_19_31 at 0 range 19 .. 31;
end record;
subtype SERCOM_CTRLC_SERCOM_I2CS_SDASETUP_Field is HAL.UInt4;
-- I2CS Control C
type SERCOM_CTRLC_SERCOM_I2CS_Register is record
-- SDA Setup Time
SDASETUP : SERCOM_CTRLC_SERCOM_I2CS_SDASETUP_Field := 16#0#;
-- unspecified
Reserved_4_23 : HAL.UInt20 := 16#0#;
-- Data 32 Bit
DATA32B : Boolean := False;
-- unspecified
Reserved_25_31 : HAL.UInt7 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for SERCOM_CTRLC_SERCOM_I2CS_Register use record
SDASETUP at 0 range 0 .. 3;
Reserved_4_23 at 0 range 4 .. 23;
DATA32B at 0 range 24 .. 24;
Reserved_25_31 at 0 range 25 .. 31;
end record;
-- I2CS Interrupt Enable Clear
type SERCOM_INTENCLR_SERCOM_I2CS_Register is record
-- Stop Received Interrupt Disable
PREC : Boolean := False;
-- Address Match Interrupt Disable
AMATCH : Boolean := False;
-- Data Interrupt Disable
DRDY : Boolean := False;
-- unspecified
Reserved_3_6 : HAL.UInt4 := 16#0#;
-- Combined Error Interrupt Disable
ERROR : Boolean := False;
end record
with Volatile_Full_Access, Size => 8, Bit_Order => System.Low_Order_First;
for SERCOM_INTENCLR_SERCOM_I2CS_Register use record
PREC at 0 range 0 .. 0;
AMATCH at 0 range 1 .. 1;
DRDY at 0 range 2 .. 2;
Reserved_3_6 at 0 range 3 .. 6;
ERROR at 0 range 7 .. 7;
end record;
-- I2CS Interrupt Enable Set
type SERCOM_INTENSET_SERCOM_I2CS_Register is record
-- Stop Received Interrupt Enable
PREC : Boolean := False;
-- Address Match Interrupt Enable
AMATCH : Boolean := False;
-- Data Interrupt Enable
DRDY : Boolean := False;
-- unspecified
Reserved_3_6 : HAL.UInt4 := 16#0#;
-- Combined Error Interrupt Enable
ERROR : Boolean := False;
end record
with Volatile_Full_Access, Size => 8, Bit_Order => System.Low_Order_First;
for SERCOM_INTENSET_SERCOM_I2CS_Register use record
PREC at 0 range 0 .. 0;
AMATCH at 0 range 1 .. 1;
DRDY at 0 range 2 .. 2;
Reserved_3_6 at 0 range 3 .. 6;
ERROR at 0 range 7 .. 7;
end record;
-- I2CS Interrupt Flag Status and Clear
type SERCOM_INTFLAG_SERCOM_I2CS_Register is record
-- Stop Received Interrupt
PREC : Boolean := False;
-- Address Match Interrupt
AMATCH : Boolean := False;
-- Data Interrupt
DRDY : Boolean := False;
-- unspecified
Reserved_3_6 : HAL.UInt4 := 16#0#;
-- Combined Error Interrupt
ERROR : Boolean := False;
end record
with Volatile_Full_Access, Size => 8, Bit_Order => System.Low_Order_First;
for SERCOM_INTFLAG_SERCOM_I2CS_Register use record
PREC at 0 range 0 .. 0;
AMATCH at 0 range 1 .. 1;
DRDY at 0 range 2 .. 2;
Reserved_3_6 at 0 range 3 .. 6;
ERROR at 0 range 7 .. 7;
end record;
-- I2CS Status
type SERCOM_STATUS_SERCOM_I2CS_Register is record
-- Bus Error
BUSERR : Boolean := False;
-- Transmit Collision
COLL : Boolean := False;
-- Read-only. Received Not Acknowledge
RXNACK : Boolean := False;
-- Read-only. Read/Write Direction
DIR : Boolean := False;
-- Read-only. Repeated Start
SR : Boolean := False;
-- unspecified
Reserved_5_5 : HAL.Bit := 16#0#;
-- SCL Low Timeout
LOWTOUT : Boolean := False;
-- Read-only. Clock Hold
CLKHOLD : Boolean := False;
-- unspecified
Reserved_8_8 : HAL.Bit := 16#0#;
-- Slave SCL Low Extend Timeout
SEXTTOUT : Boolean := False;
-- High Speed
HS : Boolean := False;
-- Transaction Length Error
LENERR : Boolean := False;
-- unspecified
Reserved_12_15 : HAL.UInt4 := 16#0#;
end record
with Volatile_Full_Access, Size => 16,
Bit_Order => System.Low_Order_First;
for SERCOM_STATUS_SERCOM_I2CS_Register use record
BUSERR at 0 range 0 .. 0;
COLL at 0 range 1 .. 1;
RXNACK at 0 range 2 .. 2;
DIR at 0 range 3 .. 3;
SR at 0 range 4 .. 4;
Reserved_5_5 at 0 range 5 .. 5;
LOWTOUT at 0 range 6 .. 6;
CLKHOLD at 0 range 7 .. 7;
Reserved_8_8 at 0 range 8 .. 8;
SEXTTOUT at 0 range 9 .. 9;
HS at 0 range 10 .. 10;
LENERR at 0 range 11 .. 11;
Reserved_12_15 at 0 range 12 .. 15;
end record;
-- I2CS Synchronization Busy
type SERCOM_SYNCBUSY_SERCOM_I2CS_Register is record
-- Read-only. Software Reset Synchronization Busy
SWRST : Boolean;
-- Read-only. SERCOM Enable Synchronization Busy
ENABLE : Boolean;
-- unspecified
Reserved_2_3 : HAL.UInt2;
-- Read-only. Length Synchronization Busy
LENGTH : Boolean;
-- unspecified
Reserved_5_31 : HAL.UInt27;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for SERCOM_SYNCBUSY_SERCOM_I2CS_Register use record
SWRST at 0 range 0 .. 0;
ENABLE at 0 range 1 .. 1;
Reserved_2_3 at 0 range 2 .. 3;
LENGTH at 0 range 4 .. 4;
Reserved_5_31 at 0 range 5 .. 31;
end record;
subtype SERCOM_LENGTH_SERCOM_I2CS_LEN_Field is HAL.UInt8;
-- I2CS Length
type SERCOM_LENGTH_SERCOM_I2CS_Register is record
-- Data Length
LEN : SERCOM_LENGTH_SERCOM_I2CS_LEN_Field := 16#0#;
-- Data Length Enable
LENEN : Boolean := False;
-- unspecified
Reserved_9_15 : HAL.UInt7 := 16#0#;
end record
with Volatile_Full_Access, Size => 16,
Bit_Order => System.Low_Order_First;
for SERCOM_LENGTH_SERCOM_I2CS_Register use record
LEN at 0 range 0 .. 7;
LENEN at 0 range 8 .. 8;
Reserved_9_15 at 0 range 9 .. 15;
end record;
subtype SERCOM_ADDR_SERCOM_I2CS_ADDR_Field is HAL.UInt10;
subtype SERCOM_ADDR_SERCOM_I2CS_ADDRMASK_Field is HAL.UInt10;
-- I2CS Address
type SERCOM_ADDR_SERCOM_I2CS_Register is record
-- General Call Address Enable
GENCEN : Boolean := False;
-- Address Value
ADDR : SERCOM_ADDR_SERCOM_I2CS_ADDR_Field := 16#0#;
-- unspecified
Reserved_11_14 : HAL.UInt4 := 16#0#;
-- Ten Bit Addressing Enable
TENBITEN : Boolean := False;
-- unspecified
Reserved_16_16 : HAL.Bit := 16#0#;
-- Address Mask
ADDRMASK : SERCOM_ADDR_SERCOM_I2CS_ADDRMASK_Field := 16#0#;
-- unspecified
Reserved_27_31 : HAL.UInt5 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for SERCOM_ADDR_SERCOM_I2CS_Register use record
GENCEN at 0 range 0 .. 0;
ADDR at 0 range 1 .. 10;
Reserved_11_14 at 0 range 11 .. 14;
TENBITEN at 0 range 15 .. 15;
Reserved_16_16 at 0 range 16 .. 16;
ADDRMASK at 0 range 17 .. 26;
Reserved_27_31 at 0 range 27 .. 31;
end record;
-- I2C Slave Mode
type SercomI2cs_Cluster is record
-- I2CS Control A
CTRLA : aliased SERCOM_CTRLA_SERCOM_I2CS_Register;
-- I2CS Control B
CTRLB : aliased SERCOM_CTRLB_SERCOM_I2CS_Register;
-- I2CS Control C
CTRLC : aliased SERCOM_CTRLC_SERCOM_I2CS_Register;
-- I2CS Interrupt Enable Clear
INTENCLR : aliased SERCOM_INTENCLR_SERCOM_I2CS_Register;
-- I2CS Interrupt Enable Set
INTENSET : aliased SERCOM_INTENSET_SERCOM_I2CS_Register;
-- I2CS Interrupt Flag Status and Clear
INTFLAG : aliased SERCOM_INTFLAG_SERCOM_I2CS_Register;
-- I2CS Status
STATUS : aliased SERCOM_STATUS_SERCOM_I2CS_Register;
-- I2CS Synchronization Busy
SYNCBUSY : aliased SERCOM_SYNCBUSY_SERCOM_I2CS_Register;
-- I2CS Length
LENGTH : aliased SERCOM_LENGTH_SERCOM_I2CS_Register;
-- I2CS Address
ADDR : aliased SERCOM_ADDR_SERCOM_I2CS_Register;
-- I2CS Data
DATA : aliased HAL.UInt32;
end record
with Size => 352;
for SercomI2cs_Cluster use record
CTRLA at 16#0# range 0 .. 31;
CTRLB at 16#4# range 0 .. 31;
CTRLC at 16#8# range 0 .. 31;
INTENCLR at 16#14# range 0 .. 7;
INTENSET at 16#16# range 0 .. 7;
INTFLAG at 16#18# range 0 .. 7;
STATUS at 16#1A# range 0 .. 15;
SYNCBUSY at 16#1C# range 0 .. 31;
LENGTH at 16#22# range 0 .. 15;
ADDR at 16#24# range 0 .. 31;
DATA at 16#28# range 0 .. 31;
end record;
-----------------------------------
-- SercomSpi cluster's Registers --
-----------------------------------
subtype SERCOM_CTRLA_SERCOM_SPI_MODE_Field is HAL.UInt3;
subtype SERCOM_CTRLA_SERCOM_SPI_DOPO_Field is HAL.UInt2;
subtype SERCOM_CTRLA_SERCOM_SPI_DIPO_Field is HAL.UInt2;
subtype SERCOM_CTRLA_SERCOM_SPI_FORM_Field is HAL.UInt4;
-- SPI Control A
type SERCOM_CTRLA_SERCOM_SPI_Register is record
-- Software Reset
SWRST : Boolean := False;
-- Enable
ENABLE : Boolean := False;
-- Operating Mode
MODE : SERCOM_CTRLA_SERCOM_SPI_MODE_Field := 16#0#;
-- unspecified
Reserved_5_6 : HAL.UInt2 := 16#0#;
-- Run during Standby
RUNSTDBY : Boolean := False;
-- Immediate Buffer Overflow Notification
IBON : Boolean := False;
-- unspecified
Reserved_9_15 : HAL.UInt7 := 16#0#;
-- Data Out Pinout
DOPO : SERCOM_CTRLA_SERCOM_SPI_DOPO_Field := 16#0#;
-- unspecified
Reserved_18_19 : HAL.UInt2 := 16#0#;
-- Data In Pinout
DIPO : SERCOM_CTRLA_SERCOM_SPI_DIPO_Field := 16#0#;
-- unspecified
Reserved_22_23 : HAL.UInt2 := 16#0#;
-- Frame Format
FORM : SERCOM_CTRLA_SERCOM_SPI_FORM_Field := 16#0#;
-- Clock Phase
CPHA : Boolean := False;
-- Clock Polarity
CPOL : Boolean := False;
-- Data Order
DORD : Boolean := False;
-- unspecified
Reserved_31_31 : HAL.Bit := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for SERCOM_CTRLA_SERCOM_SPI_Register use record
SWRST at 0 range 0 .. 0;
ENABLE at 0 range 1 .. 1;
MODE at 0 range 2 .. 4;
Reserved_5_6 at 0 range 5 .. 6;
RUNSTDBY at 0 range 7 .. 7;
IBON at 0 range 8 .. 8;
Reserved_9_15 at 0 range 9 .. 15;
DOPO at 0 range 16 .. 17;
Reserved_18_19 at 0 range 18 .. 19;
DIPO at 0 range 20 .. 21;
Reserved_22_23 at 0 range 22 .. 23;
FORM at 0 range 24 .. 27;
CPHA at 0 range 28 .. 28;
CPOL at 0 range 29 .. 29;
DORD at 0 range 30 .. 30;
Reserved_31_31 at 0 range 31 .. 31;
end record;
subtype SERCOM_CTRLB_SERCOM_SPI_CHSIZE_Field is HAL.UInt3;
subtype SERCOM_CTRLB_SERCOM_SPI_AMODE_Field is HAL.UInt2;
-- SPI Control B
type SERCOM_CTRLB_SERCOM_SPI_Register is record
-- Character Size
CHSIZE : SERCOM_CTRLB_SERCOM_SPI_CHSIZE_Field := 16#0#;
-- unspecified
Reserved_3_5 : HAL.UInt3 := 16#0#;
-- Data Preload Enable
PLOADEN : Boolean := False;
-- unspecified
Reserved_7_8 : HAL.UInt2 := 16#0#;
-- Slave Select Low Detect Enable
SSDE : Boolean := False;
-- unspecified
Reserved_10_12 : HAL.UInt3 := 16#0#;
-- Master Slave Select Enable
MSSEN : Boolean := False;
-- Address Mode
AMODE : SERCOM_CTRLB_SERCOM_SPI_AMODE_Field := 16#0#;
-- unspecified
Reserved_16_16 : HAL.Bit := 16#0#;
-- Receiver Enable
RXEN : Boolean := False;
-- unspecified
Reserved_18_31 : HAL.UInt14 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for SERCOM_CTRLB_SERCOM_SPI_Register use record
CHSIZE at 0 range 0 .. 2;
Reserved_3_5 at 0 range 3 .. 5;
PLOADEN at 0 range 6 .. 6;
Reserved_7_8 at 0 range 7 .. 8;
SSDE at 0 range 9 .. 9;
Reserved_10_12 at 0 range 10 .. 12;
MSSEN at 0 range 13 .. 13;
AMODE at 0 range 14 .. 15;
Reserved_16_16 at 0 range 16 .. 16;
RXEN at 0 range 17 .. 17;
Reserved_18_31 at 0 range 18 .. 31;
end record;
subtype SERCOM_CTRLC_SERCOM_SPI_ICSPACE_Field is HAL.UInt6;
-- SPI Control C
type SERCOM_CTRLC_SERCOM_SPI_Register is record
-- Inter-Character Spacing
ICSPACE : SERCOM_CTRLC_SERCOM_SPI_ICSPACE_Field := 16#0#;
-- unspecified
Reserved_6_23 : HAL.UInt18 := 16#0#;
-- Data 32 Bit
DATA32B : Boolean := False;
-- unspecified
Reserved_25_31 : HAL.UInt7 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for SERCOM_CTRLC_SERCOM_SPI_Register use record
ICSPACE at 0 range 0 .. 5;
Reserved_6_23 at 0 range 6 .. 23;
DATA32B at 0 range 24 .. 24;
Reserved_25_31 at 0 range 25 .. 31;
end record;
-- SPI Interrupt Enable Clear
type SERCOM_INTENCLR_SERCOM_SPI_Register is record
-- Data Register Empty Interrupt Disable
DRE : Boolean := False;
-- Transmit Complete Interrupt Disable
TXC : Boolean := False;
-- Receive Complete Interrupt Disable
RXC : Boolean := False;
-- Slave Select Low Interrupt Disable
SSL : Boolean := False;
-- unspecified
Reserved_4_6 : HAL.UInt3 := 16#0#;
-- Combined Error Interrupt Disable
ERROR : Boolean := False;
end record
with Volatile_Full_Access, Size => 8, Bit_Order => System.Low_Order_First;
for SERCOM_INTENCLR_SERCOM_SPI_Register use record
DRE at 0 range 0 .. 0;
TXC at 0 range 1 .. 1;
RXC at 0 range 2 .. 2;
SSL at 0 range 3 .. 3;
Reserved_4_6 at 0 range 4 .. 6;
ERROR at 0 range 7 .. 7;
end record;
-- SPI Interrupt Enable Set
type SERCOM_INTENSET_SERCOM_SPI_Register is record
-- Data Register Empty Interrupt Enable
DRE : Boolean := False;
-- Transmit Complete Interrupt Enable
TXC : Boolean := False;
-- Receive Complete Interrupt Enable
RXC : Boolean := False;
-- Slave Select Low Interrupt Enable
SSL : Boolean := False;
-- unspecified
Reserved_4_6 : HAL.UInt3 := 16#0#;
-- Combined Error Interrupt Enable
ERROR : Boolean := False;
end record
with Volatile_Full_Access, Size => 8, Bit_Order => System.Low_Order_First;
for SERCOM_INTENSET_SERCOM_SPI_Register use record
DRE at 0 range 0 .. 0;
TXC at 0 range 1 .. 1;
RXC at 0 range 2 .. 2;
SSL at 0 range 3 .. 3;
Reserved_4_6 at 0 range 4 .. 6;
ERROR at 0 range 7 .. 7;
end record;
-- SPI Interrupt Flag Status and Clear
type SERCOM_INTFLAG_SERCOM_SPI_Register is record
-- Read-only. Data Register Empty Interrupt
DRE : Boolean := False;
-- Transmit Complete Interrupt
TXC : Boolean := False;
-- Read-only. Receive Complete Interrupt
RXC : Boolean := False;
-- Slave Select Low Interrupt Flag
SSL : Boolean := False;
-- unspecified
Reserved_4_6 : HAL.UInt3 := 16#0#;
-- Combined Error Interrupt
ERROR : Boolean := False;
end record
with Volatile_Full_Access, Size => 8, Bit_Order => System.Low_Order_First;
for SERCOM_INTFLAG_SERCOM_SPI_Register use record
DRE at 0 range 0 .. 0;
TXC at 0 range 1 .. 1;
RXC at 0 range 2 .. 2;
SSL at 0 range 3 .. 3;
Reserved_4_6 at 0 range 4 .. 6;
ERROR at 0 range 7 .. 7;
end record;
-- SPI Status
type SERCOM_STATUS_SERCOM_SPI_Register is record
-- unspecified
Reserved_0_1 : HAL.UInt2 := 16#0#;
-- Buffer Overflow
BUFOVF : Boolean := False;
-- unspecified
Reserved_3_10 : HAL.UInt8 := 16#0#;
-- Transaction Length Error
LENERR : Boolean := False;
-- unspecified
Reserved_12_15 : HAL.UInt4 := 16#0#;
end record
with Volatile_Full_Access, Size => 16,
Bit_Order => System.Low_Order_First;
for SERCOM_STATUS_SERCOM_SPI_Register use record
Reserved_0_1 at 0 range 0 .. 1;
BUFOVF at 0 range 2 .. 2;
Reserved_3_10 at 0 range 3 .. 10;
LENERR at 0 range 11 .. 11;
Reserved_12_15 at 0 range 12 .. 15;
end record;
-- SPI Synchronization Busy
type SERCOM_SYNCBUSY_SERCOM_SPI_Register is record
-- Read-only. Software Reset Synchronization Busy
SWRST : Boolean;
-- Read-only. SERCOM Enable Synchronization Busy
ENABLE : Boolean;
-- Read-only. CTRLB Synchronization Busy
CTRLB : Boolean;
-- unspecified
Reserved_3_3 : HAL.Bit;
-- Read-only. LENGTH Synchronization Busy
LENGTH : Boolean;
-- unspecified
Reserved_5_31 : HAL.UInt27;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for SERCOM_SYNCBUSY_SERCOM_SPI_Register use record
SWRST at 0 range 0 .. 0;
ENABLE at 0 range 1 .. 1;
CTRLB at 0 range 2 .. 2;
Reserved_3_3 at 0 range 3 .. 3;
LENGTH at 0 range 4 .. 4;
Reserved_5_31 at 0 range 5 .. 31;
end record;
subtype SERCOM_LENGTH_SERCOM_SPI_LEN_Field is HAL.UInt8;
-- SPI Length
type SERCOM_LENGTH_SERCOM_SPI_Register is record
-- Data Length
LEN : SERCOM_LENGTH_SERCOM_SPI_LEN_Field := 16#0#;
-- Data Length Enable
LENEN : Boolean := False;
-- unspecified
Reserved_9_15 : HAL.UInt7 := 16#0#;
end record
with Volatile_Full_Access, Size => 16,
Bit_Order => System.Low_Order_First;
for SERCOM_LENGTH_SERCOM_SPI_Register use record
LEN at 0 range 0 .. 7;
LENEN at 0 range 8 .. 8;
Reserved_9_15 at 0 range 9 .. 15;
end record;
subtype SERCOM_ADDR_SERCOM_SPI_ADDR_Field is HAL.UInt8;
subtype SERCOM_ADDR_SERCOM_SPI_ADDRMASK_Field is HAL.UInt8;
-- SPI Address
type SERCOM_ADDR_SERCOM_SPI_Register is record
-- Address Value
ADDR : SERCOM_ADDR_SERCOM_SPI_ADDR_Field := 16#0#;
-- unspecified
Reserved_8_15 : HAL.UInt8 := 16#0#;
-- Address Mask
ADDRMASK : SERCOM_ADDR_SERCOM_SPI_ADDRMASK_Field := 16#0#;
-- unspecified
Reserved_24_31 : HAL.UInt8 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for SERCOM_ADDR_SERCOM_SPI_Register use record
ADDR at 0 range 0 .. 7;
Reserved_8_15 at 0 range 8 .. 15;
ADDRMASK at 0 range 16 .. 23;
Reserved_24_31 at 0 range 24 .. 31;
end record;
-- SPI Debug Control
type SERCOM_DBGCTRL_SERCOM_SPI_Register is record
-- Debug Mode
DBGSTOP : Boolean := False;
-- unspecified
Reserved_1_7 : HAL.UInt7 := 16#0#;
end record
with Volatile_Full_Access, Size => 8, Bit_Order => System.Low_Order_First;
for SERCOM_DBGCTRL_SERCOM_SPI_Register use record
DBGSTOP at 0 range 0 .. 0;
Reserved_1_7 at 0 range 1 .. 7;
end record;
-- SPI Mode
type SercomSpi_Cluster is record
-- SPI Control A
CTRLA : aliased SERCOM_CTRLA_SERCOM_SPI_Register;
-- SPI Control B
CTRLB : aliased SERCOM_CTRLB_SERCOM_SPI_Register;
-- SPI Control C
CTRLC : aliased SERCOM_CTRLC_SERCOM_SPI_Register;
-- SPI Baud Rate
BAUD : aliased HAL.UInt8;
-- SPI Interrupt Enable Clear
INTENCLR : aliased SERCOM_INTENCLR_SERCOM_SPI_Register;
-- SPI Interrupt Enable Set
INTENSET : aliased SERCOM_INTENSET_SERCOM_SPI_Register;
-- SPI Interrupt Flag Status and Clear
INTFLAG : aliased SERCOM_INTFLAG_SERCOM_SPI_Register;
-- SPI Status
STATUS : aliased SERCOM_STATUS_SERCOM_SPI_Register;
-- SPI Synchronization Busy
SYNCBUSY : aliased SERCOM_SYNCBUSY_SERCOM_SPI_Register;
-- SPI Length
LENGTH : aliased SERCOM_LENGTH_SERCOM_SPI_Register;
-- SPI Address
ADDR : aliased SERCOM_ADDR_SERCOM_SPI_Register;
-- SPI Data
DATA : aliased HAL.UInt32;
-- SPI Debug Control
DBGCTRL : aliased SERCOM_DBGCTRL_SERCOM_SPI_Register;
end record
with Size => 416;
for SercomSpi_Cluster use record
CTRLA at 16#0# range 0 .. 31;
CTRLB at 16#4# range 0 .. 31;
CTRLC at 16#8# range 0 .. 31;
BAUD at 16#C# range 0 .. 7;
INTENCLR at 16#14# range 0 .. 7;
INTENSET at 16#16# range 0 .. 7;
INTFLAG at 16#18# range 0 .. 7;
STATUS at 16#1A# range 0 .. 15;
SYNCBUSY at 16#1C# range 0 .. 31;
LENGTH at 16#22# range 0 .. 15;
ADDR at 16#24# range 0 .. 31;
DATA at 16#28# range 0 .. 31;
DBGCTRL at 16#30# range 0 .. 7;
end record;
-------------------------------------
-- SercomUsart cluster's Registers --
-------------------------------------
subtype SERCOM_CTRLA_SERCOM_USART_MODE_Field is HAL.UInt3;
subtype SERCOM_CTRLA_SERCOM_USART_SAMPR_Field is HAL.UInt3;
subtype SERCOM_CTRLA_SERCOM_USART_TXPO_Field is HAL.UInt2;
subtype SERCOM_CTRLA_SERCOM_USART_RXPO_Field is HAL.UInt2;
subtype SERCOM_CTRLA_SERCOM_USART_SAMPA_Field is HAL.UInt2;
subtype SERCOM_CTRLA_SERCOM_USART_FORM_Field is HAL.UInt4;
-- USART Control A
type SERCOM_CTRLA_SERCOM_USART_Register is record
-- Software Reset
SWRST : Boolean := False;
-- Enable
ENABLE : Boolean := False;
-- Operating Mode
MODE : SERCOM_CTRLA_SERCOM_USART_MODE_Field := 16#0#;
-- unspecified
Reserved_5_6 : HAL.UInt2 := 16#0#;
-- Run during Standby
RUNSTDBY : Boolean := False;
-- Immediate Buffer Overflow Notification
IBON : Boolean := False;
-- Transmit Data Invert
TXINV : Boolean := False;
-- Receive Data Invert
RXINV : Boolean := False;
-- unspecified
Reserved_11_12 : HAL.UInt2 := 16#0#;
-- Sample
SAMPR : SERCOM_CTRLA_SERCOM_USART_SAMPR_Field := 16#0#;
-- Transmit Data Pinout
TXPO : SERCOM_CTRLA_SERCOM_USART_TXPO_Field := 16#0#;
-- unspecified
Reserved_18_19 : HAL.UInt2 := 16#0#;
-- Receive Data Pinout
RXPO : SERCOM_CTRLA_SERCOM_USART_RXPO_Field := 16#0#;
-- Sample Adjustment
SAMPA : SERCOM_CTRLA_SERCOM_USART_SAMPA_Field := 16#0#;
-- Frame Format
FORM : SERCOM_CTRLA_SERCOM_USART_FORM_Field := 16#0#;
-- Communication Mode
CMODE : Boolean := False;
-- Clock Polarity
CPOL : Boolean := False;
-- Data Order
DORD : Boolean := False;
-- unspecified
Reserved_31_31 : HAL.Bit := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for SERCOM_CTRLA_SERCOM_USART_Register use record
SWRST at 0 range 0 .. 0;
ENABLE at 0 range 1 .. 1;
MODE at 0 range 2 .. 4;
Reserved_5_6 at 0 range 5 .. 6;
RUNSTDBY at 0 range 7 .. 7;
IBON at 0 range 8 .. 8;
TXINV at 0 range 9 .. 9;
RXINV at 0 range 10 .. 10;
Reserved_11_12 at 0 range 11 .. 12;
SAMPR at 0 range 13 .. 15;
TXPO at 0 range 16 .. 17;
Reserved_18_19 at 0 range 18 .. 19;
RXPO at 0 range 20 .. 21;
SAMPA at 0 range 22 .. 23;
FORM at 0 range 24 .. 27;
CMODE at 0 range 28 .. 28;
CPOL at 0 range 29 .. 29;
DORD at 0 range 30 .. 30;
Reserved_31_31 at 0 range 31 .. 31;
end record;
subtype SERCOM_CTRLB_SERCOM_USART_CHSIZE_Field is HAL.UInt3;
subtype SERCOM_CTRLB_SERCOM_USART_LINCMD_Field is HAL.UInt2;
-- USART Control B
type SERCOM_CTRLB_SERCOM_USART_Register is record
-- Character Size
CHSIZE : SERCOM_CTRLB_SERCOM_USART_CHSIZE_Field := 16#0#;
-- unspecified
Reserved_3_5 : HAL.UInt3 := 16#0#;
-- Stop Bit Mode
SBMODE : Boolean := False;
-- unspecified
Reserved_7_7 : HAL.Bit := 16#0#;
-- Collision Detection Enable
COLDEN : Boolean := False;
-- Start of Frame Detection Enable
SFDE : Boolean := False;
-- Encoding Format
ENC : Boolean := False;
-- unspecified
Reserved_11_12 : HAL.UInt2 := 16#0#;
-- Parity Mode
PMODE : Boolean := False;
-- unspecified
Reserved_14_15 : HAL.UInt2 := 16#0#;
-- Transmitter Enable
TXEN : Boolean := False;
-- Receiver Enable
RXEN : Boolean := False;
-- unspecified
Reserved_18_23 : HAL.UInt6 := 16#0#;
-- Write-only. LIN Command
LINCMD : SERCOM_CTRLB_SERCOM_USART_LINCMD_Field := 16#0#;
-- unspecified
Reserved_26_31 : HAL.UInt6 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for SERCOM_CTRLB_SERCOM_USART_Register use record
CHSIZE at 0 range 0 .. 2;
Reserved_3_5 at 0 range 3 .. 5;
SBMODE at 0 range 6 .. 6;
Reserved_7_7 at 0 range 7 .. 7;
COLDEN at 0 range 8 .. 8;
SFDE at 0 range 9 .. 9;
ENC at 0 range 10 .. 10;
Reserved_11_12 at 0 range 11 .. 12;
PMODE at 0 range 13 .. 13;
Reserved_14_15 at 0 range 14 .. 15;
TXEN at 0 range 16 .. 16;
RXEN at 0 range 17 .. 17;
Reserved_18_23 at 0 range 18 .. 23;
LINCMD at 0 range 24 .. 25;
Reserved_26_31 at 0 range 26 .. 31;
end record;
subtype SERCOM_CTRLC_SERCOM_USART_GTIME_Field is HAL.UInt3;
subtype SERCOM_CTRLC_SERCOM_USART_BRKLEN_Field is HAL.UInt2;
subtype SERCOM_CTRLC_SERCOM_USART_HDRDLY_Field is HAL.UInt2;
subtype SERCOM_CTRLC_SERCOM_USART_MAXITER_Field is HAL.UInt3;
subtype SERCOM_CTRLC_SERCOM_USART_DATA32B_Field is HAL.UInt2;
-- USART Control C
type SERCOM_CTRLC_SERCOM_USART_Register is record
-- Guard Time
GTIME : SERCOM_CTRLC_SERCOM_USART_GTIME_Field := 16#0#;
-- unspecified
Reserved_3_7 : HAL.UInt5 := 16#0#;
-- LIN Master Break Length
BRKLEN : SERCOM_CTRLC_SERCOM_USART_BRKLEN_Field := 16#0#;
-- LIN Master Header Delay
HDRDLY : SERCOM_CTRLC_SERCOM_USART_HDRDLY_Field := 16#0#;
-- unspecified
Reserved_12_15 : HAL.UInt4 := 16#0#;
-- Inhibit Not Acknowledge
INACK : Boolean := False;
-- Disable Successive NACK
DSNACK : Boolean := False;
-- unspecified
Reserved_18_19 : HAL.UInt2 := 16#0#;
-- Maximum Iterations
MAXITER : SERCOM_CTRLC_SERCOM_USART_MAXITER_Field := 16#0#;
-- unspecified
Reserved_23_23 : HAL.Bit := 16#0#;
-- Data 32 Bit
DATA32B : SERCOM_CTRLC_SERCOM_USART_DATA32B_Field := 16#0#;
-- unspecified
Reserved_26_31 : HAL.UInt6 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for SERCOM_CTRLC_SERCOM_USART_Register use record
GTIME at 0 range 0 .. 2;
Reserved_3_7 at 0 range 3 .. 7;
BRKLEN at 0 range 8 .. 9;
HDRDLY at 0 range 10 .. 11;
Reserved_12_15 at 0 range 12 .. 15;
INACK at 0 range 16 .. 16;
DSNACK at 0 range 17 .. 17;
Reserved_18_19 at 0 range 18 .. 19;
MAXITER at 0 range 20 .. 22;
Reserved_23_23 at 0 range 23 .. 23;
DATA32B at 0 range 24 .. 25;
Reserved_26_31 at 0 range 26 .. 31;
end record;
subtype SERCOM_BAUD_FRAC_MODE_SERCOM_USART_BAUD_Field is HAL.UInt13;
subtype SERCOM_BAUD_FRAC_MODE_SERCOM_USART_FP_Field is HAL.UInt3;
-- USART Baud Rate
type SERCOM_BAUD_FRAC_MODE_SERCOM_USART_Register is record
-- Baud Rate Value
BAUD : SERCOM_BAUD_FRAC_MODE_SERCOM_USART_BAUD_Field := 16#0#;
-- Fractional Part
FP : SERCOM_BAUD_FRAC_MODE_SERCOM_USART_FP_Field := 16#0#;
end record
with Volatile_Full_Access, Size => 16,
Bit_Order => System.Low_Order_First;
for SERCOM_BAUD_FRAC_MODE_SERCOM_USART_Register use record
BAUD at 0 range 0 .. 12;
FP at 0 range 13 .. 15;
end record;
subtype SERCOM_BAUD_FRACFP_MODE_SERCOM_USART_BAUD_Field is HAL.UInt13;
subtype SERCOM_BAUD_FRACFP_MODE_SERCOM_USART_FP_Field is HAL.UInt3;
-- USART Baud Rate
type SERCOM_BAUD_FRACFP_MODE_SERCOM_USART_Register is record
-- Baud Rate Value
BAUD : SERCOM_BAUD_FRACFP_MODE_SERCOM_USART_BAUD_Field := 16#0#;
-- Fractional Part
FP : SERCOM_BAUD_FRACFP_MODE_SERCOM_USART_FP_Field := 16#0#;
end record
with Volatile_Full_Access, Size => 16,
Bit_Order => System.Low_Order_First;
for SERCOM_BAUD_FRACFP_MODE_SERCOM_USART_Register use record
BAUD at 0 range 0 .. 12;
FP at 0 range 13 .. 15;
end record;
-- USART Interrupt Enable Clear
type SERCOM_INTENCLR_SERCOM_USART_Register is record
-- Data Register Empty Interrupt Disable
DRE : Boolean := False;
-- Transmit Complete Interrupt Disable
TXC : Boolean := False;
-- Receive Complete Interrupt Disable
RXC : Boolean := False;
-- Receive Start Interrupt Disable
RXS : Boolean := False;
-- Clear To Send Input Change Interrupt Disable
CTSIC : Boolean := False;
-- Break Received Interrupt Disable
RXBRK : Boolean := False;
-- unspecified
Reserved_6_6 : HAL.Bit := 16#0#;
-- Combined Error Interrupt Disable
ERROR : Boolean := False;
end record
with Volatile_Full_Access, Size => 8, Bit_Order => System.Low_Order_First;
for SERCOM_INTENCLR_SERCOM_USART_Register use record
DRE at 0 range 0 .. 0;
TXC at 0 range 1 .. 1;
RXC at 0 range 2 .. 2;
RXS at 0 range 3 .. 3;
CTSIC at 0 range 4 .. 4;
RXBRK at 0 range 5 .. 5;
Reserved_6_6 at 0 range 6 .. 6;
ERROR at 0 range 7 .. 7;
end record;
-- USART Interrupt Enable Set
type SERCOM_INTENSET_SERCOM_USART_Register is record
-- Data Register Empty Interrupt Enable
DRE : Boolean := False;
-- Transmit Complete Interrupt Enable
TXC : Boolean := False;
-- Receive Complete Interrupt Enable
RXC : Boolean := False;
-- Receive Start Interrupt Enable
RXS : Boolean := False;
-- Clear To Send Input Change Interrupt Enable
CTSIC : Boolean := False;
-- Break Received Interrupt Enable
RXBRK : Boolean := False;
-- unspecified
Reserved_6_6 : HAL.Bit := 16#0#;
-- Combined Error Interrupt Enable
ERROR : Boolean := False;
end record
with Volatile_Full_Access, Size => 8, Bit_Order => System.Low_Order_First;
for SERCOM_INTENSET_SERCOM_USART_Register use record
DRE at 0 range 0 .. 0;
TXC at 0 range 1 .. 1;
RXC at 0 range 2 .. 2;
RXS at 0 range 3 .. 3;
CTSIC at 0 range 4 .. 4;
RXBRK at 0 range 5 .. 5;
Reserved_6_6 at 0 range 6 .. 6;
ERROR at 0 range 7 .. 7;
end record;
-- USART Interrupt Flag Status and Clear
type SERCOM_INTFLAG_SERCOM_USART_Register is record
-- Read-only. Data Register Empty Interrupt
DRE : Boolean := False;
-- Transmit Complete Interrupt
TXC : Boolean := False;
-- Read-only. Receive Complete Interrupt
RXC : Boolean := False;
-- Write-only. Receive Start Interrupt
RXS : Boolean := False;
-- Clear To Send Input Change Interrupt
CTSIC : Boolean := False;
-- Break Received Interrupt
RXBRK : Boolean := False;
-- unspecified
Reserved_6_6 : HAL.Bit := 16#0#;
-- Combined Error Interrupt
ERROR : Boolean := False;
end record
with Volatile_Full_Access, Size => 8, Bit_Order => System.Low_Order_First;
for SERCOM_INTFLAG_SERCOM_USART_Register use record
DRE at 0 range 0 .. 0;
TXC at 0 range 1 .. 1;
RXC at 0 range 2 .. 2;
RXS at 0 range 3 .. 3;
CTSIC at 0 range 4 .. 4;
RXBRK at 0 range 5 .. 5;
Reserved_6_6 at 0 range 6 .. 6;
ERROR at 0 range 7 .. 7;
end record;
-- USART Status
type SERCOM_STATUS_SERCOM_USART_Register is record
-- Parity Error
PERR : Boolean := False;
-- Frame Error
FERR : Boolean := False;
-- Buffer Overflow
BUFOVF : Boolean := False;
-- Read-only. Clear To Send
CTS : Boolean := False;
-- Inconsistent Sync Field
ISF : Boolean := False;
-- Collision Detected
COLL : Boolean := False;
-- Read-only. Transmitter Empty
TXE : Boolean := False;
-- Maximum Number of Repetitions Reached
ITER : Boolean := False;
-- unspecified
Reserved_8_15 : HAL.UInt8 := 16#0#;
end record
with Volatile_Full_Access, Size => 16,
Bit_Order => System.Low_Order_First;
for SERCOM_STATUS_SERCOM_USART_Register use record
PERR at 0 range 0 .. 0;
FERR at 0 range 1 .. 1;
BUFOVF at 0 range 2 .. 2;
CTS at 0 range 3 .. 3;
ISF at 0 range 4 .. 4;
COLL at 0 range 5 .. 5;
TXE at 0 range 6 .. 6;
ITER at 0 range 7 .. 7;
Reserved_8_15 at 0 range 8 .. 15;
end record;
-- USART Synchronization Busy
type SERCOM_SYNCBUSY_SERCOM_USART_Register is record
-- Read-only. Software Reset Synchronization Busy
SWRST : Boolean;
-- Read-only. SERCOM Enable Synchronization Busy
ENABLE : Boolean;
-- Read-only. CTRLB Synchronization Busy
CTRLB : Boolean;
-- Read-only. RXERRCNT Synchronization Busy
RXERRCNT : Boolean;
-- Read-only. LENGTH Synchronization Busy
LENGTH : Boolean;
-- unspecified
Reserved_5_31 : HAL.UInt27;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for SERCOM_SYNCBUSY_SERCOM_USART_Register use record
SWRST at 0 range 0 .. 0;
ENABLE at 0 range 1 .. 1;
CTRLB at 0 range 2 .. 2;
RXERRCNT at 0 range 3 .. 3;
LENGTH at 0 range 4 .. 4;
Reserved_5_31 at 0 range 5 .. 31;
end record;
subtype SERCOM_LENGTH_SERCOM_USART_LEN_Field is HAL.UInt8;
subtype SERCOM_LENGTH_SERCOM_USART_LENEN_Field is HAL.UInt2;
-- USART Length
type SERCOM_LENGTH_SERCOM_USART_Register is record
-- Data Length
LEN : SERCOM_LENGTH_SERCOM_USART_LEN_Field := 16#0#;
-- Data Length Enable
LENEN : SERCOM_LENGTH_SERCOM_USART_LENEN_Field := 16#0#;
-- unspecified
Reserved_10_15 : HAL.UInt6 := 16#0#;
end record
with Volatile_Full_Access, Size => 16,
Bit_Order => System.Low_Order_First;
for SERCOM_LENGTH_SERCOM_USART_Register use record
LEN at 0 range 0 .. 7;
LENEN at 0 range 8 .. 9;
Reserved_10_15 at 0 range 10 .. 15;
end record;
-- USART Debug Control
type SERCOM_DBGCTRL_SERCOM_USART_Register is record
-- Debug Mode
DBGSTOP : Boolean := False;
-- unspecified
Reserved_1_7 : HAL.UInt7 := 16#0#;
end record
with Volatile_Full_Access, Size => 8, Bit_Order => System.Low_Order_First;
for SERCOM_DBGCTRL_SERCOM_USART_Register use record
DBGSTOP at 0 range 0 .. 0;
Reserved_1_7 at 0 range 1 .. 7;
end record;
type SercomUsart_Disc is
(Default,
Frac_Mode,
Fracfp_Mode,
Usartfp_Mode);
pragma Warnings (Off, "bits of * unused");
-- USART Mode
type SercomUsart_Cluster
(Discriminent : SercomUsart_Disc := Default)
is record
-- USART Control A
CTRLA : aliased SERCOM_CTRLA_SERCOM_USART_Register;
-- USART Control B
CTRLB : aliased SERCOM_CTRLB_SERCOM_USART_Register;
-- USART Control C
CTRLC : aliased SERCOM_CTRLC_SERCOM_USART_Register;
-- USART Receive Pulse Length
RXPL : aliased HAL.UInt8;
-- USART Interrupt Enable Clear
INTENCLR : aliased SERCOM_INTENCLR_SERCOM_USART_Register;
-- USART Interrupt Enable Set
INTENSET : aliased SERCOM_INTENSET_SERCOM_USART_Register;
-- USART Interrupt Flag Status and Clear
INTFLAG : aliased SERCOM_INTFLAG_SERCOM_USART_Register;
-- USART Status
STATUS : aliased SERCOM_STATUS_SERCOM_USART_Register;
-- USART Synchronization Busy
SYNCBUSY : aliased SERCOM_SYNCBUSY_SERCOM_USART_Register;
-- USART Receive Error Count
RXERRCNT : aliased HAL.UInt8;
-- USART Length
LENGTH : aliased SERCOM_LENGTH_SERCOM_USART_Register;
-- USART Data
DATA : aliased HAL.UInt32;
-- USART Debug Control
DBGCTRL : aliased SERCOM_DBGCTRL_SERCOM_USART_Register;
case Discriminent is
when Default =>
-- USART Baud Rate
BAUD : aliased HAL.UInt16;
when Frac_Mode =>
-- USART Baud Rate
BAUD_FRAC_MODE : aliased
SERCOM_BAUD_FRAC_MODE_SERCOM_USART_Register;
when Fracfp_Mode =>
-- USART Baud Rate
BAUD_FRACFP_MODE : aliased
SERCOM_BAUD_FRACFP_MODE_SERCOM_USART_Register;
when Usartfp_Mode =>
-- USART Baud Rate
BAUD_USARTFP_MODE : aliased HAL.UInt16;
end case;
end record
with Unchecked_Union, Size => 416;
pragma Warnings (On, "bits of * unused");
for SercomUsart_Cluster use record
CTRLA at 16#0# range 0 .. 31;
CTRLB at 16#4# range 0 .. 31;
CTRLC at 16#8# range 0 .. 31;
RXPL at 16#E# range 0 .. 7;
INTENCLR at 16#14# range 0 .. 7;
INTENSET at 16#16# range 0 .. 7;
INTFLAG at 16#18# range 0 .. 7;
STATUS at 16#1A# range 0 .. 15;
SYNCBUSY at 16#1C# range 0 .. 31;
RXERRCNT at 16#20# range 0 .. 7;
LENGTH at 16#22# range 0 .. 15;
DATA at 16#28# range 0 .. 31;
DBGCTRL at 16#30# range 0 .. 7;
BAUD at 16#C# range 0 .. 15;
BAUD_FRAC_MODE at 16#C# range 0 .. 15;
BAUD_FRACFP_MODE at 16#C# range 0 .. 15;
BAUD_USARTFP_MODE at 16#C# range 0 .. 15;
end record;
-----------------
-- Peripherals --
-----------------
type SERCOM0_Disc is
(I2Cm,
I2Cs,
Spi_Mode,
Usart_Mode);
-- Serial Communication Interface 0
type SERCOM_Internal
(Discriminent : SERCOM0_Disc := I2Cm)
is record
case Discriminent is
when I2Cm =>
-- I2C Master Mode
SERCOM_I2CM : aliased SercomI2cm_Cluster;
when I2Cs =>
-- I2C Slave Mode
SERCOM_I2CS : aliased SercomI2cs_Cluster;
when Spi_Mode =>
-- SPI Mode
SERCOM_SPI : aliased SercomSpi_Cluster;
when Usart_Mode =>
-- USART Mode
SERCOM_USART : aliased SercomUsart_Cluster;
end case;
end record
with Unchecked_Union, Volatile;
for SERCOM_Internal use record
SERCOM_I2CM at 0 range 0 .. 415;
SERCOM_I2CS at 0 range 0 .. 351;
SERCOM_SPI at 0 range 0 .. 415;
SERCOM_USART at 0 range 0 .. 415;
end record;
end SAM.SERCOM;
|
-- { dg-do run }
-- { dg-options "-O3" }
procedure Round_Div is
type Fixed is delta 1.0 range -2147483648.0 .. 2147483647.0;
A : Fixed := 1.0;
B : Fixed := 3.0;
C : Integer;
function Divide (X, Y : Fixed) return Integer is
begin
return Integer (X / Y);
end;
begin
C := Divide (A, B);
if C /= 0 then
raise Program_Error;
end if;
end Round_Div;
|
-- WORDS, a Latin dictionary, by Colonel William Whitaker (USAF, Retired)
--
-- Copyright William A. Whitaker (1936–2010)
--
-- This is a free program, which means it is proper to copy it and pass
-- it on to your friends. Consider it a developmental item for which
-- there is no charge. However, just for form, it is Copyrighted
-- (c). Permission is hereby freely given for any and all use of program
-- and data. You can sell it as your own, but at least tell me.
--
-- This version is distributed without obligation, but the developer
-- would appreciate comments and suggestions.
--
-- All parts of the WORDS system, source code and data files, are made freely
-- available to anyone who wishes to use them, for whatever purpose.
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
package Words_Engine.Trick_Tables is
Tricks_Exception : exception;
type Trick_Class is (TC_Flip_Flop, TC_Flip, TC_Internal, TC_Slur);
type Trick (Op : Trick_Class := TC_Flip_Flop) is
record
Max : Integer := 0;
case Op is
when TC_Flip_Flop =>
FF1 : Unbounded_String := Null_Unbounded_String;
FF2 : Unbounded_String := Null_Unbounded_String;
when TC_Flip =>
FF3 : Unbounded_String := Null_Unbounded_String;
FF4 : Unbounded_String := Null_Unbounded_String;
when TC_Internal =>
I1 : Unbounded_String := Null_Unbounded_String;
I2 : Unbounded_String := Null_Unbounded_String;
when TC_Slur =>
S1 : Unbounded_String := Null_Unbounded_String;
end case;
end record;
type TricksT is array (Integer range <>) of Trick;
type Strings is array (Integer range <>) of Unbounded_String;
function Member (Needle : Unbounded_String;
Haystack : Strings) return Boolean;
function "+" (Source : String) return Unbounded_String
renames To_Unbounded_String;
function Common_Prefix (S : String) return Boolean;
function Get_Tricks_Table (C : Character) return TricksT;
function Get_Slur_Tricks_Table (C : Character) return TricksT;
Any_Tricks : constant TricksT := (
(Max => 0, Op => TC_Internal, I1 => +"ae", I2 => +"e"),
(Max => 0, Op => TC_Internal, I1 => +"bul", I2 => +"bol"),
(Max => 0, Op => TC_Internal, I1 => +"bol", I2 => +"bul"),
(Max => 0, Op => TC_Internal, I1 => +"cl", I2 => +"cul"),
(Max => 0, Op => TC_Internal, I1 => +"cu", I2 => +"quu"),
(Max => 0, Op => TC_Internal, I1 => +"f", I2 => +"ph"),
(Max => 0, Op => TC_Internal, I1 => +"ph", I2 => +"f"),
(Max => 0, Op => TC_Internal, I1 => +"h", I2 => +""),
(Max => 0, Op => TC_Internal, I1 => +"oe", I2 => +"e"),
(Max => 0, Op => TC_Internal, I1 => +"vul", I2 => +"vol"),
(Max => 0, Op => TC_Internal, I1 => +"vol", I2 => +"vul"),
(Max => 0, Op => TC_Internal, I1 => +"uol", I2 => +"vul")
);
Mediaeval_Tricks : constant TricksT := (
-- Harrington/Elliott 1.1.1
(Max => 0, Op => TC_Internal, I1 => +"col", I2 => +"caul"),
-- Harrington/Elliott 1.3
(Max => 0, Op => TC_Internal, I1 => +"e", I2 => +"ae"),
(Max => 0, Op => TC_Internal, I1 => +"o", I2 => +"u"),
(Max => 0, Op => TC_Internal, I1 => +"i", I2 => +"y"),
-- Harrington/Elliott 1.3.1
(Max => 0, Op => TC_Internal, I1 => +"ism", I2 => +"sm"),
(Max => 0, Op => TC_Internal, I1 => +"isp", I2 => +"sp"),
(Max => 0, Op => TC_Internal, I1 => +"ist", I2 => +"st"),
(Max => 0, Op => TC_Internal, I1 => +"iz", I2 => +"z"),
(Max => 0, Op => TC_Internal, I1 => +"esm", I2 => +"sm"),
(Max => 0, Op => TC_Internal, I1 => +"esp", I2 => +"sp"),
(Max => 0, Op => TC_Internal, I1 => +"est", I2 => +"st"),
(Max => 0, Op => TC_Internal, I1 => +"ez", I2 => +"z"),
-- Harrington/Elliott 1.4
(Max => 0, Op => TC_Internal, I1 => +"di", I2 => +"z"),
(Max => 0, Op => TC_Internal, I1 => +"f", I2 => +"ph"),
(Max => 0, Op => TC_Internal, I1 => +"is", I2 => +"ix"),
(Max => 0, Op => TC_Internal, I1 => +"b", I2 => +"p"),
(Max => 0, Op => TC_Internal, I1 => +"d", I2 => +"t"),
(Max => 0, Op => TC_Internal, I1 => +"v", I2 => +"b"),
(Max => 0, Op => TC_Internal, I1 => +"v", I2 => +"f"),
(Max => 0, Op => TC_Internal, I1 => +"v", I2 => +"f"),
(Max => 0, Op => TC_Internal, I1 => +"s", I2 => +"x"),
-- Harrington/Elliott 1.4.1
(Max => 0, Op => TC_Internal, I1 => +"ci", I2 => +"ti"),
-- Harrington/Elliott 1.4.2
(Max => 0, Op => TC_Internal, I1 => +"nt", I2 => +"nct"),
(Max => 0, Op => TC_Internal, I1 => +"s", I2 => +"ns"),
-- Others
(Max => 0, Op => TC_Internal, I1 => +"ch", I2 => +"c"),
(Max => 0, Op => TC_Internal, I1 => +"c", I2 => +"ch"),
(Max => 0, Op => TC_Internal, I1 => +"th", I2 => +"t"),
(Max => 0, Op => TC_Internal, I1 => +"t", I2 => +"th")
);
end Words_Engine.Trick_Tables;
|
package body afrl.cmasi.location3D is
function getFullLmcpTypeName(this : Location3D) return String is ("afrl.cmasi.location3D.Location3D");
function getLmcpTypeName(this : Location3D) return String is ("Location3D");
function getLmcpType(this : Location3D) return UInt32_t is (CMASIEnum'Pos(LOCATION3D_ENUM));
function getLatitude (this : Location3D'Class) return Double_t is (this.Latitude);
procedure setLatitude(this : out Location3D'Class; Latitude : in Double_t) is
begin
this.Latitude := Latitude;
end setLatitude;
function getLongitude(this : Location3D'Class) return Double_t is (this.Longitude);
procedure setLongitude(this : out Location3D'Class; Longitude : in double_t) is
begin
this.Longitude := Longitude;
end setLongitude;
function getAltitude(this : Location3D'Class) return Float_t is (this.Altitude);
procedure setAltitude(this : out Location3D'Class; Altitude : in Float_t) is
begin
this.Altitude := Altitude;
end setAltitude;
function getAltitudeType(this : Location3D'Class) return AltitudeTypeEnum is (this.AltitudeType);
procedure setAltitudeType(this : out Location3D'Class; AltitudeType : in AltitudeTypeEnum) is
begin
this.AltitudeType := AltitudeType;
end setAltitudeType;
end afrl.cmasi.location3D;
|
with Ada.Containers.Vectors;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
package Parser is
-- Declare needed types
type Parts is array (0 .. 3) of Unbounded_String;
package Parts_Vector is new Ada.Containers.Vectors
( Index_Type => Natural,
Element_Type => Parts );
use Parts_Vector;
-- Functions
procedure Parse_Input(Input : String; All_Parts : in out Parts_Vector.Vector);
function Load_File(Path : String) return Parts_Vector.Vector;
function Get_Part(All_Lines : Parts_Vector.Vector; Name : String) return Parts_Vector.Vector;
procedure Parser_Debug(All_Lines : Parts_Vector.Vector);
end Parser;
|
-- Copyright (c) 2015-2017 Maxim Reznik <reznikmm@gmail.com>
--
-- SPDX-License-Identifier: MIT
-- License-Filename: LICENSE
-------------------------------------------------------------
with Incr.Documents;
with Incr.Lexers.Incremental;
with Incr.Nodes;
with Incr.Version_Trees;
package Incr.Parsers.Incremental is
-- @summary
-- Incremental Parser
--
-- @description
-- This package provides incremental syntactical analyser.
--
-- The package uses three versions of the document:
--
-- * Reference - version when last analysis completed
-- * Changing - current version under construction
-- * Previous - last read-olny version of document to be analyzed
--
package Parser_Data_Providers is
type Parser_State is new Natural;
type Production_Index is new Natural;
type Action_Kinds is (Shift, Reduce, Error, Finish);
type Action (Kind : Action_Kinds := Error) is record
case Kind is
when Shift =>
State : Parser_State;
when Reduce =>
Prod : Production_Index;
when Error | Finish =>
null;
end case;
end record;
type Action_Table is array
(Parser_State range <>, Nodes.Token_Kind range <>) of Action;
type Action_Table_Access is access constant Action_Table;
type State_Table is array
(Parser_State range <>, Nodes.Node_Kind range <>) of Parser_State;
type State_Table_Access is access constant State_Table;
type Parts_Count_Table is array (Production_Index range <>) of Natural;
type Parts_Count_Table_Access is access constant Parts_Count_Table;
type Parser_Data_Provider is limited interface;
type Parser_Data_Provider_Access is
access all Parser_Data_Provider'Class;
not overriding function Actions
(Self : Parser_Data_Provider) return Action_Table_Access is abstract;
not overriding function States
(Self : Parser_Data_Provider) return State_Table_Access is abstract;
not overriding function Part_Counts
(Self : Parser_Data_Provider) return Parts_Count_Table_Access is
abstract;
not overriding function Kind_Image
(Self : Parser_Data_Provider;
Kind : Nodes.Node_Kind) return Wide_Wide_String is abstract;
type Node_Factory is limited interface;
type Node_Factory_Access is access all Node_Factory'Class;
not overriding procedure Create_Node
(Self : aliased in out Node_Factory;
Prod : Production_Index;
Children : Nodes.Node_Array;
Node : out Nodes.Node_Access;
Kind : out Nodes.Node_Kind) is abstract;
end Parser_Data_Providers;
type Incremental_Parser is tagged limited private;
-- Type to perform incremental lexical analysis
type Incremental_Parser_Access is access Incremental_Parser;
procedure Run
(Self : Incremental_Parser;
Lexer : Incr.Lexers.Incremental.Incremental_Lexer_Access;
Provider : Parser_Data_Providers.Parser_Data_Provider_Access;
Factory : Parser_Data_Providers.Node_Factory_Access;
Document : Documents.Document_Access;
Reference : Version_Trees.Version);
-- Start analysis by looking for tokens where re-lexing should be start.
-- Mark them with Need_Analysis flag.
private
type Incremental_Parser is tagged limited record
null;
end record;
end Incr.Parsers.Incremental;
|
-- -----------------------------------------------------------------------------
-- Copyright (C) 2003-2019 Stichting Mapcode Foundation (http://www.mapcode.com)
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-- -----------------------------------------------------------------------------
package body Language_Utils is
-- Make Unicode_Sequence
function To_Unicode (Str : String) return Unicode_Sequence is
Res : Unicode_Sequence (1 .. Str'Length);
begin
for I in Str'Range loop
Res(I - Str'First + 1) := Character'Pos (Str(I));
end loop;
return Res;
end To_Unicode;
-- Make character set
function To_Set (Code : Char_Code) return Char_Set is
Res : Char_Set;
begin
for I in Code'Range loop
Res (I - Code'First + 1) := Wide_Character'Val (Code(I));
end loop;
return Res;
end To_Set;
-- Make descriptor
function Build_Desc (Name : Unicode_Sequence;
Code : Char_Code) return Language_Desc is
Res : Language_Desc (Name'Length);
begin
Res.Name.Txt := Name;
Res.Set := To_Set (Code);
-- Store first and last character of the set
Res.First := Wide_Character'Last;
Res.Last := Wide_Character'First;
for C of Res.Set loop
if C > '9' and then C /= 'I' and then C /= 'O' then
-- Discard characterers that are shared
if C < Res.First then
Res.First := C;
end if;
if C > '9' and then C > Res.Last then
Res.Last := C;
end if;
end if;
end loop;
return Res;
end Build_Desc;
end Language_Utils;
|
-- SPDX-FileCopyrightText: 2020 Max Reznik <reznikmm@gmail.com>
--
-- SPDX-License-Identifier: MIT
----------------------------------------------------------------
with League.Strings;
with XML.SAX.Attributes;
with XML.SAX.Output_Destinations;
with XML.SAX.Writers;
package Custom_Writers is
type SAX_Output_Destination_Access is
access all XML.SAX.Output_Destinations.SAX_Output_Destination'Class;
type Writer is limited new XML.SAX.Writers.SAX_Writer with private;
procedure Set_Output_Destination
(Self : in out Writer'Class;
Output : not null SAX_Output_Destination_Access);
not overriding procedure Unescaped_Characters
(Self : in out Writer;
Text : League.Strings.Universal_String);
private
type Writer is limited new XML.SAX.Writers.SAX_Writer with record
Output : SAX_Output_Destination_Access;
Tag : League.Strings.Universal_String;
CDATA : Boolean := False;
end record;
overriding function Error_String
(Self : Writer) return League.Strings.Universal_String;
overriding procedure Characters
(Self : in out Writer;
Text : League.Strings.Universal_String;
Success : in out Boolean);
overriding procedure End_Element
(Self : in out Writer;
Namespace_URI : League.Strings.Universal_String;
Local_Name : League.Strings.Universal_String;
Qualified_Name : League.Strings.Universal_String;
Success : in out Boolean);
overriding procedure Start_Element
(Self : in out Writer;
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);
overriding procedure Comment
(Self : in out Writer;
Text : League.Strings.Universal_String;
Success : in out Boolean);
overriding procedure Processing_Instruction
(Self : in out Writer;
Target : League.Strings.Universal_String;
Data : League.Strings.Universal_String;
Success : in out Boolean);
overriding procedure Start_CDATA
(Self : in out Writer;
Success : in out Boolean);
overriding procedure End_CDATA
(Self : in out Writer;
Success : in out Boolean);
end Custom_Writers;
|
-- SPDX-License-Identifier: MIT
--
-- Copyright (c) 2009 - 2019 Gautier de Montmollin
-- SWITZERLAND
--
-- 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.
-- The "Deflate" method combines a LZ77 compression
-- method with some Huffman encoding gymnastics
-- Magic numbers in this procedure are adjusted through experimentation and marked with: *Tuned*
--
-- To do:
-- - Taillaule: try with slider and/or initial lz window not centered
-- - Taillaule: compare slider to random and fixed in addition to initial
-- - Taillaule: try L_sup distance
-- - Taillaule: restrict BL_Vector to short LZ distances (long distances perhaps too random)
-- - Taillaule: check LZ vector norms on literals only, too (consider
-- distances & lengths as noise)
-- - Taillaule: use a corpus of files badly compressed by our Deflate comparatively
-- to other Deflates (e.g. 7Z seems better with databases)
-- - Add DeflOpt to slowest method, or approximate it by tweaking
-- distance and length statistics before computing their Huffman codes, or
-- reinvent it by computing the size of emitted codes and trying slight changes
-- to the codes' bit lengths.
-- - Improve LZ77 compression: see Zip.LZ77 to-do list; check with bypass_LZ77 below
-- and various programs based on LZ77 using the trace >= some and the LZ77 dump
-- in UnZip.Decompress.
-- - Make this procedure standalone & generic like LZMA.Encoding;
-- use it in the Zada project (Zlib replacement)
with System;
with Ada.Unchecked_Deallocation;
with DCF.Zip.CRC;
with DCF.Streams;
with DCF.Lz77;
with DCF.Length_Limited_Huffman_Code_Lengths;
procedure DCF.Zip.Compress.Deflate
(Input, Output : in out DCF.Streams.Root_Zipstream_Type'Class;
Input_Size : File_Size_Type;
Feedback : Feedback_Proc;
Method : Deflation_Method;
CRC : in out Unsigned_32; -- Only updated here
Output_Size : out File_Size_Type;
Compression_Ok : out Boolean) -- Indicates compressed < uncompressed
is
-- Options for testing.
-- All should be on False for normal use of this procedure.
Deactivate_Scanning : constant Boolean := False; -- Impact analysis of the scanning method
-- System.Word_Size: 13.3(8): A word is the largest amount of storage
-- that can be conveniently and efficiently manipulated by the hardware,
-- given the implementation's run-time model
Min_Bits_32 : constant := Integer'Max (32, System.Word_Size);
-- We define an Integer type which is at least 32 bits, but n bits
-- on a native n (> 32) bits architecture (no performance hit on 64+
-- bits architectures).
-- Integer_M16 not needed: Integer already guarantees 16 bits
type Integer_M32 is range -2**(Min_Bits_32 - 1) .. 2**(Min_Bits_32 - 1) - 1;
subtype Natural_M32 is Integer_M32 range 0 .. Integer_M32'Last;
subtype Positive_M32 is Integer_M32 range 1 .. Integer_M32'Last;
-------------------------------------
-- Buffered I/O - byte granularity --
-------------------------------------
-- Define data types needed to implement input and output file buffers
procedure Dispose_Buffer is new Ada.Unchecked_Deallocation (Byte_Buffer, P_Byte_Buffer);
Inbuf : P_Byte_Buffer; -- I/O buffers
Outbuf : P_Byte_Buffer;
Inbufidx : Positive; -- Points to next char in buffer to be read
Outbufidx : Positive := 1; -- Points to next free space in output buffer
Maxinbufidx : Natural; -- Count of valid chars in input buffer
Inputeof : Boolean; -- End of file indicator
procedure Read_Block is
begin
Zip.Blockread (Stream => Input, Buffer => Inbuf.all, Actually_Read => Maxinbufidx);
Inputeof := Maxinbufidx = 0;
Inbufidx := 1;
end Read_Block;
-- Exception for the case where compression works but produces
-- a bigger file than the file to be compressed (data is too "random").
Compression_Inefficient : exception;
procedure Write_Block is
Amount : constant Integer := Outbufidx - 1;
begin
Output_Size := Output_Size + File_Size_Type (Integer'Max (0, Amount));
if Output_Size >= Input_Size then
-- The compression so far is obviously inefficient for that file.
-- Useless to go further.
-- Stop immediately before growing the file more than the
-- uncompressed size.
raise Compression_Inefficient;
end if;
Zip.Blockwrite (Output, Outbuf (1 .. Amount));
Outbufidx := 1;
end Write_Block;
procedure Put_Byte (B : Byte) is -- Put a byte, at the byte granularity level
pragma Inline (Put_Byte);
begin
Outbuf (Outbufidx) := B;
Outbufidx := Outbufidx + 1;
if Outbufidx > Outbuf'Last then
Write_Block;
end if;
end Put_Byte;
procedure Flush_Byte_Buffer is
begin
if Outbufidx > 1 then
Write_Block;
end if;
end Flush_Byte_Buffer;
------------------------------------------------------
-- Bit code buffer, for sending data at bit level --
------------------------------------------------------
-- Output buffer. Bits are inserted starting at the right (least
-- significant bits). The width of bit_buffer must be at least 16 bits
subtype U32 is Unsigned_32;
Bit_Buffer : U32 := 0;
-- Number of valid bits in bit_buffer. All bits above the last valid bit are always zero
Valid_Bits : Integer := 0;
procedure Flush_Bit_Buffer is
begin
while Valid_Bits > 0 loop
Put_Byte (Byte (Bit_Buffer and 16#FF#));
Bit_Buffer := Shift_Right (Bit_Buffer, 8);
Valid_Bits := Integer'Max (0, Valid_Bits - 8);
end loop;
Bit_Buffer := 0;
end Flush_Bit_Buffer;
-- Bit codes are at most 15 bits for Huffman codes,
-- or 13 for explicit codes (distance extra bits).
subtype Code_Size_Type is Integer range 1 .. 15;
-- Send a value on a given number of bits.
procedure Put_Code (Code : U32; Code_Size : Code_Size_Type) is
pragma Inline (Put_Code);
begin
-- Put bits from code at the left of existing ones. They might be shifted away
-- partially on the left side (or even entirely if valid_bits is already = 32).
Bit_Buffer := Bit_Buffer or Shift_Left (Code, Valid_Bits);
Valid_Bits := Valid_Bits + Code_Size;
if Valid_Bits > 32 then
-- Flush 32 bits to output as 4 bytes
Put_Byte (Byte (Bit_Buffer and 16#FF#));
Put_Byte (Byte (Shift_Right (Bit_Buffer, 8) and 16#FF#));
Put_Byte (Byte (Shift_Right (Bit_Buffer, 16) and 16#FF#));
Put_Byte (Byte (Shift_Right (Bit_Buffer, 24) and 16#FF#));
Valid_Bits := Valid_Bits - 32;
-- Empty buffer and put on it the rest of the code
Bit_Buffer := Shift_Right (Code, Code_Size - Valid_Bits);
end if;
end Put_Code;
------------------------------------------------------
-- Deflate, post LZ encoding, with Huffman encoding --
------------------------------------------------------
Invalid : constant := -1;
subtype Huffman_Code_Range is Integer range Invalid .. Integer'Last;
type Length_Code_Pair is record
Bit_Length : Natural; -- Huffman code length, in bits
Code : Huffman_Code_Range := Invalid; -- The code itself
end record;
procedure Invert (Lc : in out Length_Code_Pair) is
pragma Inline (Invert);
A : Natural := Lc.Code;
B : Natural := 0;
begin
for I in 1 .. Lc.Bit_Length loop
B := B * 2 + A mod 2;
A := A / 2;
end loop;
Lc.Code := B;
end Invert;
-- The Huffman code set (and therefore the Huffman tree) is completely determined by
-- the bit length to be used for reaching leaf nodes, thanks to two special
-- rules (explanation in RFC 1951, section 3.2.2).
--
-- So basically the process is the following:
--
-- (A) Gather statistics (just counts) for the alphabet
-- (B) Turn these counts into code lengths, by calling Length_limited_Huffman_code_lengths
-- (C) Build Huffman codes (the bits to be sent) with a call to Prepare_Huffman_codes
--
-- In short:
--
-- data -> (A) -> stats -> (B) -> Huffman codes' bit lengths -> (C) -> Huffman codes
type Huff_Descriptor is array (Natural range <>) of Length_Code_Pair;
type Bit_Length_Array is array (Natural range <>) of Natural;
subtype Alphabet_Lit_Len is Natural range 0 .. 287;
subtype Bit_Length_Array_Lit_Len is Bit_Length_Array (Alphabet_Lit_Len);
subtype Alphabet_Dis is Natural range 0 .. 31;
subtype Bit_Length_Array_Dis is Bit_Length_Array (Alphabet_Dis);
type Deflate_Huff_Descriptors is record
-- Tree descriptor for Literal, EOB or Length encoding
Lit_Len : Huff_Descriptor (0 .. 287);
-- Tree descriptor for Distance encoding
Dis : Huff_Descriptor (0 .. 31);
end record;
-- NB: Appnote: "Literal codes 286-287 and distance codes 30-31 are never used
-- but participate in the Huffman construction."
-- Setting upper bound to 285 for literals leads to invalid codes, sometimes.
-- Copy bit length vectors into Deflate Huffman descriptors
function Build_Descriptors
(Bl_For_Lit_Len : Bit_Length_Array_Lit_Len;
Bl_For_Dis : Bit_Length_Array_Dis) return Deflate_Huff_Descriptors
is
New_D : Deflate_Huff_Descriptors;
begin
for I in New_D.Lit_Len'Range loop
New_D.Lit_Len (I) := (Bit_Length => Bl_For_Lit_Len (I), Code => Invalid);
end loop;
for I in New_D.Dis'Range loop
New_D.Dis (I) := (Bit_Length => Bl_For_Dis (I), Code => Invalid);
end loop;
return New_D;
end Build_Descriptors;
type Count_Type is range 0 .. File_Size_Type'Last / 2 - 1;
type Stats_Type is array (Natural range <>) of Count_Type;
-- The following is a translation of Zopfli's OptimizeHuffmanForRle (v. 11-May-2016).
-- Possible gain: shorten the compression header containing the Huffman trees' bit lengths.
-- Possible loss: since the stats do not correspond anymore exactly to the data
-- to be compressed, the Huffman trees might be suboptimal.
--
-- Zopfli comment:
-- Changes the population counts in a way that the consequent Huffman tree
-- compression, especially its rle-part, will be more likely to compress this data
-- more efficiently.
procedure Tweak_For_Better_Rle (Counts : in out Stats_Type) is
Length : Integer := Counts'Length;
Stride : Integer;
Symbol, Sum, Limit, New_Count : Count_Type;
Good_For_Rle : array (Counts'Range) of Boolean := (others => False);
begin
-- 1) We don't want to touch the trailing zeros. We may break the
-- rules of the format by adding more data in the distance codes.
loop
if Length = 0 then
return;
end if;
exit when Counts (Length - 1) /= 0;
Length := Length - 1;
end loop;
-- Now counts(0..length - 1) does not have trailing zeros.
--
-- 2) Let's mark all population counts that already can be encoded with an rle code.
--
-- Let's not spoil any of the existing good rle codes.
-- Mark any seq of 0's that is longer than 5 as a good_for_rle.
-- Mark any seq of non-0's that is longer than 7 as a good_for_rle.
Symbol := Counts (0);
Stride := 0;
for I in 0 .. Length loop
if I = Length or else Counts (I) /= Symbol then
if (Symbol = 0 and then Stride >= 5) or else (Symbol /= 0 and then Stride >= 7) then
for K in 0 .. Stride - 1 loop
Good_For_Rle (I - K - 1) := True;
end loop;
end if;
Stride := 1;
if I /= Length then
Symbol := Counts (I);
end if;
else
Stride := Stride + 1;
end if;
end loop;
-- 3) Let's replace those population counts that lead to more rle codes.
Stride := 0;
Limit := Counts (0);
Sum := 0;
for I in 0 .. Length loop
if I = Length
or else Good_For_Rle (I)
or else (I > 0 and then Good_For_Rle (I - 1)) -- Added from Brotli, item #1
-- Heuristic for selecting the stride ranges to collapse.
or else abs (Counts (I) - Limit) >= 4
then
if Stride >= 4 or else (Stride >= 3 and then Sum = 0) then
-- The stride must end, collapse what we have, if we have enough (4).
-- New_Count is the average of counts on the stride's interval, upper-rounded
New_Count :=
Count_Type'Max (1, (Sum + Count_Type (Stride) / 2) / Count_Type (Stride));
if Sum = 0 then
-- Don't make an all zeros stride to be upgraded to ones.
New_Count := 0;
end if;
for K in 0 .. Stride - 1 loop
-- We don't want to change value at counts(i),
-- that is already belonging to the next stride. Thus - 1.
-- Replace histogram value by averaged value
Counts (I - K - 1) := New_Count;
end loop;
end if;
Stride := 0;
Sum := 0;
if I < Length - 3 then
-- All interesting strides have a count of at least 4, at
-- least when non-zeros. Limit is the average of next 4
-- counts, upper-rounded
Limit := (Counts (I) + Counts (I + 1) + Counts (I + 2) + Counts (I + 3) + 2) / 4;
elsif I < Length then
Limit := Counts (I);
else
Limit := 0;
end if;
end if;
Stride := Stride + 1;
if I /= Length then
Sum := Sum + Counts (I);
end if;
end loop;
end Tweak_For_Better_Rle;
subtype Stats_Lit_Len_Type is Stats_Type (Alphabet_Lit_Len);
subtype Stats_Dis_Type is Stats_Type (Alphabet_Dis);
-- Phase (B) : we turn statistics into Huffman bit lengths
function Build_Descriptors
(Stats_Lit_Len : Stats_Lit_Len_Type;
Stats_Dis : Stats_Dis_Type) return Deflate_Huff_Descriptors
is
Bl_For_Lit_Len : Bit_Length_Array_Lit_Len;
Bl_For_Dis : Bit_Length_Array_Dis;
procedure Llhcl_Lit_Len is new Length_Limited_Huffman_Code_Lengths
(Alphabet_Lit_Len,
Count_Type,
Stats_Lit_Len_Type,
Bit_Length_Array_Lit_Len,
15);
procedure Llhcl_Dis is new Length_Limited_Huffman_Code_Lengths
(Alphabet_Dis,
Count_Type,
Stats_Dis_Type,
Bit_Length_Array_Dis,
15);
Stats_Dis_Copy : Stats_Dis_Type := Stats_Dis;
Used : Natural := 0;
begin
-- See "PatchDistanceCodesForBuggyDecoders" in Zopfli's deflate.c
-- NB: here, we patch the occurrences and not the bit lengths, to avoid invalid codes.
-- The decoding bug concerns Zlib v.<= 1.2.1, UnZip v.<= 6.0, WinZip v.10.0.
for I in Stats_Dis_Copy'Range loop
if Stats_Dis_Copy (I) /= 0 then
Used := Used + 1;
end if;
end loop;
if Used < 2 then
if Used = 0 then -- No distance code used at all (data must be almost random)
Stats_Dis_Copy (0) := 1;
Stats_Dis_Copy (1) := 1;
elsif Stats_Dis_Copy (0) = 0 then
Stats_Dis_Copy (0) := 1; -- now code 0 and some other code have non-zero counts
else
Stats_Dis_Copy (1) := 1; -- now codes 0 and 1 have non-zero counts
end if;
end if;
Llhcl_Lit_Len (Stats_Lit_Len, Bl_For_Lit_Len); -- Call the magic algorithm for setting
Llhcl_Dis (Stats_Dis_Copy, Bl_For_Dis); -- up Huffman lengths of both trees
return Build_Descriptors (Bl_For_Lit_Len, Bl_For_Dis);
end Build_Descriptors;
-- Here is one original part in the Taillaule algorithm: use of basic
-- topology (L1, L2 distances) to check similarities between Huffman code sets.
-- Bit length vector. Convention: 16 is unused bit length (close to the bit length for the
-- rarest symbols, 15, and far from the bit length for the most frequent symbols, 1).
-- Deflate uses 0 for unused.
subtype Bl_Code is Integer_M32 range 1 .. 16;
type Bl_Vector is array (1 .. 288 + 32) of Bl_Code;
function Convert (H : Deflate_Huff_Descriptors) return Bl_Vector is
Bv : Bl_Vector;
J : Positive := 1;
begin
for I in H.Lit_Len'Range loop
if H.Lit_Len (I).Bit_Length = 0 then
Bv (J) := 16;
else
Bv (J) := Integer_M32 (H.Lit_Len (I).Bit_Length);
end if;
J := J + 1;
end loop;
for I in H.Dis'Range loop
if H.Dis (I).Bit_Length = 0 then
Bv (J) := 16;
else
Bv (J) := Integer_M32 (H.Dis (I).Bit_Length);
end if;
J := J + 1;
end loop;
return Bv;
end Convert;
-- L1 or Manhattan distance
function L1_Distance (B1, B2 : Bl_Vector) return Natural_M32 is
S : Natural_M32 := 0;
begin
for I in B1'Range loop
S := S + abs (B1 (I) - B2 (I));
end loop;
return S;
end L1_Distance;
-- L1, tweaked
Tweak : constant array (Bl_Code) of Positive_M32 :=
-- For the origin of the tweak function, see "za_work.xls", sheet "Deflate".
-- function f3 = 0.20 f1 [logarithmic] + 0.80 * identity
-- NB: all values are multiplied by 100 for accuracy.
(100, 255, 379, 490, 594, 694, 791, 885, 978, 1069, 1159, 1249, 1338, 1426, 1513, 1600);
-- Neutral is:
-- (100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500, 1600)
function L1_Tweaked (B1, B2 : Bl_Vector) return Natural_M32 is
S : Natural_M32 := 0;
begin
for I in B1'Range loop
S := S + abs (Tweak (B1 (I)) - Tweak (B2 (I)));
end loop;
return S;
end L1_Tweaked;
-- L2 or Euclidean distance
function L2_Distance_Square (B1, B2 : Bl_Vector) return Natural_M32 is
S : Natural_M32 := 0;
begin
for I in B1'Range loop
S := S + (B1 (I) - B2 (I))**2;
end loop;
return S;
end L2_Distance_Square;
-- L2, tweaked
function L2_Tweaked_Square (B1, B2 : Bl_Vector) return Natural_M32 is
S : Natural_M32 := 0;
begin
for I in B1'Range loop
S := S + (Tweak (B1 (I)) - Tweak (B2 (I)))**2;
end loop;
return S;
end L2_Tweaked_Square;
type Distance_Type is (L1, L1_Tweaked, L2, L2_Tweaked);
function Similar
(H1, H2 : Deflate_Huff_Descriptors;
Dist_Kind : Distance_Type;
Threshold : Natural;
Comment : String) return Boolean
is
Dist : Natural_M32;
Thres : Natural_M32 := Natural_M32 (Threshold);
begin
case Dist_Kind is
when L1 =>
Dist := L1_Distance (Convert (H1), Convert (H2));
when L1_Tweaked =>
Thres := Thres * Tweak (1);
Dist := L1_Tweaked (Convert (H1), Convert (H2));
when L2 =>
Thres := Thres * Thres;
Dist := L2_Distance_Square (Convert (H1), Convert (H2));
when L2_Tweaked =>
Thres := (Thres * Thres) * (Tweak (1) * Tweak (1));
Dist := L2_Tweaked_Square (Convert (H1), Convert (H2));
end case;
return Dist < Thres;
end Similar;
-- Another original part in the Taillaule algorithm: the possibility of recycling
-- Huffman codes. It is possible only if previous block was not stored and if
-- the new block's used alphabets are included in the old block's used alphabets.
function Recyclable (H_Old, H_New : Deflate_Huff_Descriptors) return Boolean is
begin
for I in H_Old.Lit_Len'Range loop
if H_Old.Lit_Len (I).Bit_Length = 0 and H_New.Lit_Len (I).Bit_Length > 0 then
return False; -- Code used in new, but not in old
end if;
end loop;
for I in H_Old.Dis'Range loop
if H_Old.Dis (I).Bit_Length = 0 and H_New.Dis (I).Bit_Length > 0 then
return False; -- Code used in new, but not in old
end if;
end loop;
return True;
end Recyclable;
-- Phase (C): the Prepare_Huffman_codes procedure finds the Huffman code for each
-- value, given the bit length imposed as input.
procedure Prepare_Huffman_Codes (Hd : in out Huff_Descriptor) is
Max_Huffman_Bits : constant := 15;
Bl_Count, Next_Code : array (0 .. Max_Huffman_Bits) of Natural := (others => 0);
Code : Natural := 0;
Bl : Natural;
begin
-- Algorithm from RFC 1951, section 3.2.2.
-- Step 1)
for I in Hd'Range loop
Bl := Hd (I).Bit_Length;
Bl_Count (Bl) := Bl_Count (Bl) + 1; -- One more code to be defined with bit length bl
end loop;
-- Step 2)
for Bits in 1 .. Max_Huffman_Bits loop
Code := (Code + Bl_Count (Bits - 1)) * 2;
Next_Code (Bits) := Code; -- This will be the first code for bit length "bits"
end loop;
-- Step 3)
for N in Hd'Range loop
Bl := Hd (N).Bit_Length;
if Bl > 0 then
Hd (N).Code := Next_Code (Bl);
Next_Code (Bl) := Next_Code (Bl) + 1;
else
Hd (N).Code := 0;
end if;
end loop;
-- Invert bit order for output:
for I in Hd'Range loop
Invert (Hd (I));
end loop;
end Prepare_Huffman_Codes;
-- This is the phase (C) for the pair of alphabets used in the Deflate format
function Prepare_Huffman_Codes
(Dhd : Deflate_Huff_Descriptors) return Deflate_Huff_Descriptors
is
Dhd_Var : Deflate_Huff_Descriptors := Dhd;
begin
Prepare_Huffman_Codes (Dhd_Var.Lit_Len);
Prepare_Huffman_Codes (Dhd_Var.Dis);
return Dhd_Var;
end Prepare_Huffman_Codes;
-- Emit a variable length Huffman code
procedure Put_Huffman_Code (Lc : Length_Code_Pair) is
pragma Inline (Put_Huffman_Code);
begin
-- Huffman code of length 0 should never occur: when constructing
-- the code lengths (LLHCL) any single occurrence in the statistics
-- will trigger the build of a code length of 1 or more.
Put_Code
(Code => U32 (Lc.Code),
Code_Size => Code_Size_Type (Lc.Bit_Length) -- Range check for length 0 (if enabled).
);
end Put_Huffman_Code;
-- This is where the "dynamic" Huffman trees are sent before the block's data are sent.
--
-- The decoder needs to know in advance the pair of trees (first tree for literals-eob-LZ
-- lengths, second tree for LZ distances) for decoding the compressed data.
-- But this information takes some room. Fortunately Deflate allows for compressing it
-- with a combination of Huffman and Run-Length Encoding (RLE) to make this header smaller.
-- Concretely, the trees are described by the bit length of each symbol, so the header's
-- content is a vector of length max 320, whose contents are in the 0 .. 18 range and typically
-- look like: ... 8, 8, 9, 7, 8, 10, 6, 8, 8, 8, 8, 8, 11, 8, 9, 8, ...
-- Clearly this vector has redundancies and can be sent in a compressed form. In this example,
-- the RLE will compress the string of 8's with a single code 8, then a code 17
-- (repeat x times). Anyway, the very frequent 8's will be encoded with a small number of
-- bits (less than the 5 plain bits, or maximum 7 Huffman-encoded bits
-- needed for encoding integers in the 0 .. 18 range).
procedure Put_Compression_Structure
(Dhd : Deflate_Huff_Descriptors;
Cost_Analysis : Boolean; -- If True: just simulate the whole, and count needed bits
Bits : in out Count_Type) -- This is incremented when cost_analysis = True
is
subtype Alphabet is Integer range 0 .. 18;
type Alpha_Array is new Bit_Length_Array (Alphabet);
Truc_Freq, Truc_Bl : Alpha_Array;
Truc : Huff_Descriptor (Alphabet);
-- Compression structure: cs_bl is the "big" array with all bit lengths
-- for compressing data. cs_bl will be sent compressed, too.
Cs_Bl : array (1 .. Dhd.Lit_Len'Length + Dhd.Dis'Length) of Natural;
Last_Cs_Bl : Natural;
Max_Used_Lln_Code : Alphabet_Lit_Len := 0;
Max_Used_Dis_Code : Alphabet_Dis := 0;
procedure Concatenate_All_Bit_Lengths is
Idx : Natural := 0;
begin
for A in reverse Alphabet_Lit_Len loop
if Dhd.Lit_Len (A).Bit_Length > 0 then
Max_Used_Lln_Code := A;
exit;
end if;
end loop;
for A in reverse Alphabet_Dis loop
if Dhd.Dis (A).Bit_Length > 0 then
Max_Used_Dis_Code := A;
exit;
end if;
end loop;
-- Copy bit lengths for both trees into one array, cs_bl.
for A in 0 .. Max_Used_Lln_Code loop
Idx := Idx + 1;
Cs_Bl (Idx) := Dhd.Lit_Len (A).Bit_Length;
end loop;
for A in 0 .. Max_Used_Dis_Code loop
Idx := Idx + 1;
Cs_Bl (Idx) := Dhd.Dis (A).Bit_Length;
end loop;
Last_Cs_Bl := Idx;
end Concatenate_All_Bit_Lengths;
Extra_Bits_Needed : constant array (Alphabet) of Natural :=
(16 => 2, 17 => 3, 18 => 7, others => 0);
type Emission_Mode is (Simulate, Effective);
procedure Emit_Data_Compression_Structures (Mode : Emission_Mode) is
procedure Emit_Data_Compression_Atom (X : Alphabet; Extra_Code : U32 := 0) is
-- x is a bit length (value in 0..15), or a RLE instruction
begin
case Mode is
when Simulate =>
Truc_Freq (X) := Truc_Freq (X) + 1; -- +1 for x's histogram bar
when Effective =>
Put_Huffman_Code (Truc (X));
declare
Extra_Bits : constant Natural := Extra_Bits_Needed (X);
begin
if Extra_Bits > 0 then
Put_Code (Extra_Code, Extra_Bits);
end if;
end;
end case;
end Emit_Data_Compression_Atom;
Idx : Natural := 0;
Rep : Positive; -- Number of times current atom is repeated, >= 1
begin
-- Emit the bit lengths, with some RLE encoding (Appnote: 5.5.3; RFC 1951: 3.2.7)
Idx := 1;
loop
Rep := 1; -- Current atom, cs_bl(idx), is repeated 1x so far - obvious, isn't it?
for J in Idx + 1 .. Last_Cs_Bl loop
exit when Cs_Bl (J) /= Cs_Bl (Idx);
Rep := Rep + 1;
end loop;
-- Now rep is the number of repetitions of current atom, including itself
if Idx > 1
and then Cs_Bl (Idx) = Cs_Bl (Idx - 1)
and then Rep >= 3
-- Better repeat a long sequence of zeros by using codes 17 or 18
-- just after a 138-long previous sequence:
and then not (Cs_Bl (Idx) = 0 and then Rep > 6)
then
Rep := Integer'Min (Rep, 6);
Emit_Data_Compression_Atom
(16,
U32 (Rep - 3)); -- 16: "Repeat previous 3 to 6 times"
Idx := Idx + Rep;
elsif Cs_Bl (Idx) = 0 and then Rep >= 3 then
-- The 0 bit length may occur on long ranges of an alphabet (unused symbols)
if Rep <= 10 then
Emit_Data_Compression_Atom
(17,
U32 (Rep - 3)); -- 17: "Repeat zero 3 to 10 times"
else
Rep := Integer'Min (Rep, 138);
Emit_Data_Compression_Atom
(18,
U32 (Rep - 11)); -- 18: "Repeat zero 11 to 138 times"
end if;
Idx := Idx + Rep;
else
Emit_Data_Compression_Atom (Cs_Bl (Idx));
Idx := Idx + 1;
end if;
exit when Idx > Last_Cs_Bl;
end loop;
end Emit_Data_Compression_Structures;
-- Alphabet permutation for shortening in-use alphabet.
-- After the RLE codes 16, 17, 18 and the bit length 0, which are assumed to be always used,
-- the most usual bit lengths (around 8, which is the "neutral" bit length) appear first.
-- For example, if the rare bit lengths 1 and 15 don't occur in any of the two Huffman trees
-- for LZ data, then codes 1 and 15 have a length 0 in the local Alphabet and we can omit
-- sending the last two bit lengths.
Alphabet_Permutation : constant array (Alphabet) of Natural :=
(16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15);
procedure Llhcl is new Length_Limited_Huffman_Code_Lengths
(Alphabet,
Natural,
Alpha_Array,
Alpha_Array,
7);
A_Non_Zero : Alphabet;
begin
Concatenate_All_Bit_Lengths;
Truc_Freq := (others => 0);
Emit_Data_Compression_Structures (Simulate);
-- We have now statistics of all bit lengths occurrences of both Huffman
-- trees used for compressing the data.
-- We turn these counts into bit lengths for the local tree
-- that helps us to store the compression structure in a more compact form.
Llhcl (Truc_Freq, Truc_Bl); -- Call the magic algorithm for setting up Huffman lengths
-- At least lengths for codes 16, 17, 18, 0 will always be sent,
-- even if all other bit lengths are 0 because codes 1 to 15 are unused.
A_Non_Zero := 3;
for A in Alphabet loop
if A > A_Non_Zero and then Truc_Bl (Alphabet_Permutation (A)) > 0 then
A_Non_Zero := A;
end if;
end loop;
if Cost_Analysis then
-- In this mode, no data output: we sum up the exact
-- number of bits needed by the compression header.
Bits := Bits + 14 + Count_Type (1 + A_Non_Zero) * 3;
for A in Alphabet loop
Bits := Bits + Count_Type (Truc_Freq (A) * (Truc_Bl (A) + Extra_Bits_Needed (A)));
end loop;
else
-- We output the compression header to the output stream.
for A in Alphabet loop
Truc (A).Bit_Length := Truc_Bl (A);
end loop;
Prepare_Huffman_Codes (Truc);
-- Output of the compression structure
Put_Code
(U32 (Max_Used_Lln_Code - 256),
5); -- max_used_lln_code is always >= 256 = EOB code
Put_Code (U32 (Max_Used_Dis_Code), 5);
Put_Code (U32 (A_Non_Zero - 3), 4);
-- Save the local alphabet's Huffman lengths. It's the compression structure
-- for compressing the data compression structure. Easy, isn't it ?
for A in 0 .. A_Non_Zero loop
Put_Code (U32 (Truc (Alphabet_Permutation (A)).Bit_Length), 3);
end loop;
-- Emit the Huffman lengths for encoding the data, in the local Huffman-encoded fashion.
Emit_Data_Compression_Structures (Effective);
end if;
end Put_Compression_Structure;
End_Of_Block : constant := 256;
-- Default Huffman trees, for "fixed" blocks, as defined in appnote.txt or RFC 1951
Default_Lit_Len_Bl : constant Bit_Length_Array_Lit_Len :=
(0 .. 143 => 8, -- For literals ("plain text" bytes)
144 .. 255 => 9, -- For more literals ("plain text" bytes)
End_Of_Block => 7, -- For EOB (256)
257 .. 279 => 7, -- For length codes
280 .. 287 => 8); -- For more length codes
Default_Dis_Bl : constant Bit_Length_Array_Dis := (others => 5);
Deflate_Fixed_Descriptors : constant Deflate_Huff_Descriptors :=
Prepare_Huffman_Codes (Build_Descriptors (Default_Lit_Len_Bl, Default_Dis_Bl));
-- Current tree descriptors
Curr_Descr : Deflate_Huff_Descriptors := Deflate_Fixed_Descriptors;
-- Write a normal, "clear-text" (post LZ, pre Huffman), 8-bit character (literal)
procedure Put_Literal_Byte (B : Byte) is
begin
Put_Huffman_Code (Curr_Descr.Lit_Len (Integer (B)));
end Put_Literal_Byte;
-- Possible ranges for distance and length encoding in the Zip-Deflate format:
subtype Length_Range is Integer range 3 .. 258;
subtype Distance_Range is Integer range 1 .. 32768;
-- This is where LZ distance-length tokens are written to the output stream.
-- The Deflate format defines a sort of logarithmic compression, with codes
-- for various distance and length ranges, plus extra bits for specifying the
-- exact values. The codes are sent as Huffman codes with variable bit lengths
-- (nothing to do with the lengths of LZ distance-length tokens).
-- Length Codes
-- ------------
-- Extra Extra Extra Extra
-- Code Bits Length Code Bits Lengths Code Bits Lengths Code Bits Length(s)
-- ---- ---- ------ ---- ---- ------- ---- ---- ------- ---- ---- ---------
-- 257 0 3 265 1 11,12 273 3 35-42 281 5 131-162
-- 258 0 4 266 1 13,14 274 3 43-50 282 5 163-194
-- 259 0 5 267 1 15,16 275 3 51-58 283 5 195-226
-- 260 0 6 268 1 17,18 276 3 59-66 284 5 227-257
-- 261 0 7 269 2 19-22 277 4 67-82 285 0 258
-- 262 0 8 270 2 23-26 278 4 83-98
-- 263 0 9 271 2 27-30 279 4 99-114
-- 264 0 10 272 2 31-34 280 4 115-130
--
-- Example: the code # 266 means the LZ length (# of message bytes to be copied)
-- shall be 13 or 14, depending on the extra bit value.
Deflate_Code_For_Lz_Length : constant array (Length_Range) of Natural :=
(3 => 257, -- Codes 257..264, with no extra bit
4 => 258,
5 => 259,
6 => 260,
7 => 261,
8 => 262,
9 => 263,
10 => 264,
11 .. 12 => 265, -- Codes 265..268, with 1 extra bit
13 .. 14 => 266,
15 .. 16 => 267,
17 .. 18 => 268,
19 .. 22 => 269, -- Codes 269..272, with 2 extra bits
23 .. 26 => 270,
27 .. 30 => 271,
31 .. 34 => 272,
35 .. 42 => 273, -- Codes 273..276, with 3 extra bits
43 .. 50 => 274,
51 .. 58 => 275,
59 .. 66 => 276,
67 .. 82 => 277, -- Codes 277..280, with 4 extra bits
83 .. 98 => 278,
99 .. 114 => 279,
115 .. 130 => 280,
131 .. 162 => 281, -- Codes 281..284, with 5 extra bits
163 .. 194 => 282,
195 .. 226 => 283,
227 .. 257 => 284,
258 => 285); -- Code 285, with no extra bit
Extra_Bits_For_Lz_Length_Offset : constant array (Length_Range) of Integer :=
(3 .. 10 | 258 => Invalid, -- just placeholder, there is no extra bit there!
11 .. 18 => 11,
19 .. 34 => 19,
35 .. 66 => 35,
67 .. 130 => 67,
131 .. 257 => 131);
Extra_Bits_For_Lz_Length : constant array (Length_Range) of Natural :=
(3 .. 10 | 258 => 0,
11 .. 18 => 1,
19 .. 34 => 2,
35 .. 66 => 3,
67 .. 130 => 4,
131 .. 257 => 5);
procedure Put_Dl_Code (Distance : Distance_Range; Length : Length_Range) is
Extra_Bits : Natural;
begin
Put_Huffman_Code (Curr_Descr.Lit_Len (Deflate_Code_For_Lz_Length (Length)));
-- Extra bits are needed to differentiate lengths sharing the same code.
Extra_Bits := Extra_Bits_For_Lz_Length (Length);
if Extra_Bits > 0 then
-- We keep only the last extra_bits bits of the length (minus given offset).
-- Example: if extra_bits = 1, only the parity is sent (0 or 1);
-- the rest has been already sent with Put_Huffman_code above.
-- Equivalent: x:= x mod (2 ** extra_bits);
Put_Code
(U32 (Length - Extra_Bits_For_Lz_Length_Offset (Length)) and
(Shift_Left (U32'(1), Extra_Bits) - 1),
Extra_Bits);
end if;
-- Distance Codes
-- --------------
-- Extra Extra Extra Extra
-- Code Bits Dist Code Bits Dist Code Bits Distance Code Bits Distance
-- ---- ---- ---- ---- ---- ------ ---- ---- -------- ---- ---- --------
-- 0 0 1 8 3 17-24 16 7 257-384 24 11 4097-6144
-- 1 0 2 9 3 25-32 17 7 385-512 25 11 6145-8192
-- 2 0 3 10 4 33-48 18 8 513-768 26 12 8193-12288
-- 3 0 4 11 4 49-64 19 8 769-1024 27 12 12289-16384
-- 4 1 5,6 12 5 65-96 20 9 1025-1536 28 13 16385-24576
-- 5 1 7,8 13 5 97-128 21 9 1537-2048 29 13 24577-32768
-- 6 2 9-12 14 6 129-192 22 10 2049-3072
-- 7 2 13-16 15 6 193-256 23 10 3073-4096
--
--
-- Example: the code # 10 means the LZ distance (# positions back in the circular
-- message buffer for starting the copy) shall be 33, plus the value given
-- by the 4 extra bits (between 0 and 15).
case Distance is
when 1 .. 4 => -- Codes 0..3, with no extra bit
Put_Huffman_Code (Curr_Descr.Dis (Distance - 1));
when 5 .. 8 => -- Codes 4..5, with 1 extra bit
Put_Huffman_Code (Curr_Descr.Dis (4 + (Distance - 5) / 2));
Put_Code (U32 ((Distance - 5) mod 2), 1);
when 9 .. 16 => -- Codes 6..7, with 2 extra bits
Put_Huffman_Code (Curr_Descr.Dis (6 + (Distance - 9) / 4));
Put_Code (U32 ((Distance - 9) mod 4), 2);
when 17 .. 32 => -- Codes 8..9, with 3 extra bits
Put_Huffman_Code (Curr_Descr.Dis (8 + (Distance - 17) / 8));
Put_Code (U32 ((Distance - 17) mod 8), 3);
when 33 .. 64 => -- Codes 10..11, with 4 extra bits
Put_Huffman_Code (Curr_Descr.Dis (10 + (Distance - 33) / 16));
Put_Code (U32 ((Distance - 33) mod 16), 4);
when 65 .. 128 => -- Codes 12..13, with 5 extra bits
Put_Huffman_Code (Curr_Descr.Dis (12 + (Distance - 65) / 32));
Put_Code (U32 ((Distance - 65) mod 32), 5);
when 129 .. 256 => -- Codes 14..15, with 6 extra bits
Put_Huffman_Code (Curr_Descr.Dis (14 + (Distance - 129) / 64));
Put_Code (U32 ((Distance - 129) mod 64), 6);
when 257 .. 512 => -- Codes 16..17, with 7 extra bits
Put_Huffman_Code (Curr_Descr.Dis (16 + (Distance - 257) / 128));
Put_Code (U32 ((Distance - 257) mod 128), 7);
when 513 .. 1024 => -- Codes 18..19, with 8 extra bits
Put_Huffman_Code (Curr_Descr.Dis (18 + (Distance - 513) / 256));
Put_Code (U32 ((Distance - 513) mod 256), 8);
when 1025 .. 2048 => -- Codes 20..21, with 9 extra bits
Put_Huffman_Code (Curr_Descr.Dis (20 + (Distance - 1025) / 512));
Put_Code (U32 ((Distance - 1025) mod 512), 9);
when 2049 .. 4096 => -- Codes 22..23, with 10 extra bits
Put_Huffman_Code (Curr_Descr.Dis (22 + (Distance - 2049) / 1024));
Put_Code (U32 ((Distance - 2049) mod 1024), 10);
when 4097 .. 8192 => -- Codes 24..25, with 11 extra bits
Put_Huffman_Code (Curr_Descr.Dis (24 + (Distance - 4097) / 2048));
Put_Code (U32 ((Distance - 4097) mod 2048), 11);
when 8193 .. 16384 => -- Codes 26..27, with 12 extra bits
Put_Huffman_Code (Curr_Descr.Dis (26 + (Distance - 8193) / 4096));
Put_Code (U32 ((Distance - 8193) mod 4096), 12);
when 16385 .. 32768 => -- Codes 28..29, with 13 extra bits
Put_Huffman_Code (Curr_Descr.Dis (28 + (Distance - 16385) / 8192));
Put_Code (U32 ((Distance - 16385) mod 8192), 13);
end case;
end Put_Dl_Code;
function Deflate_Code_For_Lz_Distance (Distance : Distance_Range) return Natural is
begin
case Distance is
when 1 .. 4 => -- Codes 0..3, with no extra bit
return Distance - 1;
when 5 .. 8 => -- Codes 4..5, with 1 extra bit
return 4 + (Distance - 5) / 2;
when 9 .. 16 => -- Codes 6..7, with 2 extra bits
return 6 + (Distance - 9) / 4;
when 17 .. 32 => -- Codes 8..9, with 3 extra bits
return 8 + (Distance - 17) / 8;
when 33 .. 64 => -- Codes 10..11, with 4 extra bits
return 10 + (Distance - 33) / 16;
when 65 .. 128 => -- Codes 12..13, with 5 extra bits
return 12 + (Distance - 65) / 32;
when 129 .. 256 => -- Codes 14..15, with 6 extra bits
return 14 + (Distance - 129) / 64;
when 257 .. 512 => -- Codes 16..17, with 7 extra bits
return 16 + (Distance - 257) / 128;
when 513 .. 1024 => -- Codes 18..19, with 8 extra bits
return 18 + (Distance - 513) / 256;
when 1025 .. 2048 => -- Codes 20..21, with 9 extra bits
return 20 + (Distance - 1025) / 512;
when 2049 .. 4096 => -- Codes 22..23, with 10 extra bits
return 22 + (Distance - 2049) / 1024;
when 4097 .. 8192 => -- Codes 24..25, with 11 extra bits
return 24 + (Distance - 4097) / 2048;
when 8193 .. 16384 => -- Codes 26..27, with 12 extra bits
return 26 + (Distance - 8193) / 4096;
when 16385 .. 32768 => -- Codes 28..29, with 13 extra bits
return 28 + (Distance - 16385) / 8192;
end case;
end Deflate_Code_For_Lz_Distance;
-----------------
-- LZ Buffer --
-----------------
-- We buffer the LZ codes (plain, or distance/length) in order to
-- analyse them and try to do smart things.
Max_Expand : constant := 14;
-- *Tuned* Sometimes it is better to store data and expand short strings
Code_For_Max_Expand : constant := 266;
subtype Expanded_Data is Byte_Buffer (1 .. Max_Expand);
type Lz_Atom_Kind is (Plain_Byte, Distance_Length);
type Lz_Atom is record
Kind : Lz_Atom_Kind;
Plain : Byte;
Lz_Distance : Natural;
Lz_Length : Natural;
Lz_Expanded : Expanded_Data;
end record;
-- *Tuned*. Min: 2**14, = 16384 (min half buffer 8192)
-- Optimal so far: 2**17
Lz_Buffer_Size : constant := 2**17;
type Lz_Buffer_Index_Type is mod Lz_Buffer_Size;
type Lz_Buffer_Type is array (Lz_Buffer_Index_Type range <>) of Lz_Atom;
Empty_Lit_Len_Stat : constant Stats_Lit_Len_Type := (End_Of_Block => 1, others => 0);
-- End_Of_Block will have to happen once, but never appears in the LZ statistics...
Empty_Dis_Stat : constant Stats_Dis_Type := (others => 0);
-- Compute statistics for both Literal-length, and Distance alphabets,
-- from a LZ buffer
procedure Get_Statistics
(Lzb : in Lz_Buffer_Type;
Stats_Lit_Len : out Stats_Lit_Len_Type;
Stats_Dis : out Stats_Dis_Type)
is
Lit_Len : Alphabet_Lit_Len;
Dis : Alphabet_Dis;
begin
Stats_Lit_Len := Empty_Lit_Len_Stat;
Stats_Dis := Empty_Dis_Stat;
for I in Lzb'Range loop
case Lzb (I).Kind is
when Plain_Byte =>
Lit_Len := Alphabet_Lit_Len (Lzb (I).Plain);
Stats_Lit_Len (Lit_Len) :=
Stats_Lit_Len (Lit_Len) + 1; -- +1 for this literal
when Distance_Length =>
Lit_Len := Deflate_Code_For_Lz_Length (Lzb (I).Lz_Length);
Stats_Lit_Len (Lit_Len) :=
Stats_Lit_Len (Lit_Len) + 1; -- +1 for this length code
Dis := Deflate_Code_For_Lz_Distance (Lzb (I).Lz_Distance);
Stats_Dis (Dis) :=
Stats_Dis (Dis) + 1; -- +1 for this distance code
end case;
end loop;
end Get_Statistics;
-- Send a LZ buffer using currently defined Huffman codes
procedure Put_Lz_Buffer (Lzb : Lz_Buffer_Type) is
begin
for I in Lzb'Range loop
case Lzb (I).Kind is
when Plain_Byte =>
Put_Literal_Byte (Lzb (I).Plain);
when Distance_Length =>
Put_Dl_Code (Lzb (I).Lz_Distance, Lzb (I).Lz_Length);
end case;
end loop;
end Put_Lz_Buffer;
Block_To_Finish : Boolean := False;
Last_Block_Marked : Boolean := False;
type Block_Type is (Stored, Fixed, Dynamic, Reserved); -- Appnote, 5.5.2
-- If last_block_type = dynamic, we may recycle previous block's Huffman codes
Last_Block_Type : Block_Type := Reserved;
procedure Mark_New_Block (Last_Block_For_Stream : Boolean) is
begin
if Block_To_Finish and Last_Block_Type in Fixed .. Dynamic then
Put_Huffman_Code (Curr_Descr.Lit_Len (End_Of_Block)); -- Finish previous block
end if;
Block_To_Finish := True;
Put_Code (Code => Boolean'Pos (Last_Block_For_Stream), Code_Size => 1);
Last_Block_Marked := Last_Block_For_Stream;
end Mark_New_Block;
-- Send a LZ buffer completely decoded as literals (LZ compression is discarded)
procedure Expand_Lz_Buffer (Lzb : Lz_Buffer_Type; Last_Block : Boolean) is
B1, B2 : Byte;
To_Be_Sent : Natural_M32 := 0;
-- To_Be_Sent is not always equal to lzb'Length: sometimes you have a DL code
Mid : Lz_Buffer_Index_Type;
begin
for I in Lzb'Range loop
case Lzb (I).Kind is
when Plain_Byte =>
To_Be_Sent := To_Be_Sent + 1;
when Distance_Length =>
To_Be_Sent := To_Be_Sent + Natural_M32 (Lzb (I).Lz_Length);
end case;
end loop;
if To_Be_Sent > 16#FFFF# then -- Ow, cannot send all that in one chunk.
-- Instead of a tedious block splitting, just divide and conquer:
Mid := Lz_Buffer_Index_Type ((Natural_M32 (Lzb'First) + Natural_M32 (Lzb'Last)) / 2);
Expand_Lz_Buffer (Lzb (Lzb'First .. Mid), Last_Block => False);
Expand_Lz_Buffer (Lzb (Mid + 1 .. Lzb'Last), Last_Block => Last_Block);
return;
end if;
B1 := Byte (To_Be_Sent mod 256);
B2 := Byte (To_Be_Sent / 256);
Mark_New_Block (Last_Block_For_Stream => Last_Block);
Last_Block_Type := Stored;
Put_Code (Code => 0, Code_Size => 2); -- Signals a "stored" block
Flush_Bit_Buffer; -- Go to byte boundary
Put_Byte (B1);
Put_Byte (B2);
Put_Byte (not B1);
Put_Byte (not B2);
for I in Lzb'Range loop
case Lzb (I).Kind is
when Plain_Byte =>
Put_Byte (Lzb (I).Plain);
when Distance_Length =>
for J in 1 .. Lzb (I).Lz_Length loop
Put_Byte (Lzb (I).Lz_Expanded (J));
end loop;
end case;
end loop;
end Expand_Lz_Buffer;
-- Extra bits that need to be sent after various Deflate codes
Extra_Bits_For_Lz_Length_Code : constant array (257 .. 285) of Natural :=
(257 .. 264 => 0,
265 .. 268 => 1,
269 .. 272 => 2,
273 .. 276 => 3,
277 .. 280 => 4,
281 .. 284 => 5,
285 => 0);
Extra_Bits_For_Lz_Distance_Code : constant array (0 .. 29) of Natural :=
(0 .. 3 => 0,
4 .. 5 => 1,
6 .. 7 => 2,
8 .. 9 => 3,
10 .. 11 => 4,
12 .. 13 => 5,
14 .. 15 => 6,
16 .. 17 => 7,
18 .. 19 => 8,
20 .. 21 => 9,
22 .. 23 => 10,
24 .. 25 => 11,
26 .. 27 => 12,
28 .. 29 => 13);
subtype Long_Length_Codes is
Alphabet_Lit_Len range Code_For_Max_Expand + 1 .. Alphabet_Lit_Len'Last;
Zero_Bl_Long_Lengths : constant Stats_Type (Long_Length_Codes) := (others => 0);
-- Send_as_block.
--
-- lzb (can be a slice of the principal buffer) will be sent as:
-- * a new "dynamic" block, preceded by a compression structure header
-- or * the continuation of previous "dynamic" block
-- or * a new "fixed" block, if lz data's Huffman descriptor is close enough to "fixed"
-- or * a new "stored" block, if lz data are too random
procedure Send_As_Block (Lzb : Lz_Buffer_Type; Last_Block : Boolean) is
New_Descr, New_Descr_2 : Deflate_Huff_Descriptors;
procedure Send_Fixed_Block is
begin
if Last_Block_Type = Fixed then
-- Cool, we don't need to mark a block boundary: the Huffman codes are already
-- the expected ones. We can just continue sending the LZ atoms.
null;
else
Mark_New_Block (Last_Block_For_Stream => Last_Block);
Curr_Descr := Deflate_Fixed_Descriptors;
Put_Code (Code => 1, Code_Size => 2); -- Signals a "fixed" block
Last_Block_Type := Fixed;
end if;
Put_Lz_Buffer (Lzb);
end Send_Fixed_Block;
Stats_Lit_Len, Stats_Lit_Len_2 : Stats_Lit_Len_Type;
Stats_Dis, Stats_Dis_2 : Stats_Dis_Type;
procedure Send_Dynamic_Block (Dyn : Deflate_Huff_Descriptors) is
Dummy : Count_Type := 0;
begin
Mark_New_Block (Last_Block_For_Stream => Last_Block);
Curr_Descr := Prepare_Huffman_Codes (Dyn);
Put_Code (Code => 2, Code_Size => 2); -- Signals a "dynamic" block
Put_Compression_Structure (Curr_Descr, Cost_Analysis => False, Bits => Dummy);
Put_Lz_Buffer (Lzb);
Last_Block_Type := Dynamic;
end Send_Dynamic_Block;
-- The following variables will contain the *exact* number of bits taken
-- by the block to be sent, using different Huffman encodings, or stored.
Stored_Format_Bits, -- Block is stored (no compression)
Fixed_Format_Bits, -- Fixed (preset) Huffman codes
Dynamic_Format_Bits, -- Dynamic Huffman codes using block's statistics
Dynamic_Format_Bits_2, -- Dynamic Huffman codes after Tweak_for_better_RLE
Recycled_Format_Bits : Count_Type :=
0; -- Continue previous block, use current Huffman codes
Stored_Format_Possible : Boolean; -- Can we store (needs expansion of DL codes) ?
Recycling_Possible : Boolean; -- Can we recycle current Huffman codes ?
procedure Compute_Sizes_Of_Variants is
C : Count_Type;
Extra : Natural;
begin
-- We count bits taken by literals, for each block format variant
for I in 0 .. 255 loop
C := Stats_Lit_Len (I); -- This literal appears c times in the LZ buffer
Stored_Format_Bits := Stored_Format_Bits + 8 * C;
Fixed_Format_Bits := Fixed_Format_Bits + Count_Type (Default_Lit_Len_Bl (I)) * C;
Dynamic_Format_Bits :=
Dynamic_Format_Bits + Count_Type (New_Descr.Lit_Len (I).Bit_Length) * C;
Dynamic_Format_Bits_2 :=
Dynamic_Format_Bits_2 + Count_Type (New_Descr_2.Lit_Len (I).Bit_Length) * C;
Recycled_Format_Bits :=
Recycled_Format_Bits + Count_Type (Curr_Descr.Lit_Len (I).Bit_Length) * C;
end loop;
-- We count bits taken by DL codes
if Stored_Format_Possible then
for I in Lzb'Range loop
case Lzb (I).Kind is
when Plain_Byte =>
null; -- Already counted
when Distance_Length =>
-- In the stored format, DL codes are expanded
Stored_Format_Bits := Stored_Format_Bits + 8 * Count_Type (Lzb (I).Lz_Length);
end case;
end loop;
end if;
-- For compressed formats, count Huffman bits and extra bits
for I in 257 .. 285 loop
C := Stats_Lit_Len (I); -- This length code appears c times in the LZ buffer
Extra := Extra_Bits_For_Lz_Length_Code (I);
Fixed_Format_Bits :=
Fixed_Format_Bits + Count_Type (Default_Lit_Len_Bl (I) + Extra) * C;
Dynamic_Format_Bits :=
Dynamic_Format_Bits + Count_Type (New_Descr.Lit_Len (I).Bit_Length + Extra) * C;
Dynamic_Format_Bits_2 :=
Dynamic_Format_Bits_2 + Count_Type (New_Descr_2.Lit_Len (I).Bit_Length + Extra) * C;
Recycled_Format_Bits :=
Recycled_Format_Bits + Count_Type (Curr_Descr.Lit_Len (I).Bit_Length + Extra) * C;
end loop;
for I in 0 .. 29 loop
C := Stats_Dis (I); -- This distance code appears c times in the LZ buffer
Extra := Extra_Bits_For_Lz_Distance_Code (I);
Fixed_Format_Bits := Fixed_Format_Bits + Count_Type (Default_Dis_Bl (I) + Extra) * C;
Dynamic_Format_Bits :=
Dynamic_Format_Bits + Count_Type (New_Descr.Dis (I).Bit_Length + Extra) * C;
Dynamic_Format_Bits_2 :=
Dynamic_Format_Bits_2 + Count_Type (New_Descr_2.Dis (I).Bit_Length + Extra) * C;
Recycled_Format_Bits :=
Recycled_Format_Bits + Count_Type (Curr_Descr.Dis (I).Bit_Length + Extra) * C;
end loop;
-- Supplemental bits to be counted
Stored_Format_Bits :=
Stored_Format_Bits +
(1 + (Stored_Format_Bits / 8) / 65_535) -- Number of stored blocks needed
* 5 -- 5 bytes per header
* 8; -- ... converted into bits
C := 1; -- Is-last-block flag
if Block_To_Finish and Last_Block_Type in Fixed .. Dynamic then
C := C + Count_Type (Curr_Descr.Lit_Len (End_Of_Block).Bit_Length);
end if;
Stored_Format_Bits := Stored_Format_Bits + C;
Fixed_Format_Bits := Fixed_Format_Bits + C + 2;
Dynamic_Format_Bits := Dynamic_Format_Bits + C + 2;
Dynamic_Format_Bits_2 := Dynamic_Format_Bits_2 + C + 2;
-- For both dynamic formats, we also counts the bits taken by
-- the compression header!
Put_Compression_Structure (New_Descr, Cost_Analysis => True, Bits => Dynamic_Format_Bits);
Put_Compression_Structure
(New_Descr_2,
Cost_Analysis => True,
Bits => Dynamic_Format_Bits_2);
end Compute_Sizes_Of_Variants;
Optimal_Format_Bits : Count_Type;
begin
Get_Statistics (Lzb, Stats_Lit_Len, Stats_Dis);
New_Descr := Build_Descriptors (Stats_Lit_Len, Stats_Dis);
Stats_Lit_Len_2 := Stats_Lit_Len;
Stats_Dis_2 := Stats_Dis;
Tweak_For_Better_Rle (Stats_Lit_Len_2);
Tweak_For_Better_Rle (Stats_Dis_2);
New_Descr_2 := Build_Descriptors (Stats_Lit_Len_2, Stats_Dis_2);
-- For "stored" block format, prevent expansion of DL codes with length > max_expand
-- We check stats are all 0 for long length codes:
Stored_Format_Possible := Stats_Lit_Len (Long_Length_Codes) = Zero_Bl_Long_Lengths;
Recycling_Possible :=
Last_Block_Type = Fixed -- The "fixed" alphabets use all symbols, then always recyclable
or else (Last_Block_Type = Dynamic and then Recyclable (Curr_Descr, New_Descr));
Compute_Sizes_Of_Variants;
if not Stored_Format_Possible then
Stored_Format_Bits := Count_Type'Last;
end if;
if not Recycling_Possible then
Recycled_Format_Bits := Count_Type'Last;
end if;
Optimal_Format_Bits :=
Count_Type'Min
(Count_Type'Min (Stored_Format_Bits, Fixed_Format_Bits),
Count_Type'Min
(Count_Type'Min (Dynamic_Format_Bits, Dynamic_Format_Bits_2),
Recycled_Format_Bits));
-- Selection of the block format with smallest size
if Fixed_Format_Bits = Optimal_Format_Bits then
Send_Fixed_Block;
elsif Dynamic_Format_Bits = Optimal_Format_Bits then
Send_Dynamic_Block (New_Descr);
elsif Dynamic_Format_Bits_2 = Optimal_Format_Bits then
Send_Dynamic_Block (New_Descr_2);
elsif Recycled_Format_Bits = Optimal_Format_Bits then
Put_Lz_Buffer (Lzb);
else -- We have stored_format_bits = optimal_format_bits
Expand_Lz_Buffer (Lzb, Last_Block);
end if;
end Send_As_Block;
subtype Full_Range_Lz_Buffer_Type is Lz_Buffer_Type (Lz_Buffer_Index_Type);
type P_Full_Range_Lz_Buffer_Type is access Full_Range_Lz_Buffer_Type;
procedure Dispose is new Ada.Unchecked_Deallocation
(Full_Range_Lz_Buffer_Type,
P_Full_Range_Lz_Buffer_Type);
-- This is the main, big, fat, circular buffer containing LZ codes,
-- each LZ code being a literal or a DL code.
-- Heap allocation is needed because default stack is too small on some targets.
Lz_Buffer : P_Full_Range_Lz_Buffer_Type;
Lz_Buffer_Index : Lz_Buffer_Index_Type := 0;
Past_Lz_Data : Boolean := False;
-- When True: some LZ_buffer_size data before lz_buffer_index (modulo!) are real, past data
---------------------------------------------------------------------------------
-- Scanning and sampling: the really sexy part of the Taillaule algorithm... --
---------------------------------------------------------------------------------
-- We examine similarities in the LZ data flow at different step sizes.
-- If the optimal Huffman encoding for this portion is very different, we choose to
-- cut current block and start a new one. The shorter the step, the higher the threshold
-- for starting a dynamic block, since the compression header is taking some room each time.
-- *Tuned* (a bit...)
Min_Step : constant := 750;
type Step_Threshold_Metric is record
Slider_Step : Lz_Buffer_Index_Type; -- Should be a multiple of Min_Step
Cutting_Threshold : Positive;
Metric : Distance_Type;
end record;
-- *Tuned* thresholds
-- NB: the enwik8, then silesia, then others tests are tough for lowering any!
Step_Choice : constant array (Positive range <>) of Step_Threshold_Metric :=
((8 * Min_Step, 420, L1_Tweaked), -- Deflate_1, Deflate_2, Deflate_3 (enwik8)
(4 * Min_Step, 430, L1_Tweaked), -- Deflate_2, Deflate_3 (silesia)
(Min_Step, 2050, L1_Tweaked)); -- Deflate_3 (DB test)
Max_Choice : constant array (Taillaule_Deflation_Method) of Positive :=
(Deflate_1 => 1,
Deflate_2 => 2,
Deflate_3 => Step_Choice'Last);
Slider_Size : constant := 4096;
Half_Slider_Size : constant := Slider_Size / 2;
Slider_Max : constant := Slider_Size - 1;
-- Phases (A) and (B) are done in a single function: we get Huffman
-- descriptors that should be good for encoding a given sequence of LZ atoms.
function Build_Descriptors (Lzb : Lz_Buffer_Type) return Deflate_Huff_Descriptors is
Stats_Lit_Len : Stats_Lit_Len_Type;
Stats_Dis : Stats_Dis_Type;
begin
Get_Statistics (Lzb, Stats_Lit_Len, Stats_Dis);
return Build_Descriptors (Stats_Lit_Len, Stats_Dis);
end Build_Descriptors;
procedure Scan_And_Send_From_Main_Buffer
(From, To : Lz_Buffer_Index_Type;
Last_Flush : Boolean)
is
-- The following descriptors are *not* used for compressing, but for detecting similarities.
Initial_Hd, Sliding_Hd : Deflate_Huff_Descriptors;
Start, Slide_Mid, Send_From : Lz_Buffer_Index_Type;
Sliding_Hd_Computed : Boolean;
begin
if To - From < Slider_Max then
Send_As_Block (Lz_Buffer (From .. To), Last_Flush);
return;
end if;
-- For further comments: n := LZ_buffer_size
if Past_Lz_Data then -- We have n / 2 previous data before 'from'.
Start := From - Lz_Buffer_Index_Type (Half_Slider_Size);
else
Start := From; -- Cannot have past data
end if;
-- Looped over, (mod n). Slider data are in two chunks in main buffer
if Start > From then
-- put_line(from'img & to'img & start'img);
declare
Copy_From : Lz_Buffer_Index_Type := Start;
Copy : Lz_Buffer_Type (0 .. Slider_Max);
begin
for I in Copy'Range loop
Copy (I) := Lz_Buffer (Copy_From);
Copy_From := Copy_From + 1; -- Loops over (mod n)
end loop;
Initial_Hd := Build_Descriptors (Copy);
end;
-- Concatenation instead of above loop bombs with a Range Check error:
-- lz_buffer(start .. lz_buffer'Last) &
-- lz_buffer(0 .. start + LZ_buffer_index_type(slider_max))
else
Initial_Hd := Build_Descriptors (Lz_Buffer (Start .. Start + Slider_Max));
end if;
Send_From := From;
Slide_Mid := From + Min_Step;
Scan_Lz_Data :
while Integer_M32 (Slide_Mid) + Half_Slider_Size < Integer_M32 (To) loop
exit Scan_Lz_Data when Deactivate_Scanning;
Sliding_Hd_Computed := False;
Browse_Step_Level :
for Level in Step_Choice'Range loop
exit Browse_Step_Level when Level > Max_Choice (Method);
if (Slide_Mid - From) mod Step_Choice (Level).Slider_Step = 0 then
if not Sliding_Hd_Computed then
Sliding_Hd :=
Build_Descriptors
(Lz_Buffer (Slide_Mid - Half_Slider_Size .. Slide_Mid + Half_Slider_Size));
Sliding_Hd_Computed := True;
end if;
if not Similar
(Initial_Hd,
Sliding_Hd,
Step_Choice (Level).Metric,
Step_Choice (Level).Cutting_Threshold,
"Compare sliding to initial (step size=" &
Lz_Buffer_Index_Type'Image (Step_Choice (Level).Slider_Step) &
')')
then
Send_As_Block (Lz_Buffer (Send_From .. Slide_Mid - 1), Last_Block => False);
Send_From := Slide_Mid;
Initial_Hd := Sliding_Hd; -- Reset reference descriptor for further comparisons
exit Browse_Step_Level; -- Cutting once at a given place is enough :-)
end if;
end if;
end loop Browse_Step_Level;
-- Exit before an eventual increment of slide_mid that would loop over (mod n).
exit Scan_Lz_Data when Integer_M32 (Slide_Mid) + Min_Step + Half_Slider_Size >=
Integer_M32 (To);
Slide_Mid := Slide_Mid + Min_Step;
end loop Scan_Lz_Data;
-- Send last block for slice from .. to.
if Send_From <= To then
Send_As_Block (Lz_Buffer (Send_From .. To), Last_Block => Last_Flush);
end if;
end Scan_And_Send_From_Main_Buffer;
procedure Flush_Half_Buffer (Last_Flush : Boolean) is
Last_Idx : constant Lz_Buffer_Index_Type := Lz_Buffer_Index - 1;
N_Div_2 : constant := Lz_Buffer_Size / 2;
begin
if Last_Idx < N_Div_2 then
Scan_And_Send_From_Main_Buffer (0, Last_Idx, Last_Flush); -- First half
else
Scan_And_Send_From_Main_Buffer (N_Div_2, Last_Idx, Last_Flush); -- Second half
end if;
-- From this point, all further calls to Flush_half_buffer will
-- have n_div_2 elements of past data.
Past_Lz_Data := True;
end Flush_Half_Buffer;
procedure Push (A : Lz_Atom) is
pragma Inline (Push);
begin
Lz_Buffer (Lz_Buffer_Index) := A;
Lz_Buffer_Index := Lz_Buffer_Index + 1; -- Becomes 0 when reaching LZ_buffer_size (modular)
if Lz_Buffer_Index * 2 = 0 then
Flush_Half_Buffer (Last_Flush => False);
end if;
end Push;
procedure Put_Or_Delay_Literal_Byte (B : Byte) is
pragma Inline (Put_Or_Delay_Literal_Byte);
begin
case Method is
when Deflate_Fixed =>
Put_Literal_Byte (B); -- Buffering is not needed in this mode
when Taillaule_Deflation_Method =>
Push ((Plain_Byte, B, 0, 0, (B, others => 0)));
end case;
end Put_Or_Delay_Literal_Byte;
procedure Put_Or_Delay_Dl_Code (Distance, Length : Integer; Expand : Expanded_Data) is
pragma Inline (Put_Or_Delay_Dl_Code);
begin
case Method is
when Deflate_Fixed =>
Put_Dl_Code (Distance, Length); -- Buffering is not needed in this mode
when Taillaule_Deflation_Method =>
Push ((Distance_Length, 0, Distance, Length, Expand));
end case;
end Put_Or_Delay_Dl_Code;
----------------------------------
-- LZ77 front-end compression --
----------------------------------
procedure Encode is
X_Percent : Natural;
Bytes_In : Natural; -- Count of input file bytes processed
User_Aborting : Boolean;
Pctdone : Natural;
function Read_Byte return Byte is
B : Byte;
begin
B := Inbuf (Inbufidx);
Inbufidx := Inbufidx + 1;
Zip.CRC.Update (CRC, (1 => B));
Bytes_In := Bytes_In + 1;
if Feedback /= null then
if Bytes_In = 1 then
Feedback (0, User_Aborting);
end if;
if X_Percent > 0
and then ((Bytes_In - 1) mod X_Percent = 0 or Bytes_In = Integer (Input_Size))
then
Pctdone := Integer ((100.0 * Float (Bytes_In)) / Float (Input_Size));
Feedback (Pctdone, User_Aborting);
if User_Aborting then
raise User_Abort;
end if;
end if;
end if;
return B;
end Read_Byte;
function More_Bytes return Boolean is
begin
if Inbufidx > Maxinbufidx then
Read_Block;
end if;
return not Inputeof;
end More_Bytes;
-- LZ77 parameters
Look_Ahead : constant Integer := 258;
String_Buffer_Size : constant := 2**15; -- Required: 2**15 for Deflate, 2**16 for Deflate_e
type Text_Buffer_Index is mod String_Buffer_Size;
type Text_Buffer is array (Text_Buffer_Index) of Byte;
Text_Buf : Text_Buffer;
R : Text_Buffer_Index;
-- If the DLE coding doesn't fit the format constraints, we need
-- to decode it as a simple sequence of literals. The buffer used is
-- called "Text" buffer by reference to "clear-text", but actually it
-- is any binary data.
procedure Lz77_Emits_Dl_Code (Distance, Length : Integer) is
-- NB: no worry, all arithmetics in Text_buffer_index are modulo String_buffer_size
B : Byte;
Copy_Start : Text_Buffer_Index;
Expand : Expanded_Data;
Ie : Positive := 1;
begin
if Distance =
String_Buffer_Size
then -- Happens with 7-Zip, cannot happen with Info-Zip
Copy_Start := R;
else
Copy_Start := R - Text_Buffer_Index (Distance);
end if;
-- Expand into the circular text buffer to have it up to date
for K in 0 .. Text_Buffer_Index (Length - 1) loop
B := Text_Buf (Copy_Start + K);
Text_Buf (R) := B;
R := R + 1;
if Ie <= Max_Expand then -- Also memorize short sequences for LZ buffer
Expand (Ie) := B; -- for the case a block needs to be stored in clear
Ie := Ie + 1;
end if;
end loop;
if Distance in Distance_Range and Length in Length_Range then
Put_Or_Delay_Dl_Code (Distance, Length, Expand);
else
for K in 0 .. Text_Buffer_Index (Length - 1) loop
Put_Or_Delay_Literal_Byte (Text_Buf (Copy_Start + K));
end loop;
end if;
end Lz77_Emits_Dl_Code;
procedure Lz77_Emits_Literal_Byte (B : Byte) is
begin
Text_Buf (R) := B;
R := R + 1;
Put_Or_Delay_Literal_Byte (B);
end Lz77_Emits_Literal_Byte;
Lz77_Choice : constant array (Deflation_Method) of Lz77.Method_Type :=
(Deflate_Fixed => Lz77.Iz_4,
Deflate_1 => Lz77.Iz_6, -- Level 6 is the default in Info-Zip's zip.exe
Deflate_2 => Lz77.Iz_8,
Deflate_3 => Lz77.Iz_10);
procedure My_Lz77 is new Lz77.Encode
(String_Buffer_Size => String_Buffer_Size,
Look_Ahead => Look_Ahead,
Threshold => 2, -- From a string match length > 2, a DL code is sent
Method => Lz77_Choice (Method),
Read_Byte => Read_Byte,
More_Bytes => More_Bytes,
Write_Literal => Lz77_Emits_Literal_Byte,
Write_Dl_Code => Lz77_Emits_Dl_Code);
begin
Read_Block;
R := Text_Buffer_Index (String_Buffer_Size - Look_Ahead);
Bytes_In := 0;
X_Percent := Integer (Input_Size / 40);
case Method is
when Deflate_Fixed => -- "Fixed" (predefined) compression structure
-- We have only one compressed data block, then it is already the last one.
Put_Code (Code => 1, Code_Size => 1); -- Signals last block
Put_Code (Code => 1, Code_Size => 2); -- Signals a "fixed" block
when Taillaule_Deflation_Method =>
null; -- No start data sent, all is delayed
end case;
-- The whole compression is happening in the following line:
My_Lz77;
-- Done. Send the code signaling the end of compressed data block:
case Method is
when Deflate_Fixed =>
Put_Huffman_Code (Curr_Descr.Lit_Len (End_Of_Block));
when Taillaule_Deflation_Method =>
if Lz_Buffer_Index * 2 = 0 then -- Already flushed at latest Push, or empty data
if Block_To_Finish and then Last_Block_Type in Fixed .. Dynamic then
Put_Huffman_Code (Curr_Descr.Lit_Len (End_Of_Block));
end if;
else
Flush_Half_Buffer (Last_Flush => True);
if Last_Block_Type in Fixed .. Dynamic then
Put_Huffman_Code (Curr_Descr.Lit_Len (End_Of_Block));
end if;
end if;
if not Last_Block_Marked then
-- Add a fake fixed block, just to have a final block...
Put_Code (Code => 1, Code_Size => 1); -- Signals last block
Put_Code (Code => 1, Code_Size => 2); -- Signals a "fixed" block
Curr_Descr := Deflate_Fixed_Descriptors;
Put_Huffman_Code (Curr_Descr.Lit_Len (End_Of_Block));
end if;
end case;
end Encode;
begin
-- Allocate input and output buffers
Inbuf := new Byte_Buffer
(1 .. Integer'Min (Integer'Max (8, Integer (Input_Size)), Default_Buffer_Size));
Outbuf := new Byte_Buffer (1 .. Default_Buffer_Size);
Output_Size := 0;
Lz_Buffer := new Full_Range_Lz_Buffer_Type;
begin
Encode;
Compression_Ok := True;
Flush_Bit_Buffer;
Flush_Byte_Buffer;
exception
when Compression_Inefficient =>
-- Escaped from Encode
Compression_Ok := False;
end;
Dispose (Lz_Buffer);
Dispose_Buffer (Inbuf);
Dispose_Buffer (Outbuf);
end DCF.Zip.Compress.Deflate;
|
-----------------------------------------------------------------------
-- gen-commands-model -- Model creation command for dynamo
-- Copyright (C) 2011, 2012 Stephane Carrez
-- Written by Stephane Carrez (Stephane.Carrez@gmail.com)
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-----------------------------------------------------------------------
with Ada.Text_IO;
with Ada.Command_Line;
with Gen.Artifacts;
with GNAT.Command_Line;
with Gen.Utils;
with Util.Files;
package body Gen.Commands.Model is
-- ------------------------------
-- Execute the command with the arguments.
-- ------------------------------
procedure Execute (Cmd : in Command;
Generator : in out Gen.Generator.Handler) is
pragma Unreferenced (Cmd);
use GNAT.Command_Line;
use Ada.Command_Line;
Name : constant String := Get_Argument;
Arg2 : constant String := Get_Argument;
Root_Dir : constant String := Generator.Get_Result_Directory;
Dir : constant String := Util.Files.Compose (Root_Dir, "db");
begin
if Name'Length = 0 then
Gen.Commands.Usage;
return;
end if;
Generator.Read_Project ("dynamo.xml");
Generator.Set_Force_Save (False);
Generator.Set_Result_Directory (Dir);
if Arg2'Length = 0 then
-- Verify that we can use the name for an Ada identifier.
if not Gen.Utils.Is_Valid_Name (Name) then
Generator.Error ("The mapping name should be a valid Ada identifier.");
raise Gen.Generator.Fatal_Error with "Invalid mapping name: " & Name;
end if;
Generator.Set_Global ("moduleName", "");
Generator.Set_Global ("modelName", Name);
else
-- Verify that we can use the name for an Ada identifier.
if not Gen.Utils.Is_Valid_Name (Name) then
Generator.Error ("The module name should be a valid Ada identifier.");
raise Gen.Generator.Fatal_Error with "Invalid module name: " & Name;
end if;
-- Likewise for the mapping name.
if not Gen.Utils.Is_Valid_Name (Arg2) then
Generator.Error ("The mapping name should be a valid Ada identifier.");
raise Gen.Generator.Fatal_Error with "Invalid mapping name: " & Arg2;
end if;
Generator.Set_Global ("moduleName", Name);
Generator.Set_Global ("modelName", Arg2);
end if;
Gen.Generator.Generate_All (Generator, Gen.Artifacts.ITERATION_TABLE, "add-model");
-- If the generation succeeds, run the generate command to generate the Ada files.
if Generator.Get_Status = Ada.Command_Line.Success then
Generator.Set_Result_Directory (Root_Dir);
Generator.Set_Force_Save (True);
Gen.Generator.Read_Models (Generator, "db");
-- Run the generation.
Gen.Generator.Prepare (Generator);
Gen.Generator.Generate_All (Generator);
Gen.Generator.Finish (Generator);
end if;
end Execute;
-- ------------------------------
-- Write the help associated with the command.
-- ------------------------------
procedure Help (Cmd : in Command;
Generator : in out Gen.Generator.Handler) is
pragma Unreferenced (Cmd, Generator);
use Ada.Text_IO;
begin
Put_Line ("add-model: Add a new database table model to the application");
Put_Line ("Usage: add-model [MODULE] NAME");
New_Line;
Put_Line (" The database table model is an XML file that describes the mapping");
Put_Line (" for of a database table to an Ada representation.");
Put_Line (" The XML description is similar to Hibernate mapping files.");
Put_Line (" (See http://docs.jboss.org/hibernate/core/3.6/"
& "reference/en-US/html/mapping.html)");
Put_Line (" If a MODULE is specified, the Ada package will be: "
& "<PROJECT>.<MODULE>.Model.<NAME>");
Put_Line (" Otherwise, the Ada package will be: <PROJECT>.Model.<NAME>");
end Help;
end Gen.Commands.Model;
|
-- This package has been generated automatically by GNATtest.
-- You are allowed to add your code to the bodies of test routines.
-- Such changes will be kept during further regeneration of this file.
-- All code placed outside of test routine bodies will be lost. The
-- code intended to set up and tear down the test environment should be
-- placed into Tk.Grid.Test_Data.
with AUnit.Assertions; use AUnit.Assertions;
with System.Assertions;
-- begin read only
-- id:2.2/00/
--
-- This section can be used to add with clauses if necessary.
--
-- end read only
with Ada.Environment_Variables; use Ada.Environment_Variables;
with Tk.Button; use Tk.Button;
with Tk.MainWindow; use Tk.MainWindow;
-- begin read only
-- end read only
package body Tk.Grid.Test_Data.Tests is
-- begin read only
-- id:2.2/01/
--
-- This section can be used to add global variables and other elements.
--
-- end read only
-- begin read only
-- end read only
-- begin read only
procedure Wrap_Test_Add_09f411_b5946b
(Child: Tk_Widget; Options: Grid_Options := Default_Grid_Options) is
begin
begin
pragma Assert(Child /= Null_Widget);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"req_sloc(tk-grid.ads:0):Test_Add1 test requirement violated");
end;
GNATtest_Generated.GNATtest_Standard.Tk.Grid.Add(Child, Options);
begin
pragma Assert(True);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"ens_sloc(tk-grid.ads:0:):Test_Add1 test commitment violated");
end;
end Wrap_Test_Add_09f411_b5946b;
-- end read only
-- begin read only
procedure Test_1_Add_test_add1(Gnattest_T: in out Test);
procedure Test_Add_09f411_b5946b(Gnattest_T: in out Test) renames
Test_1_Add_test_add1;
-- id:2.2/09f41181ba943205/Add/1/0/test_add1/
procedure Test_1_Add_test_add1(Gnattest_T: in out Test) is
procedure Add
(Child: Tk_Widget;
Options: Grid_Options := Default_Grid_Options) renames
Wrap_Test_Add_09f411_b5946b;
-- end read only
pragma Unreferenced(Gnattest_T);
Button: Tk_Button;
begin
if Value("DISPLAY", "")'Length = 0 then
Assert(True, "No display, can't test");
return;
end if;
Create(Button, ".mybutton", Button_Options'(others => <>));
Add(Button);
Assert
(Get_Size(Get_Main_Window) = (1, 1), "Failed to add widget to grid.");
Destroy(Button);
-- begin read only
end Test_1_Add_test_add1;
-- end read only
-- begin read only
procedure Wrap_Test_Add_6de79c_257591
(Widgets: Widgets_Array; Options: Grid_Options := Default_Grid_Options) is
begin
begin
pragma Assert(Widgets'Length > 0);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"req_sloc(tk-grid.ads:0):Test_Add2 test requirement violated");
end;
GNATtest_Generated.GNATtest_Standard.Tk.Grid.Add(Widgets, Options);
begin
pragma Assert(True);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"ens_sloc(tk-grid.ads:0:):Test_Add2 test commitment violated");
end;
end Wrap_Test_Add_6de79c_257591;
-- end read only
-- begin read only
procedure Test_2_Add_test_add2(Gnattest_T: in out Test);
procedure Test_Add_6de79c_257591(Gnattest_T: in out Test) renames
Test_2_Add_test_add2;
-- id:2.2/6de79c7546153f9d/Add/0/0/test_add2/
procedure Test_2_Add_test_add2(Gnattest_T: in out Test) is
procedure Add
(Widgets: Widgets_Array;
Options: Grid_Options := Default_Grid_Options) renames
Wrap_Test_Add_6de79c_257591;
-- end read only
pragma Unreferenced(Gnattest_T);
Button1: Tk_Button;
Button2: Tk_Button;
begin
if Value("DISPLAY", "")'Length = 0 then
Assert(True, "No display, can't test");
return;
end if;
Create(Button1, ".mybutton", Button_Options'(others => <>));
Create(Button2, ".mybutton2", Button_Options'(others => <>));
Add((Button1, Button2));
Assert
(Get_Size(Get_Main_Window) = (2, 1), "Failed to add widgets to grid.");
Destroy(Button1);
Destroy(Button2);
-- begin read only
end Test_2_Add_test_add2;
-- end read only
-- begin read only
procedure Wrap_Test_Set_Anchor_94c9fb_f07f8d
(Master: Tk_Widget; New_Direction: Directions_Type) is
begin
begin
pragma Assert(Master /= Null_Widget and New_Direction /= NONE);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"req_sloc(tk-grid.ads:0):Test_Anchor1 test requirement violated");
end;
GNATtest_Generated.GNATtest_Standard.Tk.Grid.Set_Anchor
(Master, New_Direction);
begin
pragma Assert(True);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"ens_sloc(tk-grid.ads:0:):Test_Anchor1 test commitment violated");
end;
end Wrap_Test_Set_Anchor_94c9fb_f07f8d;
-- end read only
-- begin read only
procedure Test_Set_Anchor_test_anchor1(Gnattest_T: in out Test);
procedure Test_Set_Anchor_94c9fb_f07f8d(Gnattest_T: in out Test) renames
Test_Set_Anchor_test_anchor1;
-- id:2.2/94c9fbd74d3a50b6/Set_Anchor/1/0/test_anchor1/
procedure Test_Set_Anchor_test_anchor1(Gnattest_T: in out Test) is
procedure Set_Anchor
(Master: Tk_Widget; New_Direction: Directions_Type) renames
Wrap_Test_Set_Anchor_94c9fb_f07f8d;
-- end read only
pragma Unreferenced(Gnattest_T);
begin
if Value("DISPLAY", "")'Length = 0 then
Assert(True, "No display, can't test");
return;
end if;
Set_Anchor(Get_Main_Window, CENTER);
Assert
(Get_Anchor(Get_Main_Window) = CENTER,
"Failed to set anchor for grid.");
-- begin read only
end Test_Set_Anchor_test_anchor1;
-- end read only
-- begin read only
function Wrap_Test_Get_Anchor_3fef99_b06609
(Master: Tk_Widget) return Directions_Type is
begin
begin
pragma Assert
(Master /= Null_Widget
or else Tk_Interp(Widgt => Master) /= Null_Interpreter);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"req_sloc(tk-grid.ads:0):Test_Anchor2 test requirement violated");
end;
declare
Test_Get_Anchor_3fef99_b06609_Result: constant Directions_Type :=
GNATtest_Generated.GNATtest_Standard.Tk.Grid.Get_Anchor(Master);
begin
begin
pragma Assert(True);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"ens_sloc(tk-grid.ads:0:):Test_Anchor2 test commitment violated");
end;
return Test_Get_Anchor_3fef99_b06609_Result;
end;
end Wrap_Test_Get_Anchor_3fef99_b06609;
-- end read only
-- begin read only
procedure Test_Get_Anchor_test_anchor2(Gnattest_T: in out Test);
procedure Test_Get_Anchor_3fef99_b06609(Gnattest_T: in out Test) renames
Test_Get_Anchor_test_anchor2;
-- id:2.2/3fef99fba2d1c85d/Get_Anchor/1/0/test_anchor2/
procedure Test_Get_Anchor_test_anchor2(Gnattest_T: in out Test) is
function Get_Anchor(Master: Tk_Widget) return Directions_Type renames
Wrap_Test_Get_Anchor_3fef99_b06609;
-- end read only
pragma Unreferenced(Gnattest_T);
begin
if Value("DISPLAY", "")'Length = 0 then
Assert(True, "No display, can't test");
return;
end if;
Assert
(Get_Anchor(Get_Main_Window) = CENTER,
"Failed to get anchor for grid.");
-- begin read only
end Test_Get_Anchor_test_anchor2;
-- end read only
-- begin read only
function Wrap_Test_Get_Bounding_Box_c2a26c_6b6e30
(Master: Tk_Widget; Column, Row, Column2, Row2: Natural)
return Bbox_Data is
begin
begin
pragma Assert(Master /= Null_Widget);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"req_sloc(tk-grid.ads:0):Test_Get_BBox test requirement violated");
end;
declare
Test_Get_Bounding_Box_c2a26c_6b6e30_Result: constant Bbox_Data :=
GNATtest_Generated.GNATtest_Standard.Tk.Grid.Get_Bounding_Box
(Master, Column, Row, Column2, Row2);
begin
begin
pragma Assert(True);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"ens_sloc(tk-grid.ads:0:):Test_Get_BBox test commitment violated");
end;
return Test_Get_Bounding_Box_c2a26c_6b6e30_Result;
end;
end Wrap_Test_Get_Bounding_Box_c2a26c_6b6e30;
-- end read only
-- begin read only
procedure Test_1_Get_Bounding_Box_test_get_bbox(Gnattest_T: in out Test);
procedure Test_Get_Bounding_Box_c2a26c_6b6e30
(Gnattest_T: in out Test) renames
Test_1_Get_Bounding_Box_test_get_bbox;
-- id:2.2/c2a26cdb24b5a363/Get_Bounding_Box/1/0/test_get_bbox/
procedure Test_1_Get_Bounding_Box_test_get_bbox(Gnattest_T: in out Test) is
function Get_Bounding_Box
(Master: Tk_Widget; Column, Row, Column2, Row2: Natural)
return Bbox_Data renames
Wrap_Test_Get_Bounding_Box_c2a26c_6b6e30;
-- end read only
pragma Unreferenced(Gnattest_T);
begin
if Value("DISPLAY", "")'Length = 0 then
Assert(True, "No display, can't test");
return;
end if;
Assert
(Get_Bounding_Box(Get_Main_Window, 0, 0, 1, 1) = (0, 0, 0, 0),
"Failed to get bounding box of the widget with selected columns and rows.");
-- begin read only
end Test_1_Get_Bounding_Box_test_get_bbox;
-- end read only
-- begin read only
function Wrap_Test_Get_Bounding_Box_154409_8eb716
(Master: Tk_Widget; Column, Row: Natural) return Bbox_Data is
begin
begin
pragma Assert(Master /= Null_Widget);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"req_sloc(tk-grid.ads:0):Test_Get_BBox2 test requirement violated");
end;
declare
Test_Get_Bounding_Box_154409_8eb716_Result: constant Bbox_Data :=
GNATtest_Generated.GNATtest_Standard.Tk.Grid.Get_Bounding_Box
(Master, Column, Row);
begin
begin
pragma Assert(True);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"ens_sloc(tk-grid.ads:0:):Test_Get_BBox2 test commitment violated");
end;
return Test_Get_Bounding_Box_154409_8eb716_Result;
end;
end Wrap_Test_Get_Bounding_Box_154409_8eb716;
-- end read only
-- begin read only
procedure Test_2_Get_Bounding_Box_test_get_bbox2(Gnattest_T: in out Test);
procedure Test_Get_Bounding_Box_154409_8eb716
(Gnattest_T: in out Test) renames
Test_2_Get_Bounding_Box_test_get_bbox2;
-- id:2.2/1544093478185a78/Get_Bounding_Box/0/0/test_get_bbox2/
procedure Test_2_Get_Bounding_Box_test_get_bbox2(Gnattest_T: in out Test) is
function Get_Bounding_Box
(Master: Tk_Widget; Column, Row: Natural) return Bbox_Data renames
Wrap_Test_Get_Bounding_Box_154409_8eb716;
-- end read only
pragma Unreferenced(Gnattest_T);
begin
if Value("DISPLAY", "")'Length = 0 then
Assert(True, "No display, can't test");
return;
end if;
Assert
(Get_Bounding_Box(Get_Main_Window, 0, 0) = (0, 0, 0, 0),
"Failed to get bounding box of the widget with selected column and row.");
-- begin read only
end Test_2_Get_Bounding_Box_test_get_bbox2;
-- end read only
-- begin read only
function Wrap_Test_Get_Bounding_Box_f0c44d_c84870
(Master: Tk_Widget) return Bbox_Data is
begin
begin
pragma Assert(Master /= Null_Widget);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"req_sloc(tk-grid.ads:0):Test_Get_BBox3 test requirement violated");
end;
declare
Test_Get_Bounding_Box_f0c44d_c84870_Result: constant Bbox_Data :=
GNATtest_Generated.GNATtest_Standard.Tk.Grid.Get_Bounding_Box
(Master);
begin
begin
pragma Assert(True);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"ens_sloc(tk-grid.ads:0:):Test_Get_BBox3 test commitment violated");
end;
return Test_Get_Bounding_Box_f0c44d_c84870_Result;
end;
end Wrap_Test_Get_Bounding_Box_f0c44d_c84870;
-- end read only
-- begin read only
procedure Test_3_Get_Bounding_Box_test_get_bbox3(Gnattest_T: in out Test);
procedure Test_Get_Bounding_Box_f0c44d_c84870
(Gnattest_T: in out Test) renames
Test_3_Get_Bounding_Box_test_get_bbox3;
-- id:2.2/f0c44deef0828329/Get_Bounding_Box/0/0/test_get_bbox3/
procedure Test_3_Get_Bounding_Box_test_get_bbox3(Gnattest_T: in out Test) is
function Get_Bounding_Box(Master: Tk_Widget) return Bbox_Data renames
Wrap_Test_Get_Bounding_Box_f0c44d_c84870;
-- end read only
pragma Unreferenced(Gnattest_T);
begin
if Value("DISPLAY", "")'Length = 0 then
Assert(True, "No display, can't test");
return;
end if;
Assert
(Get_Bounding_Box(Get_Main_Window) = (0, 0, 0, 0),
"Failed to get bounding box of the widget.");
-- begin read only
end Test_3_Get_Bounding_Box_test_get_bbox3;
-- end read only
-- begin read only
procedure Wrap_Test_Column_Configure_b41aca_dcc0a7
(Master: Tk_Widget; Child_Name: Tcl_String; Options: Column_Options) is
begin
begin
pragma Assert
(Master /= Null_Widget and Length(Source => Child_Name) > 0 and
Options /= Default_Column_Options);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"req_sloc(tk-grid.ads:0):Test_Column_Configure1 test requirement violated");
end;
GNATtest_Generated.GNATtest_Standard.Tk.Grid.Column_Configure
(Master, Child_Name, Options);
begin
pragma Assert(True);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"ens_sloc(tk-grid.ads:0:):Test_Column_Configure1 test commitment violated");
end;
end Wrap_Test_Column_Configure_b41aca_dcc0a7;
-- end read only
-- begin read only
procedure Test_1_Column_Configure_test_column_configure1
(Gnattest_T: in out Test);
procedure Test_Column_Configure_b41aca_dcc0a7
(Gnattest_T: in out Test) renames
Test_1_Column_Configure_test_column_configure1;
-- id:2.2/b41aca7d33fda6d6/Column_Configure/1/0/test_column_configure1/
procedure Test_1_Column_Configure_test_column_configure1
(Gnattest_T: in out Test) is
procedure Column_Configure
(Master: Tk_Widget; Child_Name: Tcl_String;
Options: Column_Options) renames
Wrap_Test_Column_Configure_b41aca_dcc0a7;
-- end read only
pragma Unreferenced(Gnattest_T);
Button: Tk_Button;
Options: Column_Options;
begin
if Value("DISPLAY", "")'Length = 0 then
Assert(True, "No display, can't test");
return;
end if;
Create(Button, ".mybutton", Button_Options'(others => <>));
Add(Button);
Column_Configure
(Get_Main_Window, To_Tcl_String(Tk_Path_Name(Button)),
Column_Options'(Weight => 5, others => <>));
Options := Get_Column_Options(Get_Main_Window, 0);
Assert
(Options.Weight = 5,
"Failed to set column options with child name for grid.");
Destroy(Button);
-- begin read only
end Test_1_Column_Configure_test_column_configure1;
-- end read only
-- begin read only
procedure Wrap_Test_Column_Configure_dbcaa4_baf62d
(Master, Child: Tk_Widget; Options: Column_Options) is
begin
begin
pragma Assert
(Master /= Null_Widget and Child /= Null_Widget and
Options /= Default_Column_Options);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"req_sloc(tk-grid.ads:0):Test_Column_Configure2 test requirement violated");
end;
GNATtest_Generated.GNATtest_Standard.Tk.Grid.Column_Configure
(Master, Child, Options);
begin
pragma Assert(True);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"ens_sloc(tk-grid.ads:0:):Test_Column_Configure2 test commitment violated");
end;
end Wrap_Test_Column_Configure_dbcaa4_baf62d;
-- end read only
-- begin read only
procedure Test_2_Column_Configure_test_column_configure2
(Gnattest_T: in out Test);
procedure Test_Column_Configure_dbcaa4_baf62d
(Gnattest_T: in out Test) renames
Test_2_Column_Configure_test_column_configure2;
-- id:2.2/dbcaa489b9b4b4dc/Column_Configure/0/0/test_column_configure2/
procedure Test_2_Column_Configure_test_column_configure2
(Gnattest_T: in out Test) is
procedure Column_Configure
(Master, Child: Tk_Widget; Options: Column_Options) renames
Wrap_Test_Column_Configure_dbcaa4_baf62d;
-- end read only
pragma Unreferenced(Gnattest_T);
Button: Tk_Button;
Options: Column_Options;
begin
if Value("DISPLAY", "")'Length = 0 then
Assert(True, "No display, can't test");
return;
end if;
Create(Button, ".mybutton", Button_Options'(others => <>));
Add(Button);
Column_Configure
(Get_Main_Window, Button, Column_Options'(Weight => 15, others => <>));
Options := Get_Column_Options(Get_Main_Window, 0);
Assert
(Options.Weight = 15,
"Failed to set column options with child for grid.");
Destroy(Button);
-- begin read only
end Test_2_Column_Configure_test_column_configure2;
-- end read only
-- begin read only
procedure Wrap_Test_Column_Configure_86279e_3e25dc
(Master: Tk_Widget; Column: Natural; Options: Column_Options) is
begin
begin
pragma Assert
(Master /= Null_Widget and Options /= Default_Column_Options);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"req_sloc(tk-grid.ads:0):Test_Column_Configure3 test requirement violated");
end;
GNATtest_Generated.GNATtest_Standard.Tk.Grid.Column_Configure
(Master, Column, Options);
begin
pragma Assert(True);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"ens_sloc(tk-grid.ads:0:):Test_Column_Configure3 test commitment violated");
end;
end Wrap_Test_Column_Configure_86279e_3e25dc;
-- end read only
-- begin read only
procedure Test_3_Column_Configure_test_column_configure3
(Gnattest_T: in out Test);
procedure Test_Column_Configure_86279e_3e25dc
(Gnattest_T: in out Test) renames
Test_3_Column_Configure_test_column_configure3;
-- id:2.2/86279edebadeb350/Column_Configure/0/0/test_column_configure3/
procedure Test_3_Column_Configure_test_column_configure3
(Gnattest_T: in out Test) is
procedure Column_Configure
(Master: Tk_Widget; Column: Natural; Options: Column_Options) renames
Wrap_Test_Column_Configure_86279e_3e25dc;
-- end read only
pragma Unreferenced(Gnattest_T);
Options: Column_Options;
begin
if Value("DISPLAY", "")'Length = 0 then
Assert(True, "No display, can't test");
return;
end if;
Column_Configure
(Get_Main_Window, 0, Column_Options'(Weight => 1, others => <>));
Options := Get_Column_Options(Get_Main_Window, 0);
Assert
(Options.Weight = 1,
"Failed to set column options with column number for grid.");
-- begin read only
end Test_3_Column_Configure_test_column_configure3;
-- end read only
-- begin read only
function Wrap_Test_Get_Column_Options_22be63_f54751
(Master: Tk_Widget; Column: Natural) return Column_Options is
begin
begin
pragma Assert(Master /= Null_Widget);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"req_sloc(tk-grid.ads:0):Test_Get_Column_Options test requirement violated");
end;
declare
Test_Get_Column_Options_22be63_f54751_Result: constant Column_Options :=
GNATtest_Generated.GNATtest_Standard.Tk.Grid.Get_Column_Options
(Master, Column);
begin
begin
pragma Assert(True);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"ens_sloc(tk-grid.ads:0:):Test_Get_Column_Options test commitment violated");
end;
return Test_Get_Column_Options_22be63_f54751_Result;
end;
end Wrap_Test_Get_Column_Options_22be63_f54751;
-- end read only
-- begin read only
procedure Test_Get_Column_Options_test_get_column_options
(Gnattest_T: in out Test);
procedure Test_Get_Column_Options_22be63_f54751
(Gnattest_T: in out Test) renames
Test_Get_Column_Options_test_get_column_options;
-- id:2.2/22be6327e6c5ccd3/Get_Column_Options/1/0/test_get_column_options/
procedure Test_Get_Column_Options_test_get_column_options
(Gnattest_T: in out Test) is
function Get_Column_Options
(Master: Tk_Widget; Column: Natural) return Column_Options renames
Wrap_Test_Get_Column_Options_22be63_f54751;
-- end read only
pragma Unreferenced(Gnattest_T);
Options: Column_Options;
begin
if Value("DISPLAY", "")'Length = 0 then
Assert(True, "No display, can't test");
return;
end if;
Column_Configure
(Get_Main_Window, 0, Column_Options'(Weight => 23, others => <>));
Options := Get_Column_Options(Get_Main_Window, 0);
Assert(Options.Weight = 23, "Failed to get column options for grid.");
-- begin read only
end Test_Get_Column_Options_test_get_column_options;
-- end read only
-- begin read only
procedure Wrap_Test_Configure_c67185_4765c0
(Child: Tk_Widget; Options: Grid_Options) is
begin
begin
pragma Assert
(Child /= Null_Widget and Options /= Default_Grid_Options);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"req_sloc(tk-grid.ads:0):Test_Configure1 test requirement violated");
end;
GNATtest_Generated.GNATtest_Standard.Tk.Grid.Configure(Child, Options);
begin
pragma Assert(True);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"ens_sloc(tk-grid.ads:0:):Test_Configure1 test commitment violated");
end;
end Wrap_Test_Configure_c67185_4765c0;
-- end read only
-- begin read only
procedure Test_1_Configure_test_configure1(Gnattest_T: in out Test);
procedure Test_Configure_c67185_4765c0(Gnattest_T: in out Test) renames
Test_1_Configure_test_configure1;
-- id:2.2/c6718582592dc115/Configure/1/0/test_configure1/
procedure Test_1_Configure_test_configure1(Gnattest_T: in out Test) is
procedure Configure(Child: Tk_Widget; Options: Grid_Options) renames
Wrap_Test_Configure_c67185_4765c0;
-- end read only
pragma Unreferenced(Gnattest_T);
Button: Tk_Button;
Options: Grid_Options;
begin
if Value("DISPLAY", "")'Length = 0 then
Assert(True, "No display, can't test");
return;
end if;
Create(Button, ".mybutton", Button_Options'(others => <>));
Add(Button);
Configure(Button, Grid_Options'(Row => 1, others => <>));
Options := Get_Info(Button);
Assert(Options.Row = 1, "Failed to configure widget in grid.");
Destroy(Button);
-- begin read only
end Test_1_Configure_test_configure1;
-- end read only
-- begin read only
procedure Wrap_Test_Configure_f31b66_3e2feb
(Widgets: Widgets_Array; Options: Grid_Options) is
begin
begin
pragma Assert(Widgets'Length > 0 and Options /= Default_Grid_Options);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"req_sloc(tk-grid.ads:0):Test_Configure2 test requirement violated");
end;
GNATtest_Generated.GNATtest_Standard.Tk.Grid.Configure(Widgets, Options);
begin
pragma Assert(True);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"ens_sloc(tk-grid.ads:0:):Test_Configure2 test commitment violated");
end;
end Wrap_Test_Configure_f31b66_3e2feb;
-- end read only
-- begin read only
procedure Test_2_Configure_test_configure2(Gnattest_T: in out Test);
procedure Test_Configure_f31b66_3e2feb(Gnattest_T: in out Test) renames
Test_2_Configure_test_configure2;
-- id:2.2/f31b66078cc53553/Configure/0/0/test_configure2/
procedure Test_2_Configure_test_configure2(Gnattest_T: in out Test) is
procedure Configure
(Widgets: Widgets_Array; Options: Grid_Options) renames
Wrap_Test_Configure_f31b66_3e2feb;
-- end read only
pragma Unreferenced(Gnattest_T);
Button1: Tk_Button;
Button2: Tk_Button;
Options: Grid_Options;
begin
if Value("DISPLAY", "")'Length = 0 then
Assert(True, "No display, can't test");
return;
end if;
Create(Button1, ".mybutton", Button_Options'(others => <>));
Create(Button2, ".mybutton2", Button_Options'(others => <>));
Add((Button1, Button2));
Configure((Button1, Button2), Grid_Options'(Row => 1, others => <>));
Options := Get_Info(Button1);
Assert(Options.Row = 1, "Failed to configure widgets in grid.");
Destroy(Button1);
Destroy(Button2);
-- begin read only
end Test_2_Configure_test_configure2;
-- end read only
-- begin read only
procedure Wrap_Test_Forget_7f8bc2_8fa399(Child: Tk_Widget) is
begin
begin
pragma Assert(Child /= Null_Widget);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"req_sloc(tk-grid.ads:0):Test_Forget1 test requirement violated");
end;
GNATtest_Generated.GNATtest_Standard.Tk.Grid.Forget(Child);
begin
pragma Assert(True);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"ens_sloc(tk-grid.ads:0:):Test_Forget1 test commitment violated");
end;
end Wrap_Test_Forget_7f8bc2_8fa399;
-- end read only
-- begin read only
procedure Test_1_Forget_test_forget1(Gnattest_T: in out Test);
procedure Test_Forget_7f8bc2_8fa399(Gnattest_T: in out Test) renames
Test_1_Forget_test_forget1;
-- id:2.2/7f8bc223a819d0d3/Forget/1/0/test_forget1/
procedure Test_1_Forget_test_forget1(Gnattest_T: in out Test) is
procedure Forget(Child: Tk_Widget) renames
Wrap_Test_Forget_7f8bc2_8fa399;
-- end read only
pragma Unreferenced(Gnattest_T);
Button: Tk_Button;
begin
if Value("DISPLAY", "")'Length = 0 then
Assert(True, "No display, can't test");
return;
end if;
Create(Button, ".mybutton", Button_Options'(others => <>));
Add(Button);
Forget(Button);
Assert
(Get_Slaves(Get_Main_Window)'Length = 0,
"Failed to forget widget in grid.");
Destroy(Button);
-- begin read only
end Test_1_Forget_test_forget1;
-- end read only
-- begin read only
procedure Wrap_Test_Forget_41161d_27199d(Widgets: Widgets_Array) is
begin
begin
pragma Assert(Widgets'Length > 0);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"req_sloc(tk-grid.ads:0):Test_Forget2 test requirement violated");
end;
GNATtest_Generated.GNATtest_Standard.Tk.Grid.Forget(Widgets);
begin
pragma Assert(True);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"ens_sloc(tk-grid.ads:0:):Test_Forget2 test commitment violated");
end;
end Wrap_Test_Forget_41161d_27199d;
-- end read only
-- begin read only
procedure Test_2_Forget_test_forget2(Gnattest_T: in out Test);
procedure Test_Forget_41161d_27199d(Gnattest_T: in out Test) renames
Test_2_Forget_test_forget2;
-- id:2.2/41161d5f24ba4e15/Forget/0/0/test_forget2/
procedure Test_2_Forget_test_forget2(Gnattest_T: in out Test) is
procedure Forget(Widgets: Widgets_Array) renames
Wrap_Test_Forget_41161d_27199d;
-- end read only
pragma Unreferenced(Gnattest_T);
Button1: Tk_Button;
Button2: Tk_Button;
begin
if Value("DISPLAY", "")'Length = 0 then
Assert(True, "No display, can't test");
return;
end if;
Create(Button1, ".mybutton", Button_Options'(others => <>));
Create(Button2, ".mybutton2", Button_Options'(others => <>));
Add((Button1, Button2));
Forget((Button1, Button2));
Assert
(Get_Slaves(Get_Main_Window)'Length = 0,
"Failed to forget widgets in grid.");
Destroy(Button1);
Destroy(Button2);
-- begin read only
end Test_2_Forget_test_forget2;
-- end read only
-- begin read only
function Wrap_Test_Get_Info_8760e4_ba34a0
(Child: Tk_Widget) return Grid_Options is
begin
begin
pragma Assert(Child /= Null_Widget);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"req_sloc(tk-grid.ads:0):Test_Info test requirement violated");
end;
declare
Test_Get_Info_8760e4_ba34a0_Result: constant Grid_Options :=
GNATtest_Generated.GNATtest_Standard.Tk.Grid.Get_Info(Child);
begin
begin
pragma Assert(True);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"ens_sloc(tk-grid.ads:0:):Test_Info test commitment violated");
end;
return Test_Get_Info_8760e4_ba34a0_Result;
end;
end Wrap_Test_Get_Info_8760e4_ba34a0;
-- end read only
-- begin read only
procedure Test_Get_Info_test_info(Gnattest_T: in out Test);
procedure Test_Get_Info_8760e4_ba34a0(Gnattest_T: in out Test) renames
Test_Get_Info_test_info;
-- id:2.2/8760e435e0a1baad/Get_Info/1/0/test_info/
procedure Test_Get_Info_test_info(Gnattest_T: in out Test) is
function Get_Info(Child: Tk_Widget) return Grid_Options renames
Wrap_Test_Get_Info_8760e4_ba34a0;
-- end read only
pragma Unreferenced(Gnattest_T);
Button: Tk_Button;
Options: Grid_Options;
begin
if Value("DISPLAY", "")'Length = 0 then
Assert(True, "No display, can't test");
return;
end if;
Create(Button, ".mybutton", Button_Options'(others => <>));
Add(Button, Grid_Options'(Row => 1, others => <>));
Options := Get_Info(Button);
Assert(Options.Row = 1, "Failed to get widget grid options in grid.");
Destroy(Button);
-- begin read only
end Test_Get_Info_test_info;
-- end read only
-- begin read only
function Wrap_Test_Get_Location_3c34d1_74cec4
(Master: Tk_Widget; X, Y: Pixel_Data) return Location_Position is
begin
begin
pragma Assert
(Master /= Null_Widget and X.Value > -1.0 and Y.Value > -1.0);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"req_sloc(tk-grid.ads:0):Test_Location test requirement violated");
end;
declare
Test_Get_Location_3c34d1_74cec4_Result: constant Location_Position :=
GNATtest_Generated.GNATtest_Standard.Tk.Grid.Get_Location
(Master, X, Y);
begin
begin
pragma Assert(True);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"ens_sloc(tk-grid.ads:0:):Test_Location test commitment violated");
end;
return Test_Get_Location_3c34d1_74cec4_Result;
end;
end Wrap_Test_Get_Location_3c34d1_74cec4;
-- end read only
-- begin read only
procedure Test_Get_Location_test_location(Gnattest_T: in out Test);
procedure Test_Get_Location_3c34d1_74cec4(Gnattest_T: in out Test) renames
Test_Get_Location_test_location;
-- id:2.2/3c34d18d58761388/Get_Location/1/0/test_location/
procedure Test_Get_Location_test_location(Gnattest_T: in out Test) is
function Get_Location
(Master: Tk_Widget; X, Y: Pixel_Data) return Location_Position renames
Wrap_Test_Get_Location_3c34d1_74cec4;
-- end read only
pragma Unreferenced(Gnattest_T);
begin
if Value("DISPLAY", "")'Length = 0 then
Assert(True, "No display, can't test");
return;
end if;
Assert
(Get_Location(Get_Main_Window, (0.0, PIXEL), (0.0, PIXEL)) =
(Column => 0, Row => 0),
"Failed to get location in grid.");
-- begin read only
end Test_Get_Location_test_location;
-- end read only
-- begin read only
procedure Wrap_Test_Set_Propagate_38a3d0_e08f8c
(Master: Tk_Widget; Enable: Boolean := True) is
begin
begin
pragma Assert(Master /= Null_Widget);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"req_sloc(tk-grid.ads:0):Test_Propagate1 test requirement violated");
end;
GNATtest_Generated.GNATtest_Standard.Tk.Grid.Set_Propagate
(Master, Enable);
begin
pragma Assert(True);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"ens_sloc(tk-grid.ads:0:):Test_Propagate1 test commitment violated");
end;
end Wrap_Test_Set_Propagate_38a3d0_e08f8c;
-- end read only
-- begin read only
procedure Test_Set_Propagate_test_propagate1(Gnattest_T: in out Test);
procedure Test_Set_Propagate_38a3d0_e08f8c(Gnattest_T: in out Test) renames
Test_Set_Propagate_test_propagate1;
-- id:2.2/38a3d0651f3359fd/Set_Propagate/1/0/test_propagate1/
procedure Test_Set_Propagate_test_propagate1(Gnattest_T: in out Test) is
procedure Set_Propagate
(Master: Tk_Widget; Enable: Boolean := True) renames
Wrap_Test_Set_Propagate_38a3d0_e08f8c;
-- end read only
pragma Unreferenced(Gnattest_T);
begin
if Value("DISPLAY", "")'Length = 0 then
Assert(True, "No display, can't test");
return;
end if;
Set_Propagate(Get_Main_Window, False);
Assert
(not Get_Propagate(Get_Main_Window).Result,
"Failed to set propagation for grid.");
-- begin read only
end Test_Set_Propagate_test_propagate1;
-- end read only
-- begin read only
function Wrap_Test_Get_Propagate_b85f28_142129
(Master: Tk_Widget) return Tcl_Boolean_Result is
begin
begin
pragma Assert(Master /= Null_Widget);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"req_sloc(tk-grid.ads:0):Test_Propagate2 test requirement violated");
end;
declare
Test_Get_Propagate_b85f28_142129_Result: constant Tcl_Boolean_Result :=
GNATtest_Generated.GNATtest_Standard.Tk.Grid.Get_Propagate(Master);
begin
begin
pragma Assert(True);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"ens_sloc(tk-grid.ads:0:):Test_Propagate2 test commitment violated");
end;
return Test_Get_Propagate_b85f28_142129_Result;
end;
end Wrap_Test_Get_Propagate_b85f28_142129;
-- end read only
-- begin read only
procedure Test_Get_Propagate_test_propagate2(Gnattest_T: in out Test);
procedure Test_Get_Propagate_b85f28_142129(Gnattest_T: in out Test) renames
Test_Get_Propagate_test_propagate2;
-- id:2.2/b85f2886a59076c3/Get_Propagate/1/0/test_propagate2/
procedure Test_Get_Propagate_test_propagate2(Gnattest_T: in out Test) is
function Get_Propagate
(Master: Tk_Widget) return Tcl_Boolean_Result renames
Wrap_Test_Get_Propagate_b85f28_142129;
-- end read only
pragma Unreferenced(Gnattest_T);
begin
if Value("DISPLAY", "")'Length = 0 then
Assert(True, "No display, can't test");
return;
end if;
Set_Propagate(Get_Main_Window);
Assert
(Get_Propagate(Get_Main_Window).Result,
"Failed to get propagation for grid.");
-- begin read only
end Test_Get_Propagate_test_propagate2;
-- end read only
-- begin read only
procedure Wrap_Test_Row_Configure_cd10c1_55f5f1
(Master: Tk_Widget; Child_Name: Tcl_String; Options: Column_Options) is
begin
begin
pragma Assert
(Master /= Null_Widget and Length(Source => Child_Name) > 0 and
Options /= Default_Column_Options);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"req_sloc(tk-grid.ads:0):Test_Row_Configure1 test requirement violated");
end;
GNATtest_Generated.GNATtest_Standard.Tk.Grid.Row_Configure
(Master, Child_Name, Options);
begin
pragma Assert(True);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"ens_sloc(tk-grid.ads:0:):Test_Row_Configure1 test commitment violated");
end;
end Wrap_Test_Row_Configure_cd10c1_55f5f1;
-- end read only
-- begin read only
procedure Test_1_Row_Configure_test_row_configure1(Gnattest_T: in out Test);
procedure Test_Row_Configure_cd10c1_55f5f1(Gnattest_T: in out Test) renames
Test_1_Row_Configure_test_row_configure1;
-- id:2.2/cd10c14861fb1027/Row_Configure/1/0/test_row_configure1/
procedure Test_1_Row_Configure_test_row_configure1
(Gnattest_T: in out Test) is
procedure Row_Configure
(Master: Tk_Widget; Child_Name: Tcl_String;
Options: Column_Options) renames
Wrap_Test_Row_Configure_cd10c1_55f5f1;
-- end read only
pragma Unreferenced(Gnattest_T);
Button: Tk_Button;
Options: Column_Options;
begin
if Value("DISPLAY", "")'Length = 0 then
Assert(True, "No display, can't test");
return;
end if;
Create(Button, ".mybutton", Button_Options'(others => <>));
Add(Button);
Row_Configure
(Get_Main_Window, To_Tcl_String(Tk_Path_Name(Button)),
Column_Options'(Weight => 5, others => <>));
Options := Get_Row_Options(Get_Main_Window, 0);
Assert
(Options.Weight = 5,
"Failed to set row options with child name for grid.");
Destroy(Button);
-- begin read only
end Test_1_Row_Configure_test_row_configure1;
-- end read only
-- begin read only
procedure Wrap_Test_Row_Configure_0a2e60_353acd
(Master, Child: Tk_Widget; Options: Column_Options) is
begin
begin
pragma Assert
(Master /= Null_Widget and Child /= Null_Widget and
Options /= Default_Column_Options);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"req_sloc(tk-grid.ads:0):Test_Row_Configure2 test requirement violated");
end;
GNATtest_Generated.GNATtest_Standard.Tk.Grid.Row_Configure
(Master, Child, Options);
begin
pragma Assert(True);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"ens_sloc(tk-grid.ads:0:):Test_Row_Configure2 test commitment violated");
end;
end Wrap_Test_Row_Configure_0a2e60_353acd;
-- end read only
-- begin read only
procedure Test_2_Row_Configure_test_row_configure2(Gnattest_T: in out Test);
procedure Test_Row_Configure_0a2e60_353acd(Gnattest_T: in out Test) renames
Test_2_Row_Configure_test_row_configure2;
-- id:2.2/0a2e60e5acb5492e/Row_Configure/0/0/test_row_configure2/
procedure Test_2_Row_Configure_test_row_configure2
(Gnattest_T: in out Test) is
procedure Row_Configure
(Master, Child: Tk_Widget; Options: Column_Options) renames
Wrap_Test_Row_Configure_0a2e60_353acd;
-- end read only
pragma Unreferenced(Gnattest_T);
Button: Tk_Button;
Options: Column_Options;
begin
if Value("DISPLAY", "")'Length = 0 then
Assert(True, "No display, can't test");
return;
end if;
Create(Button, ".mybutton", Button_Options'(others => <>));
Add(Button);
Row_Configure
(Get_Main_Window, Button, Column_Options'(Weight => 15, others => <>));
Options := Get_Row_Options(Get_Main_Window, 0);
Assert
(Options.Weight = 15,
"Failed to set row options with child widget for grid.");
Destroy(Button);
-- begin read only
end Test_2_Row_Configure_test_row_configure2;
-- end read only
-- begin read only
procedure Wrap_Test_Row_Configure_7261aa_f7627e
(Master: Tk_Widget; Row: Natural; Options: Column_Options) is
begin
begin
pragma Assert
(Master /= Null_Widget and Options /= Default_Column_Options);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"req_sloc(tk-grid.ads:0):Test_Row_Configure3 test requirement violated");
end;
GNATtest_Generated.GNATtest_Standard.Tk.Grid.Row_Configure
(Master, Row, Options);
begin
pragma Assert(True);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"ens_sloc(tk-grid.ads:0:):Test_Row_Configure3 test commitment violated");
end;
end Wrap_Test_Row_Configure_7261aa_f7627e;
-- end read only
-- begin read only
procedure Test_3_Row_Configure_test_row_configure3(Gnattest_T: in out Test);
procedure Test_Row_Configure_7261aa_f7627e(Gnattest_T: in out Test) renames
Test_3_Row_Configure_test_row_configure3;
-- id:2.2/7261aa6fcbc4a5c1/Row_Configure/0/0/test_row_configure3/
procedure Test_3_Row_Configure_test_row_configure3
(Gnattest_T: in out Test) is
procedure Row_Configure
(Master: Tk_Widget; Row: Natural; Options: Column_Options) renames
Wrap_Test_Row_Configure_7261aa_f7627e;
-- end read only
pragma Unreferenced(Gnattest_T);
Options: Column_Options;
begin
if Value("DISPLAY", "")'Length = 0 then
Assert(True, "No display, can't test");
return;
end if;
Column_Configure
(Get_Main_Window, 0, Column_Options'(Weight => 1, others => <>));
Options := Get_Column_Options(Get_Main_Window, 0);
Assert
(Options.Weight = 1,
"Failed to set row options with row number for grid.");
-- begin read only
end Test_3_Row_Configure_test_row_configure3;
-- end read only
-- begin read only
function Wrap_Test_Get_Row_Options_192829_8edf28
(Master: Tk_Widget; Row: Natural) return Column_Options is
begin
begin
pragma Assert(Master /= Null_Widget);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"req_sloc(tk-grid.ads:0):Test_Get_Row_Options test requirement violated");
end;
declare
Test_Get_Row_Options_192829_8edf28_Result: constant Column_Options :=
GNATtest_Generated.GNATtest_Standard.Tk.Grid.Get_Row_Options
(Master, Row);
begin
begin
pragma Assert(True);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"ens_sloc(tk-grid.ads:0:):Test_Get_Row_Options test commitment violated");
end;
return Test_Get_Row_Options_192829_8edf28_Result;
end;
end Wrap_Test_Get_Row_Options_192829_8edf28;
-- end read only
-- begin read only
procedure Test_Get_Row_Options_test_get_row_options
(Gnattest_T: in out Test);
procedure Test_Get_Row_Options_192829_8edf28
(Gnattest_T: in out Test) renames
Test_Get_Row_Options_test_get_row_options;
-- id:2.2/192829f3d87ab7ca/Get_Row_Options/1/0/test_get_row_options/
procedure Test_Get_Row_Options_test_get_row_options
(Gnattest_T: in out Test) is
function Get_Row_Options
(Master: Tk_Widget; Row: Natural) return Column_Options renames
Wrap_Test_Get_Row_Options_192829_8edf28;
-- end read only
pragma Unreferenced(Gnattest_T);
Options: Column_Options;
begin
if Value("DISPLAY", "")'Length = 0 then
Assert(True, "No display, can't test");
return;
end if;
Row_Configure
(Get_Main_Window, 0, Column_Options'(Weight => 23, others => <>));
Options := Get_Row_Options(Get_Main_Window, 0);
Assert(Options.Weight = 23, "Failed to get column options for grid.");
-- begin read only
end Test_Get_Row_Options_test_get_row_options;
-- end read only
-- begin read only
procedure Wrap_Test_Remove_cf1782_4cc907(Child: Tk_Widget) is
begin
begin
pragma Assert(Child /= Null_Widget);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"req_sloc(tk-grid.ads:0):Test_Remove1 test requirement violated");
end;
GNATtest_Generated.GNATtest_Standard.Tk.Grid.Remove(Child);
begin
pragma Assert(True);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"ens_sloc(tk-grid.ads:0:):Test_Remove1 test commitment violated");
end;
end Wrap_Test_Remove_cf1782_4cc907;
-- end read only
-- begin read only
procedure Test_1_Remove_test_remove1(Gnattest_T: in out Test);
procedure Test_Remove_cf1782_4cc907(Gnattest_T: in out Test) renames
Test_1_Remove_test_remove1;
-- id:2.2/cf1782113fce8963/Remove/1/0/test_remove1/
procedure Test_1_Remove_test_remove1(Gnattest_T: in out Test) is
procedure Remove(Child: Tk_Widget) renames
Wrap_Test_Remove_cf1782_4cc907;
-- end read only
pragma Unreferenced(Gnattest_T);
Button: Tk_Button;
begin
if Value("DISPLAY", "")'Length = 0 then
Assert(True, "No display, can't test");
return;
end if;
Create(Button, ".mybutton", Button_Options'(others => <>));
Add(Button);
Remove(Button);
Assert
(Get_Slaves(Get_Main_Window)'Length = 0,
"Failed to remove widget in grid.");
Destroy(Button);
-- begin read only
end Test_1_Remove_test_remove1;
-- end read only
-- begin read only
procedure Wrap_Test_Remove_4f07d4_13d0b1(Widgets: Widgets_Array) is
begin
begin
pragma Assert(Widgets'Length > 0);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"req_sloc(tk-grid.ads:0):Test_Remove2 test requirement violated");
end;
GNATtest_Generated.GNATtest_Standard.Tk.Grid.Remove(Widgets);
begin
pragma Assert(True);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"ens_sloc(tk-grid.ads:0:):Test_Remove2 test commitment violated");
end;
end Wrap_Test_Remove_4f07d4_13d0b1;
-- end read only
-- begin read only
procedure Test_2_Remove_test_remove2(Gnattest_T: in out Test);
procedure Test_Remove_4f07d4_13d0b1(Gnattest_T: in out Test) renames
Test_2_Remove_test_remove2;
-- id:2.2/4f07d4b23495ca01/Remove/0/0/test_remove2/
procedure Test_2_Remove_test_remove2(Gnattest_T: in out Test) is
procedure Remove(Widgets: Widgets_Array) renames
Wrap_Test_Remove_4f07d4_13d0b1;
-- end read only
pragma Unreferenced(Gnattest_T);
Button1: Tk_Button;
Button2: Tk_Button;
begin
if Value("DISPLAY", "")'Length = 0 then
Assert(True, "No display, can't test");
return;
end if;
Create(Button1, ".mybutton", Button_Options'(others => <>));
Create(Button2, ".mybutton2", Button_Options'(others => <>));
Add((Button1, Button2));
Remove((Button1, Button2));
Assert
(Get_Slaves(Get_Main_Window)'Length = 0,
"Failed to remove widgets in grid.");
Destroy(Button1);
Destroy(Button2);
-- begin read only
end Test_2_Remove_test_remove2;
-- end read only
-- begin read only
function Wrap_Test_Get_Size_fbc383_a60758
(Master: Tk_Widget) return Location_Position is
begin
begin
pragma Assert(Master /= Null_Widget);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"req_sloc(tk-grid.ads:0):Test_Size test requirement violated");
end;
declare
Test_Get_Size_fbc383_a60758_Result: constant Location_Position :=
GNATtest_Generated.GNATtest_Standard.Tk.Grid.Get_Size(Master);
begin
begin
pragma Assert(True);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"ens_sloc(tk-grid.ads:0:):Test_Size test commitment violated");
end;
return Test_Get_Size_fbc383_a60758_Result;
end;
end Wrap_Test_Get_Size_fbc383_a60758;
-- end read only
-- begin read only
procedure Test_Get_Size_test_size(Gnattest_T: in out Test);
procedure Test_Get_Size_fbc383_a60758(Gnattest_T: in out Test) renames
Test_Get_Size_test_size;
-- id:2.2/fbc383da17d84224/Get_Size/1/0/test_size/
procedure Test_Get_Size_test_size(Gnattest_T: in out Test) is
function Get_Size(Master: Tk_Widget) return Location_Position renames
Wrap_Test_Get_Size_fbc383_a60758;
-- end read only
pragma Unreferenced(Gnattest_T);
Button1: Tk_Button;
Button2: Tk_Button;
begin
if Value("DISPLAY", "")'Length = 0 then
Assert(True, "No display, can't test");
return;
end if;
Create(Button1, ".mybutton", Button_Options'(others => <>));
Create(Button2, ".mybutton2", Button_Options'(others => <>));
Add((Button1, Button2));
Assert
(Get_Size(Get_Main_Window) = (Column => 2, Row => 1),
"Failed to get grid size.");
Destroy(Button1);
Destroy(Button2);
-- begin read only
end Test_Get_Size_test_size;
-- end read only
-- begin read only
function Wrap_Test_Get_Slaves_6dfdb7_8c1fbf
(Master: Tk_Widget; Row, Column: Extended_Natural := -1)
return Widgets_Array is
begin
begin
pragma Assert(Master /= Null_Widget);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"req_sloc(tk-grid.ads:0):Test_Slaves test requirement violated");
end;
declare
Test_Get_Slaves_6dfdb7_8c1fbf_Result: constant Widgets_Array :=
GNATtest_Generated.GNATtest_Standard.Tk.Grid.Get_Slaves
(Master, Row, Column);
begin
begin
pragma Assert(True);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"ens_sloc(tk-grid.ads:0:):Test_Slaves test commitment violated");
end;
return Test_Get_Slaves_6dfdb7_8c1fbf_Result;
end;
end Wrap_Test_Get_Slaves_6dfdb7_8c1fbf;
-- end read only
-- begin read only
procedure Test_Get_Slaves_test_slaves(Gnattest_T: in out Test);
procedure Test_Get_Slaves_6dfdb7_8c1fbf(Gnattest_T: in out Test) renames
Test_Get_Slaves_test_slaves;
-- id:2.2/6dfdb7246215d3af/Get_Slaves/1/0/test_slaves/
procedure Test_Get_Slaves_test_slaves(Gnattest_T: in out Test) is
function Get_Slaves
(Master: Tk_Widget; Row, Column: Extended_Natural := -1)
return Widgets_Array renames
Wrap_Test_Get_Slaves_6dfdb7_8c1fbf;
-- end read only
pragma Unreferenced(Gnattest_T);
Button1: Tk_Button;
Button2: Tk_Button;
begin
if Value("DISPLAY", "")'Length = 0 then
Assert(True, "No display, can't test");
return;
end if;
Create(Button1, ".mybutton", Button_Options'(others => <>));
Create(Button2, ".mybutton2", Button_Options'(others => <>));
Add((Button1, Button2));
Assert
(Get_Slaves(Get_Main_Window)'Length = 2,
"Failed to get list of slaves in grid.");
Destroy(Button1);
Destroy(Button2);
-- begin read only
end Test_Get_Slaves_test_slaves;
-- end read only
-- begin read only
-- id:2.2/02/
--
-- This section can be used to add elaboration code for the global state.
--
begin
-- end read only
null;
-- begin read only
-- end read only
end Tk.Grid.Test_Data.Tests;
|
-- { dg-do run }
procedure Discr33 is
subtype Int is Integer range 1..100;
type T (D : Int := 1) is
record
A : Integer;
B : String (1..D);
C : aliased Integer;
end record;
Var : T := (D => 1, A => 1234, B => "x", C => 4567);
type Int_Ref is access all Integer;
Pointer_To_C : Int_Ref := Var.C'Access;
begin
if Pointer_To_C.all /= 4567 then
raise Program_Error;
end if;
Var := (D => 26, A => 1234, B => "abcdefghijklmnopqrstuvwxyz", C => 2345);
if Pointer_To_C.all /= 2345 then
raise Program_Error;
end if;
end Discr33;
|
package Vect8 is
type Vec is array (1 .. 2) of Long_Float;
pragma Machine_Attribute (Vec, "vector_type");
function Foo (V : Vec) return Vec;
end Vect8;
|
package Tables is
type Table is private;
type Ordering is (Lexicographic, Psionic, ...); -- add others
procedure Sort (It : in out Table;
Order_By : in Ordering := Lexicographic;
Column : in Positive := 1;
Reverse_Ordering : in Boolean := False);
private
... -- implementation specific
end Tables;
|
------------------------------------------------------------------------------
-- Copyright (c) 2015-2017, Natacha Porté --
-- --
-- Permission to use, copy, modify, and distribute this software for any --
-- purpose with or without fee is hereby granted, provided that the above --
-- copyright notice and this permission notice appear in all copies. --
-- --
-- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES --
-- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF --
-- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR --
-- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES --
-- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN --
-- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF --
-- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. --
------------------------------------------------------------------------------
with Ada.Calendar;
with Ada.Command_Line;
with Ada.Directories;
with Ada.Text_IO;
with AWS.Config;
with AWS.Server;
with Natools.Cron;
with Lithium.Dispatchers;
with Lithium.Log;
procedure Lithium.Main is
procedure Start_Mark (Cron_Entry : in out Natools.Cron.Cron_Entry);
procedure Start_Mark (Cron_Entry : in out Natools.Cron.Cron_Entry) is
Now : constant Ada.Calendar.Time := Ada.Calendar.Clock;
begin
Cron_Entry.Set
((Origin => Ada.Calendar.Time_Of
(Ada.Calendar.Year (Now),
Ada.Calendar.Month (Now),
Ada.Calendar.Day (Now),
0.0),
Period => 86_400.0),
Log.Marker'(null record));
end Start_Mark;
Cron_Entry : Natools.Cron.Cron_Entry;
WS : AWS.Server.HTTP;
Debug : constant Boolean := Ada.Command_Line.Argument_Count >= 2;
Handler : Lithium.Dispatchers.Handler;
begin
Lithium.Log.Initialize (Debug);
if Ada.Command_Line.Argument_Count >= 1 then
Handler := Lithium.Dispatchers.Create (Ada.Command_Line.Argument (1));
else
Handler := Lithium.Dispatchers.Create ("site.sx");
end if;
AWS.Server.Start (WS, Handler, AWS.Config.Get_Current);
if not Debug then
AWS.Server.Wait;
elsif Ada.Directories.Exists (Ada.Command_Line.Argument (2)) then
Ada.Text_IO.Put_Line ("Websever started, waiting for removal of "
& Ada.Command_Line.Argument (2));
Start_Mark (Cron_Entry);
loop
delay 1.0;
exit when not Ada.Directories.Exists (Ada.Command_Line.Argument (2));
end loop;
else
Ada.Text_IO.Put_Line ("Websever started, waiting for Q press");
Start_Mark (Cron_Entry);
AWS.Server.Wait (AWS.Server.Q_Key_Pressed);
end if;
AWS.Server.Shutdown (WS);
Handler.Purge;
Cron_Entry.Reset;
end Lithium.Main;
|
with impact.d3.Shape.convex;
-- #include "BulletCollision/CollisionShapes/impact.d3.Shape.convex.h"
package impact.d3.collision.gjk_epa
--
-- GJK-EPA collision solver by Nathanael Presson, 2008
--
is
use Math;
-- btGjkEpaSolver contributed under zlib by Nathanael Presson
--
package btGjkEpaSolver2
is
type eStatus is (Separated, -- Shapes doesnt penetrate
Penetrating, -- Shapes are penetrating
GJK_Failed, -- GJK phase fail, no big issue, shapes are probably just 'touching'
EPA_Failed); -- EPA phase fail, bigger problem, need to save parameters, and debug
status : eStatus;
type Witnesses is array (1 .. 2) of math.Vector_3;
type sResults is
record
witnesses : btGjkEpaSolver2.Witnesses;
normal : math.Vector_3;
distance : math.Real;
status : eStatus;
end record;
function StackSizeRequirement return Integer;
function Distance (shape0 : in impact.d3.Shape.convex.view;
wtrs0 : in Transform_3d;
shape1 : in impact.d3.Shape.convex.view;
wtrs1 : in Transform_3d;
guess : in math.Vector_3;
results : access sResults) return Boolean;
function Penetration (shape0 : in impact.d3.Shape.convex.view;
wtrs0 : in Transform_3d;
shape1 : in impact.d3.Shape.convex.view;
wtrs1 : in Transform_3d;
guess : in math.Vector_3;
results : access sResults;
usemargins : in Boolean := True) return Boolean;
function SignedDistance (position : in math.Vector_3;
margin : in math.Real;
shape0 : in impact.d3.Shape.convex.view;
wtrs0 : in Transform_3d;
results : access sResults) return math.Real;
function SignedDistance (shape0 : in impact.d3.Shape.convex.view;
wtrs0 : in Transform_3d;
shape1 : in impact.d3.Shape.convex.view;
wtrs1 : in Transform_3d;
guess : in math.Vector_3;
results : access sResults) return Boolean;
end btGjkEpaSolver2;
end impact.d3.collision.gjk_epa;
|
------------------------------------------------------------------------------
-- --
-- GNAT RUN-TIME COMPONENTS --
-- --
-- S Y S T E M . S C A L A R _ V A L U E S --
-- --
-- S p e c --
-- --
-- Copyright (C) 2001-2005, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 2, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
-- for more details. You should have received a copy of the GNU General --
-- Public License distributed with GNAT; see file COPYING. If not, write --
-- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
-- Boston, MA 02110-1301, USA. --
-- --
--
--
--
--
--
--
--
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
-- This package defines the constants used for initializing scalar values
-- when pragma Initialize_Scalars is used. The actual values are defined
-- in the binder generated file. This package contains the Ada names that
-- are used by the generated code, which are linked to the actual values
-- by the use of pragma Import.
package System.Scalar_Values is
-- Note: logically this package should be Pure since it can be accessed
-- from pure units, but the IS_xxx variables below get set at run time,
-- so they have to be library level variables. In fact we only ever
-- access this from generated code, and the compiler knows that it is
-- OK to access this unit from generated code.
type Byte1 is mod 2 ** 8;
type Byte2 is mod 2 ** 16;
type Byte4 is mod 2 ** 32;
type Byte8 is mod 2 ** 64;
-- The explicit initializations here are not really required, since these
-- variables are always set by System.Scalar_Values.Initialize.
IS_Is1 : Byte1 := 0; -- Initialize 1 byte signed
IS_Is2 : Byte2 := 0; -- Initialize 2 byte signed
IS_Is4 : Byte4 := 0; -- Initialize 4 byte signed
IS_Is8 : Byte8 := 0; -- Initialize 8 byte signed
-- For the above cases, the undefined value (set by the binder -Sin switch)
-- is the largest negative number (1 followed by all zero bits).
IS_Iu1 : Byte1 := 0; -- Initialize 1 byte unsigned
IS_Iu2 : Byte2 := 0; -- Initialize 2 byte unsigned
IS_Iu4 : Byte4 := 0; -- Initialize 4 byte unsigned
IS_Iu8 : Byte8 := 0; -- Initialize 8 byte unsigned
-- For the above cases, the undefined value (set by the binder -Sin switch)
-- is the largest unsigned number (all 1 bits).
IS_Iz1 : Byte1 := 0; -- Initialize 1 byte zeroes
IS_Iz2 : Byte2 := 0; -- Initialize 2 byte zeroes
IS_Iz4 : Byte4 := 0; -- Initialize 4 byte zeroes
IS_Iz8 : Byte8 := 0; -- Initialize 8 byte zeroes
-- For the above cases, the undefined value (set by the binder -Sin switch)
-- is the zero (all 0 bits). This is used when zero is known to be an
-- invalid value.
-- The float definitions are aliased, because we use overlays to set them
IS_Isf : aliased Short_Float := 0.0; -- Initialize short float
IS_Ifl : aliased Float := 0.0; -- Initialize float
IS_Ilf : aliased Long_Float := 0.0; -- Initialize long float
IS_Ill : aliased Long_Long_Float := 0.0; -- Initialize long long float
procedure Initialize (Mode1 : Character; Mode2 : Character);
-- This procedure is called from the binder when Initialize_Scalars mode
-- is active. The arguments are the two characters from the -S switch,
-- with letters forced upper case. So for example if -S5a is given, then
-- Mode1 will be '5' and Mode2 will be 'A'. If the parameters are EV,
-- then this routine reads the environment variable GNAT_INIT_SCALARS.
-- The possible settings are the same as those for the -S switch (except
-- for EV), i.e. IN/LO/HO/xx, xx = 2 hex digits. If no -S switch is given
-- then the default of IN (invalid values) is passed on the call.
end System.Scalar_Values;
|
pragma Style_Checks ("NM32766");
pragma Wide_Character_Encoding (Brackets);
---------------------------------------------------
-- This file has been generated automatically from
-- cbsg.idl
-- by IAC (IDL to Ada Compiler) 20.0w (rev. 90136cd4).
---------------------------------------------------
-- NOTE: If you modify this file by hand, your
-- changes will be lost when you re-run the
-- IDL to Ada compiler.
---------------------------------------------------
with CORBA.Object;
with PolyORB.Std;
with CORBA;
pragma Elaborate_All (CORBA);
package CorbaCBSG.CBSG is
type Ref is
new CORBA.Object.Ref with null record;
Repository_Id : constant PolyORB.Std.String :=
"IDL:CorbaCBSG/CBSG:1.0";
function createTimestampedSentence
(Self : Ref)
return CorbaCBSG.timestamped_Sentence;
createTimestampedSentence_Repository_Id : constant PolyORB.Std.String :=
"IDL:CorbaCBSG/CBSG/createTimestampedSentence:1.0";
function createSentence
(Self : Ref)
return CORBA.String;
createSentence_Repository_Id : constant PolyORB.Std.String :=
"IDL:CorbaCBSG/CBSG/createSentence:1.0";
function createWorkshop
(Self : Ref)
return CORBA.String;
createWorkshop_Repository_Id : constant PolyORB.Std.String :=
"IDL:CorbaCBSG/CBSG/createWorkshop:1.0";
function createShortWorkshop
(Self : Ref)
return CORBA.String;
createShortWorkshop_Repository_Id : constant PolyORB.Std.String :=
"IDL:CorbaCBSG/CBSG/createShortWorkshop:1.0";
function createFinancialReport
(Self : Ref)
return CORBA.String;
createFinancialReport_Repository_Id : constant PolyORB.Std.String :=
"IDL:CorbaCBSG/CBSG/createFinancialReport:1.0";
function Is_A
(Self : Ref;
Logical_Type_Id : PolyORB.Std.String)
return CORBA.Boolean;
private
function Is_A
(Logical_Type_Id : PolyORB.Std.String)
return CORBA.Boolean;
end CorbaCBSG.CBSG;
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.