content
stringlengths
23
1.05M
-- Copyright (C) 2019 Thierry Rascle <thierr26@free.fr> -- MIT license. Please refer to the LICENSE file. with Ada.Finalization; package Apsepp.Test_Node_Class.Runner_Sequential.W_Slave_Nodes is type Test_Runner_Sequential_W_Slave_Tasks is limited new Test_Runner_Sequential with private; overriding procedure Run (Obj : in out Test_Runner_Sequential_W_Slave_Tasks; Outcome : out Test_Outcome; Kind : Run_Kind := Assert_Cond_And_Run_Test); private type Controlled_Slaves_Array_Access is new Ada.Finalization.Limited_Controlled with record A : Test_Node_Array_Access; end record; overriding procedure Finalize (Obj : in out Controlled_Slaves_Array_Access); type Test_Runner_Sequential_W_Slave_Tasks is limited new Test_Runner_Sequential with record Slaves : Controlled_Slaves_Array_Access; end record; end Apsepp.Test_Node_Class.Runner_Sequential.W_Slave_Nodes;
pragma Ada_2012; pragma Style_Checks (Off); with Interfaces.C; use Interfaces.C; limited with bits_types_struct_iovec_h; with sys_types_h; with bits_types_h; package sys_uio_h is -- unsupported macro: UIO_MAXIOV __IOV_MAX -- Copyright (C) 1991-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/>. -- Read data from file descriptor FD, and put the result in the -- buffers described by IOVEC, which is a vector of COUNT 'struct iovec's. -- The buffers are filled in the order specified. -- Operates just like 'read' (see <unistd.h>) except that data are -- put in IOVEC instead of a contiguous buffer. -- This function is a cancellation point and therefore not marked with -- __THROW. function readv (uu_fd : int; uu_iovec : access constant bits_types_struct_iovec_h.iovec; uu_count : int) return sys_types_h.ssize_t -- /usr/include/sys/uio.h:41 with Import => True, Convention => C, External_Name => "readv"; -- Write data pointed by the buffers described by IOVEC, which -- is a vector of COUNT 'struct iovec's, to file descriptor FD. -- The data is written in the order specified. -- Operates just like 'write' (see <unistd.h>) except that the data -- are taken from IOVEC instead of a contiguous buffer. -- This function is a cancellation point and therefore not marked with -- __THROW. function writev (uu_fd : int; uu_iovec : access constant bits_types_struct_iovec_h.iovec; uu_count : int) return sys_types_h.ssize_t -- /usr/include/sys/uio.h:52 with Import => True, Convention => C, External_Name => "writev"; -- Read data from file descriptor FD at the given position OFFSET -- without change the file pointer, and put the result in the buffers -- described by IOVEC, which is a vector of COUNT 'struct iovec's. -- The buffers are filled in the order specified. Operates just like -- 'pread' (see <unistd.h>) except that data are put in IOVEC instead -- of a contiguous buffer. -- This function is a cancellation point and therefore not marked with -- __THROW. function preadv (uu_fd : int; uu_iovec : access constant bits_types_struct_iovec_h.iovec; uu_count : int; uu_offset : bits_types_h.uu_off_t) return sys_types_h.ssize_t -- /usr/include/sys/uio.h:67 with Import => True, Convention => C, External_Name => "preadv"; -- Write data pointed by the buffers described by IOVEC, which is a -- vector of COUNT 'struct iovec's, to file descriptor FD at the given -- position OFFSET without change the file pointer. The data is -- written in the order specified. Operates just like 'pwrite' (see -- <unistd.h>) except that the data are taken from IOVEC instead of a -- contiguous buffer. -- This function is a cancellation point and therefore not marked with -- __THROW. function pwritev (uu_fd : int; uu_iovec : access constant bits_types_struct_iovec_h.iovec; uu_count : int; uu_offset : bits_types_h.uu_off_t) return sys_types_h.ssize_t -- /usr/include/sys/uio.h:79 with Import => True, Convention => C, External_Name => "pwritev"; -- Read data from file descriptor FD at the given position OFFSET -- without change the file pointer, and put the result in the buffers -- described by IOVEC, which is a vector of COUNT 'struct iovec's. -- The buffers are filled in the order specified. Operates just like -- 'pread' (see <unistd.h>) except that data are put in IOVEC instead -- of a contiguous buffer. -- This function is a cancellation point and therefore not marked with -- __THROW. function preadv64 (uu_fd : int; uu_iovec : access constant bits_types_struct_iovec_h.iovec; uu_count : int; uu_offset : bits_types_h.uu_off64_t) return sys_types_h.ssize_t -- /usr/include/sys/uio.h:106 with Import => True, Convention => C, External_Name => "preadv64"; -- Write data pointed by the buffers described by IOVEC, which is a -- vector of COUNT 'struct iovec's, to file descriptor FD at the given -- position OFFSET without change the file pointer. The data is -- written in the order specified. Operates just like 'pwrite' (see -- <unistd.h>) except that the data are taken from IOVEC instead of a -- contiguous buffer. -- This function is a cancellation point and therefore not marked with -- __THROW. function pwritev64 (uu_fd : int; uu_iovec : access constant bits_types_struct_iovec_h.iovec; uu_count : int; uu_offset : bits_types_h.uu_off64_t) return sys_types_h.ssize_t -- /usr/include/sys/uio.h:118 with Import => True, Convention => C, External_Name => "pwritev64"; -- Same as preadv but with an additional flag argumenti defined at uio.h. function preadv2 (uu_fp : int; uu_iovec : access constant bits_types_struct_iovec_h.iovec; uu_count : int; uu_offset : bits_types_h.uu_off_t; uuu_flags : int) return sys_types_h.ssize_t -- /usr/include/sys/uio.h:127 with Import => True, Convention => C, External_Name => "preadv2"; -- Same as preadv but with an additional flag argument defined at uio.h. function pwritev2 (uu_fd : int; uu_iodev : access constant bits_types_struct_iovec_h.iovec; uu_count : int; uu_offset : bits_types_h.uu_off_t; uu_flags : int) return sys_types_h.ssize_t -- /usr/include/sys/uio.h:131 with Import => True, Convention => C, External_Name => "pwritev2"; -- Same as preadv but with an additional flag argumenti defined at uio.h. function preadv64v2 (uu_fp : int; uu_iovec : access constant bits_types_struct_iovec_h.iovec; uu_count : int; uu_offset : bits_types_h.uu_off64_t; uuu_flags : int) return sys_types_h.ssize_t -- /usr/include/sys/uio.h:152 with Import => True, Convention => C, External_Name => "preadv64v2"; -- Same as preadv but with an additional flag argument defined at uio.h. function pwritev64v2 (uu_fd : int; uu_iodev : access constant bits_types_struct_iovec_h.iovec; uu_count : int; uu_offset : bits_types_h.uu_off64_t; uu_flags : int) return sys_types_h.ssize_t -- /usr/include/sys/uio.h:157 with Import => True, Convention => C, External_Name => "pwritev64v2"; -- Some operating systems provide system-specific extensions to this -- header. end sys_uio_h;
------------------------------------------------------------------------------ -- -- -- ASIS-for-GNAT IMPLEMENTATION COMPONENTS -- -- -- -- A 4 G . D E C L _ S E M -- -- -- -- B o d y -- -- -- -- Copyright (C) 1995-2012, Free Software Foundation, Inc. -- -- -- -- ASIS-for-GNAT is free software; you can redistribute it and/or modify it -- -- under terms of the GNU General Public License as published by the Free -- -- Software Foundation; either version 2, or (at your option) any later -- -- version. ASIS-for-GNAT is distributed in the hope that it will be use- -- -- ful, but WITHOUT ANY WARRANTY; without even the implied warranty of MER- -- -- CHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General -- -- Public License for more details. You should have received a copy of the -- -- GNU General Public License distributed with ASIS-for-GNAT; see file -- -- COPYING. If not, write to the Free Software Foundation, 51 Franklin -- -- Street, Fifth Floor, Boston, MA 02110-1301, USA. -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- ASIS-for-GNAT was originally developed by the ASIS-for-GNAT team at the -- -- Software Engineering Laboratory of the Swiss Federal Institute of -- -- Technology (LGL-EPFL) in Lausanne, Switzerland, in cooperation with the -- -- Scientific Research Computer Center of Moscow State University (SRCC -- -- MSU), Russia, with funding partially provided by grants from the Swiss -- -- National Science Foundation and the Swiss Academy of Engineering -- -- Sciences. ASIS-for-GNAT is now maintained by AdaCore -- -- (http://www.adacore.com). -- -- -- ------------------------------------------------------------------------------ -- This package contains routines needed for semantic queries from -- the Asis.Declarations package with Asis.Declarations; use Asis.Declarations; with Asis.Definitions; use Asis.Definitions; with Asis.Iterator; use Asis.Iterator; with Asis.Elements; use Asis.Elements; with Asis.Errors; use Asis.Errors; with Asis.Exceptions; use Asis.Exceptions; with Asis.Extensions; use Asis.Extensions; with Asis.Set_Get; use Asis.Set_Get; with A4G.A_Sem; use A4G.A_Sem; with A4G.Int_Knds; use A4G.Int_Knds; with A4G.Vcheck; use A4G.Vcheck; with A4G.Mapping; use A4G.Mapping; with Atree; use Atree; with Einfo; use Einfo; with Namet; use Namet; with Nlists; use Nlists; with Sinfo; use Sinfo; with Sinput; use Sinput; package body A4G.Decl_Sem is ----------------------------- -- Corresponding_Body_Node -- ----------------------------- function Corresponding_Body_Node (Decl_Node : Node_Id) return Node_Id is Result_Node : Node_Id; begin Result_Node := Corresponding_Body (Decl_Node); if No (Result_Node) then -- package without a body return Result_Node; end if; Result_Node := Parent (Result_Node); if Nkind (Result_Node) = N_Defining_Program_Unit_Name then Result_Node := Parent (Result_Node); end if; if Nkind (Result_Node) = N_Function_Specification or else Nkind (Result_Node) = N_Procedure_Specification then Result_Node := Parent (Result_Node); end if; if Nkind (Parent (Result_Node)) = N_Subunit then -- we come back to the stub! Result_Node := Corresponding_Stub (Parent (Result_Node)); end if; if not Comes_From_Source (Result_Node) and then not (Is_Rewrite_Substitution (Result_Node) -- SCz -- and then -- Nkind (Original_Node (Result_Node)) = N_Expression_Function) ) then -- implicit body created by the compiler for renaming-as-body. -- the renaming itself is the previous list member, so Result_Node := Get_Renaming_As_Body (Decl_Node); end if; return Result_Node; end Corresponding_Body_Node; ----------------------------- -- Corresponding_Decl_Node -- ----------------------------- function Corresponding_Decl_Node (Body_Node : Node_Id) return Node_Id is Result_Node : Node_Id := Empty; Protected_Def_Node : Node_Id; Tmp_Node : Node_Id := Empty; begin case Nkind (Body_Node) is when N_Body_Stub => Result_Node := Corr_Decl_For_Stub (Body_Node); when N_Entry_Body => Protected_Def_Node := Corresponding_Spec (Parent (Body_Node)); if Ekind (Protected_Def_Node) = E_Limited_Private_Type then Protected_Def_Node := Full_View (Protected_Def_Node); end if; Protected_Def_Node := Parent (Protected_Def_Node); Protected_Def_Node := Protected_Definition (Protected_Def_Node); Tmp_Node := First_Non_Pragma (Visible_Declarations (Protected_Def_Node)); while Present (Tmp_Node) loop if Nkind (Tmp_Node) = N_Entry_Declaration and then Parent (Corresponding_Body (Tmp_Node)) = Body_Node then Result_Node := Tmp_Node; exit; end if; Tmp_Node := Next_Non_Pragma (Tmp_Node); end loop; if No (Result_Node) and then Present (Private_Declarations (Protected_Def_Node)) then Tmp_Node := First_Non_Pragma (Private_Declarations (Protected_Def_Node)); while Present (Tmp_Node) loop if Nkind (Tmp_Node) = N_Entry_Declaration and then Parent (Corresponding_Body (Tmp_Node)) = Body_Node then Result_Node := Tmp_Node; exit; end if; Tmp_Node := Next_Non_Pragma (Tmp_Node); end loop; end if; when others => Result_Node := Corresponding_Spec (Body_Node); Result_Node := Parent (Result_Node); if Nkind (Result_Node) = N_Defining_Program_Unit_Name then Result_Node := Parent (Result_Node); end if; end case; pragma Assert (Present (Result_Node)); -- now - from a defining entity to the declaration itself; note, -- that here we cannot get a defining expanded name, because the -- corresponding declaration for library units are obtained in -- another control flow case Nkind (Result_Node) is when N_Function_Specification | N_Procedure_Specification | N_Package_Specification => Result_Node := Parent (Result_Node); when N_Private_Type_Declaration => -- this is the case when a task type is the completion -- of a private type Result_Node := Full_View (Defining_Identifier (Result_Node)); Result_Node := Parent (Result_Node); when others => null; end case; return Result_Node; end Corresponding_Decl_Node; --------------------------------------- -- Get_Corresponding_Generic_Element -- --------------------------------------- function Get_Corresponding_Generic_Element (Gen_Unit : Asis.Declaration; Def_Name : Asis.Element) return Asis.Element is Kind_To_Check : constant Internal_Element_Kinds := Int_Kind (Def_Name); Sloc_To_Check : constant Source_Ptr := Sloc (Node (Def_Name)); Line_To_Check : constant Physical_Line_Number := Get_Physical_Line_Number (Sloc_To_Check); Column_To_Check : constant Column_Number := Get_Column_Number (Sloc_To_Check); Result_Element : Asis.Element := Nil_Element; Tmp_El : Asis.Element; Check_Inherited_Element : constant Boolean := Is_Part_Of_Inherited (Def_Name); Sloc_To_Check_1 : constant Source_Ptr := Sloc (Node_Field_1 (Def_Name)); Line_To_Check_1 : constant Physical_Line_Number := Get_Physical_Line_Number (Sloc_To_Check_1); Column_To_Check_1 : constant Column_Number := Get_Column_Number (Sloc_To_Check_1); -- Used in case if we are looking for an implicit Element function Is_Found (E : Asis.Element) return Boolean; -- Checks if the Element being traversed is a corresponding generic -- element for Def_Name function Is_Found (E : Asis.Element) return Boolean is Elem_Sloc : constant Source_Ptr := Sloc (Node (E)); Elem_Sloc_1 : Source_Ptr; Result : Boolean := False; begin if not (Check_Inherited_Element xor Is_Part_Of_Inherited (E)) then Result := Line_To_Check = Get_Physical_Line_Number (Elem_Sloc) and then Column_To_Check = Get_Column_Number (Elem_Sloc); if Result and then Check_Inherited_Element then Elem_Sloc_1 := Sloc (Node_Field_1 (E)); Result := Line_To_Check_1 = Get_Physical_Line_Number (Elem_Sloc_1) and then Column_To_Check_1 = Get_Column_Number (Elem_Sloc_1); end if; end if; return Result; end Is_Found; -- and now, variables and actuals for Traverse_Element My_Control : Traverse_Control := Continue; My_State : No_State := Not_Used; procedure Pre_Op (Element : Asis.Element; Control : in out Traverse_Control; State : in out No_State); procedure Look_For_Corr_Gen_El is new Traverse_Element (State_Information => No_State, Pre_Operation => Pre_Op, Post_Operation => No_Op); procedure Pre_Op (Element : Asis.Element; Control : in out Traverse_Control; State : in out No_State) is pragma Unreferenced (State); Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Element); begin case Arg_Kind is when An_Internal_Body_Stub => if Kind_To_Check = A_Defining_Identifier or else Kind_To_Check in Internal_Defining_Operator_Kinds then -- We have to traverse the code of the subunit - -- see 9217-015. But before doing this, let's check the -- name of the subunit: Tmp_El := Asis.Declarations.Names (Element) (1); if Int_Kind (Tmp_El) = Kind_To_Check and then Is_Found (Tmp_El) then Result_Element := Tmp_El; Control := Terminate_Immediately; return; end if; end if; -- If we are here, we have to traverse the proper body: Tmp_El := Corresponding_Subunit (Element); if not Is_Nil (Tmp_El) then Look_For_Corr_Gen_El (Element => Tmp_El, Control => My_Control, State => My_State); end if; when Internal_Defining_Name_Kinds => if Int_Kind (Element) = Kind_To_Check and then Is_Found (Element) then Result_Element := Element; Control := Terminate_Immediately; end if; when A_Derived_Type_Definition | A_Derived_Record_Extension_Definition | A_Formal_Derived_Type_Definition => if Check_Inherited_Element then declare Inherited_Decls : constant Asis.Element_List := Implicit_Inherited_Declarations (Element); Inherited_Subprgs : constant Asis.Element_List := Implicit_Inherited_Subprograms (Element); begin for J in Inherited_Decls'Range loop exit when My_Control = Terminate_Immediately; Look_For_Corr_Gen_El (Element => Inherited_Decls (J), Control => My_Control, State => My_State); end loop; for J in Inherited_Subprgs'Range loop exit when My_Control = Terminate_Immediately; Look_For_Corr_Gen_El (Element => Inherited_Subprgs (J), Control => My_Control, State => My_State); end loop; end; end if; when others => null; end case; end Pre_Op; begin -- Get_Corresponding_Generic_Element Look_For_Corr_Gen_El (Element => Gen_Unit, Control => My_Control, State => My_State); return Result_Element; exception when ASIS_Failed => if Status_Indicator = Unhandled_Exception_Error then Add_Call_Information (Argument => Nil_Element, Outer_Call => "A4G.Decl_Sem.Get_Corresponding_Generic_Element"); end if; raise; end Get_Corresponding_Generic_Element; ----------------------- -- Get_Expanded_Spec -- ----------------------- function Get_Expanded_Spec (Instance_Node : Node_Id) return Node_Id is Result_Node : Node_Id; begin -- GNAT constructs the structure corresponding to an expanded generic -- specification just before the instantiation itself, except the case -- of the formal package with box: if Nkind (Instance_Node) = N_Package_Declaration and then Nkind (Original_Node (Instance_Node)) = N_Formal_Package_Declaration then Result_Node := Instance_Node; else Result_Node := Prev_Non_Pragma (Instance_Node); end if; if Nkind (Result_Node) = N_Package_Body then -- Here we have the expanded generic body, therefore - one -- more step up the list Result_Node := Prev_Non_Pragma (Result_Node); end if; -- in case of a package instantiation, we have to take the whole -- expanded package, but in case of a subprogram instantiation we -- need only the subprogram declaration, which is the last element -- of the visible declarations list of the "artificial" package -- spec created by the compiler if not (Nkind (Instance_Node) = N_Package_Instantiation or else Nkind (Original_Node (Instance_Node)) = N_Formal_Package_Declaration) then Result_Node := Last_Non_Pragma (Visible_Declarations (Specification (Result_Node))); if Nkind (Result_Node) = N_Subprogram_Body then Result_Node := Parent (Parent (Corresponding_Spec (Result_Node))); end if; pragma Assert (Nkind (Result_Node) = N_Subprogram_Declaration); end if; return Result_Node; end Get_Expanded_Spec; -------------------------- -- Get_Renaming_As_Body -- -------------------------- function Get_Renaming_As_Body (Node : Node_Id; Spec_Only : Boolean := False) return Node_Id is Entity_Node : Node_Id; Scope_Node : Node_Id; Result_Node : Node_Id := Empty; List_To_Search : List_Id; Search_Node : Node_Id := Node; -- in the first List_To_Search we start not from the very beginning; -- but from the node representing the argument subprogram declaration Completion_Found : Boolean := False; procedure Search_In_List; -- looks for a possible renaming-as-bode node being a completion for -- Node, using global settings for List_To_Search and Search_Node procedure Search_In_List is begin while Present (Search_Node) loop if Nkind (Search_Node) = N_Subprogram_Renaming_Declaration and then Corresponding_Spec (Search_Node) = Entity_Node then Result_Node := Search_Node; Completion_Found := True; return; end if; Search_Node := Next_Non_Pragma (Search_Node); end loop; end Search_In_List; begin -- Get_Renaming_As_Body Entity_Node := Defining_Unit_Name (Specification (Node)); List_To_Search := List_Containing (Node); Search_In_List; if Completion_Found then goto end_of_search; end if; -- here we have to see, where we are. If we are not in a package, -- we have nothing to do, but if we are in the package, we may -- have to search again in another lists (the private part and -- the body) Scope_Node := Scope (Entity_Node); -- Node here can be of N_Subprogram_Declaration only! if Nkind (Parent (Scope_Node)) = N_Implicit_Label_Declaration then -- this is the implicit name created for a block statement, -- so we do not have any other list to search in goto end_of_search; else Scope_Node := Parent (Scope_Node); end if; if Nkind (Scope_Node) = N_Defining_Program_Unit_Name then Scope_Node := Parent (Scope_Node); end if; -- now if we are not in N_Package_Specification, we have no -- other list to search in if Nkind (Scope_Node) /= N_Package_Specification then goto end_of_search; end if; -- and here we are in N_Package_Specification if List_To_Search = Visible_Declarations (Scope_Node) then -- continuing in the private part: List_To_Search := Private_Declarations (Scope_Node); if not (No (List_To_Search) or else Is_Empty_List (List_To_Search)) then Search_Node := First_Non_Pragma (List_To_Search); Search_In_List; end if; if Completion_Found or else Spec_Only then goto end_of_search; end if; end if; -- and here we have to go into the package body, if any: Scope_Node := Corresponding_Body (Parent (Scope_Node)); if Present (Scope_Node) then while Nkind (Scope_Node) /= N_Package_Body loop Scope_Node := Parent (Scope_Node); end loop; -- and to continue to search in the package body: List_To_Search := Sinfo.Declarations (Scope_Node); if not (No (List_To_Search) or else Is_Empty_List (List_To_Search)) then Search_Node := First_Non_Pragma (List_To_Search); Search_In_List; end if; end if; << end_of_search >> return Result_Node; end Get_Renaming_As_Body; ----------------------- -- Serach_First_View -- ----------------------- function Serach_First_View (Type_Entity : Entity_Id) return Entity_Id is Type_Chars : constant Name_Id := Chars (Type_Entity); Type_Decl : constant Node_Id := Parent (Type_Entity); Result_Node : Node_Id := Empty; Scope_Node : Node_Id; Scope_Kind : Node_Kind; Search_List : List_Id; Private_Decls_Passed : Boolean := False; procedure Sesrch_In_List (L : List_Id); -- we have a separate procedure for searching in a list of -- declarations, because we have to do this search from one to -- three times in case of a package. This procedure uses Type_Chars, -- Type_Decl and Result_Node as global values, and it sets -- Result_Node equal to the node defining the type with the same name -- as the name of the type represented by Type_Entity, if the -- search is successful, otherwise it remains is equal to Empty. -- this procedure supposes, that L is not No_List procedure Sesrch_In_List (L : List_Id) is Next_Decl : Node_Id; Next_Decl_Original : Node_Id; Next_Kind : Node_Kind; begin Next_Decl := First_Non_Pragma (L); Next_Decl_Original := Original_Node (Next_Decl); Next_Kind := Nkind (Next_Decl_Original); while Present (Next_Decl) loop if (Comes_From_Source (Next_Decl_Original) and then (Next_Kind = N_Full_Type_Declaration or else Next_Kind = N_Task_Type_Declaration or else Next_Kind = N_Protected_Type_Declaration or else Next_Kind = N_Private_Type_Declaration or else Next_Kind = N_Private_Extension_Declaration or else Next_Kind = N_Formal_Type_Declaration or else -- impossible in ASIS, but possible in the tree -- because of the tree rewritings Next_Kind = N_Incomplete_Type_Declaration)) -- these cases correspond to non-rewritten type -- declarations or else (not (Comes_From_Source (Next_Decl_Original)) and then Next_Kind = N_Subtype_Declaration) -- the declaration of a derived type rewritten into a -- subtype declaration then if Is_Not_Duplicated_Decl (Next_Decl) then -- ??? <tree problem 2> - we need this "if" only because of this problem if Next_Decl_Original = Type_Decl then -- no private or incomplete view Result_Node := Type_Entity; return; end if; if Type_Chars = Chars (Defining_Identifier (Next_Decl)) then -- we've found something... Result_Node := Defining_Identifier (Next_Decl); return; end if; end if; end if; Next_Decl := Next_Non_Pragma (Next_Decl); Next_Decl_Original := Original_Node (Next_Decl); Next_Kind := Nkind (Next_Decl_Original); end loop; end Sesrch_In_List; begin -- Serach_First_View -- first, defining the scope of the Type_Entity. In case of a package -- body it will be a package spec anyway. Scope_Node := Scope (Type_Entity); if Nkind (Parent (Scope_Node)) = N_Implicit_Label_Declaration then -- this is the implicit name created for a block statement Scope_Node := Parent (Block_Node (Scope_Node)); else Scope_Node := Parent (Scope_Node); end if; if Nkind (Scope_Node) = N_Defining_Program_Unit_Name then Scope_Node := Parent (Scope_Node); end if; -- now we are in N_Function_Specification, N_Procedure_Specification -- or in N_Package_Specification Scope_Kind := Nkind (Scope_Node); if Scope_Kind = N_Function_Specification or else Scope_Kind = N_Procedure_Specification then -- we do not do this additional step for packages, because -- N_Package_Specification_Node already contains references to -- declaration lists, and for a package we gave to start from the -- declarations in the package spec, but for a subprogram -- we have to go to a subprogram body, because nothing interesting -- for this function can be declared in a separate subprogram -- specification (if any) or in a generic formal part (if any) Scope_Node := Parent (Scope_Node); Scope_Kind := Nkind (Scope_Node); end if; if Scope_Kind = N_Subprogram_Declaration or else Scope_Kind = N_Generic_Subprogram_Declaration or else Scope_Kind = N_Task_Type_Declaration or else Scope_Kind = N_Entry_Declaration or else Scope_Kind = N_Subprogram_Body_Stub then Scope_Node := Corresponding_Body (Scope_Node); Scope_Node := Parent (Scope_Node); if Nkind (Scope_Node) = N_Defining_Program_Unit_Name then Scope_Node := Parent (Scope_Node); end if; if Nkind (Scope_Node) = N_Function_Specification or else Nkind (Scope_Node) = N_Procedure_Specification then Scope_Node := Parent (Scope_Node); end if; Scope_Kind := Nkind (Scope_Node); end if; -- now, defining the list to search. In case of generics, we do not -- have to start from parsing the list of generic parameters, because -- a generic formal type cannot have a completion as its full view, -- and it cannot be a completion of some other type. if Scope_Kind = N_Subprogram_Body or else Scope_Kind = N_Task_Body or else Scope_Kind = N_Block_Statement or else Scope_Kind = N_Entry_Body then Search_List := Sinfo.Declarations (Scope_Node); elsif Scope_Kind = N_Package_Specification then Search_List := Visible_Declarations (Scope_Node); if Is_Empty_List (Search_List) then -- note, that Visible_Declarations cannot be No_List Private_Decls_Passed := True; Search_List := Private_Declarations (Scope_Node); if No (Search_List) or else Is_Empty_List (Search_List) then -- here we should go to the declarative part of the package -- body. Note, that if we are in a legal ada program, and if -- we start from a type declaration, Search_List cannot -- be No_List or an empty list Scope_Node := Parent (Corresponding_Body (Parent (Scope_Node))); -- note, that Search_Kind is unchanged here Search_List := Sinfo.Declarations (Scope_Node); end if; end if; end if; Sesrch_In_List (Search_List); if Result_Node /= Empty then if Result_Node /= Type_Entity and then Full_View (Result_Node) /= Type_Entity then -- The case when Type_Entity is a full type declaration that -- completes a private type/extension declaration that in turn -- completes an incomplete type. Result_Node := Full_View (Result_Node); end if; return Result_Node; end if; -- it is possible only for a package - we have to continue in the -- private part or/and in the body pragma Assert (Scope_Kind = N_Package_Specification); -- first, try a private part, if needed and if any if not Private_Decls_Passed then -- Scope_Node is still of N_Package_Specification kind here! Private_Decls_Passed := True; Search_List := Private_Declarations (Scope_Node); if Present (Search_List) and then Is_Non_Empty_List (Search_List) then Sesrch_In_List (Search_List); if Result_Node /= Empty then return Result_Node; end if; end if; end if; -- if we are here, Scope_Node is still of N_Package_Specification, -- and the only thing we have to do now is to check the package -- body -- There is some redundancy in the code - in fact, we need only -- one boolean flag (Private_Decls_Passed) to control the search in -- case of a package Scope_Node := Parent (Corresponding_Body (Parent (Scope_Node))); if Nkind (Scope_Node) = N_Defining_Program_Unit_Name then Scope_Node := Parent (Scope_Node); end if; Search_List := Sinfo.Declarations (Scope_Node); Sesrch_In_List (Search_List); if Result_Node /= Empty then return Result_Node; else pragma Assert (False); return Empty; end if; end Serach_First_View; end A4G.Decl_Sem;
with Report; use Report; procedure Template is begin -- Test header Test ("TEMPLATE", "Template test for GNU Ada test suite"); begin -- Body of test -- Call procedure Failed when detecting a failure Failed ("Pretend this test failed"); end; -- Display result Result; end Template;
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- Ada Modeling Framework -- -- -- -- Runtime Library Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2011, Vadim Godunko <vgodunko@gmail.com> -- -- All rights reserved. -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions -- -- are met: -- -- -- -- * Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- -- -- * Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in the -- -- documentation and/or other materials provided with the distribution. -- -- -- -- * Neither the name of the Vadim Godunko, IE nor the names of its -- -- contributors may be used to endorse or promote products derived from -- -- this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -- -- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED -- -- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -- -- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -- -- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -- -- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -- -- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- -- ------------------------------------------------------------------------------ -- $Revision$ $Date$ ------------------------------------------------------------------------------ -- This file is generated, don't edit it. ------------------------------------------------------------------------------ -- A classifier is a classification of instances - it describes a set of -- instances that have features in common. A classifier can specify a -- generalization hierarchy by referencing its general classifiers. ------------------------------------------------------------------------------ limited with AMF.CMOF.Classifiers.Collections; limited with AMF.CMOF.Features.Collections; limited with AMF.CMOF.Named_Elements.Collections; with AMF.CMOF.Namespaces; limited with AMF.CMOF.Properties.Collections; with AMF.CMOF.Types; package AMF.CMOF.Classifiers is pragma Preelaborate; type CMOF_Classifier is limited interface and AMF.CMOF.Namespaces.CMOF_Namespace and AMF.CMOF.Types.CMOF_Type; type CMOF_Classifier_Access is access all CMOF_Classifier'Class; for CMOF_Classifier_Access'Storage_Size use 0; not overriding function Get_Attribute (Self : not null access constant CMOF_Classifier) return AMF.CMOF.Properties.Collections.Set_Of_CMOF_Property is abstract; -- Getter of Classifier::attribute. -- -- Refers to all of the Properties that are direct (i.e. not inherited or -- imported) attributes of the classifier. not overriding function Get_Feature (Self : not null access constant CMOF_Classifier) return AMF.CMOF.Features.Collections.Set_Of_CMOF_Feature is abstract; -- Getter of Classifier::feature. -- -- Note that there may be members of the Classifier that are of the type -- Feature but are not included in this association, e.g. inherited -- features. not overriding function Get_General (Self : not null access constant CMOF_Classifier) return AMF.CMOF.Classifiers.Collections.Set_Of_CMOF_Classifier is abstract; -- Getter of Classifier::general. -- -- References the general classifier in the Generalization relationship. not overriding function Get_Inherited_Member (Self : not null access constant CMOF_Classifier) return AMF.CMOF.Named_Elements.Collections.Set_Of_CMOF_Named_Element is abstract; -- Getter of Classifier::inheritedMember. -- -- Specifies all elements inherited by this classifier from the general -- classifiers. not overriding function Get_Is_Final_Specialization (Self : not null access constant CMOF_Classifier) return Boolean is abstract; -- Getter of Classifier::isFinalSpecialization. -- -- If true, the Classifier cannot be specialized by generalization. Note -- that this property is preserved through package merge operations; that -- is, the capability to specialize a Classifier (i.e., -- isFinalSpecialization =false) must be preserved in the resulting -- Classifier of a package merge operation where a Classifier with -- isFinalSpecialization =false is merged with a matching Classifier with -- isFinalSpecialization =true: the resulting Classifier will have -- isFinalSpecialization =false. not overriding procedure Set_Is_Final_Specialization (Self : not null access CMOF_Classifier; To : Boolean) is abstract; -- Setter of Classifier::isFinalSpecialization. -- -- If true, the Classifier cannot be specialized by generalization. Note -- that this property is preserved through package merge operations; that -- is, the capability to specialize a Classifier (i.e., -- isFinalSpecialization =false) must be preserved in the resulting -- Classifier of a package merge operation where a Classifier with -- isFinalSpecialization =false is merged with a matching Classifier with -- isFinalSpecialization =true: the resulting Classifier will have -- isFinalSpecialization =false. not overriding function Conforms_To (Self : not null access constant CMOF_Classifier; Other : AMF.CMOF.Classifiers.CMOF_Classifier_Access) return Boolean is abstract; -- Operation Classifier::conformsTo. -- -- The query conformsTo() gives true for a classifier that defines a type -- that conforms to another. This is used, for example, in the -- specification of signature conformance for operations. not overriding function All_Features (Self : not null access constant CMOF_Classifier) return AMF.CMOF.Features.Collections.Set_Of_CMOF_Feature is abstract; -- Operation Classifier::allFeatures. -- -- The query allFeatures() gives all of the features in the namespace of -- the classifier. In general, through mechanisms such as inheritance, -- this will be a larger set than feature. not overriding function General (Self : not null access constant CMOF_Classifier) return AMF.CMOF.Classifiers.Collections.Set_Of_CMOF_Classifier is abstract; -- Operation Classifier::general. -- -- The general classifiers are the classifiers referenced by the -- generalization relationships. not overriding function Parents (Self : not null access constant CMOF_Classifier) return AMF.CMOF.Classifiers.Collections.Set_Of_CMOF_Classifier is abstract; -- Operation Classifier::parents. -- -- The query parents() gives all of the immediate ancestors of a -- generalized Classifier. not overriding function Inherited_Member (Self : not null access constant CMOF_Classifier) return AMF.CMOF.Named_Elements.Collections.Set_Of_CMOF_Named_Element is abstract; -- Operation Classifier::inheritedMember. -- -- The inheritedMember association is derived by inheriting the -- inheritable members of the parents. not overriding function All_Parents (Self : not null access constant CMOF_Classifier) return AMF.CMOF.Classifiers.Collections.Set_Of_CMOF_Classifier is abstract; -- Operation Classifier::allParents. -- -- The query allParents() gives all of the direct and indirect ancestors -- of a generalized Classifier. not overriding function Inheritable_Members (Self : not null access constant CMOF_Classifier; C : AMF.CMOF.Classifiers.CMOF_Classifier_Access) return AMF.CMOF.Named_Elements.Collections.Set_Of_CMOF_Named_Element is abstract; -- Operation Classifier::inheritableMembers. -- -- The query inheritableMembers() gives all of the members of a classifier -- that may be inherited in one of its descendants, subject to whatever -- visibility restrictions apply. not overriding function Has_Visibility_Of (Self : not null access constant CMOF_Classifier; N : AMF.CMOF.Named_Elements.CMOF_Named_Element_Access) return Boolean is abstract; -- Operation Classifier::hasVisibilityOf. -- -- The query hasVisibilityOf() determines whether a named element is -- visible in the classifier. By default all are visible. It is only -- called when the argument is something owned by a parent. not overriding function Inherit (Self : not null access constant CMOF_Classifier; Inhs : AMF.CMOF.Named_Elements.Collections.Set_Of_CMOF_Named_Element) return AMF.CMOF.Named_Elements.Collections.Set_Of_CMOF_Named_Element is abstract; -- Operation Classifier::inherit. -- -- The inherit operation is overridden to exclude redefined properties. not overriding function May_Specialize_Type (Self : not null access constant CMOF_Classifier; C : AMF.CMOF.Classifiers.CMOF_Classifier_Access) return Boolean is abstract; -- Operation Classifier::maySpecializeType. -- -- The query maySpecializeType() determines whether this classifier may -- have a generalization relationship to classifiers of the specified -- type. By default a classifier may specialize classifiers of the same or -- a more general type. It is intended to be redefined by classifiers that -- have different specialization constraints. end AMF.CMOF.Classifiers;
package Kafka.Topic.Config is -- -- Creates a new kafka topic config object -- -- librdkafka equivalent: rd_kafka_topic_conf_new -- function Create return Topic_Config_Type with Import => True, Convention => C, External_Name => "rd_kafka_topic_conf_new"; -- -- Destroys a kafka topic config object -- -- librdkafka equivalent: rd_kafka_topic_conf_destroy -- -- @param Config configuration to destroy -- procedure Destroy(Config : Topic_Config_Type) with Import => True, Convention => C, External_Name => "rd_kafka_topic_conf_destroy"; -- -- Duplicates a kafka topic config object -- -- librdkafka equivalent: rd_kafka_topic_conf_dup -- -- @param Config configuration to duplicate -- function Duplicate(Config : Topic_Config_Type) return Topic_Config_Type with Import => True, Convention => C, External_Name => "rd_kafka_topic_conf_dup"; -- -- Sets a kafka topic config property for a given kafka topic config. -- -- librdkafka equivalent: rd_kafka_topic_conf_set -- -- @param Config configuration to set the property in -- @param Name name of property to set -- @param Value value of property to set -- @raises Kafka_Error on error -- procedure Set(Config : Topic_Config_Type; Name : String; Value : String); private function rd_kafka_topic_conf_set(conf : Topic_Config_Type; name : chars_ptr; value : chars_ptr; errstr : chars_ptr; errstr_size : size_t) return Integer with Import => True, Convention => C, External_Name => "rd_kafka_topic_conf_set"; end Kafka.Topic.Config;
with Smallest_Factor; use Smallest_Factor; with Ada.Text_IO; use Ada.Text_IO; procedure Main is N : Integer := 15; Factor : Integer; begin SmallestF (N, Factor); Put_Line ("N: " & N'Image); Put_Line ("Factor: " & Factor'Image); end Main;
-- Abstract : -- -- See spec. -- -- Copyright (C) 2018 All Rights Reserved. -- -- This program is free software; you can redistribute it and/or -- modify it under terms of the GNU General Public License as -- published by the Free Software Foundation; either version 3, or (at -- your option) any later version. This program is distributed in the -- hope that it will be useful, but WITHOUT ANY WARRANTY; without even -- the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -- PURPOSE. See the GNU General Public License for more details. You -- should have received a copy of the GNU General Public License -- distributed with this program; see file COPYING. If not, write to -- the Free Software Foundation, 51 Franklin Street, Suite 500, Boston, -- MA 02110-1335, USA. pragma License (GPL); with Ada.Command_Line; with Ada.Exceptions; with Ada.Strings.Fixed; with Ada.Strings.Unbounded; with Ada.Text_IO; use Ada.Text_IO; with Emacs_Wisi_Common_Parse; use Emacs_Wisi_Common_Parse; with GNAT.OS_Lib; with GNAT.Traceback.Symbolic; with System.Storage_Elements; with WisiToken.Lexer; with WisiToken.Parse.Packrat; with WisiToken.Text_IO_Trace; procedure Gen_Emacs_Wisi_Parse_Packrat is use WisiToken; -- "+", "-" Unbounded_string Trace : aliased WisiToken.Text_IO_Trace.Trace (Descriptor'Access); Parser : WisiToken.Parse.Packrat.Parser; Parse_Data : aliased Parse_Data_Type (Parser.Line_Begin_Token'Access); begin Create_Parser (Parser, Trace'Unrestricted_Access, Parse_Data'Unchecked_Access); declare use Ada.Command_Line; begin case Argument_Count is when 0 => null; when others => Usage (Name); raise Programmer_Error with "invalid option count: " & Integer'Image (Argument_Count); end case; end; Put_Line (Name & " " & Version & ", protocol version " & Protocol_Version); -- Read commands and tokens from standard_input via GNAT.OS_Lib, -- send results to standard_output. loop Put (Prompt); Flush; declare Command_Length : constant Integer := Get_Command_Length; Command_Line : aliased String (1 .. Command_Length); Last : Integer; function Match (Target : in String) return Boolean is begin Last := Command_Line'First + Target'Length - 1; return Last <= Command_Line'Last and then Command_Line (Command_Line'First .. Last) = Target; end Match; begin Read_Input (Command_Line'Address, Command_Length); Put_Line (";; " & Command_Line); if Match ("parse") then -- Args: see Usage -- Input: <source text> -- Response: -- [response elisp vector]... -- [elisp error form]... -- prompt declare use Wisi; Cl_Params : constant Command_Line_Params := Get_Cl_Params (Command_Line, Last); Buffer : Ada.Strings.Unbounded.String_Access; procedure Clean_Up is begin Parser.Lexer.Discard_Rest_Of_Input; Parser.Put_Errors (-Cl_Param.Source_File_Name); Ada.Strings.Unbounded.Free (Buffer); end Clean_Up; begin -- Computing Line_Count in elisp allows parsing in parallel with -- sending source text. Trace_Parse := Cl_Params.Parse_Verbosity; Trace_McKenzie := Cl_Params.McKenzie_Verbosity; Trace_Action := Cl_Params.Action_Verbosity; Debug_Mode := Cl_Params.Debug_Mode; Parse_Data.Initialize (Post_Parse_Action => Cl_Params.Post_Parse_Action, Descriptor => Descriptor'Access, Source_File_Name => -Cl_Params.Source_File_Name, Line_Count => Cl_Params.Line_Count, Params => Command_Line (Last + 2 .. Command_Line'Last)); Buffer := new String (1 .. Cl_Params.Byte_Count); Read_Input (Buffer (1)'Address, Cl_Params.Byte_Count); Parser.Lexer.Reset_With_String_Access (Buffer); Parser.Parse; Parser.Execute_Actions; Put (Parse_Data); Clean_Up; exception when Syntax_Error => Clean_Up; Put_Line ("(parse_error)"); when E : Parse_Error => Clean_Up; Put_Line ("(parse_error """ & Ada.Exceptions.Exception_Message (E) & """)"); when E : Fatal_Error => Clean_Up; Put_Line ("(error """ & Ada.Exceptions.Exception_Message (E) & """)"); end; elsif Match ("noop") then -- Args: <source byte count> -- Input: <source text> -- Response: prompt declare Byte_Count : constant Integer := Get_Integer (Command_Line, Last); Buffer : constant Ada.Strings.Unbounded.String_Access := new String (1 .. Byte_Count); Token : Base_Token; Lexer_Error : Boolean; pragma Unreferenced (Lexer_Error); begin Token.ID := Invalid_Token_ID; Read_Input (Buffer (1)'Address, Byte_Count); Parser.Lexer.Reset_With_String_Access (Buffer); loop exit when Token.ID = Parser.Trace.Descriptor.EOF_ID; Lexer_Error := Parser.Lexer.Find_Next (Token); end loop; exception when Syntax_Error => Parser.Lexer.Discard_Rest_Of_Input; end; elsif Match ("quit") then exit; else Put_Line ("(error ""bad command: '" & Command_Line & "'"")"); end if; exception when E : Protocol_Error => -- don't exit the loop; allow debugging bad elisp Put_Line ("(error ""protocol error "": " & Ada.Exceptions.Exception_Message (E) & """)"); end; end loop; exception when E : others => Ada.Command_Line.Set_Exit_Status (Ada.Command_Line.Failure); New_Line (2); Put_Line ("(error ""unhandled exception: " & Ada.Exceptions.Exception_Name (E) & ": " & Ada.Exceptions.Exception_Message (E) & """)"); Put_Line (GNAT.Traceback.Symbolic.Symbolic_Traceback (E)); end Gen_Emacs_Wisi_Parse_Packrat;
-------------------------------------------------------------------------------- -- -- -- Copyright (C) 2004, RISC OS Ada Library (RASCAL) developers. -- -- -- -- This 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. -- -- -- -- This library is distributed in the hope that it will be useful, -- -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -- -- Lesser General Public License for more details. -- -- -- -- You should have received a copy of the GNU Lesser General Public -- -- License along with this library; if not, write to the Free Software -- -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -- -- -- -------------------------------------------------------------------------------- -- $Author$ -- $Date$ -- $Revision$ with RASCAL.Memory; use RASCAL.Memory; with RASCAL.OS; use RASCAL.OS; with RASCAL.Utility; use RASCAL.Utility; with Kernel; use Kernel; with Interfaces.C; use Interfaces.C; with Reporter; package body RASCAL.ToolboxProgInfo is Toolbox_ObjectMiscOp : constant := 16#44EC6#; -- function Get_Window_ID (ProgInfo : Object_ID; Flags : in System.Unsigned_Types.Unsigned := 0) return Object_ID is Register : aliased Kernel.swi_regs; Error : oserror_access; begin Register.R(0) := int(Unsigned_to_Int(Flags)); Register.R(1) := int(ProgInfo); Register.R(2) := 0; Error := Kernel.swi(Toolbox_ObjectMiscOp,Register'Access,Register'Access); if Error /= null then pragma Debug(Reporter.Report("ToolboxProgInfo.Get_Window_ID: " & To_Ada(Error.ErrMess))); OS.Raise_Error(Error); end if; return Object_ID(Register.R(0)); end Get_Window_ID; -- function Get_URI (ProgInfo : Object_ID; Flags: in System.Unsigned_Types.Unsigned := 0) return string is Register : aliased Kernel.swi_regs; Error : oserror_access; Buffer_Size : integer; begin Register.R(0) := int(Unsigned_to_Int(Flags)); Register.R(1) := int(ProgInfo); Register.R(2) := 8; Register.R(3) := 0; Register.R(4) := 0; Error := Kernel.swi(Toolbox_ObjectMiscOp,Register'Access,Register'Access); if Error /= null then pragma Debug(Reporter.Report("ToolboxProgInfo.Get_URI: " & To_Ada(Error.ErrMess))); OS.Raise_Error(Error); end if; Buffer_Size := integer(Register.R(4)); declare Buffer : string(1..Buffer_Size); begin Register.R(0) := int(Unsigned_to_Int(Flags)); Register.R(1) := int(ProgInfo); Register.R(2) := 8; Register.R(3) := Adr_To_Int(Buffer'Address); Register.R(4) := int(Buffer_Size); Error := Kernel.swi(Toolbox_ObjectMiscOp,Register'Access,Register'Access); if Error /= null then pragma Debug(Reporter.Report("ToolboxProgInfo.Get_URI: " & To_Ada(Error.ErrMess))); OS.Raise_Error(Error); end if; return MemoryToString(Buffer'Address); end; end Get_URI; -- function Get_Title (ProgInfo : Object_ID; Flags : in System.Unsigned_Types.Unsigned := 0) return string is Register : aliased Kernel.swi_regs; Error : oserror_access; Buffer_Size : integer; begin Register.R(0) := int(Unsigned_to_Int(Flags)); Register.R(1) := int(ProgInfo); Register.R(2) := 6; Register.R(3) := 0; Register.R(4) := 0; Error := Kernel.swi(Toolbox_ObjectMiscOp,Register'Access,Register'Access); if Error /= null then pragma Debug(Reporter.Report("ToolboxProgInfo.Get_Title: " & To_Ada(Error.ErrMess))); OS.Raise_Error(Error); end if; Buffer_Size := integer(Register.R(4)); declare Buffer : string(1..Buffer_Size); begin Register.R(0) := 0; Register.R(1) := int(ProgInfo); Register.R(2) := 6; Register.R(3) := Adr_To_Int(Buffer'Address); Register.R(4) := int(Buffer_Size); Error := Kernel.swi(Toolbox_ObjectMiscOp,Register'Access,Register'Access); if Error /= null then pragma Debug(Reporter.Report("ToolboxProgInfo.Get_Title: " & To_Ada(Error.ErrMess))); OS.Raise_Error(Error); end if; return MemoryToString(Buffer'Address); end; end Get_Title; -- procedure Set_URI (ProgInfo : in Object_ID; URI : in string; Flags : in System.Unsigned_Types.Unsigned := 0) is Register : aliased Kernel.swi_regs; Error : oserror_access; Null_URI : string := URI & ASCII.NUL; begin Register.R(0) := int(Unsigned_to_Int(Flags)); Register.R(1) := int(ProgInfo); Register.R(2) := 7; Register.R(3) := Adr_To_Int(Null_URI'Address); Error := Kernel.swi(Toolbox_ObjectMiscOp,Register'Access,Register'Access); if Error /= null then pragma Debug(Reporter.Report("ToolboxProgInfo.Set_URI: " & To_Ada(Error.ErrMess))); OS.Raise_Error(Error); end if; end Set_URI; -- procedure Set_Title (ProgInfo : in Object_ID; Title : in string; Flags : in System.Unsigned_Types.Unsigned := 0) is Register : aliased Kernel.swi_regs; Error : oserror_access; Null_Title : string := Title & ASCII.NUL; begin Register.R(0) := int(Unsigned_to_Int(Flags)); Register.R(1) := int(ProgInfo); Register.R(2) := 5; Register.R(3) := Adr_To_Int(Null_Title'Address); Error := Kernel.swi(Toolbox_ObjectMiscOp,Register'Access,Register'Access); if Error /= null then pragma Debug(Reporter.Report("ToolboxProgInfo.Set_Title: " & To_Ada(Error.ErrMess))); OS.Raise_Error(Error); end if; end Set_Title; -- function Get_License_Type (ProgInfo : Object_ID; Flags : in System.Unsigned_Types.Unsigned := 0) return License_Type is Register : aliased Kernel.swi_regs; Error : oserror_access; begin Register.R(0) := int(Unsigned_to_Int(Flags)); Register.R(1) := int(ProgInfo); Register.R(2) := 4; Error := Kernel.swi(Toolbox_ObjectMiscOp,Register'Access,Register'Access); if Error /= null then pragma Debug(Reporter.Report("ToolboxProgInfo.Get_License_Type: " & To_Ada(Error.ErrMess))); OS.Raise_Error(Error); end if; return License_Type'Val(integer(Register.R(0))); end Get_License_Type; -- procedure Set_License_Type (ProgInfo : in Object_ID; License : in License_Type; Flags : in System.Unsigned_Types.Unsigned := 0) is Register : aliased Kernel.swi_regs; Error : oserror_access; begin Register.R(0) := int(Unsigned_to_Int(Flags)); Register.R(1) := int(ProgInfo); Register.R(2) := 3; Register.R(3) := int(License_Type'Pos(License)); Error := Kernel.swi(Toolbox_ObjectMiscOp,Register'Access,Register'Access); if Error /= null then pragma Debug(Reporter.Report("ToolboxProgInfo.Set_License_Type: " & To_Ada(Error.ErrMess))); OS.Raise_Error(Error); end if; end Set_License_Type; -- function Get_Version (ProgInfo : Object_ID; Flags : in System.Unsigned_Types.Unsigned := 0) return string is Register : aliased Kernel.swi_regs; Error : oserror_access; Buffer_Size : integer; begin Register.R(0) := int(Unsigned_to_Int(Flags)); Register.R(1) := int(ProgInfo); Register.R(2) := 2; Register.R(3) := 0; Register.R(4) := 0; Error := Kernel.swi(Toolbox_ObjectMiscOp,Register'Access,Register'Access); if Error /= null then pragma Debug(Reporter.Report("ToolboxProgInfo.Get_Version: " & To_Ada(Error.ErrMess))); OS.Raise_Error(Error); end if; Buffer_Size := integer(Register.R(4)); declare Buffer : string(1..Buffer_Size); begin Register.R(0) := 0; Register.R(1) := int(ProgInfo); Register.R(2) := 2; Register.R(3) := Adr_To_Int(Buffer'Address); Register.R(4) := int(Buffer_Size); Error := Kernel.swi(Toolbox_ObjectMiscOp,Register'Access,Register'Access); if Error /= null then pragma Debug(Reporter.Report("ToolboxProgInfo.Get_Version: " & To_Ada(Error.ErrMess))); OS.Raise_Error(Error); end if; return MemoryToString(Buffer'Address); end; end Get_Version; -- procedure Set_Version (ProgInfo : in Object_ID; Version : in string; Flags : in System.Unsigned_Types.Unsigned := 0) is Register : aliased Kernel.swi_regs; Error : oserror_access; Null_Version : string := Version & ASCII.NUL; begin Register.R(0) := int(Unsigned_to_Int(Flags)); Register.R(1) := int(ProgInfo); Register.R(2) := 1; Register.R(3) := Adr_To_Int(Null_Version'Address); Error := Kernel.swi(Toolbox_ObjectMiscOp,Register'Access,Register'Access); if Error /= null then pragma Debug(Reporter.Report("ToolboxProgInfo.Set_Version: " & To_Ada(Error.ErrMess))); OS.Raise_Error(Error); end if; end Set_Version; -- function Get_Web_Event (ProgInfo : Object_ID; Flags : in System.Unsigned_Types.Unsigned := 0) return Toolbox_Event_Code_Type is Register : aliased Kernel.swi_regs; Error : oserror_access; begin Register.R(0) := int(Unsigned_to_Int(Flags)); Register.R(1) := int(ProgInfo); Register.R(2) := 9; Error := Kernel.swi(Toolbox_ObjectMiscOp,Register'Access,Register'Access); if Error /= null then pragma Debug(Reporter.Report("ToolboxProgInfo.Get_Web_Event: " & To_Ada(Error.ErrMess))); OS.Raise_Error(Error); end if; return Toolbox_Event_Code_Type(integer(Register.R(0))); end Get_Web_Event; -- procedure Set_Web_Event (ProgInfo : in Object_ID; Event : in Toolbox_Event_Code_Type; Flags : in System.Unsigned_Types.Unsigned := 0) is Register : aliased Kernel.swi_regs; Error : oserror_access; begin Register.R(0) := int(Unsigned_to_Int(Flags)); Register.R(1) := int(ProgInfo); Register.R(2) := 10; Register.R(3) := int(integer(Event)); Error := Kernel.swi(Toolbox_ObjectMiscOp,Register'Access,Register'Access); if Error /= null then pragma Debug(Reporter.Report("ToolboxProgInfo.Set_Web_Event: " & To_Ada(Error.ErrMess))); OS.Raise_Error(Error); end if; end Set_Web_Event; -- end RASCAL.ToolboxProgInfo;
-- Ascon128av12 -- an instantiation of the Ascon-128a (v 1.2) variant of the Ascon Authenticated -- Encryption Algorithm created by Christoph Dobraunig, Maria Eichlseder, -- Florian Mendel and Martin Schläffer. -- Copyright (c) 2018, James Humphry - see LICENSE file for details pragma SPARK_Mode(On); with Ascon; package Ascon128av12 is new Ascon(a_rounds => 12, b_rounds => 8, b_round_constants_offset => 4, rate => 128);
package body Ada.Strings.UTF_Encoding is function Contains_BOM_8 (Item : UTF_String) return Boolean; function Contains_BOM_16BE (Item : UTF_String) return Boolean; function Contains_BOM_16LE (Item : UTF_String) return Boolean; function Contains_BOM_32BE (Item : UTF_String) return Boolean; function Contains_BOM_32LE (Item : UTF_String) return Boolean; function Contains_BOM_8 (Item : UTF_String) return Boolean is begin return Item'Length >= 3 and then Item (Item'First) = BOM_8 (1) and then Item (Item'First + 1) = BOM_8 (2) and then Item (Item'First + 2) = BOM_8 (3); end Contains_BOM_8; function Contains_BOM_16BE (Item : UTF_String) return Boolean is begin return Item'Length >= 2 and then Item (Item'First) = BOM_16BE (1) and then Item (Item'First + 1) = BOM_16BE (2); end Contains_BOM_16BE; function Contains_BOM_16LE (Item : UTF_String) return Boolean is begin return Item'Length >= 2 and then Item (Item'First) = BOM_16LE (1) and then Item (Item'First + 1) = BOM_16LE (2); end Contains_BOM_16LE; function Contains_BOM_32BE (Item : UTF_String) return Boolean is begin return Item'Length >= 4 and then Item (Item'First) = BOM_32BE (1) and then Item (Item'First + 1) = BOM_32BE (2) and then Item (Item'First + 2) = BOM_32BE (3) and then Item (Item'First + 3) = BOM_32BE (4); end Contains_BOM_32BE; function Contains_BOM_32LE (Item : UTF_String) return Boolean is begin return Item'Length >= 4 and then Item (Item'First) = BOM_32LE (1) and then Item (Item'First + 1) = BOM_32LE (2) and then Item (Item'First + 2) = BOM_32LE (3) and then Item (Item'First + 3) = BOM_32LE (4); end Contains_BOM_32LE; -- implementation function Encoding ( Item : UTF_String; Default : Encoding_Scheme := UTF_8) return Encoding_Scheme is begin if Contains_BOM_32BE (Item) then -- 4 elements return UTF_32BE; elsif Contains_BOM_32LE (Item) then return UTF_32LE; elsif Contains_BOM_8 (Item) then -- 3 elements return UTF_8; elsif Contains_BOM_16BE (Item) then -- 2 elements return UTF_16BE; elsif Contains_BOM_16LE (Item) then return UTF_16LE; else return Default; end if; end Encoding; end Ada.Strings.UTF_Encoding;
package Opt11 is type String_Ptr is access constant String; type Form_Type is (Qualified, Unqualified); type Rec is record N1, N2, N3 : Natural; Fixed : String_Ptr; Form : Form_Type; Is_Local : Boolean := True; end record; pragma Pack (Rec); procedure Proc; end Opt11;
-- This spec has been automatically generated from STM32F103.svd pragma Restrictions (No_Elaboration_Code); pragma Ada_2012; pragma Style_Checks (Off); with HAL; with System; package STM32_SVD.CAN is pragma Preelaborate; --------------- -- Registers -- --------------- -- CAN_MCR type CAN_MCR_Register is record -- INRQ INRQ : Boolean := False; -- SLEEP SLEEP : Boolean := False; -- TXFP TXFP : Boolean := False; -- RFLM RFLM : Boolean := False; -- NART NART : Boolean := False; -- AWUM AWUM : Boolean := False; -- ABOM ABOM : Boolean := False; -- TTCM TTCM : Boolean := False; -- unspecified Reserved_8_14 : HAL.UInt7 := 16#0#; -- RESET RESET : Boolean := False; -- DBF DBF : Boolean := False; -- unspecified Reserved_17_31 : HAL.UInt15 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for CAN_MCR_Register use record INRQ at 0 range 0 .. 0; SLEEP at 0 range 1 .. 1; TXFP at 0 range 2 .. 2; RFLM at 0 range 3 .. 3; NART at 0 range 4 .. 4; AWUM at 0 range 5 .. 5; ABOM at 0 range 6 .. 6; TTCM at 0 range 7 .. 7; Reserved_8_14 at 0 range 8 .. 14; RESET at 0 range 15 .. 15; DBF at 0 range 16 .. 16; Reserved_17_31 at 0 range 17 .. 31; end record; -- CAN_MSR type CAN_MSR_Register is record -- Read-only. INAK INAK : Boolean := False; -- Read-only. SLAK SLAK : Boolean := False; -- ERRI ERRI : Boolean := False; -- WKUI WKUI : Boolean := False; -- SLAKI SLAKI : Boolean := False; -- unspecified Reserved_5_7 : HAL.UInt3 := 16#0#; -- Read-only. TXM TXM : Boolean := False; -- Read-only. RXM RXM : Boolean := False; -- Read-only. SAMP SAMP : Boolean := False; -- Read-only. RX RX : Boolean := False; -- unspecified Reserved_12_31 : HAL.UInt20 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for CAN_MSR_Register use record INAK at 0 range 0 .. 0; SLAK at 0 range 1 .. 1; ERRI at 0 range 2 .. 2; WKUI at 0 range 3 .. 3; SLAKI at 0 range 4 .. 4; Reserved_5_7 at 0 range 5 .. 7; TXM at 0 range 8 .. 8; RXM at 0 range 9 .. 9; SAMP at 0 range 10 .. 10; RX at 0 range 11 .. 11; Reserved_12_31 at 0 range 12 .. 31; end record; subtype CAN_TSR_CODE_Field is HAL.UInt2; -- CAN_TSR_TME array type CAN_TSR_TME_Field_Array is array (0 .. 2) of Boolean with Component_Size => 1, Size => 3; -- Type definition for CAN_TSR_TME type CAN_TSR_TME_Field (As_Array : Boolean := False) is record case As_Array is when False => -- TME as a value Val : HAL.UInt3; when True => -- TME as an array Arr : CAN_TSR_TME_Field_Array; end case; end record with Unchecked_Union, Size => 3; for CAN_TSR_TME_Field use record Val at 0 range 0 .. 2; Arr at 0 range 0 .. 2; end record; -- CAN_TSR_LOW array type CAN_TSR_LOW_Field_Array is array (0 .. 2) of Boolean with Component_Size => 1, Size => 3; -- Type definition for CAN_TSR_LOW type CAN_TSR_LOW_Field (As_Array : Boolean := False) is record case As_Array is when False => -- LOW as a value Val : HAL.UInt3; when True => -- LOW as an array Arr : CAN_TSR_LOW_Field_Array; end case; end record with Unchecked_Union, Size => 3; for CAN_TSR_LOW_Field use record Val at 0 range 0 .. 2; Arr at 0 range 0 .. 2; end record; -- CAN_TSR type CAN_TSR_Register is record -- RQCP0 RQCP0 : Boolean := False; -- TXOK0 TXOK0 : Boolean := False; -- ALST0 ALST0 : Boolean := False; -- TERR0 TERR0 : Boolean := False; -- unspecified Reserved_4_6 : HAL.UInt3 := 16#0#; -- ABRQ0 ABRQ0 : Boolean := False; -- RQCP1 RQCP1 : Boolean := False; -- TXOK1 TXOK1 : Boolean := False; -- ALST1 ALST1 : Boolean := False; -- TERR1 TERR1 : Boolean := False; -- unspecified Reserved_12_14 : HAL.UInt3 := 16#0#; -- ABRQ1 ABRQ1 : Boolean := False; -- RQCP2 RQCP2 : Boolean := False; -- TXOK2 TXOK2 : Boolean := False; -- ALST2 ALST2 : Boolean := False; -- TERR2 TERR2 : Boolean := False; -- unspecified Reserved_20_22 : HAL.UInt3 := 16#0#; -- ABRQ2 ABRQ2 : Boolean := False; -- Read-only. CODE CODE : CAN_TSR_CODE_Field := 16#0#; -- Read-only. Lowest priority flag for mailbox 0 TME : CAN_TSR_TME_Field := (As_Array => False, Val => 16#0#); -- Read-only. Lowest priority flag for mailbox 0 LOW : CAN_TSR_LOW_Field := (As_Array => False, Val => 16#0#); end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for CAN_TSR_Register use record RQCP0 at 0 range 0 .. 0; TXOK0 at 0 range 1 .. 1; ALST0 at 0 range 2 .. 2; TERR0 at 0 range 3 .. 3; Reserved_4_6 at 0 range 4 .. 6; ABRQ0 at 0 range 7 .. 7; RQCP1 at 0 range 8 .. 8; TXOK1 at 0 range 9 .. 9; ALST1 at 0 range 10 .. 10; TERR1 at 0 range 11 .. 11; Reserved_12_14 at 0 range 12 .. 14; ABRQ1 at 0 range 15 .. 15; RQCP2 at 0 range 16 .. 16; TXOK2 at 0 range 17 .. 17; ALST2 at 0 range 18 .. 18; TERR2 at 0 range 19 .. 19; Reserved_20_22 at 0 range 20 .. 22; ABRQ2 at 0 range 23 .. 23; CODE at 0 range 24 .. 25; TME at 0 range 26 .. 28; LOW at 0 range 29 .. 31; end record; subtype CAN_RF0R_FMP0_Field is HAL.UInt2; -- CAN_RF0R type CAN_RF0R_Register is record -- Read-only. FMP0 FMP0 : CAN_RF0R_FMP0_Field := 16#0#; -- unspecified Reserved_2_2 : HAL.Bit := 16#0#; -- FULL0 FULL0 : Boolean := False; -- FOVR0 FOVR0 : Boolean := False; -- RFOM0 RFOM0 : 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 CAN_RF0R_Register use record FMP0 at 0 range 0 .. 1; Reserved_2_2 at 0 range 2 .. 2; FULL0 at 0 range 3 .. 3; FOVR0 at 0 range 4 .. 4; RFOM0 at 0 range 5 .. 5; Reserved_6_31 at 0 range 6 .. 31; end record; subtype CAN_RF1R_FMP1_Field is HAL.UInt2; -- CAN_RF1R type CAN_RF1R_Register is record -- Read-only. FMP1 FMP1 : CAN_RF1R_FMP1_Field := 16#0#; -- unspecified Reserved_2_2 : HAL.Bit := 16#0#; -- FULL1 FULL1 : Boolean := False; -- FOVR1 FOVR1 : Boolean := False; -- RFOM1 RFOM1 : 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 CAN_RF1R_Register use record FMP1 at 0 range 0 .. 1; Reserved_2_2 at 0 range 2 .. 2; FULL1 at 0 range 3 .. 3; FOVR1 at 0 range 4 .. 4; RFOM1 at 0 range 5 .. 5; Reserved_6_31 at 0 range 6 .. 31; end record; -- CAN_IER type CAN_IER_Register is record -- TMEIE TMEIE : Boolean := False; -- FMPIE0 FMPIE0 : Boolean := False; -- FFIE0 FFIE0 : Boolean := False; -- FOVIE0 FOVIE0 : Boolean := False; -- FMPIE1 FMPIE1 : Boolean := False; -- FFIE1 FFIE1 : Boolean := False; -- FOVIE1 FOVIE1 : Boolean := False; -- unspecified Reserved_7_7 : HAL.Bit := 16#0#; -- EWGIE EWGIE : Boolean := False; -- EPVIE EPVIE : Boolean := False; -- BOFIE BOFIE : Boolean := False; -- LECIE LECIE : Boolean := False; -- unspecified Reserved_12_14 : HAL.UInt3 := 16#0#; -- ERRIE ERRIE : Boolean := False; -- WKUIE WKUIE : Boolean := False; -- SLKIE SLKIE : 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 CAN_IER_Register use record TMEIE at 0 range 0 .. 0; FMPIE0 at 0 range 1 .. 1; FFIE0 at 0 range 2 .. 2; FOVIE0 at 0 range 3 .. 3; FMPIE1 at 0 range 4 .. 4; FFIE1 at 0 range 5 .. 5; FOVIE1 at 0 range 6 .. 6; Reserved_7_7 at 0 range 7 .. 7; EWGIE at 0 range 8 .. 8; EPVIE at 0 range 9 .. 9; BOFIE at 0 range 10 .. 10; LECIE at 0 range 11 .. 11; Reserved_12_14 at 0 range 12 .. 14; ERRIE at 0 range 15 .. 15; WKUIE at 0 range 16 .. 16; SLKIE at 0 range 17 .. 17; Reserved_18_31 at 0 range 18 .. 31; end record; subtype CAN_ESR_LEC_Field is HAL.UInt3; subtype CAN_ESR_TEC_Field is HAL.UInt8; subtype CAN_ESR_REC_Field is HAL.UInt8; -- CAN_ESR type CAN_ESR_Register is record -- Read-only. EWGF EWGF : Boolean := False; -- Read-only. EPVF EPVF : Boolean := False; -- Read-only. BOFF BOFF : Boolean := False; -- unspecified Reserved_3_3 : HAL.Bit := 16#0#; -- LEC LEC : CAN_ESR_LEC_Field := 16#0#; -- unspecified Reserved_7_15 : HAL.UInt9 := 16#0#; -- Read-only. TEC TEC : CAN_ESR_TEC_Field := 16#0#; -- Read-only. REC REC : CAN_ESR_REC_Field := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for CAN_ESR_Register use record EWGF at 0 range 0 .. 0; EPVF at 0 range 1 .. 1; BOFF at 0 range 2 .. 2; Reserved_3_3 at 0 range 3 .. 3; LEC at 0 range 4 .. 6; Reserved_7_15 at 0 range 7 .. 15; TEC at 0 range 16 .. 23; REC at 0 range 24 .. 31; end record; subtype CAN_BTR_BRP_Field is HAL.UInt10; subtype CAN_BTR_TS1_Field is HAL.UInt4; subtype CAN_BTR_TS2_Field is HAL.UInt3; subtype CAN_BTR_SJW_Field is HAL.UInt2; -- CAN_BTR type CAN_BTR_Register is record -- BRP BRP : CAN_BTR_BRP_Field := 16#0#; -- unspecified Reserved_10_15 : HAL.UInt6 := 16#0#; -- TS1 TS1 : CAN_BTR_TS1_Field := 16#0#; -- TS2 TS2 : CAN_BTR_TS2_Field := 16#0#; -- unspecified Reserved_23_23 : HAL.Bit := 16#0#; -- SJW SJW : CAN_BTR_SJW_Field := 16#0#; -- unspecified Reserved_26_29 : HAL.UInt4 := 16#0#; -- LBKM LBKM : Boolean := False; -- SILM SILM : Boolean := False; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for CAN_BTR_Register use record BRP at 0 range 0 .. 9; Reserved_10_15 at 0 range 10 .. 15; TS1 at 0 range 16 .. 19; TS2 at 0 range 20 .. 22; Reserved_23_23 at 0 range 23 .. 23; SJW at 0 range 24 .. 25; Reserved_26_29 at 0 range 26 .. 29; LBKM at 0 range 30 .. 30; SILM at 0 range 31 .. 31; end record; subtype CAN_TI0R_EXID_Field is HAL.UInt18; subtype CAN_TI0R_STID_Field is HAL.UInt11; -- CAN_TI0R type CAN_TI0R_Register is record -- TXRQ TXRQ : Boolean := False; -- RTR RTR : Boolean := False; -- IDE IDE : Boolean := False; -- EXID EXID : CAN_TI0R_EXID_Field := 16#0#; -- STID STID : CAN_TI0R_STID_Field := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for CAN_TI0R_Register use record TXRQ at 0 range 0 .. 0; RTR at 0 range 1 .. 1; IDE at 0 range 2 .. 2; EXID at 0 range 3 .. 20; STID at 0 range 21 .. 31; end record; subtype CAN_TDT0R_DLC_Field is HAL.UInt4; subtype CAN_TDT0R_TIME_Field is HAL.UInt16; -- CAN_TDT0R type CAN_TDT0R_Register is record -- DLC DLC : CAN_TDT0R_DLC_Field := 16#0#; -- unspecified Reserved_4_7 : HAL.UInt4 := 16#0#; -- TGT TGT : Boolean := False; -- unspecified Reserved_9_15 : HAL.UInt7 := 16#0#; -- TIME TIME : CAN_TDT0R_TIME_Field := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for CAN_TDT0R_Register use record DLC at 0 range 0 .. 3; Reserved_4_7 at 0 range 4 .. 7; TGT at 0 range 8 .. 8; Reserved_9_15 at 0 range 9 .. 15; TIME at 0 range 16 .. 31; end record; -- CAN_TDL0R_DATA array element subtype CAN_TDL0R_DATA_Element is HAL.UInt8; -- CAN_TDL0R_DATA array type CAN_TDL0R_DATA_Field_Array is array (0 .. 3) of CAN_TDL0R_DATA_Element with Component_Size => 8, Size => 32; -- CAN_TDL0R type CAN_TDL0R_Register (As_Array : Boolean := False) is record case As_Array is when False => -- DATA as a value Val : HAL.UInt32; when True => -- DATA as an array Arr : CAN_TDL0R_DATA_Field_Array; end case; end record with Unchecked_Union, Size => 32, Volatile_Full_Access, Bit_Order => System.Low_Order_First; for CAN_TDL0R_Register use record Val at 0 range 0 .. 31; Arr at 0 range 0 .. 31; end record; -- CAN_TDH0R_DATA array element subtype CAN_TDH0R_DATA_Element is HAL.UInt8; -- CAN_TDH0R_DATA array type CAN_TDH0R_DATA_Field_Array is array (4 .. 7) of CAN_TDH0R_DATA_Element with Component_Size => 8, Size => 32; -- CAN_TDH0R type CAN_TDH0R_Register (As_Array : Boolean := False) is record case As_Array is when False => -- DATA as a value Val : HAL.UInt32; when True => -- DATA as an array Arr : CAN_TDH0R_DATA_Field_Array; end case; end record with Unchecked_Union, Size => 32, Volatile_Full_Access, Bit_Order => System.Low_Order_First; for CAN_TDH0R_Register use record Val at 0 range 0 .. 31; Arr at 0 range 0 .. 31; end record; subtype CAN_TI1R_EXID_Field is HAL.UInt18; subtype CAN_TI1R_STID_Field is HAL.UInt11; -- CAN_TI1R type CAN_TI1R_Register is record -- TXRQ TXRQ : Boolean := False; -- RTR RTR : Boolean := False; -- IDE IDE : Boolean := False; -- EXID EXID : CAN_TI1R_EXID_Field := 16#0#; -- STID STID : CAN_TI1R_STID_Field := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for CAN_TI1R_Register use record TXRQ at 0 range 0 .. 0; RTR at 0 range 1 .. 1; IDE at 0 range 2 .. 2; EXID at 0 range 3 .. 20; STID at 0 range 21 .. 31; end record; subtype CAN_TDT1R_DLC_Field is HAL.UInt4; subtype CAN_TDT1R_TIME_Field is HAL.UInt16; -- CAN_TDT1R type CAN_TDT1R_Register is record -- DLC DLC : CAN_TDT1R_DLC_Field := 16#0#; -- unspecified Reserved_4_7 : HAL.UInt4 := 16#0#; -- TGT TGT : Boolean := False; -- unspecified Reserved_9_15 : HAL.UInt7 := 16#0#; -- TIME TIME : CAN_TDT1R_TIME_Field := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for CAN_TDT1R_Register use record DLC at 0 range 0 .. 3; Reserved_4_7 at 0 range 4 .. 7; TGT at 0 range 8 .. 8; Reserved_9_15 at 0 range 9 .. 15; TIME at 0 range 16 .. 31; end record; -- CAN_TDL1R_DATA array element subtype CAN_TDL1R_DATA_Element is HAL.UInt8; -- CAN_TDL1R_DATA array type CAN_TDL1R_DATA_Field_Array is array (0 .. 3) of CAN_TDL1R_DATA_Element with Component_Size => 8, Size => 32; -- CAN_TDL1R type CAN_TDL1R_Register (As_Array : Boolean := False) is record case As_Array is when False => -- DATA as a value Val : HAL.UInt32; when True => -- DATA as an array Arr : CAN_TDL1R_DATA_Field_Array; end case; end record with Unchecked_Union, Size => 32, Volatile_Full_Access, Bit_Order => System.Low_Order_First; for CAN_TDL1R_Register use record Val at 0 range 0 .. 31; Arr at 0 range 0 .. 31; end record; -- CAN_TDH1R_DATA array element subtype CAN_TDH1R_DATA_Element is HAL.UInt8; -- CAN_TDH1R_DATA array type CAN_TDH1R_DATA_Field_Array is array (4 .. 7) of CAN_TDH1R_DATA_Element with Component_Size => 8, Size => 32; -- CAN_TDH1R type CAN_TDH1R_Register (As_Array : Boolean := False) is record case As_Array is when False => -- DATA as a value Val : HAL.UInt32; when True => -- DATA as an array Arr : CAN_TDH1R_DATA_Field_Array; end case; end record with Unchecked_Union, Size => 32, Volatile_Full_Access, Bit_Order => System.Low_Order_First; for CAN_TDH1R_Register use record Val at 0 range 0 .. 31; Arr at 0 range 0 .. 31; end record; subtype CAN_TI2R_EXID_Field is HAL.UInt18; subtype CAN_TI2R_STID_Field is HAL.UInt11; -- CAN_TI2R type CAN_TI2R_Register is record -- TXRQ TXRQ : Boolean := False; -- RTR RTR : Boolean := False; -- IDE IDE : Boolean := False; -- EXID EXID : CAN_TI2R_EXID_Field := 16#0#; -- STID STID : CAN_TI2R_STID_Field := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for CAN_TI2R_Register use record TXRQ at 0 range 0 .. 0; RTR at 0 range 1 .. 1; IDE at 0 range 2 .. 2; EXID at 0 range 3 .. 20; STID at 0 range 21 .. 31; end record; subtype CAN_TDT2R_DLC_Field is HAL.UInt4; subtype CAN_TDT2R_TIME_Field is HAL.UInt16; -- CAN_TDT2R type CAN_TDT2R_Register is record -- DLC DLC : CAN_TDT2R_DLC_Field := 16#0#; -- unspecified Reserved_4_7 : HAL.UInt4 := 16#0#; -- TGT TGT : Boolean := False; -- unspecified Reserved_9_15 : HAL.UInt7 := 16#0#; -- TIME TIME : CAN_TDT2R_TIME_Field := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for CAN_TDT2R_Register use record DLC at 0 range 0 .. 3; Reserved_4_7 at 0 range 4 .. 7; TGT at 0 range 8 .. 8; Reserved_9_15 at 0 range 9 .. 15; TIME at 0 range 16 .. 31; end record; -- CAN_TDL2R_DATA array element subtype CAN_TDL2R_DATA_Element is HAL.UInt8; -- CAN_TDL2R_DATA array type CAN_TDL2R_DATA_Field_Array is array (0 .. 3) of CAN_TDL2R_DATA_Element with Component_Size => 8, Size => 32; -- CAN_TDL2R type CAN_TDL2R_Register (As_Array : Boolean := False) is record case As_Array is when False => -- DATA as a value Val : HAL.UInt32; when True => -- DATA as an array Arr : CAN_TDL2R_DATA_Field_Array; end case; end record with Unchecked_Union, Size => 32, Volatile_Full_Access, Bit_Order => System.Low_Order_First; for CAN_TDL2R_Register use record Val at 0 range 0 .. 31; Arr at 0 range 0 .. 31; end record; -- CAN_TDH2R_DATA array element subtype CAN_TDH2R_DATA_Element is HAL.UInt8; -- CAN_TDH2R_DATA array type CAN_TDH2R_DATA_Field_Array is array (4 .. 7) of CAN_TDH2R_DATA_Element with Component_Size => 8, Size => 32; -- CAN_TDH2R type CAN_TDH2R_Register (As_Array : Boolean := False) is record case As_Array is when False => -- DATA as a value Val : HAL.UInt32; when True => -- DATA as an array Arr : CAN_TDH2R_DATA_Field_Array; end case; end record with Unchecked_Union, Size => 32, Volatile_Full_Access, Bit_Order => System.Low_Order_First; for CAN_TDH2R_Register use record Val at 0 range 0 .. 31; Arr at 0 range 0 .. 31; end record; subtype CAN_RI0R_EXID_Field is HAL.UInt18; subtype CAN_RI0R_STID_Field is HAL.UInt11; -- CAN_RI0R type CAN_RI0R_Register is record -- unspecified Reserved_0_0 : HAL.Bit; -- Read-only. RTR RTR : Boolean; -- Read-only. IDE IDE : Boolean; -- Read-only. EXID EXID : CAN_RI0R_EXID_Field; -- Read-only. STID STID : CAN_RI0R_STID_Field; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for CAN_RI0R_Register use record Reserved_0_0 at 0 range 0 .. 0; RTR at 0 range 1 .. 1; IDE at 0 range 2 .. 2; EXID at 0 range 3 .. 20; STID at 0 range 21 .. 31; end record; subtype CAN_RDT0R_DLC_Field is HAL.UInt4; subtype CAN_RDT0R_FMI_Field is HAL.UInt8; subtype CAN_RDT0R_TIME_Field is HAL.UInt16; -- CAN_RDT0R type CAN_RDT0R_Register is record -- Read-only. DLC DLC : CAN_RDT0R_DLC_Field; -- unspecified Reserved_4_7 : HAL.UInt4; -- Read-only. FMI FMI : CAN_RDT0R_FMI_Field; -- Read-only. TIME TIME : CAN_RDT0R_TIME_Field; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for CAN_RDT0R_Register use record DLC at 0 range 0 .. 3; Reserved_4_7 at 0 range 4 .. 7; FMI at 0 range 8 .. 15; TIME at 0 range 16 .. 31; end record; -- CAN_RDL0R_DATA array element subtype CAN_RDL0R_DATA_Element is HAL.UInt8; -- CAN_RDL0R_DATA array type CAN_RDL0R_DATA_Field_Array is array (0 .. 3) of CAN_RDL0R_DATA_Element with Component_Size => 8, Size => 32; -- CAN_RDL0R type CAN_RDL0R_Register (As_Array : Boolean := False) is record case As_Array is when False => -- DATA as a value Val : HAL.UInt32; when True => -- DATA as an array Arr : CAN_RDL0R_DATA_Field_Array; end case; end record with Unchecked_Union, Size => 32, Volatile_Full_Access, Bit_Order => System.Low_Order_First; for CAN_RDL0R_Register use record Val at 0 range 0 .. 31; Arr at 0 range 0 .. 31; end record; -- CAN_RDH0R_DATA array element subtype CAN_RDH0R_DATA_Element is HAL.UInt8; -- CAN_RDH0R_DATA array type CAN_RDH0R_DATA_Field_Array is array (4 .. 7) of CAN_RDH0R_DATA_Element with Component_Size => 8, Size => 32; -- CAN_RDH0R type CAN_RDH0R_Register (As_Array : Boolean := False) is record case As_Array is when False => -- DATA as a value Val : HAL.UInt32; when True => -- DATA as an array Arr : CAN_RDH0R_DATA_Field_Array; end case; end record with Unchecked_Union, Size => 32, Volatile_Full_Access, Bit_Order => System.Low_Order_First; for CAN_RDH0R_Register use record Val at 0 range 0 .. 31; Arr at 0 range 0 .. 31; end record; subtype CAN_RI1R_EXID_Field is HAL.UInt18; subtype CAN_RI1R_STID_Field is HAL.UInt11; -- CAN_RI1R type CAN_RI1R_Register is record -- unspecified Reserved_0_0 : HAL.Bit; -- Read-only. RTR RTR : Boolean; -- Read-only. IDE IDE : Boolean; -- Read-only. EXID EXID : CAN_RI1R_EXID_Field; -- Read-only. STID STID : CAN_RI1R_STID_Field; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for CAN_RI1R_Register use record Reserved_0_0 at 0 range 0 .. 0; RTR at 0 range 1 .. 1; IDE at 0 range 2 .. 2; EXID at 0 range 3 .. 20; STID at 0 range 21 .. 31; end record; subtype CAN_RDT1R_DLC_Field is HAL.UInt4; subtype CAN_RDT1R_FMI_Field is HAL.UInt8; subtype CAN_RDT1R_TIME_Field is HAL.UInt16; -- CAN_RDT1R type CAN_RDT1R_Register is record -- Read-only. DLC DLC : CAN_RDT1R_DLC_Field; -- unspecified Reserved_4_7 : HAL.UInt4; -- Read-only. FMI FMI : CAN_RDT1R_FMI_Field; -- Read-only. TIME TIME : CAN_RDT1R_TIME_Field; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for CAN_RDT1R_Register use record DLC at 0 range 0 .. 3; Reserved_4_7 at 0 range 4 .. 7; FMI at 0 range 8 .. 15; TIME at 0 range 16 .. 31; end record; -- CAN_RDL1R_DATA array element subtype CAN_RDL1R_DATA_Element is HAL.UInt8; -- CAN_RDL1R_DATA array type CAN_RDL1R_DATA_Field_Array is array (0 .. 3) of CAN_RDL1R_DATA_Element with Component_Size => 8, Size => 32; -- CAN_RDL1R type CAN_RDL1R_Register (As_Array : Boolean := False) is record case As_Array is when False => -- DATA as a value Val : HAL.UInt32; when True => -- DATA as an array Arr : CAN_RDL1R_DATA_Field_Array; end case; end record with Unchecked_Union, Size => 32, Volatile_Full_Access, Bit_Order => System.Low_Order_First; for CAN_RDL1R_Register use record Val at 0 range 0 .. 31; Arr at 0 range 0 .. 31; end record; -- CAN_RDH1R_DATA array element subtype CAN_RDH1R_DATA_Element is HAL.UInt8; -- CAN_RDH1R_DATA array type CAN_RDH1R_DATA_Field_Array is array (4 .. 7) of CAN_RDH1R_DATA_Element with Component_Size => 8, Size => 32; -- CAN_RDH1R type CAN_RDH1R_Register (As_Array : Boolean := False) is record case As_Array is when False => -- DATA as a value Val : HAL.UInt32; when True => -- DATA as an array Arr : CAN_RDH1R_DATA_Field_Array; end case; end record with Unchecked_Union, Size => 32, Volatile_Full_Access, Bit_Order => System.Low_Order_First; for CAN_RDH1R_Register use record Val at 0 range 0 .. 31; Arr at 0 range 0 .. 31; end record; -- CAN_FMR type CAN_FMR_Register is record -- FINIT FINIT : Boolean := False; -- unspecified Reserved_1_31 : HAL.UInt31 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for CAN_FMR_Register use record FINIT at 0 range 0 .. 0; Reserved_1_31 at 0 range 1 .. 31; end record; -- CAN_FM1R_FBM array type CAN_FM1R_FBM_Field_Array is array (0 .. 13) of Boolean with Component_Size => 1, Size => 14; -- Type definition for CAN_FM1R_FBM type CAN_FM1R_FBM_Field (As_Array : Boolean := False) is record case As_Array is when False => -- FBM as a value Val : HAL.UInt14; when True => -- FBM as an array Arr : CAN_FM1R_FBM_Field_Array; end case; end record with Unchecked_Union, Size => 14; for CAN_FM1R_FBM_Field use record Val at 0 range 0 .. 13; Arr at 0 range 0 .. 13; end record; -- CAN_FM1R type CAN_FM1R_Register is record -- Filter mode FBM : CAN_FM1R_FBM_Field := (As_Array => False, Val => 16#0#); -- unspecified Reserved_14_31 : HAL.UInt18 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for CAN_FM1R_Register use record FBM at 0 range 0 .. 13; Reserved_14_31 at 0 range 14 .. 31; end record; -- CAN_FS1R_FSC array type CAN_FS1R_FSC_Field_Array is array (0 .. 13) of Boolean with Component_Size => 1, Size => 14; -- Type definition for CAN_FS1R_FSC type CAN_FS1R_FSC_Field (As_Array : Boolean := False) is record case As_Array is when False => -- FSC as a value Val : HAL.UInt14; when True => -- FSC as an array Arr : CAN_FS1R_FSC_Field_Array; end case; end record with Unchecked_Union, Size => 14; for CAN_FS1R_FSC_Field use record Val at 0 range 0 .. 13; Arr at 0 range 0 .. 13; end record; -- CAN_FS1R type CAN_FS1R_Register is record -- Filter scale configuration FSC : CAN_FS1R_FSC_Field := (As_Array => False, Val => 16#0#); -- unspecified Reserved_14_31 : HAL.UInt18 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for CAN_FS1R_Register use record FSC at 0 range 0 .. 13; Reserved_14_31 at 0 range 14 .. 31; end record; -- CAN_FFA1R_FFA array type CAN_FFA1R_FFA_Field_Array is array (0 .. 13) of Boolean with Component_Size => 1, Size => 14; -- Type definition for CAN_FFA1R_FFA type CAN_FFA1R_FFA_Field (As_Array : Boolean := False) is record case As_Array is when False => -- FFA as a value Val : HAL.UInt14; when True => -- FFA as an array Arr : CAN_FFA1R_FFA_Field_Array; end case; end record with Unchecked_Union, Size => 14; for CAN_FFA1R_FFA_Field use record Val at 0 range 0 .. 13; Arr at 0 range 0 .. 13; end record; -- CAN_FFA1R type CAN_FFA1R_Register is record -- Filter FIFO assignment for filter 0 FFA : CAN_FFA1R_FFA_Field := (As_Array => False, Val => 16#0#); -- unspecified Reserved_14_31 : HAL.UInt18 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for CAN_FFA1R_Register use record FFA at 0 range 0 .. 13; Reserved_14_31 at 0 range 14 .. 31; end record; -- CAN_FA1R_FACT array type CAN_FA1R_FACT_Field_Array is array (0 .. 13) of Boolean with Component_Size => 1, Size => 14; -- Type definition for CAN_FA1R_FACT type CAN_FA1R_FACT_Field (As_Array : Boolean := False) is record case As_Array is when False => -- FACT as a value Val : HAL.UInt14; when True => -- FACT as an array Arr : CAN_FA1R_FACT_Field_Array; end case; end record with Unchecked_Union, Size => 14; for CAN_FA1R_FACT_Field use record Val at 0 range 0 .. 13; Arr at 0 range 0 .. 13; end record; -- CAN_FA1R type CAN_FA1R_Register is record -- Filter active FACT : CAN_FA1R_FACT_Field := (As_Array => False, Val => 16#0#); -- unspecified Reserved_14_31 : HAL.UInt18 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for CAN_FA1R_Register use record FACT at 0 range 0 .. 13; Reserved_14_31 at 0 range 14 .. 31; end record; -- F0R_FB array type F0R_FB_Field_Array is array (0 .. 31) of Boolean with Component_Size => 1, Size => 32; -- Filter bank 0 register 1 type F0R_Register (As_Array : Boolean := False) is record case As_Array is when False => -- FB as a value Val : HAL.UInt32; when True => -- FB as an array Arr : F0R_FB_Field_Array; end case; end record with Unchecked_Union, Size => 32, Volatile_Full_Access, Bit_Order => System.Low_Order_First; for F0R_Register use record Val at 0 range 0 .. 31; Arr at 0 range 0 .. 31; end record; -- F1R_FB array type F1R_FB_Field_Array is array (0 .. 31) of Boolean with Component_Size => 1, Size => 32; -- Filter bank 1 register 1 type F1R_Register (As_Array : Boolean := False) is record case As_Array is when False => -- FB as a value Val : HAL.UInt32; when True => -- FB as an array Arr : F1R_FB_Field_Array; end case; end record with Unchecked_Union, Size => 32, Volatile_Full_Access, Bit_Order => System.Low_Order_First; for F1R_Register use record Val at 0 range 0 .. 31; Arr at 0 range 0 .. 31; end record; -- F2R_FB array type F2R_FB_Field_Array is array (0 .. 31) of Boolean with Component_Size => 1, Size => 32; -- Filter bank 2 register 1 type F2R_Register (As_Array : Boolean := False) is record case As_Array is when False => -- FB as a value Val : HAL.UInt32; when True => -- FB as an array Arr : F2R_FB_Field_Array; end case; end record with Unchecked_Union, Size => 32, Volatile_Full_Access, Bit_Order => System.Low_Order_First; for F2R_Register use record Val at 0 range 0 .. 31; Arr at 0 range 0 .. 31; end record; -- F3R_FB array type F3R_FB_Field_Array is array (0 .. 31) of Boolean with Component_Size => 1, Size => 32; -- Filter bank 3 register 1 type F3R_Register (As_Array : Boolean := False) is record case As_Array is when False => -- FB as a value Val : HAL.UInt32; when True => -- FB as an array Arr : F3R_FB_Field_Array; end case; end record with Unchecked_Union, Size => 32, Volatile_Full_Access, Bit_Order => System.Low_Order_First; for F3R_Register use record Val at 0 range 0 .. 31; Arr at 0 range 0 .. 31; end record; -- F4R_FB array type F4R_FB_Field_Array is array (0 .. 31) of Boolean with Component_Size => 1, Size => 32; -- Filter bank 4 register 1 type F4R_Register (As_Array : Boolean := False) is record case As_Array is when False => -- FB as a value Val : HAL.UInt32; when True => -- FB as an array Arr : F4R_FB_Field_Array; end case; end record with Unchecked_Union, Size => 32, Volatile_Full_Access, Bit_Order => System.Low_Order_First; for F4R_Register use record Val at 0 range 0 .. 31; Arr at 0 range 0 .. 31; end record; -- F5R_FB array type F5R_FB_Field_Array is array (0 .. 31) of Boolean with Component_Size => 1, Size => 32; -- Filter bank 5 register 1 type F5R_Register (As_Array : Boolean := False) is record case As_Array is when False => -- FB as a value Val : HAL.UInt32; when True => -- FB as an array Arr : F5R_FB_Field_Array; end case; end record with Unchecked_Union, Size => 32, Volatile_Full_Access, Bit_Order => System.Low_Order_First; for F5R_Register use record Val at 0 range 0 .. 31; Arr at 0 range 0 .. 31; end record; -- F6R_FB array type F6R_FB_Field_Array is array (0 .. 31) of Boolean with Component_Size => 1, Size => 32; -- Filter bank 6 register 1 type F6R_Register (As_Array : Boolean := False) is record case As_Array is when False => -- FB as a value Val : HAL.UInt32; when True => -- FB as an array Arr : F6R_FB_Field_Array; end case; end record with Unchecked_Union, Size => 32, Volatile_Full_Access, Bit_Order => System.Low_Order_First; for F6R_Register use record Val at 0 range 0 .. 31; Arr at 0 range 0 .. 31; end record; -- F7R_FB array type F7R_FB_Field_Array is array (0 .. 31) of Boolean with Component_Size => 1, Size => 32; -- Filter bank 7 register 1 type F7R_Register (As_Array : Boolean := False) is record case As_Array is when False => -- FB as a value Val : HAL.UInt32; when True => -- FB as an array Arr : F7R_FB_Field_Array; end case; end record with Unchecked_Union, Size => 32, Volatile_Full_Access, Bit_Order => System.Low_Order_First; for F7R_Register use record Val at 0 range 0 .. 31; Arr at 0 range 0 .. 31; end record; -- F8R_FB array type F8R_FB_Field_Array is array (0 .. 31) of Boolean with Component_Size => 1, Size => 32; -- Filter bank 8 register 1 type F8R_Register (As_Array : Boolean := False) is record case As_Array is when False => -- FB as a value Val : HAL.UInt32; when True => -- FB as an array Arr : F8R_FB_Field_Array; end case; end record with Unchecked_Union, Size => 32, Volatile_Full_Access, Bit_Order => System.Low_Order_First; for F8R_Register use record Val at 0 range 0 .. 31; Arr at 0 range 0 .. 31; end record; -- F9R_FB array type F9R_FB_Field_Array is array (0 .. 31) of Boolean with Component_Size => 1, Size => 32; -- Filter bank 9 register 1 type F9R_Register (As_Array : Boolean := False) is record case As_Array is when False => -- FB as a value Val : HAL.UInt32; when True => -- FB as an array Arr : F9R_FB_Field_Array; end case; end record with Unchecked_Union, Size => 32, Volatile_Full_Access, Bit_Order => System.Low_Order_First; for F9R_Register use record Val at 0 range 0 .. 31; Arr at 0 range 0 .. 31; end record; -- F10R_FB array type F10R_FB_Field_Array is array (0 .. 31) of Boolean with Component_Size => 1, Size => 32; -- Filter bank 10 register 1 type F10R_Register (As_Array : Boolean := False) is record case As_Array is when False => -- FB as a value Val : HAL.UInt32; when True => -- FB as an array Arr : F10R_FB_Field_Array; end case; end record with Unchecked_Union, Size => 32, Volatile_Full_Access, Bit_Order => System.Low_Order_First; for F10R_Register use record Val at 0 range 0 .. 31; Arr at 0 range 0 .. 31; end record; -- F11R_FB array type F11R_FB_Field_Array is array (0 .. 31) of Boolean with Component_Size => 1, Size => 32; -- Filter bank 11 register 1 type F11R_Register (As_Array : Boolean := False) is record case As_Array is when False => -- FB as a value Val : HAL.UInt32; when True => -- FB as an array Arr : F11R_FB_Field_Array; end case; end record with Unchecked_Union, Size => 32, Volatile_Full_Access, Bit_Order => System.Low_Order_First; for F11R_Register use record Val at 0 range 0 .. 31; Arr at 0 range 0 .. 31; end record; -- F12R_FB array type F12R_FB_Field_Array is array (0 .. 31) of Boolean with Component_Size => 1, Size => 32; -- Filter bank 4 register 1 type F12R_Register (As_Array : Boolean := False) is record case As_Array is when False => -- FB as a value Val : HAL.UInt32; when True => -- FB as an array Arr : F12R_FB_Field_Array; end case; end record with Unchecked_Union, Size => 32, Volatile_Full_Access, Bit_Order => System.Low_Order_First; for F12R_Register use record Val at 0 range 0 .. 31; Arr at 0 range 0 .. 31; end record; -- F13R_FB array type F13R_FB_Field_Array is array (0 .. 31) of Boolean with Component_Size => 1, Size => 32; -- Filter bank 13 register 1 type F13R_Register (As_Array : Boolean := False) is record case As_Array is when False => -- FB as a value Val : HAL.UInt32; when True => -- FB as an array Arr : F13R_FB_Field_Array; end case; end record with Unchecked_Union, Size => 32, Volatile_Full_Access, Bit_Order => System.Low_Order_First; for F13R_Register use record Val at 0 range 0 .. 31; Arr at 0 range 0 .. 31; end record; ----------------- -- Peripherals -- ----------------- -- Controller area network type CAN_Peripheral is record -- CAN_MCR CAN_MCR : aliased CAN_MCR_Register; -- CAN_MSR CAN_MSR : aliased CAN_MSR_Register; -- CAN_TSR CAN_TSR : aliased CAN_TSR_Register; -- CAN_RF0R CAN_RF0R : aliased CAN_RF0R_Register; -- CAN_RF1R CAN_RF1R : aliased CAN_RF1R_Register; -- CAN_IER CAN_IER : aliased CAN_IER_Register; -- CAN_ESR CAN_ESR : aliased CAN_ESR_Register; -- CAN_BTR CAN_BTR : aliased CAN_BTR_Register; -- CAN_TI0R CAN_TI0R : aliased CAN_TI0R_Register; -- CAN_TDT0R CAN_TDT0R : aliased CAN_TDT0R_Register; -- CAN_TDL0R CAN_TDL0R : aliased CAN_TDL0R_Register; -- CAN_TDH0R CAN_TDH0R : aliased CAN_TDH0R_Register; -- CAN_TI1R CAN_TI1R : aliased CAN_TI1R_Register; -- CAN_TDT1R CAN_TDT1R : aliased CAN_TDT1R_Register; -- CAN_TDL1R CAN_TDL1R : aliased CAN_TDL1R_Register; -- CAN_TDH1R CAN_TDH1R : aliased CAN_TDH1R_Register; -- CAN_TI2R CAN_TI2R : aliased CAN_TI2R_Register; -- CAN_TDT2R CAN_TDT2R : aliased CAN_TDT2R_Register; -- CAN_TDL2R CAN_TDL2R : aliased CAN_TDL2R_Register; -- CAN_TDH2R CAN_TDH2R : aliased CAN_TDH2R_Register; -- CAN_RI0R CAN_RI0R : aliased CAN_RI0R_Register; -- CAN_RDT0R CAN_RDT0R : aliased CAN_RDT0R_Register; -- CAN_RDL0R CAN_RDL0R : aliased CAN_RDL0R_Register; -- CAN_RDH0R CAN_RDH0R : aliased CAN_RDH0R_Register; -- CAN_RI1R CAN_RI1R : aliased CAN_RI1R_Register; -- CAN_RDT1R CAN_RDT1R : aliased CAN_RDT1R_Register; -- CAN_RDL1R CAN_RDL1R : aliased CAN_RDL1R_Register; -- CAN_RDH1R CAN_RDH1R : aliased CAN_RDH1R_Register; -- CAN_FMR CAN_FMR : aliased CAN_FMR_Register; -- CAN_FM1R CAN_FM1R : aliased CAN_FM1R_Register; -- CAN_FS1R CAN_FS1R : aliased CAN_FS1R_Register; -- CAN_FFA1R CAN_FFA1R : aliased CAN_FFA1R_Register; -- CAN_FA1R CAN_FA1R : aliased CAN_FA1R_Register; -- Filter bank 0 register 1 F0R1 : aliased F0R_Register; -- Filter bank 0 register 2 F0R2 : aliased F0R_Register; -- Filter bank 1 register 1 F1R1 : aliased F1R_Register; -- Filter bank 1 register 2 F1R2 : aliased F1R_Register; -- Filter bank 2 register 1 F2R1 : aliased F2R_Register; -- Filter bank 2 register 2 F2R2 : aliased F2R_Register; -- Filter bank 3 register 1 F3R1 : aliased F3R_Register; -- Filter bank 3 register 2 F3R2 : aliased F3R_Register; -- Filter bank 4 register 1 F4R1 : aliased F4R_Register; -- Filter bank 4 register 2 F4R2 : aliased F4R_Register; -- Filter bank 5 register 1 F5R1 : aliased F5R_Register; -- Filter bank 5 register 2 F5R2 : aliased F5R_Register; -- Filter bank 6 register 1 F6R1 : aliased F6R_Register; -- Filter bank 6 register 2 F6R2 : aliased F6R_Register; -- Filter bank 7 register 1 F7R1 : aliased F7R_Register; -- Filter bank 7 register 2 F7R2 : aliased F7R_Register; -- Filter bank 8 register 1 F8R1 : aliased F8R_Register; -- Filter bank 8 register 2 F8R2 : aliased F8R_Register; -- Filter bank 9 register 1 F9R1 : aliased F9R_Register; -- Filter bank 9 register 2 F9R2 : aliased F9R_Register; -- Filter bank 10 register 1 F10R1 : aliased F10R_Register; -- Filter bank 10 register 2 F10R2 : aliased F10R_Register; -- Filter bank 11 register 1 F11R1 : aliased F11R_Register; -- Filter bank 11 register 2 F11R2 : aliased F11R_Register; -- Filter bank 4 register 1 F12R1 : aliased F12R_Register; -- Filter bank 12 register 2 F12R2 : aliased F12R_Register; -- Filter bank 13 register 1 F13R1 : aliased F13R_Register; -- Filter bank 13 register 2 F13R2 : aliased F13R_Register; end record with Volatile; for CAN_Peripheral use record CAN_MCR at 16#0# range 0 .. 31; CAN_MSR at 16#4# range 0 .. 31; CAN_TSR at 16#8# range 0 .. 31; CAN_RF0R at 16#C# range 0 .. 31; CAN_RF1R at 16#10# range 0 .. 31; CAN_IER at 16#14# range 0 .. 31; CAN_ESR at 16#18# range 0 .. 31; CAN_BTR at 16#1C# range 0 .. 31; CAN_TI0R at 16#180# range 0 .. 31; CAN_TDT0R at 16#184# range 0 .. 31; CAN_TDL0R at 16#188# range 0 .. 31; CAN_TDH0R at 16#18C# range 0 .. 31; CAN_TI1R at 16#190# range 0 .. 31; CAN_TDT1R at 16#194# range 0 .. 31; CAN_TDL1R at 16#198# range 0 .. 31; CAN_TDH1R at 16#19C# range 0 .. 31; CAN_TI2R at 16#1A0# range 0 .. 31; CAN_TDT2R at 16#1A4# range 0 .. 31; CAN_TDL2R at 16#1A8# range 0 .. 31; CAN_TDH2R at 16#1AC# range 0 .. 31; CAN_RI0R at 16#1B0# range 0 .. 31; CAN_RDT0R at 16#1B4# range 0 .. 31; CAN_RDL0R at 16#1B8# range 0 .. 31; CAN_RDH0R at 16#1BC# range 0 .. 31; CAN_RI1R at 16#1C0# range 0 .. 31; CAN_RDT1R at 16#1C4# range 0 .. 31; CAN_RDL1R at 16#1C8# range 0 .. 31; CAN_RDH1R at 16#1CC# range 0 .. 31; CAN_FMR at 16#200# range 0 .. 31; CAN_FM1R at 16#204# range 0 .. 31; CAN_FS1R at 16#20C# range 0 .. 31; CAN_FFA1R at 16#214# range 0 .. 31; CAN_FA1R at 16#21C# range 0 .. 31; F0R1 at 16#240# range 0 .. 31; F0R2 at 16#244# range 0 .. 31; F1R1 at 16#248# range 0 .. 31; F1R2 at 16#24C# range 0 .. 31; F2R1 at 16#250# range 0 .. 31; F2R2 at 16#254# range 0 .. 31; F3R1 at 16#258# range 0 .. 31; F3R2 at 16#25C# range 0 .. 31; F4R1 at 16#260# range 0 .. 31; F4R2 at 16#264# range 0 .. 31; F5R1 at 16#268# range 0 .. 31; F5R2 at 16#26C# range 0 .. 31; F6R1 at 16#270# range 0 .. 31; F6R2 at 16#274# range 0 .. 31; F7R1 at 16#278# range 0 .. 31; F7R2 at 16#27C# range 0 .. 31; F8R1 at 16#280# range 0 .. 31; F8R2 at 16#284# range 0 .. 31; F9R1 at 16#288# range 0 .. 31; F9R2 at 16#28C# range 0 .. 31; F10R1 at 16#290# range 0 .. 31; F10R2 at 16#294# range 0 .. 31; F11R1 at 16#298# range 0 .. 31; F11R2 at 16#29C# range 0 .. 31; F12R1 at 16#2A0# range 0 .. 31; F12R2 at 16#2A4# range 0 .. 31; F13R1 at 16#2A8# range 0 .. 31; F13R2 at 16#2AC# range 0 .. 31; end record; -- Controller area network CAN1_Periph : aliased CAN_Peripheral with Import, Address => System'To_Address (16#40006400#); -- Controller area network CAN2_Periph : aliased CAN_Peripheral with Import, Address => System'To_Address (16#40006800#); end STM32_SVD.CAN;
with Big_Integers; use Big_Integers; with Types; use Types; with Conversion; use Conversion; package Curve25519_Mult with SPARK_Mode is function Multiply (X, Y : Integer_255) return Product_Integer with Pre => All_In_Range (X, Y, Min_Multiply, Max_Multiply), Post => +Multiply'Result = (+X) * (+Y); end Curve25519_Mult;
------------------------------------------------------------------------------ -- -- -- GNAT COMPILER COMPONENTS -- -- -- -- P R J . E N V -- -- -- -- S p e c -- -- -- -- $Revision$ -- -- -- Copyright (C) 2001 Free Software Foundation, Inc. -- -- -- -- GNAT is free software; you can redistribute it and/or modify it under -- -- terms of the GNU General Public License as published by the Free Soft- -- -- ware Foundation; either version 2, or (at your option) any later ver- -- -- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -- -- for more details. You should have received a copy of the GNU General -- -- Public License distributed with GNAT; see file COPYING. If not, write -- -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, -- -- MA 02111-1307, USA. -- -- -- -- GNAT was originally developed by the GNAT team at New York University. -- -- Extensive contributions were provided by Ada Core Technologies Inc. -- -- -- ------------------------------------------------------------------------------ -- This package implements services for Project-aware tools, related -- to the environment (gnat.adc, ADA_INCLUDE_PATH, ADA_OBJECTS_PATH) with GNAT.OS_Lib; use GNAT.OS_Lib; package Prj.Env is procedure Initialize; -- Put Standard_Naming_Data into Namings table (called by Prj.Initialize) procedure Print_Sources; -- Output the list of sources, after Project files have been scanned procedure Create_Mapping_File (Name : in out Temp_File_Name); -- Create a temporary mapping file. For each unit, put the mapping of -- its spec and or body to its file name and path name in this file. procedure Create_Config_Pragmas_File (For_Project : Project_Id; Main_Project : Project_Id); -- If there needs to have SFN pragmas, either for non standard naming -- schemes or for individual units, or if Global_Configuration_Pragmas -- has been specified in package gnatmake of the main project, or if -- Local_Configuration_Pragmas has been specified in package Compiler -- of the main project, build (if needed) a temporary file that contains -- all configuration pragmas, and specify the configuration pragmas file -- in the project data. function Ada_Include_Path (Project : Project_Id) return String_Access; -- Get the ADA_INCLUDE_PATH of a Project file. For the first call, compute -- it and cache it. function Ada_Objects_Path (Project : Project_Id; Including_Libraries : Boolean := True) return String_Access; -- Get the ADA_OBJECTS_PATH of a Project file. For the first call, compute -- it and cache it. When Including_Libraries is False, do not include the -- object directories of the library projects, and do not cache the result. function Path_Name_Of_Library_Unit_Body (Name : String; Project : Project_Id) return String; -- Returns the Path of a library unit. function File_Name_Of_Library_Unit_Body (Name : String; Project : Project_Id) return String; -- Returns the file name of a library unit, in canonical case. Name may or -- may not have an extension (corresponding to the naming scheme of the -- project). If there is no body with this name, but there is a spec, the -- name of the spec is returned. If neither a body or a spec can be found, -- return an empty string. procedure Get_Reference (Source_File_Name : String; Project : out Project_Id; Path : out Name_Id); -- Returns the project of a source. generic with procedure Action (Path : String); procedure For_All_Source_Dirs (Project : Project_Id); -- Iterate through all the source directories of a project, -- including those of imported or modified projects. generic with procedure Action (Path : String); procedure For_All_Object_Dirs (Project : Project_Id); -- Iterate through all the object directories of a project, -- including those of imported or modified projects. end Prj.Env;
--////////////////////////////////////////////////////////// -- SFML - Simple and Fast Multimedia Library -- Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) -- 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. --////////////////////////////////////////////////////////// --////////////////////////////////////////////////////////// with Sf.System.Time; package Sf.Network.IpAddress is --////////////////////////////////////////////////////////// --////////////////////////////////////////////////////////// --////////////////////////////////////////////////////////// --////////////////////////////////////////////////////////// --////////////////////////////////////////////////////////// --/ @brief Encapsulate an IPv4 network address --/ --////////////////////////////////////////////////////////// type sfAddress_Array is array (0 .. 15) of aliased sfInt8; type sfIpAddress is record address : sfAddress_Array; end record; --////////////////////////////////////////////////////////// --/ @brief Empty object that represents invalid addresses --/ --////////////////////////////////////////////////////////// None : aliased constant sfIpAddress; --////////////////////////////////////////////////////////// --/ @brief Value representing any address (0.0.0.0) --/ --////////////////////////////////////////////////////////// Any : aliased constant sfIpAddress; --////////////////////////////////////////////////////////// --/ @brief Local host IP address (127.0.0.1, or "localhost") --/ --////////////////////////////////////////////////////////// LocalHost : aliased constant sfIpAddress; --////////////////////////////////////////////////////////// --/ @brief UDP broadcast address (255.255.255.255) --/ --////////////////////////////////////////////////////////// Broadcast : aliased constant sfIpAddress; --////////////////////////////////////////////////////////// --/ @brief Create an address from a string --/ --/ Here @a address can be either a decimal address --/ (ex: "192.168.1.56") or a network name (ex: "localhost"). --/ --/ @param str IP address or network name --/ --/ @return Resulting address --/ --////////////////////////////////////////////////////////// function fromString (str : String) return sfIpAddress; --////////////////////////////////////////////////////////// --/ @brief Create an address from 4 bytes --/ --/ Calling sfIpAddress_fromBytes(a, b, c, d) is equivalent --/ to calling sfIpAddress_fromString("a.b.c.d"), but safer --/ as it doesn't have to parse a string to get the address --/ components. --/ --/ @param byte0 First byte of the address --/ @param byte1 Second byte of the address --/ @param byte2 Third byte of the address --/ @param byte3 Fourth byte of the address --/ --/ @return Resulting address --/ --////////////////////////////////////////////////////////// function fromBytes (byte0 : sfUint8; byte1 : sfUint8; byte2 : sfUint8; byte3 : sfUint8) return sfIpAddress; --////////////////////////////////////////////////////////// --/ @brief Construct an address from a 32-bits integer --/ --/ This function uses the internal representation of --/ the address directly. It should be used for optimization --/ purposes, and only if you got that representation from --/ sfIpAddress_ToInteger. --/ --/ @param address 4 bytes of the address packed into a 32-bits integer --/ --/ @return Resulting address --/ --////////////////////////////////////////////////////////// function fromInteger (address : sfUint32) return sfIpAddress; --////////////////////////////////////////////////////////// --/ @brief Get a string representation of an address --/ --/ The returned string is the decimal representation of the --/ IP address (like "192.168.1.56"), even if it was constructed --/ from a host name. --/ --/ @param address Address object --/ @param str String where the string representation will be stored --/ --////////////////////////////////////////////////////////// procedure toString (address : sfIpAddress; str : out String); --////////////////////////////////////////////////////////// --/ @brief Get an integer representation of the address --/ --/ The returned number is the internal representation of the --/ address, and should be used for optimization purposes only --/ (like sending the address through a socket). --/ The integer produced by this function can then be converted --/ back to a sfIpAddress with sfIpAddress_FromInteger. --/ --/ @param address Address object --/ --/ @return 32-bits sfUint32 integer representation of the address --/ --////////////////////////////////////////////////////////// function toInteger (address : sfIpAddress) return sfUint32; --////////////////////////////////////////////////////////// --/ @brief Get the computer's local address --/ --/ The local address is the address of the computer from the --/ LAN point of view, i.e. something like 192.168.1.56. It is --/ meaningful only for communications over the local network. --/ Unlike sfIpAddress_getPublicAddress, this function is fast --/ and may be used safely anywhere. --/ --/ @return Local IP address of the computer --/ --////////////////////////////////////////////////////////// function getLocalAddress return sfIpAddress; --////////////////////////////////////////////////////////// --/ @brief Get the computer's public address --/ --/ The public address is the address of the computer from the --/ internet point of view, i.e. something like 89.54.1.169. --/ It is necessary for communications over the world wide web. --/ The only way to get a public address is to ask it to a --/ distant website; as a consequence, this function depends on --/ both your network connection and the server, and may be --/ very slow. You should use it as few as possible. Because --/ this function depends on the network connection and on a distant --/ server, you may use a time limit if you don't want your program --/ to be possibly stuck waiting in case there is a problem; use --/ 0 to deactivate this limit. --/ --/ @param timeout Maximum time to wait --/ --/ @return Public IP address of the computer --/ --////////////////////////////////////////////////////////// function getPublicAddress (timeout : Sf.System.Time.sfTime) return sfIpAddress; private pragma Convention (C_Pass_By_Copy, sfIpAddress); pragma Import (C, None, "sfIpAddress_None"); pragma Import (C, Any, "sfIpAddress_Any"); pragma Import (C, LocalHost, "sfIpAddress_LocalHost"); pragma Import (C, Broadcast, "sfIpAddress_Broadcast"); pragma Import (C, fromBytes, "sfIpAddress_fromBytes"); pragma Import (C, fromInteger, "sfIpAddress_fromInteger"); pragma Import (C, toInteger, "sfIpAddress_toInteger"); pragma Import (C, getLocalAddress, "sfIpAddress_getLocalAddress"); pragma Import (C, getPublicAddress, "sfIpAddress_getPublicAddress"); end Sf.Network.IpAddress;
-- C35A05D.ADA -- Grant of Unlimited Rights -- -- Under contracts F33600-87-D-0337, F33600-84-D-0280, MDA903-79-C-0687, -- F08630-91-C-0015, and DCA100-97-D-0025, the U.S. Government obtained -- unlimited rights in the software and documentation contained herein. -- Unlimited rights are defined in DFAR 252.227-7013(a)(19). By making -- this public release, the Government intends to confer upon all -- recipients unlimited rights equal to those held by the Government. -- These rights include rights to use, duplicate, release or disclose the -- released technical data and computer software in whole or in part, in -- any manner and for any purpose whatsoever, and to have or permit others -- to do so. -- -- DISCLAIMER -- -- ALL MATERIALS OR INFORMATION HEREIN RELEASED, MADE AVAILABLE OR -- DISCLOSED ARE AS IS. THE GOVERNMENT MAKES NO EXPRESS OR IMPLIED -- WARRANTY AS TO ANY MATTER WHATSOEVER, INCLUDING THE CONDITIONS OF THE -- SOFTWARE, DOCUMENTATION OR OTHER INFORMATION RELEASED, MADE AVAILABLE -- OR DISCLOSED, OR THE OWNERSHIP, MERCHANTABILITY, OR FITNESS FOR A -- PARTICULAR PURPOSE OF SAID MATERIAL. --* -- CHECK THAT FOR FIXED POINT TYPES THE FORE AND AFT ATTRIBUTES YIELD -- THE CORRECT VALUES. -- CASE D: TYPES TYPICAL OF APPLICATIONS USING FIXED POINT ARITHMETIC. -- WRG 8/14/86 WITH REPORT; USE REPORT; PROCEDURE C35A05D IS PI : CONSTANT := 3.14159_26535_89793_23846; TWO_PI : CONSTANT := 2 * PI; HALF_PI : CONSTANT := PI / 2; MM : CONSTANT := 23; -- THE NAME OF EACH TYPE OR SUBTYPE ENDS WITH THAT TYPE'S -- 'MANTISSA VALUE. TYPE MICRO_ANGLE_ERROR_M15 IS DELTA 16.0 RANGE -(2.0 ** 19) .. 2.0 ** 19; TYPE TRACK_RANGE_M15 IS DELTA 0.125 RANGE -(2.0 ** 12) .. 2.0 ** 12; TYPE SECONDS_MM IS DELTA 2.0 ** (8 - MM) RANGE -(2.0 ** 8) .. 2.0 ** 8; TYPE RANGE_CELL_MM IS DELTA 2.0 ** (-5) RANGE -(2.0 ** (MM - 5) ) .. 2.0 ** (MM - 5); TYPE PIXEL_M10 IS DELTA 1.0 / 1024.0 RANGE 0.0 .. 1.0; TYPE RULER_M8 IS DELTA 1.0 / 16.0 RANGE 0.0 .. 12.0; TYPE HOURS_M16 IS DELTA 24.0 * 2.0 ** (-15) RANGE 0.0 .. 24.0; TYPE MILES_M16 IS DELTA 3000.0 * 2.0 ** (-15) RANGE 0.0 .. 3000.0; TYPE SYMMETRIC_DEGREES_M7 IS DELTA 2.0 RANGE -180.0 .. 180.0; TYPE NATURAL_DEGREES_M15 IS DELTA 2.0 ** (-6) RANGE 0.0 .. 360.0; TYPE SYMMETRIC_RADIANS_M16 IS DELTA PI * 2.0 ** (-15) RANGE -PI .. PI; TYPE NATURAL_RADIANS_M8 IS DELTA TWO_PI * 2.0 ** ( -7) RANGE 0.0 .. TWO_PI; ------------------------------------------------------------------- SUBTYPE ST_MILES_M8 IS MILES_M16 DELTA 3000.0 * 2.0 ** (-15) RANGE 0.0 .. 10.0; SUBTYPE ST_NATURAL_DEGREES_M11 IS NATURAL_DEGREES_M15 DELTA 0.25 RANGE 0.0 .. 360.0; SUBTYPE ST_SYMMETRIC_RADIANS_M8 IS SYMMETRIC_RADIANS_M16 DELTA HALF_PI * 2.0 ** (-7) RANGE -HALF_PI .. HALF_PI; ------------------------------------------------------------------- PROCEDURE CHECK_FORE_AND_AFT (NAME : STRING; ACTUAL_FORE : INTEGER; CORRECT_FORE : POSITIVE; ACTUAL_AFT : INTEGER; CORRECT_AFT : POSITIVE) IS BEGIN IF ACTUAL_FORE /= IDENT_INT (CORRECT_FORE) THEN FAILED (NAME & "'FORE =" & INTEGER'IMAGE(ACTUAL_FORE) ); END IF; IF ACTUAL_AFT /= IDENT_INT (CORRECT_AFT) THEN FAILED (NAME & "'AFT =" & INTEGER'IMAGE(ACTUAL_AFT) ); END IF; END CHECK_FORE_AND_AFT; BEGIN TEST ("C35A05D", "CHECK THAT FOR FIXED POINT TYPES THE FORE AND " & "AFT ATTRIBUTES YIELD THE CORRECT VALUES - " & "TYPICAL TYPES"); CHECK_FORE_AND_AFT ("MICRO_ANGLE_ERROR_M15", MICRO_ANGLE_ERROR_M15'FORE, 7, MICRO_ANGLE_ERROR_M15'AFT, 1); CHECK_FORE_AND_AFT ("TRACK_RANGE_M15", TRACK_RANGE_M15'FORE, 5, TRACK_RANGE_M15'AFT, 1); CHECK_FORE_AND_AFT ("SECONDS_MM", SECONDS_MM'FORE, 4, SECONDS_MM'AFT, 5); CHECK_FORE_AND_AFT ("RANGE_CELL_MM", RANGE_CELL_MM'FORE, 7, RANGE_CELL_MM'AFT, 2); CHECK_FORE_AND_AFT ("PIXEL_M10", PIXEL_M10'FORE, 2, PIXEL_M10'AFT, 4); CHECK_FORE_AND_AFT ("RULER_M8", RULER_M8'FORE, 3, RULER_M8'AFT, 2); CHECK_FORE_AND_AFT ("HOURS_M16", HOURS_M16'FORE, 3, HOURS_M16'AFT, 4); CHECK_FORE_AND_AFT ("MILES_M16", MILES_M16'FORE, 5, MILES_M16'AFT, 2); CHECK_FORE_AND_AFT ("SYMMETRIC_DEGREES_M7", SYMMETRIC_DEGREES_M7'FORE, 4, SYMMETRIC_DEGREES_M7'AFT, 1); CHECK_FORE_AND_AFT ("NATURAL_DEGREES_M15", NATURAL_DEGREES_M15'FORE, 4, NATURAL_DEGREES_M15'AFT, 2); CHECK_FORE_AND_AFT ("SYMMETRIC_RADIANS_M16", SYMMETRIC_RADIANS_M16'FORE, 2, SYMMETRIC_RADIANS_M16'AFT, 5); CHECK_FORE_AND_AFT ("NATURAL_RADIANS_M8", NATURAL_RADIANS_M8'FORE, 2, NATURAL_RADIANS_M8'AFT, 2); CHECK_FORE_AND_AFT ("ST_MILES_M8", ST_MILES_M8'FORE, 3, ST_MILES_M8'AFT, 2); CHECK_FORE_AND_AFT ("ST_NATURAL_DEGREES_M11", ST_NATURAL_DEGREES_M11'FORE, 4, ST_NATURAL_DEGREES_M11'AFT, 1); CHECK_FORE_AND_AFT ("ST_SYMMETRIC_RADIANS_M8", ST_SYMMETRIC_RADIANS_M8'FORE, 2, ST_SYMMETRIC_RADIANS_M8'AFT, 2); RESULT; END C35A05D;
----------------------------------------------------------------------- -- babel-archivers -- File archiver -- Copyright (C) 2015 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 Babel.Streams; package Babel.Archivers is type Archiver_Type is abstract tagged limited private; type Archiver_Access is access all Archiver_Type'Class; -- Create an archive that will write on the given data stream. procedure Create (Archiver : in out Archiver_Type; Stream : in Babel.Streams.Stream_Access) is abstract; -- Append the file at the end of the archiver. procedure Append_File (Archiver : in out Archiver_Type; File : in Babel.Files.File_Type) is abstract; -- Open the archiver to read the given data stream. procedure Open (Archiver : in out Archiver_Type; Stream : in Babel.Streams.Stream_Access) is abstract; -- Returns true if the archiver contains another file entry. function Has_Element (Archiver : in Archiver_Type) return Boolean is abstract; -- Read the next file entry from the archive. procedure Next (Archiver : in out Archiver_Type) is abstract; -- Get the current file entry from the archive. function Element (Archiver : in Archiver_Type) return Babel.Files.File_Type is abstract; -- Open a stream to read the content of the file stored in the archive. procedure Open_File (Archiver : in out Archiver_Type; Stream : out Babel.Streams.Stream_Access) is abstract; -- Flush the data stream. procedure Flush (Archiver : in out Archiver_Type) is null; private type Archiver_Type is abstract limited new Ada.Finalization.Limited_Controlled with record Input : Babel.Streams.Stream_Access; Output : Babel.Streams.Stream_Access; end record; -- Release the archive internal storage. overriding procedure Finalize (Archiver : in out Archiver_Type); end Babel.Archivers;
with Text_IO; use Text_IO; procedure Hello is a: Natural := 0; begin Put_Line("Helloó, World!"); end Hello;
generic type Element_Type is private; package Generic_Stack is type T is limited private; procedure Push( Stack: in out T; Element: in Element_Type ); procedure Pop( Stack: in out T; Element: out Element_Type ); procedure Peek( Stack: in out T; Element: out Element_Type ); function Empty( Stack: in T ) return Boolean; procedure Reset( Stack: in out T ); Underflow : exception; private type Stack_Node; type Stack_Node_Ptr is access Stack_Node; type Stack_Node is record Data : Element_Type; Next : Stack_Node_Ptr; end record; type T is record Head : Stack_Node_Ptr; end record; end Generic_Stack;
package body SDL_ttf is -- ==================================== function Open_Font (file : String; ptsize : C.int) return Font_ptr is begin return OpenFont (CS.New_String (file), ptsize); end Open_Font; -- ==================================== function Open_Font_Index (file : String; ptsize : C.int; index : C.long) return Font_ptr is begin return OpenFontIndex (CS.New_String (file), ptsize, index); end Open_Font_Index; -- ==================================== function Font_Face_Family_Name (font : Font_ptr) return String is begin return CS.Value (FontFaceFamilyName (font)); end Font_Face_Family_Name; -- ==================================== function Font_Face_Style_Name (font : Font_ptr) return String is begin return CS.Value (FontFaceStyleName (font)); end Font_Face_Style_Name; -- ==================================== function Size_Text (font : Font_ptr; text : String; w, h : C.int) return C.int is begin return (SizeText (font, CS.New_String (text), w, h)); end Size_Text; -- ==================================== function Size_UTF8 (font : Font_ptr; text : String; w, h : C.int) return C.int is begin return (SizeUTF8 (font, CS.New_String (text), w, h)); end Size_UTF8; -- ==================================== function Render_Text_Solid (font : Font_ptr; text : String; fg : V.Color) return V.Surface_ptr is begin return RenderText_Solid (font, CS.New_String (text), fg); end Render_Text_Solid; -- ==================================== function Render_UTF8_Solid (font : Font_ptr; text : String; fg : V.Color) return V.Surface_ptr is begin return RenderUTF8_Solid (font, CS.New_String (text), fg); end Render_UTF8_Solid; -- ==================================== function Render_Text_Shaded (font : Font_ptr; text : String; fg : V.Color; bg : V.Color) return V.Surface_ptr is begin return RenderText_Shaded (font, CS.New_String (text), fg, bg); end Render_Text_Shaded; -- ==================================== function Render_UTF8_Shaded (font : Font_ptr; text : String; fg : V.Color; bg : V.Color) return V.Surface_ptr is begin return RenderUTF8_Shaded (font, CS.New_String (text), fg, bg); end Render_UTF8_Shaded; -- ==================================== function Render_Text_Blended (font : Font_ptr; text : String; fg : V.Color) return V.Surface is begin return RenderText_Blended (font, CS.New_String (text), fg); end Render_Text_Blended; -- ==================================== function Render_UTF8_Blended (font : Font_ptr; text : String; fg : V.Color) return V.Surface is begin return RenderUTF8_Blended (font, CS.New_String (text), fg); end Render_UTF8_Blended; -- ==================================== procedure Set_Font_Style (font : Font_ptr; style : TTF_STYLE) is begin SetFontStyle (font, style); end Set_Font_Style; end SDL_ttf;
with Interfaces.C; use Interfaces.C; with System; package Warn12_Pkg is Anysize_Array: constant := 0; type Sid_And_Attributes is record Sid : System.Address; Attributes : Interfaces.C.Unsigned_Long; end record; type Sid_And_Attributes_Array is array (Integer range 0..Anysize_Array) of aliased Sid_And_Attributes; type Token_Groups is record GroupCount : Interfaces.C.Unsigned_Long; Groups : Sid_And_Attributes_Array; end record; end Warn12_Pkg;
------------------------------------------------------------------------------ -- -- -- GNAT COMPILER COMPONENTS -- -- -- -- P R J . S T R T -- -- -- -- S p e c -- -- -- -- $Revision$ -- -- -- Copyright (C) 2001 Free Software Foundation, Inc. -- -- -- -- GNAT is free software; you can redistribute it and/or modify it under -- -- terms of the GNU General Public License as published by the Free Soft- -- -- ware Foundation; either version 2, or (at your option) any later ver- -- -- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -- -- for more details. You should have received a copy of the GNU General -- -- Public License distributed with GNAT; see file COPYING. If not, write -- -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, -- -- MA 02111-1307, USA. -- -- -- -- GNAT was originally developed by the GNAT team at New York University. -- -- Extensive contributions were provided by Ada Core Technologies Inc. -- -- -- ------------------------------------------------------------------------------ -- -- This package implements parsing of string expressions in project files. with Prj.Tree; use Prj.Tree; private package Prj.Strt is procedure Parse_String_Type_List (First_String : out Project_Node_Id); -- Get the list of literal strings that are allowed for a typed string. -- On entry, the current token is the first literal string following -- a left parenthesis in a string type declaration such as: -- type Toto is ("string_1", "string_2", "string_3"); -- On exit, the current token is the right parenthesis. -- The parameter First_String is a node that contained the first -- literal string of the string type, linked with the following -- literal strings. -- -- Report an error if -- - a literal string is not found at the beginning of the list -- or after a comma -- - two literal strings in the list are equal procedure Start_New_Case_Construction (String_Type : Project_Node_Id); -- This procedure is called at the beginning of a case construction -- The parameter String_Type is the node for the string type -- of the case label variable. -- The different literal strings of the string type are stored -- into a table to be checked against the case labels of the -- case construction. procedure End_Case_Construction; -- This procedure is called at the end of a case construction -- to remove the case labels and to restore the previous state. -- In particular, in the case of nested case constructions, -- the case labels of the enclosing case construction are restored. procedure Parse_Choice_List (First_Choice : out Project_Node_Id); -- Get the label for a choice list. -- Report an error if -- - a case label is not a literal string -- - a case label is not in the typed string list -- - the same case label is repeated in the same case construction procedure Parse_Expression (Expression : out Project_Node_Id; Current_Project : Project_Node_Id; Current_Package : Project_Node_Id); -- Parse a simple string expression or a string list expression. -- Current_Project is the node of the project file being parsed. -- Current_Package is the node of the package being parsed, -- or Empty_Node when we are at the project level (not in a package). -- On exit, Expression is the node of the expression that has -- been parsed. procedure Parse_Variable_Reference (Variable : out Project_Node_Id; Current_Project : Project_Node_Id; Current_Package : Project_Node_Id); -- Parse a variable or attribute reference. -- Used internally (in expressions) and for case variables (in Prj.Dect). -- Current_Package is the node of the package being parsed, -- or Empty_Node when we are at the project level (not in a package). -- On exit, Variable is the node of the variable or attribute reference. -- A variable reference is made of one to three simple names. -- An attribute reference is made of one or two simple names, -- followed by an apostroph, followed by the attribute simple name. end Prj.Strt;
with Agar.Core.Thin; with Interfaces.C; package body Agar.Core.Config is package C renames Interfaces.C; use type C.int; function Load return Boolean is begin return Thin.Config.Load = 0; end Load; function Save return Boolean is begin return Thin.Config.Save = 0; end Save; end Agar.Core.Config;
with Ada.Text_IO; use Ada.Text_IO; package body Problem_11 is function Solution_1( G : Grid ) return Integer is Column, Row : Natural := 0; Highest_Row : constant Natural := G'Length(1); Highest_Column : constant Natural := G'Length(2); Max : Integer := 0; Temp : Natural := 0; begin for I in 0 .. Highest_Row - 1 loop for J in 0 .. Highest_Column - 1 loop if I <= (Highest_Row - 4) then Temp := G(I,J) * G(I+1,J) * G(I+2,J) * G(I+3,J); if Temp > Max then Max := Temp; end if; end if; if J <= ( Highest_Column - 4 ) then Temp := G(I,J) * G(I,J+1) * G(I,J+2) * G(I,J+3); if Temp > Max then Max := Temp; end if; end if; if I <= (Highest_Row - 4) and J <= (Highest_Column - 4) then Temp := G(I,J) * G(I+1,J+1) * G(I+2,J+2) * G(I+3,J+3); if Temp > Max then Max := Temp; end if; end if; if I >= 4 and J <= (Highest_Column - 4) then Temp := G(I,J) * G(I-1,J+1) * G(I-2,J+2) * G(I-3,J+3); if Temp > Max then Max := Temp; end if; end if; end loop; end loop; return Max; end Solution_1; procedure Test_Solution_1 is Input : constant Grid := ( (8,2,22,97,38,15,0,40,0,75,4,5,7,78,52,12,50,77,91,8), (49,49,99,40,27,81,18,57,60,87,17,40,98,43,69,48,4,56,62,0), (81,49,31,73,55,79,14,29,93,71,40,67,53,88,30,3,49,13,36,65), (52,70,95,23,4,60,11,42,69,24,68,56,1,32,56,71,37,2,36,91), (22,31,16,71,51,67,63,89,41,92,36,54,22,40,40,28,66,33,13,80), (24,47,32,60,99,3,45,2,44,75,33,53,78,36,84,20,35,17,12,50), (32,98,81,28,64,23,67,10,26,38,40,67,59,54,70,66,18,38,64,70), (67,26,20,68,2,62,12,20,95,63,94,39,63,8,40,91,66,49,94,21), (24,55,58,5,66,73,99,26,97,17,78,78,96,83,14,88,34,89,63,72), (21,36,23,9,75,0,76,44,20,45,35,14,0,61,33,97,34,31,33,95), (78,17,53,28,22,75,31,67,15,94,3,80,4,62,16,14,9,53,56,92), (16,39,5,42,96,35,31,47,55,58,88,24,0,17,54,24,36,29,85,57), (86,56,0,48,35,71,89,7,5,44,44,37,44,60,21,58,51,54,17,58), (19,80,81,68,5,94,47,69,28,73,92,13,86,52,17,77,4,89,55,40), (4,52,8,83,97,35,99,16,7,97,57,32,16,26,26,79,33,27,98,66), (88,36,68,87,57,62,20,72,3,46,33,67,46,55,12,32,63,93,53,69), (4,42,16,73,38,25,39,11,24,94,72,18,8,46,29,32,40,62,76,36), (20,69,36,41,72,30,23,88,34,62,99,69,82,67,59,85,74,4,36,16), (20,73,35,29,78,31,90,1,74,31,49,71,48,86,81,16,23,57,5,54), (1,70,54,71,83,51,54,69,16,92,33,48,61,43,52,1,89,19,67,48)); Solution : constant Integer := 70600674; begin Assert( Solution_1(Input) = Solution ); end Test_Solution_1; function Get_Solutions return Solution_Case is Ret : Solution_Case; begin Set_Name( Ret, "Problem 11"); Add_Test( Ret, Test_Solution_1'Access ); return Ret; end Get_Solutions; end Problem_11;
-- Spécification du module Piles. generic Capacite : Integer; -- Nombre maximal d'éléments qu'une pile peut contenir type T_Element is private; -- Type des éléments de la pile package Piles is type T_Pile is limited private; --! "très privé" en Algorithmique ! --! Sur un type privé, on a droit à l'affectation (:=) et l'égalité (=). --! On perd ces opérations avec un type "limited private" (très privé). -- Initilaiser une pile. La pile est vide. procedure Initialiser (Pile : out T_Pile) with Post => Est_Vide (Pile); -- Est-ce que la pile est vide ? function Est_Vide (Pile : in T_Pile) return Boolean; -- Est-ce que la pile est pleine ? function Est_Pleine (Pile : in T_Pile) return Boolean; -- L'élément en sommet de la pile. function Sommet (Pile : in T_Pile) return T_Element with Pre => not Est_Vide (Pile); -- Empiler l'élément en somment de la pile. procedure Empiler (Pile : in out T_Pile; Element : in T_Element) with Pre => not Est_Pleine (Pile), Post => Sommet (Pile) = Element; -- Supprimer l'élément en sommet de pile procedure Depiler (Pile : in out T_Pile) with Pre => not Est_Vide (Pile); -- Afficher les éléments de la pile generic with procedure Afficher_Element (Un_Element: in T_Element); procedure Afficher (Pile : in T_Pile); private type T_Tab_Elements is array (1..Capacite) of T_Element; type T_Pile is record Elements : T_Tab_Elements; -- les éléments de la pile Taille: Integer; -- Nombre d'éléments dans la pile end record; end Piles;
-- Implantation du module Ensembles. with Ada.Unchecked_Deallocation; package body Ensembles_Chainage is -- Libérer la mémoire alloué auparavant. procedure Free is new Ada.Unchecked_Deallocation (T_Cellule, T_Ensemble); procedure Initialiser (Ensemble : out T_Ensemble) is begin Ensemble := Null; end Initialiser; procedure Detruire (Ensemble : in out T_Ensemble) is begin if (Ensemble /= Null) then Detruire (Ensemble.all.Suivant); Free (Ensemble); else null; end if; end Detruire; function Est_Vide (Ensemble : in T_Ensemble) return Boolean is begin return Ensemble = Null; end Est_Vide; function Taille (Ensemble : in T_Ensemble) return Integer is begin if (Ensemble = Null) then return 0; else return 1 + Taille (Ensemble.all.suivant); end if; end Taille; function Est_Present (Ensemble : in T_Ensemble; Element : in T_Element) return Boolean is present : Boolean; Temp : T_Ensemble; begin present := False; Temp := Ensemble; while (Temp /= Null) loop if (Temp.all.Element = Element) then present := True; end if; Temp := Temp.all.Suivant; end loop; return present; end Est_Present; procedure Ajouter (Ensemble : in out T_Ensemble; Element : in T_Element) is Nouvelle_Cellule, Temp : T_Ensemble; begin Nouvelle_Cellule := New T_Cellule'(Element, Null); if ( Ensemble = Null) then -- Si l'ensemble est vide. Ensemble := Nouvelle_Cellule; --Créer une nouvelle cellule. else -- Sinon, on ajoute à la fin de l'ensemble. Temp := Ensemble; while (Temp.all.Suivant /= Null) loop Temp := Temp.all.Suivant; end loop; Temp.all.Suivant := Nouvelle_Cellule; --Créer une nouvelle cellule.; end if; end Ajouter; procedure Supprimer (Ensemble : in out T_Ensemble; Element : in T_Element) is Temp : T_Ensemble; begin if (Ensemble.all.Element = Element) then Temp := Ensemble.all.Suivant; Free (Ensemble); Ensemble := Temp; else Supprimer (Ensemble.all.Suivant, Element); end if; end Supprimer; procedure Appliquer_Sur_Tous (Ensemble : in T_Ensemble) is Temp : T_Ensemble; begin Temp := Ensemble; while (Temp /= NULL) loop Operation (Temp.all.Element); Temp := Temp.all.Suivant; end loop; end Appliquer_Sur_Tous; end Ensembles_Chainage;
-- Copyright (C) 2019 Thierry Rascle <thierr26@free.fr> -- MIT license. Please refer to the LICENSE file. generic Test_Node_Tag : Tag; procedure Apsepp.Test_Node_Class.Generic_Assert (Cond : Boolean; Message : String := "");
----------------------------------------------------------------------- -- druss-commands-status -- Druss status commands -- Copyright (C) 2017, 2018, 2019, 2021 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.Properties; with Util.Strings; with Druss.Gateways; package body Druss.Commands.Status is -- ------------------------------ -- Execute the wifi 'status' command to print the Wifi current status. -- ------------------------------ procedure Do_Status (Command : in Command_Type; Args : in Argument_List'Class; Context : in out Context_Type) is pragma Unreferenced (Command, Args); procedure Box_Status (Gateway : in out Druss.Gateways.Gateway_Type); Console : constant Druss.Commands.Consoles.Console_Access := Context.Console; N : Natural := 0; procedure Box_Status (Gateway : in out Druss.Gateways.Gateway_Type) is begin Gateway.Refresh; Console.Start_Row; Console.Print_Field (F_IP_ADDR, Gateway.Ip); Console.Print_Field (F_WAN_IP, Gateway.Wan.Get ("wan.ip.address", " ")); Print_Status (Console, F_INTERNET, Gateway.Wan.Get ("wan.internet.state", " ")); Console.Print_Field (F_VOIP, Gateway.Voip.Get ("voip.0.status", " ")); Print_On_Off (Console, F_WIFI, Gateway.Wifi.Get ("wireless.radio.24.enable", " ")); if not Gateway.Wifi.Exists ("wireless.radio.5.enable") then Console.Print_Field (F_WIFI5, ""); else Print_On_Off (Console, F_WIFI5, Gateway.Wifi.Get ("wireless.radio.5.enable", " ")); end if; Console.Print_Field (F_ACCESS_CONTROL, Gateway.IPtv.Get ("iptv.length", "x")); Console.Print_Field (F_DEVICES, Gateway.Hosts.Get ("hosts.list.length", "")); Print_Uptime (Console, F_UPTIME, Gateway.Device.Get ("device.uptime", "")); Console.End_Row; N := N + 1; Gateway.Hosts.Save_Properties ("sum-" & Util.Strings.Image (N) & ".properties"); end Box_Status; begin Console.Start_Title; Console.Print_Title (F_IP_ADDR, "LAN IP", 16); Console.Print_Title (F_WAN_IP, "WAN IP", 16); Console.Print_Title (F_INTERNET, "Internet", 9); Console.Print_Title (F_VOIP, "VoIP", 6); Console.Print_Title (F_WIFI, "Wifi 2.4G", 10); Console.Print_Title (F_WIFI5, "Wifi 5G", 10); Console.Print_Title (F_ACCESS_CONTROL, "Parental", 10); Console.Print_Title (F_DYNDNS, "DynDNS", 10); Console.Print_Title (F_DEVICES, "Devices", 12); Console.Print_Title (F_UPTIME, "Uptime", 12); Console.End_Title; Druss.Gateways.Iterate (Context.Gateways, Gateways.ITER_ENABLE, Box_Status'Access); end Do_Status; -- ------------------------------ -- Execute a status command to report information about the Bbox. -- ------------------------------ overriding procedure Execute (Command : in out Command_Type; Name : in String; Args : in Argument_List'Class; Context : in out Context_Type) is pragma Unreferenced (Name); begin Command.Do_Status (Args, Context); end Execute; -- ------------------------------ -- Write the help associated with the command. -- ------------------------------ overriding procedure Help (Command : in out Command_Type; Name : in String; Context : in out Context_Type) is pragma Unreferenced (Command); Console : constant Druss.Commands.Consoles.Console_Access := Context.Console; begin Console.Notice (N_HELP, "status: give information about the Bbox status"); Console.Notice (N_HELP, "Usage: wifi {<action>} [<parameters>]"); Console.Notice (N_HELP, ""); Console.Notice (N_HELP, " status [IP]... Give information about the Bbox status"); end Help; end Druss.Commands.Status;
-- Ada regular expression library -- (c) Kristian Klomsten Skordal 2020-2021 <kristian.skordal@wafflemail.net> -- Report bugs and issues on <https://github.com/skordal/ada-regex> with Regex_Test_Cases; with AUnit.Test_Caller; package body Regex_Test_Suite is package Regex_Test_Caller is new AUnit.Test_Caller (Regex_Test_Cases.Test_Fixture); function Test_Suite return AUnit.Test_Suites.Access_Test_Suite is Retval : constant AUnit.Test_Suites.Access_Test_Suite := new AUnit.Test_Suites.Test_Suite; begin Retval.Add_Test (Regex_Test_Caller.Create ("single-character", Regex_Test_Cases.Test_Single_Character'Access)); Retval.Add_Test (Regex_Test_Caller.Create ("kleene-closure", Regex_Test_Cases.Test_Kleene_Closure'Access)); Retval.Add_Test (Regex_Test_Caller.Create ("concatenation", Regex_Test_Cases.Test_Concatenation'Access)); Retval.Add_Test (Regex_Test_Caller.Create ("alternation-single", Regex_Test_Cases.Test_Alternation_Single'Access)); Retval.Add_Test (Regex_Test_Caller.Create ("alternation-multiple", Regex_Test_Cases.Test_Alternation_Multiple'Access)); Retval.Add_Test (Regex_Test_Caller.Create ("dragon-book", Regex_Test_Cases.Test_Dragon_Example'Access)); Retval.Add_Test (Regex_Test_Caller.Create ("any-character-single", Regex_Test_Cases.Test_Any_Char_Single'Access)); Retval.Add_Test (Regex_Test_Caller.Create ("any-character-optional", Regex_Test_Cases.Test_Any_Char_Optional'Access)); Retval.Add_Test (Regex_Test_Caller.Create ("any-alternate", Regex_Test_Cases.Test_Any_Alternate'Access)); Retval.Add_Test (Regex_Test_Caller.Create ("escaped-char", Regex_Test_Cases.Test_Escape_Seqs'Access)); Retval.Add_Test (Regex_Test_Caller.Create ("quotes", Regex_Test_Cases.Test_Quotes'Access)); Retval.Add_Test (Regex_Test_Caller.Create ("single-quotes", Regex_Test_Cases.Test_Single_Quotes'Access)); Retval.Add_Test (Regex_Test_Caller.Create ("single-range", Regex_Test_Cases.Test_Single_Range'Access)); Retval.Add_Test (Regex_Test_Caller.Create ("multiple-ranges", Regex_Test_Cases.Test_Multiple_Ranges'Access)); Retval.Add_Test (Regex_Test_Caller.Create ("ranges-and-chars", Regex_Test_Cases.Test_Ranges_And_Chars'Access)); Retval.Add_Test (Regex_Test_Caller.Create ("plus-operator", Regex_Test_Cases.Test_Plus_Operator'Access)); Retval.Add_Test (Regex_Test_Caller.Create ("hexadecimal", Regex_Test_Cases.Test_Hexadecimal'Access)); Retval.Add_Test (Regex_Test_Caller.Create ("question-mark", Regex_Test_Cases.Test_Question_Operator'Access)); Retval.Add_Test (Regex_Test_Caller.Create ("partial-match", Regex_Test_Cases.Test_Partial_Matching'Access)); Retval.Add_Test (Regex_Test_Caller.Create ("newlines", Regex_Test_Cases.Test_Newlines'Access)); Retval.Add_Test (Regex_Test_Caller.Create ("syntax-tree-compile", Regex_Test_Cases.Test_Syntax_Tree_Compile'Access)); Retval.Add_Test (Regex_Test_Caller.Create ("multiple-accept", Regex_Test_Cases.Test_Multiple_Accept'Access)); return Retval; end Test_Suite; end Regex_Test_Suite;
with Ada.Strings.Fixed; with Ada.Directories; package body Test is package Text_IO renames Ada.Text_IO; package Result_IO is new Ada.Text_IO.Enumeration_IO (Result_t); package Fixed_Strings renames Ada.Strings.Fixed; package Strings renames Ada.Strings; package Directories renames Ada.Directories; use type UB_Strings.Unbounded_String; -- -- Check -- procedure Check (Test_Context : in Context_t; Test : in Test_t; Condition : in Boolean; Statement : in String := "") is Result : Valid_Result_t; begin if Condition then Result := Pass; else Result := Fail; end if; Satisfy (Test_Context => Test_Context, Test => Test, Result => Result, Statement => Statement); end Check; -- -- Check_Program -- procedure Check_Program (Test_Context : in Context_t; Base : in UB_Strings.Unbounded_String) is Want_Program : UB_Strings.Unbounded_String; Path : UB_Strings.Unbounded_String; File : Text_IO.File_Type; begin UB_Strings.Append (Path, Test_Context.Test_DB); UB_Strings.Append (Path, Base); UB_Strings.Append (Path, "/program"); Text_IO.Open (File => File, Mode => Text_IO.In_File, Name => UB_Strings.To_String (Path)); Want_Program := UB_Strings.To_Unbounded_String (Text_IO.Get_Line (File)); if Want_Program /= Test_Context.Program then raise Program_Error with "program does not match test database"; end if; end Check_Program; -- -- Initialize -- procedure Initialize (Test_Context : out Context_t; Program : in String; Test_DB : in String; Test_Results : in String) is begin Test_Context.Program := UB_Strings.To_Unbounded_String (Program); Test_Context.Test_DB := UB_Strings.To_Unbounded_String (Test_DB); Test_Context.Test_Results := UB_Strings.To_Unbounded_String (Test_Results); Text_IO.Create (File => Test_Context.Output_File, Name => Program & ".log_out", Mode => Text_IO.Out_File); Text_IO.Create (File => Test_Context.Error_File, Name => Program & ".log_error", Mode => Text_IO.Out_File); Text_IO.Set_Output (Test_Context.Output_File); Text_IO.Set_Error (Test_Context.Error_File); end Initialize; -- -- Satisfy -- procedure Satisfy (Test_Context : in Context_t; Test : in Test_t; Result : in Valid_Result_t; Statement : in String := "") is File : Text_IO.File_Type; Base : UB_Strings.Unbounded_String; Path : UB_Strings.Unbounded_String; begin -- Build path to test entry. UB_Strings.Set_Unbounded_String (Base, ""); UB_Strings.Append (Base, "/tests/"); UB_Strings.Append (Base, Fixed_Strings.Trim (Test_t'Image (Test), Strings.Left)); -- Check database entry exists. UB_Strings.Set_Unbounded_String (Path, ""); UB_Strings.Append (Path, Test_Context.Test_DB); UB_Strings.Append (Path, Base); if Directories.Exists (UB_Strings.To_String (Path)) = False then raise Program_Error with "test " & Fixed_Strings.Trim (Test_t'Image (Test), Strings.Left) & " not defined"; end if; -- Check the current program is the one that should be satisfying the test. Check_Program (Test_Context, Base); -- Build path to state file. UB_Strings.Set_Unbounded_String (Path, ""); UB_Strings.Append (Path, Test_Context.Test_Results); UB_Strings.Append (Path, Base); UB_Strings.Append (Path, "/statement"); -- Yes, Ada has race conditions built in! Text_IO.Create (File, Name => UB_Strings.To_String (Path)); Text_IO.Put (File, Statement); Text_IO.New_Line (File); Text_IO.Close (File); -- Build path to state file. UB_Strings.Set_Unbounded_String (Path, ""); UB_Strings.Append (Path, Test_Context.Test_Results); UB_Strings.Append (Path, Base); UB_Strings.Append (Path, "/state"); -- Yes, Ada has race conditions built in! Text_IO.Create (File, Name => UB_Strings.To_String (Path)); Result_IO.Put (File, Result); Text_IO.New_Line (File); end Satisfy; end Test;
-- Copyright (c) 2019 Maxim Reznik <reznikmm@gmail.com> -- -- SPDX-License-Identifier: MIT -- License-Filename: LICENSE ------------------------------------------------------------- with Program.Lexical_Elements; with Program.Scanned_Rule_Handlers; with Program.Scanner_States; with Program.Source_Buffers; package Program.Scanners is pragma Pure; type Scanner is tagged limited private; -- Scaner of source code procedure Set_Source (Self : in out Scanner'Class; Source : not null Program.Source_Buffers.Source_Buffer_Access); -- Assign source buffer to the scanner function Get_Source (Self : Scanner'Class) return not null Program.Source_Buffers.Source_Buffer_Access; -- Get assigned source buffer procedure Set_Handler (Self : in out Scanner'Class; Handler : not null Program.Scanned_Rule_Handlers.Handler_Access); -- Assign rule handler to the scanner subtype Start_Condition is Program.Scanner_States.State; procedure Set_Start_Condition (Self : in out Scanner'Class; Condition : Start_Condition); -- Set new start condition to the scanner function Get_Start_Condition (Self : Scanner'Class) return Start_Condition; -- Get current start condition procedure Get_Token (Self : access Scanner'Class; Value : out Program.Lexical_Elements.Lexical_Element_Kind); -- Scan for next token. The scanner searches for text matching regexps -- and calls corresponding routine of rule handler. Rule handler decodes -- token kind and return Skip flag. Get_Token returns when Skip = False. function Get_Span (Self : Scanner'Class) return Program.Source_Buffers.Span; -- Get Span of last token package Tables is use Program.Scanner_States; subtype Code_Point is Natural; function To_Class (Value : Code_Point) return Character_Class with Inline; function Switch (S : State; Class : Character_Class) return State with Inline; function Rule (S : State) return Rule_Index; end Tables; private Buffer_Half_Size : constant := 1024; End_Of_Buffer : constant Program.Source_Buffers.Character_Length := 0; subtype Buffer_Index is Positive range 1 .. 2 * Buffer_Half_Size; Error_Character : constant Program.Scanner_States.Character_Class := 0; Error_State : constant Program.Scanner_States.State := Program.Scanner_States.Error_State; type Scanner is tagged limited record Handler : Program.Scanned_Rule_Handlers.Handler_Access; Source : Program.Source_Buffers.Source_Buffer_Access; Start : Program.Scanner_States.State := Program.Scanner_States.INITIAL; Next : Buffer_Index := 1; -- Where we scan Classes buffer Offset : Positive := 1; -- Corresponding offset in Source_Buffer From : Positive := 1; -- Start of token in Source_Buffer To : Natural; -- End of token in Source_Buffer EOF : Natural := 0; Classes : Program.Source_Buffers.Character_Info_Array (Buffer_Index) := (1 => (Class => Error_Character, Length => End_Of_Buffer), others => <>); end record; procedure Read_Buffer (Self : in out Scanner'Class); end Program.Scanners;
-------------------------------------------------------------------------------------------------------------------- -- Copyright (c) 2013-2018 Luke A. Guest -- -- This software is provided 'as-is', without any express or implied -- warranty. In no event will the authors be held liable for any damages -- arising from the use of this software. -- -- Permission is granted to anyone to use this software for any purpose, -- including commercial applications, and to alter it and redistribute it -- freely, subject to the following restrictions: -- -- 1. The origin of this software must not be misrepresented; you must not -- claim that you wrote the original software. If you use this software -- in a product, an acknowledgment in the product documentation would be -- appreciated but is not required. -- -- 2. Altered source versions must be plainly marked as such, and must not be -- misrepresented as being the original software. -- -- 3. This notice may not be removed or altered from any source -- distribution. -------------------------------------------------------------------------------------------------------------------- -- SDL.Power -- -- Battery access on the target platform. -------------------------------------------------------------------------------------------------------------------- package SDL.Power is type State is (Unknown, -- Cannot determine power status. Battery, -- Not plugged in, running on the battery. No_Battery, -- Plugged in, no battery available. Charging, -- Plugged in, charging battery. Charged -- Plugged in, battery charged. ) with Convention => C; type Seconds is range 0 .. Integer'Last; type Percentage is range 0 .. 100; type Battery_Info is record Power_State : State; Time_Valid : Boolean; Time : Seconds; Percentage_Valid : Boolean; Percent : Percentage; end record; procedure Info (Data : in out Battery_Info); end SDL.Power;
------------------------------------------------------------------------------ -- -- -- GNAT RUN-TIME COMPONENTS -- -- -- -- G N A T . B R A N C H _ P R E D I C T I O N -- -- -- -- S p e c -- -- -- -- Copyright (C) 2019-2020, AdaCore -- -- -- -- GNAT is free software; you can redistribute it and/or modify it under -- -- terms of the GNU General Public License as published by the Free Soft- -- -- ware Foundation; either version 3, or (at your option) any later ver- -- -- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- -- or FITNESS FOR A PARTICULAR PURPOSE. -- -- -- -- As a special exception under Section 7 of GPL version 3, you are granted -- -- additional permissions described in the GCC Runtime Library Exception, -- -- version 3.1, as published by the Free Software Foundation. -- -- -- -- You should have received a copy of the GNU General Public License and -- -- a copy of the GCC Runtime Library Exception along with this program; -- -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- -- <http://www.gnu.org/licenses/>. -- -- -- -- GNAT was originally developed by the GNAT team at New York University. -- -- Extensive contributions were provided by Ada Core Technologies Inc. -- -- -- ------------------------------------------------------------------------------ -- This package provides routines giving hints to the branch predictor of the -- code generator. These hints are useful when optimization is enabled and the -- branch probability heuristics are used (which is the default), but they are -- overridden when profile feedback-directed optimization is used instead. -- The canonical pattern is to use them as the condition of an If statement: -- -- if Likely (X > 0) then -- Do_Something; -- end if; -- -- when it is not obvious that one outcome of the condition is more likely -- than the other, or else to reverse the prediction made by the heuristics -- in very peculiar cases. In the other cases, it is better not to use them, -- because predicting how programs actually perform is notoriously hard. package GNAT.Branch_Prediction is pragma Pure; function Expect (Condition : Boolean; Outcome : Boolean) return Boolean; pragma Import (Intrinsic, Expect, "__builtin_expect"); -- This function returns the value of its first parameter Condition and -- tells the branch predictor that this value is expected to be Outcome. function Likely (Condition : Boolean) return Boolean; pragma Import (Intrinsic, Likely, "__builtin_likely"); -- This function returns the value of its parameter Condition and tells -- the branch predictor that this value is expected to be True. Calling -- it is strictly equivalent to calling Expect with Outcome set to True. function Unlikely (Condition : Boolean) return Boolean; pragma Import (Intrinsic, Unlikely, "__builtin_unlikely"); -- This function returns the value of its parameter Condition and tells -- the branch predictor that this value is expected to be False. Calling -- it is strictly equivalent to calling Expect with Outcome set to False. end GNAT.Branch_Prediction;
-- telnet localhost 3776 with Ada.Streams.Stream_IO.Sockets; procedure socket_server is Server : Ada.Streams.Stream_IO.Sockets.Listener := Ada.Streams.Stream_IO.Sockets.Listen (3776); begin pragma Debug (Ada.Debug.Put ("opened")); declare File : Ada.Streams.Stream_IO.File_Type; begin Ada.Streams.Stream_IO.Sockets.Accept_Socket (Server, File); pragma Debug (Ada.Debug.Put ("connected")); while not Ada.Streams.Stream_IO.End_Of_File (File) loop declare Item : Ada.Streams.Stream_Element_Array (0 .. 0); Last : Ada.Streams.Stream_Element_Offset; begin Ada.Streams.Stream_IO.Read (File, Item, Last); Ada.Streams.Stream_IO.Write (File, Item (Item'First .. Last)); end; end loop; Ada.Streams.Stream_IO.Close (File); pragma Debug (Ada.Debug.Put ("disconnected")); end; Ada.Streams.Stream_IO.Sockets.Close (Server); pragma Debug (Ada.Debug.Put ("closed")); end socket_server;
-- -- Copyright (C) 2017, AdaCore -- -- This spec has been automatically generated from STM32F7x9.svd -- This is a version for the STM32F7x9 MCU package Ada.Interrupts.Names is -- All identifiers in this unit are implementation defined pragma Implementation_Defined; ---------------- -- Interrupts -- ---------------- -- System tick Sys_Tick_Interrupt : constant Interrupt_ID := -1; -- Window Watchdog interrupt WWDG_Interrupt : constant Interrupt_ID := 0; -- Tamper and TimeStamp interrupts through the EXTI line TAMP_STAMP_Interrupt : constant Interrupt_ID := 2; -- RTC Tamper or TimeStamp /CSS on LSE through EXTI line 19 interrupts RTC_WKUP_Interrupt : constant Interrupt_ID := 3; -- Flash global interrupt FLASH_Interrupt : constant Interrupt_ID := 4; -- RCC global interrupt RCC_Interrupt : constant Interrupt_ID := 5; -- EXTI Line0 interrupt EXTI0_Interrupt : constant Interrupt_ID := 6; -- EXTI Line1 interrupt EXTI1_Interrupt : constant Interrupt_ID := 7; -- EXTI Line2 interrupt EXTI2_Interrupt : constant Interrupt_ID := 8; -- EXTI Line3 interrupt EXTI3_Interrupt : constant Interrupt_ID := 9; -- EXTI Line4 interrupt EXTI4_Interrupt : constant Interrupt_ID := 10; -- DMA1 Stream0 global interrupt DMA1_Stream0_Interrupt : constant Interrupt_ID := 11; -- DMA1 Stream1 global interrupt DMA1_Stream1_Interrupt : constant Interrupt_ID := 12; -- DMA1 Stream2 global interrupt DMA1_Stream2_Interrupt : constant Interrupt_ID := 13; -- DMA1 Stream3 global interrupt DMA1_Stream3_Interrupt : constant Interrupt_ID := 14; -- DMA1 Stream4 global interrupt DMA1_Stream4_Interrupt : constant Interrupt_ID := 15; -- DMA1 Stream5 global interrupt DMA1_Stream5_Interrupt : constant Interrupt_ID := 16; -- DMA1 Stream6 global interrupt DMA1_Stream6_Interrupt : constant Interrupt_ID := 17; -- ADC1 global interrupt ADC_Interrupt : constant Interrupt_ID := 18; -- CAN1 TX interrupts CAN1_TX_Interrupt : constant Interrupt_ID := 19; -- CAN1 RX0 interrupts CAN1_RX0_Interrupt : constant Interrupt_ID := 20; -- CAN1 RX1 interrupts CAN1_RX1_Interrupt : constant Interrupt_ID := 21; -- CAN1 SCE interrupt CAN1_SCE_Interrupt : constant Interrupt_ID := 22; -- EXTI Line[9:5] interrupts EXTI9_5_Interrupt : constant Interrupt_ID := 23; -- TIM1 Break interrupt and TIM9 global interrupt TIM1_BRK_TIM9_Interrupt : constant Interrupt_ID := 24; -- TIM1 Update interrupt and TIM10 global interrupt TIM1_UP_TIM10_Interrupt : constant Interrupt_ID := 25; -- TIM1 Trigger and Commutation interrupts and TIM11 global interrupt TIM1_TRG_COM_TIM11_Interrupt : constant Interrupt_ID := 26; -- TIM1 Capture Compare interrupt TIM1_CC_Interrupt : constant Interrupt_ID := 27; -- TIM2 global interrupt TIM2_Interrupt : constant Interrupt_ID := 28; -- TIM3 global interrupt TIM3_Interrupt : constant Interrupt_ID := 29; -- TIM4 global interrupt TIM4_Interrupt : constant Interrupt_ID := 30; -- I2C1 event interrupt I2C1_EV_Interrupt : constant Interrupt_ID := 31; -- I2C1 error interrupt I2C1_ER_Interrupt : constant Interrupt_ID := 32; -- I2C2 event interrupt I2C2_EV_Interrupt : constant Interrupt_ID := 33; -- I2C2 error interrupt I2C2_ER_Interrupt : constant Interrupt_ID := 34; -- SPI1 global interrupt SPI1_Interrupt : constant Interrupt_ID := 35; -- SPI2 global interrupt SPI2_Interrupt : constant Interrupt_ID := 36; -- USART1 global interrupt USART1_Interrupt : constant Interrupt_ID := 37; -- USART2 global interrupt USART2_Interrupt : constant Interrupt_ID := 38; -- USART3 global interrupt USART3_Interrupt : constant Interrupt_ID := 39; -- EXTI Line[15:10] interrupts EXTI15_10_Interrupt : constant Interrupt_ID := 40; -- RTC alarms through EXTI line 18 interrupts RTC_ALARM_Interrupt : constant Interrupt_ID := 41; -- USB On-The-Go FS Wakeup through EXTI line interrupt OTG_FS_WKUP_Interrupt : constant Interrupt_ID := 42; -- TIM8 Break interrupt and TIM12 global interrupt TIM8_BRK_TIM12_Interrupt : constant Interrupt_ID := 43; -- TIM8 Update interrupt and TIM13 global interrupt TIM8_UP_TIM13_Interrupt : constant Interrupt_ID := 44; -- TIM8 Trigger and Commutation interrupts and TIM14 global interrupt TIM8_TRG_COM_TIM14_Interrupt : constant Interrupt_ID := 45; -- TIM8 Capture Compare interrupt TIM8_CC_Interrupt : constant Interrupt_ID := 46; -- DMA1 Stream7 global interrupt DMA1_Stream7_Interrupt : constant Interrupt_ID := 47; -- FMC global interrupt FMC_Interrupt : constant Interrupt_ID := 48; -- SDMMC1 global interrupt SDMMC1_Interrupt : constant Interrupt_ID := 49; -- TIM5 global interrupt TIM5_Interrupt : constant Interrupt_ID := 50; -- SPI3 global interrupt SPI3_Interrupt : constant Interrupt_ID := 51; -- UART4 global interrupt UART4_Interrupt : constant Interrupt_ID := 52; -- UART5 global interrupt UART5_Interrupt : constant Interrupt_ID := 53; -- TIM6 global interrupt, DAC1 and DAC2 underrun error interrupt TIM6_DAC_Interrupt : constant Interrupt_ID := 54; -- TIM7 global interrupt TIM7_Interrupt : constant Interrupt_ID := 55; -- DMA2 Stream0 global interrupt DMA2_Stream0_Interrupt : constant Interrupt_ID := 56; -- DMA2 Stream1 global interrupt DMA2_Stream1_Interrupt : constant Interrupt_ID := 57; -- DMA2 Stream2 global interrupt DMA2_Stream2_Interrupt : constant Interrupt_ID := 58; -- DMA2 Stream3 global interrupt DMA2_Stream3_Interrupt : constant Interrupt_ID := 59; -- DMA2 Stream4 global interrupt DMA2_Stream4_Interrupt : constant Interrupt_ID := 60; -- Ethernet global interrupt ETH_Interrupt : constant Interrupt_ID := 61; -- Ethernet global interrupt ETH_WKUP_Interrupt : constant Interrupt_ID := 62; -- CAN2 TX interrupts CAN2_TX_Interrupt : constant Interrupt_ID := 63; -- CAN2 RX0 interrupts CAN2_RX0_Interrupt : constant Interrupt_ID := 64; -- CAN2 RX1 interrupts CAN2_RX1_Interrupt : constant Interrupt_ID := 65; -- CAN2 SCE interrupt CAN2_SCE_Interrupt : constant Interrupt_ID := 66; -- USB On The Go FS global interrupt OTG_FS_Interrupt : constant Interrupt_ID := 67; -- DMA2 Stream5 global interrupt DMA2_Stream5_Interrupt : constant Interrupt_ID := 68; -- DMA2 Stream6 global interrupt DMA2_Stream6_Interrupt : constant Interrupt_ID := 69; -- DMA2 Stream7 global interrupt DMA2_Stream7_Interrupt : constant Interrupt_ID := 70; -- USART6 global interrupt USART6_Interrupt : constant Interrupt_ID := 71; -- I2C3 event interrupt I2C3_EV_Interrupt : constant Interrupt_ID := 72; -- I2C3 error interrupt I2C3_ER_Interrupt : constant Interrupt_ID := 73; -- USB On The Go HS End Point 1 Out global interrupt OTG_HS_EP1_OUT_Interrupt : constant Interrupt_ID := 74; -- USB On The Go HS End Point 1 In global interrupt OTG_HS_EP1_IN_Interrupt : constant Interrupt_ID := 75; -- USB On The Go HS Wakeup through EXTI interrupt OTG_HS_WKUP_Interrupt : constant Interrupt_ID := 76; -- USB On The Go HS global interrupt OTG_HS_Interrupt : constant Interrupt_ID := 77; -- DCMI global interrupt DCMI_Interrupt : constant Interrupt_ID := 78; -- Hash and Rng global interrupt HASH_RNG_Interrupt : constant Interrupt_ID := 80; -- FPU global interrupt FPU_Interrupt : constant Interrupt_ID := 81; -- UART7 global interrupt UART7_Interrupt : constant Interrupt_ID := 82; -- UART 8 global interrupt UART8_Interrupt : constant Interrupt_ID := 83; -- SPI 4 global interrupt SPI4_Interrupt : constant Interrupt_ID := 84; -- SPI 5 global interrupt SPI5_Interrupt : constant Interrupt_ID := 85; -- SPI 6 global interrupt SPI6_Interrupt : constant Interrupt_ID := 86; -- SAI1 global interrupt SAI1_Interrupt : constant Interrupt_ID := 87; -- LTDC global interrupt LTDC_Interrupt : constant Interrupt_ID := 88; -- LTDC Error global interrupt LTDC_ER_Interrupt : constant Interrupt_ID := 89; -- DMA2D global interrupt DMA2D_Interrupt : constant Interrupt_ID := 90; -- SAI2 global interrupt SAI2_Interrupt : constant Interrupt_ID := 91; -- QUADSPI global interrupt QUADSPI_Interrupt : constant Interrupt_ID := 92; -- LPTIM1 global interrupt LPTIM1_Interrupt : constant Interrupt_ID := 93; -- CEC global interrupt CEC_Interrupt : constant Interrupt_ID := 94; -- I2C4 event interrupt I2C4_EV_Interrupt : constant Interrupt_ID := 95; -- I2C4 error interrupt I2C4_ER_Interrupt : constant Interrupt_ID := 96; -- SPDIF_RX global interrupt SPDIF_RX_Interrupt : constant Interrupt_ID := 97; -- DSI global interrupt DSI_Interrupt : constant Interrupt_ID := 98; -- DFSDM1 Filter 0 global interrupt DFSDM1_FLT0_Interrupt : constant Interrupt_ID := 99; -- DFSDM1 Filter 1 global interrupt DFSDM1_FLT1_Interrupt : constant Interrupt_ID := 100; -- DFSDM1 Filter 2 global interrupt DFSDM1_FLT2_Interrupt : constant Interrupt_ID := 101; -- DFSDM1 Filter 3 global interrupt DFSDM1_FLT3_Interrupt : constant Interrupt_ID := 102; -- SDMMC2 global interrupt SDMMC2_Interrupt : constant Interrupt_ID := 103; -- CAN3 TX interrupt CAN3_TX_Interrupt : constant Interrupt_ID := 104; -- CAN3 RX0 interrupt CAN3_RX0_Interrupt : constant Interrupt_ID := 105; -- CAN3 RX1 interrupt CAN3_RX1_Interrupt : constant Interrupt_ID := 106; -- CAN3 SCE interrupt CAN3_SCE_Interrupt : constant Interrupt_ID := 107; -- JPEG global interrupt JPEG_Interrupt : constant Interrupt_ID := 108; -- MDIO slave global interrupt MDIOS_Interrupt : constant Interrupt_ID := 109; end Ada.Interrupts.Names;
-- { dg-do run } -- { dg-options "-gnatVa" } with Unchecked_Conversion; procedure Unchecked_Convert3 is type Word is range -(2**15) .. (2**15) - 1; type UWord is mod (2**16); function To_Word is new unchecked_conversion (UWord, Word); function F return UWord is begin return 65036; end; W : Word := To_Word(F); begin null; end;
------------------------------------------------------------------------------ -- -- -- GNAT COMPILER COMPONENTS -- -- -- -- S Y S T E M . S E C O N D A R Y _ S T A C K -- -- -- -- B o d y -- -- -- -- Copyright (C) 1992-2020, Free Software Foundation, Inc. -- -- -- -- GNAT is free software; you can redistribute it and/or modify it under -- -- terms of the GNU General Public License as published by the Free Soft- -- -- ware Foundation; either version 3, or (at your option) any later ver- -- -- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- -- or FITNESS FOR A PARTICULAR PURPOSE. -- -- -- -- As a special exception under Section 7 of GPL version 3, you are granted -- -- additional permissions described in the GCC Runtime Library Exception, -- -- version 3.1, as published by the Free Software Foundation. -- -- -- -- You should have received a copy of the GNU General Public License and -- -- a copy of the GCC Runtime Library Exception along with this program; -- -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- -- <http://www.gnu.org/licenses/>. -- -- -- -- GNAT was originally developed by the GNAT team at New York University. -- -- Extensive contributions were provided by Ada Core Technologies Inc. -- -- -- ------------------------------------------------------------------------------ pragma Compiler_Unit_Warning; with Ada.Unchecked_Conversion; with Ada.Unchecked_Deallocation; with System; use System; with System.Parameters; use System.Parameters; with System.Soft_Links; use System.Soft_Links; with System.Storage_Elements; use System.Storage_Elements; package body System.Secondary_Stack is ------------------------------------ -- Binder Allocated Stack Support -- ------------------------------------ -- When at least one of the following restrictions -- -- No_Implicit_Heap_Allocations -- No_Implicit_Task_Allocations -- -- is in effect, the binder creates a static secondary stack pool, where -- each stack has a default size. Assignment of these stacks to tasks is -- performed by SS_Init. The following variables are defined in this unit -- in order to avoid depending on the binder. Their values are set by the -- binder. Binder_SS_Count : Natural; pragma Export (Ada, Binder_SS_Count, "__gnat_binder_ss_count"); -- The number of secondary stacks in the pool created by the binder Binder_Default_SS_Size : Size_Type; pragma Export (Ada, Binder_Default_SS_Size, "__gnat_default_ss_size"); -- The default secondary stack size as specified by the binder. The value -- is defined here rather than in init.c or System.Init because the ZFP and -- Ravenscar-ZFP run-times lack these locations. Binder_Default_SS_Pool : Address; pragma Export (Ada, Binder_Default_SS_Pool, "__gnat_default_ss_pool"); -- The address of the secondary stack pool created by the binder Binder_Default_SS_Pool_Index : Natural := 0; -- Index into the secondary stack pool created by the binder ----------------------- -- Local subprograms -- ----------------------- procedure Allocate_Dynamic (Stack : SS_Stack_Ptr; Mem_Size : Memory_Size; Addr : out Address); pragma Inline (Allocate_Dynamic); -- Allocate enough space on dynamic secondary stack Stack to fit a request -- of size Mem_Size. Addr denotes the address of the first byte of the -- allocation. procedure Allocate_On_Chunk (Stack : SS_Stack_Ptr; Prev_Chunk : SS_Chunk_Ptr; Chunk : SS_Chunk_Ptr; Byte : Memory_Index; Mem_Size : Memory_Size; Addr : out Address); pragma Inline (Allocate_On_Chunk); -- Allocate enough space on chunk Chunk to fit a request of size Mem_Size. -- Stack is the owner of the allocation Chunk. Prev_Chunk is the preceding -- chunk of Chunk. Byte indicates the first free byte within Chunk. Addr -- denotes the address of the first byte of the allocation. This routine -- updates the state of Stack.all to reflect the side effects of the -- allocation. procedure Allocate_Static (Stack : SS_Stack_Ptr; Mem_Size : Memory_Size; Addr : out Address); pragma Inline (Allocate_Static); -- Allocate enough space on static secondary stack Stack to fit a request -- of size Mem_Size. Addr denotes the address of the first byte of the -- allocation. procedure Free is new Ada.Unchecked_Deallocation (SS_Chunk, SS_Chunk_Ptr); -- Free a dynamically allocated chunk procedure Free is new Ada.Unchecked_Deallocation (SS_Stack, SS_Stack_Ptr); -- Free a dynamically allocated secondary stack function Has_Enough_Free_Memory (Chunk : SS_Chunk_Ptr; Byte : Memory_Index; Mem_Size : Memory_Size) return Boolean; pragma Inline (Has_Enough_Free_Memory); -- Determine whether chunk Chunk has enough room to fit a memory request of -- size Mem_Size, starting from the first free byte of the chunk denoted by -- Byte. function Number_Of_Chunks (Stack : SS_Stack_Ptr) return Chunk_Count; pragma Inline (Number_Of_Chunks); -- Count the number of static and dynamic chunks of secondary stack Stack function Size_Up_To_And_Including (Chunk : SS_Chunk_Ptr) return Memory_Size; pragma Inline (Size_Up_To_And_Including); -- Calculate the size of secondary stack which houses chunk Chunk, from the -- start of the secondary stack up to and including Chunk itself. The size -- includes the following kinds of memory: -- -- * Free memory in used chunks due to alignment holes -- * Occupied memory by allocations -- -- This is a constant time operation, regardless of the secondary stack's -- nature. function Top_Chunk_Id (Stack : SS_Stack_Ptr) return Chunk_Id_With_Invalid; pragma Inline (Top_Chunk_Id); -- Obtain the Chunk_Id of the chunk indicated by secondary stack Stack's -- pointer. function Used_Memory_Size (Stack : SS_Stack_Ptr) return Memory_Size; pragma Inline (Used_Memory_Size); -- Calculate the size of stack Stack's occupied memory usage. This includes -- the following kinds of memory: -- -- * Free memory in used chunks due to alignment holes -- * Occupied memory by allocations -- -- This is a constant time operation, regardless of the secondary stack's -- nature. ---------------------- -- Allocate_Dynamic -- ---------------------- procedure Allocate_Dynamic (Stack : SS_Stack_Ptr; Mem_Size : Memory_Size; Addr : out Address) is function Allocate_New_Chunk return SS_Chunk_Ptr; pragma Inline (Allocate_New_Chunk); -- Create a new chunk which is big enough to fit a request of size -- Mem_Size. ------------------------ -- Allocate_New_Chunk -- ------------------------ function Allocate_New_Chunk return SS_Chunk_Ptr is Chunk_Size : Memory_Size; begin -- The size of the new chunk must fit the memory request precisely. -- In the case where the memory request is way too small, use the -- default chunk size. This avoids creating multiple tiny chunks. Chunk_Size := Mem_Size; if Chunk_Size < Stack.Default_Chunk_Size then Chunk_Size := Stack.Default_Chunk_Size; end if; return new SS_Chunk (Chunk_Size); -- The creation of the new chunk may exhaust the heap. Raise a new -- Storage_Error to indicate that the secondary stack is exhausted -- as well. exception when Storage_Error => raise Storage_Error with "secondary stack exhausted"; end Allocate_New_Chunk; -- Local variables Next_Chunk : SS_Chunk_Ptr; -- Start of processing for Allocate_Dynamic begin -- Determine whether the chunk indicated by the stack pointer is big -- enough to fit the memory request and if it is, allocate on it. if Has_Enough_Free_Memory (Chunk => Stack.Top.Chunk, Byte => Stack.Top.Byte, Mem_Size => Mem_Size) then Allocate_On_Chunk (Stack => Stack, Prev_Chunk => null, Chunk => Stack.Top.Chunk, Byte => Stack.Top.Byte, Mem_Size => Mem_Size, Addr => Addr); return; end if; -- At this point it is known that the chunk indicated by the stack -- pointer is not big enough to fit the memory request. Examine all -- subsequent chunks, and apply the following criteria: -- -- * If the current chunk is too small, free it -- -- * If the current chunk is big enough, allocate on it -- -- This ensures that no space is wasted. The process is costly, however -- allocation is costly in general. Paying the price here keeps routines -- SS_Mark and SS_Release cheap. while Stack.Top.Chunk.Next /= null loop -- The current chunk is big enough to fit the memory request, -- allocate on it. if Has_Enough_Free_Memory (Chunk => Stack.Top.Chunk.Next, Byte => Stack.Top.Chunk.Next.Memory'First, Mem_Size => Mem_Size) then Allocate_On_Chunk (Stack => Stack, Prev_Chunk => Stack.Top.Chunk, Chunk => Stack.Top.Chunk.Next, Byte => Stack.Top.Chunk.Next.Memory'First, Mem_Size => Mem_Size, Addr => Addr); return; -- Otherwise the chunk is too small, free it else Next_Chunk := Stack.Top.Chunk.Next.Next; -- Unchain the chunk from the stack. This keeps the next candidate -- chunk situated immediately after Top.Chunk. -- -- Top.Chunk Top.Chunk.Next Top.Chunk.Next.Next -- | | (Next_Chunk) -- v v v -- +-------+ +------------+ +--------------+ -- | | --> | | --> | | -- +-------+ +------------+ +--------------+ -- to be freed Free (Stack.Top.Chunk.Next); Stack.Top.Chunk.Next := Next_Chunk; end if; end loop; -- At this point one of the following outcomes took place: -- -- * Top.Chunk is the last chunk in the stack -- -- * Top.Chunk was not the last chunk originally. It was followed by -- chunks which were too small and as a result were deleted, thus -- making Top.Chunk the last chunk in the stack. -- -- Either way, nothing should be hanging off the chunk indicated by the -- stack pointer. pragma Assert (Stack.Top.Chunk.Next = null); -- Create a new chunk big enough to fit the memory request, and allocate -- on it. Stack.Top.Chunk.Next := Allocate_New_Chunk; Allocate_On_Chunk (Stack => Stack, Prev_Chunk => Stack.Top.Chunk, Chunk => Stack.Top.Chunk.Next, Byte => Stack.Top.Chunk.Next.Memory'First, Mem_Size => Mem_Size, Addr => Addr); end Allocate_Dynamic; ----------------------- -- Allocate_On_Chunk -- ----------------------- procedure Allocate_On_Chunk (Stack : SS_Stack_Ptr; Prev_Chunk : SS_Chunk_Ptr; Chunk : SS_Chunk_Ptr; Byte : Memory_Index; Mem_Size : Memory_Size; Addr : out Address) is New_High_Water_Mark : Memory_Size; begin -- The allocation occurs on a reused or a brand new chunk. Such a chunk -- must always be connected to some previous chunk. if Prev_Chunk /= null then pragma Assert (Prev_Chunk.Next = Chunk); -- Update the Size_Up_To_Chunk because this value is invalidated for -- reused and new chunks. -- -- Prev_Chunk Chunk -- v v -- . . . . . . . +--------------+ +-------- -- . --> |##############| --> | -- . . . . . . . +--------------+ +-------- -- | | -- -------------------+------------+ -- Size_Up_To_Chunk Size -- -- The Size_Up_To_Chunk is equal to the size of the whole stack up to -- the previous chunk, plus the size of the previous chunk itself. Chunk.Size_Up_To_Chunk := Size_Up_To_And_Including (Prev_Chunk); end if; -- The chunk must have enough room to fit the memory request. If this is -- not the case, then a previous step picked the wrong chunk. pragma Assert (Has_Enough_Free_Memory (Chunk, Byte, Mem_Size)); -- The first byte of the allocation is the first free byte within the -- chunk. Addr := Chunk.Memory (Byte)'Address; -- The chunk becomes the chunk indicated by the stack pointer. This is -- either the currently indicated chunk, an existing chunk, or a brand -- new chunk. Stack.Top.Chunk := Chunk; -- The next free byte is immediately after the memory request -- -- Addr Top.Byte -- | | -- +-----|--------|----+ -- |##############| | -- +-------------------+ -- ??? this calculation may overflow on 32bit targets Stack.Top.Byte := Byte + Mem_Size; -- At this point the next free byte cannot go beyond the memory capacity -- of the chunk indicated by the stack pointer, except when the chunk is -- full, in which case it indicates the byte beyond the chunk. Ensure -- that the occupied memory is at most as much as the capacity of the -- chunk. Top.Byte - 1 denotes the last occupied byte. pragma Assert (Stack.Top.Byte - 1 <= Stack.Top.Chunk.Size); -- Calculate the new high water mark now that the memory request has -- been fulfilled, and update if necessary. The new high water mark is -- technically the size of the used memory by the whole stack. New_High_Water_Mark := Used_Memory_Size (Stack); if New_High_Water_Mark > Stack.High_Water_Mark then Stack.High_Water_Mark := New_High_Water_Mark; end if; end Allocate_On_Chunk; --------------------- -- Allocate_Static -- --------------------- procedure Allocate_Static (Stack : SS_Stack_Ptr; Mem_Size : Memory_Size; Addr : out Address) is begin -- Static secondary stack allocations are performed only on the static -- chunk. There should be no dynamic chunks following the static chunk. pragma Assert (Stack.Top.Chunk = Stack.Static_Chunk'Access); pragma Assert (Stack.Top.Chunk.Next = null); -- Raise Storage_Error if the static chunk does not have enough room to -- fit the memory request. This indicates that the stack is about to be -- depleted. if not Has_Enough_Free_Memory (Chunk => Stack.Top.Chunk, Byte => Stack.Top.Byte, Mem_Size => Mem_Size) then raise Storage_Error with "secondary stack exhaused"; end if; Allocate_On_Chunk (Stack => Stack, Prev_Chunk => null, Chunk => Stack.Top.Chunk, Byte => Stack.Top.Byte, Mem_Size => Mem_Size, Addr => Addr); end Allocate_Static; -------------------- -- Get_Chunk_Info -- -------------------- function Get_Chunk_Info (Stack : SS_Stack_Ptr; C_Id : Chunk_Id) return Chunk_Info is function Find_Chunk return SS_Chunk_Ptr; pragma Inline (Find_Chunk); -- Find the chunk which corresponds to Id. Return null if no such chunk -- exists. ---------------- -- Find_Chunk -- ---------------- function Find_Chunk return SS_Chunk_Ptr is Chunk : SS_Chunk_Ptr; Id : Chunk_Id; begin Chunk := Stack.Static_Chunk'Access; Id := 1; while Chunk /= null loop if Id = C_Id then return Chunk; end if; Chunk := Chunk.Next; Id := Id + 1; end loop; return null; end Find_Chunk; -- Local variables Chunk : constant SS_Chunk_Ptr := Find_Chunk; -- Start of processing for Get_Chunk_Info begin if Chunk = null then return Invalid_Chunk; else return (Size => Chunk.Size, Size_Up_To_Chunk => Chunk.Size_Up_To_Chunk); end if; end Get_Chunk_Info; -------------------- -- Get_Stack_Info -- -------------------- function Get_Stack_Info (Stack : SS_Stack_Ptr) return Stack_Info is Info : Stack_Info; begin Info.Default_Chunk_Size := Stack.Default_Chunk_Size; Info.Freeable := Stack.Freeable; Info.High_Water_Mark := Stack.High_Water_Mark; Info.Number_Of_Chunks := Number_Of_Chunks (Stack); Info.Top.Byte := Stack.Top.Byte; Info.Top.Chunk := Top_Chunk_Id (Stack); return Info; end Get_Stack_Info; ---------------------------- -- Has_Enough_Free_Memory -- ---------------------------- function Has_Enough_Free_Memory (Chunk : SS_Chunk_Ptr; Byte : Memory_Index; Mem_Size : Memory_Size) return Boolean is begin -- Byte - 1 denotes the last occupied byte. Subtracting that byte from -- the memory capacity of the chunk yields the size of the free memory -- within the chunk. The chunk can fit the request as long as the free -- memory is as big as the request. return Chunk.Size - (Byte - 1) >= Mem_Size; end Has_Enough_Free_Memory; ---------------------- -- Number_Of_Chunks -- ---------------------- function Number_Of_Chunks (Stack : SS_Stack_Ptr) return Chunk_Count is Chunk : SS_Chunk_Ptr; Count : Chunk_Count; begin Chunk := Stack.Static_Chunk'Access; Count := 0; while Chunk /= null loop Chunk := Chunk.Next; Count := Count + 1; end loop; return Count; end Number_Of_Chunks; ------------------------------ -- Size_Up_To_And_Including -- ------------------------------ function Size_Up_To_And_Including (Chunk : SS_Chunk_Ptr) return Memory_Size is begin return Chunk.Size_Up_To_Chunk + Chunk.Size; end Size_Up_To_And_Including; ----------------- -- SS_Allocate -- ----------------- procedure SS_Allocate (Addr : out Address; Storage_Size : Storage_Count) is function Round_Up (Size : Storage_Count) return Memory_Size; pragma Inline (Round_Up); -- Round Size up to the nearest multiple of the maximum alignment -------------- -- Round_Up -- -------------- function Round_Up (Size : Storage_Count) return Memory_Size is Algn_MS : constant Memory_Size := Memory_Alignment; Size_MS : constant Memory_Size := Memory_Size (Size); begin -- Detect a case where the Storage_Size is very large and may yield -- a rounded result which is outside the range of Chunk_Memory_Size. -- Treat this case as secondary-stack depletion. if Memory_Size'Last - Algn_MS < Size_MS then raise Storage_Error with "secondary stack exhausted"; end if; return ((Size_MS + Algn_MS - 1) / Algn_MS) * Algn_MS; end Round_Up; -- Local variables Stack : constant SS_Stack_Ptr := Get_Sec_Stack.all; Mem_Size : Memory_Size; -- Start of processing for SS_Allocate begin -- It should not be possible to request an allocation of negative or -- zero size. pragma Assert (Storage_Size > 0); -- Round the requested size up to the nearest multiple of the maximum -- alignment to ensure efficient access. Mem_Size := Round_Up (Storage_Size); if Sec_Stack_Dynamic then Allocate_Dynamic (Stack, Mem_Size, Addr); else Allocate_Static (Stack, Mem_Size, Addr); end if; end SS_Allocate; ------------- -- SS_Free -- ------------- procedure SS_Free (Stack : in out SS_Stack_Ptr) is Static_Chunk : constant SS_Chunk_Ptr := Stack.Static_Chunk'Access; Next_Chunk : SS_Chunk_Ptr; begin -- Free all dynamically allocated chunks. The first dynamic chunk is -- found immediately after the static chunk of the stack. while Static_Chunk.Next /= null loop Next_Chunk := Static_Chunk.Next.Next; Free (Static_Chunk.Next); Static_Chunk.Next := Next_Chunk; end loop; -- At this point one of the following outcomes has taken place: -- -- * The stack lacks any dynamic chunks -- -- * The stack had dynamic chunks which were all freed -- -- Either way, there should be nothing hanging off the static chunk pragma Assert (Static_Chunk.Next = null); -- Free the stack only when it was dynamically allocated if Stack.Freeable then Free (Stack); end if; end SS_Free; ---------------- -- SS_Get_Max -- ---------------- function SS_Get_Max return Long_Long_Integer is Stack : constant SS_Stack_Ptr := Get_Sec_Stack.all; begin return Long_Long_Integer (Stack.High_Water_Mark); end SS_Get_Max; ------------- -- SS_Info -- ------------- procedure SS_Info is procedure SS_Info_Dynamic (Stack : SS_Stack_Ptr); pragma Inline (SS_Info_Dynamic); -- Output relevant information concerning dynamic secondary stack Stack function Total_Memory_Size (Stack : SS_Stack_Ptr) return Memory_Size; pragma Inline (Total_Memory_Size); -- Calculate the size of stack Stack's total memory usage. This includes -- the following kinds of memory: -- -- * Free memory in used chunks due to alignment holes -- * Free memory in the topmost chunk due to partial usage -- * Free memory in unused chunks following the chunk indicated by the -- stack pointer. -- * Memory occupied by allocations -- -- This is a linear-time operation on the number of chunks. --------------------- -- SS_Info_Dynamic -- --------------------- procedure SS_Info_Dynamic (Stack : SS_Stack_Ptr) is begin Put_Line (" Number of Chunks : " & Number_Of_Chunks (Stack)'Img); Put_Line (" Default size of Chunks : " & Stack.Default_Chunk_Size'Img); end SS_Info_Dynamic; ----------------------- -- Total_Memory_Size -- ----------------------- function Total_Memory_Size (Stack : SS_Stack_Ptr) return Memory_Size is Chunk : SS_Chunk_Ptr; Total : Memory_Size; begin -- The total size of the stack is equal to the size of the stack up -- to the chunk indicated by the stack pointer, plus the size of the -- indicated chunk, plus the size of any subsequent chunks. Total := Size_Up_To_And_Including (Stack.Top.Chunk); Chunk := Stack.Top.Chunk.Next; while Chunk /= null loop Total := Total + Chunk.Size; Chunk := Chunk.Next; end loop; return Total; end Total_Memory_Size; -- Local variables Stack : constant SS_Stack_Ptr := Get_Sec_Stack.all; -- Start of processing for SS_Info begin Put_Line ("Secondary Stack information:"); Put_Line (" Total size : " & Total_Memory_Size (Stack)'Img & " bytes"); Put_Line (" Current allocated space : " & Used_Memory_Size (Stack)'Img & " bytes"); if Sec_Stack_Dynamic then SS_Info_Dynamic (Stack); end if; end SS_Info; ------------- -- SS_Init -- ------------- procedure SS_Init (Stack : in out SS_Stack_Ptr; Size : Size_Type := Unspecified_Size) is function Next_Available_Binder_Sec_Stack return SS_Stack_Ptr; pragma Inline (Next_Available_Binder_Sec_Stack); -- Return a pointer to the next available stack from the pool created by -- the binder. This routine updates global Default_Sec_Stack_Pool_Index. ------------------------------------- -- Next_Available_Binder_Sec_Stack -- ------------------------------------- function Next_Available_Binder_Sec_Stack return SS_Stack_Ptr is -- The default-sized secondary stack pool generated by the binder -- is passed to this unit as an Address because it is not possible -- to define a pointer to an array of unconstrained components. The -- pointer is instead obtained using an unchecked conversion to a -- constrained array of secondary stacks with the same size as that -- specified by the binder. -- WARNING: The following data structure must be synchronized with -- the one created in Bindgen.Gen_Output_File_Ada. The version in -- bindgen is called Sec_Default_Sized_Stacks. type SS_Pool is array (1 .. Binder_SS_Count) of aliased SS_Stack (Binder_Default_SS_Size); type SS_Pool_Ptr is access SS_Pool; -- A reference to the secondary stack pool function To_SS_Pool_Ptr is new Ada.Unchecked_Conversion (Address, SS_Pool_Ptr); -- Use an unchecked conversion to obtain a pointer to one of the -- secondary stacks from the pool generated by the binder. There -- are several reasons for using the conversion: -- -- * Accessibility checks prevent a value of a local pointer to be -- stored outside this scope. The conversion is safe because the -- pool is global to the whole application. -- -- * Unchecked_Access may circumvent the accessibility checks, but -- it is incompatible with restriction No_Unchecked_Access. -- -- * Unrestricted_Access may circumvent the accessibility checks, -- but it is incompatible with pure Ada constructs. -- ??? cannot find the restriction or switch pragma Warnings (Off); function To_SS_Stack_Ptr is new Ada.Unchecked_Conversion (Address, SS_Stack_Ptr); pragma Warnings (On); Pool : SS_Pool_Ptr; begin -- Obtain a typed view of the pool Pool := To_SS_Pool_Ptr (Binder_Default_SS_Pool); -- Advance the stack index to the next available stack Binder_Default_SS_Pool_Index := Binder_Default_SS_Pool_Index + 1; -- Return a pointer to the next available stack return To_SS_Stack_Ptr (Pool (Binder_Default_SS_Pool_Index)'Address); end Next_Available_Binder_Sec_Stack; -- Local variables Stack_Size : Memory_Size_With_Invalid; -- Start of processing for SS_Init begin -- Allocate a new stack on the heap or use one from the pool created by -- the binder. if Stack = null then -- The caller requested a pool-allocated stack. Determine the proper -- size of the stack based on input from the binder or the runtime in -- case the pool is exhausted. if Size = Unspecified_Size then -- Use the default secondary stack size as specified by the binder -- only when it has been set. This prevents a bootstrap issue with -- older compilers where the size is never set. if Binder_Default_SS_Size > 0 then Stack_Size := Binder_Default_SS_Size; -- Otherwise use the default stack size of the particular runtime else Stack_Size := Runtime_Default_Sec_Stack_Size; end if; -- Otherwise the caller requested a heap-allocated stack. Use the -- specified size directly. else Stack_Size := Size; end if; -- The caller requested a pool-allocated stack. Use one as long as -- the pool created by the binder has available stacks. This stack -- cannot be deallocated. if Size = Unspecified_Size and then Binder_SS_Count > 0 and then Binder_Default_SS_Pool_Index < Binder_SS_Count then Stack := Next_Available_Binder_Sec_Stack; Stack.Freeable := False; -- Otherwise the caller requested a heap-allocated stack, or the pool -- created by the binder ran out of available stacks. This stack can -- be deallocated. else -- It should not be possible to create a stack with a negative -- default chunk size. pragma Assert (Stack_Size in Memory_Size); Stack := new SS_Stack (Stack_Size); Stack.Freeable := True; end if; -- Otherwise the stack was already created either by the compiler or by -- the user, and is about to be reused. else null; end if; -- The static chunk becomes the chunk indicated by the stack pointer. -- Note that the stack may still hold dynamic chunks, which in turn may -- be reused or freed. Stack.Top.Chunk := Stack.Static_Chunk'Access; -- The first free byte is the first free byte of the chunk indicated by -- the stack pointer. Stack.Top.Byte := Stack.Top.Chunk.Memory'First; -- Since the chunk indicated by the stack pointer is also the first -- chunk in the stack, there are no prior chunks, therefore the size -- of the stack up to the chunk is zero. Stack.Top.Chunk.Size_Up_To_Chunk := 0; -- Reset the high water mark to account for brand new allocations Stack.High_Water_Mark := 0; end SS_Init; ------------- -- SS_Mark -- ------------- function SS_Mark return Mark_Id is Stack : constant SS_Stack_Ptr := Get_Sec_Stack.all; begin return (Stack => Stack, Top => Stack.Top); end SS_Mark; ---------------- -- SS_Release -- ---------------- procedure SS_Release (M : Mark_Id) is begin M.Stack.Top := M.Top; end SS_Release; ------------------ -- Top_Chunk_Id -- ------------------ function Top_Chunk_Id (Stack : SS_Stack_Ptr) return Chunk_Id_With_Invalid is Chunk : SS_Chunk_Ptr; Id : Chunk_Id; begin Chunk := Stack.Static_Chunk'Access; Id := 1; while Chunk /= null loop if Chunk = Stack.Top.Chunk then return Id; end if; Chunk := Chunk.Next; Id := Id + 1; end loop; return Invalid_Chunk_Id; end Top_Chunk_Id; ---------------------- -- Used_Memory_Size -- ---------------------- function Used_Memory_Size (Stack : SS_Stack_Ptr) return Memory_Size is begin -- The size of the occupied memory is equal to the size up to the chunk -- indicated by the stack pointer, plus the size in use by the indicated -- chunk itself. Top.Byte - 1 is the last occupied byte. -- -- Top.Byte -- | -- . . . . . . . +--------------|----+ -- . ..> |##############| | -- . . . . . . . +-------------------+ -- | | -- -------------------+-------------+ -- Size_Up_To_Chunk size in use -- ??? this calculation may overflow on 32bit targets return Stack.Top.Chunk.Size_Up_To_Chunk + Stack.Top.Byte - 1; end Used_Memory_Size; end System.Secondary_Stack;
-- SPDX-License-Identifier: Apache-2.0 -- -- Copyright (c) 2015 onox <denkpadje@gmail.com> -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. with GL.Objects.Programs; private with GL.Low_Level; package GL.Objects.Pipelines is pragma Preelaborate; type Stage_Bits is record Vertex_Shader : Boolean := False; Fragment_Shader : Boolean := False; Geometry_Shader : Boolean := False; Tess_Control_Shader : Boolean := False; Tess_Evaluation_Shader : Boolean := False; Compute_Shader : Boolean := False; end record; type Pipeline is new GL_Object with private; procedure Use_Program_Stages (Object : Pipeline; Stages : Stage_Bits; Program : Programs.Program) with Pre => Program.Separable; -- Use the specified stages from the given program in the pipeline procedure Bind (Object : Pipeline); -- Bind the pipeline to the current context function Validate (Object : Pipeline) return Boolean; function Info_Log (Object : Pipeline) return String; overriding procedure Initialize_Id (Object : in out Pipeline); overriding procedure Delete_Id (Object : in out Pipeline); overriding function Identifier (Object : Pipeline) return Types.Debug.Identifier is (Types.Debug.Program_Pipeline); private type Pipeline is new GL_Object with null record; for Stage_Bits use record Vertex_Shader at 0 range 0 .. 0; Fragment_Shader at 0 range 1 .. 1; Geometry_Shader at 0 range 2 .. 2; Tess_Control_Shader at 0 range 3 .. 3; Tess_Evaluation_Shader at 0 range 4 .. 4; Compute_Shader at 0 range 5 .. 5; end record; for Stage_Bits'Size use Low_Level.Bitfield'Size; end GL.Objects.Pipelines;
with Ada.Text_IO; use Ada.Text_IO; with Ada.Containers.Vectors; procedure SelfRef is subtype Seed is Natural range 0 .. 1_000_000; subtype Num is Natural range 0 .. 10; type NumList is array (0 .. 10) of Num; package IO is new Ada.Text_IO.Integer_IO (Natural); package DVect is new Ada.Containers.Vectors (Positive, NumList); function Init (innum : Seed) return NumList is list : NumList := (others => 0); number : Seed := innum; d : Num; begin loop d := Num (number mod 10); list (d) := list (d) + 1; number := number / 10; exit when number = 0; end loop; return list; end Init; procedure Next (inoutlist : in out NumList) is list : NumList := (others => 0); begin for i in list'Range loop if inoutlist (i) /= 0 then list (i) := list (i) + 1; list (inoutlist (i)) := list (inoutlist (i)) + 1; end if; end loop; inoutlist := list; end Next; procedure Show (list : NumList) is begin for i in reverse list'Range loop if list (i) > 0 then IO.Put (list (i), Width => 1); IO.Put (i, Width => 1); end if; end loop; New_Line; end Show; function Iterate (theseed : Seed; p : Boolean) return Natural is list : NumList := Init (theseed); vect : DVect.Vector; begin vect.Append (list); loop if p then Show (list); end if; Next (list); exit when vect.Contains (list); vect.Append (list); end loop; return Integer (DVect.Length (vect)) + 1; end Iterate; mseed : Seed; len, maxlen : Natural := 0; begin for i in Seed'Range loop len := Iterate (i, False); if len > maxlen then mseed := i; maxlen := len; end if; end loop; IO.Put (maxlen, Width => 1); Put_Line (" Iterations:"); IO.Put (mseed, Width => 1); New_Line; len := Iterate (mseed, True); end SelfRef;
with Ada.Integer_Text_IO; with Ada.Text_IO; with BigInteger; use BigInteger; package body Problem_16 is package IO renames Ada.Text_IO; package I_IO renames Ada.Integer_Text_IO; procedure Solve is Big : constant BigInteger.BigInt := BigInteger.Create(2)**1_000; Str : constant String := BigInteger.ToString(Big); Digit_Sum : Natural := 0; begin for index in Str'Range loop Digit_Sum := Digit_Sum + Character'Pos(Str(index)) - Character'Pos('0'); end loop; I_IO.Put(Digit_Sum); IO.New_Line; end Solve; end Problem_16;
package Example1 is procedure Sense ; procedure Handle_Deadline; Count : Integer := 0; Dummy : Integer := 0; end Example1;
-- part of OpenGLAda, (c) 2017 Felix Krause -- released under the terms of the MIT license, see the file "COPYING" with Ada.Strings.Unbounded; with GL.Types; package GL.Context is pragma Preelaborate; use GL.Types; type String_List is array (Positive range <>) of Ada.Strings.Unbounded.Unbounded_String; Null_String_List : constant String_List := (2 .. 1 => <>); -- these two require OpenGL 3: function Major_Version return Int; function Minor_Version return Int; -- legacy (deprecated in OpenGL 3) function Version_String return String; function Vendor return String; function Renderer return String; -- uses OpenGL 3 interface if available, otherwise old interface function Extensions return String_List; function Has_Extension (Name : String) return Boolean; function Primary_Shading_Language_Version return String; -- available since OpenGL 4.3: function Supported_Shading_Language_Versions return String_List; function Supports_Shading_Language_Version (Name : String) return Boolean; end GL.Context;
-- { dg-do run } with System; use System; with Ada.Text_IO; use Ada.Text_IO; procedure Conv1 is type Short is mod 2**16; type R_L is record S : Short; C : Character; end record; for R_L'Bit_Order use Low_Order_First; for R_L'Scalar_Storage_Order use Low_Order_First; for R_L use record S at 0 range 0 .. 15; C at 2 range 0 .. 7; end record; type R_H is new R_L; for R_H'Bit_Order use High_Order_First; for R_H'Scalar_Storage_Order use High_Order_First; for R_H use record S at 0 range 0 .. 15; C at 2 range 0 .. 7; end record; procedure Dump (Name : String; S : Short; C : Character) is begin Put_Line (Name & " = (S =>" & S'Img & ", C => '" & C & "')"); end Dump; X_L : R_L; X_H : R_H; begin X_L.S := 12345; X_L.C := 'a'; Dump ("X_L", X_L.S, X_L.C); -- { dg-output "X_L = \\(S => 12345, C => 'a'\\).*\n" } X_H.S := 23456; X_H.C := 'b'; Dump ("X_H", X_H.S, X_H.C); -- { dg-output "X_H = \\(S => 23456, C => 'b'\\).*\n" } X_H := R_H (X_L); Dump ("X_H", X_H.S, X_H.C); -- { dg-output "X_H = \\(S => 12345, C => 'a'\\).*\n" } end;
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- Localization, Internationalization, Globalization for Ada -- -- -- -- Runtime Library Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2010, Vadim Godunko <vgodunko@gmail.com> -- -- All rights reserved. -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions -- -- are met: -- -- -- -- * Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- -- -- * Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in the -- -- documentation and/or other materials provided with the distribution. -- -- -- -- * Neither the name of the Vadim Godunko, IE nor the names of its -- -- contributors may be used to endorse or promote products derived from -- -- this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -- -- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED -- -- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -- -- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -- -- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -- -- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -- -- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- -- ------------------------------------------------------------------------------ -- $Revision$ $Date$ ------------------------------------------------------------------------------ with Matreshka.Internals.Regexps.Compiler.Optimizer; with Matreshka.Internals.Regexps.Compiler.Parser; with Matreshka.Internals.Regexps.Compiler.Semantic; package body Matreshka.Internals.Regexps.Compiler is use Matreshka.Internals.Regexps.Compiler.Optimizer; use Matreshka.Internals.Regexps.Compiler.Parser; use Matreshka.Internals.Regexps.Compiler.Semantic; procedure Append (Pattern : not null Shared_Pattern_Access; List : Node_List_Index; Node : Positive); function Create_Node_List (Pattern : not null Shared_Pattern_Access; Parent : Positive) return Node_List_Index; procedure Add (Pattern : in out Shared_Pattern; Class : Positive; Member : Positive); procedure Set_Preferred (Pattern : not null Shared_Pattern_Access; Node : Positive; To : Positive); procedure Set_Fallback (Pattern : not null Shared_Pattern_Access; Node : Positive; To : Positive); procedure Set_Expression (Pattern : not null Shared_Pattern_Access; Node : Positive; To : Positive); --------- -- Add -- --------- procedure Add (Pattern : in out Shared_Pattern; Class : Positive; Member : Positive) is begin if Pattern.AST (Class).Members = 0 then Pattern.Last_List := Pattern.Last_List + 1; Pattern.AST (Class).Members := Pattern.Last_List; Pattern.List (Pattern.Last_List) := (Class, Member, Member); Pattern.AST (Member).List := Pattern.Last_List; Pattern.AST (Member).Next := 0; else Attach (Pattern, Pattern.List (Pattern.AST (Class).Members).Head, Member); end if; end Add; ------------ -- Append -- ------------ procedure Append (Pattern : not null Shared_Pattern_Access; List : Node_List_Index; Node : Positive) is pragma Assert (Pattern.AST (Node).List = 0); J : constant Natural := Pattern.List (List).Tail; begin if J = 0 then Pattern.List (List).Head := Node; Pattern.List (List).Tail := Node; Pattern.AST (Node).List := List; else Pattern.List (List).Tail := Node; Pattern.AST (J).Next := Node; Pattern.AST (Node).List := List; Pattern.AST (Node).Previous := J; end if; end Append; ------------ -- Attach -- ------------ procedure Attach (Pattern : in out Shared_Pattern; Head : Positive; Node : Positive) is J : Positive; begin if Pattern.AST (Head).List = 0 then Pattern.Last_List := Pattern.Last_List + 1; Pattern.List (Pattern.Last_List) := (0, Head, Head); Pattern.AST (Head).List := Pattern.Last_List; end if; J := Pattern.List (Pattern.AST (Head).List).Tail; Pattern.List (Pattern.AST (Head).List).Tail := Node; Pattern.AST (J).Next := Node; Pattern.AST (Node).List := Pattern.AST (Head).List; Pattern.AST (Node).Previous := J; end Attach; ------------- -- Compile -- ------------- function Compile (Expression : not null Matreshka.Internals.Strings.Shared_String_Access) return not null Shared_Pattern_Access is State : aliased Compiler_State; begin State.Data := Expression; return Pattern : constant not null Shared_Pattern_Access := YYParse (State'Access) do Analyze (Pattern); Optimize (Pattern); end return; end Compile; ------------------------ -- Create_Alternative -- ------------------------ function Create_Alternative (Pattern : not null Shared_Pattern_Access; Prefered : Positive; Alternative : Positive) return Positive is begin Pattern.Last := Pattern.Last + 1; Pattern.AST (Pattern.Last) := (N_Alternation, 0, 0, 0, 0, 0); Set_Preferred (Pattern, Pattern.Last, Prefered); Set_Fallback (Pattern, Pattern.Last, Alternative); return Pattern.Last; end Create_Alternative; ------------------------------- -- Create_Anchor_End_Of_Line -- ------------------------------- function Create_Anchor_End_Of_Line (Pattern : not null Shared_Pattern_Access) return Positive is begin Pattern.Last := Pattern.Last + 1; Pattern.AST (Pattern.Last) := (N_Anchor, 0, 0, 0, False, True); return Pattern.Last; end Create_Anchor_End_Of_Line; --------------------------------- -- Create_Anchor_Start_Of_Line -- --------------------------------- function Create_Anchor_Start_Of_Line (Pattern : not null Shared_Pattern_Access) return Positive is begin Pattern.Last := Pattern.Last + 1; Pattern.AST (Pattern.Last) := (N_Anchor, 0, 0, 0, True, False); return Pattern.Last; end Create_Anchor_Start_Of_Line; ---------------------------- -- Create_Character_Class -- ---------------------------- function Create_Character_Class (Pattern : not null Shared_Pattern_Access) return Positive is begin Pattern.Last := Pattern.Last + 1; Pattern.AST (Pattern.Last) := (N_Character_Class, 0, 0, 0, False, 0); return Pattern.Last; end Create_Character_Class; ---------------------- -- Create_Match_Any -- ---------------------- function Create_Match_Any (Pattern : not null Shared_Pattern_Access) return Positive is begin Pattern.Last := Pattern.Last + 1; Pattern.AST (Pattern.Last) := (N_Match_Any, 0, 0, 0); return Pattern.Last; end Create_Match_Any; ---------------------------- -- Create_Match_Character -- ---------------------------- function Create_Match_Character (Pattern : not null Shared_Pattern_Access; Character : Matreshka.Internals.Unicode.Code_Point) return Positive is begin Pattern.Last := Pattern.Last + 1; Pattern.AST (Pattern.Last) := (N_Match_Code, 0, 0, 0, Character); return Pattern.Last; end Create_Match_Character; --------------------------- -- Create_Match_Property -- --------------------------- function Create_Match_Property (Pattern : not null Shared_Pattern_Access; Value : Matreshka.Internals.Unicode.Ucd.Boolean_Properties; Negative : Boolean) return Positive is begin Pattern.Last := Pattern.Last + 1; Pattern.AST (Pattern.Last) := (N_Match_Property, 0, 0, 0, (Binary, Value), Negative); return Pattern.Last; end Create_Match_Property; --------------------------- -- Create_Match_Property -- --------------------------- function Create_Match_Property (Pattern : not null Shared_Pattern_Access; Value : General_Category_Flags; Negative : Boolean) return Positive is begin Pattern.Last := Pattern.Last + 1; Pattern.AST (Pattern.Last) := (N_Match_Property, 0, 0, 0, (General_Category, Value), Negative); return Pattern.Last; end Create_Match_Property; ----------------------------- -- Create_Member_Character -- ----------------------------- procedure Create_Member_Character (Pattern : not null Shared_Pattern_Access; Class : Positive; Character : Matreshka.Internals.Unicode.Code_Point) is begin Pattern.Last := Pattern.Last + 1; Pattern.AST (Pattern.Last) := (N_Member_Code, 0, 0, 0, Character); Add (Pattern.all, Class, Pattern.Last); end Create_Member_Character; ---------------------------- -- Create_Member_Property -- ---------------------------- procedure Create_Member_Property (Pattern : not null Shared_Pattern_Access; Class : Positive; Value : Matreshka.Internals.Unicode.Ucd.Boolean_Properties; Negative : Boolean) is begin Pattern.Last := Pattern.Last + 1; Pattern.AST (Pattern.Last) := (N_Member_Property, 0, 0, 0, (Binary, Value), Negative); Add (Pattern.all, Class, Pattern.Last); end Create_Member_Property; ---------------------------- -- Create_Member_Property -- ---------------------------- procedure Create_Member_Property (Pattern : not null Shared_Pattern_Access; Class : Positive; Value : General_Category_Flags; Negative : Boolean) is begin Pattern.Last := Pattern.Last + 1; Pattern.AST (Pattern.Last) := (N_Member_Property, 0, 0, 0, (General_Category, Value), Negative); Add (Pattern.all, Class, Pattern.Last); end Create_Member_Property; ------------------------- -- Create_Member_Range -- ------------------------- procedure Create_Member_Range (Pattern : not null Shared_Pattern_Access; Class : Positive; Low : Matreshka.Internals.Unicode.Code_Point; High : Matreshka.Internals.Unicode.Code_Point) is begin Pattern.Last := Pattern.Last + 1; Pattern.AST (Pattern.Last) := (N_Member_Range, 0, 0, 0, Low, High); Add (Pattern.all, Class, Pattern.Last); end Create_Member_Range; ---------------------- -- Create_Node_List -- ---------------------- function Create_Node_List (Pattern : not null Shared_Pattern_Access; Parent : Positive) return Node_List_Index is begin Pattern.Last_List := Pattern.Last_List + 1; Pattern.List (Pattern.Last_List) := (Parent, 0, 0); return Pattern.Last_List; end Create_Node_List; ----------------------- -- Create_Repetition -- ----------------------- function Create_Repetition (Pattern : not null Shared_Pattern_Access; Expression : Positive; Lower : Natural; Upper : Natural; Greedy : Boolean) return Positive is begin Pattern.Last := Pattern.Last + 1; Pattern.AST (Pattern.Last) := (N_Multiplicity, 0, 0, 0, 0, Greedy, Lower, Upper); Set_Expression (Pattern, Pattern.Last, Expression); return Pattern.Last; end Create_Repetition; -------------------------- -- Create_Subexpression -- -------------------------- function Create_Subexpression (Pattern : not null Shared_Pattern_Access; Expression : Positive; Capture : Boolean) return Positive is begin Pattern.Last := Pattern.Last + 1; Pattern.AST (Pattern.Last) := (N_Subexpression, 0, 0, 0, 0, Capture, 0); Set_Expression (Pattern, Pattern.Last, Expression); return Pattern.Last; end Create_Subexpression; -------------------- -- Get_Expression -- -------------------- function Get_Expression (Pattern : not null Shared_Pattern_Access; Node : Positive) return Natural is begin if Pattern.AST (Node).Kind = N_Multiplicity then return Pattern.List (Pattern.AST (Node).Item).Head; elsif Pattern.AST (Node).Kind = N_Subexpression then return Pattern.List (Pattern.AST (Node).Subexpression).Head; else raise Program_Error; end if; end Get_Expression; ------------------ -- Get_Fallback -- ------------------ function Get_Fallback (Pattern : not null Shared_Pattern_Access; Node : Positive) return Natural is begin return Pattern.List (Pattern.AST (Node).Fallback).Head; end Get_Fallback; --------------------- -- Get_Lower_Bound -- --------------------- function Get_Lower_Bound (Pattern : not null Shared_Pattern_Access; Node : Positive) return Natural is begin return Pattern.AST (Node).Lower; end Get_Lower_Bound; ----------------- -- Get_Members -- ----------------- function Get_Members (Pattern : not null Shared_Pattern_Access; Node : Positive) return Natural is begin return Pattern.List (Pattern.AST (Node).Members).Head; end Get_Members; ---------------------- -- Get_Next_Sibling -- ---------------------- function Get_Next_Sibling (Pattern : not null Shared_Pattern_Access; Node : Positive) return Natural is begin return Pattern.AST (Node).Next; end Get_Next_Sibling; ------------------- -- Get_Preferred -- ------------------- function Get_Preferred (Pattern : not null Shared_Pattern_Access; Node : Positive) return Natural is begin return Pattern.List (Pattern.AST (Node).Preferred).Head; end Get_Preferred; -------------------------- -- Get_Previous_Sibling -- -------------------------- function Get_Previous_Sibling (Pattern : not null Shared_Pattern_Access; Node : Positive) return Natural is begin return Pattern.AST (Node).Previous; end Get_Previous_Sibling; --------------------- -- Get_Upper_Bound -- --------------------- function Get_Upper_Bound (Pattern : not null Shared_Pattern_Access; Node : Positive) return Natural is begin return Pattern.AST (Node).Upper; end Get_Upper_Bound; -------------------- -- Set_Expression -- -------------------- procedure Set_Expression (Pattern : not null Shared_Pattern_Access; Node : Positive; To : Positive) is begin if Pattern.AST (Node).Kind = N_Subexpression then if Pattern.AST (Node).Subexpression = 0 then if Pattern.AST (To).List = 0 then Pattern.AST (Node).Subexpression := Create_Node_List (Pattern, Node); Append (Pattern, Pattern.AST (Node).Subexpression, To); else Pattern.AST (Node).Subexpression := Pattern.AST (To).List; end if; else raise Program_Error; end if; elsif Pattern.AST (Node).Kind = N_Multiplicity then if Pattern.AST (Node).Item = 0 then if Pattern.AST (To).List = 0 then Pattern.AST (Node).Item := Create_Node_List (Pattern, Node); Append (Pattern, Pattern.AST (Node).Item, To); else Pattern.AST (Node).Item := Pattern.AST (To).List; end if; else raise Program_Error; end if; end if; end Set_Expression; ------------------ -- Set_Fallback -- ------------------ procedure Set_Fallback (Pattern : not null Shared_Pattern_Access; Node : Positive; To : Positive) is begin if Pattern.AST (Node).Fallback = 0 then if Pattern.AST (To).List = 0 then Pattern.AST (Node).Fallback := Create_Node_List (Pattern, Node); Append (Pattern, Pattern.AST (Node).Fallback, To); else Pattern.AST (Node).Fallback := Pattern.AST (To).List; end if; else raise Program_Error; end if; end Set_Fallback; ------------------- -- Set_Preferred -- ------------------- procedure Set_Preferred (Pattern : not null Shared_Pattern_Access; Node : Positive; To : Positive) is begin if Pattern.AST (Node).Preferred = 0 then if Pattern.AST (To).List = 0 then Pattern.AST (Node).Preferred := Create_Node_List (Pattern, Node); Append (Pattern, Pattern.AST (Node).Preferred, To); else Pattern.AST (Node).Preferred := Pattern.AST (To).List; end if; else raise Program_Error; end if; end Set_Preferred; ------------- -- YYError -- ------------- procedure YYError (Self : not null access Compiler_State; Error : YY_Errors; Index : Natural) is begin if Self.YY_Error.Error = No_Error then Self.YY_Error := (Error, Index); end if; end YYError; end Matreshka.Internals.Regexps.Compiler;
----------------------------------------------------------------------- -- Render Tests - Unit tests for AWA Wiki rendering -- Copyright (C) 2013, 2016, 2020, 2021 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.Wide_Wide_Text_IO; with Ada.Directories; with Util.Measures; with Wiki.Strings; with Wiki.Render.Wiki; with Wiki.Render.Html; with Wiki.Render.Text; with Wiki.Filters.Html; with Wiki.Filters.TOC; with Wiki.Filters.Autolink; with Wiki.Filters.Variables; with Wiki.Filters.Collectors; with Wiki.Plugins.Templates; with Wiki.Plugins.Conditions; with Wiki.Plugins.Variables; with Wiki.Streams.Text_IO; with Wiki.Streams.Html.Text_IO; with Wiki.Documents; with Wiki.Parsers; package body Wiki.Tests is use Ada.Strings.Unbounded; -- ------------------------------ -- Test rendering a wiki text in HTML or text. -- ------------------------------ procedure Test_Render (T : in out Test) is use Ada.Directories; Result_File : constant String := To_String (T.Result); Dir : constant String := Containing_Directory (Result_File); Doc : Wiki.Documents.Document; Engine : Wiki.Parsers.Parser; Toc_Filter : aliased Wiki.Filters.TOC.TOC_Filter; Html_Filter : aliased Wiki.Filters.Html.Html_Filter_Type; Var_Filter : aliased Wiki.Filters.Variables.Variable_Filter; Auto_Filter : aliased Wiki.Filters.Autolink.Autolink_Filter; Words : aliased Wiki.Filters.Collectors.Word_Collector_Type; Links : aliased Wiki.Filters.Collectors.Link_Collector_Type; Images : aliased Wiki.Filters.Collectors.Image_Collector_Type; Template : aliased Wiki.Plugins.Templates.File_Template_Plugin; Condition : aliased Wiki.Plugins.Conditions.Condition_Plugin; Variables : aliased Wiki.Plugins.Variables.Variable_Plugin; List_Vars : aliased Wiki.Plugins.Variables.List_Variable_Plugin; Input : aliased Wiki.Streams.Text_IO.File_Input_Stream; Output : aliased Wiki.Streams.Html.Text_IO.Html_Output_Stream; type Test_Factory is new Wiki.Plugins.Plugin_Factory with null record; -- Find a plugin knowing its name. overriding function Find (Factory : in Test_Factory; Name : in String) return Wiki.Plugins.Wiki_Plugin_Access; overriding function Find (Factory : in Test_Factory; Name : in String) return Wiki.Plugins.Wiki_Plugin_Access is pragma Unreferenced (Factory); begin if Name = "if" or Name = "else" or Name = "elsif" or Name = "end" then return Condition'Unchecked_Access; elsif Name = "set" then return Variables'Unchecked_Access; elsif Name = "list" then return List_Vars'Unchecked_Access; else return Template.Find (Name); end if; end Find; Local_Factory : aliased Test_Factory; Has_Collector : constant Boolean := Length (T.Collect) > 0; begin if not Exists (Dir) then Create_Path (Dir); end if; Input.Open (Path => To_String (T.File), Form => "WCEM=8"); Output.Create (Result_File, "WCEM=8"); Template.Set_Template_Path (Containing_Directory (To_String (T.File))); Condition.Append ("public", ""); Condition.Append ("user", "admin"); declare Time : Util.Measures.Stamp; begin Engine.Set_Syntax (T.Source); Engine.Set_Plugin_Factory (Local_Factory'Unchecked_Access); if Has_Collector then Engine.Add_Filter (Words'Unchecked_Access); Engine.Add_Filter (Links'Unchecked_Access); Engine.Add_Filter (Images'Unchecked_Access); end if; Engine.Add_Filter (Toc_Filter'Unchecked_Access); Engine.Add_Filter (Auto_Filter'Unchecked_Access); Engine.Add_Filter (Html_Filter'Unchecked_Access); Engine.Add_Filter (Var_Filter'Unchecked_Access); Engine.Parse (Input'Unchecked_Access, Doc); Var_Filter.Add_Variable (String '("file"), Wiki.Strings.To_WString (To_String (T.Name))); Util.Measures.Report (Time, "Parse " & To_String (T.Name)); if T.Source = Wiki.SYNTAX_HTML or T.Is_Cvt then declare Renderer : aliased Wiki.Render.Wiki.Wiki_Renderer; begin Renderer.Set_Output_Stream (Output'Unchecked_Access, T.Format); Renderer.Render (Doc); Output.Close; Util.Measures.Report (Time, "Render Wiki " & To_String (T.Name)); end; elsif T.Is_Html then declare Renderer : aliased Wiki.Render.Html.Html_Renderer; begin Renderer.Set_Output_Stream (Output'Unchecked_Access); Renderer.Set_Render_TOC (True); Renderer.Render (Doc); Output.Close; Util.Measures.Report (Time, "Render HTML " & To_String (T.Name)); end; else declare Renderer : aliased Wiki.Render.Text.Text_Renderer; begin Renderer.Set_Output_Stream (Output'Unchecked_Access); Renderer.Render (Doc); Output.Close; Util.Measures.Report (Time, "Render Text " & To_String (T.Name)); end; end if; end; Input.Close; Util.Tests.Assert_Equal_Files (T => T, Expect => To_String (T.Expect), Test => Result_File, Message => "Render"); if Has_Collector then declare procedure Print (Pos : in Wiki.Filters.Collectors.Cursor); Path : constant String := To_String (T.Collect); Dir : constant String := Containing_Directory (Path); File : Ada.Wide_Wide_Text_IO.File_Type; procedure Print (Pos : in Wiki.Filters.Collectors.Cursor) is use Wiki.Filters.Collectors; Word : constant Wiki.Strings.WString := WString_Maps.Key (Pos); Count : constant Natural := WString_Maps.Element (Pos); begin Ada.Wide_Wide_Text_IO.Put (File, Word); Ada.Wide_Wide_Text_IO.Put_Line (File, Natural'Wide_Wide_Image (Count)); end Print; begin if not Exists (Dir) then Create_Path (Dir); end if; Ada.Wide_Wide_Text_IO.Create (File, Ada.Wide_Wide_Text_IO.Out_File, Path); Ada.Wide_Wide_Text_IO.Put_Line (File, "== Words =="); Words.Iterate (Print'Access); Ada.Wide_Wide_Text_IO.Put_Line (File, "== Links =="); Links.Iterate (Print'Access); Ada.Wide_Wide_Text_IO.Put_Line (File, "== Images =="); Images.Iterate (Print'Access); Ada.Wide_Wide_Text_IO.Close (File); Util.Tests.Assert_Equal_Files (T => T, Expect => To_String (T.Expect_Collect), Test => Path, Message => "Collect"); end; end if; end Test_Render; -- ------------------------------ -- Test case name -- ------------------------------ overriding function Name (T : in Test) return Util.Tests.Message_String is begin if T.Source = Wiki.SYNTAX_HTML then return Util.Tests.Format ("Test IMPORT " & To_String (T.Name)); elsif T.Is_Html then return Util.Tests.Format ("Test HTML " & To_String (T.Name)); else return Util.Tests.Format ("Test TEXT " & To_String (T.Name)); end if; end Name; -- ------------------------------ -- Perform the test. -- ------------------------------ overriding procedure Run_Test (T : in out Test) is begin T.Test_Render; end Run_Test; procedure Add_Tests (Suite : in Util.Tests.Access_Test_Suite) is use Ada.Directories; procedure Add_Import_Tests; procedure Add_Wiki_Tests; procedure Add_Convert_Tests; function Create_Test (Name : in String; Path : in String; Format : in Wiki.Wiki_Syntax; Prefix : in String; Collect : in String; Is_Html : in Boolean) return Test_Case_Access; Result_Dir : constant String := ""; Expect_Dir : constant String := "regtests/expect"; Expect_Path : constant String := Util.Tests.Get_Path (Expect_Dir); Result_Path : constant String := Util.Tests.Get_Test_Path (Result_Dir); Search : Search_Type; Filter : constant Filter_Type := (others => True); Ent : Directory_Entry_Type; function Create_Test (Name : in String; Path : in String; Format : in Wiki.Wiki_Syntax; Prefix : in String; Collect : in String; Is_Html : in Boolean) return Test_Case_Access is Tst : Test_Case_Access; begin Tst := new Test; Tst.Is_Html := Is_Html; Tst.Name := To_Unbounded_String (Name); Tst.File := To_Unbounded_String (Path); Tst.Expect := To_Unbounded_String (Expect_Path & Prefix & Name); Tst.Result := To_Unbounded_String (Result_Path & Prefix & Name); if Collect'Length > 0 then Tst.Collect := To_Unbounded_String (Result_Path & Collect & Name); Tst.Expect_Collect := To_Unbounded_String (Expect_Path & Collect & Name); end if; Tst.Format := Format; Tst.Source := Format; return Tst; end Create_Test; procedure Add_Wiki_Tests is Dir : constant String := "regtests/files/wiki"; Path : constant String := Util.Tests.Get_Path (Dir); begin if Kind (Path) /= Directory then Ada.Text_IO.Put_Line ("Cannot read test directory: " & Path); end if; Start_Search (Search, Directory => Path, Pattern => "*.*", Filter => Filter); while More_Entries (Search) loop Get_Next_Entry (Search, Ent); declare Simple : constant String := Simple_Name (Ent); Ext : constant String := Ada.Directories.Extension (Simple); Tst : Test_Case_Access; Format : Wiki.Wiki_Syntax; begin if Simple /= "." and then Simple /= ".." and then Simple /= ".svn" and then Simple (Simple'Last) /= '~' then if Ext = "wiki" then Format := Wiki.SYNTAX_GOOGLE; elsif Ext = "dotclear" then Format := Wiki.SYNTAX_DOTCLEAR; elsif Ext = "creole" then Format := Wiki.SYNTAX_CREOLE; elsif Ext = "phpbb" then Format := Wiki.SYNTAX_PHPBB; elsif Ext = "mediawiki" then Format := Wiki.SYNTAX_MEDIA_WIKI; elsif Ext = "markdown" then Format := Wiki.SYNTAX_MARKDOWN; else Format := Wiki.SYNTAX_MIX; end if; Tst := Create_Test (Simple, Path & "/" & Simple, Format, "/wiki-html/", "/wiki-collect/", True); Suite.Add_Test (Tst.all'Access); Tst := Create_Test (Simple, Path & "/" & Simple, Format, "/wiki-txt/", "", False); Suite.Add_Test (Tst.all'Access); end if; end; end loop; end Add_Wiki_Tests; procedure Add_Import_Tests is Dir : constant String := "regtests/files/html"; Path : constant String := Util.Tests.Get_Path (Dir); begin if Kind (Path) /= Directory then Ada.Text_IO.Put_Line ("Cannot read test directory: " & Path); end if; Start_Search (Search, Directory => Path, Pattern => "*.*", Filter => Filter); while More_Entries (Search) loop Get_Next_Entry (Search, Ent); declare Simple : constant String := Simple_Name (Ent); Name : constant String := Base_Name (Simple); Tst : Test_Case_Access; begin if Simple /= "." and then Simple /= ".." and then Simple /= ".svn" and then Simple (Simple'Last) /= '~' then for Syntax in Wiki.Wiki_Syntax'Range loop case Syntax is when Wiki.SYNTAX_CREOLE => Tst := Create_Test (Name & ".creole", Path & "/" & Simple, Syntax, "/wiki-import/", "", True); when Wiki.SYNTAX_DOTCLEAR => Tst := Create_Test (Name & ".dotclear", Path & "/" & Simple, Syntax, "/wiki-import/", "", True); when Wiki.SYNTAX_MEDIA_WIKI => Tst := Create_Test (Name & ".mediawiki", Path & "/" & Simple, Syntax, "/wiki-import/", "", True); when Wiki.SYNTAX_MARKDOWN => Tst := Create_Test (Name & ".markdown", Path & "/" & Simple, Syntax, "/wiki-import/", "", True); when others => Tst := null; end case; if Tst /= null then Tst.Source := Wiki.SYNTAX_HTML; Suite.Add_Test (Tst.all'Access); end if; end loop; end if; end; end loop; end Add_Import_Tests; procedure Add_Convert_Tests is Dir : constant String := "regtests/files/convert"; Path : constant String := Util.Tests.Get_Path (Dir); begin if Kind (Path) /= Directory then Ada.Text_IO.Put_Line ("Cannot read test directory: " & Path); end if; Start_Search (Search, Directory => Path, Pattern => "*.*", Filter => Filter); while More_Entries (Search) loop Get_Next_Entry (Search, Ent); declare Simple : constant String := Simple_Name (Ent); Ext : constant String := Ada.Directories.Extension (Simple); Name : constant String := Base_Name (Simple); Tst : Test_Case_Access; Format : Wiki.Wiki_Syntax; begin if Simple /= "." and then Simple /= ".." and then Simple /= ".svn" and then Simple (Simple'Last) /= '~' then if Ext = "wiki" then Format := Wiki.SYNTAX_GOOGLE; elsif Ext = "dotclear" then Format := Wiki.SYNTAX_DOTCLEAR; elsif Ext = "creole" then Format := Wiki.SYNTAX_CREOLE; elsif Ext = "phpbb" then Format := Wiki.SYNTAX_PHPBB; elsif Ext = "mediawiki" then Format := Wiki.SYNTAX_MEDIA_WIKI; elsif Ext = "markdown" then Format := Wiki.SYNTAX_MARKDOWN; else Format := Wiki.SYNTAX_MIX; end if; for Syntax in Wiki.Wiki_Syntax'Range loop case Syntax is when Wiki.SYNTAX_CREOLE => Tst := Create_Test (Name & ".creole", Path & "/" & Simple, Syntax, "/wiki-convert/", "", True); when Wiki.SYNTAX_DOTCLEAR => Tst := Create_Test (Name & ".dotclear", Path & "/" & Simple, Syntax, "/wiki-convert/", "", True); when Wiki.SYNTAX_MEDIA_WIKI => Tst := Create_Test (Name & ".mediawiki", Path & "/" & Simple, Syntax, "/wiki-convert/", "", True); when Wiki.SYNTAX_MARKDOWN => Tst := Create_Test (Name & ".markdown", Path & "/" & Simple, Syntax, "/wiki-convert/", "", True); when others => Tst := null; end case; if Tst /= null then Tst.Is_Cvt := True; Tst.Source := Format; Suite.Add_Test (Tst.all'Access); end if; end loop; end if; end; end loop; end Add_Convert_Tests; begin Add_Wiki_Tests; Add_Import_Tests; Add_Convert_Tests; end Add_Tests; end Wiki.Tests;
with AUnit.Test_Cases; package GStreamer.Rtsp.url.Tests is use AUnit; type Test_Case is new AUnit.Test_Cases.Test_Case with null record; function Name (Test : Test_Case) return Message_String; procedure Register_Tests (Test : in out Test_Case); end GStreamer.Rtsp.url.Tests;
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- XML Processor -- -- -- -- Runtime Library Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2011, Vadim Godunko <vgodunko@gmail.com> -- -- All rights reserved. -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions -- -- are met: -- -- -- -- * Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- -- -- * Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in the -- -- documentation and/or other materials provided with the distribution. -- -- -- -- * Neither the name of the Vadim Godunko, IE nor the names of its -- -- contributors may be used to endorse or promote products derived from -- -- this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -- -- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED -- -- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -- -- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -- -- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -- -- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -- -- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- -- ------------------------------------------------------------------------------ -- $Revision$ $Date$ ------------------------------------------------------------------------------ -- Normalization utilities for public and system identifiers. ------------------------------------------------------------------------------ with Ada.Streams; with League.Characters.Latin; with League.Text_Codecs; package body Matreshka.XML_Catalogs.Normalization is use League.Characters.Latin; use type League.Characters.Universal_Character; PublicId_URN_Namespace : constant League.Strings.Universal_String := League.Strings.To_Universal_String ("urn:publicid:"); UTF8_Codec : constant League.Text_Codecs.Text_Codec := League.Text_Codecs.Codec (League.Strings.To_Universal_String ("utf-8")); -- Codec to encode URI. --------------------------------- -- Normalize_Public_Identifier -- --------------------------------- function Normalize_Public_Identifier (Public_Identifier : League.Strings.Universal_String) return League.Strings.Universal_String is Result : League.Strings.Universal_String; Char : League.Characters.Universal_Character; Is_Space : Boolean; begin -- [XML Catalogs] 6.2. Public Identifier Normalization -- -- In order to accurately and interoperably compare public identifiers, -- catalog processors must perform normalization on public identifiers -- in both the catalog and the input passed to them. -- -- All strings of white space in public identifiers must be normalized -- to single space characters (#x20), and leading and trailing white -- space must be removed. Is_Space := True; for J in 1 .. Public_Identifier.Length loop Char := Public_Identifier.Element (J); if Char = Space or Char = Carriage_Return or Char = Line_Feed or Char = Character_Tabulation then if not Is_Space then Is_Space := True; Result.Append (Space); end if; else Is_Space := False; Result.Append (Public_Identifier.Element (J)); end if; end loop; if Is_Space and not Result.Is_Empty then return Result.Slice (1, Result.Length - 1); else return Result; end if; end Normalize_Public_Identifier; ------------------- -- Normalize_URI -- ------------------- function Normalize_URI (URI : League.Strings.Universal_String) return League.Strings.Universal_String is use type Ada.Streams.Stream_Element; -- [XML Catalogs] 6.3. System Identifier and URI Normalization -- -- "In order to accurately and interoperably compare system identifiers -- and URI references, catalog processors must perform normalization. -- The normalization described in this section must be performed on -- system identifiers and URI references passed as input to the resolver -- and on strings in the catalog that are compared to them. -- -- URI references require encoding and escaping of certain characters. -- The disallowed characters include all non-ASCII characters, plus the -- excluded characters listed in Section 2.4 of [RFC 2396], except for -- the number sign (#) and percent sign (%) characters and the square -- bracket characters re-allowed in [RFC 2732]. These characters are -- summarized in Table 1, “Excluded US-ASCII Characters”. -- -- Table 1. Excluded US-ASCII Characters -- Hex Value Character Hex Value Character Hex Value Character -- 00 NUL 0F SI 1E RS -- 01 SOH 10 DLE 1F US -- 02 STX 11 DC1 20 (space) -- 03 ETX 12 DC2 22 " -- 04 EOT 13 DC3 3C < -- 05 ENQ 14 DC4 3E > -- 06 ACK 15 NAK 5C \ -- 07 BEL 16 SYN 5E ^ -- 08 BS 17 ETB 60 ` -- 09 HT 18 CAN 7B { -- 0A LF 19 EM 7C | -- 0B VT 1A SUB 7D } -- 0C FF 1B ESC 7F DEL -- 0D CR 1C FS -- 0E SO 1D GS -- -- Catalog processors must escape disallowed characters as follows: -- -- 1. Each disallowed character is converted to UTF-8 [RFC 2279] as one -- or more bytes. -- -- 2. Any octets corresponding to a disallowed character are escaped -- with the URI escaping mechanism (that is, converted to %HH, where HH -- is the hexadecimal notation of the octet value). If escaping must be -- performed, uppercase hexadecimal characters should be used. -- -- 3. The original character is replaced by the resulting character -- sequence. Note that this normalization process is idempotent: -- repeated normalization does not change a normalized URI reference." -- Actual algoriphm is slightly differ: it converts URI into UTF-8 and -- escape all disallowed characters. This produce equivalent result, -- because all ASCII characters are mapped to the elements with the same -- codes, and all non-ASCII characters are mapped to multibyte sequences -- with codes outside of ASCII range. Hex : constant array (Ada.Streams.Stream_Element range 0 .. 15) of Wide_Wide_Character := "0123456789ABCDEF"; Encoded : constant Ada.Streams.Stream_Element_Array := UTF8_Codec.Encode (URI).To_Stream_Element_Array; Result : League.Strings.Universal_String; begin for J in Encoded'Range loop case Encoded (J) is when 16#00# .. 16#20# -- NUL .. (space) | 16#22# -- " | 16#3C# -- < | 16#3E# -- > | 16#5C# -- \ | 16#5E# -- ^ | 16#60# -- ` | 16#7B# -- { | 16#7C# -- | | 16#7D# -- } | 16#7F# -- DEL | 16#80# .. 16#FF# -- non-ASCII codes => Result.Append ('%'); Result.Append (Hex (Encoded (J) / 16)); Result.Append (Hex (Encoded (J) mod 16)); when others => Result.Append (Wide_Wide_Character'Val (Encoded (J))); end case; end loop; return Result; end Normalize_URI; ---------------- -- Unwrap_URN -- ---------------- procedure Unwrap_URN (URI : League.Strings.Universal_String; Identifier : out League.Strings.Universal_String; Unwrapped : out Boolean) is -- [XML Catalogs] 6.4. URN "Unwrapping" -- -- This OASIS Standard requires processors to implement special -- treatment of URNs in the publicid URN Namespace ([RFC 3151]). -- -- URNs of this form must, in some contexts, be "unwrapped" by the -- Catalog processor. This unwrapping translates the URN form of the -- public identifier back into the standard ISO 8879 form for the -- purposes of subsequent catalog processing. -- -- Unwrapping a urn:publicid: URN is accomplished by transcribing -- characters in the URN according to the fol- lowing table after -- discarding the leading urn:publicid: string: -- -- URN Characters Public Identifier Characters -- + " " (space) -- : // -- ; :: -- %2B + -- %3A : -- %2F / -- %3B ; -- %27 ' -- %3F ? -- %23 # -- %25 % -- -- URNs in the publicid namespace should always represent normalized -- public identifiers (Section 6.2, “Public Identifier Normalization”). -- In the event that an unwrapped public identifier is not normalized, -- the catalog processor must normalize it." Char : League.Characters.Universal_Character; Char_1 : League.Characters.Universal_Character; Char_2 : League.Characters.Universal_Character; J : Natural; begin Identifier := League.Strings.Empty_Universal_String; if not URI.Starts_With (PublicId_URN_Namespace) then -- Return when URI is not in publicid URN namespace. Unwrapped := False; return; end if; J := PublicId_URN_Namespace.Length + 1; while J <= URI.Length loop Char := URI.Element (J); if Char = Plus_Sign then Identifier.Append (Space); elsif Char = Colon then Identifier.Append (Solidus); Identifier.Append (Solidus); elsif Char = Semicolon then Identifier.Append (Colon); Identifier.Append (Colon); elsif Char = Percent_Sign and then J + 2 <= URI.Length then Char_1 := URI.Element (J + 1); Char_2 := URI.Element (J + 2); if Char_1 = Digit_Two and Char_2 = Latin_Capital_Letter_B then Identifier.Append (Plus_Sign); elsif Char_1 = Digit_Three and Char_2 = Latin_Capital_Letter_A then Identifier.Append (Colon); elsif Char_1 = Digit_Two and Char_2 = Latin_Capital_Letter_F then Identifier.Append (Solidus); elsif Char_1 = Digit_Three and Char_2 = Latin_Capital_Letter_B then Identifier.Append (Semicolon); elsif Char_1 = Digit_Two and Char_2 = Digit_Seven then Identifier.Append (Apostrophe); elsif Char_1 = Digit_Three and Char_2 = Latin_Capital_Letter_F then Identifier.Append (Question_Mark); elsif Char_1 = Digit_Two and Char_2 = Digit_Three then Identifier.Append (Number_Sign); elsif Char_1 = Digit_Two and Char_2 = Digit_Five then Identifier.Append (Percent_Sign); else Identifier.Append (Char); Identifier.Append (Char_1); Identifier.Append (Char_2); end if; J := J + 2; else Identifier.Append (Char); end if; J := J + 1; end loop; Identifier := Normalize_Public_Identifier (Identifier); Unwrapped := True; end Unwrap_URN; end Matreshka.XML_Catalogs.Normalization;
with Instruction; use Instruction; -- specification of the VM implementation package Machine with SPARK_Mode is -- the VM returns either -- Success: when the program executes successfully and returns a value -- IllegalProgram: when the program executes an invalid behaviour -- CyclesExhausted: when the program has not returned a value before -- the cycle count was exhausted (see the Cycles -- argument to the ExecuteProgram procedure below) type ReturnCode is (Success,CyclesExhausted,IllegalProgram); -- each program has exactly this many instructions MAX_PROGRAM_LENGTH : constant Integer := 65536; -- type of values that the program counter (pc) holds -- note that the first instruction in the program is at position 1 type ProgramCounter is range 1 .. MAX_PROGRAM_LENGTH; -- a program is just an array of instructions, indexed by the pc type Program is array (ProgramCounter) of Instruction.Instr; -- called to execute the given program. -- at most Cycles instructions will be executed. -- if Cycles instructions have been executed without encountering a -- RET instruction and without encountering invalid behaviour, -- then Ret is set to CyclesExhausted. -- Otherwise, if no invalid behaviour is encountered, then Ret is set -- Success and Result will contain the value returned by the RET -- instruction encountered. -- Otherwise, if an invalid behaviour is encountered, then Ret is set -- to IllegalProgram. -- If Ret is CyclesExhausted or IllegalProgram, Result is meaningless procedure ExecuteProgram(Prog : in Program; Cycles : in Integer; Ret : out ReturnCode; Result : out Integer); -- analyse the given program to determine whether it might encounter -- invalid behaviour while executing for Cycles instructions -- from an initial state with unknown register and memory contents. -- returns True if the program might encounter invalid -- behaviour. Otherwise, returns False if the program is guaranteed -- not to encounter invalid behaviour while Cycles instructions are executed function DetectInvalidBehaviour(Prog : in Program; Cycles : in Integer) return Boolean; end Machine;
with Ada.Text_IO; use Ada.Text_IO; procedure Test is function F(X: in out Integer) return integer is begin return 0; end; begin if F(42) = 0 then new_line; end if; end;
package Inline5_Pkg is procedure Test (I : Integer); pragma Inline (Test); end Inline5_Pkg;
------ USANDO IN OUT procedure Hello is a: Integer; b: Float := 2.0 ; c: Boolean := false; function uno(a,b:out Boolean; x,y :in Integer) return Boolean is begin Put(one); return a; end uno; function dos(a: in out Float; x,y :in Integer) return Boolean is begin Put(one); return a; end dos; begin c := dos(c); Put(b); end Hello;
-- SPDX-FileCopyrightText: 2010-2021 Max Reznik <reznikmm@gmail.com> -- -- SPDX-License-Identifier: MIT ------------------------------------------------------------- with League.Strings; package WebIDL.Tokens is pragma Preelaborate; type Token_Kind is ('(', ')', ',', '-', '.', ':', ';', '<', '=', '>', '?', '[', ']', '{', '}', Ellipsis_Token, Any_Token, Async_Token, Attribute_Token, Bigint_Token, Boolean_Token, Byte_Token, Callback_Token, Const_Token, Constructor_Token, Deleter_Token, Dictionary_Token, Double_Token, Enum_Token, False_Token, Float_Token, Getter_Token, Includes_Token, Inherit_Token, Interface_Token, Iterable_Token, Long_Token, Maplike_Token, Mixin_Token, Namespace_Token, Null_Token, Object_Token, Octet_Token, Optional_Token, Or_Token, Other_Token, Partial_Token, Readonly_Token, Record_Token, Required_Token, Sequence_Token, Setlike_Token, Setter_Token, Short_Token, Static_Token, Stringifier_Token, Symbol_Token, True_Token, Typedef_Token, Undefined_Token, Unrestricted_Token, Unsigned_Token, ArrayBuffer_Token, ByteString_Token, DataView_Token, DOMString_Token, Float32Array_Token, Float64Array_Token, FrozenArray_Token, Infinity_Token, Int16Array_Token, Int32Array_Token, Int8Array_Token, NaN_Token, ObservableArray_Token, Promise_Token, Uint16Array_Token, Uint32Array_Token, Uint8Array_Token, Uint8ClampedArray_Token, USVString_Token, Integer_Token, Decimal_Token, Identifier_Token, String_Token, End_Of_Stream_Token, Error_Token); type Token (Kind : Token_Kind := End_Of_Stream_Token) is record Text : League.Strings.Universal_String; end record; end WebIDL.Tokens;
-- C74305A.ADA -- Grant of Unlimited Rights -- -- Under contracts F33600-87-D-0337, F33600-84-D-0280, MDA903-79-C-0687, -- F08630-91-C-0015, and DCA100-97-D-0025, the U.S. Government obtained -- unlimited rights in the software and documentation contained herein. -- Unlimited rights are defined in DFAR 252.227-7013(a)(19). By making -- this public release, the Government intends to confer upon all -- recipients unlimited rights equal to those held by the Government. -- These rights include rights to use, duplicate, release or disclose the -- released technical data and computer software in whole or in part, in -- any manner and for any purpose whatsoever, and to have or permit others -- to do so. -- -- DISCLAIMER -- -- ALL MATERIALS OR INFORMATION HEREIN RELEASED, MADE AVAILABLE OR -- DISCLOSED ARE AS IS. THE GOVERNMENT MAKES NO EXPRESS OR IMPLIED -- WARRANTY AS TO ANY MATTER WHATSOEVER, INCLUDING THE CONDITIONS OF THE -- SOFTWARE, DOCUMENTATION OR OTHER INFORMATION RELEASED, MADE AVAILABLE -- OR DISCLOSED, OR THE OWNERSHIP, MERCHANTABILITY, OR FITNESS FOR A -- PARTICULAR PURPOSE OF SAID MATERIAL. --* -- CHECK THAT A DEFERRED CONSTANT CAN BE USED AS A DEFAULT -- INITIALIZATION FOR A PARAMETER OR AS A DEFAULT INITIA- -- LIZATION FOR A COMPONENT (NON GENERIC CASE). -- DAT 4/06/81 -- RM 5/21/81 -- SPS 8/23/82 -- SPS 2/10/83 -- SPS 10/20/83 -- EG 12/20/83 -- GJD 11/15/95 REMOVED ADA 95 INCOMPATIBILITY. WITH REPORT; PROCEDURE C74305A IS USE REPORT; PACKAGE PK IS TYPE T1 IS PRIVATE; TYPE T2 IS PRIVATE; C1 : CONSTANT T1; -- OK. PROCEDURE P1 (P : T1 := C1); -- OK. TYPE R1 IS RECORD C : T1 := C1; -- OK. END RECORD; PRIVATE PROCEDURE PROC2 (P : T1 := C1); -- OK. TYPE R2 IS RECORD C : T1 := C1; -- OK. D : INTEGER := C1'SIZE; -- OK. END RECORD; FUNCTION F1 (P : T1) RETURN T1; TYPE T1 IS NEW INTEGER; TYPE T2 IS ARRAY (1..2) OF INTEGER; -- OK. FUNCTION F2 (P : T1) RETURN T1; PROCEDURE P3 (P : T1 := C1+1); -- OK. PROCEDURE P4 (P : T1 := F1(C1)); TYPE R5 IS RECORD C : T1 := F2(C1); END RECORD; PROCEDURE P5 (P : T1 := C1+2) RENAMES P3; TYPE R3 IS RECORD C : T1 := C1; -- OK. END RECORD; C1 : CONSTANT T1 := 1; -- OK. C2 : CONSTANT T2 := (1,1); -- OK. END PK; USE PK; PACKAGE BODY PK IS R11 : R1; PROCEDURE P1 (P : T1 := C1) IS BEGIN IF ( P /= 1 ) THEN FAILED ("PARAMETER DEFAULT OF P1 NOT PROPERLY " & "INITIALIZED"); END IF; END P1; PROCEDURE PROC2 (P : T1 := C1) IS BEGIN NULL; END PROC2; PROCEDURE P3 (P : T1 := C1+1) IS BEGIN IF ( P /= 3 ) THEN FAILED ("PARAMETER DEFAULT OF P5 NOT PROPERLY " & "INITIALIZED"); END IF; END P3; FUNCTION F1 (P : T1) RETURN T1 IS BEGIN RETURN P+10; END F1; PROCEDURE P4 (P : T1 := F1(C1)) IS BEGIN IF ( P /= 11 ) THEN FAILED ("WRONG ACTUAL PARAMETER RECEIVED"); END IF; END P4; FUNCTION F2 (P : T1) RETURN T1 IS BEGIN RETURN P+20; END F2; BEGIN -- PK BODY. DECLARE R55 : R5; BEGIN TEST ("C74305A","CHECK THAT A DEFERRED CONSTANT CAN " & "BE USED AS A DEFAULT INITIALIZATION " & "FOR A PARAMETER OR AS A DEFAULT " & "INITIALIZATION FOR A COMPONENT (NON " & "GENERIC CASE)"); IF ( R11.C /= 1 ) THEN FAILED ("RECORD R11 NOT PROPERLY INITIALIZED"); END IF; P4; IF ( R55.C /= 21 ) THEN FAILED ("RECORD R55 NOT PROPERLY INITIALIZED"); END IF; P5; END; END PK; BEGIN P1; RESULT; END C74305A;
----------------------------------------------------------------------- -- awa-events-dispatchers-tasks -- AWA Event Dispatchers -- Copyright (C) 2012, 2015, 2017 Stephane Carrez -- Written by Stephane Carrez (Stephane.Carrez@gmail.com) -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. ----------------------------------------------------------------------- with Ada.Unchecked_Deallocation; with Util.Log.Loggers; with AWA.Services.Contexts; package body AWA.Events.Dispatchers.Tasks is use Util.Log; use Ada.Strings.Unbounded; Log : constant Loggers.Logger := Loggers.Create ("AWA.Events.Dispatchers.Tasks"); -- ------------------------------ -- Start the dispatcher. -- ------------------------------ overriding procedure Start (Manager : in out Task_Dispatcher) is begin if Manager.Queues.Get_Count > 0 then Log.Info ("Starting the tasks"); if Manager.Workers = null then Manager.Workers := new Consumer_Array (1 .. Manager.Task_Count); end if; for I in Manager.Workers'Range loop Manager.Workers (I).Start (Manager'Unchecked_Access); end loop; else Log.Info ("No event dispatcher task started (no event queue to poll)"); end if; end Start; -- ------------------------------ -- Stop the dispatcher. -- ------------------------------ overriding procedure Stop (Manager : in out Task_Dispatcher) is procedure Free is new Ada.Unchecked_Deallocation (Object => Consumer_Array, Name => Consumer_Array_Access); begin if Manager.Workers /= null then Log.Info ("Stopping the event dispatcher tasks"); for I in Manager.Workers'Range loop if Manager.Workers (I)'Callable then Manager.Workers (I).Stop; else Log.Error ("Event consumer task terminated abnormally"); end if; end loop; Free (Manager.Workers); end if; end Stop; procedure Add_Queue (Manager : in out Task_Dispatcher; Queue : in AWA.Events.Queues.Queue_Ref; Added : out Boolean) is begin Log.Info ("Adding queue {0} to the task dispatcher", Queue.Get_Name); Manager.Queues.Enqueue (Queue); Added := True; end Add_Queue; function Create_Dispatcher (Service : in AWA.Events.Services.Event_Manager_Access; Match : in String; Count : in Positive; Priority : in Positive) return Dispatcher_Access is Result : constant Task_Dispatcher_Access := new Task_Dispatcher; begin Result.Task_Count := Count; Result.Priority := Priority; Result.Match := To_Unbounded_String (Match); Result.Manager := Service.all'Access; return Result.all'Access; end Create_Dispatcher; task body Consumer is Dispatcher : Task_Dispatcher_Access; Time : Duration := 0.01; Do_Work : Boolean := True; Context : AWA.Services.Contexts.Service_Context; begin Log.Info ("Event consumer is ready"); select accept Start (D : in Task_Dispatcher_Access) do Dispatcher := D; end Start; Log.Info ("Event consumer is started"); -- Set the service context. Context.Set_Context (Application => Dispatcher.Manager.Get_Application.all'Access, Principal => null); while Do_Work loop declare Nb_Queues : constant Natural := Dispatcher.Queues.Get_Count; Queue : AWA.Events.Queues.Queue_Ref; Nb_Events : Natural := 0; begin -- We can have several tasks that dispatch events from several queues. -- Each queue in the list must be given the same polling quota. -- Pick a queue and dispatch some pending events. -- Put back the queue in the fifo. for I in 1 .. Nb_Queues loop Dispatcher.Queues.Dequeue (Queue); begin Dispatcher.Dispatch (Queue, Nb_Events); exception when E : others => Log.Error ("Exception when dispatching events", E, True); end; Dispatcher.Queues.Enqueue (Queue); end loop; -- If we processed something, reset the timeout delay and continue polling. -- Otherwise, double the sleep time. if Nb_Events /= 0 then Time := 0.01; else Log.Debug ("Sleeping {0} seconds", Duration'Image (Time)); select accept Stop do Do_Work := False; end Stop; or accept Start (D : in Task_Dispatcher_Access) do Dispatcher := D; end Start; or delay Time; end select; if Time < 60.0 then Time := Time * 2.0; end if; end if; end; end loop; or terminate; end select; end Consumer; end AWA.Events.Dispatchers.Tasks;
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- Web Framework -- -- -- -- Tools Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2015-2018, Vadim Godunko <vgodunko@gmail.com> -- -- All rights reserved. -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions -- -- are met: -- -- -- -- * Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- -- -- * Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in the -- -- documentation and/or other materials provided with the distribution. -- -- -- -- * Neither the name of the Vadim Godunko, IE nor the names of its -- -- contributors may be used to endorse or promote products derived from -- -- this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -- -- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED -- -- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -- -- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -- -- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -- -- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -- -- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- -- ------------------------------------------------------------------------------ -- $Revision$ $Date$ ------------------------------------------------------------------------------ with Asis; with League.Strings; package Properties.Tools is function Get_Aspect (Element : Asis.Declaration; Name : Wide_String) return Wide_String; function Library_Level_Header (Unit : Asis.Compilation_Unit) return League.Strings.Universal_String; function Corresponding_Type_Subprograms (Definition : Asis.Definition) return Asis.Declaration_List; -- For given type definition return list of primitive subprograms function Corresponding_Type_Components (Definition : Asis.Definition) return Asis.Declaration_List; -- For given (non-array complex) type definition return list of component function Corresponding_Type_Discriminants (Definition : Asis.Definition) return Asis.Declaration_List; -- For given (non-array complex) type definition return list of discr-s. function Is_Primitive_Subprogram (Definition : Asis.Definition; Subprogram : Asis.Declaration) return Boolean; -- Check if given Subprogram is primitive subprograms for given type function Parameter_Profile (Prefix : Asis.Expression) return Asis.Parameter_Specification_List; -- For given prefix of procedure call return corresponding parameter -- declaration list function Corresponding_Type (Declaration : Asis.Declaration) return Asis.Declaration; -- Return type declaration for given primitive subprogram function Corresponding_Declaration (Name : Asis.Expression) return Asis.Declaration; -- Like Asis.Expressions.Corresponding_Name_Declaration, but takes -- selector of selected_component function Type_Declaration_View (Declaration : Asis.Declaration) return Asis.Definition; -- Like Asis.Declarations.Type_Declaration_View but expand derived types function Array_Component_Definition (Type_Definition : Asis.Type_Definition) return Asis.Component_Definition; -- Like Asis.Definitions.Array_Component_Definition, but takes into account -- implicit dereference. function Is_Equal_Type (Left : Asis.Declaration; Right : Asis.Declaration) return Boolean; function Is_Array (Exp : Asis.Expression) return Boolean; function Enclosing_Declaration (X : Asis.Element) return Asis.Declaration; function Has_Controlling_Result (Func : Asis.Declaration) return Boolean; -- Check if function Func is like 'function F return T' where T is tagged function Is_Array_Buffer (Element : Asis.Declaration) return Boolean; -- Check if given type declaration has corresponding pragma -- JavaScript_Array_Buffer function Join (Left, Right : League.Strings.Universal_String) return League.Strings.Universal_String; -- Return Left & Right function Comma (Left, Right : League.Strings.Universal_String) return League.Strings.Universal_String; -- Return Left & "," & Right function "or" (Left, Right : Boolean) return Boolean is (Standard."or" (Left, Right)); function Get_Dimension (Exp : Asis.Expression) return Natural; -- Return dimention of an array aggregate Exp. Return 0 if subaggregate function Attribute_Definition (Decl : Asis.Declaration; Attr : Wide_String) return Asis.Expression; -- find corresponding attribute declaration end Properties.Tools;
------------------------------------------------------------------------------ -- -- -- GNAT COMPILER COMPONENTS -- -- -- -- I N T E R F A C E S . C _ S T R E A M S -- -- -- -- B o d y -- -- -- -- Copyright (C) 1996-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. -- -- -- -- As a special exception under Section 7 of GPL version 3, you are granted -- -- additional permissions described in the GCC Runtime Library Exception, -- -- version 3.1, as published by the Free Software Foundation. -- -- -- -- You should have received a copy of the GNU General Public License and -- -- a copy of the GCC Runtime Library Exception along with this program; -- -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- -- <http://www.gnu.org/licenses/>. -- -- -- -- GNAT was originally developed by the GNAT team at New York University. -- -- Extensive contributions were provided by Ada Core Technologies Inc. -- -- -- ------------------------------------------------------------------------------ with Ada.Unchecked_Conversion; package body Interfaces.C_Streams is use type System.CRTL.size_t; ---------------------------- -- Interfaced C functions -- ---------------------------- function C_fread (buffer : voids; size : size_t; count : size_t; stream : FILEs) return size_t; pragma Import (C, C_fread, "fread"); function C_fwrite (buffer : voids; size : size_t; count : size_t; stream : FILEs) return size_t; pragma Import (C, C_fwrite, "fwrite"); function C_setvbuf (stream : FILEs; buffer : chars; mode : int; size : size_t) return int; pragma Import (C, C_setvbuf, "setvbuf"); ------------ -- fread -- ------------ function fread (buffer : voids; size : size_t; count : size_t; stream : FILEs) return size_t is begin return C_fread (buffer, size, count, stream); end fread; ------------ -- fread -- ------------ -- The following declarations should really be nested within fread, but -- limitations in front end inlining make this undesirable right now ??? type Byte_Buffer is array (0 .. size_t'Last / 2 - 1) of Unsigned_8; -- This should really be 0 .. size_t'last, but there is a problem -- in gigi in handling such types (introduced in GCC 3 Sep 2001) -- since the size in bytes of this array overflows ??? type Acc_Bytes is access all Byte_Buffer; function To_Acc_Bytes is new Ada.Unchecked_Conversion (voids, Acc_Bytes); function fread (buffer : voids; index : size_t; size : size_t; count : size_t; stream : FILEs) return size_t is begin return C_fread (To_Acc_Bytes (buffer) (index * size)'Address, size, count, stream); end fread; ------------ -- fwrite -- ------------ function fwrite (buffer : voids; size : size_t; count : size_t; stream : FILEs) return size_t is begin return C_fwrite (buffer, size, count, stream); end fwrite; ------------- -- setvbuf -- ------------- function setvbuf (stream : FILEs; buffer : chars; mode : int; size : size_t) return int is begin return C_setvbuf (stream, buffer, mode, size); end setvbuf; end Interfaces.C_Streams;
-- { dg-do compile } procedure Prot1 is protected type Prot is procedure Change (x : integer); private Flag : Boolean; end Prot; type Handle is access protected procedure (X : Integer); procedure Manage (Ptr : Handle) is begin null; end; protected body prot is procedure Change (x : integer) is begin null; end; end; Sema : Prot; begin Manage (Sema.Change'Unrestricted_Access); end;
procedure Input_1 is generic type T is private; type Index is range <>; type Array_T is array (Index range <>) of T; Null_Value : T; with function Img (A, B: T) return boolean; procedure Generic_Reverse_Array (X : in out Array_T); procedure Generic_Reverse_Array (X : in out Array_T) is begin for I in X'First .. (X'Last + X'First) / 2 loop declare Tmp : T; X_Left : T renames X (I); X_Right : T renames X (X'Last + X'First - I); begin Tmp := X_Left; X_Left := X_Right; X_Right := Tmp; end; end loop; end Generic_Reverse_Array; type Color is (None, Black, Red, Green, Blue, White); type Color_Array is array (Integer range <>) of Color; procedure Reverse_Color_Array is new Generic_Reverse_Array (T => Color, Index => Integer, Array_T => Color_Array, Null_Value => None); type Shape is (None, Circle, Triangle, Square); type Shape_Array is array (Integer range <>) of Shape; procedure Reverse_Shape_Array is new Generic_Reverse_Array (T => Shape, Index => Integer, Array_T => Shape_Array, Null_Value => None); begin null; end Input_1;
with Ada.Text_IO; use Ada.Text_IO; with Generic_Taylor_Series; with Generic_Rational; procedure Test_Taylor_Series is package Integer_Rationals is new Generic_Rational (Integer); package Integer_Taylor_Series is new Generic_Taylor_Series (Integer_Rationals); use Integer_Taylor_Series; -- Procedure to print a series procedure Put (A : Taylor_Series) is use Integer_Rationals; procedure Put (A : Rational) is begin if Numerator (A) = 1 then Put (" 1"); else Put (Integer'Image (Numerator (A))); end if; if Denominator (A) /= 1 then Put (" /"); Put (Integer'Image (Denominator (A))); end if; end Put; begin if A (0) /= 0 then Put (A (0)); end if; for Power in 1..A'Last loop if A (Power) > 0 then Put (" +"); Put (A (Power)); Put (" X **" & Integer'Image (Power)); elsif A (Power) < 0 then Put (" -"); Put (abs A (Power)); Put (" X **" & Integer'Image (Power)); end if; end loop; end Put; -- Cosine generator function Cos (N : Natural) return Taylor_Series is begin if N = 0 then return One; else return One - Integral (Integral (Cos (N - 1))); end if; end Cos; begin Put ("Cos ="); Put (Cos (5)); Put_Line (" ..."); Put ("Sin ="); Put (Integral (Cos (5))); Put_Line (" ..."); end Test_Taylor_Series;
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- SQL Database Access -- -- -- -- Runtime Library Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2012-2014, Vadim Godunko <vgodunko@gmail.com> -- -- All rights reserved. -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions -- -- are met: -- -- -- -- * Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- -- -- * Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in the -- -- documentation and/or other materials provided with the distribution. -- -- -- -- * Neither the name of the Vadim Godunko, IE nor the names of its -- -- contributors may be used to endorse or promote products derived from -- -- this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -- -- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED -- -- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -- -- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -- -- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -- -- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -- -- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- -- ------------------------------------------------------------------------------ -- $Revision$ $Date$ ------------------------------------------------------------------------------ with Matreshka.Internals.SQL_Drivers.MySQL.Queries; package body Matreshka.Internals.SQL_Drivers.MySQL.Databases is use type Interfaces.C.char_array; use type Interfaces.C.int; UTF8_Encoding : constant Interfaces.C.char_array := "utf8mb4" & Interfaces.C.nul; procedure Set_MySQL_Error (Self : not null access MySQL_Database'Class); -- Sets error message to reported by database. procedure Execute_Query (Self : not null access MySQL_Database'Class; Query : String; Success : in out Boolean); -- Internal subprogram to executre simple parameter-less and result-less -- queries at connection initialization time. ----------- -- Close -- ----------- overriding procedure Close (Self : not null access MySQL_Database) is begin if Self.Handle /= null then mysql_close (Self.Handle); Self.Handle := null; end if; end Close; ------------ -- Commit -- ------------ overriding procedure Commit (Self : not null access MySQL_Database) is begin raise Program_Error; end Commit; --------------------- -- Database_Handle -- --------------------- function Database_Handle (Self : not null access constant MySQL_Database'Class) return MYSQL_Access is begin return Self.Handle; end Database_Handle; ------------------- -- Error_Message -- ------------------- overriding function Error_Message (Self : not null access MySQL_Database) return League.Strings.Universal_String is begin return Self.Error; end Error_Message; ------------------- -- Execute_Query -- ------------------- procedure Execute_Query (Self : not null access MySQL_Database'Class; Query : String; Success : in out Boolean) is procedure Set_MySQL_Stmt_Error; Handle : MYSQL_STMT_Access; C_Query : Interfaces.C.Strings.chars_ptr; Status : Interfaces.C.int; B_Status : my_bool; -------------------------- -- Set_MySQL_Stmt_Error -- -------------------------- procedure Set_MySQL_Stmt_Error is begin Self.Error := League.Strings.From_UTF_8_String (Interfaces.C.Strings.Value (mysql_stmt_error (Handle))); Success := False; end Set_MySQL_Stmt_Error; begin if not Success then -- Return immidiately when error condition had been detected. It -- allows to write sequence of call to Execute_Query without -- intermediate check for error conditions. return; end if; -- Allocate statement handle. Handle := mysql_stmt_init (Self.Database_Handle); if Handle = null then Self.Error := League.Strings.To_Universal_String ("out of memory"); Success := False; return; end if; -- Prepare statement. C_Query := Interfaces.C.Strings.New_String (Query); Status := mysql_stmt_prepare (Handle, C_Query, Interfaces.C.unsigned_long (Interfaces.C.Strings.Strlen (C_Query))); Interfaces.C.Strings.Free (C_Query); if Status /= 0 then Set_MySQL_Stmt_Error; return; end if; -- Execute statement. Status := mysql_stmt_execute (Handle); if Status /= 0 then Set_MySQL_Stmt_Error; return; end if; -- Deallocate statement. B_Status := mysql_stmt_close (Handle); if B_Status /= 0 then Set_MySQL_Stmt_Error; return; end if; end Execute_Query; -------------- -- Finalize -- -------------- overriding procedure Finalize (Self : not null access MySQL_Database) is begin if Self.Handle /= null then Self.Close; end if; end Finalize; ---------- -- Open -- ---------- overriding function Open (Self : not null access MySQL_Database; Options : SQL.Options.SQL_Options) return Boolean is Database_Name : constant League.Strings.Universal_String := League.Strings.To_Universal_String ("database"); Host_Name : constant League.Strings.Universal_String := League.Strings.To_Universal_String ("host"); Password_Name : constant League.Strings.Universal_String := League.Strings.To_Universal_String ("password"); Port_Name : constant League.Strings.Universal_String := League.Strings.To_Universal_String ("port"); Socket_Name : constant League.Strings.Universal_String := League.Strings.To_Universal_String ("socket"); User_Name : constant League.Strings.Universal_String := League.Strings.To_Universal_String ("user"); Host_Option : Interfaces.C.Strings.chars_ptr := Interfaces.C.Strings.Null_Ptr; User_Option : Interfaces.C.Strings.chars_ptr := Interfaces.C.Strings.Null_Ptr; Password_Option : Interfaces.C.Strings.chars_ptr := Interfaces.C.Strings.Null_Ptr; Database_Option : Interfaces.C.Strings.chars_ptr := Interfaces.C.Strings.Null_Ptr; Port_Option : Interfaces.C.unsigned := 0; Socket_Option : Interfaces.C.Strings.chars_ptr := Interfaces.C.Strings.Null_Ptr; Result : MYSQL_Access; Success : Boolean; begin -- Initialize handle. Self.Handle := mysql_init (null); if Self.Handle = null then Self.Error := League.Strings.To_Universal_String ("insufficient memory to allocate a new object"); return False; end if; -- Set client character encoding to 'utf-8'. if mysql_options (Self.Handle, MYSQL_SET_CHARSET_NAME, UTF8_Encoding) /= 0 then Self.Error := League.Strings.To_Universal_String ("unknown option"); return False; end if; -- Prepare options. if Options.Is_Set (Host_Name) then Host_Option := Interfaces.C.Strings.New_String (Options.Get (Host_Name).To_UTF_8_String); end if; if Options.Is_Set (User_Name) then User_Option := Interfaces.C.Strings.New_String (Options.Get (User_Name).To_UTF_8_String); end if; if Options.Is_Set (Password_Name) then Password_Option := Interfaces.C.Strings.New_String (Options.Get (Password_Name).To_UTF_8_String); end if; if Options.Is_Set (Database_Name) then Database_Option := Interfaces.C.Strings.New_String (Options.Get (Database_Name).To_UTF_8_String); end if; if Options.Is_Set (Port_Name) then Port_Option := Interfaces.C.unsigned'Wide_Wide_Value (Options.Get (Port_Name).To_Wide_Wide_String); end if; if Options.Is_Set (Socket_Name) then Socket_Option := Interfaces.C.Strings.New_String (Options.Get (Socket_Name).To_UTF_8_String); end if; -- Connect to database. Result := mysql_real_connect (Self.Handle, Host_Option, User_Option, Password_Option, Database_Option, Port_Option, Socket_Option, 0); -- Cleanup options. Interfaces.C.Strings.Free (Host_Option); Interfaces.C.Strings.Free (User_Option); Interfaces.C.Strings.Free (Password_Option); Interfaces.C.Strings.Free (Database_Option); Interfaces.C.Strings.Free (Socket_Option); -- Check result of operation. if Result = null then Self.Set_MySQL_Error; return False; end if; -- Configure connection. Success := True; -- Set time_zone variable to UTC. Driver assumes that all date/time -- types are represented as UTC time. Execute_Query (Self, "SET time_zone = '+00:00'", Success); return Success; end Open; ----------- -- Query -- ----------- overriding function Query (Self : not null access MySQL_Database) return not null Query_Access is begin return Result : constant not null Query_Access := new Queries.MySQL_Query do Queries.Initialize (Queries.MySQL_Query'Class (Result.all)'Access, Self); end return; end Query; --------------------- -- Set_MySQL_Error -- --------------------- procedure Set_MySQL_Error (Self : not null access MySQL_Database'Class) is Error : constant String := Interfaces.C.Strings.Value (mysql_error (Self.Handle)); begin Self.Error := League.Strings.From_UTF_8_String (Error); end Set_MySQL_Error; end Matreshka.Internals.SQL_Drivers.MySQL.Databases;
with Ada.Numerics.Elementary_Functions; with Ada.Numerics.Discrete_Random; with SDL.Video.Windows.Makers; with SDL.Video.Renderers.Makers; with SDL.Video.Surfaces; with SDL.Video.Rectangles; with SDL.TTFs.Makers; with SDL.Events.Events; with SDL.Events.Keyboards; with SDL.Events.Mice; procedure Honeycombs is use SDL.Video.Rectangles; use SDL.C; Width : constant := 560; Height : constant := 595; Offset_X : constant := 10.0; Offset_Y : constant := 40.0; Radius : constant := 60.0; Rows : constant := 4; Cols : constant := 5; TTF_File : constant String := "NotoSans-Bold.ttf"; TTF_Size_Cell : constant := 72; TTF_Size_Sum : constant := 38; Offset_Sum_X : constant := 35; Offset_Sum_Y : constant := 530; type Node_Id is mod 6; type Shape_List is array (Node_Id) of Point; type Cell_Info is record Center : Point; Marked : Boolean; Label : String (1 .. 1); end record; type Cell_List is array (Positive range <>) of Cell_Info; function Make_Shape return Shape_List is use Ada.Numerics.Elementary_Functions; Shape : Shape_List; begin for I in Shape'Range loop Shape (I) := (X => int (Radius * Cos (Float (I), Cycle => 6.0)), Y => int (Radius * Sin (Float (I), Cycle => 6.0))); end loop; return Shape; end Make_Shape; function Make_Cells (Rows, Cols : in Positive) return Cell_List is subtype Label_Type is Character range 'A' .. 'Z'; package Randoms is new Ada.Numerics.Discrete_Random (Label_Type); use Randoms; Y_Scale : constant Float := Ada.Numerics.Elementary_Functions.Sqrt (3.0); List : Cell_List (1 .. Rows * Cols); Info : Cell_Info; Gen : Generator; begin Reset (Gen); for R in 1 .. Rows loop for C in 1 .. Cols loop Info.Center.X := int (Offset_X + Radius * 1.5 * Float (C)); Info.Center.Y := int (Offset_Y + Radius * Y_Scale * (Float (R) - Float (C mod 2) / 2.0)); Info.Marked := False; Info.Label (1) := Random (Gen); List ((R - 1) * Cols + C) := Info; end loop; end loop; return List; end Make_Cells; Window : SDL.Video.Windows.Window; Win_Surf : SDL.Video.Surfaces.Surface; Renderer : SDL.Video.Renderers.Renderer; Font_Cell : SDL.TTFs.Fonts; Font_Sum : SDL.TTFs.Fonts; Cells : Cell_List := Make_Cells (Rows, Cols); Shape : constant Shape_List := Make_Shape; Sum_Text : String (1 .. Rows * Cols); Sum_Last : Natural := Sum_Text'First - 1; function Orient_2D (A, B, C : Point) return int is ((B.X - A.X) * (C.Y - A.Y) - (B.Y - A.Y) * (C.X - A.X)); function "+" (Left, Right : Point) return Point is ((Left.X + Right.X, Left.Y + Right.Y)); function Inside (P : Point; Cell : Cell_Info) return Boolean is Count : Natural := 0; begin for Node in Shape'Range loop Count := Count + (if Orient_2D (Cell.Center + Shape (Node), Cell.Center + Shape (Node + 1), P) > 0 then 1 else 0); end loop; return Count = 6; end Inside; procedure Draw (Cell : Cell_Info) is Surface : constant SDL.Video.Surfaces.Surface := Font_Cell.Render_Solid (Cell.Label, (30, 230, 230, 255)); Self_Area : SDL.Video.Rectangles.Rectangle; Source_Area : SDL.Video.Rectangles.Rectangle := (0, 0, 0, 0); begin -- Fill for Y in int (-Radius) .. int (Radius) loop for X in int (-Radius) .. int (Radius) loop if Inside (Cell.Center + (X, Y), Cell) then Renderer.Draw (Point => Cell.Center + (X, Y)); end if; end loop; end loop; -- Label Self_Area := (Cell.Center.X - Surface.Size.Width / 2, Cell.Center.Y - Surface.Size.Height / 2, 0, 0); Win_Surf.Blit (Self_Area, Surface, Source_Area); -- Outline Renderer.Set_Draw_Colour ((0, 0, 0, 255)); for Id in Shape'Range loop Renderer.Draw (Line => (Cell.Center + Shape (Id), Cell.Center + Shape (Id + 1))); end loop; end Draw; procedure Find_And_Mark (Click : Point; Key : String) is Self_Area : SDL.Video.Rectangles.Rectangle; Source_Area : SDL.Video.Rectangles.Rectangle := (0, 0, 0, 0); begin for Cell of Cells loop if not Cell.Marked and then (Inside (Click, Cell) or Cell.Label = Key) then Cell.Marked := True; Sum_Last := Sum_Last + 1; Sum_Text (Sum_Last) := Cell.Label (1); Renderer.Set_Draw_Colour ((230, 20, 220, 255)); Draw (Cell); -- Update sum text Self_Area := (Offset_Sum_X, Offset_Sum_Y, 0, 0); Win_Surf.Blit (Self_Area, Font_Sum.Render_Solid (Sum_Text (Sum_Text'First .. Sum_Last), (0, 200, 200, 255)), Source_Area); Window.Update_Surface; exit; end if; end loop; end Find_And_Mark; procedure Wait is use type SDL.Events.Event_Types; use SDL.Events.Keyboards; Event : SDL.Events.Events.Events; begin loop SDL.Events.Events.Wait (Event); case Event.Common.Event_Type is when SDL.Events.Quit => return; when SDL.Events.Mice.Button_Down => Find_And_Mark ((Event.Mouse_Button.X, Event.Mouse_Button.Y), ""); when SDL.Events.Keyboards.Key_Down => Find_And_Mark ((0, 0), Image (Event.Keyboard.Key_Sym.Key_Code)); null; when others => null; end case; end loop; end Wait; begin if not SDL.Initialise (Flags => SDL.Enable_Screen) then return; end if; if not SDL.TTFs.Initialise then null; end if; SDL.TTFs.Makers.Create (Font_Cell, TTF_File, TTF_Size_Cell); SDL.TTFs.Makers.Create (Font_Sum, TTF_File, TTF_Size_Sum); SDL.Video.Windows.Makers.Create (Win => Window, Title => "Honeycombs", Position => SDL.Natural_Coordinates'(X => 10, Y => 10), Size => SDL.Positive_Sizes'(Width, Height), Flags => 0); Win_Surf := Window.Get_Surface; SDL.Video.Renderers.Makers.Create (Renderer, Window.Get_Surface); Renderer.Set_Draw_Colour ((0, 0, 0, 255)); Renderer.Fill (Rectangle => (0, 0, Width, Height)); for Cell of Cells loop Renderer.Set_Draw_Colour ((230, 230, 0, 255)); Draw (Cell); end loop; Window.Update_Surface; Wait; Window.Finalize; SDL.Finalise; end Honeycombs;
-- Copyright (C) 2019 Thierry Rascle <thierr26@free.fr> -- MIT license. Please refer to the LICENSE file. with Apsepp.Scope_Bound_Locks; use Apsepp.Scope_Bound_Locks; with Apsepp.Test_Reporter_Class; with Apsepp.Test_Node_Class.Suite_Stub; use Apsepp.Test_Node_Class.Suite_Stub; package Apsepp.Test_Node_Class.Runner_Sequential is type Test_Runner_Sequential is limited new Test_Suite_Stub with private; overriding function Child_Count (Obj : Test_Runner_Sequential) return Test_Node_Count is (1); overriding function Child (Obj : Test_Runner_Sequential; K : Test_Node_Index) return Test_Node_Access; overriding function No_Subtasking (Obj : Test_Runner_Sequential) return Boolean is (True); overriding function Routine (Obj : Test_Runner_Sequential; K : Test_Routine_Index) return Test_Routine; overriding procedure Run (Obj : in out Test_Runner_Sequential; Outcome : out Test_Outcome; Kind : Run_Kind := Assert_Cond_And_Run_Test); private use Test_Reporter_Class; type Test_Runner_Sequential is limited new Test_Suite_Stub with record Child_Access : Test_Node_Access; Reporter_Access : Test_Reporter_Access; R_A_S_CB : SB_Lock_CB; end record; end Apsepp.Test_Node_Class.Runner_Sequential;
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- Localization, Internationalization, Globalization for Ada -- -- -- -- Tools Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2013, Vadim Godunko <vgodunko@gmail.com> -- -- All rights reserved. -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions -- -- are met: -- -- -- -- * Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- -- -- * Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in the -- -- documentation and/or other materials provided with the distribution. -- -- -- -- * Neither the name of the Vadim Godunko, IE nor the names of its -- -- contributors may be used to endorse or promote products derived from -- -- this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -- -- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED -- -- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -- -- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -- -- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -- -- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -- -- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- -- ------------------------------------------------------------------------------ -- $Revision$ $Date$ ------------------------------------------------------------------------------ -- This program generates timezone information from TZDATA. ------------------------------------------------------------------------------ with Ada.Characters.Wide_Wide_Latin_1; with Ada.Containers.Vectors; with Ada.Strings.Wide_Wide_Fixed; with Ada.Unchecked_Deallocation; with Ada.Wide_Wide_Text_IO; with League.Application; with League.Strings; with Matreshka.Internals.Calendars.Gregorian; with Matreshka.Internals.Calendars.Times; procedure Gen_TZ is use Matreshka.Internals.Calendars; use Matreshka.Internals.Calendars.Gregorian; use Matreshka.Internals.Calendars.Times; type Time_Kinds is (Wall, Standard, UTC); type Day_Kinds is (Number, Last_Sunday, Last_Saturday); type TZ_Zone_Record is record GMT_Offset : Relative_Time; Rules : League.Strings.Universal_String; Year : Year_Number; Month : Month_Number := 1; Day_Kind : Day_Kinds := Number; Day : Day_Number := 1; Hour : Hour_Number := 0; Minute : Minute_Number := 0; Second : Second_Number := 0; Time_Kind : Time_Kinds := Wall; end record; type Time_Zone_Access is access all Internal_Time_Zone; package TZ_Zone_Vectors is new Ada.Containers.Vectors (Positive, TZ_Zone_Record); type TZ_Zone_Info is record Name : League.Strings.Universal_String; Records : TZ_Zone_Vectors.Vector; end record; X_Open_Epoch : constant := 2_299_161; Ticks_In_Day : constant := 24 * 60 * 60 * 10_000_000; Ticks_In_Hour : constant := 60 * 60 * 10_000_000; Ticks_In_Minute : constant := 60 * 10_000_000; Ticks_In_Second : constant := 10_000_000; procedure Load_TZ_File (File_Name : League.Strings.Universal_String); function To_Absolute_Time (Year : Year_Number; Month : Month_Number; Day : Day_Number; Hour : Hour_Number; Minute : Minute_Number; Second : Second_Number) return Absolute_Time; function To_Relative_Time (Hour : Hour_Number; Minute : Minute_Number; Second : Second_Number) return Relative_Time; function Image (Item : Absolute_Time) return Wide_Wide_String; function Image (Item : Relative_Time) return Wide_Wide_String; TZ : TZ_Zone_Info; procedure Prepend (Item : in out Time_Zone_Access; Value : Zone_Record); ----------- -- Image -- ----------- function Image (Item : Absolute_Time) return Wide_Wide_String is Digit : constant array (Absolute_Time range 0 .. 9) of Wide_Wide_Character := "0123456789"; Image : Wide_Wide_String := "000_000_000_000_0000000"; First : Natural := Image'Last + 1; Aux : Absolute_Time := Item; begin while Aux /= 0 loop First := First - 1; if Image (First) = '_' then First := First - 1; end if; Image (First) := Digit (Aux mod 10); Aux := Aux / 10; end loop; return Image; end Image; ----------- -- Image -- ----------- function Image (Item : Relative_Time) return Wide_Wide_String is Digit : constant array (Relative_Time range 0 .. 9) of Wide_Wide_Character := "0123456789"; Image : Wide_Wide_String := "000_000_000_000_0000000"; First : Natural := Image'Last + 1; Aux : Relative_Time := Item; begin while Aux /= 0 loop First := First - 1; if Image (First) = '_' then First := First - 1; end if; Image (First) := Digit (Aux mod 10); Aux := Aux / 10; end loop; return Image; end Image; ------------------ -- Load_TZ_File -- ------------------ procedure Load_TZ_File (File_Name : League.Strings.Universal_String) is File : Ada.Wide_Wide_Text_IO.File_Type; Buffer : Wide_Wide_String (1 .. 1024); First : Positive; Last : Natural; Field_First : Positive; Field_Last : Natural; procedure Parse_Field; -- Parses field. Sets Field_First and Field_Last to the first and last -- characters of the field, excluding heading and traling spaces. Update -- First to track current position. procedure Parse_GMTOFF (Value : out Relative_Time); -- Parses GMTOFF field of Zone record. procedure Parse_Month (Value : out Month_Number); -- Parses month name. procedure Parse_Time (Hour : out Hour_Number; Minute : out Minute_Number; Second : out Second_Number; Kind : out Time_Kinds); -- Parses time component with modifiers ('s'). procedure Parse_Zone_Common (Value : in out TZ_Zone_Record); -- Parses common fields of Zone record. ----------------- -- Parse_Field -- ----------------- procedure Parse_Field is begin -- Skip leading whitespaces. for J in First .. Last loop First := J; exit when Buffer (J) /= ' ' and Buffer (J) /= Ada.Characters.Wide_Wide_Latin_1.HT; end loop; Field_First := First; if Buffer (Field_First) = '"' then -- Use of quatation mark is not supported. raise Program_Error; end if; for J in First .. Last loop if Buffer (J) = ' ' or Buffer (J) = Ada.Characters.Wide_Wide_Latin_1.HT then Field_Last := J - 1; First := J + 1; exit; elsif J = Last then Field_Last := Last; First := Last + 1; end if; end loop; Ada.Wide_Wide_Text_IO.Put_Line (''' & Buffer (Field_First .. Field_Last) & '''); end Parse_Field; ------------------ -- Parse_GMTOFF -- ------------------ procedure Parse_GMTOFF (Value : out Relative_Time) is Hour : Hour_Number := 0; Minute : Minute_Number := 0; Second : Second_Number := 0; First : Positive := Field_First; Last : Natural := Field_Last; Minus : Boolean := False; begin -- Look for minus sign. if Buffer (First) = '-' then Minus := True; First := First + 1; end if; -- Lookup for hour separator. for J in First .. Field_Last loop if Buffer (J) = ':' then Last := J - 1; exit; end if; end loop; if First <= Last then Hour := Hour_Number'Wide_Wide_Value (Buffer (First .. Last)); First := Last + 2; Last := Field_Last; end if; -- Lookup for minute separator. for J in First .. Field_Last loop if Buffer (J) = ':' then Last := J - 1; exit; end if; end loop; if First <= Last then Minute := Minute_Number'Wide_Wide_Value (Buffer (First .. Last)); First := Last + 2; Last := Field_Last; end if; -- Process second if any. if First <= Last then Second := Second_Number'Wide_Wide_Value (Buffer (First .. Last)); end if; Value := To_Relative_Time (Hour, Minute, Second); if Minus then Value := -Value; end if; end Parse_GMTOFF; ----------------- -- Parse_Month -- ----------------- procedure Parse_Month (Value : out Month_Number) is Image : constant Wide_Wide_String := Buffer (Field_First .. Field_Last); begin if Image = "Jan" then Value := 1; elsif Image = "Feb" then Value := 2; elsif Image = "Mar" then Value := 3; elsif Image = "Apr" then Value := 4; elsif Image = "May" then Value := 5; elsif Image = "Jun" then Value := 6; elsif Image = "Jul" then Value := 7; elsif Image = "Aug" then Value := 8; elsif Image = "Sep" then Value := 9; elsif Image = "Oct" then Value := 10; elsif Image = "Nov" then Value := 11; elsif Image = "Dec" then Value := 12; else raise Constraint_Error; end if; end Parse_Month; ---------------- -- Parse_Time -- ---------------- procedure Parse_Time (Hour : out Hour_Number; Minute : out Minute_Number; Second : out Second_Number; Kind : out Time_Kinds) is First : Positive := Field_First; Last : Natural := Field_Last; begin -- Set default values. Hour := 0; Minute := 0; Second := 0; Kind := Wall; -- Lookup for hour separator. for J in First .. Last loop if Buffer (J) not in '0' .. '9' then Last := J - 1; exit; end if; end loop; if First <= Last then Hour := Hour_Number'Wide_Wide_Value (Buffer (First .. Last)); if Last = Field_Last then First := Field_Last + 1; elsif Buffer (Last + 1) = ':' then First := Last + 2; else First := Last + 1; end if; end if; -- Lookup for minute separator. Last := Field_Last; for J in First .. Field_Last loop if Buffer (J) not in '0' .. '9' then Last := J - 1; exit; end if; end loop; if First <= Last then Minute := Minute_Number'Wide_Wide_Value (Buffer (First .. Last)); if Last = Field_Last then First := Field_Last + 1; elsif Buffer (Last + 1) = ':' then First := Last + 2; else First := Last + 1; end if; end if; -- Lookup for second separator. Last := Field_Last; for J in First .. Field_Last loop if Buffer (J) not in '0' .. '9' then Last := J - 1; exit; end if; end loop; if First <= Last then Second := Second_Number'Wide_Wide_Value (Buffer (First .. Last)); if Last = Field_Last then First := Field_Last + 1; elsif Buffer (Last + 1) = ':' then First := Last + 2; else First := Last + 1; end if; end if; Last := Field_Last; -- Parse modifier if any. if First <= Last then if Buffer (First .. Last) = "s" then Kind := Standard; elsif Buffer (First .. Last) = "u" then Kind := UTC; else raise Constraint_Error; end if; end if; end Parse_Time; ------------------------ -- Parse_Zone_Commmon -- ------------------------ procedure Parse_Zone_Common (Value : in out TZ_Zone_Record) is begin -- Parse GMTOFF field. Parse_Field; Parse_GMTOFF (Value.GMT_Offset); -- Process RULES field. Parse_Field; if Buffer (Field_First .. Field_Last) /= "-" then Value.Rules := League.Strings.To_Universal_String (Buffer (Field_First .. Field_Last)); end if; -- Skip FORMAT field. Parse_Field; -- Process components of [UNTIL] field. -- Year component. Parse_Field; if Field_First <= Field_Last then Value.Year := Year_Number'Wide_Wide_Value (Buffer (Field_First .. Field_Last)); else Ada.Wide_Wide_Text_IO.Put_Line (">>> END OF TIME <<<"); Value.Year := Year_Number'Last; end if; -- Month component. Parse_Field; if Field_First <= Field_Last then Parse_Month (Value.Month); end if; -- Day component. Parse_Field; if Field_First <= Field_Last then -- Special values. if Buffer (Field_First .. Field_Last) = "lastSun" then Value.Day_Kind := Last_Sunday; elsif Buffer (Field_First .. Field_Last) = "lastSat" then Value.Day_Kind := Last_Saturday; -- Simple numeric value. else Value.Day := Day_Number'Wide_Wide_Value (Buffer (Field_First .. Field_Last)); end if; end if; -- Time component. Parse_Field; if Field_First <= Field_Last then Parse_Time (Value.Hour, Value.Minute, Value.Second, Value.Time_Kind); end if; end Parse_Zone_Common; begin Ada.Wide_Wide_Text_IO.Open (File, Ada.Wide_Wide_Text_IO.In_File, File_Name.To_UTF_8_String, "wcem=8"); while not Ada.Wide_Wide_Text_IO.End_Of_File (File) loop Ada.Wide_Wide_Text_IO.Get_Line (File, Buffer, Last); -- Remove comments for J in Buffer'First .. Last loop if Buffer (J) = '#' then Last := J - 1; -- Remove trailing spaces and horizontal tabulations. for J in reverse Buffer'First .. Last loop exit when Buffer (J) /= ' ' and Buffer (J) /= Ada.Characters.Wide_Wide_Latin_1.HT; Last := J - 1; end loop; exit; end if; end loop; -- Process non-empty line. if Last >= Buffer'First then First := Buffer'First; if Buffer (1 .. 4) = "Rule" then -- Rule line. null; elsif Buffer (1 .. 4) = "Link" then Ada.Wide_Wide_Text_IO.Put_Line (Buffer (First .. Last)); elsif Buffer (1 .. 4) = "Zone" then Ada.Wide_Wide_Text_IO.Put_Line (Buffer (First .. Last)); -- Zone primary line. declare D : TZ_Zone_Record; begin -- Skip record kind. Parse_Field; -- Parse name of timezone. Parse_Field; TZ.Name := League.Strings.To_Universal_String (Buffer (Field_First .. Field_Last)); -- Parse common fields. Parse_Zone_Common (D); TZ.Records.Append (D); end; else Ada.Wide_Wide_Text_IO.Put_Line (Buffer (First .. Last)); -- Zone continuation line. declare D : TZ_Zone_Record; begin -- Parse common fields. Parse_Zone_Common (D); TZ.Records.Append (D); end; end if; end if; end loop; Ada.Wide_Wide_Text_IO.Close (File); end Load_TZ_File; ------------- -- Prepend -- ------------- procedure Prepend (Item : in out Time_Zone_Access; Value : Zone_Record) is procedure Free is new Ada.Unchecked_Deallocation (Internal_Time_Zone, Time_Zone_Access); Aux : Time_Zone_Access := Item; begin if Aux = null then Item := new Internal_Time_Zone (1); else Item := new Internal_Time_Zone (Aux.Length + 1); Item.Data (Aux.Data'First + 1 .. Aux.Data'Last + 1) := Aux.Data; end if; Item.Data (Item.Data'First) := Value; Free (Aux); end Prepend; ---------------------- -- To_Absolute_Time -- ---------------------- function To_Absolute_Time (Year : Year_Number; Month : Month_Number; Day : Day_Number; Hour : Hour_Number; Minute : Minute_Number; Second : Second_Number) return Absolute_Time is begin return Absolute_Time (Julian_Day (Year, Month, Day) - X_Open_Epoch) * Ticks_In_Day + Absolute_Time (Hour) * Ticks_In_Hour + Absolute_Time (Minute) * Ticks_In_Minute + Absolute_Time (Second) * Ticks_In_Second; end To_Absolute_Time; ---------------------- -- To_Relative_Time -- ---------------------- function To_Relative_Time (Hour : Hour_Number; Minute : Minute_Number; Second : Second_Number) return Relative_Time is begin return Relative_Time (Hour) * Ticks_In_Hour + Relative_Time (Minute) * Ticks_In_Minute + Relative_Time (Second) * Ticks_In_Second; end To_Relative_Time; procedure Test (Z : not null Time_Zone_Access; Y : Year_Number; M : Month_Number; D : Day_Number; H : Hour_Number; N : Minute_Number; S : Second_Number) is Year : Year_Number; Month : Month_Number; Day : Day_Number; Hour : Hour_Number; Minute : Minute_Number; Second : Second_Number; Fraction : Nano_Second_100_Number; JDay : Julian_Day_Number; Stamp : Absolute_Time; begin Stamp := Create (UTC_Time_Zone'Access, Julian_Day (Y, M, D), H, N, S, 0); Split (UTC_Time_Zone'Access, Stamp, JDay, Hour, Minute, Second, Fraction); Split (JDay, Year, Month, Day); Ada.Wide_Wide_Text_IO.Put (Ada.Strings.Wide_Wide_Fixed.Trim (Year_Number'Wide_Wide_Image (Year), Ada.Strings.Both) & "-" & Ada.Strings.Wide_Wide_Fixed.Trim (Month_Number'Wide_Wide_Image (Month), Ada.Strings.Both) & "-" & Ada.Strings.Wide_Wide_Fixed.Trim (Day_Number'Wide_Wide_Image (Day), Ada.Strings.Both) & " " & Ada.Strings.Wide_Wide_Fixed.Trim (Hour_Number'Wide_Wide_Image (Hour), Ada.Strings.Both) & ":" & Ada.Strings.Wide_Wide_Fixed.Trim (Minute_Number'Wide_Wide_Image (Minute), Ada.Strings.Both) & ":" & Ada.Strings.Wide_Wide_Fixed.Trim (Second_Number'Wide_Wide_Image (Second), Ada.Strings.Both) & " => "); Split (Z.all'Unchecked_Access, Stamp, JDay, Hour, Minute, Second, Fraction); Split (JDay, Year, Month, Day); Ada.Wide_Wide_Text_IO.Put_Line (Ada.Strings.Wide_Wide_Fixed.Trim (Year_Number'Wide_Wide_Image (Year), Ada.Strings.Both) & "-" & Ada.Strings.Wide_Wide_Fixed.Trim (Month_Number'Wide_Wide_Image (Month), Ada.Strings.Both) & "-" & Ada.Strings.Wide_Wide_Fixed.Trim (Day_Number'Wide_Wide_Image (Day), Ada.Strings.Both) & " " & Ada.Strings.Wide_Wide_Fixed.Trim (Hour_Number'Wide_Wide_Image (Hour), Ada.Strings.Both) & ":" & Ada.Strings.Wide_Wide_Fixed.Trim (Minute_Number'Wide_Wide_Image (Minute), Ada.Strings.Both) & ":" & Ada.Strings.Wide_Wide_Fixed.Trim (Second_Number'Wide_Wide_Image (Second), Ada.Strings.Both)); end Test; From : Absolute_Time := 0; Z : Time_Zone_Access; begin Load_TZ_File (League.Application.Arguments.Element (1)); -- Generate zone information. for R of TZ.Records loop Prepend (Z, (From, R.GMT_Offset)); Ada.Wide_Wide_Text_IO.Put_Line (Image (From) & ", " & Image (R.GMT_Offset)); if R.Year /= Year_Number'Last then From := To_Absolute_Time (R.Year, R.Month, R.Day, R.Hour, R.Minute, R.Second); case R.Time_Kind is when Wall => From := From - Absolute_Time (R.GMT_Offset); -- XXX Note: this time must be corrected according to modifier. when Standard => From := From - Absolute_Time (R.GMT_Offset); when UTC => null; end case; else From := Absolute_Time'Last; end if; end loop; -- Some tests. Test (Z, 1879, 12, 31, 21, 29, 39); Test (Z, 1879, 12, 31, 21, 29, 40); Test (Z, 1916, 7, 2, 21, 29, 59); Test (Z, 1916, 7, 2, 21, 30, 00); Test (Z, 1917, 7, 1, 20, 29, 11); Test (Z, 1917, 7, 1, 20, 29, 12); Test (Z, 2011, 3, 26, 22, 59, 59); Test (Z, 2011, 3, 26, 23, 0, 0); end Gen_TZ;
----------------------------------------------------------------------- -- asf-converters -- ASF Converters -- Copyright (C) 2010 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 EL.Objects; with ASF.Components.Base; with ASF.Contexts.Faces; -- The <b>ASF.Converters</b> defines an interface used by the conversion model -- to translate an object into a string when formatting the response and translate -- a string into an object during the apply request or validation phases (JSF postback). -- -- See JSR 314 - JavaServer Faces Specification 3.3.2 Converter -- (To_String is the JSF getAsString method and To_Object is the JSF getAsObject method) package ASF.Converters is Invalid_Conversion : exception; -- ------------------------------ -- Converter -- ------------------------------ -- The <b>Converter</b> must implement two functions to convert a string into -- an object and the opposite. The converter instance must be registered in -- the component factory (See <b>ASF.Factory.Component_Factory</b>). -- Unlike the Java implementation, the instance will be shared by multiple -- views and requests. type Converter is limited interface; type Converter_Access is access all Converter'Class; -- Convert the object value into a string. The object value is associated -- with the specified component. -- If the string cannot be converted, the Invalid_Conversion exception should be raised. function To_String (Convert : in Converter; Context : in ASF.Contexts.Faces.Faces_Context'Class; Component : in ASF.Components.Base.UIComponent'Class; Value : in EL.Objects.Object) return String is abstract; -- Convert the string into an object for the specified component. -- If the string cannot be converted, the Invalid_Conversion exception should be raised. function To_Object (Convert : in Converter; Context : in ASF.Contexts.Faces.Faces_Context'Class; Component : in ASF.Components.Base.UIComponent'Class; Value : in String) return EL.Objects.Object is abstract; end ASF.Converters;
----------------------------------------------------------------------- -- security-permissions -- Definition of permissions -- Copyright (C) 2010, 2011, 2012, 2016, 2017 Stephane Carrez -- Written by Stephane Carrez (Stephane.Carrez@gmail.com) -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. ----------------------------------------------------------------------- private with Interfaces; -- == Permission == -- The <b>Security.Permissions</b> package defines the different permissions that can be -- checked by the access control manager. An application should declare each permission -- by instantiating the <tt>Definition</tt> package: -- -- package Perm_Create_Workspace is new Security.Permissions.Definition ("create-workspace"); -- -- This declares a permission that can be represented by "<tt>create-workspace</tt>" in -- configuration files. In Ada, the permission is used as follows: -- -- Perm_Create_Workspace.Permission -- package Security.Permissions is Invalid_Name : exception; -- Max number of permissions supported by the implementation. MAX_PERMISSION : constant Natural := 255; type Permission_Index is new Natural range 0 .. MAX_PERMISSION; type Permission_Index_Array is array (Positive range <>) of Permission_Index; NONE : constant Permission_Index := Permission_Index'First; -- Get the permission index associated with the name. function Get_Permission_Index (Name : in String) return Permission_Index; -- Get the list of permissions whose name is given in the string with separated comma. function Get_Permission_Array (List : in String) return Permission_Index_Array; -- Get the permission name given the index. function Get_Name (Index : in Permission_Index) return String; -- The permission root class. -- Each permission is represented by a <b>Permission_Index</b> number to provide a fast -- and efficient permission check. type Permission (Id : Permission_Index) is tagged limited null record; generic Name : String; package Definition is function Permission return Permission_Index; pragma Inline_Always (Permission); end Definition; -- Add the permission name and allocate a unique permission index. procedure Add_Permission (Name : in String; Index : out Permission_Index); type Permission_Index_Set is private; -- Check if the permission index set contains the given permission index. function Has_Permission (Set : in Permission_Index_Set; Index : in Permission_Index) return Boolean; -- Add the permission index to the set. procedure Add_Permission (Set : in out Permission_Index_Set; Index : in Permission_Index); -- Get the last permission index registered in the global permission map. function Get_Last_Permission_Index return Permission_Index; -- The empty set of permission indexes. EMPTY_SET : constant Permission_Index_Set; private INDEX_SET_SIZE : constant Natural := (MAX_PERMISSION + 7) / 8; type Permission_Index_Set is array (0 .. INDEX_SET_SIZE - 1) of Interfaces.Unsigned_8; EMPTY_SET : constant Permission_Index_Set := (others => 0); end Security.Permissions;
------------------------------------------------------------------------------ -- -- -- Copyright (C) 2017, AdaCore -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions are -- -- met: -- -- 1. Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- 2. Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in -- -- the documentation and/or other materials provided with the -- -- distribution. -- -- 3. Neither the name of the copyright holder nor the names of its -- -- contributors may be used to endorse or promote products derived -- -- from this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -- -- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -- -- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -- -- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -- -- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -- -- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -- -- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- -- ------------------------------------------------------------------------------ -- This package provides utility routines for use with the Data Watchpoint -- Trace (DWT) facility defined by ARM for Cortex M processors. As such it -- should be vendor-independent. with HAL; use HAL; package Cortex_M.DWT is -- Data Watchpoint Trace pragma Elaborate_Body; -- The assumption is that application code will access the registers of -- the DWT directly, via the SVD-generated package Cortex_M_SVD.DWT, -- except when the convenience routines below are utilized. ---------------------------- -- Convenience functions -- ---------------------------- -- DWT reset values. These constant are the control register considered -- as unsigned 32-bit values for convenient comparison using the function -- below. The values are just the NUMCOMP nibble and the boolean flags in -- the next nibble. No_DWT_Present : constant UInt32 := 0; Only_One_Comparator : constant UInt32 := 16#1000_0000#; -- 268435456 dec One_Comparator_Watchpoints : constant UInt32 := 16#1F00_0000#; -- 520093696 dec Four_Comparators_Watchpoints_And_Triggers : constant UInt32 := 16#4000_0000#; -- 1073741824 dec Four_Comparators_Watchpoints_Only : constant UInt32 := 16#4F00_0000#; -- 1325400064 dec function DWT_Reset_Value return UInt32 with Inline; -- Returns the value of the DWT.CTRL register as a word, for convenient -- comparison to the constants above. procedure Enable_DWT_Unit with Post => DWT_Unit_Enabled, Inline; -- Sets the trace enable bit (TRCENA) in the Debug Exception & Monitor Ctrl -- (DEMCR) register within the Cortex M Debug peripheral. procedure Disable_DWT_Unit with Post => not DWT_Unit_Enabled, Inline; -- Clears the trace enable bit (TRCENA) in the Debug Exception & Monitor -- Ctrl (DEMCR) register within the Cortex M Debug peripheral. function DWT_Unit_Enabled return Boolean with Inline; end Cortex_M.DWT;
pragma License (Unrestricted); -- runtime unit with Ada.Exceptions; package System.Finally is -- This unit will be linked if these subprograms are called from -- UNIT__finalize_spec, UNIT__finalize_body, or finalize_library -- generated by gnatbind. pragma Preelaborate; -- implementation of Save_Library_Occurrence (s-soflin.ads) procedure Save_Library_Occurrence ( X : Ada.Exceptions.Exception_Occurrence_Access) with Export, Convention => Ada, External_Name => "system__soft_links__save_library_occurrence"; -- implementation of Reraise_Library_Exception_If_Any (a-except-2005.adb) procedure Reraise_Library_Exception_If_Any with Export, Convention => Ada, External_Name => "__gnat_reraise_library_exception_if_any"; end System.Finally;
--------------------------------------------------------------------------- -- package body Tridiagonal, symmetric matrix tridiagonalization -- Copyright (C) 2018 Jonathan S. Parker -- -- Permission to use, copy, modify, and/or distribute this software for any -- purpose with or without fee is hereby granted, provided that the above -- copyright notice and this permission notice appear in all copies. -- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. --------------------------------------------------------------------------- with Ada.Numerics; with Ada.Numerics.Generic_Elementary_Functions; with Givens_Rotation; package body Tridiagonal is package math is new Ada.Numerics.Generic_Elementary_Functions (Real); use math; package Rotate is new Givens_Rotation (Real); use Rotate; Zero : constant Real := +0.0; One : constant Real := +1.0; Two : constant Real := +2.0; function Identity return A_Matrix is Q : A_Matrix; begin Q := (others => (others => Zero)); for c in C_Index loop Q(c, c) := One; end loop; return Q; end Identity; type Rotation is record sn : Real := Zero; cs : Real := One; cs_minus_1 : Real := Zero; sn_minus_1 : Real := Zero; hypotenuse : Real := Zero; P_bigger_than_L : Boolean := True; Skip_Rotation : Boolean := True; Pivot_Col : C_Index := C_Index'First; Hi_Row : R_Index := R_Index'First; Lo_Row : R_Index := R_Index'First; end record; type Row is array(C_Index) of Real; -- Sum = Small + Large. Lost_Bits = Small - (Sum - Large) procedure Sum_with_Dropped_Bits (A, B : in Real; Sum : out Real; Dropped_Bits : out Real) is begin Sum := A + B; if Abs A > Abs B then Dropped_Bits := B - (Sum - A); else Dropped_Bits := A - (Sum - B); end if; end Sum_with_Dropped_Bits; --------------------------------------- -- Arg_1_is_Negligible_Respect_Arg_2 -- --------------------------------------- -- If Abs_x is negligible in comparison to Abs_y then return True. function Arg_1_is_Negligible_Respect_Arg_2 (x, y : Real) return Boolean is Abs_x : constant Real := Abs x; Abs_y : constant Real := Abs y; Min_Allowed_Real : constant Real := Two**(Real'Machine_Emin + 16); Added_Range : constant := 3; -- 2, 3 seem bst; 3 gives 2**(-53) Eps_Factor : constant Real := Real'Epsilon * Two**(-Added_Range); begin if Abs_x < Min_Allowed_Real and then Abs_x <= Abs_y then -- eg, Abs_x = 0 return True; elsif Abs_x < Abs_y * Eps_Factor then return True; else return False; end if; end Arg_1_is_Negligible_Respect_Arg_2; --------------------------------- -- Lower_Diagonal_QR_Iteration -- --------------------------------- -- Operates only on square real blocks. procedure Lower_Diagonal_QR_Iteration (A : in out A_Matrix; Q : in out A_Matrix; Shift : in Real; Final_Shift_Col : in C_Index := C_Index'Last; Starting_Col : in C_Index := C_Index'First; Final_Col : in C_Index := C_Index'Last; Q_Matrix_Desired : in Boolean := True) is Rotations : array (C_Index) of Rotation; ----------------------------------------- -- Multiply_A_on_RHS_with_Transpose_of -- ----------------------------------------- -- multiply A on the right by R_transpose: -- A = A * R_transpose procedure Multiply_A_on_RHS_with_Transpose_of (R : in Rotation) is sn : Real renames R.sn; cs : Real renames R.cs; cs_minus_1 : Real renames R.cs_minus_1; sn_minus_1 : Real renames R.sn_minus_1; P_bigger_than_L : Boolean renames R.P_bigger_than_L; Skip_Rotation : Boolean renames R.Skip_Rotation; Pivot_Row : R_Index renames R.Hi_Row; Low_Row : R_Index renames R.Lo_Row; A_pvt, A_low : Real; begin if Skip_Rotation then return; end if; -- Rotate corresponding columns. Multiply on RHS by transpose -- of above givens matrix (second step of similarity transformation). -- (Low_Row is Lo visually, but its index is higher than Pivot's.) if P_bigger_than_L then -- |s| < |c| for r in Index'Base'Max(Starting_Col, Pivot_Row-1) .. Pivot_Row+1 loop A_pvt := A(r, Pivot_Row); A_low := A(r, Low_Row); A(r, Pivot_Row) := A_pvt + ( cs_minus_1*A_pvt + sn*A_low); A(r, Low_Row) := A_low + (-sn*A_pvt + cs_minus_1*A_low); end loop; else -- Abs_P <= Abs_L, so abs t := abs (P / L) <= 1 for r in Index'Base'Max(Starting_Col, Pivot_Row-1) .. Pivot_Row+1 loop A_pvt := A(r, Pivot_Row); A_low := A(r, Low_Row); A(r, Pivot_Row) := A_low + ( cs*A_pvt + sn_minus_1*A_low); A(r, Low_Row) :=-A_pvt + (-sn_minus_1*A_pvt + cs*A_low); end loop; end if; end Multiply_A_on_RHS_with_Transpose_of; --------------------------------------- -- Rotate_to_Kill_Element_Lo_of_pCol -- --------------------------------------- -- Try to zero out A(Lo_Row, Pivot_Col) with a similarity transformation. -- In other words, multiply A on left by R: -- -- A = R * A -- -- and multiply Q on right by R_transpose: -- -- Q = Q * R_transpose -- procedure Rotate_to_Kill_Element_Lo_of_pCol (R : in Rotation) is sn : constant Real := R.sn; cs : constant Real := R.cs; cs_minus_1 : constant Real := R.cs_minus_1; sn_minus_1 : constant Real := R.sn_minus_1; P_bigger_than_L : constant Boolean := R.P_bigger_than_L; Skip_Rotation : constant Boolean := R.Skip_Rotation; Pivot_Col : constant C_Index := R.Pivot_Col; Pivot_Row : constant R_Index := R.Hi_Row; Low_Row : constant R_Index := R.Lo_Row; A_pvt, A_low, Q_pvt, Q_low : Real; begin if Skip_Rotation then return; end if; if P_bigger_than_L then -- |s| < |c| --for c in Starting_Col .. Final_Col loop --for c in Pivot_Col .. Final_Col loop -- works only for upper hessenbergs for c in Pivot_Col .. Pivot_Col+2 loop -- works only for Tridiagonals A_pvt := A(Pivot_Row, c); A_low := A(Low_Row, c); A(Pivot_Row, c) := A_pvt + ( cs_minus_1*A_pvt + sn*A_low); A(Low_Row, c) := A_low + (-sn*A_pvt + cs_minus_1*A_low); end loop; else -- Abs_P <= Abs_L, so abs t := abs (P / L) <= 1 --for c in Starting_Col .. Final_Col loop --for c in Pivot_Col .. Final_Col loop -- works only for upper hessenbergs for c in Pivot_Col .. Pivot_Col+2 loop -- works only for Tridiagonals A_pvt := A(Pivot_Row, c); A_low := A(Low_Row, c); A(Pivot_Row, c) := A_low + ( cs*A_pvt + sn_minus_1*A_low); A(Low_Row, c) :=-A_pvt + (-sn_minus_1*A_pvt + cs*A_low); end loop; end if; -- Rotate corresponding columns of Q. (Multiply on RHS by transpose -- of above givens matrix to accumulate full Q.) if Q_Matrix_Desired then if P_bigger_than_L then -- |s| < |c| for r in Starting_Col .. Final_Col loop Q_pvt := Q(r, Pivot_Row); Q_low := Q(r, Low_Row); Q(r, Pivot_Row) := Q_pvt + (cs_minus_1*Q_pvt + sn*Q_low); Q(r, Low_Row) := Q_low + (-sn*Q_pvt + cs_minus_1*Q_low); end loop; else -- Abs_P <= Abs_L, so abs t := abs (P / L) <= 1 for r in Starting_Col .. Final_Col loop Q_pvt := Q(r, Pivot_Row); Q_low := Q(r, Low_Row); Q(r, Pivot_Row) := Q_low + (cs*Q_pvt + sn_minus_1*Q_low); Q(r, Low_Row) :=-Q_pvt + (-sn_minus_1*Q_pvt + cs*Q_low); end loop; end if; -- P_bigger_than_L end if; -- Q_Matrix_Desired end Rotate_to_Kill_Element_Lo_of_pCol; type Diag_Storage is array(Index) of Real; Matrix_Size : constant Integer := Integer (Final_Col)-Integer (Starting_Col)+1; tst1, tst2 : Real; Lost_Bits : Diag_Storage; hypot, sn, cs, cs_minus_1, sn_minus_1 : Real; P_bigger_than_L : Boolean; Skip_Rotation : Boolean; Hi_Row, Lo_Row : R_Index; P, L : Real; begin if Matrix_Size < 3 then return; end if; -- can't QR it. Lost_Bits := (others => 0.0); -- Subtract 'Shift' from each diagonal element of A. -- Sum = A(c, c) + (-Shift) -- Sum = Small + Large. Lost_Bits = Small - (Sum - Large) declare Sum, Dropped_Bits : Real; begin for c in Starting_Col .. Final_Shift_Col loop Sum_with_Dropped_Bits (A(c,c), -Shift, Sum, Dropped_Bits); A(c, c) := Sum; Lost_Bits(c) := Dropped_Bits; end loop; end; for Pivot_Col in Starting_Col .. Final_Shift_Col-1 loop Hi_Row := Pivot_Col; Lo_Row := Hi_Row + 1; P := A(Hi_Row, Pivot_Col); L := A(Lo_Row, Pivot_Col); tst1 := Abs A(Lo_Row, Pivot_Col); tst2 := Abs A(Pivot_Col, Pivot_Col) + Abs A(Lo_Row, Lo_Row); if Arg_1_is_Negligible_Respect_Arg_2 (tst1, tst2) then Rotations(Pivot_Col).Skip_Rotation := True; -- Rotations is initialized. A(Lo_Row, Pivot_Col) := Zero; A(Pivot_Col, Lo_Row) := Zero; else Get_Rotation_That_Zeros_Out_Low (P, L, sn, cs, cs_minus_1, sn_minus_1, hypot, P_bigger_than_L, Skip_Rotation); Rotations(Pivot_Col) := (sn => sn, cs => cs, cs_minus_1 => cs_minus_1, sn_minus_1 => sn_minus_1, hypotenuse => hypot, P_bigger_than_L => P_bigger_than_L, Skip_Rotation => Skip_Rotation, Pivot_Col => Pivot_Col, Hi_Row => Hi_Row, Lo_Row => Lo_Row); -- Zero out A(Lo_Row, Pivot_Col). Update A and Q as global memory. -- Apply rotation by multiplying Givens Matrix on LHS of A. -- Then multiply transpose of Givens Matrix on RHS of Q. Rotate_to_Kill_Element_Lo_of_pCol (Rotations(Pivot_Col)); A(Hi_Row, Pivot_Col) := Real'Copy_Sign (hypot, A(Hi_Row, Pivot_Col)); A(Lo_Row, Pivot_Col) := Zero; end if; end loop; -- over Pivot_Col -- These can be done inside the above loop (after a delay of 1 step): for Pivot_Col in Starting_Col .. Final_Shift_Col-1 loop Multiply_A_on_RHS_with_Transpose_of (Rotations(Pivot_Col)); end loop; -- Add Shift back to A: for c in Starting_Col .. Final_Shift_Col loop A(c, c) := (A(c, c) + Shift) + Lost_Bits(c); -- best default end loop; for c in Starting_Col+1 .. Final_Col loop --A(c-1, c) := Half * (A(c, c-1) + A(c-1, c)); A(c, c-1) := A(c-1, c); end loop; for c in Starting_Col+2 .. Final_Col loop A(c-2, c) := Zero; end loop; end Lower_Diagonal_QR_Iteration; -------------------- -- Tridiagonalize -- -------------------- -- Operates only on square real blocks. -- -- Want to use similarity transforms to make A into T, -- Tridiagonal. Let Qj be a 2x2 givens rotation matrix, -- and let Qj' be its transpose (and inverse). Then form -- -- A = -- -- (Q1*...*Qn) * (Qn'*...*Q1') * A * (Q1*...*Qn) * (Qn'*...*Q1') = -- -- Q * T * Q', -- -- where T = Q' * A * Q. -- -- To complete the decomposition of A to T, insert Qj * Qj' into -- Q * T * Q' to get Q * (Qj * Qj') * T * (Qj * Qj') * Q'. -- -- So to develop Q, we rotate columns of Q by multiplying on RHS with -- Qj. H gets multiplied on the LHS by Qj' (rotating rows to zero out -- the lower triangular region) and on the RHS by Qj. -- -- Wind up with the eigenvalue equation A = Q * T * Q' which becomes -- -- A * Q = Q * T. -- -- If T were diagonal, then the column vectors of Q would be the eigenvectors -- and the diagonal elements of T would be the eigenvalues. procedure Tridiagonalize (A : in out A_Matrix; Q : out A_Matrix; Starting_Col : in C_Index := C_Index'First; Final_Col : in C_Index := C_Index'Last; Initial_Q : in A_Matrix := Identity; Q_Matrix_Desired : in Boolean := True) is ----------------------------------------- -- Rotate_to_Kill_Element_Hi_of_pRow -- ----------------------------------------- -- Zero out A(Lo_Row, pCol) with a similarity transformation. In -- other words, multiply A on left by Q_tr and on right by Q: -- A_t = Q_transpose * A * Q -- Use enhanced precision rotations here. procedure Rotate_to_Kill_Element_Hi_of_pRow (pRow : in R_Index; Hi_Col : in C_Index; Lo_Col : in C_Index) is sn, cs : Real; cs_minus_1 : Real; sn_minus_1 : Real; P_bigger_than_L : Boolean; Skip_Rotation : Boolean; Pivot_Row : R_Index renames pRow; Pivot_Col : C_Index renames Lo_Col; A_pvt, A_low, Q_pvt, Q_low : Real; P : constant Real := A(Pivot_Row, Pivot_Col); -- P is for Pivot L : constant Real := A(Pivot_Row, Hi_Col); hypot : Real; begin --if not A(Pivot_Row, Pivot_Col)'valid or else not A(Pivot_Row, Hi_Col)'valid then -- raise Constraint_Error with "Invalid input in Rotate_to_Kill.."; --end if; Get_Rotation_That_Zeros_Out_Low (P, L, sn, cs, cs_minus_1, sn_minus_1, hypot, P_bigger_than_L, Skip_Rotation); if Skip_Rotation then return; end if; -- Rotate rows. Multiply on LHS by givens rotation G. -- Want Q' A Q = H = upper hessenberg. -- Each step is: G A G' = partial H -- So the desired Q will be the product of the G' matrices -- which we obtain by repeatedly multiplying I on the RHS by G'. if P_bigger_than_L then -- |s| < |c| for r in Pivot_Row .. Final_Col loop A_pvt := A(r, Pivot_Col); A_low := A(r, Hi_Col); A(r, Pivot_Col) := A_pvt + ( cs_minus_1*A_pvt + sn*A_low); A(r, Hi_Col) := A_low + (-sn*A_pvt + cs_minus_1*A_low); end loop; else -- Abs_P <= Abs_L, so abs t := abs (P / L) <= 1 for r in Pivot_Row .. Final_Col loop A_pvt := A(r, Pivot_Col); A_low := A(r, Hi_Col); A(r, Pivot_Col) := A_low + ( cs*A_pvt + sn_minus_1*A_low); A(r, Hi_Col) :=-A_pvt + (-sn_minus_1*A_pvt + cs*A_low); end loop; end if; -- Rotate corresponding columns. Multiply on RHS by transpose -- of above givens matrix (second step of similarity transformation). -- (Hi_Col is Lo visually, but its index is higher than Pivot's.) -- Do the above 2 rotations in a single step (tho' it hardly matters): -- -- A(Pivot_Col, Pivot_Col) := cs**2*x + cs*sn*2.0*z + sn**2*y; -- A(Hi_Col, Hi_Col) := sn**2*x - cs*sn*2.0*z + cs**2*y; -- A(Pivot_Col, Hi_Col) := cn**2*z - sn**2*z + sn*cs*(y - x); -- -- x_new := A(Pivot_Col, Pivot_Col) := x + (cs*sn*2.0*z + sn**2*(y - x)); -- y_new := A(Hi_Col, Hi_Col) := y - (cs*sn*2.0*z + sn**2*(y - x)); -- z_new := A(Pivot_Col, Hi_Col) := z - sn**2*z2 + sn*cs*(y - x); -- -- x_new := A(Pivot_Col, Pivot_Col) := x + sn*(cs*2.0*z + sn*(y - x)); -- y_new := A(Hi_Col, Hi_Col) := y - sn*(cs*2.0*z + sn*(y - x)); -- z_new := A(Pivot_Col, Hi_Col) := z - sn*(sn*2.0*z - cs*(y - x)); if P_bigger_than_L then -- |s| < |c| declare r : constant Index := Pivot_Col; begin A_pvt := A(Pivot_Col, r); A_low := A(Hi_Col, r); A(Pivot_Col, r) := A_pvt + ( cs_minus_1*A_pvt + sn*A_low); A(Hi_Col, r) := A_low + (-sn*A_pvt + cs_minus_1*A_low); end; declare r : constant Index := Hi_Col; begin A_pvt := A(Pivot_Col, r); A_low := A(Hi_Col, r); --A(Pivot_Col, r) := A_pvt + ( cs_minus_1*A_pvt + sn*A_low); A(Hi_Col, r) := A_low + (-sn*A_pvt + cs_minus_1*A_low); end; else -- Abs_P <= Abs_L, so abs t := abs (P / L) <= 1 declare r : constant Index := Pivot_Col; begin A_pvt := A(Pivot_Col, r); A_low := A(Hi_Col, r); A(Pivot_Col, r) := A_low + ( cs*A_pvt + sn_minus_1*A_low); A(Hi_Col, r) :=-A_pvt + (-sn_minus_1*A_pvt + cs*A_low); end; declare r : constant Index := Hi_Col; begin A_pvt := A(Pivot_Col, r); A_low := A(Hi_Col, r); --A(Pivot_Col, r) := A_low + ( cs*A_pvt + sn_minus_1*A_low); A(Hi_Col, r) :=-A_pvt + (-sn_minus_1*A_pvt + cs*A_low); end; end if; -- Have modified 2 cols of entire (symmetric) matrix: Pivot_Col, Hi_Col. -- Now copy the cols to the 2 rows you get by transposing the 2 cols. for c in Starting_Col .. Final_Col loop A(Pivot_Col, c) := A(c, Pivot_Col); end loop; for c in Starting_Col .. Final_Col loop A(Hi_Col, c) := A(c, Hi_Col); end loop; -- Rotate corresponding columns of Q. (Multiply on RHS by transpose -- of above givens matrix to accumulate full Q.) if Q_Matrix_Desired then if P_bigger_than_L then -- |s| < |c| for r in Starting_Col .. Final_Col loop Q_pvt := Q(r, Pivot_Col); Q_low := Q(r, Hi_Col); Q(r, Pivot_Col) := Q_pvt + ( cs_minus_1*Q_pvt + sn*Q_low); Q(r, Hi_Col) := Q_low + (-sn*Q_pvt + cs_minus_1*Q_low); end loop; else -- Abs_P <= Abs_L, so abs t := abs (P / L) <= 1 for r in Starting_Col .. Final_Col loop Q_pvt := Q(r, Pivot_Col); Q_low := Q(r, Hi_Col); Q(r, Pivot_Col) := Q_low + ( cs*Q_pvt + sn_minus_1*Q_low); Q(r, Hi_Col) :=-Q_pvt + (-sn_minus_1*Q_pvt + cs*Q_low); end loop; end if; -- P_bigger_than_L end if; -- Q_Matrix_Desired end Rotate_to_Kill_Element_Hi_of_pRow; procedure Get_Sqrt_of_Sum_of_Sqrs_of_Row (Row_Id : in R_Index; Starting_Col : in C_Index; Ending_Col : in C_Index; Row_Sums : out Row) is Emin : constant Integer := Real'Machine_Emin; Emax : constant Integer := Real'Machine_Emax; Max : Real := Zero; Un_Scale, Scale : Real := Zero; Abs_A : Real := Zero; M_exp : Integer := 0; begin Max := Abs A(Row_Id, Starting_Col); if Ending_Col > Starting_Col then for c in Starting_Col+1 .. Ending_Col loop Abs_A := Abs A(Row_Id, c); if Abs_A > Max then Max := Abs_A; end if; end loop; end if; if Max < Two**Emin then Row_Sums := (others => Zero); return; end if; if Max < Two**(Emin / 2) or else Max > Two**(Emax / 4) then M_Exp := Real'Exponent (Max); Scale := Two ** (-M_Exp); Un_Scale := Two ** ( M_Exp); else Scale := One; Un_Scale := One; end if; Row_Sums(Starting_Col) := Abs A(Row_Id, Starting_Col); if Ending_Col > Starting_Col then Compensated_Sum: declare Term, Sum_tmp, Err, Sum : Real := Zero; begin for c in Starting_Col .. Ending_Col loop Term := (Scale * A(Row_Id, c)) ** 2; Term := Term - Err; -- correction to Term, next term in sum. Sum_tmp := Sum + Term; -- now increment Sum Err := (Sum_tmp - Sum) - Term; Sum := Sum_tmp; Row_Sums(c) := Un_Scale * Sqrt (Sum); end loop; end Compensated_Sum; end if; end Get_Sqrt_of_Sum_of_Sqrs_of_Row; Row_Sums : Row := (others => Zero); type Int64 is range -2**63+1 .. 2**63-1; Matrix_Size : constant Int64 := Int64 (Final_Col)-Int64 (Starting_Col)+1; Pivot_Col : C_Index; begin if Matrix_Size < 4 then return; end if; -- already tridiagonalized. Q := Initial_Q; for Pivot_Row in Starting_Col .. Final_Col-2 loop Pivot_Col := Pivot_Row + 1; Get_Sqrt_of_Sum_of_Sqrs_of_Row (Row_Id => Pivot_Row, Starting_Col => Pivot_Col, Ending_Col => Final_Col, Row_Sums => Row_Sums); for Hi_Col in Pivot_Col+1 .. Final_Col loop Rotate_to_Kill_Element_Hi_of_pRow -- zero out A(Pivot_Row, Hi_Col) (pRow => Pivot_Row, Hi_Col => Hi_Col, -- Hi = high to eye; its id is lower than Lo_Row. Lo_Col => Pivot_Col); A(Pivot_Row, Hi_Col) := Zero; A(Hi_Col, Pivot_Row) := Zero; A(Pivot_Row, Pivot_Col) := Real'Copy_Sign (Row_Sums(Hi_Col), A(Pivot_Row, Pivot_Col)); A(Pivot_Col, Pivot_Row) := A(Pivot_Row, Pivot_Col); end loop; -- over Hi_Col end loop; -- over Pivot_Col; max val of Pivot_Col is Final_Col-1 end Tridiagonalize; end Tridiagonal;
-- Abstract : -- -- Syntax tree type and operations. -- -- Design : -- -- There is one syntax tree for each parallel parser. There is one -- shared Terminals array (provided by the master parser), matching -- the actual input text. -- -- Node contains a Parent component, to make it easy to traverse the -- tree in any direction. However, we do not set the Parent nodes -- while parsing, to simplify branching the syntax tree for parallel -- parsing. When a new nonterm is added to a branched tree, if it set -- the parent component of its children, it would first have to move -- those children, and all intervening nodes, into the branched tree. -- Since Shared_Terminals nodes are created before all other nodes -- (when the lexer is run, to allow Lexer_To_Augmented to store info -- in the node), that would mean every branched tree is a practically -- complete copy of the entire tree, significantly slowing down -- parsing (by a factor of 250 on ada-mode wisi.adb when we did this -- by mistake!). -- -- The parent components are set by Set_Parents, which is called by -- Parser.Execute_Actions before the actions are executed. -- Fortunately, we don't need the parent components during error -- recover. After calling Set_Parents (ie, while editing the syntax -- tree after parse), any functions that modify children or parents -- update the corresponding links, setting them to Invalid_Node_Index -- or Deleted_Child as appropriate. -- -- We provide Base_Tree and Tree in one package, because only Tree -- needs an API; the only way Base_Tree is accessed is via Tree. -- -- Base_Tree and Tree are not limited to allow -- wisitoken-parse-lr-parser_lists.ads Prepend_Copy to copy them. No -- Adjust is needed; Shared_Tree is shared between parsers, and -- Augmented pointers are also shared, since during parse they are -- set only for Shared_Terminals. -- -- Copyright (C) 2018 - 2020 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); with Ada.Finalization; with SAL.Gen_Unbounded_Definite_Vectors; with WisiToken.Lexer; package WisiToken.Syntax_Trees is type Base_Tree is new Ada.Finalization.Controlled with private; type Base_Tree_Access is access all Base_Tree; overriding procedure Finalize (Tree : in out Base_Tree); -- Free any allocated storage. function Is_Empty (Tree : in Base_Tree) return Boolean; type Tree is new Ada.Finalization.Controlled with private; type Tree_Variable_Reference (Element : not null access Tree) is null record with Implicit_Dereference => Element; type Tree_Constant_Reference (Element : not null access constant Tree) is null record with Implicit_Dereference => Element; function Is_Empty (Tree : in Syntax_Trees.Tree) return Boolean; procedure Initialize (Branched_Tree : in out Tree; Shared_Tree : in Base_Tree_Access; Flush : in Boolean; Set_Parents : in Boolean := False) with Pre => Branched_Tree.Is_Empty and Shared_Tree.Is_Empty; -- Set Branched_Tree to refer to Shared_Tree. overriding procedure Finalize (Tree : in out Syntax_Trees.Tree); -- Free any allocated storage. type Node_Label is (Shared_Terminal, -- text is user input, accessed via Parser.Terminals Virtual_Terminal, -- no text; inserted during error recovery Virtual_Identifier, -- text in user data, created during tree rewrite Nonterm -- contains terminals/nonterminals/identifiers ); type User_Data_Type is tagged limited null record; -- Many test languages don't need this, so we default the procedures -- to null. type User_Data_Access is access all User_Data_Type'Class; procedure Set_Lexer_Terminals (User_Data : in out User_Data_Type; Lexer : in WisiToken.Lexer.Handle; Terminals : in Base_Token_Array_Access_Constant) is null; procedure Reset (User_Data : in out User_Data_Type) is null; -- Reset to start a new parse. procedure Initialize_Actions (User_Data : in out User_Data_Type; Tree : in Syntax_Trees.Tree'Class) is null; -- Called by Execute_Actions, before processing the tree. procedure Lexer_To_Augmented (User_Data : in out User_Data_Type; Tree : in out Syntax_Trees.Tree'Class; Token : in Base_Token; Lexer : not null access WisiToken.Lexer.Instance'Class) is null; -- Read auxiliary data from Lexer, do something useful with it. -- Called before parsing, once for each token in the input stream. If -- Token is a grammar token, client can use Tree.Set_Augmented -- (Token.Tree_Node). function Insert_After (User_Data : in out User_Data_Type; Tree : in Syntax_Trees.Tree'Class; Token : in Valid_Node_Index; Insert_On_Blank_Line : in Boolean) return Boolean; -- Return True if ID should be treated as if inserted after the -- previous shared terminal, rather than before the next (which is -- the default). This can affect which line it appears on, which -- affects indentation. Called from Insert_Token. -- -- The default implementation always returns False. procedure Insert_Token (User_Data : in out User_Data_Type; Tree : in out Syntax_Trees.Tree'Class; Token : in Valid_Node_Index) is null; -- Token was inserted in error recovery; update other tokens and Tree -- as needed. Called from Execute_Actions for each inserted token, -- before processing the syntax tree. procedure Delete_Token (User_Data : in out User_Data_Type; Tree : in out Syntax_Trees.Tree'Class; Token_Index : in WisiToken.Token_Index) is null; -- Token at Token_Index was deleted in error recovery; update -- remaining tokens as needed. Called from Execute_Actions for each -- deleted token, before processing the syntax tree. procedure Reduce (User_Data : in out User_Data_Type; Tree : in out Syntax_Trees.Tree'Class; Nonterm : in Valid_Node_Index; Tokens : in Valid_Node_Index_Array) is null; -- Reduce Tokens to Nonterm. Nonterm.Byte_Region is computed by -- caller. type Semantic_Action is access procedure (User_Data : in out User_Data_Type'Class; Tree : in out Syntax_Trees.Tree; Nonterm : in Valid_Node_Index; Tokens : in Valid_Node_Index_Array); -- Routines of this type are called by -- WisiToken.LR.Parser.Execute_Actions when it processes a Nonterm -- node in the syntax tree. Tokens are the children of Nonterm. Null_Action : constant Semantic_Action := null; procedure Clear (Tree : in out Syntax_Trees.Base_Tree); procedure Clear (Tree : in out Syntax_Trees.Tree); -- Delete all Elements and free associated memory; keep results of -- Initialize. procedure Flush (Tree : in out Syntax_Trees.Tree); -- Move all nodes in branched part to shared tree, set Flush mode -- True. procedure Set_Flush_False (Tree : in out Syntax_Trees.Tree); -- Set Flush mode False; use Flush to set True. function Flushed (Tree : in Syntax_Trees.Tree) return Boolean; function Copy_Subtree (Tree : in out Syntax_Trees.Tree; Root : in Valid_Node_Index) return Valid_Node_Index with Pre => Tree.Flushed and Tree.Parents_Set; -- Deep copy (into Tree) subtree of Tree rooted at Root. Return root -- of new subtree; it has no parent. -- -- Parents of new child nodes are set. Node index order is preserved. -- References to objects external to tree are shallow copied -- (Terminals, Augmented, Action). function Add_Nonterm (Tree : in out Syntax_Trees.Tree; Production : in Production_ID; Children : in Valid_Node_Index_Array; Action : in Semantic_Action := null; Default_Virtual : in Boolean := False) return Valid_Node_Index with Pre => not Tree.Traversing and (for all C of Children => C /= Deleted_Child); -- Add a new Nonterm node, which can be empty. Result points to the -- added node. If Children'Length = 0, set Nonterm.Virtual := -- Default_Virtual. -- -- If Tree.Parents_Set, then Children.Parent are set to the new node, -- and in previous parents of those children (if any), the -- corresponding entry in Children is set to Deleted_Child. function Add_Terminal (Tree : in out Syntax_Trees.Tree; Terminal : in Token_Index; Terminals : in Base_Token_Arrays.Vector) return Valid_Node_Index with Pre => not Tree.Traversing; -- Add a new Terminal node. Terminal must be an index into Terminals. -- Result points to the added node. function Add_Terminal (Tree : in out Syntax_Trees.Tree; Terminal : in Token_ID; Before : in Base_Token_Index := Invalid_Token_Index) return Valid_Node_Index with Pre => not Tree.Traversing; -- Add a new Virtual_Terminal node with no parent. Before is the -- index of the terminal in Terminals that this virtual is inserted -- before during error correction; if Invalid_Token_Index, it is -- inserted during EBNF translation, and there is no such terminal. -- Result points to the added node. function Before (Tree : in Syntax_Trees.Tree; Virtual_Terminal : in Valid_Node_Index) return Base_Token_Index with Pre => Tree.Is_Virtual_Terminal (Virtual_Terminal); function Add_Identifier (Tree : in out Syntax_Trees.Tree; ID : in Token_ID; Identifier : in Identifier_Index; Byte_Region : in WisiToken.Buffer_Region) return Valid_Node_Index with Pre => Tree.Flushed and (not Tree.Traversing); -- Add a new Virtual_Identifier node with no parent. Byte_Region -- should point to an area in the source buffer related to the new -- identifier, to aid debugging. Result points to the added node. procedure Add_Child (Tree : in out Syntax_Trees.Tree; Parent : in Valid_Node_Index; Child : in Valid_Node_Index) with Pre => Tree.Flushed and Tree.Parents_Set and (not Tree.Traversing) and Tree.Is_Nonterm (Parent); -- Sets Child.Parent. function Child_Index (Tree : in out Syntax_Trees.Tree; Parent : in Valid_Node_Index; Child : in Valid_Node_Index) return SAL.Peek_Type with Pre => Tree.Has_Child (Parent, Child); procedure Replace_Child (Tree : in out Syntax_Trees.Tree; Parent : in Valid_Node_Index; Child_Index : in SAL.Peek_Type; Old_Child : in Valid_Node_Index; New_Child : in Valid_Node_Index; Old_Child_New_Parent : in Node_Index := Invalid_Node_Index) with Pre => Tree.Flushed and Tree.Parents_Set and (not Tree.Traversing) and (Tree.Is_Nonterm (Parent) and then (Tree.Child (Parent, Child_Index) = Old_Child and (Old_Child = Deleted_Child or else Tree.Parent (Old_Child) = Parent))); -- In Parent.Children, replace child at Child_Index with New_Child. -- Unless Old_Child is Deleted_Child, set Old_Child.Parent to -- Old_Child_New_Parent (may be Invalid_Node_Index). Unless New_Child -- is Deleted_Child, set New_Child.Parent to Parent. -- -- If Old_Child is Deleted_Child, Old_Child_New_Parent should be left -- to default. procedure Set_Children (Tree : in out Syntax_Trees.Tree; Node : in Valid_Node_Index; New_ID : in WisiToken.Production_ID; Children : in Valid_Node_Index_Array) with Pre => Tree.Flushed and Tree.Parents_Set and (not Tree.Traversing) and Tree.Is_Nonterm (Node) and (for all C of Children => C /= Deleted_Child); -- If parents of current Node.Children are not Invalid_Node_Index, -- set corresponding entry in those parents to Deleted_Child, then -- set Parent to Invalid_Node_Index. -- -- Then set ID of Node to New_ID, and Node.Children to Children; set -- parents of Children to Node. -- -- If New_ID /= Tree.Production_ID (Node), Node.Action is set -- to null, because the old Action probably no longer applies. procedure Delete_Parent (Tree : in out Syntax_Trees.Tree; Node : in Valid_Node_Index) with Pre => Tree.Flushed and Tree.Parents_Set and (not Tree.Traversing) and Tree.Parent (Node) /= Invalid_Node_Index; -- Set child in Node.Parent to Deleted_Child. If Node.Parent = -- Tree.Root, set Tree.Root to Node. Set Node.Parent to -- Invalid_Node_Index. procedure Set_Node_Identifier (Tree : in Syntax_Trees.Tree; Node : in Valid_Node_Index; ID : in Token_ID; Identifier : in Identifier_Index) with Pre => Tree.Flushed and Tree.Parents_Set and (not Tree.Traversing) and Tree.Is_Nonterm (Node); -- Set parents of current Node.Children to Invalid_Node_Index. -- Then change Node to a Virtual_Identifier. procedure Set_State (Tree : in out Syntax_Trees.Tree; Node : in Valid_Node_Index; State : in State_Index); function State (Tree : in Syntax_Trees.Tree; Node : in Valid_Node_Index) return Unknown_State_Index; function Label (Tree : in Syntax_Trees.Tree; Node : in Valid_Node_Index) return Node_Label; function Child_Count (Tree : in Syntax_Trees.Tree; Node : in Valid_Node_Index) return Ada.Containers.Count_Type with Pre => Tree.Is_Nonterm (Node); function Children (Tree : in Syntax_Trees.Tree; Node : in Valid_Node_Index) return Valid_Node_Index_Array with Pre => Tree.Is_Nonterm (Node); -- Any children that were cleared by Add_Nonterm are returned as -- Deleted_Child. function Child (Tree : in Syntax_Trees.Tree; Node : in Valid_Node_Index; Child_Index : in Positive_Index_Type) return Node_Index with Pre => Tree.Is_Nonterm (Node); function Has_Branched_Nodes (Tree : in Syntax_Trees.Tree) return Boolean; function Has_Children (Tree : in Syntax_Trees.Tree; Node : in Valid_Node_Index) return Boolean with Pre => Tree.Is_Nonterm (Node); function Has_Child (Tree : in Syntax_Trees.Tree; Node : in Valid_Node_Index; Child : in Valid_Node_Index) return Boolean with Pre => Tree.Is_Nonterm (Node); function Has_Parent (Tree : in Syntax_Trees.Tree; Child : in Valid_Node_Index) return Boolean; function Has_Parent (Tree : in Syntax_Trees.Tree; Children : in Valid_Node_Index_Array) return Boolean; function Buffer_Region_Is_Empty (Tree : in Syntax_Trees.Tree; Node : in Valid_Node_Index) return Boolean; -- True if contained buffer region is empty; always the case for -- virtual tokens, and for most copied tokens. Use Has_Children or -- Child_Count to see if Node has children. function Is_Nonterm (Tree : in Syntax_Trees.Tree; Node : in Valid_Node_Index) return Boolean; function Is_Shared_Terminal (Tree : in Syntax_Trees.Tree; Node : in Valid_Node_Index) return Boolean; function Is_Virtual_Terminal (Tree : in Syntax_Trees.Tree; Node : in Valid_Node_Index) return Boolean; function Is_Virtual (Tree : in Syntax_Trees.Tree; Node : in Valid_Node_Index) return Boolean; -- Virtual_Terminal, Virtual_Identifier, or Nonterm that contains some Virtual tokens. function Is_Virtual_Identifier (Tree : in Syntax_Trees.Tree; Node : in Valid_Node_Index) return Boolean; function Traversing (Tree : in Syntax_Trees.Tree) return Boolean; function Parents_Set (Tree : in Syntax_Trees.Tree) return Boolean; procedure Set_Parents (Tree : in out Syntax_Trees.Tree) with Pre => Tree.Flushed and Tree.Root /= Invalid_Node_Index; function Parent (Tree : in Syntax_Trees.Tree; Node : in Valid_Node_Index; Count : in Positive := 1) return Node_Index with Pre => Tree.Parents_Set; -- Return Count parent of Node. procedure Set_Name_Region (Tree : in out Syntax_Trees.Tree; Node : in Valid_Node_Index; Region : in Buffer_Region) with Pre => Tree.Is_Nonterm (Node); function ID (Tree : in Syntax_Trees.Tree; Node : in Valid_Node_Index) return WisiToken.Token_ID; function Production_ID (Tree : in Syntax_Trees.Tree; Node : in Valid_Node_Index) return WisiToken.Production_ID with Pre => Tree.Is_Nonterm (Node); function Byte_Region (Tree : in Syntax_Trees.Tree; Node : in Valid_Node_Index) return WisiToken.Buffer_Region; function RHS_Index (Tree : in Syntax_Trees.Tree; Node : in Valid_Node_Index) return Natural with Pre => Tree.Is_Nonterm (Node); function Same_Token (Tree_1 : in Syntax_Trees.Tree'Class; Index_1 : in Valid_Node_Index; Tree_2 : in Syntax_Trees.Tree'Class; Index_2 : in Valid_Node_Index) return Boolean; -- True if the two tokens have the same ID and Byte_Region. function Recover_Token (Tree : in Syntax_Trees.Tree; Node : in Valid_Node_Index) return WisiToken.Recover_Token; function Recover_Token_Array (Tree : in Syntax_Trees.Tree; Nodes : in Valid_Node_Index_Array) return WisiToken.Recover_Token_Array; procedure Set_Augmented (Tree : in out Syntax_Trees.Tree; Node : in Valid_Node_Index; Value : in Base_Token_Class_Access); -- Value will be deallocated when Tree is finalized. function Augmented (Tree : in Syntax_Trees.Tree; Node : in Valid_Node_Index) return Base_Token_Class_Access; -- Returns result of Set_Augmented. function Augmented_Const (Tree : in Syntax_Trees.Tree; Node : in Valid_Node_Index) return Base_Token_Class_Access_Constant; function Action (Tree : in Syntax_Trees.Tree; Node : in Valid_Node_Index) return Semantic_Action with Pre => Tree.Is_Nonterm (Node); function Find_Ancestor (Tree : in Syntax_Trees.Tree; Node : in Valid_Node_Index; ID : in Token_ID; Max_Parent : in Boolean := False) return Node_Index with Pre => Tree.Parents_Set; function Find_Ancestor (Tree : in Syntax_Trees.Tree; Node : in Valid_Node_Index; IDs : in Token_ID_Array; Max_Parent : in Boolean := False) return Node_Index with Pre => Tree.Parents_Set; -- Return the ancestor of Node that contains ID (starting search with -- Node.Parent), or Invalid_Node_Index if none match. -- -- If Max_Parent, return max parent found if none match; this will be -- Invalid_Node_Index if Node has no parent. function Find_Sibling (Tree : in Syntax_Trees.Tree; Node : in Valid_Node_Index; ID : in Token_ID) return Node_Index with Pre => Tree.Parents_Set and then Tree.Has_Parent (Node); -- Return the sibling of Node that contains ID, or Invalid_Node_Index if -- none match. function Find_Child (Tree : in Syntax_Trees.Tree; Node : in Valid_Node_Index; ID : in Token_ID) return Node_Index with Pre => Tree.Is_Nonterm (Node); -- Return the child of Node whose ID is ID, or Invalid_Node_Index if -- none match. function Find_Descendant (Tree : in Syntax_Trees.Tree; Node : in Valid_Node_Index; ID : in Token_ID) return Node_Index; -- Return the descendant of Node (may be Node) whose ID is ID, or -- Invalid_Node_Index if none match. function Find_Descendant (Tree : in Syntax_Trees.Tree; Node : in Valid_Node_Index; Predicate : access function (Tree : in Syntax_Trees.Tree; Node : in Valid_Node_Index) return Boolean) return Node_Index; -- Return the descendant of Node (may be Node) for which Predicate -- returns True, or Invalid_Node_Index if none do. function Is_Descendant_Of (Tree : in Syntax_Trees.Tree; Root : in Valid_Node_Index; Descendant : in Valid_Node_Index) return Boolean with Pre => Tree.Parents_Set and Tree.Is_Nonterm (Root); procedure Set_Root (Tree : in out Syntax_Trees.Tree; Root : in Valid_Node_Index); function Root (Tree : in Syntax_Trees.Tree) return Node_Index; -- Return value set by Set_Root. -- returns Invalid_Node_Index if Tree is empty. function Sub_Tree_Root (Tree : in Syntax_Trees.Tree; Node : in Valid_Node_Index) return Valid_Node_Index with Pre => Tree.Parents_Set; -- Return top ancestor of Node. procedure Process_Tree (Tree : in out Syntax_Trees.Tree; Process_Node : access procedure (Tree : in out Syntax_Trees.Tree; Node : in Valid_Node_Index); Root : in Node_Index := Invalid_Node_Index) with Pre => Root /= Invalid_Node_Index or Tree.Root /= Invalid_Node_Index; -- Traverse subtree of Tree rooted at Root (default Tree.Root) in -- depth-first order, calling Process_Node on each node. function Identifier (Tree : in Syntax_Trees.Tree; Node : in Valid_Node_Index) return Base_Identifier_Index with Pre => Tree.Is_Virtual_Identifier (Node); function Terminal (Tree : in Syntax_Trees.Tree; Node : in Valid_Node_Index) return Base_Token_Index with Pre => Tree.Is_Shared_Terminal (Node); function First_Shared_Terminal (Tree : in Syntax_Trees.Tree; Node : in Valid_Node_Index) return Base_Token_Index; -- Returns first shared terminal in subtree under Node -- (ignoring virtual terminals). If result is Invalid_Token_Index, -- all terminals are virtual, or a nonterm is empty. function Last_Shared_Terminal (Tree : in Syntax_Trees.Tree; Node : in Valid_Node_Index) return Base_Token_Index; -- Returns last shared terminal in subtree under Node (ignoring -- virtual terminals). If result is Invalid_Token_Index, all -- terminals are virtual, or a nonterm is empty. function Get_Terminals (Tree : in Syntax_Trees.Tree; Node : in Valid_Node_Index) return Valid_Node_Index_Array; -- Return sequence of terminals in Node. -- -- "Terminals" can be Shared_Terminal, Virtual_Terminal, -- Virtual_Identifier. function First_Terminal (Tree : in Syntax_Trees.Tree; Node : in Valid_Node_Index) return Node_Index; -- First of Get_Terminals. Invalid_Node_Index if Node is an empty nonterminal. function Last_Terminal (Tree : in Syntax_Trees.Tree; Node : in Valid_Node_Index) return Node_Index; -- Last of Get_Terminals. Invalid_Node_Index if Node is an empty nonterminal. function Prev_Terminal (Tree : in Syntax_Trees.Tree; Node : in Valid_Node_Index) return Node_Index with Pre => Tree.Parents_Set and Tree.Label (Node) in Shared_Terminal | Virtual_Terminal | Virtual_Identifier; -- Return the terminal that is immediately before Node in Tree; -- Invalid_Node_Index if Node is the first terminal in Tree. function Next_Terminal (Tree : in Syntax_Trees.Tree; Node : in Valid_Node_Index) return Node_Index with Pre => Tree.Parents_Set and Tree.Label (Node) in Shared_Terminal | Virtual_Terminal | Virtual_Identifier; -- Return the terminal that is immediately after Node in Tree; -- Invalid_Node_Index if Node is the last terminal in Tree. function Get_Terminal_IDs (Tree : in Syntax_Trees.Tree; Node : in Valid_Node_Index) return Token_ID_Array; -- Same as Get_Terminals, but return the IDs. function First_Terminal_ID (Tree : in Syntax_Trees.Tree; Node : in Valid_Node_Index) return Token_ID; -- First of Get_Terminal_IDs; Invalid_Token_ID if Node is empty. function Get_IDs (Tree : in Syntax_Trees.Tree; Node : in Valid_Node_Index; ID : in Token_ID) return Valid_Node_Index_Array; -- Return all descendants of Node matching ID. function Image (Tree : in Syntax_Trees.Tree; Node : in Valid_Node_Index; Descriptor : in WisiToken.Descriptor; Include_Children : in Boolean := False; Include_RHS_Index : in Boolean := False; Node_Numbers : in Boolean := False) return String; function Image (Tree : in Syntax_Trees.Tree; Nodes : in Valid_Node_Index_Array; Descriptor : in WisiToken.Descriptor) return String; -- For debug and error messages. function First_Index (Tree : in Syntax_Trees.Tree) return Node_Index; function Last_Index (Tree : in Syntax_Trees.Tree) return Node_Index; package Node_Sets is new SAL.Gen_Unbounded_Definite_Vectors (Valid_Node_Index, Boolean, Default_Element => False); function Image (Item : in Node_Sets.Vector; Inverted : in Boolean := False) return String; -- Simple list of numbers, for debugging function Error_Message (Tree : in Syntax_Trees.Tree; Terminals : in Base_Token_Array_Access_Constant; Node : in Valid_Node_Index; File_Name : in String; Message : in String) return String; -- Get Line, column from Node. type Validate_Node is access procedure (Tree : in Syntax_Trees.Tree; Node : in Valid_Node_Index; Node_Image_Output : in out Boolean); -- Called by Validate_Tree for each node visited; perform other -- checks, output to Text_IO.Current_Error. If Node_Image_Output is -- False, output Image (Tree, Node, Descriptor, Node_Numbers => True) once -- before any error messages. procedure Validate_Tree (Tree : in out Syntax_Trees.Tree; Terminals : in Base_Token_Array_Access_Constant; Descriptor : in WisiToken.Descriptor; File_Name : in String; Root : in Node_Index := Invalid_Node_Index; Validate_Node : in Syntax_Trees.Validate_Node := null) with Pre => Tree.Flushed and Tree.Parents_Set; -- Verify child/parent links, and that no children are Deleted_Child. -- Violations output a message to Text_IO.Current_Error. type Image_Augmented is access function (Aug : in Base_Token_Class_Access) return String; type Image_Action is access function (Action : in Semantic_Action) return String; procedure Print_Tree (Tree : in Syntax_Trees.Tree; Descriptor : in WisiToken.Descriptor; Root : in Node_Index := Invalid_Node_Index; Image_Augmented : in Syntax_Trees.Image_Augmented := null; Image_Action : in Syntax_Trees.Image_Action := null) with Pre => Tree.Flushed; -- Print tree rooted at Root (default Tree.Root) to -- Text_IO.Current_Output, for debugging. For each node, -- Image_Augmented is called if it is not null and node.augmented is -- not null. private use all type Ada.Containers.Count_Type; type Node (Label : Node_Label := Virtual_Terminal) is -- Label has a default to allow changing the label during tree editing. record ID : WisiToken.Token_ID := Invalid_Token_ID; Byte_Region : Buffer_Region := Null_Buffer_Region; -- Computed by Set_Children, used in Semantic_Check actions and debug -- messages. Parent : Node_Index := Invalid_Node_Index; State : Unknown_State_Index := Unknown_State; -- Parse state that was on stack with this token, to allow undoing a -- reduce. Augmented : Base_Token_Class_Access := null; case Label is when Shared_Terminal => Terminal : Token_Index; -- into Parser.Terminals when Virtual_Terminal => Before : Base_Token_Index := Invalid_Token_Index; -- into Parser.Terminals when Virtual_Identifier => Identifier : Identifier_Index; -- into user data when Nonterm => Virtual : Boolean := False; -- True if any child node is Virtual_Terminal or Nonterm with Virtual -- set. Used by Semantic_Check actions. RHS_Index : Natural; -- With ID, index into Productions. -- Used for debug output, keep for future use. Action : Semantic_Action := null; Name : Buffer_Region := Null_Buffer_Region; -- Name is set and checked by Semantic_Check actions. Children : Valid_Node_Index_Arrays.Vector; Min_Terminal_Index : Base_Token_Index := Invalid_Token_Index; -- Cached for push_back of nonterminals during recovery end case; end record; subtype Nonterm_Node is Node (Nonterm); package Node_Arrays is new SAL.Gen_Unbounded_Definite_Vectors (Valid_Node_Index, Node, Default_Element => (others => <>)); type Base_Tree is new Ada.Finalization.Controlled with record Nodes : Node_Arrays.Vector; -- During normal parsing, tokens are added to Nodes by "parallel" -- LALR parsers, but they are all run from one Ada task, so there's -- no need for Nodes to be Protected. Packrat parsing also has a -- single Ada task. -- -- During McKenzie_Recover, which has multiple Ada tasks, the syntax -- tree is read but not modified. Augmented_Present : Boolean := False; -- True if Set_Augmented has been called on any node. Declared in -- Base_Tree so it can be checked by Finalize (Base_Tree) and -- Finalize (Tree). Traversing : Boolean := False; -- True while traversing tree in Process_Tree. -- Declared in Base_Tree so it is cleared by Finalize. Parents_Set : Boolean := False; -- We don't set Node.Parent until after parse is done; see Design -- note above. end record; function Is_Empty (Tree : in Base_Tree) return Boolean is (Tree.Nodes.Length = 0); type Tree is new Ada.Finalization.Controlled with record Shared_Tree : Base_Tree_Access; -- If we need to set anything (ie parent) in Shared_Tree, we move the -- branch point instead, unless Flush = True. Last_Shared_Node : Node_Index := Invalid_Node_Index; Branched_Nodes : Node_Arrays.Vector; Flush : Boolean := False; -- If Flush is True, all nodes are in Shared_Tree. Otherwise, all -- greater than Last_Shared_Node are in Branched_Nodes. -- -- We maintain Last_Shared_Node when Flush is True or False, so -- subprograms that have no reason to check Flush can rely on -- Last_Shared_Node. Root : Node_Index := Invalid_Node_Index; end record with Type_Invariant => (Shared_Tree = null or else (if Tree.Flush then Last_Shared_Node = Shared_Tree.Nodes.Last_Index and Branched_Nodes.Length = 0 else Last_Shared_Node <= Shared_Tree.Nodes.Last_Index and Last_Shared_Node < Branched_Nodes.First_Index)); subtype Node_Const_Ref is Node_Arrays.Constant_Reference_Type; subtype Node_Var_Ref is Node_Arrays.Variable_Reference_Type; function Get_Node_Const_Ref (Tree : in Syntax_Trees.Tree; Node : in Valid_Node_Index) return Node_Const_Ref is (if Node <= Tree.Last_Shared_Node then Tree.Shared_Tree.Nodes.Constant_Ref (Node) else Tree.Branched_Nodes.Constant_Ref (Node)); function Get_Node_Var_Ref (Tree : in Syntax_Trees.Tree; Node : in Valid_Node_Index) return Node_Var_Ref is (if Node <= Tree.Last_Shared_Node then Tree.Shared_Tree.Nodes.Variable_Ref (Node) else Tree.Branched_Nodes.Variable_Ref (Node)); function Is_Empty (Tree : in Syntax_Trees.Tree) return Boolean is (Tree.Branched_Nodes.Length = 0 and (Tree.Shared_Tree = null or else Tree.Shared_Tree.Is_Empty)); function Parents_Set (Tree : in Syntax_Trees.Tree) return Boolean is (Tree.Shared_Tree.Parents_Set); end WisiToken.Syntax_Trees;
-------------------------------------------------------------------------------------------------------------------- -- Copyright (c) 2013-2020, Luke A. Guest -- -- This software is provided 'as-is', without any express or implied -- warranty. In no event will the authors be held liable for any damages -- arising from the use of this software. -- -- Permission is granted to anyone to use this software for any purpose, -- including commercial applications, and to alter it and redistribute it -- freely, subject to the following restrictions: -- -- 1. The origin of this software must not be misrepresented; you must not -- claim that you wrote the original software. If you use this software -- in a product, an acknowledgment in the product documentation would be -- appreciated but is not required. -- -- 2. Altered source versions must be plainly marked as such, and must not be -- misrepresented as being the original software. -- -- 3. This notice may not be removed or altered from any source -- distribution. -------------------------------------------------------------------------------------------------------------------- with Interfaces.C.Strings; with SDL; with SDL.Error; with SDL.Video.Windows; package body SDL.Clipboard is package C renames Interfaces.C; use type C.int; procedure Check_For_Window is Init_Value : constant SDL.Init_Flags := SDL.Was_Initialised and SDL.Enable_Screen; begin if Init_Value /= SDL.Enable_Screen then raise Clipboard_Error with "SDL screen subsystem has not been initialised."; end if; if SDL.Video.Windows.Exist = False then raise Clipboard_Error with "No windows have been created."; end if; end Check_For_Window; function Get return Ada.Strings.UTF_Encoding.UTF_8_String is function SDL_Get_Clipboard_Text return C.Strings.chars_ptr with Import => True, Convention => C, External_Name => "SDL_GetClipboardText"; begin Check_For_Window; return C.Strings.Value (SDL_Get_Clipboard_Text); end Get; function Is_Empty return Boolean is function SDL_Has_Clipboard_Text return SDL_Bool with Import => True, Convention => C, External_Name => "SDL_HasClipboardText"; begin Check_For_Window; return (if SDL_Has_Clipboard_Text = SDL_True then False else True); end Is_Empty; procedure Set (Text : in Ada.Strings.UTF_Encoding.UTF_8_String) is function SDL_Set_Clipboard_Text (C_Str : in C.char_array) return C.int with Import => True, Convention => C, External_Name => "SDL_SetClipboardText"; begin Check_For_Window; if SDL_Set_Clipboard_Text (C.To_C (Text)) /= Success then raise Clipboard_Error with SDL.Error.Get; end if; end Set; end SDL.Clipboard;
with OpenAL.Thin; with OpenAL.ALC_Thin; package body OpenAL.Extension.EFX is -- -- Auxiliary_Effect_Slot_Is_Valid -- function Auxiliary_Effect_Slot_Is_Valid (Extension : in Extension_t; Slot : in Auxiliary_Effect_Slot_t) return Boolean is begin Check_Loaded (Extension); return Boolean (Extension.API.Is_Auxiliary_Effect_Slot (Types.Unsigned_Integer_t (Slot))); end Auxiliary_Effect_Slot_Is_Valid; -- -- Check_Loaded -- use type Context.Context_t; procedure Check_Loaded (Extension : in Extension_t) is begin if Extension.Loaded = False then raise Program_Error with "extension not loaded"; end if; if Extension.Owner_Context /= Context.Get_Current_Context then raise Program_Error with "extension was not loaded in the current context"; end if; end Check_Loaded; -- -- Delete_* -- procedure Delete_Auxiliary_Effect_Slots (Extension : in Extension_t; Slots : in Auxiliary_Effect_Slot_Array_t) is begin Check_Loaded (Extension); Extension.API.Delete_Auxiliary_Effect_Slots (Size => Slots'Length, Slots => Slots (Slots'First)'Address); end Delete_Auxiliary_Effect_Slots; procedure Delete_Effects (Extension : in Extension_t; Effects : in Effect_Array_t) is begin Check_Loaded (Extension); Extension.API.Delete_Effects (Size => Effects'Length, Effects => Effects (Effects'First)'Address); end Delete_Effects; procedure Delete_Filters (Extension : in Extension_t; Filters : in Filter_Array_t) is begin Check_Loaded (Extension); Extension.API.Delete_Filters (Size => Filters'Length, Filters => Filters (Filters'First)'Address); end Delete_Filters; -- -- Effect_Is_Valid -- function Effect_Is_Valid (Extension : in Extension_t; Effect : in Effect_t) return Boolean is begin Check_Loaded (Extension); return Boolean (Extension.API.Is_Effect (Types.Unsigned_Integer_t (Effect))); end Effect_Is_Valid; -- -- Filter_Is_Valid -- function Filter_Is_Valid (Extension : in Extension_t; Filter : in Filter_t) return Boolean is begin Check_Loaded (Extension); return Boolean (Extension.API.Is_Filter (Types.Unsigned_Integer_t (Filter))); end Filter_Is_Valid; -- -- Generate_* -- procedure Generate_Auxiliary_Effect_Slots (Extension : in Extension_t; Slots : in out Auxiliary_Effect_Slot_Array_t) is begin Check_Loaded (Extension); Extension.API.Gen_Auxiliary_Effect_Slots (Size => Slots'Length, Slots => Slots (Slots'First)'Address); end Generate_Auxiliary_Effect_Slots; procedure Generate_Effects (Extension : in Extension_t; Effects : in out Effect_Array_t) is begin Check_Loaded (Extension); Extension.API.Gen_Effects (Size => Effects'Length, Effects => Effects (Effects'First)'Address); end Generate_Effects; procedure Generate_Filters (Extension : in Extension_t; Filters : in out Filter_Array_t) is begin Check_Loaded (Extension); Extension.API.Gen_Filters (Size => Filters'Length, Filters => Filters (Filters'First)'Address); end Generate_Filters; -- -- Get_Effect_Type -- function Get_Effect_Type (Extension : in Extension_t; Effect : in Effect_t) return Effect_Type_t is Effect_Type : aliased Types.Integer_t; begin Check_Loaded (Extension); Extension.API.Get_Effecti (Effect => Types.Unsigned_Integer_t (Effect), Parameter => EFX_Thin.AL_EFFECT_TYPE, Value => Effect_Type'Address); return Map_To_Effect_Type (Effect_Type); end Get_Effect_Type; -- -- Get_Filter_Type -- function Get_Filter_Type (Extension : in Extension_t; Filter : in Filter_t) return Filter_Type_t is Filter_Type : aliased Types.Integer_t; begin Check_Loaded (Extension); Extension.API.Get_Filteri (Filter => Types.Unsigned_Integer_t (Filter), Parameter => EFX_Thin.AL_FILTER_TYPE, Value => Filter_Type'Address); return Map_To_Filter_Type (Filter_Type); end Get_Filter_Type; -- -- Get_Major_Version -- function Get_Major_Version (Extension : in Extension_t) return Natural is Value : aliased Types.Integer_t := 0; begin Check_Loaded (Extension); ALC_Thin.Get_Integerv (Device => Context.Device_Data (Context.Get_Context_Device (Extension.Owner_Context)), Token => EFX_Thin.ALC_EFX_MAJOR_VERSION, Size => 1, Data => Value'Address); return Natural (Value); end Get_Major_Version; -- -- Get_Maximum_Auxiliary_Sends -- function Get_Maximum_Auxiliary_Sends (Extension : in Extension_t) return Source_Auxiliary_Send_t is Value : aliased Types.Integer_t := 0; begin Check_Loaded (Extension); ALC_Thin.Get_Integerv (Device => Context.Device_Data (Context.Get_Context_Device (Extension.Owner_Context)), Token => EFX_Thin.ALC_MAX_AUXILIARY_SENDS, Size => 1, Data => Value'Address); return Source_Auxiliary_Send_t (Value); end Get_Maximum_Auxiliary_Sends; -- -- Get_Minor_Version -- function Get_Minor_Version (Extension : in Extension_t) return Natural is Value : aliased Types.Integer_t := 0; begin Check_Loaded (Extension); ALC_Thin.Get_Integerv (Device => Context.Device_Data (Context.Get_Context_Device (Extension.Owner_Context)), Token => EFX_Thin.ALC_EFX_MAJOR_VERSION, Size => 1, Data => Value'Address); return Natural (Value); end Get_Minor_Version; -- -- Is_Present -- function Is_Present (Device : in Context.Device_t) return Boolean is begin return Context.Is_Extension_Present (Device => Device, Name => "ALC_EXT_EFX"); end Is_Present; -- -- Load_Extension -- function Load_Extension return Extension_t is Current_Context : Context.Context_t; begin Current_Context := Context.Get_Current_Context; if Current_Context = Context.Invalid_Context then raise Program_Error with "no current context"; end if; return Extension_t' (Owner_Context => Current_Context, API => EFX_Thin.Load_API, Loaded => True); end Load_Extension; -- -- Map_To_Effect_Type -- function Map_To_Effect_Type (Effect_Type : in Types.Integer_t) return Effect_Type_t is Value : Effect_Type_t; begin case Effect_Type is when EFX_Thin.AL_EFFECT_NULL => Value := Null_Effect; when EFX_Thin.AL_EFFECT_REVERB => Value := Reverb; when EFX_Thin.AL_EFFECT_CHORUS => Value := Chorus; when EFX_Thin.AL_EFFECT_DISTORTION => Value := Distortion; when EFX_Thin.AL_EFFECT_ECHO => Value := Echo; when EFX_Thin.AL_EFFECT_FLANGER => Value := Flanger; when EFX_Thin.AL_EFFECT_FREQUENCY_SHIFTER => Value := Frequency_Shifter; when EFX_Thin.AL_EFFECT_VOCAL_MORPHER => Value := Vocal_Morpher; when EFX_Thin.AL_EFFECT_PITCH_SHIFTER => Value := Pitch_Shifter; when EFX_Thin.AL_EFFECT_RING_MODULATOR => Value := Ring_Modulator; when EFX_Thin.AL_EFFECT_AUTOWAH => Value := Autowah; when EFX_Thin.AL_EFFECT_COMPRESSOR => Value := Compressor; when EFX_Thin.AL_EFFECT_EQUALIZER => Value := Equalizer; when EFX_Thin.AL_EFFECT_EAXREVERB => Value := EAX_Reverb; when others => Value := Unknown_Effect; end case; return Value; end Map_To_Effect_Type; -- -- Map_To_Filter_Type -- function Map_To_Filter_Type (Filter_Type : in Types.Integer_t) return Filter_Type_t is Value : Filter_Type_t; begin case Filter_Type is when EFX_Thin.AL_FILTER_NULL => Value := Null_Filter; when EFX_Thin.AL_FILTER_LOWPASS => Value := Low_Pass_Filter; when EFX_Thin.AL_FILTER_HIGHPASS => Value := High_Pass_Filter; when EFX_Thin.AL_FILTER_BANDPASS => Value := Band_Pass_Filter; when others => Value := Unknown_Filter; end case; return Value; end Map_To_Filter_Type; -- -- Set_Air_Absorption_Factor -- procedure Set_Air_Absorption_Factor (Extension : in Extension_t; Source : in OpenAL.Source.Source_t; Factor : in Air_Absorption_Factor_t) is begin Check_Loaded (Extension); Thin.Sourcef (Source_ID => OpenAL.Source.To_Integer (Source), Parameter => EFX_Thin.AL_AIR_ABSORPTION_FACTOR, Value => Types.Float_t (Factor)); end Set_Air_Absorption_Factor; -- -- Set_Auxiliary_Effect_Slot_Auto_Send -- procedure Set_Auxiliary_Effect_Slot_Auto_Send (Extension : in Extension_t; Slot : in Auxiliary_Effect_Slot_t; Enable : in Boolean) is begin Check_Loaded (Extension); Extension.API.Auxiliary_Effect_Sloti (Slot => Types.Unsigned_Integer_t (Slot), Parameter => EFX_Thin.AL_EFFECTSLOT_AUXILIARY_SEND_AUTO, Value => Types.Integer_t (Boolean'Pos (Enable))); end Set_Auxiliary_Effect_Slot_Auto_Send; -- -- Set_Auxiliary_Effect_Slot_Effect -- procedure Set_Auxiliary_Effect_Slot_Effect (Extension : in Extension_t; Slot : in Auxiliary_Effect_Slot_t; Effect : in Effect_t) is begin Check_Loaded (Extension); Extension.API.Auxiliary_Effect_Sloti (Slot => Types.Unsigned_Integer_t (Slot), Parameter => EFX_Thin.AL_EFFECTSLOT_EFFECT, Value => Types.Integer_t (Effect)); end Set_Auxiliary_Effect_Slot_Effect; -- -- Set_Auxiliary_Effect_Slot_Gain -- procedure Set_Auxiliary_Effect_Slot_Gain (Extension : in Extension_t; Slot : in Auxiliary_Effect_Slot_t; Gain : in Gain_t) is begin Check_Loaded (Extension); Extension.API.Auxiliary_Effect_Slotf (Slot => Types.Unsigned_Integer_t (Slot), Parameter => EFX_Thin.AL_EFFECTSLOT_GAIN, Value => Gain); end Set_Auxiliary_Effect_Slot_Gain; -- -- Set_Auxiliary_Send_Filter -- procedure Set_Auxiliary_Send_Filter (Extension : in Extension_t; Source : in OpenAL.Source.Source_t; Slot : in Auxiliary_Effect_Slot_t; Source_Send : in Source_Auxiliary_Send_t := 0; Filter : in Filter_t := No_Filter) is begin Check_Loaded (Extension); Thin.Source_3i (Source_ID => OpenAL.Source.To_Integer (Source), Parameter => EFX_Thin.AL_AUXILIARY_SEND_FILTER, Value_1 => Types.Integer_t (Slot), Value_2 => Types.Integer_t (Source_Send), Value_3 => Types.Integer_t (Filter)); end Set_Auxiliary_Send_Filter; -- -- Set_Auxiliary_Send_Filter_Gain_Auto -- procedure Set_Auxiliary_Send_Filter_Gain_Auto (Extension : in Extension_t; Source : in OpenAL.Source.Source_t; Enable : in Boolean) is begin Check_Loaded (Extension); Thin.Sourcei (Source_ID => OpenAL.Source.To_Integer (Source), Parameter => EFX_Thin.AL_AUXILIARY_SEND_FILTER_GAIN_AUTO, Value => Types.Integer_t (Boolean'Pos (Enable))); end Set_Auxiliary_Send_Filter_Gain_Auto; -- -- Set_Auxiliary_Send_Filter_Gain_HF_Auto -- procedure Set_Auxiliary_Send_Filter_Gain_HF_Auto (Extension : in Extension_t; Source : in OpenAL.Source.Source_t; Enable : in Boolean) is begin Check_Loaded (Extension); Thin.Sourcei (Source_ID => OpenAL.Source.To_Integer (Source), Parameter => EFX_Thin.AL_AUXILIARY_SEND_FILTER_GAINHF_AUTO, Value => Types.Integer_t (Boolean'Pos (Enable))); end Set_Auxiliary_Send_Filter_Gain_HF_Auto; -- -- Set_Cone_Outer_Gain_HF -- procedure Set_Cone_Outer_Gain_HF (Extension : in Extension_t; Source : in OpenAL.Source.Source_t; Factor : in Cone_Outer_Gain_HF_Factor_t) is begin Check_Loaded (Extension); Thin.Sourcef (Source_ID => OpenAL.Source.To_Integer (Source), Parameter => EFX_Thin.AL_CONE_OUTER_GAINHF, Value => Types.Float_t (Factor)); end Set_Cone_Outer_Gain_HF; -- -- Set_Direct_Filter -- procedure Set_Direct_Filter (Extension : in Extension_t; Source : in OpenAL.Source.Source_t; Filter : in Filter_t) is begin Check_Loaded (Extension); Thin.Sourcei (Source_ID => OpenAL.Source.To_Integer (Source), Parameter => EFX_Thin.AL_DIRECT_FILTER, Value => Types.Integer_t (Filter)); end Set_Direct_Filter; -- -- Set_Direct_Filter_Gain_HF_Auto -- procedure Set_Direct_Filter_Gain_HF_Auto (Extension : in Extension_t; Source : in OpenAL.Source.Source_t; Enable : in Boolean) is begin Check_Loaded (Extension); Thin.Sourcei (Source_ID => OpenAL.Source.To_Integer (Source), Parameter => EFX_Thin.AL_DIRECT_FILTER_GAINHF_AUTO, Value => Types.Integer_t (Boolean'Pos (Enable))); end Set_Direct_Filter_Gain_HF_Auto; -- -- Set_Effect_Parameter -- type Map_Effect_Parameter_t is array (Effect_Parameter_t) of Types.Enumeration_t; Map_Effect_Parameter : constant Map_Effect_Parameter_t := (Autowah_Attack_Time => EFX_Thin.AL_AUTOWAH_ATTACK_TIME, Autowah_Peak_Gain => EFX_Thin.AL_AUTOWAH_PEAK_GAIN, Autowah_Release_Time => EFX_Thin.AL_AUTOWAH_RELEASE_TIME, Autowah_Resonance => EFX_Thin.AL_AUTOWAH_RESONANCE, Chorus_Delay => EFX_Thin.AL_CHORUS_DELAY, Chorus_Depth => EFX_Thin.AL_CHORUS_DEPTH, Chorus_Feedback => EFX_Thin.AL_CHORUS_FEEDBACK, Chorus_Phase => EFX_Thin.AL_CHORUS_PHASE, Chorus_Rate => EFX_Thin.AL_CHORUS_RATE, Chorus_Waveform => EFX_Thin.AL_CHORUS_WAVEFORM, Distortion_Edge => EFX_Thin.AL_DISTORTION_EDGE, Distortion_EQ_Bandwidth => EFX_Thin.AL_DISTORTION_EQBANDWIDTH, Distortion_EQ_Center => EFX_Thin.AL_DISTORTION_EQCENTER, Distortion_Gain => EFX_Thin.AL_DISTORTION_GAIN, Distortion_Lowpass_Cutoff => EFX_Thin.AL_DISTORTION_LOWPASS_CUTOFF, EAX_Reverb_Air_Absorption_Gain_HF => EFX_Thin.AL_EAXREVERB_AIR_ABSORPTION_GAINHF, EAX_Reverb_Decay_HF_Limit => EFX_Thin.AL_EAXREVERB_DECAY_HFLIMIT, EAX_Reverb_Decay_HF_Ratio => EFX_Thin.AL_EAXREVERB_DECAY_HFRATIO, EAX_Reverb_Decay_LF_Ratio => EFX_Thin.AL_EAXREVERB_DECAY_LFRATIO, EAX_Reverb_Decay_Time => EFX_Thin.AL_EAXREVERB_DECAY_TIME, EAX_Reverb_Density => EFX_Thin.AL_EAXREVERB_DENSITY, EAX_Reverb_Diffusion => EFX_Thin.AL_EAXREVERB_DIFFUSION, EAX_Reverb_Echo_Depth => EFX_Thin.AL_EAXREVERB_ECHO_DEPTH, EAX_Reverb_Echo_Time => EFX_Thin.AL_EAXREVERB_ECHO_TIME, EAX_Reverb_Gain => EFX_Thin.AL_EAXREVERB_GAIN, EAX_Reverb_Gain_HF => EFX_Thin.AL_EAXREVERB_GAINHF, EAX_Reverb_Gain_LF => EFX_Thin.AL_EAXREVERB_GAINLF, EAX_Reverb_HF_Reference => EFX_Thin.AL_EAXREVERB_HFREFERENCE, EAX_Reverb_Late_Reverb_Delay => EFX_Thin.AL_EAXREVERB_LATE_REVERB_DELAY, EAX_Reverb_Late_Reverb_Gain => EFX_Thin.AL_EAXREVERB_LATE_REVERB_GAIN, EAX_Reverb_Late_Reverb_Pan => EFX_Thin.AL_EAXREVERB_LATE_REVERB_PAN, EAX_Reverb_LF_Reference => EFX_Thin.AL_EAXREVERB_LFREFERENCE, EAX_Reverb_Modulation_Depth => EFX_Thin.AL_EAXREVERB_MODULATION_DEPTH, EAX_Reverb_Modulation_Time => EFX_Thin.AL_EAXREVERB_MODULATION_TIME, EAX_Reverb_Reflections_Delay => EFX_Thin.AL_EAXREVERB_REFLECTIONS_DELAY, EAX_Reverb_Reflections_Gain => EFX_Thin.AL_EAXREVERB_REFLECTIONS_GAIN, EAX_Reverb_Reflections_Pan => EFX_Thin.AL_EAXREVERB_REFLECTIONS_PAN, EAX_Reverb_Room_Rolloff_Factor => EFX_Thin.AL_EAXREVERB_ROOM_ROLLOFF_FACTOR, Echo_Damping => EFX_Thin.AL_ECHO_DAMPING, Echo_Delay => EFX_Thin.AL_ECHO_DELAY, Echo_Feedback => EFX_Thin.AL_ECHO_FEEDBACK, Echo_LR_Delay => EFX_Thin.AL_ECHO_LRDELAY, Echo_Spread => EFX_Thin.AL_ECHO_SPREAD, Equalizer_High_Cutoff => EFX_Thin.AL_EQUALIZER_HIGH_CUTOFF, Equalizer_High_Gain => EFX_Thin.AL_EQUALIZER_HIGH_GAIN, Equalizer_Low_Cutoff => EFX_Thin.AL_EQUALIZER_LOW_CUTOFF, Equalizer_Low_Gain => EFX_Thin.AL_EQUALIZER_LOW_GAIN, Equalizer_Mid1_Center => EFX_Thin.AL_EQUALIZER_MID1_CENTER, Equalizer_Mid1_Gain => EFX_Thin.AL_EQUALIZER_MID1_GAIN, Equalizer_Mid1_Width => EFX_Thin.AL_EQUALIZER_MID1_WIDTH, Equalizer_Mid2_Center => EFX_Thin.AL_EQUALIZER_MID2_CENTER, Equalizer_Mid2_Gain => EFX_Thin.AL_EQUALIZER_MID2_GAIN, Equalizer_Mid2_Width => EFX_Thin.AL_EQUALIZER_MID2_WIDTH, Flanger_Delay => EFX_Thin.AL_FLANGER_DELAY, Flanger_Depth => EFX_Thin.AL_FLANGER_DEPTH, Flanger_Feedback => EFX_Thin.AL_FLANGER_FEEDBACK, Flanger_Phase => EFX_Thin.AL_FLANGER_PHASE, Flanger_Rate => EFX_Thin.AL_FLANGER_RATE, Flanger_Waveform => EFX_Thin.AL_FLANGER_WAVEFORM, Frequency_Shifter_Frequency => EFX_Thin.AL_FREQUENCY_SHIFTER_FREQUENCY, Frequency_Shifter_Left_Direction => EFX_Thin.AL_FREQUENCY_SHIFTER_LEFT_DIRECTION, Frequency_Shifter_Right_Direction => EFX_Thin.AL_FREQUENCY_SHIFTER_RIGHT_DIRECTION, Pitch_Shifter_Coarse_Tune => EFX_Thin.AL_PITCH_SHIFTER_COARSE_TUNE, Pitch_Shifter_Fine_Tune => EFX_Thin.AL_PITCH_SHIFTER_FINE_TUNE, Reverb_Air_Absorption_Gain_HF => EFX_Thin.AL_REVERB_AIR_ABSORPTION_GAINHF, Reverb_Decay_HF_Limit => EFX_Thin.AL_REVERB_DECAY_HFLIMIT, Reverb_Decay_HF_Ratio => EFX_Thin.AL_REVERB_DECAY_HFRATIO, Reverb_Decay_Time => EFX_Thin.AL_REVERB_DECAY_TIME, Reverb_Density => EFX_Thin.AL_REVERB_DENSITY, Reverb_Diffusion => EFX_Thin.AL_REVERB_DIFFUSION, Reverb_Gain => EFX_Thin.AL_REVERB_GAIN, Reverb_Gain_HF => EFX_Thin.AL_REVERB_GAINHF, Reverb_Late_Reverb_Delay => EFX_Thin.AL_REVERB_LATE_REVERB_DELAY, Reverb_Late_Reverb_Gain => EFX_Thin.AL_REVERB_LATE_REVERB_GAIN, Reverb_Reflections_Delay => EFX_Thin.AL_REVERB_REFLECTIONS_DELAY, Reverb_Reflections_Gain => EFX_Thin.AL_REVERB_REFLECTIONS_GAIN, Reverb_Room_Rolloff_Factor => EFX_Thin.AL_REVERB_ROOM_ROLLOFF_FACTOR, Ring_Modulator_Frequency => EFX_Thin.AL_RING_MODULATOR_FREQUENCY, Ring_Modulator_Highpass_Cutoff => EFX_Thin.AL_RING_MODULATOR_HIGHPASS_CUTOFF, Ring_Modulator_Waveform => EFX_Thin.AL_RING_MODULATOR_WAVEFORM, Vocal_Morpher_Phoneme_A => EFX_Thin.AL_VOCAL_MORPHER_PHONEMEA, Vocal_Morpher_Phoneme_A_Coarse_Tuning => EFX_Thin.AL_VOCAL_MORPHER_PHONEMEA_COARSE_TUNING, Vocal_Morpher_Phoneme_B => EFX_Thin.AL_VOCAL_MORPHER_PHONEMEB, Vocal_Morpher_Phoneme_B_Coarse_Tuning => EFX_Thin.AL_VOCAL_MORPHER_PHONEMEB_COARSE_TUNING, Vocal_Morpher_Rate => EFX_Thin.AL_VOCAL_MORPHER_RATE, Vocal_Morpher_Waveform => EFX_Thin.AL_VOCAL_MORPHER_WAVEFORM, Compressor_On_Off => EFX_Thin.AL_COMPRESSOR_ONOFF); procedure Set_Effect_Parameter (Extension : in Extension_t; Effect : in Effect_t; Parameter : in Effect_Parameter_t; Value : in Types.Float_t) is begin Check_Loaded (Extension); Extension.API.Effectf (Effect => Types.Unsigned_Integer_t (Effect), Parameter => Map_Effect_Parameter (Parameter), Value => Value); end Set_Effect_Parameter; -- -- Set_Effect_Type -- type Map_Effect_Type_t is array (Valid_Effect_Type_t) of Types.Integer_t; Map_Effect_Type : constant Map_Effect_Type_t := (Reverb => EFX_Thin.AL_EFFECT_REVERB, Chorus => EFX_Thin.AL_EFFECT_CHORUS, Distortion => EFX_Thin.AL_EFFECT_DISTORTION, Echo => EFX_Thin.AL_EFFECT_ECHO, Flanger => EFX_Thin.AL_EFFECT_FLANGER, Frequency_Shifter => EFX_Thin.AL_EFFECT_FREQUENCY_SHIFTER, Vocal_Morpher => EFX_Thin.AL_EFFECT_VOCAL_MORPHER, Pitch_Shifter => EFX_Thin.AL_EFFECT_PITCH_SHIFTER, Ring_Modulator => EFX_Thin.AL_EFFECT_RING_MODULATOR, Autowah => EFX_Thin.AL_EFFECT_AUTOWAH, Compressor => EFX_Thin.AL_EFFECT_COMPRESSOR, Equalizer => EFX_Thin.AL_EFFECT_EQUALIZER, EAX_Reverb => EFX_Thin.AL_EFFECT_EAXREVERB); procedure Set_Effect_Type (Extension : in Extension_t; Effect : in Effect_t; Effect_Type : in Valid_Effect_Type_t) is begin Check_Loaded (Extension); Extension.API.Effecti (Effect => Types.Unsigned_Integer_t (Effect), Parameter => EFX_Thin.AL_EFFECT_TYPE, Value => Map_Effect_Type (Effect_Type)); end Set_Effect_Type; -- -- Set_Filter_Parameter -- type Map_Filter_Parameter_t is array (Filter_Parameter_t) of Types.Enumeration_t; Map_Filter_Parameter : constant Map_Filter_Parameter_t := (Low_Pass_Gain => EFX_Thin.AL_LOWPASS_GAIN, Low_Pass_Gain_HF => EFX_Thin.AL_LOWPASS_GAINHF, High_Pass_Gain => EFX_Thin.AL_HIGHPASS_GAIN, High_Pass_Gain_LF => EFX_Thin.AL_HIGHPASS_GAINLF, Band_Pass_Gain => EFX_Thin.AL_BANDPASS_GAIN, Band_Pass_Gain_LF => EFX_Thin.AL_BANDPASS_GAINLF, Band_Pass_Gain_HF => EFX_Thin.AL_BANDPASS_GAINHF); procedure Set_Filter_Parameter (Extension : in Extension_t; Filter : in Filter_t; Parameter : in Filter_Parameter_t; Value : in Types.Float_t) is begin Check_Loaded (Extension); Extension.API.Filterf (Filter => Types.Unsigned_Integer_t (Filter), Parameter => Map_Filter_Parameter (Parameter), Value => Value); end Set_Filter_Parameter; -- -- Set_Filter_Type -- type Map_Filter_Type_t is array (Valid_Filter_Type_t) of Types.Integer_t; Map_Filter_Type : constant Map_Filter_Type_t := (Low_Pass_Filter => EFX_Thin.AL_FILTER_LOWPASS, Band_Pass_Filter => EFX_Thin.AL_FILTER_BANDPASS, High_Pass_Filter => EFX_Thin.AL_FILTER_HIGHPASS); procedure Set_Filter_Type (Extension : in Extension_t; Filter : in Filter_t; Filter_Type : in Valid_Filter_Type_t) is begin Check_Loaded (Extension); Extension.API.Filteri (Filter => Types.Unsigned_Integer_t (Filter), Parameter => EFX_Thin.AL_FILTER_TYPE, Value => Map_Filter_Type (Filter_Type)); end Set_Filter_Type; -- -- Set_Meters_Per_Unit -- procedure Set_Meters_Per_Unit (Extension : in Extension_t; Meters : in Meters_t) is begin Check_Loaded (Extension); Thin.Listenerf (Parameter => EFX_Thin.AL_METERS_PER_UNIT, Value => Types.Float_t (Meters)); end Set_Meters_Per_Unit; -- -- Set_Room_Rolloff_Factor -- procedure Set_Room_Rolloff_Factor (Extension : in Extension_t; Source : in OpenAL.Source.Source_t; Factor : in Room_Rolloff_Factor_t) is begin Check_Loaded (Extension); Thin.Sourcef (Source_ID => OpenAL.Source.To_Integer (Source), Parameter => EFX_Thin.AL_ROOM_ROLLOFF_FACTOR, Value => Types.Float_t (Factor)); end Set_Room_Rolloff_Factor; end OpenAL.Extension.EFX;
------------------------------------------------------------------------------ -- -- -- Copyright (C) 2015-2016, AdaCore -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions are -- -- met: -- -- 1. Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- 2. Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in -- -- the documentation and/or other materials provided with the -- -- distribution. -- -- 3. Neither the name of the copyright holder nor the names of its -- -- contributors may be used to endorse or promote products derived -- -- from this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -- -- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -- -- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -- -- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -- -- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -- -- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -- -- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- -- ------------------------------------------------------------------------------ with STM32.GPIO; with STM32.Device; with OpenMV; with ST7735R; use ST7735R; with ST7735R.RAM_Framebuffer; use ST7735R.RAM_Framebuffer; with Ravenscar_Time; package body OpenMV.LCD_Shield is LCD_RST : STM32.GPIO.GPIO_Point renames Shield_PWM1; LCD_RS : STM32.GPIO.GPIO_Point renames Shield_PWM2; LCD_CS : STM32.GPIO.GPIO_Point renames Shield_SEL; All_Points : constant STM32.GPIO.GPIO_Points := (LCD_RS, LCD_CS, LCD_RST); LCD_Driver : ST7735R_RAM_Framebuffer_Screen (Shield_SPI'Access, LCD_CS'Access, LCD_RS'Access, LCD_RST'Access, Ravenscar_Time.Delays); Is_Initialized : Boolean := False; ----------------- -- Initialized -- ----------------- function Initialized return Boolean is (Is_Initialized); ---------------- -- Initialize -- ---------------- procedure Initialize is GPIO_Conf : STM32.GPIO.GPIO_Port_Configuration; begin -- Initalize shield SPI port Initialize_Shield_SPI; STM32.Device.Enable_Clock (All_Points); GPIO_Conf.Mode := STM32.GPIO.Mode_Out; GPIO_Conf.Output_Type := STM32.GPIO.Push_Pull; GPIO_Conf.Speed := STM32.GPIO.Speed_100MHz; GPIO_Conf.Resistors := STM32.GPIO.Floating; STM32.GPIO.Configure_IO (All_Points, GPIO_Conf); Initialize (LCD_Driver); Set_Memory_Data_Access (LCD => LCD_Driver, Color_Order => RGB_Order, Vertical => Vertical_Refresh_Top_Bottom, Horizontal => Horizontal_Refresh_Left_Right, Row_Addr_Order => Row_Address_Bottom_Top, Column_Addr_Order => Column_Address_Right_Left, Row_Column_Exchange => False); Set_Pixel_Format (LCD_Driver, Pixel_16bits); Set_Frame_Rate_Normal (LCD_Driver, RTN => 16#01#, Front_Porch => 16#2C#, Back_Porch => 16#2D#); Set_Frame_Rate_Idle (LCD_Driver, RTN => 16#01#, Front_Porch => 16#2C#, Back_Porch => 16#2D#); Set_Frame_Rate_Partial_Full (LCD_Driver, RTN_Part => 16#01#, Front_Porch_Part => 16#2C#, Back_Porch_Part => 16#2D#, RTN_Full => 16#01#, Front_Porch_Full => 16#2C#, Back_Porch_Full => 16#2D#); Set_Inversion_Control (LCD_Driver, Normal => Line_Inversion, Idle => Line_Inversion, Full_Partial => Line_Inversion); Set_Power_Control_1 (LCD_Driver, AVDD => 2#101#, -- 5 VRHP => 2#0_0010#, -- 4.6 VRHN => 2#0_0010#, -- -4.6 MODE => 2#10#); -- AUTO Set_Power_Control_2 (LCD_Driver, VGH25 => 2#11#, -- 2.4 VGSEL => 2#01#, -- 3*AVDD VGHBT => 2#01#); -- -10 Set_Power_Control_3 (LCD_Driver, 16#0A#, 16#00#); Set_Power_Control_4 (LCD_Driver, 16#8A#, 16#2A#); Set_Power_Control_5 (LCD_Driver, 16#8A#, 16#EE#); Set_Vcom (LCD_Driver, 16#E#); Set_Address (LCD_Driver, X_Start => 0, X_End => 127, Y_Start => 0, Y_End => 159); Turn_On (LCD_Driver); LCD_Driver.Initialize_Layer (Layer => 1, Mode => HAL.Bitmap.RGB_565, X => 0, Y => 0, Width => Image_Width, Height => Image_Height); Is_Initialized := True; end Initialize; ---------------- -- Get_Bitmap -- ---------------- function Get_Bitmap return not null HAL.Bitmap.Any_Bitmap_Buffer is begin return LCD_Driver.Hidden_Buffer (1); end Get_Bitmap; ---------------------- -- Rotate_Screen_90 -- ---------------------- procedure Rotate_Screen_90 is begin Set_Memory_Data_Access (LCD => LCD_Driver, Color_Order => RGB_Order, Vertical => Vertical_Refresh_Top_Bottom, Horizontal => Horizontal_Refresh_Left_Right, Row_Addr_Order => Row_Address_Top_Bottom, Column_Addr_Order => Column_Address_Left_Right, Row_Column_Exchange => False); end Rotate_Screen_90; --------------------- -- Rotate_Screen_0 -- --------------------- procedure Rotate_Screen_0 is begin Set_Memory_Data_Access (LCD => LCD_Driver, Color_Order => RGB_Order, Vertical => Vertical_Refresh_Top_Bottom, Horizontal => Horizontal_Refresh_Left_Right, Row_Addr_Order => Row_Address_Bottom_Top, Column_Addr_Order => Column_Address_Right_Left, Row_Column_Exchange => False); end Rotate_Screen_0; ------------- -- Display -- ------------- procedure Display is begin LCD_Driver.Update_Layer (1); end Display; end OpenMV.LCD_Shield;
pragma License (Unrestricted); -- runtime unit package System.Debug is pragma Preelaborate; -- implementation of Ada.Debug function File return String with Import, Convention => Intrinsic; function Line return Positive with Import, Convention => Intrinsic; function Source_Location return String with Import, Convention => Intrinsic; function Enclosing_Entity return String with Import, Convention => Intrinsic; function Default_Put ( S : String; Source_Location : String; Enclosing_Entity : String) return Boolean with Export, Convention => Ada, External_Name => "__drake_debug_default_put"; type Put_Handler is access function ( S : String; Source_Location : String; Enclosing_Entity : String) return Boolean; Put_Hook : not null Put_Handler := Default_Put'Access with Export, Convention => Ada, External_Name => "__drake_debug_put_hook"; procedure Put ( S : String; Source_Location : String := Debug.Source_Location; Enclosing_Entity : String := Debug.Enclosing_Entity) with Import, Convention => Ada, External_Name => "__drake_debug_put"; function Put ( S : String; Source_Location : String := Debug.Source_Location; Enclosing_Entity : String := Debug.Enclosing_Entity) return Boolean with Import, Convention => Ada, External_Name => "__drake_debug_put"; -- for compiler-units function Runtime_Error ( S : String; Source_Location : String := Debug.Source_Location; Enclosing_Entity : String := Debug.Enclosing_Entity) return Boolean with Export, Convention => Ada, External_Name => "__drake_runtime_error"; pragma Machine_Attribute (Runtime_Error, "noreturn"); pragma Inline_Always (Runtime_Error); -- [gcc-7] can not skip calling Raise_Assertion_Error after "noreturn" private function Put_Impl ( S : String; Source_Location : String := Debug.Source_Location; Enclosing_Entity : String := Debug.Enclosing_Entity) return Boolean with Export, Convention => Ada, External_Name => "__drake_debug_put"; end System.Debug;
package Sorts is type Integer_List is array (Integer range <>) of Integer; procedure Sort(List : in out Integer_List); procedure Display_List (List : in Integer_List); end Sorts;
------------------------------------------------------------------------------ -- -- -- Copyright (C) 2017, AdaCore -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions are -- -- met: -- -- 1. Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- 2. Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in -- -- the documentation and/or other materials provided with the -- -- distribution. -- -- 3. Neither the name of STMicroelectronics nor the names of its -- -- contributors may be used to endorse or promote products derived -- -- from this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -- -- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -- -- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -- -- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -- -- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -- -- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -- -- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- -- -- -- -- This file is based on X-CUBE-53L0A1 STM32Cube expansion -- -- -- -- COPYRIGHT(c) 2016 STMicroelectronics -- ------------------------------------------------------------------------------ with HAL.I2C; package VL53L0X is Fix_Point_16_16_Delta : constant := 1.0 / (2.0 ** 16); type Fix_Point_16_16 is delta Fix_Point_16_16_Delta range -2.0 ** 15 .. 2.0 ** 15 - Fix_Point_16_16_Delta with Size => 32; type VL53L0X_Ranging_Sensor (Port : not null HAL.I2C.Any_I2C_Port) is limited private; type VL53L0X_GPIO_Functionality is (No_Interrupt, Level_Low, Level_High, Out_Of_Window, New_Sample_Ready); type VL53L0X_Interrupt_Polarity is (Polarity_Low, Polarity_High); procedure Initialize (This : in out VL53L0X_Ranging_Sensor); function Read_Id (This : VL53L0X_Ranging_Sensor) return HAL.UInt16; procedure Set_Device_Address (This : in out VL53L0X_Ranging_Sensor; Addr : HAL.I2C.I2C_Address; Status : out Boolean); procedure Data_Init (This : in out VL53L0X_Ranging_Sensor; Status : out Boolean); procedure Static_Init (This : in out VL53L0X_Ranging_Sensor; GPIO_Function : VL53L0X_GPIO_Functionality; Status : out Boolean); procedure Perform_Ref_Calibration (This : in out VL53L0X_Ranging_Sensor; Status : out Boolean); procedure Start_Range_Single_Millimeters (This : VL53L0X_Ranging_Sensor; Status : out Boolean); -- Start a read operation on sensor function Range_Value_Available (This : VL53L0X_Ranging_Sensor) return Boolean; -- Returns True when a new value is available function Read_Range_Millimeters (This : VL53L0X_Ranging_Sensor) return HAL.UInt16 with Pre => Range_Value_Available (This); -- Read the available ranging value function Read_Range_Single_Millimeters (This : VL53L0X_Ranging_Sensor) return HAL.UInt16; procedure Set_GPIO_Config (This : in out VL53L0X_Ranging_Sensor; Functionality : VL53L0X_GPIO_Functionality; Polarity : VL53L0X_Interrupt_Polarity; Status : out Boolean); procedure Clear_Interrupt_Mask (This : VL53L0X_Ranging_Sensor); function Measurement_Timing_Budget (This : VL53L0X_Ranging_Sensor) return HAL.UInt32; procedure Set_Measurement_Timing_Budget (This : VL53L0X_Ranging_Sensor; Budget_Micro_Seconds : HAL.UInt32; Status : out Boolean); -- Sets the measurement timing budget. -- The more time, the more precisions. By default, the budget is ~33ms procedure Set_Signal_Rate_Limit (This : VL53L0X_Ranging_Sensor; Rate_Limit : Fix_Point_16_16); -- Default signal rate: 0.25 MCPS procedure Set_VCSEL_Pulse_Period_Pre_Range (This : VL53L0X_Ranging_Sensor; Period : HAL.UInt8; Status : out Boolean); -- Default period: 14 PCLKs procedure Set_VCSEL_Pulse_Period_Final_Range (This : VL53L0X_Ranging_Sensor; Period : HAL.UInt8; Status : out Boolean); -- Default period: 10 PCLKs procedure SetInterMeasurementPeriodMilliSeconds (This : VL53L0X_Ranging_Sensor; Period : HAL.UInt32; Status : out Boolean); procedure GetInterMeasurementPeriodMilliSeconds (This : in out VL53L0X_Ranging_Sensor; Status : out Boolean); procedure GetDeviceParameters (This : in out VL53L0X_Ranging_Sensor; Status : out Boolean); private REG_SYSRANGE_START : constant := 16#000#; -- mask existing bit in #REG_SYSRANGE_START REG_SYSRANGE_MODE_MASK : constant := 16#0F#; -- bit 0 in #REG_SYSRANGE_START write 1 toggle state in -- continuous mode and arm next shot in single shot mode REG_SYSRANGE_MODE_START_STOP : constant := 16#01#; -- bit 1 write 0 in #REG_SYSRANGE_START set single shot mode REG_SYSRANGE_MODE_SINGLESHOT : constant := 16#00#; -- bit 1 write 1 in #REG_SYSRANGE_START set back-to-back -- operation mode REG_SYSRANGE_MODE_BACKTOBACK : constant := 16#02#; -- bit 2 write 1 in #REG_SYSRANGE_START set timed operation -- mode REG_SYSRANGE_MODE_TIMED : constant := 16#04#; -- bit 3 write 1 in #REG_SYSRANGE_START set histogram operation -- mode REG_SYSRANGE_MODE_HISTOGRAM : constant := 16#08#; REG_SYSTEM_THRESH_HIGH : constant := 16#000C#; REG_SYSTEM_THRESH_LOW : constant := 16#000E#; REG_SYSTEM_SEQUENCE_CONFIG : constant := 16#0001#; REG_SYSTEM_RANGE_CONFIG : constant := 16#0009#; REG_SYSTEM_INTERMEASUREMENT_PERIOD : constant := 16#0004#; REG_SYSTEM_INTERRUPT_CONFIG_GPIO : constant := 16#000A#; REG_SYSTEM_INTERRUPT_GPIO_DISABLED : constant := 16#00#; REG_SYSTEM_INTERRUPT_GPIO_LEVEL_LOW : constant := 16#01#; REG_SYSTEM_INTERRUPT_GPIO_LEVEL_HIGH : constant := 16#02#; REG_SYSTEM_INTERRUPT_GPIO_OUT_OF_WINDOW : constant := 16#03#; REG_SYSTEM_INTERRUPT_GPIO_NEW_SAMPLE_READY : constant := 16#04#; REG_GPIO_HV_MUX_ACTIVE_HIGH : constant := 16#0084#; REG_SYSTEM_INTERRUPT_CLEAR : constant := 16#000B#; -- Result registers REG_RESULT_INTERRUPT_STATUS : constant := 16#0013#; REG_RESULT_RANGE_STATUS : constant := 16#0014#; REG_RESULT_CORE_PAGE : constant := 1; REG_RESULT_CORE_AMBIENT_WINDOW_EVENTS_RTN : constant := 16#00BC#; REG_RESULT_CORE_RANGING_TOTAL_EVENTS_RTN : constant := 16#00C0#; REG_RESULT_CORE_AMBIENT_WINDOW_EVENTS_REF : constant := 16#00D0#; REG_RESULT_CORE_RANGING_TOTAL_EVENTS_REF : constant := 16#00D4#; REG_RESULT_PEAK_SIGNAL_RATE_REF : constant := 16#00B6#; -- Algo register REG_ALGO_PART_TO_PART_RANGE_OFFSET_MM : constant := 16#0028#; REG_I2C_SLAVE_DEVICE_ADDRESS : constant := 16#008A#; -- Check Limit registers REG_MSRC_CONFIG_CONTROL : constant := 16#0060#; REG_PRE_RANGE_CONFIG_MIN_SNR : constant := 16#0027#; REG_PRE_RANGE_CONFIG_VALID_PHASE_LOW : constant := 16#0056#; REG_PRE_RANGE_CONFIG_VALID_PHASE_HIGH : constant := 16#0057#; REG_PRE_RANGE_MIN_COUNT_RATE_RTN_LIMIT : constant := 16#0064#; REG_FINAL_RANGE_CONFIG_MIN_SNR : constant := 16#0067#; REG_FINAL_RANGE_CONFIG_VALID_PHASE_LOW : constant := 16#0047#; REG_FINAL_RANGE_CONFIG_VALID_PHASE_HIGH : constant := 16#0048#; REG_FINAL_RANGE_CONFIG_MIN_COUNT_RATE_RTN_LIMIT : constant := 16#0044#; REG_PRE_RANGE_CONFIG_SIGMA_THRESH_HI : constant := 16#0061#; REG_PRE_RANGE_CONFIG_SIGMA_THRESH_LO : constant := 16#0062#; -- PRE RANGE registers REG_PRE_RANGE_CONFIG_VCSEL_PERIOD : constant := 16#0050#; REG_PRE_RANGE_CONFIG_TIMEOUT_MACROP_HI : constant := 16#0051#; REG_PRE_RANGE_CONFIG_TIMEOUT_MACROP_LO : constant := 16#0052#; REG_SYSTEM_HISTOGRAM_BIN : constant := 16#0081#; REG_HISTOGRAM_CONFIG_INITIAL_PHASE_SELECT : constant := 16#0033#; REG_HISTOGRAM_CONFIG_READOUT_CTRL : constant := 16#0055#; REG_FINAL_RANGE_CONFIG_VCSEL_PERIOD : constant := 16#0070#; REG_FINAL_RANGE_CONFIG_TIMEOUT_MACROP_HI : constant := 16#0071#; REG_FINAL_RANGE_CONFIG_TIMEOUT_MACROP_LO : constant := 16#0072#; REG_CROSSTALK_COMPENSATION_PEAK_RATE_MCPS : constant := 16#0020#; REG_MSRC_CONFIG_TIMEOUT_MACROP : constant := 16#0046#; REG_SOFT_RESET_GO2_SOFT_RESET_N : constant := 16#00bf#; REG_IDENTIFICATION_MODEL_ID : constant := 16#00c0#; REG_IDENTIFICATION_REVISION_ID : constant := 16#00c2#; REG_OSC_CALIBRATE_VAL : constant := 16#00f8#; SIGMA_ESTIMATE_MAX_VALUE : constant := 65535; -- equivalent to a range sigma of 655.35mm REG_GLOBAL_CONFIG_VCSEL_WIDTH : constant := 16#032#; REG_GLOBAL_CONFIG_SPAD_ENABLES_REF_0 : constant := 16#0B0#; REG_GLOBAL_CONFIG_SPAD_ENABLES_REF_1 : constant := 16#0B1#; REG_GLOBAL_CONFIG_SPAD_ENABLES_REF_2 : constant := 16#0B2#; REG_GLOBAL_CONFIG_SPAD_ENABLES_REF_3 : constant := 16#0B3#; REG_GLOBAL_CONFIG_SPAD_ENABLES_REF_4 : constant := 16#0B4#; REG_GLOBAL_CONFIG_SPAD_ENABLES_REF_5 : constant := 16#0B5#; REG_GLOBAL_CONFIG_REF_EN_START_SELECT : constant := 16#B6#; REG_DYNAMIC_SPAD_NUM_REQUESTED_REF_SPAD : constant := 16#4E#; REG_DYNAMIC_SPAD_REF_EN_START_OFFSET : constant := 16#4F#; REG_POWER_MANAGEMENT_GO1_POWER_FORCE : constant := 16#80#; -- Speed of light in um per 1E-10 Seconds SPEED_OF_LIGHT_IN_AIR : constant := 2997; REG_VHV_CONFIG_PAD_SCL_SDA_EXTSUP_HV : constant := 16#0089#; REG_ALGO_PHASECAL_LIM : constant := 16#0030#; REG_ALGO_PHASECAL_CONFIG_TIMEOUT : constant := 16#0030#; type VL53L0X_Device_Specific_Parameters is record Osc_Frequency : HAL.UInt32 := 0; Last_Timeout : HAL.UInt16 := 0; Pin0_Functionality : VL53L0X_GPIO_Functionality := No_Interrupt; Final_Range_Timeout_Micro_Seconds : HAL.UInt32 := 0; Final_Range_Vcsel_Pulse_Period : HAL.UInt8 := 0; Pre_Range_Timeout_Micro_Seconds : HAL.UInt32 := 0; Pre_Range_Vcsel_Pulse_Period : HAL.UInt8 := 0; Sigma_Est_Ref_Array : HAL.UInt16 := 0; Sigma_Est_Eff_Pulse_Width : HAL.UInt16 := 0; Sigma_Est_Eff_Amb_Width : HAL.UInt16 := 0; StopVariable : HAL.UInt8; TargetRefRate : HAL.UInt16; SigmaEstimate : Fix_Point_16_16; SignalEstimate : Fix_Point_16_16; LastSignalRefMcps : Fix_Point_16_16; -- uint8_t *pTuningSettingsPointer; UseInternalTuningSettings : Boolean; Linearity_Corrective_Gain : HAL.UInt16; Dmax_Cal_Range_MilliMeter : HAL.UInt16; Dmax_Cal_Signal_Rate_Rtn_MegaCps : HAL.UInt32; Read_Data_From_Device_Done : Boolean := False; Module_Id : HAL.UInt8; Revision : HAL.UInt8; Reference_SPAD_Count : HAL.UInt8; Reference_SPAD_Type : HAL.UInt8; Reference_SPADs_Initialised : Boolean := False; Part_UID_Upper : HAL.UInt32; Part_UID_Lower : HAL.UInt32; end record; type Histogram_Modes is (Disabled, Reference_Only, Return_Only, Both); type Device_Modes is (Single_Ranging, Continuous_Ranging, Continuous_Timed_Ranging, Single_Histogram); CHECKENABLE_NUMBER_OF_CHECKS : constant HAL.UInt32 := 6; type LimitChecksEnableT is array (1 .. CHECKENABLE_NUMBER_OF_CHECKS) of Boolean; type LimitChecksStatusT is array (1 .. CHECKENABLE_NUMBER_OF_CHECKS) of HAL.UInt8; type LimitChecksValueT is array (1 .. CHECKENABLE_NUMBER_OF_CHECKS) of Fix_Point_16_16; type VL53L0X_Device_Parameters is record Device_Mode : Device_Modes; Histogram_Mode : Histogram_Modes; X_Talk_Compensation_Enable : Boolean; X_Talk_Compensation_Range_MilliMeter : HAL.UInt16; X_Talk_Compensation_Rate_Mcps : Fix_Point_16_16; MeasurementTimingBudgetMicroSeconds : HAL.UInt32; InterMeasurementPeriodMilliSeconds : HAL.UInt32; RangeOffsetMicroMeters : HAL.UInt32; LimitChecksEnable : LimitChecksEnableT; LimitChecksStatus : LimitChecksStatusT; LimitChecksValue : LimitChecksValueT; WrapAroundCheckEnable : Boolean; end record; type VL53L0X_Ranging_Sensor (Port : not null HAL.I2C.Any_I2C_Port) is limited record -- Default address: can be changed by software I2C_Address : HAL.I2C.I2C_Address := 16#52#; Stop_Variable : HAL.UInt8; Device_Specific_Params : VL53L0X_Device_Specific_Parameters; Device_Params : VL53L0X_Device_Parameters; end record; procedure I2C_Write (This : VL53L0X_Ranging_Sensor; Data : HAL.UInt8_Array; Status : out Boolean); procedure I2C_Read (This : VL53L0X_Ranging_Sensor; Data : out HAL.UInt8_Array; Status : out Boolean); procedure Write (This : VL53L0X_Ranging_Sensor; Index : HAL.UInt8; Data : HAL.UInt8_Array; Status : out Boolean); procedure Write (This : VL53L0X_Ranging_Sensor; Index : HAL.UInt8; Data : HAL.UInt8; Status : out Boolean); procedure Write (This : VL53L0X_Ranging_Sensor; Index : HAL.UInt8; Data : HAL.UInt16; Status : out Boolean); procedure Write (This : VL53L0X_Ranging_Sensor; Index : HAL.UInt8; Data : HAL.UInt32; Status : out Boolean); procedure Read (This : VL53L0X_Ranging_Sensor; Index : HAL.UInt8; Data : out HAL.UInt8_Array; Status : out Boolean); procedure Read (This : VL53L0X_Ranging_Sensor; Index : HAL.UInt8; Data : out HAL.UInt8; Status : out Boolean); procedure Read (This : VL53L0X_Ranging_Sensor; Index : HAL.UInt8; Data : out HAL.UInt16; Status : out Boolean); procedure Read (This : VL53L0X_Ranging_Sensor; Index : HAL.UInt8; Data : out HAL.UInt32; Status : out Boolean); function Set_Signal_Rate_Limit (This : VL53L0X_Ranging_Sensor; Limit_Mcps : Fix_Point_16_16) return Boolean; function SPAD_Info (This : VL53L0X_Ranging_Sensor; SPAD_Count : out HAL.UInt8; Is_Aperture : out Boolean) return Boolean; type VL53L0x_Sequence_Step is (TCC, DSS, MSRC, Pre_Range, Final_Range); type VL53L0x_Sequence_Step_Enabled is array (VL53L0x_Sequence_Step) of Boolean; type VL53L0x_Sequence_Step_Timeout is array (VL53L0x_Sequence_Step) of HAL.UInt32; function Sequence_Step_Enabled (This : VL53L0X_Ranging_Sensor) return VL53L0x_Sequence_Step_Enabled; function Sequence_Step_Timeout (This : VL53L0X_Ranging_Sensor; Step : VL53L0x_Sequence_Step; As_Mclks : Boolean := False) return HAL.UInt32; function VCSel_Pulse_Period (This : VL53L0X_Ranging_Sensor; Sequence : VL53L0x_Sequence_Step) return HAL.UInt8; procedure Set_VCSel_Pulse_Period (This : VL53L0X_Ranging_Sensor; Period : HAL.UInt8; Sequence : VL53L0x_Sequence_Step; Status : out Boolean); end VL53L0X;
------------------------------------------------------------------------------ -- -- -- GNAT ncurses Binding -- -- -- -- Terminal_Interface.Curses.Mouse -- -- -- -- B O D Y -- -- -- ------------------------------------------------------------------------------ -- Copyright (c) 1998 Free Software Foundation, Inc. -- -- -- -- Permission is hereby granted, free of charge, to any person obtaining a -- -- copy of this software and associated documentation files (the -- -- "Software"), to deal in the Software without restriction, including -- -- without limitation the rights to use, copy, modify, merge, publish, -- -- distribute, distribute with modifications, sublicense, and/or sell -- -- copies of the Software, and to permit persons to whom the Software is -- -- furnished to do so, subject to the following conditions: -- -- -- -- The above copyright notice and this permission notice shall be included -- -- in all copies or substantial portions of the Software. -- -- -- -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -- -- OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -- -- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -- -- IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -- -- DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -- -- OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR -- -- THE USE OR OTHER DEALINGS IN THE SOFTWARE. -- -- -- -- Except as contained in this notice, the name(s) of the above copyright -- -- holders shall not be used in advertising or otherwise to promote the -- -- sale, use or other dealings in this Software without prior written -- -- authorization. -- ------------------------------------------------------------------------------ -- Author: Juergen Pfeifer <Juergen.Pfeifer@T-Online.de> 1996 -- Version Control: -- $Revision: 1.9 $ -- Binding Version 00.93 ------------------------------------------------------------------------------ with System; with Terminal_Interface.Curses.Aux; use Terminal_Interface.Curses.Aux; with Interfaces; with Interfaces.C; with Unchecked_Conversion; package body Terminal_Interface.Curses.Mouse is use type System.Bit_Order; use type Interfaces.C.int; function CInt_To_Mask is new Unchecked_Conversion (Source => C_Int, Target => Event_Mask); function Mask_To_CInt is new Unchecked_Conversion (Source => Event_Mask, Target => C_Int); function Has_Mouse return Boolean is function Mouse_Avail return C_Int; pragma Import (C, Mouse_Avail, "_nc_has_mouse"); begin if Has_Key (Key_Mouse) or else Mouse_Avail /= 0 then return True; else return False; end if; end Has_Mouse; function Get_Mouse return Mouse_Event is type Event_Access is access all Mouse_Event; function Getmouse (Ev : Event_Access) return C_Int; pragma Import (C, Getmouse, "getmouse"); Event : aliased Mouse_Event; begin if Getmouse (Event'Access) = Curses_Err then raise Curses_Exception; end if; return Event; end Get_Mouse; procedure Register_Reportable_Event (B : in Mouse_Button; S : in Button_State; Mask : in out Event_Mask) is type Evt_Access is access all Event_Mask; function Register (B : C_Int; S : C_Int; M : Evt_Access) return C_Int; pragma Import (C, Register, "_nc_ada_mouse_mask"); T : aliased Event_Mask := Mask; M : Evt_Access := T'Access; R : constant C_Int := Register (C_Int (Mouse_Button'Pos (B)), C_Int (Button_State'Pos (S)), M); begin if R = Curses_Err then raise Curses_Exception; end if; Mask := T; end Register_Reportable_Event; function Start_Mouse (Mask : Event_Mask := All_Events) return Event_Mask is type Int_Access is access all C_Int; function MMask (M : C_Int; O : Int_Access := null) return C_Int; pragma Import (C, MMask, "mousemask"); R : C_Int; begin R := MMask (Mask_To_CInt (Mask)); return CInt_To_Mask (R); end Start_Mouse; procedure End_Mouse is Old : constant Event_Mask := Start_Mouse (No_Events); begin null; end End_Mouse; procedure Get_Event (Event : in Mouse_Event; Y : out Line_Position; X : out Column_Position; Button : out Mouse_Button; State : out Button_State) is procedure Dispatch_Event (M : in C_Int; B : out C_Int; S : out C_Int); pragma Import (C, Dispatch_Event, "_nc_ada_mouse_event"); Mask : constant Interfaces.C.int := Mask_To_CInt (Event.Bstate); B, S : C_Int; begin X := Column_Position (Event.X); Y := Line_Position (Event.Y); Dispatch_Event (Mask, B, S); Button := Mouse_Button'Val (B); State := Button_State'Val (S); end Get_Event; procedure Unget_Mouse (Event : in Mouse_Event) is function Ungetmouse (Ev : Mouse_Event) return C_Int; pragma Import (C, Ungetmouse, "ungetmouse"); begin if Ungetmouse (Event) = Curses_Err then raise Curses_Exception; end if; end Unget_Mouse; function Enclosed_In_Window (Win : Window := Standard_Window; Event : Mouse_Event) return Boolean is function Wenclose (Win : Window; Y : C_Int; X : C_Int) return C_Int; pragma Import (C, Wenclose, "wenclose"); begin if Wenclose (Win, C_Int (Event.Y), C_Int (Event.X)) = Curses_False then return False; else return True; end if; end Enclosed_In_Window; function Mouse_Interval (Msec : Natural := 200) return Natural is function Mouseinterval (Msec : C_Int) return C_Int; pragma Import (C, Mouseinterval, "mouseinterval"); begin return Natural (Mouseinterval (C_Int (Msec))); end Mouse_Interval; end Terminal_Interface.Curses.Mouse;
-- SPDX-License-Identifier: Apache-2.0 -- -- Copyright (c) 2016 onox <denkpadje@gmail.com> -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. with Ada.Characters.Latin_1; with AUnit.Assertions; with AUnit.Test_Caller; with JSON.Streams; with JSON.Tokenizers; with JSON.Types; package body Test_Tokenizers is package Types is new JSON.Types (Long_Integer, Long_Float); package Tokenizers is new JSON.Tokenizers (Types); package Streams renames JSON.Streams; use type JSON.Streams.AS.Stream_Element_Offset; String_Offset_Message : constant String := "String value at wrong offset"; String_Length_Message : constant String := "String value has incorrect length"; use AUnit.Assertions; package Caller is new AUnit.Test_Caller (Test); Test_Suite : aliased AUnit.Test_Suites.Test_Suite; function Suite return AUnit.Test_Suites.Access_Test_Suite is Name : constant String := "(Tokenizers) "; begin Test_Suite.Add_Test (Caller.Create (Name & "Tokenize text 'null'", Test_Null_Token'Access)); Test_Suite.Add_Test (Caller.Create (Name & "Tokenize text 'true'", Test_True_Token'Access)); Test_Suite.Add_Test (Caller.Create (Name & "Tokenize text 'false'", Test_False_Token'Access)); Test_Suite.Add_Test (Caller.Create (Name & "Tokenize text '""""'", Test_Empty_String_Token'Access)); Test_Suite.Add_Test (Caller.Create (Name & "Tokenize text '""test""'", Test_Non_Empty_String_Token'Access)); Test_Suite.Add_Test (Caller.Create (Name & "Tokenize text '""12.34""'", Test_Number_String_Token'Access)); Test_Suite.Add_Test (Caller.Create (Name & "Tokenize text '""horizontal\ttab""'", Test_Escaped_Character_String_Token'Access)); Test_Suite.Add_Test (Caller.Create (Name & "Tokenize text '""foo\""\\bar""'", Test_Escaped_Quotation_Solidus_String_Token'Access)); Test_Suite.Add_Test (Caller.Create (Name & "Tokenize text '0'", Test_Zero_Number_Token'Access)); Test_Suite.Add_Test (Caller.Create (Name & "Tokenize text '42'", Test_Integer_Number_Token'Access)); Test_Suite.Add_Test (Caller.Create (Name & "Tokenize text '3.14'", Test_Float_Number_Token'Access)); Test_Suite.Add_Test (Caller.Create (Name & "Tokenize text '-2.71'", Test_Negative_Float_Number_Token'Access)); Test_Suite.Add_Test (Caller.Create (Name & "Tokenize text '4e2'", Test_Integer_Exponent_Number_Token'Access)); Test_Suite.Add_Test (Caller.Create (Name & "Tokenize text '0.314e1'", Test_Float_Exponent_Number_Token'Access)); Test_Suite.Add_Test (Caller.Create (Name & "Tokenize text '4e-1'", Test_Float_Negative_Exponent_Number_Token'Access)); Test_Suite.Add_Test (Caller.Create (Name & "Tokenize text '[]'", Test_Empty_Array_Tokens'Access)); Test_Suite.Add_Test (Caller.Create (Name & "Tokenize text '[null]'", Test_One_Element_Array_Tokens'Access)); Test_Suite.Add_Test (Caller.Create (Name & "Tokenize text '[1,2]'", Test_Two_Elements_Array_Tokens'Access)); Test_Suite.Add_Test (Caller.Create (Name & "Tokenize text '{}'", Test_Empty_Object_Tokens'Access)); Test_Suite.Add_Test (Caller.Create (Name & "Tokenize text '{""foo"":""bar""}'", Test_One_Pair_Object_Tokens'Access)); Test_Suite.Add_Test (Caller.Create (Name & "Tokenize text '{""foo"": true,""bar"":false}'", Test_Two_Pairs_Object_Tokens'Access)); -- Exceptions Test_Suite.Add_Test (Caller.Create (Name & "Reject text '""no\nnewline""'", Test_Control_Character_String_Exception'Access)); Test_Suite.Add_Test (Caller.Create (Name & "Reject text '""unexpected\xcharacter""'", Test_Unexpected_Escaped_Character_String_Exception'Access)); Test_Suite.Add_Test (Caller.Create (Name & "Reject text '-'", Test_Minus_Number_EOF_Exception'Access)); Test_Suite.Add_Test (Caller.Create (Name & "Reject text '-,'", Test_Minus_Number_Exception'Access)); Test_Suite.Add_Test (Caller.Create (Name & "Reject text '3.'", Test_End_Dot_Number_Exception'Access)); Test_Suite.Add_Test (Caller.Create (Name & "Reject text '1E'", Test_End_Exponent_Number_Exception'Access)); Test_Suite.Add_Test (Caller.Create (Name & "Reject text '1.E'", Test_End_Dot_Exponent_Number_Exception'Access)); Test_Suite.Add_Test (Caller.Create (Name & "Reject text '1E-'", Test_End_Exponent_Minus_Number_Exception'Access)); Test_Suite.Add_Test (Caller.Create (Name & "Reject text '1E,'", Test_End_Exponent_One_Digit_Exception'Access)); Test_Suite.Add_Test (Caller.Create (Name & "Reject text '1E-,'", Test_End_Exponent_Minus_One_Digit_Exception'Access)); Test_Suite.Add_Test (Caller.Create (Name & "Reject text '+42'", Test_Prefixed_Plus_Number_Exception'Access)); Test_Suite.Add_Test (Caller.Create (Name & "Reject text '-02'", Test_Leading_Zeroes_Integer_Number_Exception'Access)); Test_Suite.Add_Test (Caller.Create (Name & "Reject text '-003.14'", Test_Leading_Zeroes_Float_Number_Exception'Access)); Test_Suite.Add_Test (Caller.Create (Name & "Reject text 'tr'", Test_Incomplete_True_Text_Exception'Access)); Test_Suite.Add_Test (Caller.Create (Name & "Reject text 'f'", Test_Incomplete_False_Text_Exception'Access)); Test_Suite.Add_Test (Caller.Create (Name & "Reject text 'nul'", Test_Incomplete_Null_Text_Exception'Access)); Test_Suite.Add_Test (Caller.Create (Name & "Reject text 'unexpected'", Test_Unknown_Keyword_Text_Exception'Access)); return Test_Suite'Access; end Suite; use type Tokenizers.Token_Kind; procedure Assert_Kind (Left, Right : Tokenizers.Token_Kind; Message : String) is begin Assert (Left = Right, Message & " (Expected " & Right'Image & "; Got " & Left'Image & ")"); end Assert_Kind; procedure Fail (Message : String) is begin Assert (False, Message); end Fail; procedure Expect_EOF (Stream : aliased in out Streams.Stream) is Token : Tokenizers.Token; begin Tokenizers.Read_Token (Stream, Token, Expect_EOF => True); exception when Tokenizers.Tokenizer_Error => Fail ("Expected EOF"); end Expect_EOF; -- Keyword procedure Test_Null_Token (Object : in out Test) is Text : constant String := "null"; Stream : aliased Streams.Stream := Streams.Create_Stream (Streams.From_Text (Text)); Token : Tokenizers.Token; begin Tokenizers.Read_Token (Stream, Token); Assert_Kind (Token.Kind, Tokenizers.Null_Token, "Not Null_Token"); Expect_EOF (Stream); end Test_Null_Token; procedure Test_True_Token (Object : in out Test) is Text : constant String := "true"; Stream : aliased Streams.Stream := Streams.Create_Stream (Streams.From_Text (Text)); Token : Tokenizers.Token; begin Tokenizers.Read_Token (Stream, Token); Assert_Kind (Token.Kind, Tokenizers.Boolean_Token, "Not Boolean_Token"); Assert (Token.Boolean_Value, "Boolean value not True"); Expect_EOF (Stream); end Test_True_Token; procedure Test_False_Token (Object : in out Test) is Text : constant String := "false"; Stream : aliased Streams.Stream := Streams.Create_Stream (Streams.From_Text (Text)); Token : Tokenizers.Token; begin Tokenizers.Read_Token (Stream, Token); Assert_Kind (Token.Kind, Tokenizers.Boolean_Token, "Not Boolean_Token"); Assert (not Token.Boolean_Value, "Boolean value not False"); Expect_EOF (Stream); end Test_False_Token; -- String procedure Test_Empty_String_Token (Object : in out Test) is Text : constant String := """"""; Stream : aliased Streams.Stream := Streams.Create_Stream (Streams.From_Text (Text)); Token : Tokenizers.Token; begin Tokenizers.Read_Token (Stream, Token); Assert_Kind (Token.Kind, Tokenizers.String_Token, "Not String_Token"); Assert (Token.String_Offset = 2, String_Offset_Message); Assert (Token.String_Length = 0, String_Length_Message); Expect_EOF (Stream); end Test_Empty_String_Token; procedure Test_Non_Empty_String_Token (Object : in out Test) is Text : constant String := """test"""; Stream : aliased Streams.Stream := Streams.Create_Stream (Streams.From_Text (Text)); Token : Tokenizers.Token; begin Tokenizers.Read_Token (Stream, Token); Assert_Kind (Token.Kind, Tokenizers.String_Token, "Not String_Token"); Assert (Token.String_Offset = 2, String_Offset_Message); Assert (Token.String_Length = 4, String_Length_Message); Expect_EOF (Stream); end Test_Non_Empty_String_Token; procedure Test_Number_String_Token (Object : in out Test) is Text : constant String := """12.34"""; Stream : aliased Streams.Stream := Streams.Create_Stream (Streams.From_Text (Text)); Token : Tokenizers.Token; begin Tokenizers.Read_Token (Stream, Token); Assert_Kind (Token.Kind, Tokenizers.String_Token, "Not String_Token"); Assert (Token.String_Offset = 2, String_Offset_Message); Assert (Token.String_Length = 5, String_Length_Message); Expect_EOF (Stream); end Test_Number_String_Token; procedure Test_Escaped_Character_String_Token (Object : in out Test) is Text : constant String := """horizontal\ttab"""; Stream : aliased Streams.Stream := Streams.Create_Stream (Streams.From_Text (Text)); Token : Tokenizers.Token; begin Tokenizers.Read_Token (Stream, Token); Assert_Kind (Token.Kind, Tokenizers.String_Token, "Not String_Token"); Assert (Token.String_Offset = 2, String_Offset_Message); Assert (Token.String_Length = 15, String_Length_Message); Expect_EOF (Stream); end Test_Escaped_Character_String_Token; procedure Test_Escaped_Quotation_Solidus_String_Token (Object : in out Test) is Text : constant String := """foo\""\\bar"""; Stream : aliased Streams.Stream := Streams.Create_Stream (Streams.From_Text (Text)); Token : Tokenizers.Token; begin Tokenizers.Read_Token (Stream, Token); Assert_Kind (Token.Kind, Tokenizers.String_Token, "Not String_Token"); Assert (Token.String_Offset = 2, String_Offset_Message); Assert (Token.String_Length = 10, String_Length_Message); Expect_EOF (Stream); end Test_Escaped_Quotation_Solidus_String_Token; -- Integer/Float number procedure Test_Zero_Number_Token (Object : in out Test) is Text : constant String := "0"; Stream : aliased Streams.Stream := Streams.Create_Stream (Streams.From_Text (Text)); Token : Tokenizers.Token; begin Tokenizers.Read_Token (Stream, Token); Assert_Kind (Token.Kind, Tokenizers.Integer_Token, "Not Integer_Token"); Assert (Token.Integer_Value = 0, "Integer value not equal to 0"); Expect_EOF (Stream); end Test_Zero_Number_Token; procedure Test_Integer_Number_Token (Object : in out Test) is Text : constant String := "42"; Stream : aliased Streams.Stream := Streams.Create_Stream (Streams.From_Text (Text)); Token : Tokenizers.Token; begin Tokenizers.Read_Token (Stream, Token); Assert_Kind (Token.Kind, Tokenizers.Integer_Token, "Not Integer_Token"); Assert (Token.Integer_Value = 42, "Integer value not equal to 42"); Expect_EOF (Stream); end Test_Integer_Number_Token; procedure Test_Float_Number_Token (Object : in out Test) is Text : constant String := "3.14"; Stream : aliased Streams.Stream := Streams.Create_Stream (Streams.From_Text (Text)); Token : Tokenizers.Token; begin Tokenizers.Read_Token (Stream, Token); Assert_Kind (Token.Kind, Tokenizers.Float_Token, "Not Float_Token"); Assert (Token.Float_Value = 3.14, "Float value not equal to 3.14"); Expect_EOF (Stream); end Test_Float_Number_Token; procedure Test_Negative_Float_Number_Token (Object : in out Test) is Text : constant String := "-2.71"; Stream : aliased Streams.Stream := Streams.Create_Stream (Streams.From_Text (Text)); Token : Tokenizers.Token; begin Tokenizers.Read_Token (Stream, Token); Assert_Kind (Token.Kind, Tokenizers.Float_Token, "Not Float_Token"); Assert (Token.Float_Value = -2.71, "Float value not equal to -2.71"); Expect_EOF (Stream); end Test_Negative_Float_Number_Token; procedure Test_Integer_Exponent_Number_Token (Object : in out Test) is Text : constant String := "4e2"; Stream : aliased Streams.Stream := Streams.Create_Stream (Streams.From_Text (Text)); Token : Tokenizers.Token; begin Tokenizers.Read_Token (Stream, Token); Assert_Kind (Token.Kind, Tokenizers.Integer_Token, "Not Integer_Token"); Assert (Token.Integer_Value = 400, "Integer value not equal to 400"); Expect_EOF (Stream); end Test_Integer_Exponent_Number_Token; procedure Test_Float_Exponent_Number_Token (Object : in out Test) is Text : constant String := "0.314e1"; Stream : aliased Streams.Stream := Streams.Create_Stream (Streams.From_Text (Text)); Token : Tokenizers.Token; begin Tokenizers.Read_Token (Stream, Token); Assert_Kind (Token.Kind, Tokenizers.Float_Token, "Not Float_Token"); Assert (Token.Float_Value = 3.14, "Float value not equal to 3.14"); Expect_EOF (Stream); end Test_Float_Exponent_Number_Token; procedure Test_Float_Negative_Exponent_Number_Token (Object : in out Test) is Text : constant String := "4e-1"; Stream : aliased Streams.Stream := Streams.Create_Stream (Streams.From_Text (Text)); Token : Tokenizers.Token; begin Tokenizers.Read_Token (Stream, Token); Assert_Kind (Token.Kind, Tokenizers.Float_Token, "Not Float_Token"); Assert (Token.Float_Value = 0.4, "Float value not equal to 0.4"); Expect_EOF (Stream); end Test_Float_Negative_Exponent_Number_Token; -- Array procedure Test_Empty_Array_Tokens (Object : in out Test) is Text : constant String := "[]"; Stream : aliased Streams.Stream := Streams.Create_Stream (Streams.From_Text (Text)); Token : Tokenizers.Token; begin Tokenizers.Read_Token (Stream, Token); Assert_Kind (Token.Kind, Tokenizers.Begin_Array_Token, "Not Begin_Array_Token"); Tokenizers.Read_Token (Stream, Token); Assert_Kind (Token.Kind, Tokenizers.End_Array_Token, "Not End_Array_Token"); Expect_EOF (Stream); end Test_Empty_Array_Tokens; procedure Test_One_Element_Array_Tokens (Object : in out Test) is Text : constant String := "[null]"; Stream : aliased Streams.Stream := Streams.Create_Stream (Streams.From_Text (Text)); Token : Tokenizers.Token; begin Tokenizers.Read_Token (Stream, Token); Assert_Kind (Token.Kind, Tokenizers.Begin_Array_Token, "Not Begin_Array_Token"); -- null Tokenizers.Read_Token (Stream, Token); Assert_Kind (Token.Kind, Tokenizers.Null_Token, "Not Null_Token"); Tokenizers.Read_Token (Stream, Token); Assert_Kind (Token.Kind, Tokenizers.End_Array_Token, "Not End_Array_Token"); Expect_EOF (Stream); end Test_One_Element_Array_Tokens; procedure Test_Two_Elements_Array_Tokens (Object : in out Test) is Text : constant String := "[1,2]"; Stream : aliased Streams.Stream := Streams.Create_Stream (Streams.From_Text (Text)); Token : Tokenizers.Token; begin Tokenizers.Read_Token (Stream, Token); Assert_Kind (Token.Kind, Tokenizers.Begin_Array_Token, "Not Begin_Array_Token"); -- 1 Tokenizers.Read_Token (Stream, Token); Assert_Kind (Token.Kind, Tokenizers.Integer_Token, "Not Integer_Token"); Assert (Token.Integer_Value = 1, "Integer value not equal to 1"); -- , Tokenizers.Read_Token (Stream, Token); Assert_Kind (Token.Kind, Tokenizers.Value_Separator_Token, "Not Value_Separator_Token"); -- 2 Tokenizers.Read_Token (Stream, Token); Assert_Kind (Token.Kind, Tokenizers.Integer_Token, "Not Integer_Token"); Assert (Token.Integer_Value = 2, "Integer value not equal to 2"); Tokenizers.Read_Token (Stream, Token); Assert_Kind (Token.Kind, Tokenizers.End_Array_Token, "Not End_Array_Token"); Expect_EOF (Stream); end Test_Two_Elements_Array_Tokens; -- Object procedure Test_Empty_Object_Tokens (Object : in out Test) is Text : constant String := "{}"; Stream : aliased Streams.Stream := Streams.Create_Stream (Streams.From_Text (Text)); Token : Tokenizers.Token; begin Tokenizers.Read_Token (Stream, Token); Assert_Kind (Token.Kind, Tokenizers.Begin_Object_Token, "Not Begin_Object_Token"); Tokenizers.Read_Token (Stream, Token); Assert_Kind (Token.Kind, Tokenizers.End_Object_Token, "Not End_Object_Token"); Expect_EOF (Stream); end Test_Empty_Object_Tokens; procedure Test_One_Pair_Object_Tokens (Object : in out Test) is Text : constant String := "{""foo"":""bar""}"; Stream : aliased Streams.Stream := Streams.Create_Stream (Streams.From_Text (Text)); Token : Tokenizers.Token; begin Tokenizers.Read_Token (Stream, Token); Assert_Kind (Token.Kind, Tokenizers.Begin_Object_Token, "Not Begin_Object_Token"); -- "foo" Tokenizers.Read_Token (Stream, Token); Assert_Kind (Token.Kind, Tokenizers.String_Token, "Not String_Token"); Assert (Token.String_Offset = 3, String_Offset_Message); Assert (Token.String_Length = 3, String_Length_Message); -- : Tokenizers.Read_Token (Stream, Token); Assert_Kind (Token.Kind, Tokenizers.Name_Separator_Token, "Not Name_Separator_Token"); -- "bar" Tokenizers.Read_Token (Stream, Token); Assert_Kind (Token.Kind, Tokenizers.String_Token, "Not String_Token"); Assert (Token.String_Offset = 9, String_Offset_Message); Assert (Token.String_Length = 3, String_Length_Message); Tokenizers.Read_Token (Stream, Token); Assert_Kind (Token.Kind, Tokenizers.End_Object_Token, "Not End_Object_Token"); Expect_EOF (Stream); end Test_One_Pair_Object_Tokens; procedure Test_Two_Pairs_Object_Tokens (Object : in out Test) is Text : constant String := "{""foo"":true,""bar"":false}"; Stream : aliased Streams.Stream := Streams.Create_Stream (Streams.From_Text (Text)); Token : Tokenizers.Token; begin Tokenizers.Read_Token (Stream, Token); Assert_Kind (Token.Kind, Tokenizers.Begin_Object_Token, "Not Begin_Object_Token"); -- "foo" Tokenizers.Read_Token (Stream, Token); Assert_Kind (Token.Kind, Tokenizers.String_Token, "Not String_Token"); Assert (Token.String_Offset = 3, String_Offset_Message); Assert (Token.String_Length = 3, String_Length_Message); -- : Tokenizers.Read_Token (Stream, Token); Assert_Kind (Token.Kind, Tokenizers.Name_Separator_Token, "Not Name_Separator_Token"); -- true Tokenizers.Read_Token (Stream, Token); Assert_Kind (Token.Kind, Tokenizers.Boolean_Token, "Not Boolean_Token"); Assert (Token.Boolean_Value, "Boolean value not True"); -- , Tokenizers.Read_Token (Stream, Token); Assert_Kind (Token.Kind, Tokenizers.Value_Separator_Token, "Not Value_Separator_Token"); -- "bar" Tokenizers.Read_Token (Stream, Token); Assert_Kind (Token.Kind, Tokenizers.String_Token, "Not String_Token"); Assert (Token.String_Offset = 14, String_Offset_Message); Assert (Token.String_Length = 3, String_Length_Message); -- : Tokenizers.Read_Token (Stream, Token); Assert_Kind (Token.Kind, Tokenizers.Name_Separator_Token, "Not Name_Separator_Token"); -- false Tokenizers.Read_Token (Stream, Token); Assert_Kind (Token.Kind, Tokenizers.Boolean_Token, "Not Boolean_Token"); Assert (not Token.Boolean_Value, "Boolean value not False"); Tokenizers.Read_Token (Stream, Token); Assert_Kind (Token.Kind, Tokenizers.End_Object_Token, "Not End_Object_Token"); Expect_EOF (Stream); end Test_Two_Pairs_Object_Tokens; -- Exceptions procedure Test_Control_Character_String_Exception (Object : in out Test) is LF : Character renames Ada.Characters.Latin_1.LF; Text : constant String := """no" & LF & "newline"""; Stream : aliased Streams.Stream := Streams.Create_Stream (Streams.From_Text (Text)); Token : Tokenizers.Token; begin Tokenizers.Read_Token (Stream, Token); Fail ("Expected Tokenizer_Error"); exception when Tokenizers.Tokenizer_Error => null; end Test_Control_Character_String_Exception; procedure Test_Unexpected_Escaped_Character_String_Exception (Object : in out Test) is Text : constant String := """unexpected\xcharacter"""; Stream : aliased Streams.Stream := Streams.Create_Stream (Streams.From_Text (Text)); Token : Tokenizers.Token; begin Tokenizers.Read_Token (Stream, Token); Fail ("Expected Tokenizer_Error"); exception when Tokenizers.Tokenizer_Error => null; end Test_Unexpected_Escaped_Character_String_Exception; procedure Test_Minus_Number_EOF_Exception (Object : in out Test) is Text : constant String := "-"; Stream : aliased Streams.Stream := Streams.Create_Stream (Streams.From_Text (Text)); Token : Tokenizers.Token; begin Tokenizers.Read_Token (Stream, Token); Fail ("Expected Tokenizer_Error"); exception when Tokenizers.Tokenizer_Error => null; end Test_Minus_Number_EOF_Exception; procedure Test_Minus_Number_Exception (Object : in out Test) is Text : constant String := "-,"; Stream : aliased Streams.Stream := Streams.Create_Stream (Streams.From_Text (Text)); Token : Tokenizers.Token; begin Tokenizers.Read_Token (Stream, Token); Fail ("Expected Tokenizer_Error"); exception when Tokenizers.Tokenizer_Error => null; end Test_Minus_Number_Exception; procedure Test_End_Dot_Number_Exception (Object : in out Test) is Text : constant String := "3."; Stream : aliased Streams.Stream := Streams.Create_Stream (Streams.From_Text (Text)); Token : Tokenizers.Token; begin Tokenizers.Read_Token (Stream, Token); Fail ("Expected Tokenizer_Error"); exception when Tokenizers.Tokenizer_Error => null; end Test_End_Dot_Number_Exception; procedure Test_End_Exponent_Number_Exception (Object : in out Test) is Text : constant String := "1E"; Stream : aliased Streams.Stream := Streams.Create_Stream (Streams.From_Text (Text)); Token : Tokenizers.Token; begin Tokenizers.Read_Token (Stream, Token); Fail ("Expected Tokenizer_Error"); exception when Tokenizers.Tokenizer_Error => null; end Test_End_Exponent_Number_Exception; procedure Test_End_Dot_Exponent_Number_Exception (Object : in out Test) is Text : constant String := "1.E"; Stream : aliased Streams.Stream := Streams.Create_Stream (Streams.From_Text (Text)); Token : Tokenizers.Token; begin Tokenizers.Read_Token (Stream, Token); Fail ("Expected Tokenizer_Error"); exception when Tokenizers.Tokenizer_Error => null; end Test_End_Dot_Exponent_Number_Exception; procedure Test_End_Exponent_Minus_Number_Exception (Object : in out Test) is Text : constant String := "1E-"; Stream : aliased Streams.Stream := Streams.Create_Stream (Streams.From_Text (Text)); Token : Tokenizers.Token; begin Tokenizers.Read_Token (Stream, Token); Fail ("Expected Tokenizer_Error"); exception when Tokenizers.Tokenizer_Error => null; end Test_End_Exponent_Minus_Number_Exception; procedure Test_End_Exponent_One_Digit_Exception (Object : in out Test) is Text : constant String := "1E,"; Stream : aliased Streams.Stream := Streams.Create_Stream (Streams.From_Text (Text)); Token : Tokenizers.Token; begin Tokenizers.Read_Token (Stream, Token); Fail ("Expected Tokenizer_Error"); exception when Tokenizers.Tokenizer_Error => null; end Test_End_Exponent_One_Digit_Exception; procedure Test_End_Exponent_Minus_One_Digit_Exception (Object : in out Test) is Text : constant String := "1E-,"; Stream : aliased Streams.Stream := Streams.Create_Stream (Streams.From_Text (Text)); Token : Tokenizers.Token; begin Tokenizers.Read_Token (Stream, Token); Fail ("Expected Tokenizer_Error"); exception when Tokenizers.Tokenizer_Error => null; end Test_End_Exponent_Minus_One_Digit_Exception; procedure Test_Prefixed_Plus_Number_Exception (Object : in out Test) is Text : constant String := "+42"; Stream : aliased Streams.Stream := Streams.Create_Stream (Streams.From_Text (Text)); Token : Tokenizers.Token; begin Tokenizers.Read_Token (Stream, Token); Fail ("Expected Tokenizer_Error"); exception when Tokenizers.Tokenizer_Error => null; end Test_Prefixed_Plus_Number_Exception; procedure Test_Leading_Zeroes_Integer_Number_Exception (Object : in out Test) is Text : constant String := "-02"; Stream : aliased Streams.Stream := Streams.Create_Stream (Streams.From_Text (Text)); Token : Tokenizers.Token; begin Tokenizers.Read_Token (Stream, Token); Fail ("Expected Tokenizer_Error"); exception when Tokenizers.Tokenizer_Error => null; end Test_Leading_Zeroes_Integer_Number_Exception; procedure Test_Leading_Zeroes_Float_Number_Exception (Object : in out Test) is Text : constant String := "-003.14"; Stream : aliased Streams.Stream := Streams.Create_Stream (Streams.From_Text (Text)); Token : Tokenizers.Token; begin Tokenizers.Read_Token (Stream, Token); Fail ("Expected Tokenizer_Error"); exception when Tokenizers.Tokenizer_Error => null; end Test_Leading_Zeroes_Float_Number_Exception; procedure Test_Incomplete_True_Text_Exception (Object : in out Test) is Text : constant String := "tr"; Stream : aliased Streams.Stream := Streams.Create_Stream (Streams.From_Text (Text)); Token : Tokenizers.Token; begin Tokenizers.Read_Token (Stream, Token); Fail ("Expected Tokenizer_Error"); exception when Tokenizers.Tokenizer_Error => null; end Test_Incomplete_True_Text_Exception; procedure Test_Incomplete_False_Text_Exception (Object : in out Test) is Text : constant String := "f"; Stream : aliased Streams.Stream := Streams.Create_Stream (Streams.From_Text (Text)); Token : Tokenizers.Token; begin Tokenizers.Read_Token (Stream, Token); Fail ("Expected Tokenizer_Error"); exception when Tokenizers.Tokenizer_Error => null; end Test_Incomplete_False_Text_Exception; procedure Test_Incomplete_Null_Text_Exception (Object : in out Test) is Text : constant String := "nul"; Stream : aliased Streams.Stream := Streams.Create_Stream (Streams.From_Text (Text)); Token : Tokenizers.Token; begin Tokenizers.Read_Token (Stream, Token); Fail ("Expected Tokenizer_Error"); exception when Tokenizers.Tokenizer_Error => null; end Test_Incomplete_Null_Text_Exception; procedure Test_Unknown_Keyword_Text_Exception (Object : in out Test) is Text : constant String := "unexpected"; Stream : aliased Streams.Stream := Streams.Create_Stream (Streams.From_Text (Text)); Token : Tokenizers.Token; begin Tokenizers.Read_Token (Stream, Token); Fail ("Expected Tokenizer_Error"); exception when Tokenizers.Tokenizer_Error => null; end Test_Unknown_Keyword_Text_Exception; end Test_Tokenizers;
-- { dg-do run } -- { dg-options "-gnatws" } procedure View_Conversion1 is type Matrix is array (Integer range <>, Integer range <>) of Float; S1 : Matrix (-3 .. -2, 2 .. 3) := ((2.0, -1.0), (-1.0, 2.0)); S2 : Matrix (1 .. 2, 1 .. 2) := S1; S3 : Matrix (2 .. 3, -3 .. -2); S4 : Matrix (1 .. 2, 1 .. 2); function Normal_Last (A : Matrix; N : Natural) return Boolean is begin if A'Last (1) = N and then A'Last (2) = N then return True; else return False; end if; end; procedure Transpose (A : Matrix; B : out Matrix) is N : constant Natural := A'Length (1); subtype Normal_Matrix is Matrix (1 .. N, 1 .. N); begin if not Normal_Last (A, N) or else not Normal_Last (B, N) then Transpose (Normal_Matrix (A), Normal_Matrix (B)); return; end if; for J in 1 .. N loop for K in 1 .. N loop B (J, K) := A (K, J); end loop; end loop; end; begin Transpose (S1, S3); Transpose (S3, S4); if S4 /= S2 then raise Program_Error; end if; end;
-- 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 Trades.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.Containers; use Ada.Containers; with Maps; use Maps; -- begin read only -- end read only package body Trades.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_BuyItems_295d66_e10e97 (BaseItemIndex: BaseCargo_Container.Extended_Index; Amount: String) is begin begin pragma Assert(Amount'Length > 0); null; exception when System.Assertions.Assert_Failure => AUnit.Assertions.Assert (False, "req_sloc(trades.ads:0):Test_BuyItems test requirement violated"); end; GNATtest_Generated.GNATtest_Standard.Trades.BuyItems (BaseItemIndex, Amount); begin pragma Assert(True); null; exception when System.Assertions.Assert_Failure => AUnit.Assertions.Assert (False, "ens_sloc(trades.ads:0:):Test_BuyItems test commitment violated"); end; end Wrap_Test_BuyItems_295d66_e10e97; -- end read only -- begin read only procedure Test_BuyItems_test_buyitems(Gnattest_T: in out Test); procedure Test_BuyItems_295d66_e10e97(Gnattest_T: in out Test) renames Test_BuyItems_test_buyitems; -- id:2.2/295d66b8c191f255/BuyItems/1/0/test_buyitems/ procedure Test_BuyItems_test_buyitems(Gnattest_T: in out Test) is procedure BuyItems (BaseItemIndex: BaseCargo_Container.Extended_Index; Amount: String) renames Wrap_Test_BuyItems_295d66_e10e97; -- end read only pragma Unreferenced(Gnattest_T); BaseIndex: constant Natural := SkyMap(Player_Ship.Sky_X, Player_Ship.Sky_Y).BaseIndex; OldAmount: constant Natural := Sky_Bases(BaseIndex).Cargo(2).Amount; begin if OldAmount = 0 then Sky_Bases(BaseIndex).Cargo(2).Amount := 2; end if; BuyItems(2, "1"); Sky_Bases(BaseIndex).Cargo(2).Amount := OldAmount; Assert(True, "This test can only crash."); -- begin read only end Test_BuyItems_test_buyitems; -- end read only -- begin read only procedure Wrap_Test_SellItems_079195_4009e6 (ItemIndex: Inventory_Container.Extended_Index; Amount: String) is begin begin pragma Assert (ItemIndex in Player_Ship.Cargo.First_Index .. Player_Ship.Cargo.Last_Index and Amount'Length > 0); null; exception when System.Assertions.Assert_Failure => AUnit.Assertions.Assert (False, "req_sloc(trades.ads:0):Test_SellItems test requirement violated"); end; GNATtest_Generated.GNATtest_Standard.Trades.SellItems(ItemIndex, Amount); begin pragma Assert(True); null; exception when System.Assertions.Assert_Failure => AUnit.Assertions.Assert (False, "ens_sloc(trades.ads:0:):Test_SellItems test commitment violated"); end; end Wrap_Test_SellItems_079195_4009e6; -- end read only -- begin read only procedure Test_SellItems_test_sellitems(Gnattest_T: in out Test); procedure Test_SellItems_079195_4009e6(Gnattest_T: in out Test) renames Test_SellItems_test_sellitems; -- id:2.2/0791958f8fd18173/SellItems/1/0/test_sellitems/ procedure Test_SellItems_test_sellitems(Gnattest_T: in out Test) is procedure SellItems (ItemIndex: Inventory_Container.Extended_Index; Amount: String) renames Wrap_Test_SellItems_079195_4009e6; -- end read only pragma Unreferenced(Gnattest_T); OldAmount: constant Positive := Player_Ship.Cargo(2).Amount; begin SellItems(2, "1"); Player_Ship.Cargo(2).Amount := OldAmount; Player_Ship.Crew(2).Payment(2) := 1; Player_Ship.Crew(3).Payment(2) := 4; Player_Ship.Crew(4).Payment(2) := 1; SellItems(2, "1"); Player_Ship.Cargo(2).Amount := OldAmount; Player_Ship.Crew(2).Payment(2) := 0; Player_Ship.Crew(3).Payment(2) := 0; Player_Ship.Crew(4).Payment(2) := 0; Assert(True, "This tests can only crash."); -- begin read only end Test_SellItems_test_sellitems; -- end read only -- begin read only procedure Wrap_Test_GenerateTraderCargo_9d8e19_e2d9dd (ProtoIndex: Unbounded_String) is begin begin pragma Assert (Proto_Ships_Container.Contains(Proto_Ships_List, ProtoIndex)); null; exception when System.Assertions.Assert_Failure => AUnit.Assertions.Assert (False, "req_sloc(trades.ads:0):Test_GenerateTraderCargo test requirement violated"); end; GNATtest_Generated.GNATtest_Standard.Trades.GenerateTraderCargo (ProtoIndex); begin pragma Assert(True); null; exception when System.Assertions.Assert_Failure => AUnit.Assertions.Assert (False, "ens_sloc(trades.ads:0:):Test_GenerateTraderCargo test commitment violated"); end; end Wrap_Test_GenerateTraderCargo_9d8e19_e2d9dd; -- end read only -- begin read only procedure Test_GenerateTraderCargo_test_generatetradercargo (Gnattest_T: in out Test); procedure Test_GenerateTraderCargo_9d8e19_e2d9dd (Gnattest_T: in out Test) renames Test_GenerateTraderCargo_test_generatetradercargo; -- id:2.2/9d8e192e181a5de1/GenerateTraderCargo/1/0/test_generatetradercargo/ procedure Test_GenerateTraderCargo_test_generatetradercargo (Gnattest_T: in out Test) is procedure GenerateTraderCargo(ProtoIndex: Unbounded_String) renames Wrap_Test_GenerateTraderCargo_9d8e19_e2d9dd; -- end read only pragma Unreferenced(Gnattest_T); begin GenerateTraderCargo(To_Unbounded_String("96")); Assert(TraderCargo.Length > 0, "Failed to generate cargo for trade."); -- begin read only end Test_GenerateTraderCargo_test_generatetradercargo; -- 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 Trades.Test_Data.Tests;
----------------------------------------------------------------------- -- gen-model-enums -- Enum definitions -- Copyright (C) 2011, 2012, 2018 Stephane Carrez -- Written by Stephane Carrez (Stephane.Carrez@gmail.com) -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. ----------------------------------------------------------------------- with Ada.Strings.Unbounded; with Util.Beans.Objects; with Gen.Model.List; with Gen.Model.Mappings; with Gen.Model.Packages; package Gen.Model.Enums is use Ada.Strings.Unbounded; type Enum_Definition; type Enum_Definition_Access is access all Enum_Definition'Class; -- ------------------------------ -- Enum value definition -- ------------------------------ type Value_Definition is new Definition with record Number : Natural := 0; Enum : Enum_Definition_Access; end record; type Value_Definition_Access is access all Value_Definition'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 : Value_Definition; Name : String) return Util.Beans.Objects.Object; -- Compare two enum literals. function "<" (Left, Right : in Value_Definition_Access) return Boolean; package Value_List is new Gen.Model.List (T => Value_Definition, T_Access => Value_Definition_Access); -- ------------------------------ -- Table Definition -- ------------------------------ type Enum_Definition is new Mappings.Mapping_Definition with record Values : aliased Value_List.List_Definition; Values_Bean : Util.Beans.Objects.Object; Package_Def : Gen.Model.Packages.Package_Definition_Access; Type_Name : Unbounded_String; Nullable_Type : Unbounded_String; Pkg_Name : Unbounded_String; Sql_Type : Unbounded_String; end record; -- 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 : Enum_Definition; Name : String) return Util.Beans.Objects.Object; -- Prepare the generation of the model. overriding procedure Prepare (O : in out Enum_Definition); -- Initialize the table definition instance. overriding procedure Initialize (O : in out Enum_Definition); -- Add an enum value to this enum definition and return the new value. procedure Add_Value (Enum : in out Enum_Definition; Name : in String; Value : out Value_Definition_Access); -- Create an enum with the given name. function Create_Enum (Name : in Unbounded_String) return Enum_Definition_Access; end Gen.Model.Enums;
package Version with Preelaborate is Current : constant String := "0.0.1"; Name : constant String := "WebsiteGenerator"; Link : constant String := "https://github.com/bracke/websitegenerator"; private end Version;
procedure Array_Test is A, B : array (1..20) of Integer; -- Ada array indices may begin at any value, not just 0 or 1 C : array (-37..20) of integer -- Ada arrays may be indexed by enumerated types, which are -- discrete non-numeric types type Days is (Mon, Tue, Wed, Thu, Fri, Sat, Sun); type Activities is (Work, Fish); type Daily_Activities is array(Days) of Activities; This_Week : Daily_Activities := (Mon..Fri => Work, Others => Fish); -- Or any numeric type type Fingers is range 1..4; -- exclude thumb type Fingers_Extended_Type is array(fingers) of Boolean; Fingers_Extended : Fingers_Extended_Type; -- Array types may be unconstrained. The variables of the type -- must be constrained type Arr is array (Integer range <>) of Integer; Uninitialized : Arr (1 .. 10); Initialized_1 : Arr (1 .. 20) := (others => 1); Initialized_2 : Arr := (1 .. 30 => 2); Const : constant Arr := (1 .. 10 => 1, 11 .. 20 => 2, 21 | 22 => 3); Centered : Arr (-50..50) := (0 => 1, Others => 0); Result : Integer begin A := (others => 0); -- Assign whole array B := (1 => 1, 2 => 1, 3 => 2, others => 0); -- Assign whole array, different values A (1) := -1; -- Assign individual element A (2..4) := B (1..3); -- Assign a slice A (3..5) := (2, 4, -1); -- Assign a constant slice A (3..5) := A (4..6); -- It is OK to overlap slices when assigned Fingers_Extended'First := False; -- Set first element of array Fingers_Extended'Last := False; -- Set last element of array end Array_Test;
with Ada.Text_IO; use Ada.Text_IO; procedure Test is function F return character is begin return 'a'; end F; function G(C: Character) return character is begin return c; end G; begin Put(F); New_Line; Put(G('b')); New_Line; Put(G(F)); New_Line; end;
with Interfaces.C; use Interfaces.C; with SDL_SDL_events_h; use SDL_SDL_events_h; with SDL_SDL_keysym_h; use SDL_SDL_keysym_h; package body Keyboard is Is_Pressed : array (Key_Kind) of Boolean := (others => False); ------------ -- Update -- ------------ procedure Update is Evt : aliased SDL_Event; begin while SDL_PollEvent (Evt'Access) /= 0 loop if Evt.c_type = SDL_KEYDOWN or else Evt.c_type = SDL_KEYUP then case Evt.key.keysym.sym is when SDLK_LEFT => Is_Pressed (Left) := Evt.c_type = SDL_KEYDOWN; when SDLK_RIGHT => Is_Pressed (Right) := Evt.c_type = SDL_KEYDOWN; when SDLK_DOWN => Is_Pressed (Down) := Evt.c_type = SDL_KEYDOWN; when SDLK_UP => Is_Pressed (Up) := Evt.c_type = SDL_KEYDOWN; when SDLK_ESCAPE => Is_Pressed (Esc) := Evt.c_type = SDL_KEYDOWN; when others => null; end case; end if; end loop; end Update; ------------- -- Pressed -- ------------- function Pressed (Key : Key_Kind) return Boolean is (Is_Pressed (Key)); end Keyboard;
------------------------------------------------------------------------------ -- Copyright (C) 2017-2020 by Heisenbug Ltd. (gh+saatana@heisenbug.eu) -- -- This work is free. You can redistribute it and/or modify it under the -- terms of the Do What The Fuck You Want To Public License, Version 2, -- as published by Sam Hocevar. See the LICENSE file for more details. ------------------------------------------------------------------------------ pragma License (Unrestricted); with Ada.Command_Line; with Ada.Text_IO; with Saatana.Crypto.Phelix.Test_Vectors; procedure Test_Phelix with SPARK_Mode => Off is pragma Assertion_Policy (Check); use type Saatana.Crypto.MAC_Stream; use type Saatana.Crypto.Stream_Offset; Num_Tests : Natural := 0; Num_Succeeded : Natural := 0; procedure Add_Test (Passed : in Boolean); procedure Add_Test (Passed : in Boolean) is begin Num_Tests := Num_Tests + 1; Num_Succeeded := (if Passed then Num_Succeeded + 1 else Num_Succeeded); if not Passed then Ada.Text_IO.Put_Line ("<ERR> Test" & Natural'Image (Num_Tests) & " failed!"); end if; end Add_Test; function Image (S : in Saatana.Crypto.General_Stream) return String; function Image (S : in Saatana.Crypto.General_Stream) return String is type Character_Lookup is array (Saatana.Crypto.Byte range <>) of Character; Result : String (1 .. S'Length * 2); Hex_Char : constant Character_Lookup (0 .. 15) := "0123456789ABCDEF"; use type Saatana.Crypto.Byte; begin for I in S'Range loop Result (Result'First + Natural (I - S'First) * 2) := Hex_Char (S (I) / 16); Result (Result'First + Natural (I - S'First) * 2 + 1) := Hex_Char (S (I) mod 16); end loop; return Result; end Image; Verbose : Boolean := False; KAT_Only : Boolean := False; begin Evaluate_Command_Line : for Number in 1 .. Ada.Command_Line.Argument_Count loop Check_Argument : declare Argument : constant String := Ada.Command_Line.Argument (Number => Number); begin if Argument = "--verbose" then Verbose := True; elsif Argument = "--kat-only" then KAT_Only := True; else Ada.Text_IO.Put_Line (File => Ada.Text_IO.Standard_Error, Item => "Unrecognized command line parameter """ & Argument & """ ignored."); end if; end Check_Argument; end loop Evaluate_Command_Line; Ada.Text_IO.Put_Line ("Running KAT (Known Answers Tests)..."); KAT_Loop : for T of Saatana.Crypto.Phelix.Test_Vectors.KAT loop Test_Encrypt_Decrypt : declare use type Saatana.Crypto.Ciphertext_Stream; use type Saatana.Crypto.Plaintext_Stream; use type Saatana.Crypto.Phelix.MAC_Size_32; Mac_Len : constant Saatana.Crypto.Phelix.MAC_Size_32 := 8 * T.MAC.all'Length; This : Saatana.Crypto.Phelix.Context; begin Saatana.Crypto.Phelix.Setup_Key (This => This, Key => T.Key.all, Mac_Size => Mac_Len); Test_Encrypt_Decrypt_Bytes : declare Result_Cipher : Saatana.Crypto.Ciphertext_Stream (T.Plaintext.all'Range); Result_Plaintext : Saatana.Crypto.Plaintext_Stream (T.Plaintext.all'Range); Result_MAC : Saatana.Crypto.MAC_Stream (0 .. Saatana.Crypto.Stream_Offset (Mac_Len) / 8 - 1); begin Saatana.Crypto.Phelix.Setup_Nonce (This => This, Nonce => T.Nonce.all); Saatana.Crypto.Phelix.Process_AAD (This => This, Aad => T.Aad.all); Saatana.Crypto.Phelix.Encrypt_Bytes (This => This, Source => T.Plaintext.all, Destination => Result_Cipher); Saatana.Crypto.Phelix.Finalize (This => This, Mac => Result_MAC); if Verbose then -- KAT input. Ada.Text_IO.Put_Line ("Key : " & Image (Saatana.Crypto.General_Stream (T.Key.all))); Ada.Text_IO.Put_Line ("Nonce : " & Image (Saatana.Crypto.General_Stream (T.Nonce.all))); Ada.Text_IO.Put_Line ("AAD : " & Image (Saatana.Crypto.General_Stream (T.Aad.all))); Ada.Text_IO.Put_Line ("Plaintext : " & Image (Saatana.Crypto.General_Stream (T.Plaintext.all))); -- Computed output, being compared with expected from KAT vector. Ada.Text_IO.Put_Line ("Ciphertext: " & Image (Saatana.Crypto.General_Stream (Result_Cipher))); Ada.Text_IO.Put_Line ("MAC : " & Image (Saatana.Crypto.General_Stream (Result_MAC))); Ada.Text_IO.New_Line; end if; Add_Test (Result_Cipher = T.Cipher.all); Add_Test (Result_MAC = T.MAC.all); Saatana.Crypto.Phelix.Setup_Nonce (This => This, Nonce => T.Nonce.all); Saatana.Crypto.Phelix.Process_AAD (This => This, Aad => T.Aad.all); Saatana.Crypto.Phelix.Decrypt_Bytes (This => This, Source => T.Cipher.all, Destination => Result_Plaintext); Saatana.Crypto.Phelix.Finalize (This => This, Mac => Result_MAC); Add_Test (Result_Plaintext = T.Plaintext.all); Add_Test (Result_MAC = T.MAC.all); -- Same as above, but with byte-for-byte en/de-cryption. This -- is done to verify that the implementation actually works as a -- stream cipher. -- NOTE: Phelix does still require processing of 32-bit words in -- each step, so we cannot exactly call it byte-for-byte -- processing. If an actual implementation needs to encrypt -- a stream in a byte-for-byte manner, it needs to store up -- to four bytes of the plaintext or cipher stream before -- calling Encrypt/Decrypt_Bytes. Saatana.Crypto.Phelix.Setup_Nonce (This => This, Nonce => T.Nonce.all); Saatana.Crypto.Phelix.Process_AAD (This => This, Aad => T.Aad.all); Loop_Over_Plaintext_Bytes : for I in T.Plaintext.all'Range loop if I mod 4 = 0 then Process_Plaintext_Word : declare Last_Byte : constant Saatana.Crypto.Stream_Index := Saatana.Crypto.Stream_Index'Min (I + 3, T.Plaintext.all'Last); begin -- Process only on word boundaries. Saatana.Crypto.Phelix.Encrypt_Bytes (This => This, Source => T.Plaintext.all (I .. Last_Byte), Destination => Result_Cipher (I .. Last_Byte)); end Process_Plaintext_Word; end if; end loop Loop_Over_Plaintext_Bytes; Saatana.Crypto.Phelix.Finalize (This => This, Mac => Result_MAC); Add_Test (Result_Cipher = T.Cipher.all); Add_Test (Result_MAC = T.MAC.all); Saatana.Crypto.Phelix.Setup_Nonce (This => This, Nonce => T.Nonce.all); Saatana.Crypto.Phelix.Process_AAD (This => This, Aad => T.Aad.all); Loop_Over_Ciphertext_Bytes : for I in T.Cipher.all'Range loop if I mod 4 = 0 then Process_Ciphertext_Word : declare Last_Byte : constant Saatana.Crypto.Stream_Index := Saatana.Crypto.Stream_Index'Min (I + 3, T.Plaintext.all'Last); begin Saatana.Crypto.Phelix.Decrypt_Bytes (This => This, Source => T.Cipher.all (I .. Last_Byte), Destination => Result_Plaintext (I .. Last_Byte)); end Process_Ciphertext_Word; end if; end loop Loop_Over_Ciphertext_Bytes; Saatana.Crypto.Phelix.Finalize (This => This, Mac => Result_MAC); Add_Test (Result_Plaintext = T.Plaintext.all); Add_Test (Result_MAC = T.MAC.all); end Test_Encrypt_Decrypt_Bytes; Test_Encrypt_Decrypt_Packets : declare Enc_Packet : Saatana.Crypto.Ciphertext_Stream (0 .. T.Plaintext.all'Length + T.Aad.all'Length - 1); Dec_Packet : Saatana.Crypto.Plaintext_Stream (0 .. T.Plaintext.all'Length + T.Aad.all'Length - 1); Result_MAC : Saatana.Crypto.MAC_Stream (0 .. Saatana.Crypto.Stream_Offset (Mac_Len) / 8 - 1); begin Saatana.Crypto.Phelix.Encrypt_Packet (This => This, Nonce => T.Nonce.all, Header => T.Aad.all, Payload => T.Plaintext.all, Packet => Enc_Packet, Mac => Result_MAC); Add_Test (Saatana.Crypto.Ciphertext_Stream (T.Aad.all) & T.Cipher.all = Enc_Packet); Add_Test (Result_MAC = T.MAC.all); Saatana.Crypto.Phelix.Decrypt_Packet (This => This, Nonce => T.Nonce.all, Header => T.Aad.all, Payload => T.Cipher.all, Packet => Dec_Packet, Mac => Result_MAC); Add_Test (T.Aad.all & T.Plaintext.all = Dec_Packet); Add_Test (Result_MAC = T.MAC.all); end Test_Encrypt_Decrypt_Packets; end Test_Encrypt_Decrypt; end loop KAT_Loop; if not KAT_Only then Ada.Text_IO.Put_Line ("Running additional ""Transmit"" tests..."); Transmit_Tests : declare KEY_LENGTH : constant := Saatana.Crypto.Phelix.Max_Key_Size / 8; MAC_LENGTH : constant := Saatana.Crypto.Phelix.Max_MAC_Size / 8; NONCE_LENGTH : constant := Saatana.Crypto.Phelix.Max_Nonce_Size / 8; NONCE_FIRST : constant Saatana.Crypto.Stream_Offset := 0; NONCE_LAST : constant Saatana.Crypto.Stream_Offset := NONCE_FIRST + NONCE_LENGTH - 1; MAC_FIRST : constant Saatana.Crypto.Stream_Offset := NONCE_LAST + 1; MAC_LAST : constant Saatana.Crypto.Stream_Offset := MAC_FIRST + MAC_LENGTH - 1; EMPTY : constant Saatana.Crypto.General_Stream := (1 .. 0 => 0); use type Saatana.Crypto.Byte; use type Saatana.Crypto.Ciphertext_Stream; use type Saatana.Crypto.Key_Stream; use type Saatana.Crypto.Nonce_Stream; use type Saatana.Crypto.Phelix.MAC_Size_32; procedure Send_Nonce (Key : in Saatana.Crypto.Key_Stream; Nonce : in Saatana.Crypto.Nonce_Stream; Packet : out Saatana.Crypto.Ciphertext_Stream); procedure Receive_Nonce (Key : in Saatana.Crypto.Key_Stream; Packet : in Saatana.Crypto.Ciphertext_Stream; Authenticated : out Boolean); procedure Receive_Nonce (Key : in Saatana.Crypto.Key_Stream; Packet : in Saatana.Crypto.Ciphertext_Stream; Authenticated : out Boolean) is Ctx : Saatana.Crypto.Phelix.Context; Mac : Saatana.Crypto.MAC_Stream (0 .. MAC_LENGTH - 1); Nonce : constant Saatana.Crypto.Nonce_Stream := Saatana.Crypto.Nonce_Stream (Packet (NONCE_FIRST .. NONCE_LAST)); Received_Nonce : Saatana.Crypto.Nonce_Stream (0 .. NONCE_LENGTH - 1); begin Saatana.Crypto.Phelix.Setup_Key (This => Ctx, Key => Key, Mac_Size => MAC_LENGTH * 8); -- Verify received packet. Saatana.Crypto.Phelix.Decrypt_Packet (This => Ctx, Nonce => Nonce, Header => Saatana.Crypto.Plaintext_Stream (Nonce), Payload => Saatana.Crypto.Ciphertext_Stream (EMPTY), Packet => Saatana.Crypto.Plaintext_Stream (Received_Nonce), Mac => Mac); -- MAC must match, otherwise someone tampered with our packet. Authenticated := Mac = Saatana.Crypto.MAC_Stream (Packet (MAC_FIRST .. MAC_LAST)); end Receive_Nonce; procedure Send_Nonce (Key : in Saatana.Crypto.Key_Stream; Nonce : in Saatana.Crypto.Nonce_Stream; Packet : out Saatana.Crypto.Ciphertext_Stream) is Ctx : Saatana.Crypto.Phelix.Context; begin Saatana.Crypto.Phelix.Setup_Key (This => Ctx, Key => Key, Mac_Size => MAC_LENGTH * 8); -- Transmit that Nonce to the client. Saatana.Crypto.Phelix.Encrypt_Packet (This => Ctx, Nonce => Nonce, Header => Saatana.Crypto.Plaintext_Stream (Nonce), Payload => Saatana.Crypto.Plaintext_Stream (EMPTY), Packet => Packet (NONCE_FIRST .. NONCE_LAST), Mac => Saatana.Crypto.MAC_Stream (Packet (MAC_FIRST .. MAC_LAST))); end Send_Nonce; Key : Saatana.Crypto.Key_Stream (0 .. KEY_LENGTH - 1); Nonce : Saatana.Crypto.Nonce_Stream (0 .. NONCE_LENGTH - 1); Packet : Saatana.Crypto.Ciphertext_Stream (NONCE_FIRST .. MAC_LAST); Authenticated : Boolean; begin -- Communication setup. Key := (others => 0); -- Generate random/unique nonce. Nonce := (others => 0); Check_MAC_Handling : for I in 1 .. 1024 loop Send_Nonce (Key => Key, Nonce => Nonce, Packet => Packet); if Verbose then Ada.Text_IO.Put_Line ("Key : " & Image (Saatana.Crypto.General_Stream (Key))); Ada.Text_IO.Put_Line ("Nonce : " & Image (Saatana.Crypto.General_Stream (Nonce))); Ada.Text_IO.Put_Line ("Packet: " & Image (Saatana.Crypto.General_Stream (Packet))); Ada.Text_IO.New_Line; end if; -- Check if the MAC matches with whatever has been sent. Receive_Nonce (Key => Key, Packet => Packet, Authenticated => Authenticated); Add_Test (Authenticated); -- Tamper with the packet. Authentication should fail now. Receive_Nonce (Key => Key, Packet => (Packet (Packet'First) xor 1) & Packet (Packet'First + 1 .. Packet'Last), Authenticated => Authenticated); Add_Test (not Authenticated); -- Use Nonce and MAC as new Key and increment the nonce. Key := Saatana.Crypto.Key_Stream (Packet (MAC_FIRST .. MAC_LAST)) & Key (NONCE_FIRST .. NONCE_LAST); -- "Randomly" advance Nonce. -- -- We take the current key stream, null out its two low order bytes, -- and the result is being added Key (0) * Key (1) times to Nonce to -- create a new seemingly random Nonce. Shuffle_Nonce : declare Operand : constant Saatana.Crypto.Nonce_Stream := Saatana.Crypto.Nonce_Stream (Key (Key'First .. Key'First + 13) & (14 .. NONCE_LENGTH - 1 => 0)); begin Loop_For_First_Byte_Of_Key : for J in 1 .. Key (Key'First) loop Loop_For_Second_Byte_Of_Key : for K in 1 .. Key (Key'First + 1) loop Nonce := Nonce + Operand; end loop Loop_For_Second_Byte_Of_Key; end loop Loop_For_First_Byte_Of_Key; end Shuffle_Nonce; end loop Check_MAC_Handling; -- Check for any regressions. If, after all this Nonce shuffling above, -- the last packet is still the expected one, we are good. Add_Test (Image (Saatana.Crypto.General_Stream (Packet)) = "8F636CA7CC87C0AC88B35964B605E0005A586B0519BA64C6245C8724D3BEDAF1"); end Transmit_Tests; end if; -- KAT only requested Ada.Text_IO.Put_Line ("Test results:" & Natural'Image (Num_Succeeded) & " out of" & Natural'Image (Num_Tests) & " succeeded."); Ada.Text_IO.Put_Line (if Num_Tests = Num_Succeeded then "<OK>" else "<FAILED>"); Ada.Command_Line.Set_Exit_Status (Code => (if Num_Tests = Num_Succeeded then Ada.Command_Line.Success else Ada.Command_Line.Failure)); end Test_Phelix;
with HAL; use HAL; package Random is function Next return UInt16; function In_Range (First, Last : Natural) return Natural; end Random;
with Semantica.Declsc3a, Pilas, Decls.Dgenerals; use Semantica.Declsc3a; package Semantica.gci is Camp_Nul : constant Camp := (Const, Var_Nul); type T_Param is record Base, Despl : num_Var; end record; procedure Genera (Instr : in tInstruccio; C1 : in Camp := Camp_Nul; C2 : in Camp := Camp_Nul; C3 : in Camp := Camp_Nul); procedure Inicia_Generacio (nomFitxer : in String); procedure Gci_Decprocediment (A : in Pnode); procedure gci_Programa (A : in Pnode); procedure Gci_Encap (A : in Pnode; I : in Id_Nom); procedure gci_Pencap (A : in Pnode); procedure gci_Param (A : in Pnode); procedure gci_Declaracions (A : in Pnode); procedure gci_Decvar (A : in Pnode); procedure gci_Declsvar (A : in Pnode); procedure gci_Decconst (A : in Pnode); procedure gci_Deccol (A : in Pnode); procedure gci_Pcoleccio (A : in Pnode; base: in out Valor; Idarray : out Id_nom); procedure gci_Bloc (A : in Pnode); procedure Gci_Assignacio (Idref, Iddref, Idrexp, Iddexp: in num_var); --Procediments procedure gci_Referencia_Proc (A : in Pnode; Idproc : out num_proc); procedure gci_Ref_Pri (A : in Pnode; Idproc : out num_proc); procedure gci_Identificador (A : in Pnode; Idres, Iddesp: out num_var; Idtipus : out Id_Nom); procedure gci_Constant (A : in Pnode; Idres : out Num_var); procedure gci_Expressio (A : in Pnode; Idr, Idd: out num_var); procedure gci_Expressioc (A : in Pnode; Idres,Idresdesp: out num_var); procedure gci_Exp_Relacional (IdResE, IdResD, IddespE, IddespD : in num_var; IdResultExp, IddespExp : out num_var; Op : in Operacio); procedure gci_Exp_Logica (IdResE, IdResD, IddespE, IddespD : in num_var; IdResultExp, IddespExp : out num_var; Op : in Operacio); procedure gci_Exp_Aritmetica (IdResE, IdResD, IddespE, IddespD : in num_var; IdResultExp, IddespExp : out num_var; Op : in Operacio); procedure gci_Expressiou (A : in Pnode; Idr, Idd : out num_var); procedure gci_Exp_Negacio (idRes, Iddesp : in num_var; IdresultExp, IddespExp : out num_var); procedure gci_Exp_Neglogica (idRes, Iddesp : in num_var; IdresultExp, IddespExp : out num_var); procedure gci_Referencia_Var (A : in Pnode; Idres, Iddesp: out Num_Var; Idtipus : out Id_Nom); --Arrays procedure gci_Ref_Pri (A : in Pnode; Idres, Iddesp, Idbase : out Num_var; Idtipus : out Id_Nom; It_Idx : out Cursor_Idx); procedure gci_Ref_Rec (A : in Pnode; Idres, Iddesp: out num_var; Idtipus : out Id_Nom); procedure gci_Sconds (A : in Pnode); procedure gci_Scondc (A : in Pnode); procedure gci_Srep (A : in Pnode); procedure Calcula_Despls; private Nprofunditat : nprof; end Semantica.gci;
-- DECLS-DTSIMBOLS.ads -- Declaracions de taula de simbols with Decls.Dtdesc, Decls.Dgenerals, Decls.D_Taula_De_Noms, Ada.Text_IO; use Decls.Dtdesc, Decls.Dgenerals, Decls.D_Taula_De_Noms, Ada.Text_IO; package Decls.Dtsimbols is --pragma pure; type Tsimbols is private; type Ttsimbols is array (Num_Proc) of Tsimbols; --Serveix per al joc de proves type Cursor_Idx is new Rang_Despl; type Cursor_Arg is new Rang_Despl; -- Operacions -- VERSIO 1: llenguatge simple sense estructura -- de blocs estil Fortran. procedure Printts (Ts : in Tsimbols; Tn : in Taula_De_Noms); procedure Tbuida (Ts : out Tsimbols); procedure posa (ts : in out tsimbols; id : in id_nom; d : in descrip; e : out boolean); function cons (ts : in tsimbols; id : in id_nom) return descrip; -- VERSIO 2: Normal, llenguatge amb blocs -- estil Pascal. procedure entrabloc (ts : in out tsimbols); procedure surtbloc (ts : in out tsimbols; tn : in taula_de_noms); -- VERSIO 3: Blocs mes records. procedure posacamp (ts : in out tsimbols; idr : in id_nom; idc : in id_nom; d : in descrip; e : out boolean); function conscamp (ts : in tsimbols; idr : in id_nom; idc : in id_nom) return descrip; -- VERSIO 4: Arrays. procedure posa_idx (ts : in out tsimbols; ida : in id_nom; idi : in id_nom; e : out boolean); function primer_idx (ts : in tsimbols; ida : in id_nom) return cursor_idx; function idx_valid (ci : in cursor_idx) return boolean; function succ_idx (ts : in tsimbols; ci : in cursor_idx) return cursor_idx; function cons_idx (ts : in tsimbols; ci : in cursor_idx) return id_nom; -- VERSIO 5: Procediments procedure posa_arg (ts : in out tsimbols; idp : in id_nom; ida : in id_nom; da : in descrip; e : out boolean); function primer_arg (ts : in tsimbols; idp : in id_nom) return cursor_arg; function Succ_Arg (ts : in tsimbols; ca : in cursor_arg) return cursor_arg; function arg_valid (Ca : in Cursor_arg) return boolean; procedure cons_arg (ts : in tsimbols; ca : in cursor_arg; ida : out id_nom; dn : out descrip); procedure actualitza (ts : in out tsimbols; id : in id_nom; d : in descrip); private type tipus_descripcio is record np : nprof; d : descrip; s : rang_despl; end record; type tipus_expansio is record np : nprof; d : descrip; id : id_nom; s : rang_despl; end record; type taula_ambits is array (1 .. nprof'Last) of rang_despl; type taula_expansio is array (1 .. rang_despl'Last) of tipus_expansio; type taula_desc is array (1 .. id_nom'Last) of tipus_descripcio; type tsimbols is record tdesc : taula_desc; texp : taula_expansio; tambit : taula_ambits; prof : nprof; end record; end Decls.Dtsimbols;
-- SipHash.Discrete -- Implementing SipHash over a generic (relatively small) discrete type -- Copyright (c) 2015, James Humphry - see LICENSE file for details -- This generic function will calculate SipHash over arrays such as the standard -- String type, a discrete type indexed by an integer type. The range of values -- of the discrete type needs to fit in 8 bits. pragma SPARK_Mode; generic type T is (<>); type T_Index is range <>; type T_Array is array (T_Index range <>) of T; type Hash_Type is mod <>; function SipHash.Discrete (m : T_Array) return Hash_Type with Global => (Input => Initial_Hash_State);
-- Copyright (C) 2019 Thierry Rascle <thierr26@free.fr> -- MIT license. Please refer to the LICENSE file. with Apsepp.Generic_Fixture, Apsepp.Generic_Shared_Instance; package Apsepp_Shared_Instance_Test_Fixture is procedure Increment_Lock_Count; procedure Increment_Unlock_Count; procedure CB; type Shared_Instance_Test_Fixture is tagged limited null record; type Shared_Instance_Test_Fixture_Access is not null access all Shared_Instance_Test_Fixture; not overriding procedure Reset (Obj : Shared_Instance_Test_Fixture); not overriding function Lock_Count (Obj : Shared_Instance_Test_Fixture) return Natural; not overriding function Unlock_Count (Obj : Shared_Instance_Test_Fixture) return Natural; not overriding function CB_Calls_Count (Obj : Shared_Instance_Test_Fixture) return Natural; function Allocate return Shared_Instance_Test_Fixture_Access is (new Shared_Instance_Test_Fixture'(null record)); package Shared_Instance_T_F is new Apsepp.Generic_Fixture (Fixture_Type => Shared_Instance_Test_Fixture, Fixture_Type_Access => Shared_Instance_Test_Fixture_Access, Default_Allocator => Allocate); function Instance return Shared_Instance_Test_Fixture_Access renames Shared_Instance_T_F.Instance; type SIFLI_Interfa is limited interface; not overriding function Primitive (Obj : SIFLI_Interfa) return Character is abstract; type SIFLI_Concrete_1 is limited new SIFLI_Interfa with null record; overriding function Primitive (Obj : SIFLI_Concrete_1) return Character is ('1'); SIFLI_Concrete_1_Instance : aliased SIFLI_Concrete_1; type SIFLI_Concrete_2 is limited new SIFLI_Interfa with null record; overriding function Primitive (Obj : SIFLI_Concrete_2) return Character is ('2'); not overriding function Allocate_SIFLI_Concrete_2 return SIFLI_Concrete_2 is (null record); SIFLI_Concrete_2_Instance : aliased SIFLI_Concrete_2; package SIFLI_Shared_Instance_L is new Apsepp.Generic_Shared_Instance (Instance_Ancestor_Type => SIFLI_Interfa, Lock_CB => Increment_Lock_Count'Access); function Allocate_SIFLI_Concrete_1_L return SIFLI_Shared_Instance_L.Instance_Type_Access is (new SIFLI_Concrete_1'(null record)); function Allocate_SIFLI_Concrete_2_L return SIFLI_Shared_Instance_L.Instance_Type_Access is (new SIFLI_Concrete_2'(null record)); package SIFLI_Shared_Instance_U is new Apsepp.Generic_Shared_Instance (Instance_Ancestor_Type => SIFLI_Interfa, Unlock_CB => Increment_Unlock_Count'Access); function Allocate_SIFLI_Concrete_1_U return SIFLI_Shared_Instance_U.Instance_Type_Access is (new SIFLI_Concrete_1'(null record)); function Allocate_SIFLI_Concrete_2_U return SIFLI_Shared_Instance_U.Instance_Type_Access is (new SIFLI_Concrete_2'(null record)); end Apsepp_Shared_Instance_Test_Fixture;
-- -- Copyright (C) 2019, AdaCore -- -- This spec has been automatically generated from ATSAMV71Q21.svd pragma Ada_2012; pragma Style_Checks (Off); with System; package Interfaces.SAM.PMC is pragma Preelaborate; pragma No_Elaboration_Code_All; --------------- -- Registers -- --------------- subtype PMC_PMC_SCER_USBCLK_Field is Interfaces.SAM.Bit; -- PMC_PMC_SCER_PCK array element subtype PMC_PMC_SCER_PCK_Element is Interfaces.SAM.Bit; -- PMC_PMC_SCER_PCK array type PMC_PMC_SCER_PCK_Field_Array is array (0 .. 6) of PMC_PMC_SCER_PCK_Element with Component_Size => 1, Size => 7; -- Type definition for PMC_PMC_SCER_PCK type PMC_PMC_SCER_PCK_Field (As_Array : Boolean := False) is record case As_Array is when False => -- PCK as a value Val : Interfaces.SAM.UInt7; when True => -- PCK as an array Arr : PMC_PMC_SCER_PCK_Field_Array; end case; end record with Unchecked_Union, Size => 7; for PMC_PMC_SCER_PCK_Field use record Val at 0 range 0 .. 6; Arr at 0 range 0 .. 6; end record; -- System Clock Enable Register type PMC_PMC_SCER_Register is record -- unspecified Reserved_0_4 : Interfaces.SAM.UInt5 := 16#0#; -- Write-only. Enable USB FS Clock USBCLK : PMC_PMC_SCER_USBCLK_Field := 16#0#; -- unspecified Reserved_6_7 : Interfaces.SAM.UInt2 := 16#0#; -- Write-only. Programmable Clock 0 Output Enable PCK : PMC_PMC_SCER_PCK_Field := (As_Array => False, Val => 16#0#); -- unspecified Reserved_15_31 : Interfaces.SAM.UInt17 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for PMC_PMC_SCER_Register use record Reserved_0_4 at 0 range 0 .. 4; USBCLK at 0 range 5 .. 5; Reserved_6_7 at 0 range 6 .. 7; PCK at 0 range 8 .. 14; Reserved_15_31 at 0 range 15 .. 31; end record; subtype PMC_PMC_SCDR_USBCLK_Field is Interfaces.SAM.Bit; -- PMC_PMC_SCDR_PCK array element subtype PMC_PMC_SCDR_PCK_Element is Interfaces.SAM.Bit; -- PMC_PMC_SCDR_PCK array type PMC_PMC_SCDR_PCK_Field_Array is array (0 .. 6) of PMC_PMC_SCDR_PCK_Element with Component_Size => 1, Size => 7; -- Type definition for PMC_PMC_SCDR_PCK type PMC_PMC_SCDR_PCK_Field (As_Array : Boolean := False) is record case As_Array is when False => -- PCK as a value Val : Interfaces.SAM.UInt7; when True => -- PCK as an array Arr : PMC_PMC_SCDR_PCK_Field_Array; end case; end record with Unchecked_Union, Size => 7; for PMC_PMC_SCDR_PCK_Field use record Val at 0 range 0 .. 6; Arr at 0 range 0 .. 6; end record; -- System Clock Disable Register type PMC_PMC_SCDR_Register is record -- unspecified Reserved_0_4 : Interfaces.SAM.UInt5 := 16#0#; -- Write-only. Disable USB FS Clock USBCLK : PMC_PMC_SCDR_USBCLK_Field := 16#0#; -- unspecified Reserved_6_7 : Interfaces.SAM.UInt2 := 16#0#; -- Write-only. Programmable Clock 0 Output Disable PCK : PMC_PMC_SCDR_PCK_Field := (As_Array => False, Val => 16#0#); -- unspecified Reserved_15_31 : Interfaces.SAM.UInt17 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for PMC_PMC_SCDR_Register use record Reserved_0_4 at 0 range 0 .. 4; USBCLK at 0 range 5 .. 5; Reserved_6_7 at 0 range 6 .. 7; PCK at 0 range 8 .. 14; Reserved_15_31 at 0 range 15 .. 31; end record; subtype PMC_PMC_SCSR_HCLKS_Field is Interfaces.SAM.Bit; subtype PMC_PMC_SCSR_USBCLK_Field is Interfaces.SAM.Bit; -- PMC_PMC_SCSR_PCK array element subtype PMC_PMC_SCSR_PCK_Element is Interfaces.SAM.Bit; -- PMC_PMC_SCSR_PCK array type PMC_PMC_SCSR_PCK_Field_Array is array (0 .. 6) of PMC_PMC_SCSR_PCK_Element with Component_Size => 1, Size => 7; -- Type definition for PMC_PMC_SCSR_PCK type PMC_PMC_SCSR_PCK_Field (As_Array : Boolean := False) is record case As_Array is when False => -- PCK as a value Val : Interfaces.SAM.UInt7; when True => -- PCK as an array Arr : PMC_PMC_SCSR_PCK_Field_Array; end case; end record with Unchecked_Union, Size => 7; for PMC_PMC_SCSR_PCK_Field use record Val at 0 range 0 .. 6; Arr at 0 range 0 .. 6; end record; -- System Clock Status Register type PMC_PMC_SCSR_Register is record -- Read-only. HCLK Status HCLKS : PMC_PMC_SCSR_HCLKS_Field; -- unspecified Reserved_1_4 : Interfaces.SAM.UInt4; -- Read-only. USB FS Clock Status USBCLK : PMC_PMC_SCSR_USBCLK_Field; -- unspecified Reserved_6_7 : Interfaces.SAM.UInt2; -- Read-only. Programmable Clock 0 Output Status PCK : PMC_PMC_SCSR_PCK_Field; -- unspecified Reserved_15_31 : Interfaces.SAM.UInt17; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for PMC_PMC_SCSR_Register use record HCLKS at 0 range 0 .. 0; Reserved_1_4 at 0 range 1 .. 4; USBCLK at 0 range 5 .. 5; Reserved_6_7 at 0 range 6 .. 7; PCK at 0 range 8 .. 14; Reserved_15_31 at 0 range 15 .. 31; end record; -- PMC_PMC_PCER0_PID array element subtype PMC_PMC_PCER0_PID_Element is Interfaces.SAM.Bit; -- PMC_PMC_PCER0_PID array type PMC_PMC_PCER0_PID_Field_Array is array (7 .. 31) of PMC_PMC_PCER0_PID_Element with Component_Size => 1, Size => 25; -- Type definition for PMC_PMC_PCER0_PID type PMC_PMC_PCER0_PID_Field (As_Array : Boolean := False) is record case As_Array is when False => -- PID as a value Val : Interfaces.SAM.UInt25; when True => -- PID as an array Arr : PMC_PMC_PCER0_PID_Field_Array; end case; end record with Unchecked_Union, Size => 25; for PMC_PMC_PCER0_PID_Field use record Val at 0 range 0 .. 24; Arr at 0 range 0 .. 24; end record; -- Peripheral Clock Enable Register 0 type PMC_PMC_PCER0_Register is record -- unspecified Reserved_0_6 : Interfaces.SAM.UInt7 := 16#0#; -- Write-only. Peripheral Clock 7 Enable PID : PMC_PMC_PCER0_PID_Field := (As_Array => False, Val => 16#0#); end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for PMC_PMC_PCER0_Register use record Reserved_0_6 at 0 range 0 .. 6; PID at 0 range 7 .. 31; end record; -- PMC_PMC_PCDR0_PID array element subtype PMC_PMC_PCDR0_PID_Element is Interfaces.SAM.Bit; -- PMC_PMC_PCDR0_PID array type PMC_PMC_PCDR0_PID_Field_Array is array (7 .. 31) of PMC_PMC_PCDR0_PID_Element with Component_Size => 1, Size => 25; -- Type definition for PMC_PMC_PCDR0_PID type PMC_PMC_PCDR0_PID_Field (As_Array : Boolean := False) is record case As_Array is when False => -- PID as a value Val : Interfaces.SAM.UInt25; when True => -- PID as an array Arr : PMC_PMC_PCDR0_PID_Field_Array; end case; end record with Unchecked_Union, Size => 25; for PMC_PMC_PCDR0_PID_Field use record Val at 0 range 0 .. 24; Arr at 0 range 0 .. 24; end record; -- Peripheral Clock Disable Register 0 type PMC_PMC_PCDR0_Register is record -- unspecified Reserved_0_6 : Interfaces.SAM.UInt7 := 16#0#; -- Write-only. Peripheral Clock 7 Disable PID : PMC_PMC_PCDR0_PID_Field := (As_Array => False, Val => 16#0#); end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for PMC_PMC_PCDR0_Register use record Reserved_0_6 at 0 range 0 .. 6; PID at 0 range 7 .. 31; end record; -- PMC_PMC_PCSR0_PID array element subtype PMC_PMC_PCSR0_PID_Element is Interfaces.SAM.Bit; -- PMC_PMC_PCSR0_PID array type PMC_PMC_PCSR0_PID_Field_Array is array (7 .. 31) of PMC_PMC_PCSR0_PID_Element with Component_Size => 1, Size => 25; -- Type definition for PMC_PMC_PCSR0_PID type PMC_PMC_PCSR0_PID_Field (As_Array : Boolean := False) is record case As_Array is when False => -- PID as a value Val : Interfaces.SAM.UInt25; when True => -- PID as an array Arr : PMC_PMC_PCSR0_PID_Field_Array; end case; end record with Unchecked_Union, Size => 25; for PMC_PMC_PCSR0_PID_Field use record Val at 0 range 0 .. 24; Arr at 0 range 0 .. 24; end record; -- Peripheral Clock Status Register 0 type PMC_PMC_PCSR0_Register is record -- unspecified Reserved_0_6 : Interfaces.SAM.UInt7; -- Read-only. Peripheral Clock 7 Status PID : PMC_PMC_PCSR0_PID_Field; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for PMC_PMC_PCSR0_Register use record Reserved_0_6 at 0 range 0 .. 6; PID at 0 range 7 .. 31; end record; subtype PMC_CKGR_UCKR_UPLLEN_Field is Interfaces.SAM.Bit; subtype PMC_CKGR_UCKR_UPLLCOUNT_Field is Interfaces.SAM.UInt4; -- UTMI Clock Register type PMC_CKGR_UCKR_Register is record -- unspecified Reserved_0_15 : Interfaces.SAM.UInt16 := 16#0#; -- UTMI PLL Enable UPLLEN : PMC_CKGR_UCKR_UPLLEN_Field := 16#0#; -- unspecified Reserved_17_19 : Interfaces.SAM.UInt3 := 16#0#; -- UTMI PLL Startup Time UPLLCOUNT : PMC_CKGR_UCKR_UPLLCOUNT_Field := 16#0#; -- unspecified Reserved_24_31 : Interfaces.SAM.Byte := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for PMC_CKGR_UCKR_Register use record Reserved_0_15 at 0 range 0 .. 15; UPLLEN at 0 range 16 .. 16; Reserved_17_19 at 0 range 17 .. 19; UPLLCOUNT at 0 range 20 .. 23; Reserved_24_31 at 0 range 24 .. 31; end record; subtype PMC_CKGR_MOR_MOSCXTEN_Field is Interfaces.SAM.Bit; subtype PMC_CKGR_MOR_MOSCXTBY_Field is Interfaces.SAM.Bit; subtype PMC_CKGR_MOR_WAITMODE_Field is Interfaces.SAM.Bit; subtype PMC_CKGR_MOR_MOSCRCEN_Field is Interfaces.SAM.Bit; -- Main RC Oscillator Frequency Selection type CKGR_MOR_MOSCRCF_Field is ( -- The RC oscillator frequency is at 4 MHz Val_4_Mhz, -- The RC oscillator frequency is at 8 MHz Val_8_Mhz, -- The RC oscillator frequency is at 12 MHz Val_12_Mhz) with Size => 3; for CKGR_MOR_MOSCRCF_Field use (Val_4_Mhz => 0, Val_8_Mhz => 1, Val_12_Mhz => 2); subtype PMC_CKGR_MOR_MOSCXTST_Field is Interfaces.SAM.Byte; -- Write Access Password type CKGR_MOR_KEY_Field is ( -- Reset value for the field Ckgr_Mor_Key_Field_Reset, -- Writing any other value in this field aborts the write -- operation.Always reads as 0. Passwd) with Size => 8; for CKGR_MOR_KEY_Field use (Ckgr_Mor_Key_Field_Reset => 0, Passwd => 55); subtype PMC_CKGR_MOR_MOSCSEL_Field is Interfaces.SAM.Bit; subtype PMC_CKGR_MOR_CFDEN_Field is Interfaces.SAM.Bit; subtype PMC_CKGR_MOR_XT32KFME_Field is Interfaces.SAM.Bit; -- Main Oscillator Register type PMC_CKGR_MOR_Register is record -- Main Crystal Oscillator Enable MOSCXTEN : PMC_CKGR_MOR_MOSCXTEN_Field := 16#0#; -- Main Crystal Oscillator Bypass MOSCXTBY : PMC_CKGR_MOR_MOSCXTBY_Field := 16#0#; -- Wait Mode Command (Write-only) WAITMODE : PMC_CKGR_MOR_WAITMODE_Field := 16#0#; -- Main RC Oscillator Enable MOSCRCEN : PMC_CKGR_MOR_MOSCRCEN_Field := 16#0#; -- Main RC Oscillator Frequency Selection MOSCRCF : CKGR_MOR_MOSCRCF_Field := Interfaces.SAM.PMC.Val_4_Mhz; -- unspecified Reserved_7_7 : Interfaces.SAM.Bit := 16#0#; -- Main Crystal Oscillator Startup Time MOSCXTST : PMC_CKGR_MOR_MOSCXTST_Field := 16#0#; -- Write Access Password KEY : CKGR_MOR_KEY_Field := Ckgr_Mor_Key_Field_Reset; -- Main Clock Oscillator Selection MOSCSEL : PMC_CKGR_MOR_MOSCSEL_Field := 16#0#; -- Clock Failure Detector Enable CFDEN : PMC_CKGR_MOR_CFDEN_Field := 16#0#; -- 32.768 kHz Crystal Oscillator Frequency Monitoring Enable XT32KFME : PMC_CKGR_MOR_XT32KFME_Field := 16#0#; -- unspecified Reserved_27_31 : Interfaces.SAM.UInt5 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for PMC_CKGR_MOR_Register use record MOSCXTEN at 0 range 0 .. 0; MOSCXTBY at 0 range 1 .. 1; WAITMODE at 0 range 2 .. 2; MOSCRCEN at 0 range 3 .. 3; MOSCRCF at 0 range 4 .. 6; Reserved_7_7 at 0 range 7 .. 7; MOSCXTST at 0 range 8 .. 15; KEY at 0 range 16 .. 23; MOSCSEL at 0 range 24 .. 24; CFDEN at 0 range 25 .. 25; XT32KFME at 0 range 26 .. 26; Reserved_27_31 at 0 range 27 .. 31; end record; subtype PMC_CKGR_MCFR_MAINF_Field is Interfaces.SAM.UInt16; subtype PMC_CKGR_MCFR_MAINFRDY_Field is Interfaces.SAM.Bit; subtype PMC_CKGR_MCFR_RCMEAS_Field is Interfaces.SAM.Bit; subtype PMC_CKGR_MCFR_CCSS_Field is Interfaces.SAM.Bit; -- Main Clock Frequency Register type PMC_CKGR_MCFR_Register is record -- Main Clock Frequency MAINF : PMC_CKGR_MCFR_MAINF_Field := 16#0#; -- Main Clock Frequency Measure Ready MAINFRDY : PMC_CKGR_MCFR_MAINFRDY_Field := 16#0#; -- unspecified Reserved_17_19 : Interfaces.SAM.UInt3 := 16#0#; -- RC Oscillator Frequency Measure (write-only) RCMEAS : PMC_CKGR_MCFR_RCMEAS_Field := 16#0#; -- unspecified Reserved_21_23 : Interfaces.SAM.UInt3 := 16#0#; -- Counter Clock Source Selection CCSS : PMC_CKGR_MCFR_CCSS_Field := 16#0#; -- unspecified Reserved_25_31 : Interfaces.SAM.UInt7 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for PMC_CKGR_MCFR_Register use record MAINF at 0 range 0 .. 15; MAINFRDY at 0 range 16 .. 16; Reserved_17_19 at 0 range 17 .. 19; RCMEAS at 0 range 20 .. 20; Reserved_21_23 at 0 range 21 .. 23; CCSS at 0 range 24 .. 24; Reserved_25_31 at 0 range 25 .. 31; end record; subtype PMC_CKGR_PLLAR_DIVA_Field is Interfaces.SAM.Byte; subtype PMC_CKGR_PLLAR_PLLACOUNT_Field is Interfaces.SAM.UInt6; subtype PMC_CKGR_PLLAR_MULA_Field is Interfaces.SAM.UInt11; subtype PMC_CKGR_PLLAR_ONE_Field is Interfaces.SAM.Bit; -- PLLA Register type PMC_CKGR_PLLAR_Register is record -- PLLA Front End Divider DIVA : PMC_CKGR_PLLAR_DIVA_Field := 16#0#; -- PLLA Counter PLLACOUNT : PMC_CKGR_PLLAR_PLLACOUNT_Field := 16#0#; -- unspecified Reserved_14_15 : Interfaces.SAM.UInt2 := 16#0#; -- PLLA Multiplier MULA : PMC_CKGR_PLLAR_MULA_Field := 16#0#; -- unspecified Reserved_27_28 : Interfaces.SAM.UInt2 := 16#0#; -- Must Be Set to 1 ONE : PMC_CKGR_PLLAR_ONE_Field := 16#0#; -- unspecified Reserved_30_31 : Interfaces.SAM.UInt2 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for PMC_CKGR_PLLAR_Register use record DIVA at 0 range 0 .. 7; PLLACOUNT at 0 range 8 .. 13; Reserved_14_15 at 0 range 14 .. 15; MULA at 0 range 16 .. 26; Reserved_27_28 at 0 range 27 .. 28; ONE at 0 range 29 .. 29; Reserved_30_31 at 0 range 30 .. 31; end record; -- Master Clock Source Selection type PMC_MCKR_CSS_Field is ( -- SLCK is selected Slow_Clk, -- MAINCK is selected Main_Clk, -- PLLACK is selected Plla_Clk, -- UPPLLCKDIV is selected Upll_Clk) with Size => 2; for PMC_MCKR_CSS_Field use (Slow_Clk => 0, Main_Clk => 1, Plla_Clk => 2, Upll_Clk => 3); -- Processor Clock Prescaler type PMC_MCKR_PRES_Field is ( -- Selected clock Clk_1, -- Selected clock divided by 2 Clk_2, -- Selected clock divided by 4 Clk_4, -- Selected clock divided by 8 Clk_8, -- Selected clock divided by 16 Clk_16, -- Selected clock divided by 32 Clk_32, -- Selected clock divided by 64 Clk_64, -- Selected clock divided by 3 Clk_3) with Size => 3; for PMC_MCKR_PRES_Field use (Clk_1 => 0, Clk_2 => 1, Clk_4 => 2, Clk_8 => 3, Clk_16 => 4, Clk_32 => 5, Clk_64 => 6, Clk_3 => 7); -- Master Clock Division type PMC_MCKR_MDIV_Field is ( -- MCK is FCLK divided by 1. Eq_Pck, -- MCK is FCLK divided by 2. Pck_Div2, -- MCK is FCLK divided by 4. Pck_Div4, -- MCK is FCLK divided by 3. Pck_Div3) with Size => 2; for PMC_MCKR_MDIV_Field use (Eq_Pck => 0, Pck_Div2 => 1, Pck_Div4 => 2, Pck_Div3 => 3); subtype PMC_PMC_MCKR_UPLLDIV2_Field is Interfaces.SAM.Bit; -- Master Clock Register type PMC_PMC_MCKR_Register is record -- Master Clock Source Selection CSS : PMC_MCKR_CSS_Field := Interfaces.SAM.PMC.Slow_Clk; -- unspecified Reserved_2_3 : Interfaces.SAM.UInt2 := 16#0#; -- Processor Clock Prescaler PRES : PMC_MCKR_PRES_Field := Interfaces.SAM.PMC.Clk_1; -- unspecified Reserved_7_7 : Interfaces.SAM.Bit := 16#0#; -- Master Clock Division MDIV : PMC_MCKR_MDIV_Field := Interfaces.SAM.PMC.Eq_Pck; -- unspecified Reserved_10_12 : Interfaces.SAM.UInt3 := 16#0#; -- UPLL Divider by 2 UPLLDIV2 : PMC_PMC_MCKR_UPLLDIV2_Field := 16#0#; -- unspecified Reserved_14_31 : Interfaces.SAM.UInt18 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for PMC_PMC_MCKR_Register use record CSS at 0 range 0 .. 1; Reserved_2_3 at 0 range 2 .. 3; PRES at 0 range 4 .. 6; Reserved_7_7 at 0 range 7 .. 7; MDIV at 0 range 8 .. 9; Reserved_10_12 at 0 range 10 .. 12; UPLLDIV2 at 0 range 13 .. 13; Reserved_14_31 at 0 range 14 .. 31; end record; subtype PMC_PMC_USB_USBS_Field is Interfaces.SAM.Bit; subtype PMC_PMC_USB_USBDIV_Field is Interfaces.SAM.UInt4; -- USB Clock Register type PMC_PMC_USB_Register is record -- USB Input Clock Selection USBS : PMC_PMC_USB_USBS_Field := 16#0#; -- unspecified Reserved_1_7 : Interfaces.SAM.UInt7 := 16#0#; -- Divider for USB_48M USBDIV : PMC_PMC_USB_USBDIV_Field := 16#0#; -- unspecified Reserved_12_31 : Interfaces.SAM.UInt20 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for PMC_PMC_USB_Register use record USBS at 0 range 0 .. 0; Reserved_1_7 at 0 range 1 .. 7; USBDIV at 0 range 8 .. 11; Reserved_12_31 at 0 range 12 .. 31; end record; -- Programmable Clock Source Selection type PMC_PCK_CSS_Field is ( -- SLCK is selected Slow_Clk, -- MAINCK is selected Main_Clk, -- PLLACK is selected Plla_Clk, -- UPLLCKDIV is selected Upll_Clk, -- MCK is selected Mck) with Size => 3; for PMC_PCK_CSS_Field use (Slow_Clk => 0, Main_Clk => 1, Plla_Clk => 2, Upll_Clk => 3, Mck => 4); subtype PMC_PMC_PCK_PRES_Field is Interfaces.SAM.Byte; -- Programmable Clock Register (chid = 0) 0 type PMC_PMC_PCK_Register is record -- Programmable Clock Source Selection CSS : PMC_PCK_CSS_Field := Interfaces.SAM.PMC.Slow_Clk; -- unspecified Reserved_3_3 : Interfaces.SAM.Bit := 16#0#; -- Programmable Clock Prescaler PRES : PMC_PMC_PCK_PRES_Field := 16#0#; -- unspecified Reserved_12_31 : Interfaces.SAM.UInt20 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for PMC_PMC_PCK_Register use record CSS at 0 range 0 .. 2; Reserved_3_3 at 0 range 3 .. 3; PRES at 0 range 4 .. 11; Reserved_12_31 at 0 range 12 .. 31; end record; -- Programmable Clock Register (chid = 0) 0 type PMC_PMC_PCK_Registers is array (0 .. 7) of PMC_PMC_PCK_Register with Volatile; subtype PMC_PMC_IER_MOSCXTS_Field is Interfaces.SAM.Bit; subtype PMC_PMC_IER_LOCKA_Field is Interfaces.SAM.Bit; subtype PMC_PMC_IER_MCKRDY_Field is Interfaces.SAM.Bit; subtype PMC_PMC_IER_LOCKU_Field is Interfaces.SAM.Bit; -- PMC_PMC_IER_PCKRDY array element subtype PMC_PMC_IER_PCKRDY_Element is Interfaces.SAM.Bit; -- PMC_PMC_IER_PCKRDY array type PMC_PMC_IER_PCKRDY_Field_Array is array (0 .. 6) of PMC_PMC_IER_PCKRDY_Element with Component_Size => 1, Size => 7; -- Type definition for PMC_PMC_IER_PCKRDY type PMC_PMC_IER_PCKRDY_Field (As_Array : Boolean := False) is record case As_Array is when False => -- PCKRDY as a value Val : Interfaces.SAM.UInt7; when True => -- PCKRDY as an array Arr : PMC_PMC_IER_PCKRDY_Field_Array; end case; end record with Unchecked_Union, Size => 7; for PMC_PMC_IER_PCKRDY_Field use record Val at 0 range 0 .. 6; Arr at 0 range 0 .. 6; end record; subtype PMC_PMC_IER_MOSCSELS_Field is Interfaces.SAM.Bit; subtype PMC_PMC_IER_MOSCRCS_Field is Interfaces.SAM.Bit; subtype PMC_PMC_IER_CFDEV_Field is Interfaces.SAM.Bit; subtype PMC_PMC_IER_XT32KERR_Field is Interfaces.SAM.Bit; -- Interrupt Enable Register type PMC_PMC_IER_Register is record -- Write-only. Main Crystal Oscillator Status Interrupt Enable MOSCXTS : PMC_PMC_IER_MOSCXTS_Field := 16#0#; -- Write-only. PLLA Lock Interrupt Enable LOCKA : PMC_PMC_IER_LOCKA_Field := 16#0#; -- unspecified Reserved_2_2 : Interfaces.SAM.Bit := 16#0#; -- Write-only. Master Clock Ready Interrupt Enable MCKRDY : PMC_PMC_IER_MCKRDY_Field := 16#0#; -- unspecified Reserved_4_5 : Interfaces.SAM.UInt2 := 16#0#; -- Write-only. UTMI PLL Lock Interrupt Enable LOCKU : PMC_PMC_IER_LOCKU_Field := 16#0#; -- unspecified Reserved_7_7 : Interfaces.SAM.Bit := 16#0#; -- Write-only. Programmable Clock Ready 0 Interrupt Enable PCKRDY : PMC_PMC_IER_PCKRDY_Field := (As_Array => False, Val => 16#0#); -- unspecified Reserved_15_15 : Interfaces.SAM.Bit := 16#0#; -- Write-only. Main Clock Source Oscillator Selection Status Interrupt -- Enable MOSCSELS : PMC_PMC_IER_MOSCSELS_Field := 16#0#; -- Write-only. Main RC Oscillator Status Interrupt Enable MOSCRCS : PMC_PMC_IER_MOSCRCS_Field := 16#0#; -- Write-only. Clock Failure Detector Event Interrupt Enable CFDEV : PMC_PMC_IER_CFDEV_Field := 16#0#; -- unspecified Reserved_19_20 : Interfaces.SAM.UInt2 := 16#0#; -- Write-only. 32.768 kHz Crystal Oscillator Error Interrupt Enable XT32KERR : PMC_PMC_IER_XT32KERR_Field := 16#0#; -- unspecified Reserved_22_31 : Interfaces.SAM.UInt10 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for PMC_PMC_IER_Register use record MOSCXTS at 0 range 0 .. 0; LOCKA at 0 range 1 .. 1; Reserved_2_2 at 0 range 2 .. 2; MCKRDY at 0 range 3 .. 3; Reserved_4_5 at 0 range 4 .. 5; LOCKU at 0 range 6 .. 6; Reserved_7_7 at 0 range 7 .. 7; PCKRDY at 0 range 8 .. 14; Reserved_15_15 at 0 range 15 .. 15; MOSCSELS at 0 range 16 .. 16; MOSCRCS at 0 range 17 .. 17; CFDEV at 0 range 18 .. 18; Reserved_19_20 at 0 range 19 .. 20; XT32KERR at 0 range 21 .. 21; Reserved_22_31 at 0 range 22 .. 31; end record; subtype PMC_PMC_IDR_MOSCXTS_Field is Interfaces.SAM.Bit; subtype PMC_PMC_IDR_LOCKA_Field is Interfaces.SAM.Bit; subtype PMC_PMC_IDR_MCKRDY_Field is Interfaces.SAM.Bit; subtype PMC_PMC_IDR_LOCKU_Field is Interfaces.SAM.Bit; -- PMC_PMC_IDR_PCKRDY array element subtype PMC_PMC_IDR_PCKRDY_Element is Interfaces.SAM.Bit; -- PMC_PMC_IDR_PCKRDY array type PMC_PMC_IDR_PCKRDY_Field_Array is array (0 .. 6) of PMC_PMC_IDR_PCKRDY_Element with Component_Size => 1, Size => 7; -- Type definition for PMC_PMC_IDR_PCKRDY type PMC_PMC_IDR_PCKRDY_Field (As_Array : Boolean := False) is record case As_Array is when False => -- PCKRDY as a value Val : Interfaces.SAM.UInt7; when True => -- PCKRDY as an array Arr : PMC_PMC_IDR_PCKRDY_Field_Array; end case; end record with Unchecked_Union, Size => 7; for PMC_PMC_IDR_PCKRDY_Field use record Val at 0 range 0 .. 6; Arr at 0 range 0 .. 6; end record; subtype PMC_PMC_IDR_MOSCSELS_Field is Interfaces.SAM.Bit; subtype PMC_PMC_IDR_MOSCRCS_Field is Interfaces.SAM.Bit; subtype PMC_PMC_IDR_CFDEV_Field is Interfaces.SAM.Bit; subtype PMC_PMC_IDR_XT32KERR_Field is Interfaces.SAM.Bit; -- Interrupt Disable Register type PMC_PMC_IDR_Register is record -- Write-only. Main Crystal Oscillator Status Interrupt Disable MOSCXTS : PMC_PMC_IDR_MOSCXTS_Field := 16#0#; -- Write-only. PLLA Lock Interrupt Disable LOCKA : PMC_PMC_IDR_LOCKA_Field := 16#0#; -- unspecified Reserved_2_2 : Interfaces.SAM.Bit := 16#0#; -- Write-only. Master Clock Ready Interrupt Disable MCKRDY : PMC_PMC_IDR_MCKRDY_Field := 16#0#; -- unspecified Reserved_4_5 : Interfaces.SAM.UInt2 := 16#0#; -- Write-only. UTMI PLL Lock Interrupt Disable LOCKU : PMC_PMC_IDR_LOCKU_Field := 16#0#; -- unspecified Reserved_7_7 : Interfaces.SAM.Bit := 16#0#; -- Write-only. Programmable Clock Ready 0 Interrupt Disable PCKRDY : PMC_PMC_IDR_PCKRDY_Field := (As_Array => False, Val => 16#0#); -- unspecified Reserved_15_15 : Interfaces.SAM.Bit := 16#0#; -- Write-only. Main Clock Source Oscillator Selection Status Interrupt -- Disable MOSCSELS : PMC_PMC_IDR_MOSCSELS_Field := 16#0#; -- Write-only. Main RC Status Interrupt Disable MOSCRCS : PMC_PMC_IDR_MOSCRCS_Field := 16#0#; -- Write-only. Clock Failure Detector Event Interrupt Disable CFDEV : PMC_PMC_IDR_CFDEV_Field := 16#0#; -- unspecified Reserved_19_20 : Interfaces.SAM.UInt2 := 16#0#; -- Write-only. 32.768 kHz Crystal Oscillator Error Interrupt Disable XT32KERR : PMC_PMC_IDR_XT32KERR_Field := 16#0#; -- unspecified Reserved_22_31 : Interfaces.SAM.UInt10 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for PMC_PMC_IDR_Register use record MOSCXTS at 0 range 0 .. 0; LOCKA at 0 range 1 .. 1; Reserved_2_2 at 0 range 2 .. 2; MCKRDY at 0 range 3 .. 3; Reserved_4_5 at 0 range 4 .. 5; LOCKU at 0 range 6 .. 6; Reserved_7_7 at 0 range 7 .. 7; PCKRDY at 0 range 8 .. 14; Reserved_15_15 at 0 range 15 .. 15; MOSCSELS at 0 range 16 .. 16; MOSCRCS at 0 range 17 .. 17; CFDEV at 0 range 18 .. 18; Reserved_19_20 at 0 range 19 .. 20; XT32KERR at 0 range 21 .. 21; Reserved_22_31 at 0 range 22 .. 31; end record; subtype PMC_PMC_SR_MOSCXTS_Field is Interfaces.SAM.Bit; subtype PMC_PMC_SR_LOCKA_Field is Interfaces.SAM.Bit; subtype PMC_PMC_SR_MCKRDY_Field is Interfaces.SAM.Bit; subtype PMC_PMC_SR_LOCKU_Field is Interfaces.SAM.Bit; subtype PMC_PMC_SR_OSCSELS_Field is Interfaces.SAM.Bit; -- PMC_PMC_SR_PCKRDY array element subtype PMC_PMC_SR_PCKRDY_Element is Interfaces.SAM.Bit; -- PMC_PMC_SR_PCKRDY array type PMC_PMC_SR_PCKRDY_Field_Array is array (0 .. 6) of PMC_PMC_SR_PCKRDY_Element with Component_Size => 1, Size => 7; -- Type definition for PMC_PMC_SR_PCKRDY type PMC_PMC_SR_PCKRDY_Field (As_Array : Boolean := False) is record case As_Array is when False => -- PCKRDY as a value Val : Interfaces.SAM.UInt7; when True => -- PCKRDY as an array Arr : PMC_PMC_SR_PCKRDY_Field_Array; end case; end record with Unchecked_Union, Size => 7; for PMC_PMC_SR_PCKRDY_Field use record Val at 0 range 0 .. 6; Arr at 0 range 0 .. 6; end record; subtype PMC_PMC_SR_MOSCSELS_Field is Interfaces.SAM.Bit; subtype PMC_PMC_SR_MOSCRCS_Field is Interfaces.SAM.Bit; subtype PMC_PMC_SR_CFDEV_Field is Interfaces.SAM.Bit; subtype PMC_PMC_SR_CFDS_Field is Interfaces.SAM.Bit; subtype PMC_PMC_SR_FOS_Field is Interfaces.SAM.Bit; subtype PMC_PMC_SR_XT32KERR_Field is Interfaces.SAM.Bit; -- Status Register type PMC_PMC_SR_Register is record -- Read-only. Main Crystal Oscillator Status MOSCXTS : PMC_PMC_SR_MOSCXTS_Field; -- Read-only. PLLA Lock Status LOCKA : PMC_PMC_SR_LOCKA_Field; -- unspecified Reserved_2_2 : Interfaces.SAM.Bit; -- Read-only. Master Clock Status MCKRDY : PMC_PMC_SR_MCKRDY_Field; -- unspecified Reserved_4_5 : Interfaces.SAM.UInt2; -- Read-only. UTMI PLL Lock Status LOCKU : PMC_PMC_SR_LOCKU_Field; -- Read-only. Slow Clock Source Oscillator Selection OSCSELS : PMC_PMC_SR_OSCSELS_Field; -- Read-only. Programmable Clock Ready Status PCKRDY : PMC_PMC_SR_PCKRDY_Field; -- unspecified Reserved_15_15 : Interfaces.SAM.Bit; -- Read-only. Main Clock Source Oscillator Selection Status MOSCSELS : PMC_PMC_SR_MOSCSELS_Field; -- Read-only. Main RC Oscillator Status MOSCRCS : PMC_PMC_SR_MOSCRCS_Field; -- Read-only. Clock Failure Detector Event CFDEV : PMC_PMC_SR_CFDEV_Field; -- Read-only. Clock Failure Detector Status CFDS : PMC_PMC_SR_CFDS_Field; -- Read-only. Clock Failure Detector Fault Output Status FOS : PMC_PMC_SR_FOS_Field; -- Read-only. Slow Crystal Oscillator Error XT32KERR : PMC_PMC_SR_XT32KERR_Field; -- unspecified Reserved_22_31 : Interfaces.SAM.UInt10; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for PMC_PMC_SR_Register use record MOSCXTS at 0 range 0 .. 0; LOCKA at 0 range 1 .. 1; Reserved_2_2 at 0 range 2 .. 2; MCKRDY at 0 range 3 .. 3; Reserved_4_5 at 0 range 4 .. 5; LOCKU at 0 range 6 .. 6; OSCSELS at 0 range 7 .. 7; PCKRDY at 0 range 8 .. 14; Reserved_15_15 at 0 range 15 .. 15; MOSCSELS at 0 range 16 .. 16; MOSCRCS at 0 range 17 .. 17; CFDEV at 0 range 18 .. 18; CFDS at 0 range 19 .. 19; FOS at 0 range 20 .. 20; XT32KERR at 0 range 21 .. 21; Reserved_22_31 at 0 range 22 .. 31; end record; subtype PMC_PMC_IMR_MOSCXTS_Field is Interfaces.SAM.Bit; subtype PMC_PMC_IMR_LOCKA_Field is Interfaces.SAM.Bit; subtype PMC_PMC_IMR_MCKRDY_Field is Interfaces.SAM.Bit; subtype PMC_PMC_IMR_LOCKU_Field is Interfaces.SAM.Bit; -- PMC_PMC_IMR_PCKRDY array element subtype PMC_PMC_IMR_PCKRDY_Element is Interfaces.SAM.Bit; -- PMC_PMC_IMR_PCKRDY array type PMC_PMC_IMR_PCKRDY_Field_Array is array (0 .. 6) of PMC_PMC_IMR_PCKRDY_Element with Component_Size => 1, Size => 7; -- Type definition for PMC_PMC_IMR_PCKRDY type PMC_PMC_IMR_PCKRDY_Field (As_Array : Boolean := False) is record case As_Array is when False => -- PCKRDY as a value Val : Interfaces.SAM.UInt7; when True => -- PCKRDY as an array Arr : PMC_PMC_IMR_PCKRDY_Field_Array; end case; end record with Unchecked_Union, Size => 7; for PMC_PMC_IMR_PCKRDY_Field use record Val at 0 range 0 .. 6; Arr at 0 range 0 .. 6; end record; subtype PMC_PMC_IMR_MOSCSELS_Field is Interfaces.SAM.Bit; subtype PMC_PMC_IMR_MOSCRCS_Field is Interfaces.SAM.Bit; subtype PMC_PMC_IMR_CFDEV_Field is Interfaces.SAM.Bit; subtype PMC_PMC_IMR_XT32KERR_Field is Interfaces.SAM.Bit; -- Interrupt Mask Register type PMC_PMC_IMR_Register is record -- Read-only. Main Crystal Oscillator Status Interrupt Mask MOSCXTS : PMC_PMC_IMR_MOSCXTS_Field; -- Read-only. PLLA Lock Interrupt Mask LOCKA : PMC_PMC_IMR_LOCKA_Field; -- unspecified Reserved_2_2 : Interfaces.SAM.Bit; -- Read-only. Master Clock Ready Interrupt Mask MCKRDY : PMC_PMC_IMR_MCKRDY_Field; -- unspecified Reserved_4_5 : Interfaces.SAM.UInt2; -- Read-only. UTMI PLL Lock Interrupt Mask LOCKU : PMC_PMC_IMR_LOCKU_Field; -- unspecified Reserved_7_7 : Interfaces.SAM.Bit; -- Read-only. Programmable Clock Ready 0 Interrupt Mask PCKRDY : PMC_PMC_IMR_PCKRDY_Field; -- unspecified Reserved_15_15 : Interfaces.SAM.Bit; -- Read-only. Main Clock Source Oscillator Selection Status Interrupt -- Mask MOSCSELS : PMC_PMC_IMR_MOSCSELS_Field; -- Read-only. Main RC Status Interrupt Mask MOSCRCS : PMC_PMC_IMR_MOSCRCS_Field; -- Read-only. Clock Failure Detector Event Interrupt Mask CFDEV : PMC_PMC_IMR_CFDEV_Field; -- unspecified Reserved_19_20 : Interfaces.SAM.UInt2; -- Read-only. 32.768 kHz Crystal Oscillator Error Interrupt Mask XT32KERR : PMC_PMC_IMR_XT32KERR_Field; -- unspecified Reserved_22_31 : Interfaces.SAM.UInt10; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for PMC_PMC_IMR_Register use record MOSCXTS at 0 range 0 .. 0; LOCKA at 0 range 1 .. 1; Reserved_2_2 at 0 range 2 .. 2; MCKRDY at 0 range 3 .. 3; Reserved_4_5 at 0 range 4 .. 5; LOCKU at 0 range 6 .. 6; Reserved_7_7 at 0 range 7 .. 7; PCKRDY at 0 range 8 .. 14; Reserved_15_15 at 0 range 15 .. 15; MOSCSELS at 0 range 16 .. 16; MOSCRCS at 0 range 17 .. 17; CFDEV at 0 range 18 .. 18; Reserved_19_20 at 0 range 19 .. 20; XT32KERR at 0 range 21 .. 21; Reserved_22_31 at 0 range 22 .. 31; end record; -- PMC_PMC_FSMR_FSTT array element subtype PMC_PMC_FSMR_FSTT_Element is Interfaces.SAM.Bit; -- PMC_PMC_FSMR_FSTT array type PMC_PMC_FSMR_FSTT_Field_Array is array (0 .. 15) of PMC_PMC_FSMR_FSTT_Element with Component_Size => 1, Size => 16; -- Type definition for PMC_PMC_FSMR_FSTT type PMC_PMC_FSMR_FSTT_Field (As_Array : Boolean := False) is record case As_Array is when False => -- FSTT as a value Val : Interfaces.SAM.UInt16; when True => -- FSTT as an array Arr : PMC_PMC_FSMR_FSTT_Field_Array; end case; end record with Unchecked_Union, Size => 16; for PMC_PMC_FSMR_FSTT_Field use record Val at 0 range 0 .. 15; Arr at 0 range 0 .. 15; end record; subtype PMC_PMC_FSMR_RTTAL_Field is Interfaces.SAM.Bit; subtype PMC_PMC_FSMR_RTCAL_Field is Interfaces.SAM.Bit; subtype PMC_PMC_FSMR_USBAL_Field is Interfaces.SAM.Bit; subtype PMC_PMC_FSMR_LPM_Field is Interfaces.SAM.Bit; -- Flash Low-power Mode type PMC_FSMR_FLPM_Field is ( -- Flash is in Standby Mode when system enters Wait Mode Flash_Standby, -- Flash is in Deep-power-down mode when system enters Wait Mode Flash_Deep_Powerdown, -- Idle mode Flash_Idle) with Size => 2; for PMC_FSMR_FLPM_Field use (Flash_Standby => 0, Flash_Deep_Powerdown => 1, Flash_Idle => 2); subtype PMC_PMC_FSMR_FFLPM_Field is Interfaces.SAM.Bit; -- Fast Startup Mode Register type PMC_PMC_FSMR_Register is record -- Fast Startup Input Enable 0 FSTT : PMC_PMC_FSMR_FSTT_Field := (As_Array => False, Val => 16#0#); -- RTT Alarm Enable RTTAL : PMC_PMC_FSMR_RTTAL_Field := 16#0#; -- RTC Alarm Enable RTCAL : PMC_PMC_FSMR_RTCAL_Field := 16#0#; -- USB Alarm Enable USBAL : PMC_PMC_FSMR_USBAL_Field := 16#0#; -- unspecified Reserved_19_19 : Interfaces.SAM.Bit := 16#0#; -- Low-power Mode LPM : PMC_PMC_FSMR_LPM_Field := 16#0#; -- Flash Low-power Mode FLPM : PMC_FSMR_FLPM_Field := Interfaces.SAM.PMC.Flash_Standby; -- Force Flash Low-power Mode FFLPM : PMC_PMC_FSMR_FFLPM_Field := 16#0#; -- unspecified Reserved_24_31 : Interfaces.SAM.Byte := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for PMC_PMC_FSMR_Register use record FSTT at 0 range 0 .. 15; RTTAL at 0 range 16 .. 16; RTCAL at 0 range 17 .. 17; USBAL at 0 range 18 .. 18; Reserved_19_19 at 0 range 19 .. 19; LPM at 0 range 20 .. 20; FLPM at 0 range 21 .. 22; FFLPM at 0 range 23 .. 23; Reserved_24_31 at 0 range 24 .. 31; end record; -- PMC_PMC_FSPR_FSTP array element subtype PMC_PMC_FSPR_FSTP_Element is Interfaces.SAM.Bit; -- PMC_PMC_FSPR_FSTP array type PMC_PMC_FSPR_FSTP_Field_Array is array (0 .. 15) of PMC_PMC_FSPR_FSTP_Element with Component_Size => 1, Size => 16; -- Type definition for PMC_PMC_FSPR_FSTP type PMC_PMC_FSPR_FSTP_Field (As_Array : Boolean := False) is record case As_Array is when False => -- FSTP as a value Val : Interfaces.SAM.UInt16; when True => -- FSTP as an array Arr : PMC_PMC_FSPR_FSTP_Field_Array; end case; end record with Unchecked_Union, Size => 16; for PMC_PMC_FSPR_FSTP_Field use record Val at 0 range 0 .. 15; Arr at 0 range 0 .. 15; end record; -- Fast Startup Polarity Register type PMC_PMC_FSPR_Register is record -- Fast Startup Input Polarity 0 FSTP : PMC_PMC_FSPR_FSTP_Field := (As_Array => False, Val => 16#0#); -- unspecified Reserved_16_31 : Interfaces.SAM.UInt16 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for PMC_PMC_FSPR_Register use record FSTP at 0 range 0 .. 15; Reserved_16_31 at 0 range 16 .. 31; end record; subtype PMC_PMC_FOCR_FOCLR_Field is Interfaces.SAM.Bit; -- Fault Output Clear Register type PMC_PMC_FOCR_Register is record -- Write-only. Fault Output Clear FOCLR : PMC_PMC_FOCR_FOCLR_Field := 16#0#; -- unspecified Reserved_1_31 : Interfaces.SAM.UInt31 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for PMC_PMC_FOCR_Register use record FOCLR at 0 range 0 .. 0; Reserved_1_31 at 0 range 1 .. 31; end record; subtype PMC_PMC_WPMR_WPEN_Field is Interfaces.SAM.Bit; -- Write Protection Key type PMC_WPMR_WPKEY_Field is ( -- Reset value for the field Pmc_Wpmr_Wpkey_Field_Reset, -- Writing any other value in this field aborts the write operation of -- the WPEN bit. Always reads as 0. Passwd) with Size => 24; for PMC_WPMR_WPKEY_Field use (Pmc_Wpmr_Wpkey_Field_Reset => 0, Passwd => 5262659); -- Write Protection Mode Register type PMC_PMC_WPMR_Register is record -- Write Protection Enable WPEN : PMC_PMC_WPMR_WPEN_Field := 16#0#; -- unspecified Reserved_1_7 : Interfaces.SAM.UInt7 := 16#0#; -- Write Protection Key WPKEY : PMC_WPMR_WPKEY_Field := Pmc_Wpmr_Wpkey_Field_Reset; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for PMC_PMC_WPMR_Register use record WPEN at 0 range 0 .. 0; Reserved_1_7 at 0 range 1 .. 7; WPKEY at 0 range 8 .. 31; end record; subtype PMC_PMC_WPSR_WPVS_Field is Interfaces.SAM.Bit; subtype PMC_PMC_WPSR_WPVSRC_Field is Interfaces.SAM.UInt16; -- Write Protection Status Register type PMC_PMC_WPSR_Register is record -- Read-only. Write Protection Violation Status WPVS : PMC_PMC_WPSR_WPVS_Field; -- unspecified Reserved_1_7 : Interfaces.SAM.UInt7; -- Read-only. Write Protection Violation Source WPVSRC : PMC_PMC_WPSR_WPVSRC_Field; -- unspecified Reserved_24_31 : Interfaces.SAM.Byte; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for PMC_PMC_WPSR_Register use record WPVS at 0 range 0 .. 0; Reserved_1_7 at 0 range 1 .. 7; WPVSRC at 0 range 8 .. 23; Reserved_24_31 at 0 range 24 .. 31; end record; subtype PMC_PMC_VERSION_VERSION_Field is Interfaces.SAM.UInt12; subtype PMC_PMC_VERSION_MFN_Field is Interfaces.SAM.UInt3; -- Version Register type PMC_PMC_VERSION_Register is record -- Read-only. Version of the Hardware Module VERSION : PMC_PMC_VERSION_VERSION_Field; -- unspecified Reserved_12_15 : Interfaces.SAM.UInt4; -- Read-only. Metal Fix Number MFN : PMC_PMC_VERSION_MFN_Field; -- unspecified Reserved_19_31 : Interfaces.SAM.UInt13; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for PMC_PMC_VERSION_Register use record VERSION at 0 range 0 .. 11; Reserved_12_15 at 0 range 12 .. 15; MFN at 0 range 16 .. 18; Reserved_19_31 at 0 range 19 .. 31; end record; -- PMC_PMC_PCER1_PID array element subtype PMC_PMC_PCER1_PID_Element is Interfaces.SAM.Bit; -- PMC_PMC_PCER1_PID array type PMC_PMC_PCER1_PID_Field_Array is array (32 .. 35) of PMC_PMC_PCER1_PID_Element with Component_Size => 1, Size => 4; -- Type definition for PMC_PMC_PCER1_PID type PMC_PMC_PCER1_PID_Field (As_Array : Boolean := False) is record case As_Array is when False => -- PID as a value Val : Interfaces.SAM.UInt4; when True => -- PID as an array Arr : PMC_PMC_PCER1_PID_Field_Array; end case; end record with Unchecked_Union, Size => 4; for PMC_PMC_PCER1_PID_Field use record Val at 0 range 0 .. 3; Arr at 0 range 0 .. 3; end record; subtype PMC_PMC_PCER1_PID37_Field is Interfaces.SAM.Bit; -- PMC_PMC_PCER1_PID array type PMC_PMC_PCER1_PID_Field_Array_1 is array (39 .. 53) of PMC_PMC_PCER1_PID_Element with Component_Size => 1, Size => 15; -- Type definition for PMC_PMC_PCER1_PID type PMC_PMC_PCER1_PID_Field_1 (As_Array : Boolean := False) is record case As_Array is when False => -- PID as a value Val : Interfaces.SAM.UInt15; when True => -- PID as an array Arr : PMC_PMC_PCER1_PID_Field_Array_1; end case; end record with Unchecked_Union, Size => 15; for PMC_PMC_PCER1_PID_Field_1 use record Val at 0 range 0 .. 14; Arr at 0 range 0 .. 14; end record; -- PMC_PMC_PCER1_PID array type PMC_PMC_PCER1_PID_Field_Array_2 is array (56 .. 60) of PMC_PMC_PCER1_PID_Element with Component_Size => 1, Size => 5; -- Type definition for PMC_PMC_PCER1_PID type PMC_PMC_PCER1_PID_Field_2 (As_Array : Boolean := False) is record case As_Array is when False => -- PID as a value Val : Interfaces.SAM.UInt5; when True => -- PID as an array Arr : PMC_PMC_PCER1_PID_Field_Array_2; end case; end record with Unchecked_Union, Size => 5; for PMC_PMC_PCER1_PID_Field_2 use record Val at 0 range 0 .. 4; Arr at 0 range 0 .. 4; end record; -- Peripheral Clock Enable Register 1 type PMC_PMC_PCER1_Register is record -- Write-only. Peripheral Clock 32 Enable PID : PMC_PMC_PCER1_PID_Field := (As_Array => False, Val => 16#0#); -- unspecified Reserved_4_4 : Interfaces.SAM.Bit := 16#0#; -- Write-only. Peripheral Clock 37 Enable PID37 : PMC_PMC_PCER1_PID37_Field := 16#0#; -- unspecified Reserved_6_6 : Interfaces.SAM.Bit := 16#0#; -- Write-only. Peripheral Clock 39 Enable PID_1 : PMC_PMC_PCER1_PID_Field_1 := (As_Array => False, Val => 16#0#); -- unspecified Reserved_22_23 : Interfaces.SAM.UInt2 := 16#0#; -- Write-only. Peripheral Clock 56 Enable PID_2 : PMC_PMC_PCER1_PID_Field_2 := (As_Array => False, Val => 16#0#); -- unspecified Reserved_29_31 : Interfaces.SAM.UInt3 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for PMC_PMC_PCER1_Register use record PID at 0 range 0 .. 3; Reserved_4_4 at 0 range 4 .. 4; PID37 at 0 range 5 .. 5; Reserved_6_6 at 0 range 6 .. 6; PID_1 at 0 range 7 .. 21; Reserved_22_23 at 0 range 22 .. 23; PID_2 at 0 range 24 .. 28; Reserved_29_31 at 0 range 29 .. 31; end record; -- PMC_PMC_PCDR1_PID array element subtype PMC_PMC_PCDR1_PID_Element is Interfaces.SAM.Bit; -- PMC_PMC_PCDR1_PID array type PMC_PMC_PCDR1_PID_Field_Array is array (32 .. 35) of PMC_PMC_PCDR1_PID_Element with Component_Size => 1, Size => 4; -- Type definition for PMC_PMC_PCDR1_PID type PMC_PMC_PCDR1_PID_Field (As_Array : Boolean := False) is record case As_Array is when False => -- PID as a value Val : Interfaces.SAM.UInt4; when True => -- PID as an array Arr : PMC_PMC_PCDR1_PID_Field_Array; end case; end record with Unchecked_Union, Size => 4; for PMC_PMC_PCDR1_PID_Field use record Val at 0 range 0 .. 3; Arr at 0 range 0 .. 3; end record; subtype PMC_PMC_PCDR1_PID37_Field is Interfaces.SAM.Bit; -- PMC_PMC_PCDR1_PID array type PMC_PMC_PCDR1_PID_Field_Array_1 is array (39 .. 53) of PMC_PMC_PCDR1_PID_Element with Component_Size => 1, Size => 15; -- Type definition for PMC_PMC_PCDR1_PID type PMC_PMC_PCDR1_PID_Field_1 (As_Array : Boolean := False) is record case As_Array is when False => -- PID as a value Val : Interfaces.SAM.UInt15; when True => -- PID as an array Arr : PMC_PMC_PCDR1_PID_Field_Array_1; end case; end record with Unchecked_Union, Size => 15; for PMC_PMC_PCDR1_PID_Field_1 use record Val at 0 range 0 .. 14; Arr at 0 range 0 .. 14; end record; -- PMC_PMC_PCDR1_PID array type PMC_PMC_PCDR1_PID_Field_Array_2 is array (56 .. 60) of PMC_PMC_PCDR1_PID_Element with Component_Size => 1, Size => 5; -- Type definition for PMC_PMC_PCDR1_PID type PMC_PMC_PCDR1_PID_Field_2 (As_Array : Boolean := False) is record case As_Array is when False => -- PID as a value Val : Interfaces.SAM.UInt5; when True => -- PID as an array Arr : PMC_PMC_PCDR1_PID_Field_Array_2; end case; end record with Unchecked_Union, Size => 5; for PMC_PMC_PCDR1_PID_Field_2 use record Val at 0 range 0 .. 4; Arr at 0 range 0 .. 4; end record; -- Peripheral Clock Disable Register 1 type PMC_PMC_PCDR1_Register is record -- Write-only. Peripheral Clock 32 Disable PID : PMC_PMC_PCDR1_PID_Field := (As_Array => False, Val => 16#0#); -- unspecified Reserved_4_4 : Interfaces.SAM.Bit := 16#0#; -- Write-only. Peripheral Clock 37 Disable PID37 : PMC_PMC_PCDR1_PID37_Field := 16#0#; -- unspecified Reserved_6_6 : Interfaces.SAM.Bit := 16#0#; -- Write-only. Peripheral Clock 39 Disable PID_1 : PMC_PMC_PCDR1_PID_Field_1 := (As_Array => False, Val => 16#0#); -- unspecified Reserved_22_23 : Interfaces.SAM.UInt2 := 16#0#; -- Write-only. Peripheral Clock 56 Disable PID_2 : PMC_PMC_PCDR1_PID_Field_2 := (As_Array => False, Val => 16#0#); -- unspecified Reserved_29_31 : Interfaces.SAM.UInt3 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for PMC_PMC_PCDR1_Register use record PID at 0 range 0 .. 3; Reserved_4_4 at 0 range 4 .. 4; PID37 at 0 range 5 .. 5; Reserved_6_6 at 0 range 6 .. 6; PID_1 at 0 range 7 .. 21; Reserved_22_23 at 0 range 22 .. 23; PID_2 at 0 range 24 .. 28; Reserved_29_31 at 0 range 29 .. 31; end record; -- PMC_PMC_PCSR1_PID array element subtype PMC_PMC_PCSR1_PID_Element is Interfaces.SAM.Bit; -- PMC_PMC_PCSR1_PID array type PMC_PMC_PCSR1_PID_Field_Array is array (32 .. 35) of PMC_PMC_PCSR1_PID_Element with Component_Size => 1, Size => 4; -- Type definition for PMC_PMC_PCSR1_PID type PMC_PMC_PCSR1_PID_Field (As_Array : Boolean := False) is record case As_Array is when False => -- PID as a value Val : Interfaces.SAM.UInt4; when True => -- PID as an array Arr : PMC_PMC_PCSR1_PID_Field_Array; end case; end record with Unchecked_Union, Size => 4; for PMC_PMC_PCSR1_PID_Field use record Val at 0 range 0 .. 3; Arr at 0 range 0 .. 3; end record; subtype PMC_PMC_PCSR1_PID37_Field is Interfaces.SAM.Bit; -- PMC_PMC_PCSR1_PID array type PMC_PMC_PCSR1_PID_Field_Array_1 is array (39 .. 53) of PMC_PMC_PCSR1_PID_Element with Component_Size => 1, Size => 15; -- Type definition for PMC_PMC_PCSR1_PID type PMC_PMC_PCSR1_PID_Field_1 (As_Array : Boolean := False) is record case As_Array is when False => -- PID as a value Val : Interfaces.SAM.UInt15; when True => -- PID as an array Arr : PMC_PMC_PCSR1_PID_Field_Array_1; end case; end record with Unchecked_Union, Size => 15; for PMC_PMC_PCSR1_PID_Field_1 use record Val at 0 range 0 .. 14; Arr at 0 range 0 .. 14; end record; -- PMC_PMC_PCSR1_PID array type PMC_PMC_PCSR1_PID_Field_Array_2 is array (56 .. 60) of PMC_PMC_PCSR1_PID_Element with Component_Size => 1, Size => 5; -- Type definition for PMC_PMC_PCSR1_PID type PMC_PMC_PCSR1_PID_Field_2 (As_Array : Boolean := False) is record case As_Array is when False => -- PID as a value Val : Interfaces.SAM.UInt5; when True => -- PID as an array Arr : PMC_PMC_PCSR1_PID_Field_Array_2; end case; end record with Unchecked_Union, Size => 5; for PMC_PMC_PCSR1_PID_Field_2 use record Val at 0 range 0 .. 4; Arr at 0 range 0 .. 4; end record; -- Peripheral Clock Status Register 1 type PMC_PMC_PCSR1_Register is record -- Read-only. Peripheral Clock 32 Status PID : PMC_PMC_PCSR1_PID_Field; -- unspecified Reserved_4_4 : Interfaces.SAM.Bit; -- Read-only. Peripheral Clock 37 Status PID37 : PMC_PMC_PCSR1_PID37_Field; -- unspecified Reserved_6_6 : Interfaces.SAM.Bit; -- Read-only. Peripheral Clock 39 Status PID_1 : PMC_PMC_PCSR1_PID_Field_1; -- unspecified Reserved_22_23 : Interfaces.SAM.UInt2; -- Read-only. Peripheral Clock 56 Status PID_2 : PMC_PMC_PCSR1_PID_Field_2; -- unspecified Reserved_29_31 : Interfaces.SAM.UInt3; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for PMC_PMC_PCSR1_Register use record PID at 0 range 0 .. 3; Reserved_4_4 at 0 range 4 .. 4; PID37 at 0 range 5 .. 5; Reserved_6_6 at 0 range 6 .. 6; PID_1 at 0 range 7 .. 21; Reserved_22_23 at 0 range 22 .. 23; PID_2 at 0 range 24 .. 28; Reserved_29_31 at 0 range 29 .. 31; end record; subtype PMC_PMC_PCR_PID_Field is Interfaces.SAM.UInt7; -- Generic Clock Source Selection type PMC_PCR_GCLKCSS_Field is ( -- SLCK is selected Slow_Clk, -- MAINCK is selected Main_Clk, -- PLLACK is selected Plla_Clk, -- UPLLCK is selected Upll_Clk, -- MCK is selected Mck_Clk) with Size => 3; for PMC_PCR_GCLKCSS_Field use (Slow_Clk => 0, Main_Clk => 1, Plla_Clk => 2, Upll_Clk => 3, Mck_Clk => 4); subtype PMC_PMC_PCR_CMD_Field is Interfaces.SAM.Bit; subtype PMC_PMC_PCR_GCLKDIV_Field is Interfaces.SAM.Byte; subtype PMC_PMC_PCR_EN_Field is Interfaces.SAM.Bit; subtype PMC_PMC_PCR_GCLKEN_Field is Interfaces.SAM.Bit; -- Peripheral Control Register type PMC_PMC_PCR_Register is record -- Peripheral ID PID : PMC_PMC_PCR_PID_Field := 16#0#; -- unspecified Reserved_7_7 : Interfaces.SAM.Bit := 16#0#; -- Generic Clock Source Selection GCLKCSS : PMC_PCR_GCLKCSS_Field := Interfaces.SAM.PMC.Slow_Clk; -- unspecified Reserved_11_11 : Interfaces.SAM.Bit := 16#0#; -- Command CMD : PMC_PMC_PCR_CMD_Field := 16#0#; -- unspecified Reserved_13_19 : Interfaces.SAM.UInt7 := 16#0#; -- Generic Clock Division Ratio GCLKDIV : PMC_PMC_PCR_GCLKDIV_Field := 16#0#; -- Enable EN : PMC_PMC_PCR_EN_Field := 16#0#; -- Generic Clock Enable GCLKEN : PMC_PMC_PCR_GCLKEN_Field := 16#0#; -- unspecified Reserved_30_31 : Interfaces.SAM.UInt2 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for PMC_PMC_PCR_Register use record PID at 0 range 0 .. 6; Reserved_7_7 at 0 range 7 .. 7; GCLKCSS at 0 range 8 .. 10; Reserved_11_11 at 0 range 11 .. 11; CMD at 0 range 12 .. 12; Reserved_13_19 at 0 range 13 .. 19; GCLKDIV at 0 range 20 .. 27; EN at 0 range 28 .. 28; GCLKEN at 0 range 29 .. 29; Reserved_30_31 at 0 range 30 .. 31; end record; subtype PMC_PMC_OCR_CAL4_Field is Interfaces.SAM.UInt7; subtype PMC_PMC_OCR_SEL4_Field is Interfaces.SAM.Bit; subtype PMC_PMC_OCR_CAL8_Field is Interfaces.SAM.UInt7; subtype PMC_PMC_OCR_SEL8_Field is Interfaces.SAM.Bit; subtype PMC_PMC_OCR_CAL12_Field is Interfaces.SAM.UInt7; subtype PMC_PMC_OCR_SEL12_Field is Interfaces.SAM.Bit; -- Oscillator Calibration Register type PMC_PMC_OCR_Register is record -- Main RC Oscillator Calibration Bits for 4 MHz CAL4 : PMC_PMC_OCR_CAL4_Field := 16#0#; -- Selection of Main RC Oscillator Calibration Bits for 4 MHz SEL4 : PMC_PMC_OCR_SEL4_Field := 16#0#; -- Main RC Oscillator Calibration Bits for 8 MHz CAL8 : PMC_PMC_OCR_CAL8_Field := 16#0#; -- Selection of Main RC Oscillator Calibration Bits for 8 MHz SEL8 : PMC_PMC_OCR_SEL8_Field := 16#0#; -- Main RC Oscillator Calibration Bits for 12 MHz CAL12 : PMC_PMC_OCR_CAL12_Field := 16#0#; -- Selection of Main RC Oscillator Calibration Bits for 12 MHz SEL12 : PMC_PMC_OCR_SEL12_Field := 16#0#; -- unspecified Reserved_24_31 : Interfaces.SAM.Byte := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for PMC_PMC_OCR_Register use record CAL4 at 0 range 0 .. 6; SEL4 at 0 range 7 .. 7; CAL8 at 0 range 8 .. 14; SEL8 at 0 range 15 .. 15; CAL12 at 0 range 16 .. 22; SEL12 at 0 range 23 .. 23; Reserved_24_31 at 0 range 24 .. 31; end record; -- PMC_PMC_SLPWK_ER0_PID array element subtype PMC_PMC_SLPWK_ER0_PID_Element is Interfaces.SAM.Bit; -- PMC_PMC_SLPWK_ER0_PID array type PMC_PMC_SLPWK_ER0_PID_Field_Array is array (7 .. 31) of PMC_PMC_SLPWK_ER0_PID_Element with Component_Size => 1, Size => 25; -- Type definition for PMC_PMC_SLPWK_ER0_PID type PMC_PMC_SLPWK_ER0_PID_Field (As_Array : Boolean := False) is record case As_Array is when False => -- PID as a value Val : Interfaces.SAM.UInt25; when True => -- PID as an array Arr : PMC_PMC_SLPWK_ER0_PID_Field_Array; end case; end record with Unchecked_Union, Size => 25; for PMC_PMC_SLPWK_ER0_PID_Field use record Val at 0 range 0 .. 24; Arr at 0 range 0 .. 24; end record; -- SleepWalking Enable Register 0 type PMC_PMC_SLPWK_ER0_Register is record -- unspecified Reserved_0_6 : Interfaces.SAM.UInt7 := 16#0#; -- Write-only. Peripheral 7 SleepWalking Enable PID : PMC_PMC_SLPWK_ER0_PID_Field := (As_Array => False, Val => 16#0#); end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for PMC_PMC_SLPWK_ER0_Register use record Reserved_0_6 at 0 range 0 .. 6; PID at 0 range 7 .. 31; end record; -- PMC_PMC_SLPWK_DR0_PID array element subtype PMC_PMC_SLPWK_DR0_PID_Element is Interfaces.SAM.Bit; -- PMC_PMC_SLPWK_DR0_PID array type PMC_PMC_SLPWK_DR0_PID_Field_Array is array (7 .. 31) of PMC_PMC_SLPWK_DR0_PID_Element with Component_Size => 1, Size => 25; -- Type definition for PMC_PMC_SLPWK_DR0_PID type PMC_PMC_SLPWK_DR0_PID_Field (As_Array : Boolean := False) is record case As_Array is when False => -- PID as a value Val : Interfaces.SAM.UInt25; when True => -- PID as an array Arr : PMC_PMC_SLPWK_DR0_PID_Field_Array; end case; end record with Unchecked_Union, Size => 25; for PMC_PMC_SLPWK_DR0_PID_Field use record Val at 0 range 0 .. 24; Arr at 0 range 0 .. 24; end record; -- SleepWalking Disable Register 0 type PMC_PMC_SLPWK_DR0_Register is record -- unspecified Reserved_0_6 : Interfaces.SAM.UInt7 := 16#0#; -- Write-only. Peripheral 7 SleepWalking Disable PID : PMC_PMC_SLPWK_DR0_PID_Field := (As_Array => False, Val => 16#0#); end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for PMC_PMC_SLPWK_DR0_Register use record Reserved_0_6 at 0 range 0 .. 6; PID at 0 range 7 .. 31; end record; -- PMC_PMC_SLPWK_SR0_PID array element subtype PMC_PMC_SLPWK_SR0_PID_Element is Interfaces.SAM.Bit; -- PMC_PMC_SLPWK_SR0_PID array type PMC_PMC_SLPWK_SR0_PID_Field_Array is array (7 .. 31) of PMC_PMC_SLPWK_SR0_PID_Element with Component_Size => 1, Size => 25; -- Type definition for PMC_PMC_SLPWK_SR0_PID type PMC_PMC_SLPWK_SR0_PID_Field (As_Array : Boolean := False) is record case As_Array is when False => -- PID as a value Val : Interfaces.SAM.UInt25; when True => -- PID as an array Arr : PMC_PMC_SLPWK_SR0_PID_Field_Array; end case; end record with Unchecked_Union, Size => 25; for PMC_PMC_SLPWK_SR0_PID_Field use record Val at 0 range 0 .. 24; Arr at 0 range 0 .. 24; end record; -- SleepWalking Status Register 0 type PMC_PMC_SLPWK_SR0_Register is record -- unspecified Reserved_0_6 : Interfaces.SAM.UInt7; -- Read-only. Peripheral 7 SleepWalking Status PID : PMC_PMC_SLPWK_SR0_PID_Field; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for PMC_PMC_SLPWK_SR0_Register use record Reserved_0_6 at 0 range 0 .. 6; PID at 0 range 7 .. 31; end record; -- PMC_PMC_SLPWK_ASR0_PID array element subtype PMC_PMC_SLPWK_ASR0_PID_Element is Interfaces.SAM.Bit; -- PMC_PMC_SLPWK_ASR0_PID array type PMC_PMC_SLPWK_ASR0_PID_Field_Array is array (7 .. 31) of PMC_PMC_SLPWK_ASR0_PID_Element with Component_Size => 1, Size => 25; -- Type definition for PMC_PMC_SLPWK_ASR0_PID type PMC_PMC_SLPWK_ASR0_PID_Field (As_Array : Boolean := False) is record case As_Array is when False => -- PID as a value Val : Interfaces.SAM.UInt25; when True => -- PID as an array Arr : PMC_PMC_SLPWK_ASR0_PID_Field_Array; end case; end record with Unchecked_Union, Size => 25; for PMC_PMC_SLPWK_ASR0_PID_Field use record Val at 0 range 0 .. 24; Arr at 0 range 0 .. 24; end record; -- SleepWalking Activity Status Register 0 type PMC_PMC_SLPWK_ASR0_Register is record -- unspecified Reserved_0_6 : Interfaces.SAM.UInt7; -- Read-only. Peripheral 7 Activity Status PID : PMC_PMC_SLPWK_ASR0_PID_Field; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for PMC_PMC_SLPWK_ASR0_Register use record Reserved_0_6 at 0 range 0 .. 6; PID at 0 range 7 .. 31; end record; subtype PMC_PMC_PMMR_PLLA_MMAX_Field is Interfaces.SAM.UInt11; -- PLL Maximum Multiplier Value Register type PMC_PMC_PMMR_Register is record -- PLLA Maximum Allowed Multiplier Value PLLA_MMAX : PMC_PMC_PMMR_PLLA_MMAX_Field := 16#0#; -- unspecified Reserved_11_31 : Interfaces.SAM.UInt21 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for PMC_PMC_PMMR_Register use record PLLA_MMAX at 0 range 0 .. 10; Reserved_11_31 at 0 range 11 .. 31; end record; -- PMC_PMC_SLPWK_ER1_PID array element subtype PMC_PMC_SLPWK_ER1_PID_Element is Interfaces.SAM.Bit; -- PMC_PMC_SLPWK_ER1_PID array type PMC_PMC_SLPWK_ER1_PID_Field_Array is array (32 .. 35) of PMC_PMC_SLPWK_ER1_PID_Element with Component_Size => 1, Size => 4; -- Type definition for PMC_PMC_SLPWK_ER1_PID type PMC_PMC_SLPWK_ER1_PID_Field (As_Array : Boolean := False) is record case As_Array is when False => -- PID as a value Val : Interfaces.SAM.UInt4; when True => -- PID as an array Arr : PMC_PMC_SLPWK_ER1_PID_Field_Array; end case; end record with Unchecked_Union, Size => 4; for PMC_PMC_SLPWK_ER1_PID_Field use record Val at 0 range 0 .. 3; Arr at 0 range 0 .. 3; end record; subtype PMC_PMC_SLPWK_ER1_PID37_Field is Interfaces.SAM.Bit; -- PMC_PMC_SLPWK_ER1_PID array type PMC_PMC_SLPWK_ER1_PID_Field_Array_1 is array (39 .. 53) of PMC_PMC_SLPWK_ER1_PID_Element with Component_Size => 1, Size => 15; -- Type definition for PMC_PMC_SLPWK_ER1_PID type PMC_PMC_SLPWK_ER1_PID_Field_1 (As_Array : Boolean := False) is record case As_Array is when False => -- PID as a value Val : Interfaces.SAM.UInt15; when True => -- PID as an array Arr : PMC_PMC_SLPWK_ER1_PID_Field_Array_1; end case; end record with Unchecked_Union, Size => 15; for PMC_PMC_SLPWK_ER1_PID_Field_1 use record Val at 0 range 0 .. 14; Arr at 0 range 0 .. 14; end record; -- PMC_PMC_SLPWK_ER1_PID array type PMC_PMC_SLPWK_ER1_PID_Field_Array_2 is array (56 .. 60) of PMC_PMC_SLPWK_ER1_PID_Element with Component_Size => 1, Size => 5; -- Type definition for PMC_PMC_SLPWK_ER1_PID type PMC_PMC_SLPWK_ER1_PID_Field_2 (As_Array : Boolean := False) is record case As_Array is when False => -- PID as a value Val : Interfaces.SAM.UInt5; when True => -- PID as an array Arr : PMC_PMC_SLPWK_ER1_PID_Field_Array_2; end case; end record with Unchecked_Union, Size => 5; for PMC_PMC_SLPWK_ER1_PID_Field_2 use record Val at 0 range 0 .. 4; Arr at 0 range 0 .. 4; end record; -- SleepWalking Enable Register 1 type PMC_PMC_SLPWK_ER1_Register is record -- Write-only. Peripheral 32 SleepWalking Enable PID : PMC_PMC_SLPWK_ER1_PID_Field := (As_Array => False, Val => 16#0#); -- unspecified Reserved_4_4 : Interfaces.SAM.Bit := 16#0#; -- Write-only. Peripheral 37 SleepWalking Enable PID37 : PMC_PMC_SLPWK_ER1_PID37_Field := 16#0#; -- unspecified Reserved_6_6 : Interfaces.SAM.Bit := 16#0#; -- Write-only. Peripheral 39 SleepWalking Enable PID_1 : PMC_PMC_SLPWK_ER1_PID_Field_1 := (As_Array => False, Val => 16#0#); -- unspecified Reserved_22_23 : Interfaces.SAM.UInt2 := 16#0#; -- Write-only. Peripheral 56 SleepWalking Enable PID_2 : PMC_PMC_SLPWK_ER1_PID_Field_2 := (As_Array => False, Val => 16#0#); -- unspecified Reserved_29_31 : Interfaces.SAM.UInt3 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for PMC_PMC_SLPWK_ER1_Register use record PID at 0 range 0 .. 3; Reserved_4_4 at 0 range 4 .. 4; PID37 at 0 range 5 .. 5; Reserved_6_6 at 0 range 6 .. 6; PID_1 at 0 range 7 .. 21; Reserved_22_23 at 0 range 22 .. 23; PID_2 at 0 range 24 .. 28; Reserved_29_31 at 0 range 29 .. 31; end record; -- PMC_PMC_SLPWK_DR1_PID array element subtype PMC_PMC_SLPWK_DR1_PID_Element is Interfaces.SAM.Bit; -- PMC_PMC_SLPWK_DR1_PID array type PMC_PMC_SLPWK_DR1_PID_Field_Array is array (32 .. 35) of PMC_PMC_SLPWK_DR1_PID_Element with Component_Size => 1, Size => 4; -- Type definition for PMC_PMC_SLPWK_DR1_PID type PMC_PMC_SLPWK_DR1_PID_Field (As_Array : Boolean := False) is record case As_Array is when False => -- PID as a value Val : Interfaces.SAM.UInt4; when True => -- PID as an array Arr : PMC_PMC_SLPWK_DR1_PID_Field_Array; end case; end record with Unchecked_Union, Size => 4; for PMC_PMC_SLPWK_DR1_PID_Field use record Val at 0 range 0 .. 3; Arr at 0 range 0 .. 3; end record; subtype PMC_PMC_SLPWK_DR1_PID37_Field is Interfaces.SAM.Bit; -- PMC_PMC_SLPWK_DR1_PID array type PMC_PMC_SLPWK_DR1_PID_Field_Array_1 is array (39 .. 53) of PMC_PMC_SLPWK_DR1_PID_Element with Component_Size => 1, Size => 15; -- Type definition for PMC_PMC_SLPWK_DR1_PID type PMC_PMC_SLPWK_DR1_PID_Field_1 (As_Array : Boolean := False) is record case As_Array is when False => -- PID as a value Val : Interfaces.SAM.UInt15; when True => -- PID as an array Arr : PMC_PMC_SLPWK_DR1_PID_Field_Array_1; end case; end record with Unchecked_Union, Size => 15; for PMC_PMC_SLPWK_DR1_PID_Field_1 use record Val at 0 range 0 .. 14; Arr at 0 range 0 .. 14; end record; -- PMC_PMC_SLPWK_DR1_PID array type PMC_PMC_SLPWK_DR1_PID_Field_Array_2 is array (56 .. 60) of PMC_PMC_SLPWK_DR1_PID_Element with Component_Size => 1, Size => 5; -- Type definition for PMC_PMC_SLPWK_DR1_PID type PMC_PMC_SLPWK_DR1_PID_Field_2 (As_Array : Boolean := False) is record case As_Array is when False => -- PID as a value Val : Interfaces.SAM.UInt5; when True => -- PID as an array Arr : PMC_PMC_SLPWK_DR1_PID_Field_Array_2; end case; end record with Unchecked_Union, Size => 5; for PMC_PMC_SLPWK_DR1_PID_Field_2 use record Val at 0 range 0 .. 4; Arr at 0 range 0 .. 4; end record; -- SleepWalking Disable Register 1 type PMC_PMC_SLPWK_DR1_Register is record -- Write-only. Peripheral 32 SleepWalking Disable PID : PMC_PMC_SLPWK_DR1_PID_Field := (As_Array => False, Val => 16#0#); -- unspecified Reserved_4_4 : Interfaces.SAM.Bit := 16#0#; -- Write-only. Peripheral 37 SleepWalking Disable PID37 : PMC_PMC_SLPWK_DR1_PID37_Field := 16#0#; -- unspecified Reserved_6_6 : Interfaces.SAM.Bit := 16#0#; -- Write-only. Peripheral 39 SleepWalking Disable PID_1 : PMC_PMC_SLPWK_DR1_PID_Field_1 := (As_Array => False, Val => 16#0#); -- unspecified Reserved_22_23 : Interfaces.SAM.UInt2 := 16#0#; -- Write-only. Peripheral 56 SleepWalking Disable PID_2 : PMC_PMC_SLPWK_DR1_PID_Field_2 := (As_Array => False, Val => 16#0#); -- unspecified Reserved_29_31 : Interfaces.SAM.UInt3 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for PMC_PMC_SLPWK_DR1_Register use record PID at 0 range 0 .. 3; Reserved_4_4 at 0 range 4 .. 4; PID37 at 0 range 5 .. 5; Reserved_6_6 at 0 range 6 .. 6; PID_1 at 0 range 7 .. 21; Reserved_22_23 at 0 range 22 .. 23; PID_2 at 0 range 24 .. 28; Reserved_29_31 at 0 range 29 .. 31; end record; -- PMC_PMC_SLPWK_SR1_PID array element subtype PMC_PMC_SLPWK_SR1_PID_Element is Interfaces.SAM.Bit; -- PMC_PMC_SLPWK_SR1_PID array type PMC_PMC_SLPWK_SR1_PID_Field_Array is array (32 .. 35) of PMC_PMC_SLPWK_SR1_PID_Element with Component_Size => 1, Size => 4; -- Type definition for PMC_PMC_SLPWK_SR1_PID type PMC_PMC_SLPWK_SR1_PID_Field (As_Array : Boolean := False) is record case As_Array is when False => -- PID as a value Val : Interfaces.SAM.UInt4; when True => -- PID as an array Arr : PMC_PMC_SLPWK_SR1_PID_Field_Array; end case; end record with Unchecked_Union, Size => 4; for PMC_PMC_SLPWK_SR1_PID_Field use record Val at 0 range 0 .. 3; Arr at 0 range 0 .. 3; end record; subtype PMC_PMC_SLPWK_SR1_PID37_Field is Interfaces.SAM.Bit; -- PMC_PMC_SLPWK_SR1_PID array type PMC_PMC_SLPWK_SR1_PID_Field_Array_1 is array (39 .. 53) of PMC_PMC_SLPWK_SR1_PID_Element with Component_Size => 1, Size => 15; -- Type definition for PMC_PMC_SLPWK_SR1_PID type PMC_PMC_SLPWK_SR1_PID_Field_1 (As_Array : Boolean := False) is record case As_Array is when False => -- PID as a value Val : Interfaces.SAM.UInt15; when True => -- PID as an array Arr : PMC_PMC_SLPWK_SR1_PID_Field_Array_1; end case; end record with Unchecked_Union, Size => 15; for PMC_PMC_SLPWK_SR1_PID_Field_1 use record Val at 0 range 0 .. 14; Arr at 0 range 0 .. 14; end record; -- PMC_PMC_SLPWK_SR1_PID array type PMC_PMC_SLPWK_SR1_PID_Field_Array_2 is array (56 .. 60) of PMC_PMC_SLPWK_SR1_PID_Element with Component_Size => 1, Size => 5; -- Type definition for PMC_PMC_SLPWK_SR1_PID type PMC_PMC_SLPWK_SR1_PID_Field_2 (As_Array : Boolean := False) is record case As_Array is when False => -- PID as a value Val : Interfaces.SAM.UInt5; when True => -- PID as an array Arr : PMC_PMC_SLPWK_SR1_PID_Field_Array_2; end case; end record with Unchecked_Union, Size => 5; for PMC_PMC_SLPWK_SR1_PID_Field_2 use record Val at 0 range 0 .. 4; Arr at 0 range 0 .. 4; end record; -- SleepWalking Status Register 1 type PMC_PMC_SLPWK_SR1_Register is record -- Read-only. Peripheral 32 SleepWalking Status PID : PMC_PMC_SLPWK_SR1_PID_Field; -- unspecified Reserved_4_4 : Interfaces.SAM.Bit; -- Read-only. Peripheral 37 SleepWalking Status PID37 : PMC_PMC_SLPWK_SR1_PID37_Field; -- unspecified Reserved_6_6 : Interfaces.SAM.Bit; -- Read-only. Peripheral 39 SleepWalking Status PID_1 : PMC_PMC_SLPWK_SR1_PID_Field_1; -- unspecified Reserved_22_23 : Interfaces.SAM.UInt2; -- Read-only. Peripheral 56 SleepWalking Status PID_2 : PMC_PMC_SLPWK_SR1_PID_Field_2; -- unspecified Reserved_29_31 : Interfaces.SAM.UInt3; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for PMC_PMC_SLPWK_SR1_Register use record PID at 0 range 0 .. 3; Reserved_4_4 at 0 range 4 .. 4; PID37 at 0 range 5 .. 5; Reserved_6_6 at 0 range 6 .. 6; PID_1 at 0 range 7 .. 21; Reserved_22_23 at 0 range 22 .. 23; PID_2 at 0 range 24 .. 28; Reserved_29_31 at 0 range 29 .. 31; end record; -- PMC_PMC_SLPWK_ASR1_PID array element subtype PMC_PMC_SLPWK_ASR1_PID_Element is Interfaces.SAM.Bit; -- PMC_PMC_SLPWK_ASR1_PID array type PMC_PMC_SLPWK_ASR1_PID_Field_Array is array (32 .. 35) of PMC_PMC_SLPWK_ASR1_PID_Element with Component_Size => 1, Size => 4; -- Type definition for PMC_PMC_SLPWK_ASR1_PID type PMC_PMC_SLPWK_ASR1_PID_Field (As_Array : Boolean := False) is record case As_Array is when False => -- PID as a value Val : Interfaces.SAM.UInt4; when True => -- PID as an array Arr : PMC_PMC_SLPWK_ASR1_PID_Field_Array; end case; end record with Unchecked_Union, Size => 4; for PMC_PMC_SLPWK_ASR1_PID_Field use record Val at 0 range 0 .. 3; Arr at 0 range 0 .. 3; end record; subtype PMC_PMC_SLPWK_ASR1_PID37_Field is Interfaces.SAM.Bit; -- PMC_PMC_SLPWK_ASR1_PID array type PMC_PMC_SLPWK_ASR1_PID_Field_Array_1 is array (39 .. 53) of PMC_PMC_SLPWK_ASR1_PID_Element with Component_Size => 1, Size => 15; -- Type definition for PMC_PMC_SLPWK_ASR1_PID type PMC_PMC_SLPWK_ASR1_PID_Field_1 (As_Array : Boolean := False) is record case As_Array is when False => -- PID as a value Val : Interfaces.SAM.UInt15; when True => -- PID as an array Arr : PMC_PMC_SLPWK_ASR1_PID_Field_Array_1; end case; end record with Unchecked_Union, Size => 15; for PMC_PMC_SLPWK_ASR1_PID_Field_1 use record Val at 0 range 0 .. 14; Arr at 0 range 0 .. 14; end record; -- PMC_PMC_SLPWK_ASR1_PID array type PMC_PMC_SLPWK_ASR1_PID_Field_Array_2 is array (56 .. 60) of PMC_PMC_SLPWK_ASR1_PID_Element with Component_Size => 1, Size => 5; -- Type definition for PMC_PMC_SLPWK_ASR1_PID type PMC_PMC_SLPWK_ASR1_PID_Field_2 (As_Array : Boolean := False) is record case As_Array is when False => -- PID as a value Val : Interfaces.SAM.UInt5; when True => -- PID as an array Arr : PMC_PMC_SLPWK_ASR1_PID_Field_Array_2; end case; end record with Unchecked_Union, Size => 5; for PMC_PMC_SLPWK_ASR1_PID_Field_2 use record Val at 0 range 0 .. 4; Arr at 0 range 0 .. 4; end record; -- SleepWalking Activity Status Register 1 type PMC_PMC_SLPWK_ASR1_Register is record -- Read-only. Peripheral 32 Activity Status PID : PMC_PMC_SLPWK_ASR1_PID_Field; -- unspecified Reserved_4_4 : Interfaces.SAM.Bit; -- Read-only. Peripheral 37 Activity Status PID37 : PMC_PMC_SLPWK_ASR1_PID37_Field; -- unspecified Reserved_6_6 : Interfaces.SAM.Bit; -- Read-only. Peripheral 39 Activity Status PID_1 : PMC_PMC_SLPWK_ASR1_PID_Field_1; -- unspecified Reserved_22_23 : Interfaces.SAM.UInt2; -- Read-only. Peripheral 56 Activity Status PID_2 : PMC_PMC_SLPWK_ASR1_PID_Field_2; -- unspecified Reserved_29_31 : Interfaces.SAM.UInt3; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for PMC_PMC_SLPWK_ASR1_Register use record PID at 0 range 0 .. 3; Reserved_4_4 at 0 range 4 .. 4; PID37 at 0 range 5 .. 5; Reserved_6_6 at 0 range 6 .. 6; PID_1 at 0 range 7 .. 21; Reserved_22_23 at 0 range 22 .. 23; PID_2 at 0 range 24 .. 28; Reserved_29_31 at 0 range 29 .. 31; end record; subtype PMC_PMC_SLPWK_AIPR_AIP_Field is Interfaces.SAM.Bit; -- SleepWalking Activity In Progress Register type PMC_PMC_SLPWK_AIPR_Register is record -- Read-only. Activity In Progress AIP : PMC_PMC_SLPWK_AIPR_AIP_Field; -- unspecified Reserved_1_31 : Interfaces.SAM.UInt31; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for PMC_PMC_SLPWK_AIPR_Register use record AIP at 0 range 0 .. 0; Reserved_1_31 at 0 range 1 .. 31; end record; subtype PMC_PMC_APLLACR_DCOFLTSEL_Field is Interfaces.SAM.UInt4; subtype PMC_PMC_APLLACR_FLTSEL_Field is Interfaces.SAM.UInt4; subtype PMC_PMC_APLLACR_BIAS_Field is Interfaces.SAM.UInt2; -- Audio PLL Analog Configuration Register type PMC_PMC_APLLACR_Register is record -- DCO Filter Selection DCOFLTSEL : PMC_PMC_APLLACR_DCOFLTSEL_Field := 16#0#; -- PLL Filter Selection FLTSEL : PMC_PMC_APLLACR_FLTSEL_Field := 16#0#; -- Bias Voltage Selection BIAS : PMC_PMC_APLLACR_BIAS_Field := 16#0#; -- unspecified Reserved_10_31 : Interfaces.SAM.UInt22 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for PMC_PMC_APLLACR_Register use record DCOFLTSEL at 0 range 0 .. 3; FLTSEL at 0 range 4 .. 7; BIAS at 0 range 8 .. 9; Reserved_10_31 at 0 range 10 .. 31; end record; subtype PMC_PMC_WMST_WMST_Field is Interfaces.SAM.Byte; -- Write Access Password type PMC_WMST_KEY_Field is ( -- Reset value for the field Pmc_Wmst_Key_Field_Reset, -- Writing any other value in this field aborts the write -- operation.Always reads as 0. Passwd) with Size => 8; for PMC_WMST_KEY_Field use (Pmc_Wmst_Key_Field_Reset => 0, Passwd => 90); -- Wait Mode Startup Time Register type PMC_PMC_WMST_Register is record -- Wait Mode Startup Time WMST : PMC_PMC_WMST_WMST_Field := 16#0#; -- unspecified Reserved_8_23 : Interfaces.SAM.UInt16 := 16#0#; -- Write Access Password KEY : PMC_WMST_KEY_Field := Pmc_Wmst_Key_Field_Reset; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for PMC_PMC_WMST_Register use record WMST at 0 range 0 .. 7; Reserved_8_23 at 0 range 8 .. 23; KEY at 0 range 24 .. 31; end record; ----------------- -- Peripherals -- ----------------- -- Power Management Controller type PMC_Peripheral is record -- System Clock Enable Register PMC_SCER : aliased PMC_PMC_SCER_Register; -- System Clock Disable Register PMC_SCDR : aliased PMC_PMC_SCDR_Register; -- System Clock Status Register PMC_SCSR : aliased PMC_PMC_SCSR_Register; -- Peripheral Clock Enable Register 0 PMC_PCER0 : aliased PMC_PMC_PCER0_Register; -- Peripheral Clock Disable Register 0 PMC_PCDR0 : aliased PMC_PMC_PCDR0_Register; -- Peripheral Clock Status Register 0 PMC_PCSR0 : aliased PMC_PMC_PCSR0_Register; -- UTMI Clock Register CKGR_UCKR : aliased PMC_CKGR_UCKR_Register; -- Main Oscillator Register CKGR_MOR : aliased PMC_CKGR_MOR_Register; -- Main Clock Frequency Register CKGR_MCFR : aliased PMC_CKGR_MCFR_Register; -- PLLA Register CKGR_PLLAR : aliased PMC_CKGR_PLLAR_Register; -- Master Clock Register PMC_MCKR : aliased PMC_PMC_MCKR_Register; -- USB Clock Register PMC_USB : aliased PMC_PMC_USB_Register; -- Programmable Clock Register (chid = 0) 0 PMC_PCK : aliased PMC_PMC_PCK_Registers; -- Interrupt Enable Register PMC_IER : aliased PMC_PMC_IER_Register; -- Interrupt Disable Register PMC_IDR : aliased PMC_PMC_IDR_Register; -- Status Register PMC_SR : aliased PMC_PMC_SR_Register; -- Interrupt Mask Register PMC_IMR : aliased PMC_PMC_IMR_Register; -- Fast Startup Mode Register PMC_FSMR : aliased PMC_PMC_FSMR_Register; -- Fast Startup Polarity Register PMC_FSPR : aliased PMC_PMC_FSPR_Register; -- Fault Output Clear Register PMC_FOCR : aliased PMC_PMC_FOCR_Register; -- Write Protection Mode Register PMC_WPMR : aliased PMC_PMC_WPMR_Register; -- Write Protection Status Register PMC_WPSR : aliased PMC_PMC_WPSR_Register; -- Version Register PMC_VERSION : aliased PMC_PMC_VERSION_Register; -- Peripheral Clock Enable Register 1 PMC_PCER1 : aliased PMC_PMC_PCER1_Register; -- Peripheral Clock Disable Register 1 PMC_PCDR1 : aliased PMC_PMC_PCDR1_Register; -- Peripheral Clock Status Register 1 PMC_PCSR1 : aliased PMC_PMC_PCSR1_Register; -- Peripheral Control Register PMC_PCR : aliased PMC_PMC_PCR_Register; -- Oscillator Calibration Register PMC_OCR : aliased PMC_PMC_OCR_Register; -- SleepWalking Enable Register 0 PMC_SLPWK_ER0 : aliased PMC_PMC_SLPWK_ER0_Register; -- SleepWalking Disable Register 0 PMC_SLPWK_DR0 : aliased PMC_PMC_SLPWK_DR0_Register; -- SleepWalking Status Register 0 PMC_SLPWK_SR0 : aliased PMC_PMC_SLPWK_SR0_Register; -- SleepWalking Activity Status Register 0 PMC_SLPWK_ASR0 : aliased PMC_PMC_SLPWK_ASR0_Register; -- PLL Maximum Multiplier Value Register PMC_PMMR : aliased PMC_PMC_PMMR_Register; -- SleepWalking Enable Register 1 PMC_SLPWK_ER1 : aliased PMC_PMC_SLPWK_ER1_Register; -- SleepWalking Disable Register 1 PMC_SLPWK_DR1 : aliased PMC_PMC_SLPWK_DR1_Register; -- SleepWalking Status Register 1 PMC_SLPWK_SR1 : aliased PMC_PMC_SLPWK_SR1_Register; -- SleepWalking Activity Status Register 1 PMC_SLPWK_ASR1 : aliased PMC_PMC_SLPWK_ASR1_Register; -- SleepWalking Activity In Progress Register PMC_SLPWK_AIPR : aliased PMC_PMC_SLPWK_AIPR_Register; -- Audio PLL Analog Configuration Register PMC_APLLACR : aliased PMC_PMC_APLLACR_Register; -- Wait Mode Startup Time Register PMC_WMST : aliased PMC_PMC_WMST_Register; end record with Volatile; for PMC_Peripheral use record PMC_SCER at 16#0# range 0 .. 31; PMC_SCDR at 16#4# range 0 .. 31; PMC_SCSR at 16#8# range 0 .. 31; PMC_PCER0 at 16#10# range 0 .. 31; PMC_PCDR0 at 16#14# range 0 .. 31; PMC_PCSR0 at 16#18# range 0 .. 31; CKGR_UCKR at 16#1C# range 0 .. 31; CKGR_MOR at 16#20# range 0 .. 31; CKGR_MCFR at 16#24# range 0 .. 31; CKGR_PLLAR at 16#28# range 0 .. 31; PMC_MCKR at 16#30# range 0 .. 31; PMC_USB at 16#38# range 0 .. 31; PMC_PCK at 16#40# range 0 .. 255; PMC_IER at 16#60# range 0 .. 31; PMC_IDR at 16#64# range 0 .. 31; PMC_SR at 16#68# range 0 .. 31; PMC_IMR at 16#6C# range 0 .. 31; PMC_FSMR at 16#70# range 0 .. 31; PMC_FSPR at 16#74# range 0 .. 31; PMC_FOCR at 16#78# range 0 .. 31; PMC_WPMR at 16#E4# range 0 .. 31; PMC_WPSR at 16#E8# range 0 .. 31; PMC_VERSION at 16#FC# range 0 .. 31; PMC_PCER1 at 16#100# range 0 .. 31; PMC_PCDR1 at 16#104# range 0 .. 31; PMC_PCSR1 at 16#108# range 0 .. 31; PMC_PCR at 16#10C# range 0 .. 31; PMC_OCR at 16#110# range 0 .. 31; PMC_SLPWK_ER0 at 16#114# range 0 .. 31; PMC_SLPWK_DR0 at 16#118# range 0 .. 31; PMC_SLPWK_SR0 at 16#11C# range 0 .. 31; PMC_SLPWK_ASR0 at 16#120# range 0 .. 31; PMC_PMMR at 16#130# range 0 .. 31; PMC_SLPWK_ER1 at 16#134# range 0 .. 31; PMC_SLPWK_DR1 at 16#138# range 0 .. 31; PMC_SLPWK_SR1 at 16#13C# range 0 .. 31; PMC_SLPWK_ASR1 at 16#140# range 0 .. 31; PMC_SLPWK_AIPR at 16#144# range 0 .. 31; PMC_APLLACR at 16#158# range 0 .. 31; PMC_WMST at 16#15C# range 0 .. 31; end record; -- Power Management Controller PMC_Periph : aliased PMC_Peripheral with Import, Address => System'To_Address (16#400E0600#); end Interfaces.SAM.PMC;
with impact.d3.Quaternions; with impact.d3.Matrix, interfaces.c.Pointers; package body impact.d3.Transform is type Scalars is array (Natural range <>) of aliased Real; package scalar_Pointers is new interfaces.c.Pointers (Natural, Real, Scalars, 0.0); function to_Transform (q : in Quaternion; c : in Vector_3 := math.Origin_3d) return Transform_3d is use linear_Algebra_3d, impact.d3.Matrix; begin return (to_Matrix (q), c); end to_Transform; function to_Transform (m : in Matrix_3x3; c : in Vector_3 := math.Origin_3d) return Transform_3d is begin return (m, c); end to_Transform; procedure mult (Self : out Transform_3d; t1, -- 't1' Transform 1 t2 : in Transform_3d) is use math.Vectors; begin Self := (t1.Rotation * t2.Rotation, Transformed (t1, t2.Translation)); end mult; function transformed (Self : in Transform_3d; x : in Vector_3) return Vector_3 is use impact.d3.Matrix, math.Vectors; begin return ((getRow (Self.Rotation, 1) * x + Self.Translation (1)), (getRow (Self.Rotation, 2) * x + Self.Translation (2)), (getRow (Self.Rotation, 3) * x + Self.Translation (3))); end transformed; function "*" (Left : in Transform_3d; Right : in Quaternion) return Quaternion is use impact.d3.Matrix, impact.d3.Quaternions; begin return multiply (getRotation (Left), Right); end "*"; function getRotation (Self : in Transform_3d) return Quaternion is use impact.d3.Matrix; q : Quaternion; begin getRotation (self.Rotation, q); return q; end getRotation; function getBasis (Self : in Transform_3d) return Matrix_3x3 is begin return self.Rotation; end getBasis; function getBasis (Self : access Transform_3d) return access Matrix_3x3 is begin return self.Rotation'Access; end getBasis; function getOrigin (Self : in Transform_3d) return Vector_3 is begin return self.Translation; end getOrigin; function getOrigin (Self : access Transform_3d) return access Vector_3 is begin return self.Translation'Unchecked_Access; end getOrigin; procedure setFromOpenGLMatrix (Self : in out Transform_3d; m : access Real) is use impact.d3.Matrix, scalar_Pointers; Start : constant scalar_Pointers.Pointer := m.all'Access; begin setFromOpenGLSubMatrix (Self.Rotation, m); self.Translation := (Pointer (Start + 12).all, Pointer (Start + 13).all, Pointer (Start + 14).all); end setFromOpenGLMatrix; procedure getOpenGLMatrix (Self : in Transform_3d; m : access Real) is use impact.d3.Matrix, scalar_Pointers; Start : constant scalar_Pointers.Pointer := m.all'Access; begin getOpenGLSubMatrix (Self.Rotation, m); Pointer (Start + 12).all := Self.Translation (1); Pointer (Start + 13).all := Self.Translation (2); Pointer (Start + 14).all := Self.Translation (3); Pointer (Start + 15).all := 1.0; end getOpenGLMatrix; procedure setOrigin (Self : in out Transform_3d; origin : in Vector_3) is begin self.Translation := origin; end setOrigin; procedure setBasis (Self : in out Transform_3d; basis : in Matrix_3x3) is begin self.Rotation := basis; end setBasis; procedure setRotation (Self : in out Transform_3d; q : in Quaternion) is use impact.d3.Matrix; begin setRotation (Self.Rotation, q); end setRotation; procedure setIdentity (Self : in out Transform_3d) is use impact.d3.Matrix; begin setIdentity (Self.Rotation); self.Translation := (0.0, 0.0, 0.0); end setIdentity; -- function "*" (Left : in Transform; Right : in Transform_3d) return Transform_3d -- is -- Result : Transform_3d; -- begin -- mult (Result, Left, Right); -- return Result; -- end; function inverse (Self : in Transform_3d) return Transform_3d is use math.Vectors; inv : constant Matrix_3x3 := transpose (Self.Rotation); begin return (inv, inv * (-self.Translation)); end inverse; function getIdentity return Transform_3d is begin return (impact.d3.Matrix.getIdentity, (0.0, 0.0, 0.0)); end getIdentity; function inverseTimes (Self : in Transform_3d; t : in Transform_3d) return Transform_3d is use impact.d3.Matrix; v : constant Vector_3 := getOrigin (t) - Self.Translation; begin return (transposeTimes (Self.Rotation, t.Rotation), v * Self.Rotation); end inverseTimes; function invXform (Self : in Transform_3d; inVec : in Vector_3) return Vector_3 is use impact.d3.Matrix, math.Vectors; v : constant Vector_3 := inVec - Self.Translation; begin return Transpose (Self.Rotation) * v; end invXform; end impact.d3.Transform;
-- Lumen.GLU -- Lumen's own thin OpenGL utilities bindings -- -- Chip Richards, NiEstu, Phoenix AZ, Summer 2010 -- This code is covered by the ISC License: -- -- Copyright © 2010, NiEstu -- -- Permission to use, copy, modify, and/or distribute this software for any -- purpose with or without fee is hereby granted, provided that the above -- copyright notice and this permission notice appear in all copies. -- -- The software is provided "as is" and the author disclaims all warranties -- with regard to this software including all implied warranties of -- merchantability and fitness. In no event shall the author be liable for any -- special, direct, indirect, or consequential damages or any damages -- whatsoever resulting from loss of use, data or profits, whether in an -- action of contract, negligence or other tortious action, arising out of or -- in connection with the use or performance of this software. -- Environment with System; with Lumen.GL; use Lumen.GL; package Lumen.GLU is --------------------------------------------------------------------------- -- Build mipmaps function Build_1D_Mipmaps (Target : in Enum; Components : in Int; Width : in Int; Format : in Enum; Data_Type : in Enum; Data : in System.Address) return Int; function Build_2D_Mipmaps (Target : in Enum; Components : in Int; Width : in Int; Height : in Int; Format : in Enum; Data_Type : in Enum; Data : in System.Address) return Int; -- Projections procedure Ortho_2D (Left : in Double; Right : in Double; Bottom : in Double; Top : in Double); procedure Perspective (FOV_Y_Angle, Aspect, Z_Near, Z_Far : in Double); -- Quadrics type Quadric is new Pointer; function New_Quadric return Quadric; procedure Delete_Quadric (Quad : in Quadric); procedure Quadric_Draw_Style (Quad : in Quadric; Draw : in Enum); procedure Quadric_Normals (Quad : in Quadric; Normal : in Enum); procedure Quadric_Orientation (Quad : in Quadric; Orientation : in Enum); procedure Quadric_Texture (Quad : in Quadric; Texture : in Bool); -- Shapes procedure Cylinder (Quad : in Quadric; Base : in Double; Top : in Double; Height : in Double; Slices : in Int; Stacks : in Int); procedure Disk (Quad : in Quadric; Inner : in Double; Outer : in Double; Slices : in Int; Loops : in Int); procedure Partial_Disk (Quad : in Quadric; Inner : in Double; Outer : in Double; Slices : in Int; Loops : in Int; Start : in Double; Sweep : in Double); procedure Sphere (Quad : in Quadric; Radius : in Double; Slices : in Int; Stacks : in Int); --------------------------------------------------------------------------- private -- These can be bound directly pragma Import (StdCall, Build_1D_Mipmaps, "gluBuild1DMipmaps"); pragma Import (StdCall, Build_2D_Mipmaps, "gluBuild2DMipmaps"); pragma Import (StdCall, Ortho_2D, "gluOrtho2D"); pragma Import (StdCall, Perspective, "gluPerspective"); pragma Import (StdCall, New_Quadric, "gluNewQuadric"); pragma Import (StdCall, Delete_Quadric, "gluDeleteQuadric"); pragma Import (StdCall, Quadric_Draw_Style, "gluQuadricDrawStyle"); pragma Import (StdCall, Quadric_Orientation, "gluQuadricOrientation"); pragma Import (StdCall, Quadric_Normals, "gluQuadricNormals"); pragma Import (StdCall, Quadric_Texture, "gluQuadricTexture"); pragma Import (StdCall, Cylinder, "gluCylinder"); pragma Import (StdCall, Sphere, "gluSphere"); pragma Import (StdCall, Disk, "gluDisk"); pragma Import (StdCall, Partial_Disk, "gluPartialDisk"); end Lumen.GLU;
with Ada.Text_Io, Ada.Integer_Text_IO, Ada.Unchecked_Conversion, Ada.Strings.Fixed; use Ada.Text_Io, Ada.Integer_Text_IO; procedure Pixel_Colour is type Pixel_Colour_Type is (Black, Red, Green, Yellow, Blue, Magenta, Cyan, White); for Pixel_Colour_Type use (Black => 40, Red => 41, Green => 42, Yellow => 43, Blue => 44, Magenta => 45, Cyan => 46, White => 47); function Colour_To_Integer is new Ada.Unchecked_Conversion (Source => Pixel_Colour_Type, Target => Integer); type Pixel_Data_Type is array (Positive range <>) of Pixel_Colour_Type; Pixel_Data : constant Pixel_Data_Type := (Yellow, Black, Yellow, Black, Red, Green, Blue, White); begin for I in Pixel_Data'Range loop Put( Character'Val(16#1b#) & "[" ); Put( Colour_To_Integer(Pixel_Data(I)), Width => 0); Put( "m " ); end loop; Put( Character'Val(16#1b#) & "[0m" ); end Pixel_Colour;
-- Abstract : -- -- call the GPS indentation engine with debug text -- -- Copyright (C) 2017 All Rights Reserved. -- -- This program is free software; you can redistribute it and/or -- modify it under terms of the GNU General Public License as -- published by the Free Software Foundation; either version 3, or (at -- your option) any later version. This program is distributed in the -- hope that it will be useful, but WITHOUT ANY WARRANTY; without even -- the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -- PURPOSE. See the GNU General Public License for more details. You -- should have received a copy of the GNU General Public License -- distributed with this program; see file COPYING. If not, write to -- the Free Software Foundation, 51 Franklin Street, Suite 500, Boston, -- MA 02110-1335, USA. pragma License (GPL); with Ada.Text_IO; use Ada.Text_IO; with Ada_Analyzer; with Case_Handling; with GNATCOLL.Symbols; with Language; procedure Debug_GPS_Indent is NL : constant Character := ASCII.LF; Buffer : constant String := "procedure Bug_002 is begin" & NL & "Error_Report.Report_Error (Severity =>" & NL & "Error_Report.Severe," & NL & "Description => ""In theory the counterp_process..., "" &" & NL & """as they should not differ but they do... """ & NL & "& ""the indexes, so that we do not crash....""," & NL & "Title => ""Curtain indexes should not differ but they do.""," & NL & "Caller_Scope => ""Curtain_Indexes_May_Differ"");" & NL & "end Bug_002;"; procedure Replace_Cb (Line : in Natural; First : in Natural; Last : in Natural; Replace : in String) is pragma Unreferenced (Last); begin -- Provide a place to put a debugger break when an indentation is computed. -- analyze calls replace_cb for ":", ":=" etc. We only -- want the leading spaces, for indentation. if Replace'Length > 0 and First = 1 then Put_Line (Natural'Image (Line) & Natural'Image (Replace'Length)); end if; end Replace_Cb; begin Ada_Analyzer.Analyze_Ada_Source (Buffer, GNATCOLL.Symbols.Allocate, Indent_Params => (Indent_Level => 3, Indent_Continue => 2, Indent_Decl => 2, -- no ada-mode equivalent Indent_Conditional => 1, -- no ada-mode equivalent Indent_Record => 3, Indent_Case_Extra => Language.Non_RM_Style, Casing_Policy => Case_Handling.Disabled, Reserved_Casing => Case_Handling.Unchanged, Ident_Casing => Case_Handling.Unchanged, Format_Operators => False, Use_Tabs => False, Align_On_Colons => False, Align_On_Arrows => False, Align_Decl_On_Colon => False, Indent_Comments => True, Stick_Comments => False), -- no ada-mode equivalent. From => 1, To => 7, Replace => Replace_Cb'Unrestricted_Access); end Debug_GPS_Indent;
with GNAT.Source_Info; package body GNATCOLL.uuid.Test is ---------- -- Name -- ---------- function Name (T : Test_Case) return AUnit.Test_String is pragma Unreferenced (T); begin return AUnit.Format (GNAT.Source_Info.File); end Name; procedure test_Generate (Test : in out AUnit.Test_Cases.Test_Case'Class) is t : UUID; begin t.Generate; t.Generate_Random; Test.Assert (t.Get_Type = DCE_RANDOM, "Get_Type RANDOM"); t.Generate_Time; Test.Assert (t.Get_Type = DCE_TIME, "Get_Type TIME"); Test.Assert (t.Get_Variant = DCE, "Get_Variant"); end test_Generate; procedure test_Parse (Test : in out AUnit.Test_Cases.Test_Case'Class) is t : UUID; t2 : UUID; begin t.Generate_Random; t2 := Parse (t.Unparse); Test.Assert (t = t2, "Roundtrip failed"); t.Clear; Test.Assert (t.Unparse_Lower = "00000000-0000-0000-0000-000000000000", "Unparse_Lower"); Test.Assert (t.Unparse_Upper = "00000000-0000-0000-0000-000000000000", "Unparse_Upper"); end test_Parse; procedure test_Clear (Test : in out AUnit.Test_Cases.Test_Case'Class) is t : UUID; begin t.Clear; Test.Assert (t.Is_Null, "Clear failed"); t.Generate_Random; Test.Assert (not t.Is_Null, "Fill failed"); end test_Clear; procedure test_gtlt (Test : in out AUnit.Test_Cases.Test_Case'Class) is t, t2 : UUID; begin t.Generate_Time; t2.Generate_Time; Test.Assert (t2 > t, "> failed"); Test.Assert (not (t2 < t), "< Faild"); Test.Assert (not (t2 = t), "= Faild"); end test_gtlt; -------------------- -- Register_Tests -- -------------------- procedure Register_Tests (T : in out Test_Case) is use AUnit.Test_Cases.Registration; begin Register_Routine (T, test_Generate'Access, "test_Generate"); Register_Routine (T, test_Parse'Access, "test_Parse"); Register_Routine (T, test_Clear'Access, "test_Clear"); Register_Routine (T, test_gtlt'Access, "test_gtlt"); end Register_Tests; end GNATCOLL.uuid.Test;
package Opt18 is type Cart_Axis_Type is (X, Y, Z); type Cart_Vector_Type is array (Cart_Axis_Type) of Float; function Mag (Item : in Cart_Vector_Type) return Float; type Unit_Vector_Type is array (Cart_Axis_Type) of Float; type Mag_Axis_Type is record Mag : Float; Axis : Unit_Vector_Type; end record; type Unit_Quaternion_Type is record X : Float; Y : Float; Z : Float; S : Float; end record; function Unit_Quaternion_To_Mag_Axis (Quaternion : in Unit_Quaternion_Type) return Mag_Axis_Type; X_Unit : constant Unit_Vector_Type := (1.0, 0.0, 0.0); end Opt18;
----------------------------------------------------------------------- -- babel-base-users-- User's database for file owership identification -- Copyright (C) 2014, 2015 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 System; with Interfaces.C.Strings; package body Babel.Base.Users is use type Interfaces.C.int; use type Interfaces.C.Strings.chars_ptr; type Passwd is record pw_name : Interfaces.C.Strings.chars_ptr; pw_passwd : Interfaces.C.Strings.chars_ptr; pw_uid : Util.Systems.Types.uid_t; pw_gid : Util.Systems.Types.gid_t; pw_gecos : Interfaces.C.Strings.chars_ptr; pw_dir : Interfaces.C.Strings.chars_ptr; pw_shell : Interfaces.C.Strings.chars_ptr; end record; pragma Convention (C, Passwd); type Passwd_Access is access all Passwd; type Group is record gr_name : Interfaces.C.Strings.chars_ptr; gr_passwd : Interfaces.C.Strings.chars_ptr; gr_gid : Util.Systems.Types.gid_t; gr_mem : Interfaces.C.Strings.chars_ptr; end record; pragma Convention (C, Group); type Group_Access is access all Group; -- Get the user name that correspond to the given user ID (looking at /etc/passwd). function Get_User (Id : in Natural) return String; -- Get the user UID that corresponds to the given user name (looking at /etc/passwd). function Get_User (Name : in String) return Natural; -- Get the group name that correspond to the given group ID (looking at /etc/group). function Get_Group (Id : in Natural) return String; -- Get the group UID that corresponds to the given group name (looking at /etc/group). function Get_Group (Name : in String) return Natural; -- ------------------------------ -- Get the user name that correspond to the given user ID (looking at /etc/passwd). -- ------------------------------ function Get_User (Id : in Natural) return String is use Util.Systems.Types; function getpwuid_r (Id : Util.Systems.Types.uid_t; Pwd : Passwd_Access; Buf : System.Address; Buflen : Interfaces.C.size_t; Res : System.Address) return Interfaces.C.int; pragma Import (C, getpwuid_r, "getpwuid_r"); Pwd : aliased Passwd; Pwd_Res : aliased Passwd_Access; Buf : aliased String (1 .. 4096); Res : Interfaces.C.int; begin Res := getpwuid_r (uid_t (Id), Pwd'Unchecked_Access, Buf (1)'Address, Buf'Length, Pwd_Res'Address); if Res /= 0 or else Pwd_Res = null or else Pwd.pw_name = Interfaces.C.Strings.Null_Ptr then return ""; end if; return Interfaces.C.Strings.Value (Pwd.pw_name); end Get_User; -- ------------------------------ -- Get the user UID that corresponds to the given user name (looking at /etc/passwd). -- ------------------------------ function Get_User (Name : in String) return Natural is use Util.Systems.Types; function getpwnam_r (Name : Interfaces.C.Strings.chars_ptr; Pwd : Passwd_Access; Buf : System.Address; Buflen : Interfaces.C.size_t; Res : System.Address) return Interfaces.C.int; pragma Import (C, getpwnam_r, "getpwnam_r"); Pwd : aliased Passwd; Pwd_Res : aliased Passwd_Access; Buf : aliased String (1 .. 4096); Res : Interfaces.C.int; Ptr : Interfaces.C.Strings.chars_ptr := Interfaces.C.Strings.New_String (Name); begin Res := getpwnam_r (Ptr, Pwd'Unchecked_Access, Buf (1)'Address, Buf'Length, Pwd_Res'Address); Interfaces.C.Strings.Free (Ptr); if Res /= 0 or else Pwd_Res = null or else Pwd.pw_name = Interfaces.C.Strings.Null_Ptr then return INVALID_ID; end if; return Natural (Pwd.pw_uid); end Get_User; -- ------------------------------ -- Get the group name that correspond to the given group ID (looking at /etc/group). -- ------------------------------ function Get_Group (Id : in Natural) return String is use Util.Systems.Types; function getgrgid_r (Id : Util.Systems.Types.uid_t; Grp : Group_Access; Buf : System.Address; Buflen : Interfaces.C.size_t; Res : System.Address) return Interfaces.C.int; pragma Import (C, getgrgid_r, "getgrgid_r"); Grp : aliased Group; Grp_Res : aliased Group_Access; Buf : aliased String (1 .. 4096); Res : Interfaces.C.int; begin Res := getgrgid_r (gid_t (Id), Grp'Unchecked_Access, Buf (1)'Address, Buf'Length, Grp_Res'Address); if Res /= 0 or else Grp_Res = null or else Grp.gr_name = Interfaces.C.Strings.Null_Ptr then return ""; end if; return Interfaces.C.Strings.Value (Grp.gr_name); end Get_Group; -- ------------------------------ -- Get the group UID that corresponds to the given group name (looking at /etc/group). -- ------------------------------ function Get_Group (Name : in String) return Natural is use Util.Systems.Types; function getgrnam_r (Name : Interfaces.C.Strings.chars_ptr; Grp : Group_Access; Buf : System.Address; Buflen : Interfaces.C.size_t; Res : System.Address) return Interfaces.C.int; pragma Import (C, getgrnam_r, "getgrnam_r"); Grp : aliased Group; Grp_Res : aliased Group_Access; Buf : aliased String (1 .. 4096); Res : Interfaces.C.int; Ptr : Interfaces.C.Strings.chars_ptr := Interfaces.C.Strings.New_String (Name); begin Res := getgrnam_r (Ptr, Grp'Unchecked_Access, Buf (1)'Address, Buf'Length, Grp_Res'Address); Interfaces.C.Strings.Free (Ptr); if Res /= 0 or else Grp_Res = null or else Grp.gr_name = Interfaces.C.Strings.Null_Ptr then return INVALID_ID; end if; return Natural (Grp.gr_gid); end Get_Group; -- ------------------------------ -- Find the UID and GID for the user that corresponds to the given name and group. -- ------------------------------ function Find (From : in Database; User : in String; Group : in String) return User_Type is Result : User_Type; Id : Natural; begin From.Users.Find_Id (User, Get_User'Access, Id, Result.Name); Result.Uid := Uid_Type (Id); From.Groups.Find_Id (Group, Get_Group'Access, Id, Result.Group); Result.Gid := Gid_Type (Id); return Result; end Find; -- ------------------------------ -- Find the UID and GID for the user that corresponds to the given name and group. -- ------------------------------ function Find (From : in Database; User : in Uid_Type; Group : in Gid_Type) return User_Type is Result : User_Type; begin Result.Uid := User; Result.Gid := Group; From.Users.Find_Name (Natural (User), Get_User'Access, Result.Name); From.Groups.Find_Name (Natural (Group), Get_Group'Access, Result.Group); return Result; end Find; -- ------------------------------ -- Get the user name associated with the given UID. -- Returns null if the UID was not found. -- ------------------------------ function Get_Name (From : in Database; Id : in Uid_Type) return Name_Access is Result : Name_Access; begin From.Users.Find_Name (Natural (Id), Get_User'Access, Result); return Result; end Get_Name; -- ------------------------------ -- Get the UID associated with the given user name. -- ------------------------------ function Get_Uid (From : in Database; Name : in String) return Uid_Type is Uid : Natural; Result_Name : Name_Access; begin From.Users.Find_Id (Name, Get_User'Access, Uid, Result_Name); return Uid_Type (Uid); end Get_Uid; -- ------------------------------ -- Get the group name associated with the given GID. -- Returns null if the GID was not found. -- ------------------------------ function Get_Group (From : in Database; Id : in Gid_Type) return Name_Access is Result : Name_Access; begin From.Groups.Find_Name (Natural (Id), Get_Group'Access, Result); return Result; end Get_Group; -- ------------------------------ -- Get the GID associated with the given group name. -- ------------------------------ function Get_Gid (From : in Database; Name : in String) return Gid_Type is Gid : Natural; Result_Name : Name_Access; begin From.Groups.Find_Id (Name, Get_Group'Access, Gid, Result_Name); return Gid_Type (Gid); end Get_Gid; function Hash (Key : in Natural) return Ada.Containers.Hash_Type is begin return Ada.Containers.Hash_Type (Key); end Hash; -- To keep the implementation simple, the same protected type and same hash maps -- is used for the users and groups database. protected body Local_Base is -- ------------------------------ -- Find in the ID map for the associated user/group name. -- If the item is not found in the map, call the <tt>Search</tt> function to resolve it. -- If the ID was not found, return a null name. -- ------------------------------ procedure Find_Name (Id : in Natural; Search : not null access function (Id : in Natural) return String; Name : out Name_Access) is Pos : constant Id_Map.Cursor := Ids.Find (Id); begin if Id_Map.Has_Element (Pos) then Name := Id_Map.Element (Pos); else declare N : constant String := Search (Id); begin if N'Length = 0 then Name := null; else Name := new String'(N); Ids.Insert (Id, Name); Names.Insert (Name, Id); end if; end; end if; end Find_Name; -- ------------------------------ -- Find in the name map for the corresponding ID. -- If the name was not found in the map, call the <tt>Search</tt> function to resolve it. -- ------------------------------ procedure Find_Id (Name : in String; Search : not null access function (Name : in String) return Natural; Id : out Natural; Result : out Name_Access) is Pos : constant Name_Map.Cursor := Names.Find (Name'Unrestricted_Access); begin if Name_Map.Has_Element (Pos) then Id := Name_Map.Element (Pos); Result := Name_Map.Key (Pos); else Id := Search (Name); if Id /= INVALID_ID then declare N : constant Name_Access := new String '(Name); begin Result := N; Ids.Insert (Id, N); Names.Insert (N, Id); end; else Result := null; end if; end if; end Find_Id; procedure Clear is begin -- @todo: release the storage allocated for names. null; end Clear; end Local_Base; overriding procedure Initialize (Db : in out Database) is begin Db.Users := Db.User_Base'Unchecked_Access; Db.Groups := Db.Group_Base'Unchecked_Access; end Initialize; overriding procedure Finalize (Db : in out Database) is begin Db.User_Base.Clear; Db.Group_Base.Clear; end Finalize; end Babel.Base.Users;
------------------------------------------------------------------------------ -- -- -- Copyright (C) 2016, AdaCore -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions are -- -- met: -- -- 1. Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- 2. Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in -- -- the documentation and/or other materials provided with the -- -- distribution. -- -- 3. Neither the name of the copyright holder nor the names of its -- -- contributors may be used to endorse or promote products derived -- -- from this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -- -- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -- -- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -- -- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -- -- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -- -- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -- -- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- -- ------------------------------------------------------------------------------ with STM32.Device; use STM32.Device; with HAL; use HAL; package body Serial_IO.Streaming is ---------------- -- Initialize -- ---------------- procedure Initialize (This : out Serial_Port) is begin Serial_IO.Initialize_Peripheral (This.Device); This.Initialized := True; end Initialize; ----------------- -- Initialized -- ----------------- function Initialized (This : Serial_Port) return Boolean is (This.Initialized); --------------- -- Configure -- --------------- procedure Configure (This : in out Serial_Port; Baud_Rate : Baud_Rates; Parity : Parities := No_Parity; Data_Bits : Word_Lengths := Word_Length_8; End_Bits : Stop_Bits := Stopbits_1; Control : Flow_Control := No_Flow_Control) is begin Serial_IO.Configure (This.Device, Baud_Rate, Parity, Data_Bits, End_Bits, Control); end Configure; ---------------------- -- Await_Send_Ready -- ---------------------- procedure Await_Send_Ready (This : USART) is begin loop exit when Tx_Ready (This); end loop; end Await_Send_Ready; ---------------------- -- Set_Read_Timeout -- ---------------------- procedure Set_Read_Timeout (This : in out Serial_Port; Wait : Time_Span := Time_Span_Last) is begin This.Timeout := Wait; end Set_Read_Timeout; -------------------------- -- Await_Data_Available -- -------------------------- procedure Await_Data_Available (This : USART; Timeout : Time_Span := Time_Span_Last; Timed_Out : out Boolean) is Deadline : constant Time := Clock + Timeout; begin Timed_Out := True; while Clock < Deadline loop if Rx_Ready (This) then Timed_Out := False; exit; end if; end loop; end Await_Data_Available; ---------------- -- Last_Index -- ---------------- function Last_Index (First : Stream_Element_Offset; Count : Long_Integer) return Stream_Element_Offset is begin if First = Stream_Element_Offset'First and then Count = 0 then -- we need to return First - 1, but cannot raise Constraint_Error; -- per RM else return First + Stream_Element_Offset (Count) - 1; end if; end Last_Index; ---------- -- Read -- ---------- overriding procedure Read (This : in out Serial_Port; Buffer : out Ada.Streams.Stream_Element_Array; Last : out Ada.Streams.Stream_Element_Offset) is Raw : UInt9; Timed_Out : Boolean; Count : Long_Integer := 0; begin Receiving : for K in Buffer'Range loop Await_Data_Available (This.Device.Transceiver.all, This.Timeout, Timed_Out); exit Receiving when Timed_Out; Receive (This.Device.Transceiver.all, Raw); Buffer (K) := Stream_Element (Raw); Count := Count + 1; end loop Receiving; Last := Last_Index (Buffer'First, Count); end Read; ----------- -- Write -- ----------- overriding procedure Write (This : in out Serial_Port; Buffer : Ada.Streams.Stream_Element_Array) is begin for Next of Buffer loop Await_Send_Ready (This.Device.Transceiver.all); Transmit (This.Device.Transceiver.all, Stream_Element'Pos (Next)); end loop; end Write; end Serial_IO.Streaming;