repo_name
stringlengths
9
74
language
stringclasses
1 value
length_bytes
int64
11
9.34M
extension
stringclasses
2 values
content
stringlengths
11
9.34M
reznikmm/matreshka
Ada
4,615
adb
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- Open Document Toolkit -- -- -- -- Runtime Library Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2014, Vadim Godunko <[email protected]> -- -- All rights reserved. -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions -- -- are met: -- -- -- -- * Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- -- -- * Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in the -- -- documentation and/or other materials provided with the distribution. -- -- -- -- * Neither the name of the Vadim Godunko, IE nor the names of its -- -- contributors may be used to endorse or promote products derived from -- -- this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -- -- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED -- -- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -- -- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -- -- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -- -- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -- -- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- -- ------------------------------------------------------------------------------ -- $Revision$ $Date$ ------------------------------------------------------------------------------ with Matreshka.DOM_Documents; with Matreshka.ODF_String_Constants; with ODF.DOM.Iterators; with ODF.DOM.Visitors; package body Matreshka.ODF_Anim.Audio_Level_Attributes is ------------ -- Create -- ------------ overriding function Create (Parameters : not null access Matreshka.DOM_Attributes.Attribute_L2_Parameters) return Anim_Audio_Level_Attribute_Node is begin return Self : Anim_Audio_Level_Attribute_Node do Matreshka.ODF_Anim.Constructors.Initialize (Self'Unchecked_Access, Parameters.Document, Matreshka.ODF_String_Constants.Anim_Prefix); end return; end Create; -------------------- -- Get_Local_Name -- -------------------- overriding function Get_Local_Name (Self : not null access constant Anim_Audio_Level_Attribute_Node) return League.Strings.Universal_String is pragma Unreferenced (Self); begin return Matreshka.ODF_String_Constants.Audio_Level_Attribute; end Get_Local_Name; begin Matreshka.DOM_Documents.Register_Attribute (Matreshka.ODF_String_Constants.Anim_URI, Matreshka.ODF_String_Constants.Audio_Level_Attribute, Anim_Audio_Level_Attribute_Node'Tag); end Matreshka.ODF_Anim.Audio_Level_Attributes;
reznikmm/matreshka
Ada
3,970
ads
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- Ada Modeling Framework -- -- -- -- Runtime Library Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2011-2012, Vadim Godunko <[email protected]> -- -- All rights reserved. -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions -- -- are met: -- -- -- -- * Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- -- -- * Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in the -- -- documentation and/or other materials provided with the distribution. -- -- -- -- * Neither the name of the Vadim Godunko, IE nor the names of its -- -- contributors may be used to endorse or promote products derived from -- -- this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -- -- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED -- -- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -- -- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -- -- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -- -- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -- -- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- -- ------------------------------------------------------------------------------ -- $Revision$ $Date$ ------------------------------------------------------------------------------ -- This file is generated, don't edit it. ------------------------------------------------------------------------------ -- A gate is a connection point for relating a message outside an interaction -- fragment with a message inside the interaction fragment. ------------------------------------------------------------------------------ with AMF.UML.Message_Ends; package AMF.UML.Gates is pragma Preelaborate; type UML_Gate is limited interface and AMF.UML.Message_Ends.UML_Message_End; type UML_Gate_Access is access all UML_Gate'Class; for UML_Gate_Access'Storage_Size use 0; end AMF.UML.Gates;
apple-oss-distributions/old_ncurses
Ada
14,659
adb
------------------------------------------------------------------------------ -- -- -- GNAT ncurses Binding Samples -- -- -- -- Sample.Menu_Demo -- -- -- -- B O D Y -- -- -- ------------------------------------------------------------------------------ -- Copyright (c) 1998 Free Software Foundation, Inc. -- -- -- -- Permission is hereby granted, free of charge, to any person obtaining a -- -- copy of this software and associated documentation files (the -- -- "Software"), to deal in the Software without restriction, including -- -- without limitation the rights to use, copy, modify, merge, publish, -- -- distribute, distribute with modifications, sublicense, and/or sell -- -- copies of the Software, and to permit persons to whom the Software is -- -- furnished to do so, subject to the following conditions: -- -- -- -- The above copyright notice and this permission notice shall be included -- -- in all copies or substantial portions of the Software. -- -- -- -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -- -- OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -- -- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -- -- IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -- -- DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -- -- OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR -- -- THE USE OR OTHER DEALINGS IN THE SOFTWARE. -- -- -- -- Except as contained in this notice, the name(s) of the above copyright -- -- holders shall not be used in advertising or otherwise to promote the -- -- sale, use or other dealings in this Software without prior written -- -- authorization. -- ------------------------------------------------------------------------------ -- Author: Juergen Pfeifer <[email protected]> 1996 -- Version Control -- $Revision: 1.1.1.1 $ -- Binding Version 01.00 ------------------------------------------------------------------------------ with Terminal_Interface.Curses; use Terminal_Interface.Curses; with Terminal_Interface.Curses.Panels; use Terminal_Interface.Curses.Panels; with Terminal_Interface.Curses.Menus; use Terminal_Interface.Curses.Menus; with Terminal_Interface.Curses.Menus.Menu_User_Data; with Terminal_Interface.Curses.Menus.Item_User_Data; with Sample.Manifest; use Sample.Manifest; with Sample.Function_Key_Setting; use Sample.Function_Key_Setting; with Sample.Menu_Demo.Handler; with Sample.Helpers; use Sample.Helpers; with Sample.Explanation; use Sample.Explanation; package body Sample.Menu_Demo is package Spacing_Demo is procedure Spacing_Test; end Spacing_Demo; package body Spacing_Demo is procedure Spacing_Test is function My_Driver (M : Menu; K : Key_Code; P : Panel) return Boolean; procedure Set_Option_Key; procedure Set_Select_Key; procedure Set_Description_Key; procedure Set_Hide_Key; package Mh is new Sample.Menu_Demo.Handler (My_Driver); I : Item_Array_Access := new Item_Array' (New_Item ("January", "31 Days"), New_Item ("February", "28/29 Days"), New_Item ("March", "31 Days"), New_Item ("April", "30 Days"), New_Item ("May", "31 Days"), New_Item ("June", "30 Days"), New_Item ("July", "31 Days"), New_Item ("August", "31 Days"), New_Item ("September", "30 Days"), New_Item ("October", "31 Days"), New_Item ("November", "30 Days"), New_Item ("December", "31 Days"), Null_Item); M : Menu := New_Menu (I); Flip_State : Boolean := True; Hide_Long : Boolean := False; type Format_Code is (Four_By_1, Four_By_2, Four_By_3); type Operations is (Flip, Reorder, Reformat, Reselect, Describe); type Change is array (Operations) of Boolean; pragma Pack (Change); No_Change : constant Change := Change'(others => False); Current_Format : Format_Code := Four_By_1; To_Change : Change := No_Change; function My_Driver (M : Menu; K : Key_Code; P : Panel) return Boolean is begin To_Change := No_Change; if K in User_Key_Code'Range then if K = QUIT then return True; end if; end if; if K in Special_Key_Code'Range then case K is when Key_F4 => To_Change (Flip) := True; return True; when Key_F5 => To_Change (Reformat) := True; Current_Format := Four_By_1; return True; when Key_F6 => To_Change (Reformat) := True; Current_Format := Four_By_2; return True; when Key_F7 => To_Change (Reformat) := True; Current_Format := Four_By_3; return True; when Key_F8 => To_Change (Reorder) := True; return True; when Key_F9 => To_Change (Reselect) := True; return True; when Key_F10 => if Current_Format /= Four_By_3 then To_Change (Describe) := True; return True; else return False; end if; when Key_F11 => Hide_Long := not Hide_Long; declare O : Item_Option_Set; begin for J in I'Range loop Get_Options (I (J), O); O.Selectable := True; if Hide_Long then case J is when 1 | 3 | 5 | 7 | 8 | 10 | 12 => O.Selectable := False; when others => null; end case; end if; Set_Options (I (J), O); end loop; end; return False; when others => null; end case; end if; return False; end My_Driver; procedure Set_Option_Key is O : Menu_Option_Set; begin if Current_Format = Four_By_1 then Set_Soft_Label_Key (8, ""); else Get_Options (M, O); if O.Row_Major_Order then Set_Soft_Label_Key (8, "O-Col"); else Set_Soft_Label_Key (8, "O-Row"); end if; end if; Refresh_Soft_Label_Keys_Without_Update; end Set_Option_Key; procedure Set_Select_Key is O : Menu_Option_Set; begin Get_Options (M, O); if O.One_Valued then Set_Soft_Label_Key (9, "Multi"); else Set_Soft_Label_Key (9, "Singl"); end if; Refresh_Soft_Label_Keys_Without_Update; end Set_Select_Key; procedure Set_Description_Key is O : Menu_Option_Set; begin if Current_Format = Four_By_3 then Set_Soft_Label_Key (10, ""); else Get_Options (M, O); if O.Show_Descriptions then Set_Soft_Label_Key (10, "-Desc"); else Set_Soft_Label_Key (10, "+Desc"); end if; end if; Refresh_Soft_Label_Keys_Without_Update; end Set_Description_Key; procedure Set_Hide_Key is begin if Hide_Long then Set_Soft_Label_Key (11, "Enab"); else Set_Soft_Label_Key (11, "Disab"); end if; Refresh_Soft_Label_Keys_Without_Update; end Set_Hide_Key; begin Push_Environment ("MENU01"); Notepad ("MENU-PAD01"); Default_Labels; Set_Soft_Label_Key (4, "Flip"); Set_Soft_Label_Key (5, "4x1"); Set_Soft_Label_Key (6, "4x2"); Set_Soft_Label_Key (7, "4x3"); Set_Option_Key; Set_Select_Key; Set_Description_Key; Set_Hide_Key; Set_Format (M, 4, 1); loop Mh.Drive_Me (M); exit when To_Change = No_Change; if To_Change (Flip) then if Flip_State then Flip_State := False; Set_Spacing (M, 3, 2, 0); else Flip_State := True; Set_Spacing (M); end if; elsif To_Change (Reformat) then case Current_Format is when Four_By_1 => Set_Format (M, 4, 1); when Four_By_2 => Set_Format (M, 4, 2); when Four_By_3 => declare O : Menu_Option_Set; begin Get_Options (M, O); O.Show_Descriptions := False; Set_Options (M, O); Set_Format (M, 4, 3); end; end case; Set_Option_Key; Set_Description_Key; elsif To_Change (Reorder) then declare O : Menu_Option_Set; begin Get_Options (M, O); O.Row_Major_Order := not O.Row_Major_Order; Set_Options (M, O); Set_Option_Key; end; elsif To_Change (Reselect) then declare O : Menu_Option_Set; begin Get_Options (M, O); O.One_Valued := not O.One_Valued; Set_Options (M, O); Set_Select_Key; end; elsif To_Change (Describe) then declare O : Menu_Option_Set; begin Get_Options (M, O); O.Show_Descriptions := not O.Show_Descriptions; Set_Options (M, O); Set_Description_Key; end; else null; end if; end loop; Set_Spacing (M); Flip_State := True; Pop_Environment; pragma Assert (Get_Index (Items (M, 1)) = Get_Index (I (1))); Delete (M); Free (I, True); end Spacing_Test; end Spacing_Demo; procedure Demo is -- We use this datatype only to test the instantiation of -- the Menu_User_Data generic package. No functionality -- behind it. type User_Data is new Integer; type User_Data_Access is access User_Data; -- Those packages are only instantiated to test the usability. -- No real functionality is shown in the demo. package MUD is new Menu_User_Data (User_Data, User_Data_Access); package IUD is new Item_User_Data (User_Data, User_Data_Access); function My_Driver (M : Menu; K : Key_Code; P : Panel) return Boolean; package Mh is new Sample.Menu_Demo.Handler (My_Driver); Itm : Item_Array_Access := new Item_Array' (New_Item ("Menu Layout Options"), New_Item ("Demo of Hook functions"), Null_Item); M : Menu := New_Menu (Itm); U1 : User_Data_Access := new User_Data'(4711); U2 : User_Data_Access; U3 : User_Data_Access := new User_Data'(4712); U4 : User_Data_Access; function My_Driver (M : Menu; K : Key_Code; P : Panel) return Boolean is Idx : constant Positive := Get_Index (Current (M)); begin if K in User_Key_Code'Range then if K = QUIT then return True; elsif K = SELECT_ITEM then if Idx in Itm'Range then Hide (P); Update_Panels; end if; case Idx is when 1 => Spacing_Demo.Spacing_Test; when others => Not_Implemented; end case; if Idx in Itm'Range then Top (P); Show (P); Update_Panels; Update_Screen; end if; end if; end if; return False; end My_Driver; begin Push_Environment ("MENU00"); Notepad ("MENU-PAD00"); Default_Labels; Refresh_Soft_Label_Keys_Without_Update; Set_Pad_Character (M, '|'); MUD.Set_User_Data (M, U1); IUD.Set_User_Data (Itm (1), U3); Mh.Drive_Me (M); MUD.Get_User_Data (M, U2); pragma Assert (U1 = U2 and U1.all = 4711); IUD.Get_User_Data (Itm (1), U4); pragma Assert (U3 = U4 and U3.all = 4712); Pop_Environment; Delete (M); Free (Itm, True); end Demo; end Sample.Menu_Demo;
wookey-project/ewok-legacy
Ada
3,076
adb
-- -- Copyright 2018 The wookey project team <[email protected]> -- - Ryad Benadjila -- - Arnauld Michelizza -- - Mathieu Renard -- - Philippe Thierry -- - Philippe Trebuchet -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- with types.c; with c.kernel; #if CONFIG_KERNEL_PANIC_WIPE with soc; with soc.layout; use soc.layout; #end if; #if not CONFIG_KERNEL_PANIC_FREEZE with m4; with m4.scb; #end if; package body ewok.debug with spark_mode => off is procedure log (s : string; nl : boolean := true) is c_string : types.c.c_string (1 .. s'length + 3); begin for i in s'range loop c_string(1 + i - s'first) := s(i); end loop; if nl then c_string(c_string'last - 2) := ASCII.CR; c_string(c_string'last - 1) := ASCII.LF; c_string(c_string'last) := ASCII.NUL; else c_string(c_string'last - 2) := ASCII.NUL; end if; c.kernel.log (c_string); c.kernel.flush; end log; procedure log (level : t_level; s : string) is begin case level is when DEBUG => log (BG_COLOR_ORANGE & s & BG_COLOR_BLACK); when INFO => log (BG_COLOR_BLUE & s & BG_COLOR_BLACK); when WARNING => log (BG_COLOR_ORANGE & s & BG_COLOR_BLACK); when ERROR .. ALERT => log (BG_COLOR_RED & s & BG_COLOR_BLACK); end case; end log; procedure alert (s : string) is begin log (BG_COLOR_RED & s & BG_COLOR_BLACK, false); end alert; procedure newline is s : constant types.c.c_string (1 .. 3) := (ASCII.CR, ASCII.LF, ASCII.NUL); begin c.kernel.log (s); c.kernel.flush; end newline; procedure panic (s : string) is begin log (BG_COLOR_RED & "panic: " & s & BG_COLOR_BLACK); #if CONFIG_KERNEL_PANIC_FREEZE loop null; end loop; #end if; #if CONFIG_KERNEL_PANIC_REBOOT m4.scb.reset; #end if; #if CONFIG_KERNEL_PANIC_WIPE declare sram : array (0 .. soc.layout.USER_RAM_SIZE) of types.byte with address => to_address(USER_RAM_BASE); begin -- Wiping the user applications in RAM before reseting. Kernel data -- and bss are not cleared because the are in use and there should -- be no sensible content in kernel data (secrets are hold by user tasks). -- TODO: Clearing IPC content sram := (others => 0); m4.scb.reset; end; #end if; end panic; end ewok.debug;
rguilloteau/pok
Ada
1,585
adb
-- POK header -- -- The following file is a part of the POK project. Any modification should -- be made according to the POK licence. You CANNOT use this file or a part -- of a file for your own project. -- -- For more information on the POK licence, please see our LICENCE FILE -- -- Please follow the coding guidelines described in doc/CODING_GUIDELINES -- -- Copyright (c) 2007-2020 POK team package body Main is procedure Printf (String : in Interfaces.C.char_array); pragma Import (C, Printf, "printf"); Pr1_Pdataout_Id : Sampling_Port_Id_Type; procedure Send is T : Standard.Integer := 0; Data : Standard.Integer; Ret : Return_Code_Type; begin T := 3; loop Data := T; Printf ("Send..."); T := T + 1; Write_Sampling_Message (Pr1_Pdataout_Id, Data'Address, 4, Ret); Periodic_Wait (Ret); end loop; end Send; procedure Main is Ret : Return_Code_Type; Attr : Process_Attribute_Type; Id : Process_Id_Type; Port_Name : Sampling_Port_Name_Type := "pr1_pdataout "; begin Port_Name (13) := ASCII.NUL; Create_Sampling_Port (Port_Name, 4, Source, 15, Pr1_Pdataout_Id, Ret); Attr.Period := 1000; Attr.Deadline := Soft; Attr.Time_Capacity := 1; Attr.Stack_Size := 4096; Attr.Entry_Point := Send'Address; Create_Process (Attr, Id, Ret); Set_Partition_Mode (Normal, Ret); end Main; end Main;
AdaCore/training_material
Ada
907
ads
package Program_Structure is generic type T_Formal1_Type is private; package Level1 is procedure Proc (Param : in out T_Formal1_Type); generic type T_Formal2_Type is private; package Level2 is procedure Proc (Param : in out T_Formal2_Type); generic type T_Formal3_Type is private; package Level3 is procedure Proc (Param : in out T_Formal3_Type); generic type T_Formal4_Type is private; package Level4 is procedure Proc (Param : in out T_Formal4_Type); generic type T_Formal5_Type is private; package Level5 is procedure Proc (Param : in out T_Formal5_Type); end Level5; end Level4; end Level3; end Level2; end Level1; end Program_Structure;
BrickBot/Bound-T-H8-300
Ada
125,421
ads
-- Flow (decl) -- -- Flow graph structures. -- -- A component of the Bound-T Worst-Case Execution Time Tool. -- ------------------------------------------------------------------------------- -- Copyright (c) 1999 .. 2015 Tidorum Ltd -- All rights reserved. -- -- Redistribution and use in source and binary forms, with or without -- modification, are permitted provided that the following conditions are met: -- -- 1. Redistributions of source code must retain the above copyright notice, this -- list of conditions and the following disclaimer. -- 2. Redistributions in binary form must reproduce the above copyright notice, -- this list of conditions and the following disclaimer in the documentation -- and/or other materials provided with the distribution. -- -- This software is provided by the copyright holders and contributors "as is" and -- any express or implied warranties, including, but not limited to, the implied -- warranties of merchantability and fitness for a particular purpose are -- disclaimed. In no event shall the copyright owner or contributors be liable for -- any direct, indirect, incidental, special, exemplary, or consequential damages -- (including, but not limited to, procurement of substitute goods or services; -- loss of use, data, or profits; or business interruption) however caused and -- on any theory of liability, whether in contract, strict liability, or tort -- (including negligence or otherwise) arising in any way out of the use of this -- software, even if advised of the possibility of such damage. -- -- Other modules (files) of this software composition should contain their -- own copyright statements, which may have different copyright and usage -- conditions. The above conditions apply to this file. ------------------------------------------------------------------------------- -- -- $Revision: 1.81 $ -- $Date: 2015/10/24 19:36:49 $ -- -- $Log: flow.ads,v $ -- Revision 1.81 2015/10/24 19:36:49 niklas -- Moved to free licence. -- -- Revision 1.80 2013-02-19 09:17:41 niklas -- BT-CH-0245 clean-up. Only descriptions changed. -- -- Revision 1.79 2012-01-19 19:43:29 niklas -- BT-CH-0223: Package License does not depend on package Flow. -- -- Revision 1.78 2011-10-18 20:12:28 niklas -- Added Prime_Address (Node_T), for ALF export. -- -- Revision 1.77 2010-01-30 21:13:29 niklas -- BT-CH-0216: Subprograms have a Return_Method_T attribute. -- -- Revision 1.76 2009-12-27 22:34:31 niklas -- BT-CH-0205: Licensing based on code size and time/space dimensions. -- -- Revision 1.75 2009-11-27 11:28:07 niklas -- BT-CH-0184: Bit-widths, Word_T, failed modular analysis. -- -- Revision 1.74 2008/11/18 15:09:37 niklas -- Added Reject_Resolved_Edge. -- -- Revision 1.73 2008/07/14 19:16:57 niklas -- BT-CH-0135: Assertions on "instructions". -- -- Revision 1.72 2008/06/29 06:15:57 niklas -- Extended Resolve_To_Return to mark the source step as a return -- step with Calls.Return_After. This requires that the Graph also -- be a parameter for Resolve_To_Return. -- -- Revision 1.71 2008/03/11 22:08:06 niklas -- BT-CH-0121: Delayed calls and other SHARC support. -- -- Revision 1.70 2008/02/18 13:00:36 niklas -- Added function Nodes_Containing (Steps) for use in Flow.Computation. -- -- Revision 1.69 2008/01/14 20:36:20 niklas -- BT-CH-0106: Loops.Max_Depth and other changes in Loops. -- -- Revision 1.68 2007/12/27 12:44:43 niklas -- Fixed typo in description of Warning_Opt_T. -- -- Revision 1.67 2007/12/22 15:23:47 niklas -- BT-CH-0101: Option "-trace graph". -- -- Revision 1.66 2007/12/17 13:54:37 niklas -- BT-CH-0098: Assertions on stack usage and final stack height, etc. -- -- Revision 1.65 2007/11/12 21:37:27 niklas -- BT-CH-0097: Only arithmetic analysis marks boundable edge domain. -- -- Revision 1.64 2007/10/28 09:32:47 niklas -- BT-CH-0092: Arithmetic analysis of dynamic data refs is optional. -- -- Revision 1.63 2007/10/26 12:44:35 niklas -- BT-CH-0091: Reanalyse a boundable edge only if its domain grows. -- -- Revision 1.62 2007/08/31 08:44:50 niklas -- Added Warning_Opt_T for better control over warnings from the -- procedures that Add_Dynamic_Edges, in particular to suppress the -- warning when the edge is directly resolved by the data-state. -- -- Revision 1.61 2007/08/27 16:13:59 niklas -- Added Add_Resolved_Dynamic_Edge, making it possible for a boundable -- edge to resolve into another boundable edge. -- -- Revision 1.60 2007/08/25 18:48:37 niklas -- Added Image (Step_Data_Ref) suitable for tracing. -- Added Full_Image (Step_Tag_T) suitable for tracing. -- Made Image (Step_T) privately accessible for tracing purposes. -- Added optional parameter Add_Dynamic_Edge.Warn by which the -- warning can be disabled even under "-warn flow". -- -- Revision 1.59 2007/08/20 12:16:25 niklas -- Support for Storage.Data: Added preconditions for Transformed_Data -- (the effect is not null) and Constrained_Data (the condition is -- neither Never nor Always). -- -- Revision 1.58 2007/07/22 14:39:43 niklas -- Added types Step_Count_T and Node_Count_T and changed the types -- Step_Index_T and Node_Index_T to subtypes. The functions Max_Step -- and Max_Node now return Step/Node_Count_T, allowing a zero value. -- -- Revision 1.57 2007/07/21 18:18:42 niklas -- BT-CH-0064. Support for AVR/IAR switch-handler analysis. -- -- Revision 1.56 2007/06/13 16:28:18 niklas -- Improved description of edge conditions. -- -- Revision 1.55 2007/03/22 12:53:25 niklas -- Added function Prime_Address (Step_Tag_T). -- -- Revision 1.54 2007/01/13 13:51:05 niklas -- BT-CH-0041. -- -- Revision 1.53 2006/11/20 20:20:19 niklas -- BT-CH-0037. -- -- Revision 1.52 2006/10/24 08:44:32 niklas -- BT-CH-0028. -- -- Revision 1.51 2006/05/29 11:22:35 niklas -- BT-CH-0023. -- -- Revision 1.50 2006/05/18 13:02:22 niklas -- Added functions Only_Predecessor and Only_Successor. -- -- Revision 1.49 2006/05/17 20:07:43 niklas -- Added the No_Node constant. -- -- Revision 1.48 2006/05/06 06:59:22 niklas -- BT-CH-0021. -- -- Revision 1.47 2006/04/28 09:16:46 niklas -- Added function Is_Member (Tag, Step_List). -- -- Revision 1.46 2006/02/24 15:55:54 niklas -- Added an overriding "=" for Step_Tag_T, to make sure that we -- use a possible overriding Processor."=" for the State. -- Added function State (Step_Tag_T) for brevity. -- Removed superfluous "in" modes from some function parameters. -- -- Revision 1.45 2005/10/20 15:25:52 niklas -- Added function Effort (Step). -- -- Revision 1.44 2005/10/13 19:27:39 niklas -- BT-CH-0014. -- -- Revision 1.43 2005/09/12 19:03:00 niklas -- BT-CH-0008. -- -- Revision 1.42 2005/09/05 11:23:38 niklas -- BT-CH-0007. -- -- Revision 1.41 2005/09/03 11:50:29 niklas -- BT-CH-0006. -- -- Revision 1.40 2005/09/01 08:03:21 niklas -- Removed unused function Steps_By_Address. -- -- Revision 1.39 2005/08/08 13:59:49 niklas -- Implemented an "=" operation for Node_Set_T to work around a -- bug with packed boolean arrays in Gnat 3.15p. -- -- Revision 1.38 2005/07/01 10:53:48 niklas -- Added exception False_Path. Not yet used here. -- -- Revision 1.37 2005/02/23 09:05:19 niklas -- BT-CH-0005. -- -- Revision 1.36 2005/02/16 21:11:45 niklas -- BT-CH-0002. -- -- Revision 1.35 2004/10/10 09:58:38 niklas -- Add function Time for node edges. -- -- Revision 1.34 2004/04/25 20:41:03 niklas -- Corrected description of Collect_Blocks. -- -- Revision 1.33 2004/04/25 17:44:06 niklas -- First Tidorum version. -- Adapted to use Cell_T stuff from Storage and not from Arithmetic. -- Since Graph_T, Step_T and Step_Edge_T (and others) have reference -- semantics, as parameters they have mode "in" even when the subprogram -- updates the underlying graph, edge or step-edge object. -- Added Dynamic_Edge concept. This will replace flow-dynamism in steps. -- Added the feasible/infeasible concept for edges, including the -- function Feasible_Predecessors (Step). -- Removed the execution-time attribute of node edges (Edge_T). The -- execution time of a node edge is now always taken from the execution -- time of the corresponding step edge. Consequently, removed the -- procedures Set_Time (Edge_T) and Update_Edge_Times. -- Added the procedure Set_Pointers to support partial evaluation of -- dynamism pointer expressions. -- Added support for crude aliasing analysis using alias ranges. -- Moved the operations Count_Memory_Traffic and Work to the child package -- Flow.Execution, where they are more at home. -- Added functions Is_Used and Is_Defined for Storage Location_T values, -- where the interesting cell depends on the code address. -- Modified Add_Cells_Used (By => Node_T) to include cells used in the -- precondition of the edges that leave the node. -- Added several trivial operations and constants for more access and -- control over the data structures here defined. -- -- Revision 1.32 2003/03/11 08:22:40 holsti -- Added Update_Edge_Times. -- -- Revision 1.31 2001/12/10 15:07:19 holsti -- Return_Nodes description corrected. -- Null_Edge added for use in Node_Edge. -- -- Revision 1.30 2001/11/19 11:05:58 saarinen -- Added functions Sources and Targets for Step_Edge_List_T. -- Added function Return_Nodes. -- Added function Node_Edge. -- -- Revision 1.29 2001/05/21 13:42:02 holsti -- The following changes for NC_117: -- Added execution-time attribute to edges and loose edges. -- Added the functions Time and Set_Time (for step-edges and node-edges). -- Added a Time parameter to Add_Edge operations. -- Added function Edge_At to get a step edge by its index. -- Added function Step_Edge to get the step-edge that corresponds -- to a node-edge. -- It is now possible to have more than one edge between two given -- steps or two given nodes. Consequently, removed the function Edge -- (fortunately unused) to return the edge between two steps, and also -- the exception Edge_Unknown. -- Added function Return_Steps. -- -- The following changes for NC_120, NC_121, NC_122, NC_128: -- Replaced function Effort with function Work. -- Added operation Count_Memory_Traffic. -- -- Revision 1.28 2001/03/19 08:16:13 ville -- Added function to add call step -- -- Revision 1.27 2001/03/16 09:35:14 ville -- Added function returning effort of step list -- -- Revision 1.26 2001/03/08 10:38:29 holsti -- Return_Edges and Cells_Defined (By: Graph) added. -- -- Revision 1.25 2001/01/13 11:37:07 holsti -- Removed to-be's in favour or NC's. -- -- Revision 1.24 2001/01/07 21:56:42 holsti -- Step operations added to suppport liveness analysis. -- -- Revision 1.23 2000/12/28 19:43:44 holsti -- Node_At (Step_Address_T) removed (not used). -- -- Revision 1.22 2000/12/28 17:38:34 holsti -- Unresolved_Flow added. -- -- Revision 1.21 2000/12/22 13:33:20 sihvo -- Added Steps_By_Address. -- -- Revision 1.20 2000/08/18 18:14:33 holsti -- Added edge-count types to allow for graph with no edges. -- Unbounded_Vectors Index_Type removed. -- -- Revision 1.19 2000/07/24 22:23:48 holsti -- Resolution_T added. -- -- Revision 1.18 2000/07/21 21:07:05 holsti -- Unresolved_Steps replaces Steps_With_Unresolved_Flow. -- -- Revision 1.17 2000/07/18 19:51:57 holsti -- Node_Containing implemented. -- -- Revision 1.16 2000/07/16 13:06:50 holsti -- Node_Index_List_T and Add_Cells_Accessed added. -- -- Revision 1.15 2000/07/13 14:17:56 langback -- Changed return value type of Cells_Used and Cells_Defined. -- -- Revision 1.14 2000/07/13 10:59:18 langback -- Added function Cells_Used and Cells_Defined (not yet implemented). -- -- Revision 1.13 2000/07/13 10:49:07 langback -- Added function Node_Containg (however, not implemented yet). -- -- Revision 1.12 2000/07/12 20:42:25 holsti -- Added Graph parameter to To_List of Node_Set_T. -- -- Revision 1.11 2000/07/06 13:28:57 langback -- Correction to Edge_At function -- -- Revision 1.10 2000/07/06 13:23:48 langback -- Added Edge_At function over Node_Indexes -- -- Revision 1.9 2000/07/06 12:51:56 holsti -- Node sets added. Edge_At added. -- -- Revision 1.8 2000/06/28 13:37:41 holsti -- Dynamics and Bounds added. -- -- Revision 1.7 2000/06/12 14:02:58 holsti -- Added Cells_In (Graph) (not implemented yet). -- -- Revision 1.6 2000/06/11 21:37:31 holsti -- Added Condition for step-edges. -- -- Revision 1.5 2000/06/11 19:03:53 holsti -- First implementation. -- -- Revision 1.4 2000/05/05 12:06:58 holsti -- Null_Graph added. -- -- Revision 1.3 2000/04/27 10:45:52 holsti -- Using loose graph edges. -- -- Revision 1.2 2000/04/26 14:03:58 holsti -- Added Is_Empty and Take_First. -- -- Revision 1.1 2000/04/23 21:41:14 holsti -- Added Flow package. -- with Arithmetic; with Calling; with License; with Processor; with Storage; with Storage.Bounds; package Flow is -- -- A flow graph is equivalent to a finite-state automaton, with -- an initial node, edges (arcs, transitions) between nodes, and -- a subset of terminal nodes (returns). -- -- A node in the flow graph corresponds to a specific state of -- the target processor's program-sequencing (program flow control) -- function. This is represented by the type Processor.Flow_State_T. -- For a simple processor, this can be just the "Program Counter". -- For a more complex processor, additional sequencer state -- must be simulated, such as instruction pipelines, hardware -- loops, etc. -- -- In some cases, a given value of Processor.Flow_State_T needs to -- be represented by more than one node in the flow graph, to separate -- the several contexts in which this Flow_State_T can occur. Therefore -- the nodes in the graph are identified by a composite type that has -- the Flow_State_T as one component and a context reference as the -- other component. This pair is called a "step tag" for reasons that -- will become apparent below. -- -- An edge in the flow graph corresponds to a state transition -- in the target processor's program sequencer, most often to -- fetch a new instruction. -- -- For WCET analysis, the flow graph of each relevant subprogram -- in the target program is constructed, by decoding the subprogram -- starting from its entry address. -- -- A flow graph can be viewed on two levels: the step level -- and the basic-block level (or just block level, for short): -- -- > A step is an atomic graph node. Decoding a target instruction -- generates steps and edges between steps. -- -- > A basic block is a maximal, linear chain of steps such that -- it can be entered only through its first step and left only -- through its last step. -- -- Decoding a subprogram generates the steps, and edges between -- steps. When these are complete, a specific algorithm is needed -- to create the basic blocks. Edges between steps induce edges -- between blocks, but the two levels of edges are distinguished, -- just as the two levels of nodes are. -- -- Most graph-analysing algorithms in Bound-T work on the block -- level. Types and subprograms for the step level are named -- with the word "Step" and "Step_Edge", while those on the block -- level are named with "Node" and "Edge". -- -- To simplify the incremental decoding and flow-graph building, -- a flow-graph can contain "loose" edges on the step level. -- A loose edge is an edge that starts at an existing step, and -- has a known step-tag as target, but does not yet have a target -- node because the instruction at the target step-tag has not yet -- been decoded. There are separate operations to add bound -- (non-loose) edges (giving both source and target steps) and to -- add an edge that might be loose (giving the source step and the -- step-tag of the target). -- -- The result of WCET analysis is usually to add some information -- to each node and/or edge in a flow-graph. To cater for such -- additions, all nodes (whether steps or blocks) and all edges -- (whether between steps or between blocks) are numbered (indexed) -- sequentially. Thus, the additional data can be represented as -- arrays indexed with the node or edge number. -- -- Loose edges are not numbered and have no influence on the -- numbering of bound edges. -- -- When the decoded subprogram contains dynamic addressing, either -- of data memory (indexed load/store) or of program memory (indexed -- jump or call), some steps/nodes may be left in an unresolved -- state when first decoded. For dynamic jumps or calls, the full -- set of successors may not be known; for dynamic data accesses, -- the precise effect may not be known. When data-flow analysis -- has been applied to the incomplete flow graph, the dynamic -- addresses may be resolved to complete the flow graph and the -- effects. This package keeps track of the remaining unresolved -- steps in the flow graph. -- --- Flow graphs -- type Graph_T is private; -- -- A flow-graph. -- The attributes of a flow-graph include: -- -- > The entry step (and block). -- > The set of steps and blocks. -- > The set of edges (at step level and block level). -- > Possibly a set of "loose" edges where the source step is known -- and the target step-tag is known, but where the target step -- does not yet exist (or did not exist when the loose edge was -- created). -- > Possibly a set of dynamic edges where the source step is known -- but the target step-tag is dynamically computed. -- -- Before use, a Graph_T object must be initialized with the Create -- procedure. -- -- A flow-graph can be empty. A newly Created graph is empty. An -- empty graph has no nodes nor edges nor an entry step. -- -- Graph_T has reference semantics. The values of type Graph_T -- returned by functions in this package are to be understood as -- references to some underlying flow-graph objects; any update -- applied to such a reference is visible via all references to -- the same object. Parameters of type Graph_T generally have -- mode "in" even when the subprogram updates the underlying -- graph object. procedure Create (Graph : in out Graph_T); -- -- Creates a new, empty graph. function Is_Empty (Graph : Graph_T) return Boolean; -- -- Whether the graph is empty. Step_Tag_Unknown : exception; -- -- Raised when some element of a graph (step or node) is -- sought by its tag-value, but the graph does not contain -- an element with the given tag. Step_Tag_In_Use : exception; -- -- Raised when a step with a given step-tag is to be added to a -- graph, but the graph already contains a step with this tag. False_Path : exception; -- -- Raised when any analysis finds a contradiction in the target -- program state, in the current analysis context (target program -- state), to signal that the execution path to this state is false -- (infeasible). type Step_Count_T is new License.Size_Measure_T; type Node_Count_T is new Natural; -- -- A number of steps, a number of nodes. -- For licensing purposes, the size of the analysed part of -- the program is measured by the number of steps in the -- control-flow graphs in the analysis. subtype Step_Index_T is Step_Count_T range 1 .. Step_Count_T'Last; subtype Node_Index_T is Node_Count_T range 1 .. Node_Count_T'Last; -- -- Steps and nodes are numbered from 1 in each graph. type Step_Edge_Count_T is new Natural; type Edge_Count_T is new Natural; -- -- Edges (of both levels) are counted with these types. -- Note that a non-null graph may not have any edges (if it -- has only one step, or node). A graph with more than one step, -- and thus some step-edges, may have only one node, and thus no -- node edges. subtype Step_Edge_Index_T is Step_Edge_Count_T range 1 .. Step_Edge_Count_T'Last; subtype Edge_Index_T is Edge_Count_T range 1 .. Edge_Count_T'Last; -- -- Edges (of both levels) are numbered from 1 in each graph. -- However, there may not be any edges. type Node_Index_List_T is array (Positive range <>) of Node_Index_T; -- -- A list of node indices, with multiple uses. -- The main use for this type is as an alternative representation -- of a node-set (see Node_Set_T, below). function Max_Step (Graph : in Graph_T) return Step_Count_T; function Max_Node (Graph : in Graph_T) return Node_Count_T; function Max_Step_Edge (Graph : in Graph_T) return Step_Edge_Count_T; function Max_Edge (Graph : in Graph_T) return Edge_Count_T; -- -- These functions return the highest sequential number (index) -- of any step, block (node), or edge in the graph. -- All the number sequences start at 1 and run independently. -- If the graph contains no steps, Max_Step returns zero. -- If the graph contains no nodes, Max_Node returns zero. -- If the graph contains no edges at the indicated level, the -- edge number zero (for "no edge") is returned. function Code_Range (Graph : Graph_T) return Storage.Code_Address_Range_T; -- -- The smallest interval of code addresses that contains all the -- prime addresses of the steps in the given Graph. -- -- Note that the steps in the Graph do not necessarily cover every -- address in the interval, perhaps because the code of the subprogram -- is not contiguous in memory or because some step(s) represent more -- than one code memory element. Moreover, the subprogram may contain -- instructions with addresses outside this interval, because a step -- may correspond to a sequence of instructions and only the address of -- the first instruction becomes the prime address of the step. -- --- Step contexts, step data, and step tags -- -- -- We may need to analyse the same instruction, or processor -- flow-state, in different context, separated, for example, by -- the execution path that reaches this instruction, or by the -- values of some variables on which the instruction's effect -- depends, or when integrating a callee subprogram into the -- flow-graph of a caller subprogram ("integrated" decoding) as may -- be needed for the special "helper" routines that some compilers -- use to implement the preludes and postludes of subprograms. -- -- When an instruction is analysed under different conditions in -- this way, we will create as many separate steps in the flow-graph -- to represent this instruction and its effect on the execution. -- The steps must be labeled with different labels or tags. -- -- We group the different reasons for several analyses of the same -- instruction into two groups: -- -- > Values of variables (storage cells) or "data state". -- -- > All the other reasons, eg. integrated decoding of callees. -- -- Accordingly, we define two data types to be components of the -- tag of a step, in addition to Processor.Flow_State_T: -- -- > Step_Data_T to represent the values of variables. -- > Step_Context_T for all the other reasons. type Step_Data_T is abstract tagged null record; -- -- We use different Step_Data_T objects to separate the processor -- states depending on the content (values) of certain storage cells -- although the Processor.Flow_State_T is the same, so that the -- analysis can take these data values into account. -- -- The set of cells that are tracked in this way depends on the -- situation and may be quite different for different Step_Data_T -- objects. -- -- A Step_Data_T models or constrains the values of storage cells -- and is thus similar to Storage.Bounds.Bounds_T. We chose not to -- derive Step_Data_T from Storage.Bounds.Bounds_T because this lets -- each type derived from Step_Data_T use the kind of Bounds_T and -- its particular kind of Apply operation (the general Apply for -- Bounds_T is rather weak in its parameter profile). -- -- The primitive operations of Step_Data_T need, as parameters, -- several data types that will be defined later, so the primitive -- operations are also defined later. type Step_Data_Ref is access all Step_Data_T'Class; -- -- Step data states are separated by the *identity* of a Step_Data_T -- object, not by the *value* of such an object. Thus, we use an -- access to a Step_Data_T object to identify the data state. -- -- The concrete data-state types derived from Step_Data_T should -- keep track of the data states that have been encountered in a -- simulation and the corresponding Step_Data_Ref values. When the -- simulation reaches a state that has occurred before, the same -- Step_Data_Ref should be used (otherwise the number of steps -- generated in the simulation may explode). -- -- Another reason for using an access type is that this package (Flow) -- should not know of, nor depend on, the particular kinds of -- data-state objects that may be needed in the analysis. An access to -- a tagged class answers this need nicely. function Image (Item : Step_Data_Ref) return String; -- -- Describes both the identity (location, address) and the content -- (data constraints). Any_Data : constant Step_Data_Ref := null; -- -- Denotes the absence of constraints on cell values. -- -- This value means that the flow-graph construction process (decoding -- and flow tracing) is currently not simulating any data states. -- -- Data-state types derived from Step_Data_T shall *not* use Any_Data -- to mean that simulation continues but at this point cannot place -- any bounds on the data values. Instead, a non-null Step_Data_Ref -- shall be used, referring to a data state object that, through its -- content, shows that no bounds are known (eg. by using -- Storage.Bounds.Universal_Interval). type Step_Context_T; -- -- We use different Step_Context_T objects to separate the processor -- states that have the same value of Processor.Flow_State_T but -- which should be distinct steps (nodes) in the flow-graph so -- that the analysis can take the context into account. -- -- See below for the full declaration of this type. type Step_Context_Ref is access all Step_Context_T'Class; -- -- Steps contexts are separated by the *identity* of a Step_Contex_T -- object, not by the *value* of such an object. Thus, we use an -- access to a Step_Context_T object to identify the context. -- -- Another reason for using an access type is that this package (Flow) -- should not know of, nor depend on, the particular kinds of -- context objects that may be needed in the analysis. An access to -- a tagged class answers this need nicely. No_Context : constant Step_Context_Ref := null; -- -- A null or empty context. type Step_Context_T is abstract tagged record Outer : Step_Context_Ref; end record; -- -- See the earlier incomplete declaration for the general description -- and motivation of this type. -- -- The contexts of steps in a flow graph may need to be nested. -- For example, when "integrated" decoding a callee into the flow-graph -- of the caller, in an "integrated context", the callee's code may -- contain steps that need additional context, for example a new -- level of integrated decoding. Nested contexts are implemented by -- letting each context object refer to its Outer context, forming -- a root-directed, linked, tree of context objects. -- -- Outer -- Reference to the outer context level, if this is a nested -- context. Null for an unnested (outermost) context. function Image (Item : Step_Context_T) return String is abstract; -- -- A brief mark to show the kind of context. function Nested_Image (Item : Step_Context_Ref) return String; -- -- The Images of the context-nest for the given context. -- This is the concatenation of the Images of the nested contexts, -- from outer to inner. type Step_Tag_T is record Context : Step_Context_Ref; Data : Step_Data_Ref; State : Processor.Flow_State_T; end record; -- -- Unique identifier (tag, key) of a steps (and atomic nodes) in a -- flow graph. -- -- Context -- The generic (not processor-specific) part of the tag, apart -- from the Data state. -- Separates flow-graph steps that need to be analysed separately -- but have the same processor-dependent tag-value (the State) -- and the same Data state. -- May be No_Context. -- Data -- The data state of the tag. This may be generic or may be a -- data-state model defined for a specific processor and perhaps -- a specific compiler. -- Separates flow-graph steps that need to be analysed separately -- for different data states but have the same Context and State. -- Provides operations that can refine and filter the effects -- and conditions of steps and edges as they are being added to -- the flow graph, including resolving dynamic memory references -- and dynamic jumps, calls and calling protocols. -- May be Any_Data. -- State -- The processor-specific part of the tag. Provides all the -- information that the processor-specific instruction decoder -- needs to decode an instruction and insert the corresponding -- step(s) and edges into the flow graph. -- -- Note that the Data state always models a superset of the data -- state that can hold on entry to the step, *even* if the flow-graph -- is extended with new steps and edges after this step is created. -- Any analysis based on the Data state is thus *definitive* for this -- step. For example, if the Data state resolves a boundable edge -- leaving this step, the boundable edge is thereby *fully* resolved -- and can be deleted. -- -- Note, however, that this axiom (Data state is a superset) is -- not automatically maintained and ensured. The processor-specific -- types derived from Step_Data_T must take care to maintain the -- axiom by preventing new edges from targeting existing steps with -- Data components that do not include the data states from the edge. function Image (Item : Step_Tag_T) return String; -- -- A readable but compact description of the Step Tag, built from -- Processor.Image (Item.State) and Nested_Image (Item.Context). function Full_Image (Item : Step_Tag_T) return String; -- -- An image that is complete enough to correspond to the "=" function. function "=" (Left, Right : Step_Tag_T) return Boolean; -- -- Equality is defined with predefined "=" for the Context and Data -- (comparing context and data references, not the underlying objects) -- and Processor."=" for the State. function "<" (Left, Right : Step_Tag_T) return Boolean; -- -- The ordering is lexicographic with the State component -- most significant, the Context component next, and the Data -- component last. -- -- The ordering of States is defined by Processor."<" and the -- ordering for Context and Data is arbitrary (by address). -- --- In_Transit and Transit -- function In_Transit return Step_Data_Ref; -- -- A special and unique Step_Data_Ref that occurs only in a -- Step_Tag_T defined by the Transit function below. This value -- is used to show that a Decoder has used Transit to create the -- target of an edge, delegating the task of data simulation to -- the Add_Edge functions in this package. -- -- This value and the underlying Step_Data_T'Class should not -- be used in any other way. function Transit ( From : Step_Tag_T; To : Processor.Flow_State_T) return Step_Tag_T; -- -- Models a flow-state transition From a state To a new state, -- by constructing the step-tag that has the same context as in -- From but the new flow state defined by To. -- -- Note that the function does *not* model how the effect of -- the From step changes the data state. If From.Data is Any_Data -- then so is the Data in the resulting tag, otherwise the -- resulting tag has the special In_Transit Data component. -- --- Steps in flow graphs -- type Step_T is private; -- -- A step in a flow-graph. -- The attributes of a step include: -- -- > Its index number (1..). -- > Its identifying tag (Step_Tag_T). -- > Its computational effect, in terms of cell updates. This is -- the "primitive" effect, as created by the instruction decoder. -- More refined (resolved, specialized, bounded) effects may -- later be associated with the step (see Flow.Computation). -- > Additional processor-dependent information generated -- and used by the instruction decoder. -- -- The edges connected to the step are not considered attributes -- of the step, but of the graph. -- -- After steps have been collected into basic blocks, the step -- gains a new attribute: the node that contains the step. -- -- Step_T has reference semantics. The values of type Step_T -- returned by functions in this package are to be understood -- as references to some underlying step objects; any update -- applied to such a reference is visible via all references -- to the same object. Parameters of type Step_T generally -- have mode "in" even when the subprogram updates the -- underlying step object. No_Step : constant Step_T; -- -- Signifies the absence of a step. -- The default initial value of any Step_T object. type Step_List_T is array (Positive range <>) of Step_T; -- -- A set (or list) of steps, for example, all successors -- of a given step. function Index_Image (Item : Step_List_T) return String; -- -- Displays the indices of the listed steps, in the order -- they are listed. function No_Steps return Step_List_T; -- -- An empty (null) list of steps. function Is_Member ( Tag : Step_Tag_T; Steps : Step_List_T) return Boolean; -- -- Whether some step in the list of Steps has the given Tag. function Index (Step : Step_T) return Step_Index_T; -- -- The index number of a step. -- These numbers run from 1 to Max_Step. function Tag (Step : Step_T) return Step_Tag_T; -- -- The identifying tag of a step. function State (Step : Step_T) return Processor.Flow_State_T; -- -- Short for Tag (Step).State. function State (Tag : Step_Tag_T) return Processor.Flow_State_T; -- -- Same as Tag.State. function Context (Step : Step_T) return Step_Context_Ref; -- -- Short for Tag (Step).Context. function Data (Step : Step_T) return Step_Data_Ref; -- -- Short for Tag (Step).Data. -- This is the data state on entry to the step. function Data (Tag : Step_Tag_T) return Step_Data_Ref; -- -- Same as Tag.Data. -- This is the data state on entry to the step with this Tag. function Post_Data (Step : Step_T) return Step_Data_Ref; -- -- The data state on exit from the Step, in other words Data (Step) -- transformed by Effect (Step). function Prime_Address (Step : in Step_T) return Processor.Code_Address_T; -- -- Short for Processor.Prime_Address (State (Step)). function Prime_Address (Tag : in Step_Tag_T) return Processor.Code_Address_T; -- -- Short for Processor.Prime_Address (State (Tag)). function Tag_Less (Left, Right : Step_T) return Boolean; -- -- Short for Tag (Left) < Tag (Right). function Transit ( From : Step_T; To : Processor.Flow_State_T) return Step_Tag_T; -- -- Short for Transit (From => Tag (From), To => To). -- -- Note that the function does *not* model how the effect of -- the From step changes the data state. function Effect (Step : in Step_T) return Arithmetic.Effect_T; -- -- The arithmetical effect of the step. function Effect (Step : in Step_T) return Arithmetic.Effect_Ref; -- -- A reference to the effect of the step. -- If the user modifies the effect through the reference, the -- modification becomes permanently associated with the step. -- -- NOTE that the user can cause several steps to share the -- same Effect_T object; if this object is modified via the -- reference, all steps see the modification. function Is_Feasible (Step : Step_T; Within : Graph_T) return Boolean; -- -- Whether the step is really feasible (reachable) in some execution -- of the flow-graph. In some cases, compilers (or our decoders) -- can generate steps that are unreachable because logical conditions -- prevent any execution from entering the step. procedure Set_Effect ( Step : in Step_T; Effect : in Arithmetic.Effect_T); -- -- Changes the effect of the step. -- -- TBC precondition that the -- step has no successors (is not the source of any edge) or that -- the Data of the step-tag is Any_Data. Otherwise, the Data parts -- of the tags of the successors could become inconsistent because -- they depend on Post_Data (Step) which depends on Effect (Step). -- -- The new effect (a copy of the Effect parameter) is not shared -- with any other step. procedure Set_Effect ( Step : in Step_T; Effect : in Arithmetic.Effect_Ref); -- -- Changes the effect of the step, by reference. -- -- TBC preconditions as in the Set_Effect above. -- -- The step's effect will be defined by reference to Effect.all. -- The user must ensure that Effect.all exists as long as needed. -- If the same Effect reference is assigned to several steps, -- these steps will share the underlying Effect_T object, Effect.all. function Target_Range (Step : Step_T) return Storage.Alias_Range_T; -- -- The alias range that can be reached by the assignments in the -- step's effect, under the given level of alias checking. function All_Steps (Within : Graph_T) return Step_List_T; -- -- All the steps in the graph, listed so that the (Positive) index -- of a step in the list is the same as the (Step_Index_T) index of -- the step. function Step_At ( Tag : Step_Tag_T; Within : Graph_T) return Step_T; -- -- Locates the step (if any) with the given Tag, Within the -- given graph. -- If there is no such step, raises Step_Tag_Unknown. function Steps_Containing ( Address : Processor.Code_Address_T; Within : Graph_T; Calls_Too : Boolean) return Step_List_T; -- -- Locates the steps with Prime_Address equal to the given Address, -- optionally including synthetic call steps too. -- There may be zero, one, or several such steps. function Step_At ( Index : Step_Index_T; Within : Graph_T) return Step_T; -- -- The step identified by the given Index, Within the given graph. -- If the index is out of range, Constraint_Error is raised. function Entry_Step (Graph : in Graph_T) return Step_T; -- -- The entry step (entry point) of the graph, which is -- always the first step added to the graph. function Return_Steps (Graph : Graph_T) return Step_List_T; -- -- The return steps of the graph, which are the steps that -- have no leaving edges (Number_From is zero). procedure Set_Info ( Step : in Step_T; Info : in Processor.Step_Info_T); -- -- Updates the processor-dependent information in the step. function Info (Step : Step_T) return Processor.Step_Info_T; -- -- Gets the processor-dependent information in the step. function Effort (Step : Step_T) return Processor.Effort_T; -- -- The computational effort of the step. -- Same as Processor.Effort (Info (Step)). function Some_Dynamic_Edges (Within : Graph_T) return Boolean; -- -- Whether there are some boundable edges Within the -- given graph. The state of resolution of these edges -- does not matter. function Is_Member (Step : Step_T; Of_List : Step_List_T) return Boolean; -- -- Whether the given Step is an element Of the given List. type Bounded_Step_List_T (Max_Length : Natural) is record List : Step_List_T (1 .. Max_Length); Last : Natural := 0; end record; -- -- A dynamically extensible list of steps with a fixed maximum length. -- The list does not contain duplicated steps. -- The list is not necessarily ordered in any way. -- Each object of this type is initialized to the null list. -- -- List, To -- The steps in the list are List(1 .. To). procedure Erase (List : in out Bounded_Step_List_T); -- -- Clears the List to a null list. procedure Add ( Step : in Step_T; To : in out Bounded_Step_List_T); -- -- Adds (inserts) the Step To the given (bounded) step list, -- without adding duplicates. If the target list does not have -- space for the Step, the procedure propagates Constraint_Error. procedure Add ( Steps : in Step_List_T; To : in out Bounded_Step_List_T); -- -- Adds (inserts) all the Steps from the given list To the -- given (bounded) step list, without adding duplicates. -- If the target list does not have space for all steps, the -- procedure propagates Constraint_Error. function To_List (Item : Bounded_Step_List_T) return Step_List_T; -- -- All the elements from the given bounded step-list, as an -- ordinary step-list. function Total_Number_Of_Steps return Step_Count_T; -- -- The total number of steps created and added to any flow-graph. -- This is used for licensing based on the size of the program -- under analysis. function Size_Licence_Valid return Boolean; -- -- Whether the program-size limit of the current licence allows -- analysis of code of the current size (measured by the number -- of steps in all flow-graphs). -- --- Step edges (edges between steps) -- type Step_Edge_T is private; -- -- An edge between steps in a flow-graph. -- The attributes of an edge include: -- -- > Its index number (1..). -- > The source step from which the edge starts. -- > The target step at which the edge ends. -- > The logical precondition for executing the edge, a boolean -- expression to be evaluated after executing the effect of -- the source step of the edge. -- > The execution time of the edge, as some number of -- processor cycles. -- -- Step_Edge_T has reference semantics. The values of type -- Step_Edge_T returned by functions in this package are to be -- understood as references to some underlying step-edge objects; -- any update applied to such a reference is visible via all -- references to the same object. Parameters of type Step_Edge_T -- generally have mode "in" even when the subprogram updates the -- underlying step object. -- -- Within the logical preconditions of the edges emanating from -- a given step, all uses of a given cell represent the same value, -- even if the cell is a volatile cell. To be precise: if a volatile -- cell C is not assigned in the effect of the source step, then all -- uses of C in the effect of the source step, as well as in the -- preconditions of the edges leaving the source step, represent the -- same value of C, conceptually read from C when the step is entered. -- If the volatile cell C is assigned a new value in the effect of -- the source step, then all uses of C in the preconditions of the -- edges leaving the source step represent the value assigned. In -- other words, a volatile cell is not really volatile within a step -- nor during the evaluation of the preconditions of the edges that -- leave the step. The value of the volatile cell is lost (may change -- due to external input) only after evaluating those preconditions, -- before entering the next step. -- -- The above rule or assumptions regarding volatile cells make it -- easier to analyse the preconditions, for example to detect -- mutually exclusive but complete pairs of edges, such as two -- edges where one edge has the precondition "x = 0" and the other -- edge has "x /= 0". (Note that, for such pairs, the preconditions -- are sufficient as well as necessary.) No_Step_Edge : constant Step_Edge_T; -- -- Signifies the absence of a step-edge. -- The default initial value of any Step_Edge_T object. function Index (Edge : in Step_Edge_T) return Step_Edge_Index_T; -- -- The index number of a step edge. -- These numbers run from 1 to Max_Step_Edge. function Source (Edge : in Step_Edge_T) return Step_T; function Target (Edge : in Step_Edge_T) return Step_T; -- -- The source and target steps of the edge. function Condition (Edge : in Step_Edge_T) return Arithmetic.Condition_T; -- -- The precondition (necessary but perhaps not sufficient) for -- executing the edge, when evaluated after the execution of the -- source step of the edge. function Is_Feasible (Edge : Step_Edge_T) return Boolean; -- -- Whether the edge is really feasible (reachable) in some execution -- of the flow-graph. In some cases, compilers (or our decoders) -- can generate edges that are unreachable because logical conditions -- prevent any execution from entering the edge, for example because -- the edge's own precondition is constantly False. procedure Set_Condition ( On : in Step_Edge_T; To : in Arithmetic.Condition_T); -- -- Changes the precondition for executing the edge. The condition -- is expressed for evaluation in the state following the execution -- of the source step of the edge. function Time (Along : in Step_Edge_T) return Processor.Time_T; -- -- The execution time of the edge. -- -- For most processors, instructions can be decoded so that -- edges take no time to execute. In complex processors, a -- positive execution time for an edge can be used to model -- a blocking time or extra delay caused by some interaction -- between the processor resources used by the source step -- and those used by the target step. -- -- For example, in the ADSP-21020, if the source step loads -- a DAG register and the target step uses the same DAG to -- address memory, a conflict on an internal bus means that -- one NOP cycle is executed between the source and target -- steps. This can be modelled by setting one cycle as the -- execution time of the edge. procedure Set_Time ( Along : in Step_Edge_T; To : in Processor.Time_T); -- -- Sets the execution time of the edge. type Step_Edge_List_T is array (Positive range <>) of Step_Edge_T; -- -- A set (or list) of edges, for example, all edges that -- leave a given step. function No_Step_Edges return Step_Edge_List_T; -- -- An empty (null) list of step edges. function Sources ( Edges : Step_Edge_List_T; Unique : Boolean := False) return Step_List_T; -- -- The source steps of the given Edges. -- -- If Unique is False, the result has the same index range as -- the Edges and contains the source of each edge, even if several -- edges have the same source. -- -- If Unique is True, the result contains the source steps of the -- Edges without duplication. The index range of the result is not -- defined. function Targets (Edges : Step_Edge_List_T) return Step_List_T; -- -- The target steps of the given edges. function Edge_At ( Index : Step_Edge_Index_T; Within : Graph_T) return Step_Edge_T; -- -- The step edge identified by the given index, within the -- given graph. -- If the index is out of range, Constraint_Error is raised. function Edges_Into (Step : Step_T; Within : Graph_T) return Step_Edge_List_T; -- -- All the edges that enter the step (Edge.Target = Step). function Only_Edge_Into (Step : Step_T) return Step_Edge_T; -- -- The only edge that enters the step (Edge.Target = Step). -- If there are several entering edges, a Fault is emitted -- and the first such edge is returned (Constraint_Error -- if none). function Edges_From (Step : Step_T; Within : Graph_T) return Step_Edge_List_T; -- -- All the edges that leave the step (Edge.Source = Step). -- Loose edges are not included. function Only_Edge_From (Step : Step_T) return Step_Edge_T; -- -- The only edge that leaves the step (Edge.Source = Step). -- If there are several leaving edges, a Fault is emitted -- and the first such edge is returned (Constraint_Error -- if none). function Number_Into (Step : Step_T; Within : Graph_T) return Natural; -- -- The number of edges that enter the step. -- Same as Edges_Into()'Length. function Number_From (Step : Step_T; Within : Graph_T) return Natural; -- -- The number of edges that leave the step. -- Same as Edges_From()'Length. -- Loose edges are not counted. function Predecessors (Step : Step_T; Within : Graph_T) return Step_List_T; -- -- The immediate predecessors of the given step. -- The given step itself may be included, if there is a -- looping edge from this step to itself. function Feasible_Predecessors (Step : Step_T; Within : Graph_T) return Step_List_T; -- -- The immediate predecessors of the given step except those -- where the edge to the given step is marked infeasible by -- a precondition equal to Arithmetic.Never. -- Otherwise the same as Predecessors. function Successors (Step : Step_T; Within : Graph_T) return Step_List_T; -- -- The immediate successors of the given step. -- The given step itself may be included, if there is a -- looping edge from this step to itself. -- --- Nodes (basic blocks) -- type Node_T is private; -- -- A node (basic block) in a flow-graph. -- The attributes of a node include: -- -- > Its index number (1..). -- > Its identifying tag (Step_Tag_T). -- This is the same as the tag of the first step in the node. -- > The list of steps that it contains. -- > Whether some of the contains steps have unresolved -- dynamic data access or control flow. -- -- The edges connected to the node are not considered -- attributes of the node, but of the graph. No_Node : constant Node_T; -- -- Signifies the absence of a node. -- The default initial value of any Node_T object. function Index (Node : Node_T) return Node_Index_T; -- -- The index number of a node. -- These numbers run from 1 to Max_Node. function Tag (Node : Node_T) return Step_Tag_T; -- -- The identifying tag of a node. function Steps_In (Node : Node_T) return Step_List_T; -- -- The steps in the node, listed in order from the first step -- to the last step. The list contains at least one step. -- In the step-graph, these steps form a maximal linear -- chain in which each step is connected only to the next step, -- when the predecessors of the first step and the successors of -- the last step are not considered. function First_Step (Node : Node_T) return Step_T; -- -- The first step in the node. All edges leading to the -- node actually lead to this step, which is the sole entry -- point to the node. function Prime_Address (Node : Node_T) return Processor.Code_Address_T; -- -- The Prime_Address of the First_Step of the Node. function Node_Containing ( Step : Step_T; Graph : Graph_T) return Node_T; -- -- Given a step, return the node (basic block) that contains the step. -- If this function is called before basic-blocks have been -- collected, Constraint_Error results. function Node_At ( Index : Node_Index_T; Within : Graph_T) return Node_T; -- -- The node identified by the given index, within the -- given graph. -- If the index is out of range, Constraint_Error is raised. function Entry_Node (Graph : in Graph_T) return Node_T; -- -- The entry node (entry point) of the graph. -- This is necessarily the basic block that contains the -- graph's entry step (as its first step). type Node_List_T is array (Positive range <>) of Node_T; -- -- A set (or list) of nodes, for example, all successors -- of a given node. function All_Nodes (Within : Graph_T) return Node_List_T; -- -- All the nodes in the graph, listed so that the (Positive) index -- of a node in the list is the same as the (Node_Index_T) index of -- the node. function Nodes_Containing ( Steps : Step_List_T; Graph : Graph_T) return Node_List_T; -- -- For each step in Steps, the node that contains the Step. -- The result may contain duplicate nodes, if some of the Steps -- belong to the same node. function Return_Nodes (Within : Graph_T) return Node_List_T; -- -- All the return nodes. -- A return node is a node that has no successors. -- --- Node sets -- type Node_Set_T is array (Node_Index_T range <>) of Boolean; -- -- A set of flow-graph nodes, represented as a bit-map. pragma Pack(Node_Set_T); type Node_Set_Ref is access Node_Set_T; function Predefined_Equal (Left, Right : Node_Set_T) return Boolean renames "="; -- -- This is the predefined equality operation. See "=" below. function "=" (Left, Right : Node_Set_T) return Boolean; -- -- The predefined "=" has bugs for packed Boolean arrays in -- (some versions of?) Gnat 3.15p. It can return False although -- the arrays have identical components. Hypothesis: if the array -- does not entirely fill the last word, some garbage bits in the -- last word are compared, too. function No_Nodes (Within : Graph_T) return Node_Set_T; -- -- The empty set of nodes, however with the ability to hold -- any node in the given Graph. function No_Nodes (Within : Graph_T) return Node_Set_Ref; -- -- The empty set of nodes, however with the ability to hold -- any node in the given Graph. function "<=" (Left, Right : Node_Set_T) return Boolean; -- -- Whether Left is a subset of Right. function Cardinality (Set : Node_Set_T) return Node_Count_T; -- -- The number of nodes in the set. function To_List (Set : Node_Set_T; From : Graph_T) return Node_List_T; -- -- Lists all the nodes in the set (in index order). function To_Index_List (Set : Node_Set_T) return Node_Index_List_T; -- -- Lists the indices of all the nodes in the set (in index order). function To_Set ( Nodes : Node_Index_List_T; Last : Node_Index_T) return Node_Set_T; -- -- The set containing the given indices, as a subset of -- the index range 1 .. Last. -- A Constraint_Error will result if any given index -- exceeds Last. -- --- Node edges (edges between nodes) -- type Edge_T is private; -- -- An edge between nodes in a flow-graph. -- The attributes of an edge include: -- -- > Its index number (1..) -- > The source node from which the edge starts. -- > The target node at which the edge ends. -- > The corresponding step-edge. -- -- The following attributes are inherited from the corresponding -- step edge, and are always accessed from that object: -- -- > The logical precondition for taking the edge, a boolean -- expression evaluated after the execution of the source node. -- > The execution time of the edge. -- -- For repeated uses of volatile cells in the logical precondition, -- the same remarks apply as for the precondition of the underlying -- step edge. Null_Edge : constant Edge_T; -- -- Indicates the absence of an edge. function Index (Edge : in Edge_T) return Edge_Index_T; -- -- The index number of an edge. -- These numbers run from 1 to Max_Edge_Index. function Source (Edge : in Edge_T) return Node_T; function Target (Edge : in Edge_T) return Node_T; -- -- The source and target nodes of the edge. function Step_Edge (Edge : in Edge_T) return Step_Edge_T; -- -- The step-edge that corresponds to the given node-edge. -- This is the step-edge that goes from the last step in -- the source node to the first step in the target node. function Node_Edge (Edge : in Step_Edge_T; Graph : Graph_T) return Edge_T; -- -- The node-edge that corresponds to the given step-edge. -- This is the node-edge that goes from the source node -- to the target node. -- -- Null_Edge is returned if the step-edge is within a node. function Condition (Edge : in Edge_T) return Arithmetic.Condition_T; -- -- The boolean condition that is a necessary but not perhaps -- sufficient condition for the edge being executed. -- The value Arithmetic.Always indicates an unconditional -- edge. -- The value Arithmetic.Never indicates an infeasible (never -- taken) edge. -- -- An edge between nodes does not really have a precondition -- attribute, because the precondition of the corresponding -- step-edge is used. As for step-edges, the precondition is -- evaluated after the execution of the source node. When -- volatile cells are used in the precondition, the rules -- stated for the preconditions of Step_Edge_T apply. function Time (Along : Edge_T) return Processor.Time_T; -- -- The execution time of the edge. This is just the Time of -- the underlying Step_Edge. type Edge_List_T is array (Positive range <>) of Edge_T; -- -- A set (or list) of edges, for example, all edges that -- leave a given step. function No_Edges return Edge_List_T; -- -- An empty edge list. function Sources (Edges : in Edge_List_T) return Node_List_T; function Targets (Edges : in Edge_List_T) return Node_List_T; -- -- The source and target nodes of the given edges. function Step_Edges (Edges : in Edge_List_T) return Step_Edge_List_T; -- -- The step-edges that corresponds to the given node-edges. -- See the function Step_Edge, above. function Edge_At ( Index : Edge_Index_T; Within : Graph_T) return Edge_T; -- -- The edge identified by the given index, within the -- given graph. -- If the index is out of range, Constraint_Error is raised. function Edges_Into (Node : Node_T; Within : Graph_T) return Edge_List_T; -- -- All the edges that enter the node (Edge.Target = Node). function Edges_From (Node : Node_T; Within : Graph_T) return Edge_List_T; -- -- All the edges that leave the node (Edge.Source = Node). function Number_Into (Node : Node_T; Within : Graph_T) return Natural; -- -- The number of edges that enter the node. -- Same as Edges_Into()'Length. function Number_From (Node : Node_T; Within : Graph_T) return Natural; -- -- The number of edges that leave the node. -- Same as Edges_From()'Length. function Predecessors (Node : Node_T; Within : Graph_T) return Node_List_T; -- -- The immediate predecessors of the given node. -- Same as Sources(Edges_Into(Node,Within)). -- The given node itself may be included, if there is a -- looping edge from this node to itself. function Only_Predecessor (Node : Node_T; Within : Graph_T) return Flow.Node_T; -- -- The only immediate predecessor of the given Node, Within -- the given graph. If the Node has no predecessors or more -- than one predecessor, a Fault is emitted and the first -- predecessor is returned (Constraint_Error if none). function Successors (Node : Node_T; Within : Graph_T) return Node_List_T; -- -- The immediate successors of the given node. -- Same as Targets(Edges_From(Node,Within)). -- The given node itself may be included, if there is a -- looping edge from this node to itself. function Only_Successor (Node : Node_T; Within : Graph_T) return Flow.Node_T; -- -- The only immediate successor of the given Node, Within -- the given graph. If the Node has no successors or more -- than one successor, a Fault is emitted and the first -- successor is returned (Constraint_Error if none). function Return_Edges (Within : Graph_T) return Edge_List_T; -- -- All the edges that enter return nodes. -- A return node is a node that has no successors. -- If the graph has only one node (the entry node, which is -- also a return node in this case) the result is an -- empty edge list. -- -- This may seem a peculiar function (why not produce the -- return nodes instead of the edges?) but it is adapted to -- the needs of the HRT Execution Skeleton generation. function Edges ( From : Node_Set_T; Into : Node_Set_T; Not_From : Boolean := False; Not_Into : Boolean := False; Within : Graph_T) return Edge_List_T; -- -- The edges that go From a given node set Into another given -- node-set (which may be the same set). In other words, the -- edges Within the graph where the Source node is in From -- and the Target node is in Into. -- -- The Boolean parameters Not_From and Not_Into can be used -- to complement the From set membership and/or the Into set -- membership. For example, if Not_From => True and -- Not_Into => False, the function gives all the edges where -- the source node is not in From and the target edge is -- in Into. -- --- Loose edges between steps -- type Loose_Edge_T is record Source : Step_T; Cond : Arithmetic.Condition_T; Time : Processor.Time_T; Target : Step_Tag_T; Info : Processor.Loose_Edge_Info_T; end record; -- -- A new edge (state transition) discovered when incrementally -- exploring the control-flow of a subprogram. -- -- The Source step already exists within the flow-graph. -- The Target state (step tag) may or may not already -- exist in the graph. -- -- In addition to the standard edge attributes, processor-specific -- Info can be added. -- -- The precondition Cond represents the precondition of the -- edge that will leave the given Source step for the step that -- represents the Target state. For volatile cells used in Cond, -- the same rules apply as for the preconditions of Step_Edge_T -- objects. function Loose_Edges (Item : Graph_T) return Boolean; -- -- Whether the graph has some loose edges. function First_Loose_Edge (From : Graph_T) return Loose_Edge_T; -- -- Returns that loose edge E which has the smallest step-address -- as defined by Processor."<", and returns it in Giving. -- This loose edge remains in the graph's set of loose edges. -- Raises Constraint_Error if the graph has no loose edges. -- --- Boundable (dynamically computed) edges between steps -- type Boundable_Edge_T is abstract new Storage.Bounds.Boundable_T with private; -- -- A flow-state transition in which the target flow-state is computed -- dynamically during program execution. The transition is represented -- as a kind of "boundable" target object that computes the target -- flow-state(s) dynamically, using bounds on cell values on entry to -- the source step (values that flow into the source step, before -- they are updated by the possible arithmetic effect of the source -- step). -- -- The attributes of a boundable edge include: -- -- > The source step in the flow-graph. -- -- > Whether the edge represents a jump to another step in the same -- flow-graph, or a call to another subprogram (another flow-graph). -- A "jump" edge can also represent a return from the present -- subprogram (in which case no actual flow-graph edge results). -- -- > The state of resolution of the boundable edge. -- -- > The cells on which the dynamic target computation depends, -- inherited from Storage.Bounds.Boundable_T. -- -- > The number of actual edges that have been created from this -- boundable edge so far, and whether the edge has been resolved -- into a return from the present subprogram. -- -- > Information about the "domain" of the boundable edge, as it -- was when the boundable edge was last analysed to resolve it. -- The domain is the set of flow-graph steps from which flow can -- reach the boundable edge. Thus, the cell values that reach -- the boundable edge originate from these steps, or from the -- caller of the subprogram. We keep track of the domain so -- that we can avoid re-analysing the edge if its domain has -- not grown since the last analysis. The domain grows if the -- resolution of (this or other) boundable edges adds new paths -- to the steps in the domain. Only a full analysis (that is, -- all the way to arithmetic analysis if necessary) of the edge -- counts as the "last analysis" of the edge. A round of analysis -- that ends earlier, for example after constant propagation -- resolves some other boundable edge, does not count as the -- last analysis of an edge that is not yet resolved at this point. -- -- Of course, if the arithmetic effects of the steps in the domain -- are changed it can be useful to re-analyse the boundable edge -- even if no new steps have been added to the domain. -- -- > Specific attributes (in derived types) to control the resolution -- of the dynamic target and to detect when the result is stable. -- -- The operation that applies bounds to a boundable edge can extend -- the flow-graph by adding actual edges (typically only edges that -- have the same source step as the boundable edge) or steps (typically -- only steps that are targets of the added edges). When a boundable -- edge has been fully resolved in this way, the boundable edge -- itself is deleted from the graph. -- -- If a boundable edge is resolved into a return it cannot also be -- resolved into actual edges and vice versa. These are mutually -- exclusive resolutions of the boundable edge. -- -- The decision to remove the boundable edges from a graph depends -- on the state of resolution of _all_ boundable edges in the graph. -- This is the reason for recording the state in the boundable -- edge object. -- -- A boundable edge can also be resolved by assertions that list all -- the possible targets of the edge. The edge is then removed without -- waiting for the other boundable edges to be resolved. type Boundable_Edge_Role_T is ( Undefined, Boundable_Jump, Boundable_Call); -- -- The role of a boundable edge. -- -- Undefined -- The role is not yet known. The role is set when the -- edge is added to the flow-graph. -- Boundable_Jump -- The edge represents a jump to another step, or to some -- other steps, in the same flow-graph. The edge will be -- resolved to normal edges between normal steps in the same -- flow-graph, or into a return from this flow-graph. -- Boundable_Call -- The edge represents a call to another subprogram, or to -- some other subprograms. The edge will be resolved to -- normal edges from the source step to special "call steps" -- that represent the execution of the callee. type Edge_Resolution_T is ( Growing, Unresolved, Stable); -- -- The state of resolution of a boundable edge. -- -- Describes the result of trying to bound (resolve) a boundable edge -- by applying some cell-bounds to it. -- -- Unresolved -- One of the following: -- a) the boundable edge has just been added to the flow-graph -- and has not been analysed to resolve it, or -- b) the domain of the edge has grown since this edge was last -- analysed and so the edge must be re-analysed, or -- c) one or more analysis methods have been applied to the -- boundable edge (since the edge was created, or the -- flow-graph was last extended), but all failed to make -- the edge Growing or Stable. -- -- Growing -- Some analysis applied to this boundable edge has resolved some -- target addresses and added corresponding edges to the flow-graph, -- usually as loose edges. Some new steps may also have been added. -- This implies two things: firstly, the flow-graph decoding and -- tracing should be resumed and continued until all (new) loose -- edges have been processed; secondly, all boundable edges for -- which the domain of the edge has grown should be re-analysed to -- find more possible target addresses or to find that the set of -- targets is stable. -- -- Stable -- One of the following: -- (a) Some (re-) analysis applied to this boundable edge has -- found that the set of possible targets is the same as -- in the last analysis (even if the domain of the edge -- has grown). -- (b) The last analysis of this edge placed it in the Growing -- state, and the domain of this edge has not changed since -- that analysis. A new analysis would thus not give any -- new possible targets. -- Thus, the analysis of this edge seems to be complete (stable) -- and needs to be repeated only if its domain grows again. -- -- The meaning of the literals is further explained below in connection -- with the procedure Apply. -- -- The order of the literals is significant; the 'Min function is -- applied in some places (in child packages). -- -- The design of the boundable edges aims to the following overall -- iterative algorithm for building the flow-graphs of a subprogram -- when the entry address is known: -- -- Create -- the entry step, -- and perhaps other steps, -- and any edges between and from these steps, -- whether loose, real or boundable; -- -- Flow_Bounding : loop -- -- At this point the flow-graph may contain some loose -- -- edges and perhaps some boundable edges, too. -- -- Flow_Tracing: -- while there are some loose edges loop -- Decode the targets of the loose edges -- perhaps creating new steps -- and new loose, real or boundable edges; -- end loop Flow_Tracing; -- -- -- At this point the flow-graph has (or may have been) -- -- extended since the boundable edges were last analysed. -- -- If this extension has extended the domain of some -- -- boundable edge the edge should be re-analysed and -- -- so we mark such edges Unresolved again. -- -- Boundable edges that have an unchanged domain (since -- -- their last analysis) do not need re-analysed and their -- -- state is not changed. -- -- Find Unstable Dynamic Edges (this operation marks as Unresolved -- and "unstable" those boundable edges for which the domain has -- grown, and marks as Stable those Growing edges that have the -- same domain as in their last analysis); -- -- exit Flow_Bounding when all boundable edges are Stable; -- -- Analysis: -- for each analysis method (constant propagation, -- value-origin analysis, arithmetic analysis) -- loop -- -- for each unstable (and feasible) boundable edge -- loop -- if this analysis method is applicable to the edge -- then -- -- if this is the most powerful analysis we have -- (that is, arithmetic analysis) then -- Mark_Domain for the edge (this operation marks -- the edge as having been last analysed in its -- current domain); -- end if; -- -- Analyse the edge and -- if the analysis fails then -- Add nothing to the flow-graph; -- Leave the edge Unresolved; -- elsif the analysis seems stable then -- Add nothing to the flow-graph; -- Mark the edge Stable; -- else -- Add new targets to the flow-graph; -- Mark the edge Growing; -- end if; -- -- end if; -- end loop; -- -- Optionally exit from the Analysis loop if some boundable -- edge was marked Growing. This can avoid applying -- an expensive analysis (eg. arithmetic analysis) -- to a flow-graph that could be resolved with -- cheaper analyses. -- -- end loop Analysis; -- -- -- At this point: -- -- -- -- > If some boundable edge is marked Growing then the -- -- flow-graph was extended, compared to the last -- -- iteration of Flow_Bounding, so we should repeat -- -- loop Flow_Bounding to trace the new loose edges. -- -- If this increases the domain of some boundable edge -- -- then we should re-analyse that boundable edge. -- -- Furthermore, if some boundable edge is marked -- -- Unresolved then either this edge is a new one -- -- (added as a result of Growing some other boundable -- -- edge) or one of the two cases (A) or (B) below applies. -- -- -- -- > Otherwise (no Growing edges) the flow-graph is the -- -- same as at the Find_Unstable_Dynamic_Edges, above. Thus, -- -- a re-analysis of the edges is futile (it would give the -- -- same result). Furthermore, if some boundable edge is -- -- marked Unresolved (ie. not Stable) then either -- -- -- -- A) no (enabled) analysis was applicable and the -- -- edge remains unresolved, or -- -- -- -- B) all (enabled) analyses of this edge failed to -- -- resolve it (into a Stable state). -- -- -- -- The Unresolved edge may have been partially resolved, -- -- that is, some possible targets may have been found -- -- in earlier iterations of Flow_Bounding. -- -- exit Flow_Bounding when no boundable edge is Growing; -- -- end loop Flow_Bounding; -- -- At this point all feasible boundable edges are either Stable -- or Unresolved (unless Flow_Bounding was aborted by a limit -- on the number of iterations). -- -- Report error (unresolved dynamic flow) for the boundable -- edges that are Unresolved; -- -- Close and remove all boundable edges, in whatever state. function Source (Edge : Boundable_Edge_T'Class) return Step_T; -- -- The source step of the boundable edge. -- All static edges resolved from this boundable edge will have -- this step as the source. function Role (Edge : Boundable_Edge_T'Class) return Boundable_Edge_Role_T; -- -- The role of the boundable edge. function State (Edge : Boundable_Edge_T'Class) return Edge_Resolution_T; -- -- The current state of resolution of the boundable edge. When -- a boundable edge is created, the state is initially Unresolved. -- As bounds are applied to the edge, the state changes. function Full_Image (Item : Boundable_Edge_T'Class) return String; -- -- All we know of the boundable edge. procedure Add_Resolvent (To : in out Boundable_Edge_T'Class); -- -- Adds one To the count one resolved edges and marks the state -- as Growing. Notes that the edge is no longer "unstable". -- -- A fault is reported if the edge has already been resolved -- into a return. procedure Resolve_To_Return ( From : in Graph_T; Edge : in out Boundable_Edge_T'Class); -- -- Declares that the Edge has been resolved into a return from -- the subprogram (the Graph) that contains the source step, and -- marks the state as Stable. Notes that the Edge is no longer -- "unstable". -- -- If this is the first call of this operation on this Edge, the -- operation declares the source step of the Edge as a return -- step by means of Flow.Calls.Return_After. -- -- A fault is reported if the Edge has already been resolved -- into some actual edges. function Resolvents (Edge : Boundable_Edge_T'Class) return Natural; -- -- The number of actual edges that have been resolved from the -- given boundable Edge, so far. Initially zero. function Returns (Edge : Boundable_Edge_T'Class) return Boolean; -- -- Whether the given boundable Edge has been resolved to a return -- from the subprogram that contains the source step. procedure Find_Unstable_Dynamic_Edges (Within : in Graph_T); -- -- Evaluates the domains of all dynamic edges Within the graph -- with respect to the growth of the graph, since the last round -- of analysis and resolution of dynamic edges (that is, since the -- last call of this procedure). In particular, detects whether -- the new part of the graph "rejoins" the old part of the graph -- in a way that brings new (data) flow to the dynamic edges that -- were analysed in the last round. -- -- Sets the resolution state of all boundable edges Within the -- given flow-graph as follows: -- -- > If the domain of the edge, Within the current graph, has -- grown since the edge was last analysed, the edge is -- marked Unresolved (and the edge will be reanalysed unless -- it is classed as infeasible). -- -- > If the domain of a Growing edge has not grown since the -- edge was last analysed the edge is marked Stable (and -- the edge will not be reanalysed in the next round). -- -- > Marks as "unstable" all edges for which the domain has -- grown since their last analysis, and all other edges -- as "not unstable" (even if the state is Unresolved). -- -- Also begins collecting information about edges added to the -- graph from this point on; this information is used in the next -- invocation to check if the domains have grown. This operation -- shall be called when the tracing of the graph is complete except -- for the remaining boundable edges, immediately before the analysis -- to resolve these edges and possible further tracing of the graph. procedure Mark_Domain (Edge : in out Boundable_Edge_T'Class); -- -- Notes that the Edge was last fully analysed (or is about to -- be analysed) in its current domain. Thus, the domain of the -- Edge is now considered "not grown since the last analysis". -- -- This operation *shall* be executed immediately before, during -- or after the full analysis and resolution of the Edge, and -- only then. By "full analysis" we mean the most powerful form -- of analysis in our repertoire (arithmetic analysis). procedure Mark_Stable (Edge : in out Boundable_Edge_T'Class); -- -- Sets the resolution state of the Edge to Stable, and notes -- that the edge is no longer "unstable". -- not overriding procedure Apply ( Bounds : in Storage.Bounds.Bounds_T'Class; Upon : in out Boundable_Edge_T; Graph : in Graph_T) is abstract; -- -- Applies the Bounds Upon a boundable edge, hopefully resolving the -- dynamic target computation into actual (static) edges for the Graph. -- To add such edges to the Graph the Apply operation should use the -- dedicated operation Add_Resolved_Edge, declared later in this -- package (in two variants). -- -- The Bounds constrain the values of the relevant cells on entry to -- the step Source (Upon), before these cells are updated by the -- possible arithmetic effect of this step. If the target address(es) -- in fact depend on the updated values, the operation must itself -- take the updates into account in some way. -- -- This operation probably changes the state of resolution of the -- boundable edge, either indirectly by Add_Resolved_Edge or directly -- by the operation Mark_Stable. When Apply is called the initial -- state of the edge is always Unresolved. -- -- The resulting state of the boundable edge describes the success or -- failure of this application. The meaning of the three possible -- states is as follows: -- -- Growing -- The Bounds were strong enough to let us deduce one or more real -- target addresses and add the corresponding (static) edges to -- the Graph (usually as loose edges). It is also possible that -- one or more steps were added to the Graph, although new target -- steps are usually added in the Decoder as a result of following -- the new loose edges. These new edges may not have exhausted the -- possible targets of the boundable edge. It may be that the new -- parts of the Graph lead back to this boundable edge with more -- data states that generate more possible target addresses. -- Unresolved -- The Bounds were not strong enough to allow any resolution of -- the boundable edge; no real edges or other elements were added -- to the Graph. If sharper bounds cannot be found, the boundable -- edge cannot be resolved (failure). -- Stable -- The Bounds were strong enough to be used, but did not allow -- any new real target addresses for the boundable edge, so it -- seems that the edge has been fully resolved (stable state). -- -- If the state is Growing, the tracing of the flow in Graph should -- be resumed (continued) by following all new loose edges until there -- are no more loose edges. Then, new Bounds should be computed using -- the extended Graph and should again be Applied Upon this boundable -- edge, to check if new real target addresses are possible in the -- extended Graph. -- -- If the state is Stable, and all other boundable edges in the -- Graph are also Stable (or Unresolved even with the sharpest bounds -- we can apply), then it seems that the Graph is complete (or as -- complete as we can make it) and all boundable edges can be removed -- (but this is not done here, of course, since the state of all -- boundable edges must be known). -- -- To decide when the edge should be marked Stable, and to avoid -- adding duplicate edges to the Graph, the boundable edge object must -- probably keep a record of the real edges that is has given rise to, -- or of the corresponding edge preconditions or cell values. -- -- If the state is Unresolved, and sharper Bounds cannot be found, -- and all other boundable edges in the Graph are Stable or Unresolved, -- the Graph is as complete as we can make it and all boundable edges -- can be removed as above. -- -- The conceptual algorithm for this operation should thus be: -- -- if the Bounds are strong enough then -- if the Bounds allow new edges to be derived from Upon then -- call Add_Resolved_Edge to create the new edges -- else -- call Mark_Stable -- end if -- end if -- -- The hardest decision in this operation is probably whether the -- Bounds are strong enough to give confidence in the real edges -- deduced from the Bounds. For example, if the boundable edge stands -- for a switch/case statement and the Bounds allow 500 branches, -- is this likely to be correct or are the Bounds overestimated? -- If we accept too wide Bounds, we may force the analysis to explore -- hundreds of false paths. If we reject Bounds mistakenly, the -- analysis may miss important paths. -- -- Note that even if Apply marks the boundable edge as Stable, the -- edge can still be subjected to more Apply operations with new -- Bounds if some _other_ boundable edge in this Graph is resolved -- and thus extends the Graph. The new Bounds may let the new call -- of Apply further resolve the boundable edge that appeared Stable -- with the earlier Bounds, based on the incomplete Graph. -- -- This operation does _not_ override Storage.Bounds.Apply, because -- of the different parameter profile. -- -- Note that you shall perform Mark_Domain Upon the edge, usually -- immediately before Apply. -- not overriding procedure Apply ( Transfer : in Arithmetic.Transfer_Function_T'Class; Upon : in out Boundable_Edge_T; Graph : in Graph_T); -- -- Applies the Transfer function Upon a boundable edge, hopefully -- resolving the dynamic target computation into actual (static) -- edges for the Graph or (and more likely) into a return from the -- Graph, asssuming that the Transfer function models the computation -- from the entry point of the Graph up to but not including the -- Source (Upon). Note that the effect of Source (Upon) itself is not -- included in Transfer. -- -- To add such edges to the Graph the Apply operation should use the -- dedicated operation Add_Resolved_Edge, declared later in this -- package (in two variants). If the edge is resolved into a return, -- the Apply operation should use operation Resolve_To_Return. -- -- The Transfer constrains the values of the relevant cells on entry -- to the step Source (Upon), before these cells are updated by the -- possible arithmetic effect of this step. -- -- This operation probably changes the state of resolution of the -- boundable edge, either indirectly by Add_Resolved_Edge or -- Resolve_To_Return or directly by the operation Mark_Stable. -- When Apply is called the initial state of the edge is always -- Unresolved. -- -- The resulting state of the boundable edge describes the success or -- failure of this application as for Apply (Bounds), above. -- -- This operation does _not_ override Storage.Bounds.Apply, because -- of the different parameter profile. -- -- The default implementation does nothing (no resolution). -- This is a temporary solution for upwards compatibility; this -- operation will be made abstract later. -- -- Note that you shall perform Mark_Domain Upon the edge, usually -- immediately before Apply. type Target_List_T is array (Positive range <>) of Processor.Code_Address_T; -- -- A list of asserted target for a boundable edge. -- not overriding procedure Take_Asserted_Targets ( Edge : in out Boundable_Edge_T; Targets : in Target_List_T; Graph : in Graph_T); -- -- Resolves the Edge to have the asserted list of Targets. -- The Edge will then be Closed and removed from the Graph, -- but this should not be done in this operation (see -- Remove_Dynamic_Edge, below). -- -- The default implementation calls the primitive operation -- Take_Asserted_Target (see below) for each of the Targets, -- redispatching on the Edge. -- not overriding procedure Take_Asserted_Target ( Edge : in out Boundable_Edge_T; Target : in Processor.Code_Address_T; Graph : in Graph_T); -- -- Resolves the Edge to have the asserted Target as one possible -- target address. However, there may be more asserted targets. -- -- The default implementation reports a "not implemented" Fault. -- This is a temporary solution for upwards compatibility; this -- operation will be made abstract later. -- not overriding procedure Close ( Edge : in out Boundable_Edge_T; Graph : in Graph_T); -- -- Closes the Edge when all boundable edges in the Graph are stable -- or cannot be resolved further. This operation is called once, just -- before the Edge is removed from the Graph. This operation shall not -- add any steps or edges to the Graph. -- -- The default implementation reports the number of Resolvents as -- a Note. If flow-resolution is being traced (option), the same is -- also reported as a Trace line. type Dynamic_Edge_T is access all Boundable_Edge_T'Class; -- -- A dynamic edge, as a part of a flow-graph, is a reference to -- a boundable edge object of some derived type. The derived types -- are processor-specific and represent the various kinds of -- dynamically computed jumps or other transfers of control in -- the target architecture. type Dynamic_Edge_List_T is array (Positive range <>) of Dynamic_Edge_T; -- -- A list or set of dynamic edges. function Dynamic_Edges_From ( Source : Step_T; Within : Graph_T) return Dynamic_Edge_List_T; -- -- All the (unresolved) dynamic edges leaving the Source step. -- The list is non-empty iff Unresolved_Successors (Source) is True. function Dynamic_Edges (Item : Graph_T) return Dynamic_Edge_List_T; -- -- All the dynamic edges in the given graph. function Sources (Edges : in Dynamic_Edge_List_T) return Step_List_T; -- -- The source steps of the given dynamic edges. -- The result has the same 'Range as the input, so -- result(I) = Source (Edges(I)). procedure Add_Basis_Cells ( From : in Dynamic_Edge_List_T; To : in out Storage.Cell_Set_T); -- -- Adds the basis cells From each listed dynamic edge, To a -- given set of cells. -- --- Step_Data_T primitive operations -- -- -- Three groups of operations are defined: -- -- > Low-level operations that work on small pieces, eg. -- an Effect, an Expression, but which must be combined to -- implement the computations that we need. -- -- > High-level operations that do in one call exactly what -- various flow-graph construction operations need to do -- with Step_Data_T. -- -- > Abstract operations. -- -- The default implementations for some low-level operations are -- dummy, null operations; the rest delegate the operation to -- anothe low-level operation which makes sense only if the latter -- operation is overridden with a non-null operation. The dummy -- operations issue Fault messages if called. -- -- The default implementations for the high-level operations use -- the low-level operations to compute the results. However, a -- particular, concrete type derived from Step_Data_T may be able -- to make use of the additional information available in the -- high-level operations to produce a better result than can be -- achieved only by combining the low-level operations. -- -- The idea is that a derived type can override operations on -- either the low or the high level, but usually not on both -- levels, although it is certainly permissible to do so. -- -- Among all the operations in this Flow package, only the default -- implementations of the high-level Step_Data_T operations ever -- call the low-level Step_Data_T operations. Thus, if a derived -- type overrides the high-level operations without using the -- low-level operations, the derived type need not override the -- default implementations of the low-level operations. -- -- Any concrete derived type must of course implement the abstract -- operations. If the implementations use some dummy, null low-level -- operations then the latter must also be overridden. -- First, the low-level operations: function Refined_Effect ( From : Arithmetic.Effect_Ref; On : access Step_Data_T) return Arithmetic.Effect_Ref; -- -- Derives a refined, residual effect From the given effect when -- applied On a given data state. That is, this function partially -- evaluates the given effect On constrained input data. -- -- If some (useful) partial evaluation is possible, a new, refined -- effect is returned. Otherwise, the original Effect is returned. -- -- The given effect, From.all, shall not be changed. Any refinement -- in any part of the effect shall lead to a new (heap-allocated) -- Effect_T. However, the new Effect_T may reuse (refer to) those -- parts of From.all that were not refined. -- -- If the function finds a contradiction between the data state -- and some range-pre assignments in the effect the function -- shall raise False_Path. -- -- The default implementation emits a Fault message, returns the -- given effect, From, and does not propagate False_Path. function Refined_Effect ( From : Arithmetic.Effect_T; On : access Step_Data_T) return Arithmetic.Effect_Ref; -- -- Just like the Effect above (with From an Effect_Ref), but -- by taking an Effect_T instead this function can avoid to -- allocate and discard heap space for the non-refined effect. -- -- The default implementation makes a heap copy of the given -- effect, From, and passes it to the Effect function above, -- with redispatching On the data state. function Refined_Condition ( From : Arithmetic.Condition_T; On : access Step_Data_T) return Arithmetic.Condition_T; -- -- Derives a refined, residual condition From the given condition -- when applied On a given data state. That is, this function -- partially evaluates the given condition On constrained input data. -- -- If some (useful) partial evaluation is possible, a new, refined -- condition is returned. Otherwise, the original From condition -- shall be returned. -- -- If the function finds that the From condition is always false -- On the given data, it shall return Arithmetic.Never. -- -- The default implementation emits a Fault message and returns -- the given condition, From. function Transformed_Data ( From : access Step_Data_T; After : Arithmetic.Effect_T) return Step_Data_Ref; -- -- The new data state that results From a given data state, After -- an effect is applied to it. The original data state shall not -- be modified; however, if the effect causes no change in the data -- state, the function can return a new reference to the original -- data state (which is why the data state is of access mode). -- -- The function can assume that the given After effect is the -- result of the Refined_Effect function on the From state, so it -- is already partially evaluated on that state. Moreover, the -- function can assume that After'Length > 0, as the data-state -- cannot be changed by a null effect. -- -- If the function finds a contradiction between the data state and -- the effect, for example a range-pre assignment that is false in -- this data, the function shall raise False_Path. However, this -- contradiction should have been discovered earlier when the -- effect was refined From this data state. -- -- Note that an effect can *reduce* the information about data -- state, thus the result may place looser bounds or even no -- bounds on the data state. For example, the From state may imply -- that the cell C has the value 5, but After may assign an Unknown -- value to cell C so that the resulting data state has no -- information on C. -- -- The default implementation emits a Fault message, returns a -- reference to the given data state, From, and never propagates -- False_Path. function Constrained_Data ( From : access Step_Data_T; By : Arithmetic.Condition_T) return Step_Data_Ref; -- -- The constrained data state that result From a given data state -- By assuming that a given constraint condition holds. The original -- data state shall not be modified; however, if the constraint has -- no effect on the data state, the function can return a new reference -- to the original data state (which is why the data state is of -- access mode). -- -- The function can assume that the given constraint condition -- is the result of the Refined_Condition function On this data state, -- so it is already partially evaluated on this data state. Moreover, -- the function can assume that the condition is non-trivial, that is -- neither of the constants Never or Always. -- -- If the function finds that the constraint is always false for -- the given data state it shall raise False_Path. -- -- The default implementation emits a Fault message, returns the -- given data state, From, and never propagates False_Path. -- Then the high-level operations: procedure Transform_New_Step ( Data : access Step_Data_T; Step : in Step_T; Effect : in out Arithmetic.Effect_Ref; Post : out Step_Data_Ref); -- -- This operation is used when a new Step is added to the flow-graph -- with a Tag that defines some input Data state that flows into -- the new Step, and using the Add_Step operation that takes an -- Effect_Ref parameter. -- -- Precondition: Data = Data (Step) /= Any_Data. The Data parameter -- is needed only as a controlling parameter for dispatching. It -- is unspecified whether or not an effect (or the Effect) has been -- assigned to the Step. -- -- The procedure should refine the Effect, using the Data, and apply -- it to the input Data, giving the Post data state after the Step -- (which shall not be Any_Data). The refined Effect shall be returned. -- -- If the procedure finds a contradiction between the Data and the -- Effect it shall raise False_Path. -- -- The default implementation uses the low-level functions -- Refined_Effect (From : Effect_T) and Transformed_Data, -- redispatching on the Data. These low-level operations may -- propagate False_Path if their default implementations are -- overridden. procedure Transform_New_Step ( Data : access Step_Data_T; Step : in Step_T; Effect : in Arithmetic.Effect_T; Refined : out Arithmetic.Effect_Ref; Post : out Step_Data_Ref); -- -- This operation is used when a new Step is added to the flow-graph -- with a Tag that defines some input Data state that flows into -- the new Step, and using the Add_Step operation that takes an -- Effect_T parameter. -- -- Precondition: Data = Data (Step) /= Any_Data. The Data parameter -- is needed only as a controlling parameter for dispatching. Also, -- no effect is yet assigned to the Step. -- -- The procedure should refine the Effect, using the Data, return -- the possibly Refined effect, and apply the Refined effect to -- the input Data, giving the Post data state after the Step (which -- shall not be Any_Data). -- -- If the procedure finds a contradiction between the Data and the -- Effect it shall raise False_Path. -- -- The somewhat baroque profile at Effect and Refined is meant to -- avoid making a heap copy of the unrefined Effect_T. -- -- The default implementation uses the low-level functions -- Transformed_Effect (From : Effect_Ref) and Transformed_Data, -- redispatching on the Data. These low-level operations may -- propagate False_Path if their default implementations are -- overridden. procedure Refine_New_Edge ( Post : access Step_Data_T; Source : in Step_T; Target : in Step_Tag_T; Cond : in out Arithmetic.Condition_T; Giving : out Step_Data_Ref); -- -- This operation is used when a new step Edge is added to the -- flow-graph with a Source step and Target tag that indicate a -- refinement of the edge Condition and Target data state is -- possible and needed. -- -- Preconditions: -- Data (Source) /= Any_Data. -- Target.Data /= Any_Data. -- Post = Source.Post /= Any_Data. -- Cond /= Always. -- -- The Post parameter is the data state on leaving the Source -- step (including the assignments in the effect of the Source). -- It is equal to Source.Post, so redundant, but is used as a -- controlling operand for dispatching. -- -- The precondition Cond /= Always comes from the fact that if -- Cond = Always then it cannot be refined by the Post data -- and it cannot constrain the Post data for Giving, so we -- can only use Cond as such and assign Giving := Post, which -- is handled in the Add_Edge operation itself. -- -- The procedure shall apply the Post data to refine the Cond -- to be assigned to the new edge, and then apply the refined Cond -- to the Post state, Giving the constrained data state for the -- actual (refined) target tag of the new edge. -- -- The refined edge condition shall be returned in Cond. If the -- procedure finds that the condition is always False in the -- Post data state, it shall return Cond as Arithmetic.Never. -- -- The default implementation uses the low-level functions -- Refined_Condition and Transformed_Data, redispatching on the -- data state (Post). If the Refined_Condition function returns -- Arithmetic.Never, the Transformed_Data function is not called -- and the given Post data state is returned in Giving. -- Finally the abstract operations: function Image (Item : Step_Data_T) return String is abstract; -- -- A description of the data state for human understanding. -- The presentation depends on the derived type. function Image_All (Item : Step_Data_Ref) return String; -- -- Image (Item.all), or "not constrained" if Item is null. procedure Apply ( Pre : access Step_Data_T; Post : access Step_Data_T; Upon : in out Boundable_Edge_T'Class; Graph : in Graph_T) is abstract; -- -- This operation is used when a new boundable edge is added to -- the flow-graph with a Source step that has a tag that defines -- some input Pre data state /= Any_Data. The Post parameter is the -- data state after transforming Pre by the effect of the Source -- step. -- The procedure shall apply the Pre and/or the Post states Upon -- the new boundable edge, hopefully resolving the dynamic target -- computation into actual (static) edges for the Graph. -- -- We provide both the Pre and Post states for convenience. The -- Apply operation for Storage.Bounds.Bounds_T upon Boundable_Edge_T -- needs the bounds from the Pre state, but jump instructions often -- depend on the Post state. -- -- Note that the Pre and Post parameters are both controlling and -- must therefore have the same tag (in the Ada sense). -- -- This operation probably changes the state of resolution of the -- boundable edge, indirectly by Add_Resolved_Edge and/or directly -- by the operation Mark_Stable. When Apply is called the initial -- state of the edge is always Unresolved. -- -- The resulting state of the boundable edge describes the success or -- failure of this application. The meaning of the three possible -- states is as follows: -- -- Growing -- Should never occur and will cause a Fault report. -- Unresolved -- The Data bounds were not strong enough to allow any resolution of -- the boundable edge; no real edges or other elements were added -- to the Graph. If sharper bounds cannot be found, the boundable -- edge cannot be resolved (failure). -- Stable -- The Data were strong enough to resolve all the real target -- addresses for the boundable edge. Since the Data state is -- a superstate for any execution of this step, the edge is -- now fully resolved (stable state). -- -- The ideal outcome of Apply is one or more calls of Add_Resolved_Edge -- followed by one call of Mark_Stable. procedure Apply ( Data : access Step_Data_T; Upon : in Calling.Protocol_T'Class; Giving : out Calling.Protocol_Ref) is abstract; -- -- Applies the Data state Upon a boundable calling protocol, perhaps -- Giving a more constrained / better defined protocol. The procedure -- shall return Giving as null if it cannot constrain the given -- protocol (Upon) by means of the Data bounds. -- --- Step and graph construction -- procedure Add_Step ( To : in Graph_T; Tag : in Step_Tag_T; Effect : in Arithmetic.Effect_T; Info : in Processor.Step_Info_T; Giving : out Step_T); -- -- Adds a step with the given tag and other attributes -- to the graph. No edges to or from the step are yet added, -- except if there already are loose edges to this Tag, -- in which case these loose edges are converted to bound -- edges (and Edge_Duplicated may be raised, if more than -- one edge would be added between the same two nodes). -- -- If Tag.Data is not Any_Data, the operation calls the primitive -- Step_Data_T operation Transform_New_Step to refine the given -- Effect by partial evaluation on Tag.Data and then assigns the -- refined effect to the new step. This may propagate False_Path -- if there is a contradiction between Tag.Data and range-pre -- assignments in the Effect. -- -- The added step is also returned in Giving, besides being -- added to the graph. -- -- If the graph was originally null (empty), the new -- step becomes its entry step. -- -- If a step with this given address already existed in the -- graph, then Step_Tag_In_Use is raised. procedure Add_Step ( To : in Graph_T; Tag : in Step_Tag_T; Effect : in Arithmetic.Effect_Ref; Info : in Processor.Step_Info_T; Giving : out Step_T); -- -- Same as above, but with a reference to the effect, allowing -- sharing of effects across multiple copies of the same -- instruction (unless they are refined by Tag.Data). procedure Add_Edge ( To : in Graph_T; Source : in Step_T; Cond : in Arithmetic.Condition_T := Arithmetic.Always; Time : in Processor.Time_T; Target : in Step_T; Giving : out Step_Edge_T); -- -- Adds an edge from the Source step to the Target step in the graph. -- Both steps must already exist in the graph. -- -- If the Cond parameter is given, it represents a necessary but -- perhaps not sufficient condition for the edge being executed. -- The Cond is evaluated after the effect of the Source step. -- -- If the Cond refers to a volatile cell, every use of the cell in -- Cond is assumed to provide the same value; if the Source step -- assigns to the cell, the assigned value is provided (that is, -- the cell is not volatile between the effect of the Source step -- and the evalution of the Cond). -- -- The default Cond value (Always) implies an unconditional edge. -- The Cond should not be Arithmetic.Never; a Fault is emitted -- in that case (but the edge is still created). -- -- This operation uses the given Cond as such with no data- -- dependent refinment. It is the caller's responsibility to -- provide a good Cond, possibly depending on Tag (Source).Data -- and Tag (Target).Data. procedure Add_Edge ( To : in Graph_T; Source : in Step_T; Cond : in Arithmetic.Condition_T := Arithmetic.Always; Time : in Processor.Time_T; Target : in Step_T); -- -- Exactly the same as Add_Edge above, but does not give a handle -- to the new edge -- quite often this handle is not needed -- -- and therefore silently omits to create an edge if the -- Condition is Arithmetic.Never. procedure Add_Edge ( To : in Graph_T; Source : in Step_T; Cond : in Arithmetic.Condition_T := Arithmetic.Always; Time : in Processor.Time_T; Target : in Step_Tag_T; Info : in Processor.Loose_Edge_Info_T := Processor.No_Loose_Edge_Info); -- -- Adds an edge from the Source step to the Target state (tag) -- in the graph, possibly after transforming the data state of -- the Target tag. -- -- The Source step must already exist in the graph. -- -- If the Cond parameter is given, it represents a necessary but -- perhaps not sufficient condition for the edge being executed. -- The Cond is evaluated after the effect of the Source step. -- If the Cond uses volatile cells, the same rules apply as for -- the Cond parameter for an edge to an existing Target step. -- -- The default Cond value (Always) implies an unconditional edge. -- -- The Data components of the Source and Target define several -- cases as follows: -- -- 1. Tag (Source).Data = Any_Data and Target.Data = Any_Data -- -- This means normal decoding and flow-graph construction with -- no Data simulation. The Target and Cond are used as such -- with no refinement or transformation (because there is no -- data that could be used for refining or transforming). -- -- 2. Tag (Source).Data = Any_Data and Target.Data /= Any_Data -- -- This means the start of a data-dependent simulation. In -- this case, it is the caller's responsibility to include -- Effect (Source) in Target.Data and to give a useful Cond, -- perhaps refined by Target.Data. This operation uses the -- given Target and Cond with no refinement or transformation. -- -- 3. Tag (Source).Data /= Any_Data and Target.Data = Any_Data. -- -- This means that the data-dependent simulation stops and we -- return to normal decoding and flow construction. The Target -- and Cond are used as such with no refinement or transformation. -- -- 4. Tag (Source).Data /= Any_Data and Target.Data /= Any.Data. -- -- An edge of this kind means a transition in data-dependent -- flow-graph construction. There are two subcases: -- -- 4a. Target.Data /= In_Transit. -- -- An edge of this kind means a transition in data-dependent -- flow-graph construction where the caller has already computed -- the new data-state for the target. Accordingly, this operation -- uses the Target and Cond as such, with no refinement or -- transformation. -- -- 4b. Target.Data = In_Transit -- -- This means that the caller does not know about data simulation -- and has just used the Transit function to compute the Target. -- Accordingly, this operation will define the target data state -- and will refine the Cond by the data state; to do so, it calls -- the primitive Step_Data_T operation Refine_New_Edge. -- -- If the (refined) Cond is Arithmetic.Never, an edge is not -- created. Otherwise: -- -- > If a step with the target tag already exists in the graph, -- a real (bound) edge is added. In this case, the Info is not -- used (discarded). -- -- > If a step with the new target tag does not already exist in -- the graph, a loose edge is added and records the Info. procedure Add_Edge ( To : in Graph_T; Source : in Step_T; Cond : in Arithmetic.Condition_T := Arithmetic.Always; Time : in Processor.Time_T; Target : in Processor.Flow_State_T; Info : in Processor.Loose_Edge_Info_T := Processor.No_Loose_Edge_Info); -- -- Equivalent to -- Add_Edge (.. Target => Transit (From => Source, To => Target)..). type Warning_Opt_T is ( Never_Warn, Warn_If_Unresolved_By_Data, Always_Warn); -- -- Defines when warnings are issued from Add_Dynamic_Edge, below. -- -- Never_Warn -- A warning is never issued. A dynamic edge is silently added. -- Warn_If_Unresolved_By_Data -- A warning is not issued if the new dynamic edge is immediately -- resolved to a static edge by applying the data-state of the -- source step. -- Always_Warn -- A warning is always issued. -- -- Note that there may also be command-line options that interact -- with these choices and may, for example, suppress warnings even -- when Always_Warn is chosen. procedure Add_Dynamic_Edge ( To : in Graph_T; Source : in Step_T; Edge : in Dynamic_Edge_T; Warn : in Warning_Opt_T := Always_Warn); -- -- Adds a dynamic Edge from the Source step to a dynamically computed -- (set of) target addresses. The state of the Edge is initialized -- to Unresolved and its domain is considered to have grown. If the -- role of the Edge is Undefined, the role is set to Boundable_Jump. -- -- If Tag (Source).Data is not Any_Data, the operation tries to -- resolve the new Edge by applying Tag (Source).Data. If this is -- successful, the Edge is closed and deleted. -- -- The Warn parameter controls when a warning is issued. However, -- the Warn_Flow option must also be enabled for any warnings to -- result. procedure Add_Resolved_Edge ( To : in Graph_T; Source : in out Boundable_Edge_T'Class; Cond : in Arithmetic.Condition_T := Arithmetic.Always; Time : in Processor.Time_T; Target : in Step_Tag_T; Info : in Processor.Loose_Edge_Info_T := Processor.No_Loose_Edge_Info); -- -- Adds a real edge, which is resolved from a dynamic Source edge -- and thus has the same source step, to a Target state (dynamically -- computed from the Source) and with given precondition and -- execution time. -- -- The new edge is added using Add_Edge (Target : Step_Tag_T) and -- so it can be either a bound edge or a loose edge and the process -- can involve Data state transformations and can refine the Cond -- based on the Data states. See that Add_Edge for details. -- -- Sets the state of the boundable Source edge to Growing to -- show that the flow-graph is growing. Increments the number of -- Resolvents of the Source. Notes that the Source is no longer -- "unstable". procedure Add_Resolved_Edge ( To : in Graph_T; Source : in out Boundable_Edge_T'Class; Cond : in Arithmetic.Condition_T := Arithmetic.Always; Time : in Processor.Time_T; Target : in Step_T); -- -- Adds a real edge, which is resolved from a dynamic Source edge -- and thus has the same source step, to an existing Target step -- (with a tag dynamically computed from the Source) and with -- given precondition and execution time. -- -- The new edge is added using Add_Edge (Target : Step_T) and -- so the Cond may be refined based on Tag (Target).Data. See -- that Add_Edge for details. -- -- Sets the state of the boundable Source edge to Growing to -- show that the flow-graph is growing. Increments the number of -- Resolvents of the Source. Notes that the Source is no longer -- "unstable". procedure Add_Resolved_Dynamic_Edge ( To : in Graph_T; Source : in out Boundable_Edge_T'Class; Edge : in Dynamic_Edge_T; Warn : in Warning_Opt_T := Always_Warn); -- -- Adds a new dynamic Edge, which is resolved from a dynamic Source -- edge and thus has the same source step, but still needs some -- dynamic computation to resolve the (set of) target addresses. -- -- The new dynamic Edge is added using Add_Dynamic_Edge and so it -- may be resolved immediately by Tag (Source (Source)).Data; see -- Add_Dynamic_Edge for details. -- -- The Warn parameter is passed on to Add_Dynamic_Edge where it -- controls the possible warning for dynamic flow. -- -- Sets the state of the boundable Source edge to Growing to -- show that the flow-graph is growing. Increments the number of -- Resolvents of the Source. Notes that the Source is no longer -- "unstable". procedure Reject_Resolved_Edge ( Source : in Boundable_Edge_T'Class; Expr : in Arithmetic.Expr_Ref; Value : in Arithmetic.Word_T; Reason : in String); -- -- Reports that the Source has rejected a putative edge that would -- correspond to the given Value, analysed as a possible value of -- the dynamic Expression of the Source, for the given Reason. -- The Reason can be, for example, that the address computed from -- the Value is not a valid code address (misaliged, out of range). procedure Remove_Dynamic_Edge ( Edge : in out Dynamic_Edge_T; From : in Graph_T); -- -- Deletes the given dynamic Edge From the graph. This means that -- the dynamic control flow at _this_ Edge is considered fully -- resolved, or at least as fully resolved as possible. This -- happens mainly when the posible targets of the Edge have been -- asserted (see Take_Asserted_Targets). -- -- Thus procedure applies to the Close operation to the Edge, -- after the Edge is deleted from the graph, but does not otherwise -- touch nor discard the underlying boundable-edge object. procedure Remove_All_Dynamic_Edges (From : in Graph_T); -- -- Deletes all the dynamic edges From the graph. This means that -- the dynamic control flow is considered fully resolved or at least -- as fully resolved as possible. -- -- The state of all dynamic edges must be Unresolved or Stable, else -- a fault message results. -- -- This procedure applies the Close operation to each remaining -- dynamic edge in the graph, but does not otherwise touch -- nor discard the underlying boundable-edge objects. procedure Collect_Blocks (Graph : in Graph_T); -- -- Creates the basic blocks from the steps of the graph. -- Should be called once, after the graph has been constructed -- on the step level and before the graph is accessed on the -- block level. -- -- Any value of type Node_T or Edge_T that was derived from this -- graph, before the call of Collect_Blocks, should no longer -- be used, because it may refer to deleted objects or to -- collections of steps that are no longer basic blocks. function Cells_In (Graph : Graph_T) return Storage.Cell_Set_T; -- -- The set of storage cells that are accessed (read or -- written) in some step or edge precondition of the graph. -- Basis cells of boundable memory references and boundable -- edges are included. -- Cells accessed by callees are not included. function Cells_Used ( Nodes : Node_List_T; Graph : Graph_T) return Storage.Cell_List_T; -- -- The set of storage cells that are read in the nodes listed -- or in preconditions on edges within or leaving the nodes. -- Basis cells of boundable memory references and boundable -- edges are included. -- Cells accessed by callees are not included. function Cells_Defined (By : Graph_T) return Storage.Cell_Set_T; -- -- The set of storage cells that are written in the graph. -- Cells written by callees are included if they are listed in the -- effect of the call step i.e. if the call has been "launched", -- see Flow.Calls.Launch. function Cells_Defined ( Nodes : Node_List_T; Graph : Graph_T) return Storage.Cell_List_T; -- -- The set of storage cells that are written in the nodes listed. -- Cells written by callees are included if they are listed in the -- effect of the call step. procedure Add_Dynamic_Edge_Basis_Cells ( From : in Node_T; Graph : in Graph_T; To : in out Storage.Cell_Set_T); -- -- Adds the Basis cells for all dynamic edges From the steps -- in the given Graph node To the given cell-set. procedure Add_Cells_Accessed ( By : in Node_T; Graph : in Graph_T; To : in out Storage.Cell_Set_T); -- -- Finds the cells accessed (read and/or written) by the given node -- (i.e. by the effects of the steps in the node or by the preconditions -- on edges leaving the node or by boundable objects as basis cells) -- and adds these cells to the given cell-set. Cells read by callees -- are not included. Cells written by callees are included if they are -- listed in the effect of the call step. function Is_Used ( Location : Storage.Location_T; By : Step_T) return Boolean; -- -- Whether the given Location is used (read) By the given step. -- -- The step is considered to use the location if the location maps -- to a cell at the address of the step such that the cell is -- > used in a Defining assignment in the effect of the step, or -- > used in the precondition of an edge leaving the step. -- -- If the location maps to several cells at this step, it is enough -- for one of these cells to be used in the above ways. function Is_Used ( Location : Storage.Location_T; By : Node_List_T) return Boolean; -- -- Whether the given Location is used (read) By the steps in the -- given nodes. For details see Is_Used (By : Step). function Is_Defined ( Location : Storage.Location_T; By : Step_T) return Boolean; -- -- Whether the given Location is defined (assigned) By the given step. -- -- The step is considered to define the location if the location maps -- to a cell at the address of the step such that the cell is -- > defined in a Defining assignment in the effect of the step, or -- > defined by the callee of a launched call-step. -- -- If the location maps to several cells at this step, it is enough -- for one of these cells to be defined in the above ways. function Is_Defined ( Location : Storage.Location_T; By : Node_List_T) return Boolean; -- -- Whether the given Location is defined (assigned) By the steps -- in the given nodes. For details see Is_Defined (By : Step). private type Graph_Object_T; type Graph_T is access Graph_Object_T; Null_Graph : constant Graph_T := null; type Step_Object_T; type Step_T is access Step_Object_T; No_Step : constant Step_T := null; type Step_Edge_Object_T; type Step_Edge_T is access Step_Edge_Object_T; No_Step_Edge : constant Step_Edge_T := null; type Boundable_Edge_T is abstract new Storage.Bounds.Boundable_T with record Source : Step_T := No_Step; Role : Boundable_Edge_Role_T := Undefined; State : Edge_Resolution_T := Unresolved; Resolvents : Natural := 0; Returns : Boolean := False; Domain_Grown : Boolean := True; Unstable : Boolean := False; end record; -- -- The common part of a boundable edge. -- -- Source -- The source step, natch. -- Role -- The assumed or confirmed role of the edge. -- State -- The current state of resolution of the edge. -- Resolvents -- The number of static step-edges that this boundable -- edge has spawned. -- Returns -- Whether this boundable edge has been resolved to -- a return-from-subprogram. -- Domain_Grown -- Whether the domain of this boundable edge has grown since -- the last full (arithmetic) analysis of the edge. The domain -- grows if new edges enter the steps in the domain. A new -- boundable edge has Domain_Grown set by default so that -- it will always be analysed in the first round of boundable- -- edge analysis after the edge is created. -- Unstable -- Whether this boundable edge should be (re-)analysed -- in this round of boundable-edge analysis, assuming -- that the edge is feasible (reachable). type Node_Object_T (Number_Of_Steps : Positive); type Node_T is access Node_Object_T; No_Node : constant Node_T := null; type Edge_Object_T; type Edge_T is access Edge_Object_T; Null_Edge : constant Edge_T := null; function Image (Item : Step_T) return String; -- -- A description of the step, for tracing purposes. end Flow;
reznikmm/matreshka
Ada
6,981
adb
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- Open Document Toolkit -- -- -- -- Runtime Library Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2014, Vadim Godunko <[email protected]> -- -- All rights reserved. -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions -- -- are met: -- -- -- -- * Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- -- -- * Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in the -- -- documentation and/or other materials provided with the distribution. -- -- -- -- * Neither the name of the Vadim Godunko, IE nor the names of its -- -- contributors may be used to endorse or promote products derived from -- -- this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -- -- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED -- -- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -- -- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -- -- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -- -- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -- -- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- -- ------------------------------------------------------------------------------ -- $Revision$ $Date$ ------------------------------------------------------------------------------ with Matreshka.DOM_Documents; with Matreshka.ODF_String_Constants; with ODF.DOM.Iterators; with ODF.DOM.Visitors; package body Matreshka.ODF_Table.Table_Row_Group_Elements is ------------ -- Create -- ------------ overriding function Create (Parameters : not null access Matreshka.DOM_Elements.Element_L2_Parameters) return Table_Table_Row_Group_Element_Node is begin return Self : Table_Table_Row_Group_Element_Node do Matreshka.ODF_Table.Constructors.Initialize (Self'Unchecked_Access, Parameters.Document, Matreshka.ODF_String_Constants.Table_Prefix); end return; end Create; ---------------- -- Enter_Node -- ---------------- overriding procedure Enter_Node (Self : not null access Table_Table_Row_Group_Element_Node; Visitor : in out XML.DOM.Visitors.Abstract_Visitor'Class; Control : in out XML.DOM.Visitors.Traverse_Control) is begin if Visitor in ODF.DOM.Visitors.Abstract_ODF_Visitor'Class then ODF.DOM.Visitors.Abstract_ODF_Visitor'Class (Visitor).Enter_Table_Table_Row_Group (ODF.DOM.Table_Table_Row_Group_Elements.ODF_Table_Table_Row_Group_Access (Self), Control); else Matreshka.DOM_Elements.Abstract_Element_Node (Self.all).Enter_Node (Visitor, Control); end if; end Enter_Node; -------------------- -- Get_Local_Name -- -------------------- overriding function Get_Local_Name (Self : not null access constant Table_Table_Row_Group_Element_Node) return League.Strings.Universal_String is pragma Unreferenced (Self); begin return Matreshka.ODF_String_Constants.Table_Row_Group_Element; end Get_Local_Name; ---------------- -- Leave_Node -- ---------------- overriding procedure Leave_Node (Self : not null access Table_Table_Row_Group_Element_Node; Visitor : in out XML.DOM.Visitors.Abstract_Visitor'Class; Control : in out XML.DOM.Visitors.Traverse_Control) is begin if Visitor in ODF.DOM.Visitors.Abstract_ODF_Visitor'Class then ODF.DOM.Visitors.Abstract_ODF_Visitor'Class (Visitor).Leave_Table_Table_Row_Group (ODF.DOM.Table_Table_Row_Group_Elements.ODF_Table_Table_Row_Group_Access (Self), Control); else Matreshka.DOM_Elements.Abstract_Element_Node (Self.all).Leave_Node (Visitor, Control); end if; end Leave_Node; ---------------- -- Visit_Node -- ---------------- overriding procedure Visit_Node (Self : not null access Table_Table_Row_Group_Element_Node; Iterator : in out XML.DOM.Visitors.Abstract_Iterator'Class; Visitor : in out XML.DOM.Visitors.Abstract_Visitor'Class; Control : in out XML.DOM.Visitors.Traverse_Control) is begin if Iterator in ODF.DOM.Iterators.Abstract_ODF_Iterator'Class then ODF.DOM.Iterators.Abstract_ODF_Iterator'Class (Iterator).Visit_Table_Table_Row_Group (Visitor, ODF.DOM.Table_Table_Row_Group_Elements.ODF_Table_Table_Row_Group_Access (Self), Control); else Matreshka.DOM_Elements.Abstract_Element_Node (Self.all).Visit_Node (Iterator, Visitor, Control); end if; end Visit_Node; begin Matreshka.DOM_Documents.Register_Element (Matreshka.ODF_String_Constants.Table_URI, Matreshka.ODF_String_Constants.Table_Row_Group_Element, Table_Table_Row_Group_Element_Node'Tag); end Matreshka.ODF_Table.Table_Row_Group_Elements;
reznikmm/matreshka
Ada
3,679
ads
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- Open Document Toolkit -- -- -- -- Runtime Library Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2014, Vadim Godunko <[email protected]> -- -- All rights reserved. -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions -- -- are met: -- -- -- -- * Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- -- -- * Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in the -- -- documentation and/or other materials provided with the distribution. -- -- -- -- * Neither the name of the Vadim Godunko, IE nor the names of its -- -- contributors may be used to endorse or promote products derived from -- -- this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -- -- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED -- -- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -- -- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -- -- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -- -- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -- -- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- -- ------------------------------------------------------------------------------ -- $Revision$ $Date$ ------------------------------------------------------------------------------ with XML.DOM.Attributes; package ODF.DOM.Dr3d_Vup_Attributes is pragma Preelaborate; type ODF_Dr3d_Vup_Attribute is limited interface and XML.DOM.Attributes.DOM_Attribute; type ODF_Dr3d_Vup_Attribute_Access is access all ODF_Dr3d_Vup_Attribute'Class with Storage_Size => 0; end ODF.DOM.Dr3d_Vup_Attributes;
zrmyers/VulkanAda
Ada
15,754
ads
-------------------------------------------------------------------------------- -- MIT License -- -- Copyright (c) 2020 Zane Myers -- -- Permission is hereby granted, free of charge, to any person obtaining a copy -- of this software and associated documentation files (the "Software"), to deal -- in the Software without restriction, including without limitation the rights -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -- copies of the Software, and to permit persons to whom the Software is -- furnished to do so, subject to the following conditions: -- -- The above copyright notice and this permission notice shall be included in all -- copies or substantial portions of the Software. -- -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -- SOFTWARE. -------------------------------------------------------------------------------- with Vulkan.Math.GenFType; with Vulkan.Math.GenDType; with Vulkan.Math.Vec3; with Vulkan.Math.Dvec3; use Vulkan.Math.GenFType; use Vulkan.Math.GenDType; use Vulkan.Math.Vec3; use Vulkan.Math.Dvec3; -------------------------------------------------------------------------------- --< @group Vulkan Math Functions -------------------------------------------------------------------------------- --< @summary --< This package provides GLSL Geometry Built-in functions. --< --< @description --< All geometry functions operate on vectors as objects. -------------------------------------------------------------------------------- package Vulkan.Math.Geometry is pragma Preelaborate; pragma Pure; ---------------------------------------------------------------------------- --< @summary --< Calculate the magnitude of the vector. --< --< @description --< Calculate the magnitude of the GenFType vector, using the formula: --< --< Magnitude = sqrt(sum(x0^2, ..., xn^2)) --< --< @param x --< The vector to determine the magnitude for. --< --< @return --< The magnitude of the vector. ---------------------------------------------------------------------------- function Mag (x : in Vkm_GenFType) return Vkm_Float; ---------------------------------------------------------------------------- --< @summary --< Calculate the magnitude of the vector. --< --< @description --< Calculate the magnitude of the Vkm_GenDType vector, using the formula: --< --< Magnitude = sqrt(sum(x0^2, ..., xn^2)) --< --< @param x --< The vector to determine the magnitude for. --< --< @return --< The magnitude of the vector. ---------------------------------------------------------------------------- function Mag (x : in Vkm_GenDType) return Vkm_Double; ---------------------------------------------------------------------------- --< @summary --< Calculate the distance between two points, p0 and p1. --< --< @description --< Calculate the distance between two GenFType vectors representing points p0 --< and p1, using the formula: --< --< Distance = Magnitude(p0 - p1) --< --< @param p0 --< A vector which represents the first point. --< --< @param p1 --< A vector which represents the seconds point. --< --< @return --< The distance between the two points. ---------------------------------------------------------------------------- function Distance (p0, p1 : in Vkm_GenFType) return Vkm_Float is (Mag(p0 - p1)) with Inline; ---------------------------------------------------------------------------- --< @summary --< Calculate the distance between two points, p0 and p1. --< --< @description --< Calculate the distance between two GenDType vectors representing points p0 --< and p1, using the formula: --< --< Distance = Magnitude(p0 - p1) --< --< @param p0 --< A vector which represents the first point. --< --< @param p1 --< A vector which represents the seconds point. --< --< @return --< The distance between the two points. ---------------------------------------------------------------------------- function Distance (p0, p1 : in Vkm_GenDType) return Vkm_Double is (Mag(p0 - p1)) with Inline; ---------------------------------------------------------------------------- --< @summary --< Calculate the dot product between two vectors. --< --< @description --< Calculate the dot product between two GenFType vectors. --< --< x dot y = --< \ [x1 ... xN] . | y1 | = x1*y1 + ... xN * yN --< \ | ... | --< \ | yN | --< --< @param x --< The left vector in the dot product operation. --< --< @param y --< The right vector in the dot product operation. --< --< --< @return The dot product of the two vectors. ---------------------------------------------------------------------------- function Dot (x, y : in Vkm_GenFType) return Vkm_Float; ---------------------------------------------------------------------------- --< @summary --< Calculate the dot product between two vectors. --< --< @description --< Calculate the dot product between the two GenDType vectors. --< --< x dot y = --< \ [x1 ... xN] . | y1 | = x1*y1 + ... xN * yN --< \ | ... | --< \ | yN | --< --< @param x --< The left vector in the dot product operation. --< --< @param y --< The right vector in the dot product operation. --< --< @return --< The dot product of the two vectors. ---------------------------------------------------------------------------- function Dot (x, y : in Vkm_GenDType) return Vkm_Double; ---------------------------------------------------------------------------- --< @summary --< Calculate the cross product between two 3 dimmensional vectors. --< --< @description --< Calculate the cross product between two 3 dimmensional GenFType vectors. --< --< x cross y = --< \ | i j k | = i | x1 x2 | -j | x0 x2 | +k | x0 x1 | = | +(x1*y2 - x2*y1) | --< \ | x0 x1 x2 | | y1 y2 | | y0 y2 | | y0 y1 | | -(x0*y2 - x2*y1) | --< \ | y0 y1 y2 | | +(x0*y1 - x1*y0) | --< --< @param x --< The left vector in the cross product operation. --< --< @param y --< The right vector in the cross product operation. --< --< @return --< The cross product of the two vectors. ---------------------------------------------------------------------------- function Cross (x, y : in Vkm_Vec3 ) return Vkm_Vec3; ---------------------------------------------------------------------------- --< @summary --< Calculate the cross product between two 3 dimmensional vectors. --< --< @description --< Calculate the cross product between two 3 dimmensional GenDType vectors. --< --< x cross y = --< \ | i j k | = i | x1 x2 | -j | x0 x2 | +k | x0 x1 | = | +(x1*y2 - x2*y1) | --< \ | x0 x1 x2 | | y1 y2 | | y0 y2 | | y0 y1 | | -(x0*y2 - x2*y1) | --< \ | y0 y1 y2 | | +(x0*y1 - x1*y0) | --< --< @param x --< The left vector in the cross product operation. --< --< @param y --< The right vector in the cross product operation. --< --< @return --< The cross product of the two vectors. ---------------------------------------------------------------------------- function Cross (x, y : in Vkm_Dvec3) return Vkm_Dvec3; ---------------------------------------------------------------------------- --< @summary --< Normalize a vector. --< --< @description --< Normalize the GenFType vector so that it has a magnitude of 1. --< --< @param x --< The vector to normalize. --< --< @return --< The normalized vector. ---------------------------------------------------------------------------- function Normalize(x : in Vkm_GenFType) return Vkm_GenFType is (x / Mag(x)) with inline; ---------------------------------------------------------------------------- --< @summary --< Normalize a vector. --< --< @description --< Normalize the GenDType vector so that it has a magnitude of 1. --< --< @param x --< The vector to normalize. --< --< @return --< The normalized vector. ---------------------------------------------------------------------------- function Normalize(x : in Vkm_GenDType) return Vkm_GenDType is (x / Mag(x)) with inline; ---------------------------------------------------------------------------- --< @summary --< Force a normal vector to face an incident vector. --< --< @description --< Return a normal vector N as-is if an incident vector I points in the opposite --< direction of a reference normal vector, Nref. Otherwise, if I is pointing --< in the same direction as the reference normal, flip the normal vector N. --< --< - If Nref dot I is negative, these vectors are not facing the same direction. --< - If Nref dot I is positive, these vectors are facing in the same direction. --< - If Nref dot I is zero, these two vectors are orthogonal to each other. --< --< @param n --< The normal vector N --< --< @param i --< The incident vector I --< --< @param nref --< The reference normal vector Nref --< --< @return --< If I dot Nref < 0, return N. Otherwise return -N. ---------------------------------------------------------------------------- function Face_Forward(n, i, nref : in Vkm_GenFType) return Vkm_GenFType is (if Dot(nref,i) < 0.0 then n else -n) with Inline; ---------------------------------------------------------------------------- --< @summary --< Force a normal vector to face an incident vector. --< --< @description --< Return a normal vector N as-is if an incident vector I points in the opposite --< direction of a reference normal vector, Nref. Otherwise, if I is pointing --< in the same direction as the reference normal, flip the normal vector N. --< --< - If Nref dot I is negative, these vectors are not facing the same direction. --< - If Nref dot I is positive, these vectors are facing in the same direction. --< - If Nref dot I is zero, these two vectors are orthogonal to each other. --< --< @param n --< The normal vector N --< --< @param i --< The incident vector I --< --< @param nref --< The reference normal vector Nref --< --< @return --< If I dot Nref < 0, return N. Otherwise return -N. ---------------------------------------------------------------------------- function Face_Forward(n, i, nref : in Vkm_GenDType) return Vkm_GenDType is (if Dot(nref,i) < 0.0 then n else -n) with Inline; ---------------------------------------------------------------------------- --< @summary --< Calculate the reflection of an incident vector using the normal vector --< for the surface. --< --< @description --< For the incident vector I and surface orientation N, returns the reflection --< direction: --< --< I - 2 * ( N dot I ) * N. --< --< @param i --< The incident vector I. --< --< @param n --< The normal vector N. N should already be normalized. --< --< @return The reflection direction. ---------------------------------------------------------------------------- function Reflect(i, n : in Vkm_GenFType) return Vkm_GenFType is (i - 2.0 * Dot(n, i) * n) with Inline; ---------------------------------------------------------------------------- --< @summary --< Calculate the reflection of an incident vector using the normal vector --< for the surface. --< --< @description --< For the incident vector I and surface orientation N, returns the reflection --< direction: --< --< I - 2 * ( N dot I ) * N. --< --< @param i --< The incident vector I. --< --< @param n --< The normal vector N. N should already be normalized. --< --< @return The reflection direction. ---------------------------------------------------------------------------- function Reflect(i, n : in Vkm_GenDType) return Vkm_GenDType is (i - 2.0 * Dot(n, i) * n) with Inline; ---------------------------------------------------------------------------- --< @summary --< Calculate the refraction vector for the incident vector I travelling --< through the surface with normal N and a ratio of refraction eta. --< --< @description --< For the indident vector I and surface normal N, and the ratio of refraction --< eta, calculate the refraction vector. --< --< k = 1.0 - eta^2 (1.0 - dot(N,I)^2) --< If k < 0, the result is a vector of all zeros. --< Else , the result is: eta*I - (eta*dot(N,I) + sqrt(k))*N --< --< @param i --< The incident vector I. --< --< @param n --< The surface normal vector N. --< --< @param eta --< The indices of refraction. --< --< @return --< The refraction vector. ---------------------------------------------------------------------------- function Refract(i, n : in Vkm_GenFType; eta : in Vkm_Float ) return Vkm_GenFType; ---------------------------------------------------------------------------- --< @summary --< Calculate the refraction vector for the incident vector I travelling --< through the surface with normal N and a ratio of refraction eta. --< --< @description --< For the indident vector I and surface normal N, and the ratio of refraction --< eta, calculate the refraction vector. --< --< k = 1.0 - eta^2 (1.0 - dot(N,I)^2) --< If k < 0, the result is a vector of all zeros. --< Else , the result is: eta*I - (eta*dot(N,I) + sqrt(k))*N --< --< @param i --< The incident vector I. --< --< @param n --< The surface normal vector N. --< --< @param eta --< The indices of refraction. --< --< @return --< The refraction vector. ---------------------------------------------------------------------------- function Refract(i, n : in Vkm_GenDType; eta : in Vkm_Double ) return Vkm_GenDType; end Vulkan.Math.Geometry;
gcmurphy/Amass
Ada
2,645
ads
-- Copyright 2017-2021 Jeff Foley. All rights reserved. -- Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file. local json = require("json") name = "Censys" type = "cert" function start() setratelimit(3) end function vertical(ctx, domain) local c local cfg = datasrc_config() if cfg ~= nil then c = cfg.credentials end if (c == nil or c.key == nil or c.key == "" or c.secret == nil or c.secret == "") then scrape(ctx, {url=scrapeurl(domain)}) return end apiquery(ctx, cfg, domain) end function apiquery(ctx, cfg, domain) local p = 1 while(true) do local resp local reqstr = domain .. "page: " .. p -- Check if the response data is in the graph database if (cfg.ttl ~= nil and cfg.ttl > 0) then resp = obtain_response(reqstr, cfg.ttl) end if (resp == nil or resp == "") then local body, err = json.encode({ query="parsed.names: " .. domain, page=p, fields={"parsed.names"}, }) if (err ~= nil and err ~= "") then return end resp, err = request(ctx, { method="POST", data=body, url=apiurl(), headers={['Content-Type']="application/json"}, id=cfg["credentials"].key, pass=cfg["credentials"].secret, }) if (err ~= nil and err ~= "") then return end if (cfg.ttl ~= nil and cfg.ttl > 0) then cache_response(reqstr, resp) end end local d = json.decode(resp) if (d == nil or d.status ~= "ok" or #(d.results) == 0) then return end for i, r in pairs(d.results) do for j, v in pairs(r["parsed.names"]) do sendnames(ctx, v) end end if d["metadata"].page >= d["metadata"].pages then return end checkratelimit() p = p + 1 end end function apiurl() return "https://www.censys.io/api/v1/search/certificates" end function scrapeurl(domain) return "https://www.censys.io/domain/" .. domain .. "/table" end function sendnames(ctx, content) local names = find(content, subdomainre) if names == nil then return end local found = {} for i, v in pairs(names) do if found[v] == nil then newname(ctx, v) found[v] = true end end end
charlie5/aIDE
Ada
389
ads
with Asis; package AdaM.Assist.Query.find_Entities.context_Processing is procedure Process_Context (The_Context : in Asis.Context; Trace : in Boolean := False); function Get_Unit_From_File_Name (Ada_File_Name : in String; The_Context : in Asis.Context) return Asis.Compilation_Unit; end AdaM.Assist.Query.find_Entities.context_Processing;
Kidev/Ada_Drivers_Library
Ada
15,450
adb
------------------------------------------------------------------------------ -- -- -- Copyright (C) 2017, AdaCore -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions are -- -- met: -- -- 1. Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- 2. Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in -- -- the documentation and/or other materials provided with the -- -- distribution. -- -- 3. Neither the name of the copyright holder nor the names of its -- -- contributors may be used to endorse or promote products derived -- -- from this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -- -- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -- -- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -- -- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -- -- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -- -- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -- -- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- -- ------------------------------------------------------------------------------ with HAL; use HAL; with nRF51.GPIO; use nRF51.GPIO; with nRF51.ADC; use nRF51.ADC; with nRF51.Device; use nRF51.Device; with nRF51.PPI; use nRF51.PPI; with nRF51.Timers; use nRF51.Timers; with nRF51.GPIO.Tasks_And_Events; use nRF51.GPIO.Tasks_And_Events; with nRF51.Events; use nRF51.Events; with nRF51.Interrupts; use nRF51.Interrupts; package body MicroBit.IOs is -- The analog out feature is implemented as PWM signal. To generate the PWM -- signals we use a timer with the configuration described bellow. -- -- Because of the limited number of timer comparators and GPIOTE channels, -- we can only have 3 PWMs on the system at the same time. However there -- are 5 pins allowed to use PWM, so we need to dynamicaly allocate the -- PWM based on user requests. -- -- Timer configuration: -- -- Comparator 0, 1, 2 are used to control the pulse width of the 3 PWMs. -- Each of those comparator is associated with a PWM and a pin. When the -- timer counter reaches the value of a comparator, the associated pin -- toggles. -- -- Comparator 3 is use to control the period. When the timer counter reaches -- its value, all pins toggle. -- -- Comparator 3 also trigger an interrupt. In the handler for this -- interrupt, we update all the comparator values and start the timer again. -- -- -- Int handler and timer start Cmp 0 Cmp 1 Cmp 2 Cmp3, Timer stop and interrupt -- v v v v v -- _______________________________ ____ -- |_______________________| -- ______________________________________ ____ -- |________________| -- _____________________________________________ ____ -- |_________| -- -- ^------------------ Timer loop sequence -------------------^ -- -- Since all the timer events trigger a toggle of the pin, we have to make -- sure that the pin is at a good state (high) when starting the timer, -- otherwise the waveform could be inverted. This is why the GPIO channels -- are always configured when the timer is reconfigured. -- -- PPI and GPIOTE: -- -- To trigger a pin toggle from the timer compare events we use the -- following configuation. -- -- Two PPI channels are used for each PWM pin. For a PWM X, one PPI channel -- is used to trigger a GPIOTE task on comparator X event, a second PPI -- channel is used to trigger a GPIOTE event on comparator 3 event. So -- the comparator 3 event is used by all PWMs. -- -- For a PWM X, GPIOTE channel X is configure to do a pin toggle when its -- task is activated by one of the two PPI channels described above. -- Mapping between pin id and GPIO_Points Points : array (Pin_Id) of GPIO_Point := (0 => MB_P0, 1 => MB_P1, 2 => MB_P2, 3 => MB_P3, 4 => MB_P4, 5 => MB_P5, 6 => MB_P6, 7 => MB_P7, 8 => MB_P8, 9 => MB_P9, 10 => MB_P10, 11 => MB_P11, 12 => MB_P12, 13 => MB_P13, 14 => MB_P14, 15 => MB_P15, 16 => MB_P16, 17 => MB_P0, -- There's no pin17, using P0 to fill in... 18 => MB_P0, -- There's no pin18, using P0 to fill in... 19 => MB_P19, 20 => MB_P20); -- We keep track of the current mode of the pin to be able to detect when a -- change of configuration is needed. type Pin_Mode is (None, Digital_In, Digital_Out, Analog_In, Analog_Out); Current_Mode : array (Pin_Id) of Pin_Mode := (others => None); -- PWM -- Number_Of_PWMs : constant := 3; type PWM_Allocated is range 0 .. Number_Of_PWMs; subtype PWM_Id is PWM_Allocated range 0 .. Number_Of_PWMs - 1; No_PWM : constant PWM_Allocated := Number_Of_PWMs; PWM_Alloc : array (Pin_Id) of PWM_Allocated := (others => No_PWM); PWM_Timer : Timer renames Timer_0; PWM_Interrupt : constant Interrupt_Name := TIMER0_Interrupt; PWM_Global_Compare : constant Timer_Channel := 3; PWM_Precision : constant := 4; PWM_Period : UInt32 := 2_000 / PWM_Precision; type PWM_Status is record Taken : Boolean := False; Pulse_Width : Analog_Value; Cmp : UInt32 := 10; Pin : Pin_Id; end record; PWMs : array (PWM_Id) of PWM_Status; function Has_PWM (Pin : Pin_Id) return Boolean is (PWM_Alloc (Pin) /= No_PWM); procedure Allocate_PWM (Pin : Pin_Id; Success : out Boolean) with Pre => not Has_PWM (Pin); procedure Deallocate_PWM (Pin : Pin_Id) with Pre => Has_PWM (Pin), Post => not Has_PWM (Pin); procedure Configure_PPI (Id : PWM_Id); procedure Configure_GPIOTE (Id : PWM_Id); procedure Init_PWM_Timer; function To_Compare_Value (V : Analog_Value) return UInt32; procedure PWM_Timer_Handler; ---------------------- -- To_Compare_Value -- ---------------------- function To_Compare_Value (V : Analog_Value) return UInt32 is Cmp : constant UInt32 := UInt32 (Float (PWM_Period) * (Float (V) / Float (Analog_Value'Last))); begin if Cmp = 0 then return 1; elsif Cmp >= PWM_Period then return PWM_Period - 1; else return Cmp; end if; end To_Compare_Value; ------------------ -- Allocate_PWM -- ------------------ procedure Allocate_PWM (Pin : Pin_Id; Success : out Boolean) is begin for Id in PWM_Id loop if not PWMs (Id).Taken then PWMs (Id).Taken := True; PWMs (Id).Pin := Pin; PWM_Alloc (Pin) := Id; Configure_PPI (Id); Success := True; return; end if; end loop; Success := False; end Allocate_PWM; -------------------- -- Deallocate_PWM -- -------------------- procedure Deallocate_PWM (Pin : Pin_Id) is begin if PWM_Alloc (Pin) /= No_PWM then nRF51.GPIO.Tasks_And_Events.Disable (GPIOTE_Channel (PWM_Alloc (Pin))); PWMs (PWM_Alloc (Pin)).Taken := False; PWM_Alloc (Pin) := No_PWM; end if; end Deallocate_PWM; ------------------- -- Configure_PPI -- ------------------- procedure Configure_PPI (Id : PWM_Id) is Chan1 : constant Channel_ID := Channel_ID (Id) * 2; Chan2 : constant Channel_ID := Chan1 + 1; begin -- Use one PPI channel to triggerd GPTIOTE OUT task on the compare event -- associated with this PWM_Id; nRF51.PPI.Configure (Chan => Chan1, Evt_EP => PWM_Timer.Compare_Event (Timer_Channel (Id)), Task_EP => Out_Task (GPIOTE_Channel (Id))); -- Use another PPI channel to triggerd GPTIOTE OUT task on compare 3 event nRF51.PPI.Configure (Chan => Chan2, Evt_EP => PWM_Timer.Compare_Event (PWM_Global_Compare), Task_EP => Out_Task (GPIOTE_Channel (Id))); nRF51.PPI.Enable_Channel (Chan1); nRF51.PPI.Enable_Channel (Chan2); end Configure_PPI; ---------------------- -- Configure_GPIOTE -- ---------------------- procedure Configure_GPIOTE (Id : PWM_Id) is begin -- Configure the GPIOTE OUT task to toggle the pin nRF51.GPIO.Tasks_And_Events.Enable_Task (Chan => GPIOTE_Channel (Id), GPIO_Pin => Points (PWMs (Id).Pin).Pin, Action => Toggle_Pin, Initial_Value => Init_Set); end Configure_GPIOTE; ----------------------- -- PWM_Timer_Handler -- ----------------------- procedure PWM_Timer_Handler is begin Clear (PWM_Timer.Compare_Event (PWM_Global_Compare)); PWM_Timer.Set_Compare (PWM_Global_Compare, PWM_Period); PWM_Timer.Set_Compare (0, PWMs (0).Cmp); PWM_Timer.Set_Compare (1, PWMs (1).Cmp); PWM_Timer.Set_Compare (2, PWMs (2).Cmp); PWM_Timer.Start; end PWM_Timer_Handler; -------------------- -- Init_PWM_Timer -- -------------------- procedure Init_PWM_Timer is begin PWM_Timer.Set_Mode (Mode_Timer); PWM_Timer.Set_Prescaler (6); PWM_Timer.Set_Bitmode (Bitmode_32bit); -- Clear counter internal register and stop when timer reaches compare -- value 3. PWM_Timer.Compare_Shortcut (Chan => PWM_Global_Compare, Stop => True, Clear => True); PWM_Timer.Set_Compare (PWM_Global_Compare, PWM_Period); for Id in PWM_Id loop PWM_Timer.Set_Compare (Timer_Channel (Id), To_Compare_Value (PWMs (Id).Pulse_Width)); if PWMs (Id).Taken then Configure_GPIOTE (Id); end if; end loop; Enable_Interrupt (PWM_Timer.Compare_Event (PWM_Global_Compare)); nRF51.Interrupts.Register (PWM_Interrupt, PWM_Timer_Handler'Access); nRF51.Interrupts.Enable (PWM_Interrupt); end Init_PWM_Timer; --------- -- Set -- --------- procedure Set (Pin : Pin_Id; Value : Boolean) is Pt : GPIO_Point renames Points (Pin); Conf : GPIO_Configuration; begin if Current_Mode (Pin) /= Digital_Out then if Has_PWM (Pin) then Deallocate_PWM (Pin); end if; Conf.Mode := Mode_Out; Conf.Resistors := No_Pull; Conf.Input_Buffer := Input_Buffer_Connect; Conf.Sense := Sense_Disabled; Pt.Configure_IO (Conf); Current_Mode (Pin) := Digital_Out; end if; if Value then Pt.Set; else Pt.Clear; end if; end Set; --------- -- Set -- --------- function Set (Pin : Pin_Id) return Boolean is Pt : GPIO_Point renames Points (Pin); Conf : GPIO_Configuration; begin if Current_Mode (Pin) /= Digital_In then if Has_PWM (Pin) then Deallocate_PWM (Pin); end if; Conf.Mode := Mode_In; Conf.Resistors := No_Pull; Conf.Input_Buffer := Input_Buffer_Connect; Conf.Sense := Sense_Disabled; Pt.Configure_IO (Conf); Current_Mode (Pin) := Digital_In; end if; return Pt.Set; end Set; -------------------------- -- Set_Analog_Period_Us -- -------------------------- procedure Set_Analog_Period_Us (Period : Natural) is begin PWM_Period := UInt32 (Period) / PWM_Precision; -- Update the comparator values for ech PWM for PWM of PWMs loop PWM.Cmp := To_Compare_Value (PWM.Pulse_Width); end loop; end Set_Analog_Period_Us; ----------- -- Write -- ----------- procedure Write (Pin : Pin_Id; Value : Analog_Value) is Success : Boolean; Pt : GPIO_Point renames Points (Pin); Conf : GPIO_Configuration; begin if not Has_PWM (Pin) then -- Stop the timer while we configure a new pin PWM_Timer.Stop; PWM_Timer.Clear; Allocate_PWM (Pin, Success); if not Success then raise Program_Error with "No PWM available"; end if; -- Set the pin as output Conf.Mode := Mode_Out; Conf.Resistors := No_Pull; Conf.Input_Buffer := Input_Buffer_Connect; Conf.Sense := Sense_Disabled; Pt.Configure_IO (Conf); Pt.Clear; Current_Mode (Pin) := Analog_Out; Init_PWM_Timer; PWM_Timer.Start; end if; PWMs (PWM_Alloc (Pin)).Pulse_Width := Value; PWMs (PWM_Alloc (Pin)).Cmp := To_Compare_Value (Value); end Write; ------------ -- Analog -- ------------ function Analog (Pin : Pin_Id) return Analog_Value is begin if Current_Mode (Pin) /= Analog_In then if Has_PWM (Pin) then Deallocate_PWM (Pin); end if; Current_Mode (Pin) := Analog_In; end if; Start_Pin_Conversion (Pin => (case Pin is when 0 => 4, when 1 => 3, when 2 => 2, when 3 => 5, when 4 => 6, when 10 => 7, when others => 0), Input => Pin_One_Third, Ref => VDD_One_Third, Res => 10); return Analog_Value (Wait_For_Result); end Analog; end MicroBit.IOs;
persan/protobuf-ada
Ada
7,893
adb
-- Generated by the protocol buffer compiler. DO NOT EDIT! -- source: message.proto pragma Ada_2012; with Protocol_Buffers.Wire_Format; with Ada.Strings.Unbounded; package body Message is package body Person is --------------------------------------------------------------------------- -- Inherited functions and procedures from Protocol_Buffers.Message ------- --------------------------------------------------------------------------- procedure Clear (The_Message : in out Person.Instance) is begin if (The_Message.Has_Bits (0 / 32) and Protocol_Buffers.Wire_Format.Shift_Left (16#FF#, 0 mod 32)) /= 0 then The_Message.Id := 0; if The_Message.Has_Name then pragma Compile_Time_Warning (Standard.True, "Clear for message and string not implemented!"); end if; end if; The_Message.Has_Bits := (others => 0); end Clear; procedure Copy (To : in out Person.Instance; From : in Person.Instance) is begin pragma Compile_Time_Warning (Standard.True, "Copy not implemented!"); null; end Copy; function Get_Type_Name (The_Message : in Person.Instance) return Protocol_Buffers.Wire_Format.TMP_STRING is begin return "Person"; end Get_Type_Name; function Is_Initialized (The_Message : in Person.Instance) return Boolean is begin if (The_Message.Has_Bits(0) and 16#00000001#) /= 16#00000001# then return False; end if; return True; end Is_Initialized; procedure Merge (To : in out Person.Instance; From : in Person.Instance) is begin if (From.Has_Bits (0 / 32) and Protocol_Buffers.Wire_Format.Shift_Left (16#FF#, 0 mod 32)) /= 0 then -- required int32 id = 1; if From.Has_Id then To.Set_Id (From.Id); end if; -- optional string name = 2; if From.Has_Name then -- To.Set_Name (Protocol_Buffers.Wire_Format.TMP_String (Ada.Strings.Unbounded.To_String (From.Name)); To.Name := From.Name; end if; end if; end Merge; function Byte_Size (The_Message : in out Person.Instance) return Protocol_Buffers.Wire_Format.TMP_OBJECT_SIZE is Total_Size : Protocol_Buffers.Wire_Format.TMP_OBJECT_SIZE := 0; begin -- required int32 id = 1; if The_Message.Has_Id then Total_Size := Total_Size + 1 + Protocol_Buffers.IO.Coded_Output_Stream.Compute_Integer_32_Size_No_Tag (The_Message.Id); end if; -- optional string name = 2; if The_Message.Has_Name then declare asdf : Natural := Ada.Strings.Unbounded.Length(The_Message.Name); begin null; end; Total_Size := Total_Size + Protocol_Buffers.Wire_Format.TMP_OBJECT_SIZE(Ada.Strings.Unbounded.Length(The_Message.Name)); end if; The_Message.Cached_Size := Total_Size; return Total_Size; end Byte_Size; procedure Serialize_With_Cached_Sizes (The_Message : in Person.Instance; The_Coded_Output_Stream : in Protocol_Buffers.IO.Coded_Output_Stream.Instance) is begin -- required int32 id = 1; if The_Message.Has_Id then Protocol_Buffers.IO.Coded_Output_Stream.Write_Integer_32 (The_Coded_Output_Stream, 1, The_Message.Id); end if; -- optional string name = 2; if The_Message.Has_Name then Protocol_Buffers.IO.Coded_Output_Stream.Write_String (The_Coded_Output_Stream, 2, Protocol_Buffers.Wire_Format.TMP_String(Ada.Strings.Unbounded.To_String(The_Message.Name))); end if; end Serialize_With_Cached_Sizes; procedure Merge_Partial_From_Coded_Input_Stream (The_Message : in out Person.Instance; The_Coded_Input_Stream : in Protocol_Buffers.IO.Coded_Input_Stream.Instance) is Tag : Protocol_Buffers.Wire_Format.TMP_UNSIGNED_INTEGER; begin Tag := The_Coded_Input_Stream.Read_Tag; while Tag /= 0 loop case Protocol_Buffers.Wire_Format.Get_Tag_Field_Number (Tag) is -- required int32 id = 1; when 1 => if Protocol_Buffers.Wire_Format.Get_Tag_Wire_Type (Tag) = Protocol_Buffers.Wire_Format.VARINT then The_Message.Id := The_Coded_Input_Stream.Read_Integer_32; The_Message.Set_Has_Id; end if; -- optional string name = 2; when 2 => if Protocol_Buffers.Wire_Format.Get_Tag_Wire_Type (Tag) = Protocol_Buffers.Wire_Format.LENGTH_DELIMITED then The_Message.Name := Ada.Strings.Unbounded.To_Unbounded_String (String(The_Coded_Input_Stream.Read_String)); The_Message.Set_Has_Name; end if; when others => pragma Compile_Time_Warning (Standard.True, "Error handling not implemented for Merge_Partial_From_Coded_Input_Stream!"); end case; Tag := The_Coded_Input_Stream.Read_Tag; end loop; end Merge_Partial_From_Coded_Input_Stream; function Get_Cached_Size (The_Message : in Person.Instance) return Protocol_Buffers.Wire_Format.TMP_OBJECT_SIZE is begin return The_Message.Cached_Size; end Get_Cached_Size; --------------------------------------------------------------------------- -- Field accessor definitions --------------------------------------------- --------------------------------------------------------------------------- -- required int32 id = 1; function Has_Id (The_Message : in Person.Instance) return Boolean is begin return (The_Message.Has_Bits(0) and 16#00000001#) /= 0; end Has_Id; procedure Set_Has_Id (The_Message : in out Person.Instance) is begin The_Message.Has_Bits(0) := The_Message.Has_Bits(0) or 16#00000001#; end Set_Has_Id; procedure Clear_Has_Id (The_Message : in out Person.Instance) is begin The_Message.Has_Bits(0) := The_Message.Has_Bits(0) and (not 16#00000001#); end Clear_Has_Id; procedure Clear_Id (The_Message : in out Person.Instance) is begin The_Message.Id := 0; end Clear_Id; function Id (The_Message : in Person.Instance) return Protocol_Buffers.Wire_Format.TMP_INTEGER is begin return The_Message.Id; end Id; procedure Set_Id (The_Message : in out Person.Instance; Value : in Protocol_Buffers.Wire_Format.TMP_INTEGER) is begin Set_Has_Id (The_Message); The_Message.Id := Value; end Set_Id; -- optional string name = 2; function Has_Name (The_Message : in Person.Instance) return Boolean is begin return (The_Message.Has_Bits(0) and 16#00000002#) /= 0; end Has_Name; procedure Set_Has_Name (The_Message : in out Person.Instance) is begin The_Message.Has_Bits(0) := The_Message.Has_Bits(0) or 16#00000002#; end Set_Has_Name; procedure Clear_Has_Name (The_Message : in out Person.Instance) is begin The_Message.Has_Bits(0) := The_Message.Has_Bits(0) and (not 16#00000002#); end Clear_Has_Name; procedure Clear_Name (The_Message : in out Person.Instance) is begin The_Message.Name := Ada.Strings.Unbounded.To_Unbounded_String(""); end Clear_Name; function Name (The_Message : in Person.Instance) return Protocol_Buffers.Wire_Format.TMP_STRING is begin return Protocol_Buffers.Wire_Format.TMP_STRING(Ada.Strings.Unbounded.To_String(The_Message.Name)); end Name; procedure Set_Name (The_Message : in out Person.Instance; Value : in Protocol_Buffers.Wire_Format.TMP_STRING) is begin Set_Has_Name (The_Message); The_Message.Name := Ada.Strings.Unbounded.To_Unbounded_String(String(Value)); end Set_Name; end Person; end Message;
muschellij2/FSL6.0.0
Ada
3,332
adb
---------------------------------------------------------------- -- ZLib for Ada thick binding. -- -- -- -- Copyright (C) 2002-2003 Dmitriy Anisimkov -- -- -- -- Open source license information is in the zlib.ads file. -- ---------------------------------------------------------------- -- $Id: zlib-thin.adb,v 1.3 2010/07/15 14:24:17 mwebster Exp $ package body ZLib.Thin is ZLIB_VERSION : constant Chars_Ptr := zlibVersion; Z_Stream_Size : constant Int := Z_Stream'Size / System.Storage_Unit; -------------- -- Avail_In -- -------------- function Avail_In (Strm : in Z_Stream) return UInt is begin return Strm.Avail_In; end Avail_In; --------------- -- Avail_Out -- --------------- function Avail_Out (Strm : in Z_Stream) return UInt is begin return Strm.Avail_Out; end Avail_Out; ------------------ -- Deflate_Init -- ------------------ function Deflate_Init (strm : Z_Streamp; level : Int; method : Int; windowBits : Int; memLevel : Int; strategy : Int) return Int is begin return deflateInit2 (strm, level, method, windowBits, memLevel, strategy, ZLIB_VERSION, Z_Stream_Size); end Deflate_Init; ------------------ -- Inflate_Init -- ------------------ function Inflate_Init (strm : Z_Streamp; windowBits : Int) return Int is begin return inflateInit2 (strm, windowBits, ZLIB_VERSION, Z_Stream_Size); end Inflate_Init; ------------------------ -- Last_Error_Message -- ------------------------ function Last_Error_Message (Strm : in Z_Stream) return String is use Interfaces.C.Strings; begin if Strm.msg = Null_Ptr then return ""; else return Value (Strm.msg); end if; end Last_Error_Message; ------------ -- Set_In -- ------------ procedure Set_In (Strm : in out Z_Stream; Buffer : in Voidp; Size : in UInt) is begin Strm.Next_In := Buffer; Strm.Avail_In := Size; end Set_In; ------------------ -- Set_Mem_Func -- ------------------ procedure Set_Mem_Func (Strm : in out Z_Stream; Opaque : in Voidp; Alloc : in alloc_func; Free : in free_func) is begin Strm.opaque := Opaque; Strm.zalloc := Alloc; Strm.zfree := Free; end Set_Mem_Func; ------------- -- Set_Out -- ------------- procedure Set_Out (Strm : in out Z_Stream; Buffer : in Voidp; Size : in UInt) is begin Strm.Next_Out := Buffer; Strm.Avail_Out := Size; end Set_Out; -------------- -- Total_In -- -------------- function Total_In (Strm : in Z_Stream) return ULong is begin return Strm.Total_In; end Total_In; --------------- -- Total_Out -- --------------- function Total_Out (Strm : in Z_Stream) return ULong is begin return Strm.Total_Out; end Total_Out; end ZLib.Thin;
emanuelliborio/Stuff
Ada
664
adb
with Ada.Text_IO; use Ada.Text_IO; with Ada.Float_Text_IO; use Ada.Float_Text_IO; procedure calculator is Number1 : Float; Operator : Character; Number2 : Float; Result : Float; begin Put_Line("Enter your math problem: "); -- Examlple: 1+2, 1.2+3 etc. Get(Number1); Get(Operator); Get(Number2); if Operator = '+' then Result := Number1 + Number2; elsif Operator = '-' then Result := Number1 - Number2; elsif Operator = '*' then Result := Number1 * Number2; elsif Operator = '/' then Result := Number1 / Number2; else Result := 0.0; Put_Line("Invalid input"); end if; Put_Line("Result" & Float'Image(Result)); end calculator;
jscparker/math_packages
Ada
13,878
adb
-- Test QR decomposition real valued square matrices. with Ada.Numerics.Generic_elementary_functions; with Givens_QR; with Test_Matrices; With Text_IO; use Text_IO; procedure givens_qr_tst_1 is type Real is digits 15; subtype Index is Integer range 1..137; -- in this test, matrix is a square-shaped matrix on Index x Index. -- eg Hilbert's matrix is a square matrix with unique elements on the range -- Index'First .. Index'Last. However, you have the option to QR any rectangular -- sub-block of the matrix that is defined on Index x Index (provided -- number of rows is >= number of cols). -- To do that you choose new values for Starting_Row, Starting_Col, Final_Row -- Final_Col just below. subtype Row_Index is Index; subtype Col_Index is Index; Starting_Row : constant Row_Index := Index'First + 0; Starting_Col : constant Col_Index := Index'First + 0; Final_Row : constant Row_Index := Index'Last- 0; Final_Col : constant Col_Index := Index'Last- 0; type Matrix is array(Row_Index, Col_Index) of Real; --pragma Convention (Fortran, Matrix); --No! This QR prefers Ada convention. package math is new Ada.Numerics.Generic_Elementary_Functions (Real); use math; package QR is new Givens_QR (Real => Real, R_Index => Index, C_Index => Index, A_Matrix => Matrix); use QR; -- QR exports Row_Vector and Col_Vector package Make_Square_Matrix is new test_matrices (Real, Index, Matrix); use Make_Square_Matrix; package rio is new Float_IO(Real); use rio; --subtype Real_Extended is Real; -- general case, and for best speed type Real_Extended is digits 18; -- 18 ok on intel Zero : constant Real := +0.0; One : constant Real := +1.0; Two : constant Real := +2.0; A, R : Matrix; Q : Q_Matrix; Max_Error : Real; Frobenius_QR_Err_0 : Real; Max_Error_qq, Max_Error_qr : Real; Frobenius_QQ_Err, Frobenius_QR_Err : Real; Scale : Col_Vector; Permute : Permutation; -------------------- -- Frobenius_Norm -- -------------------- function Frobenius_Norm (A : in Matrix) --Final_Row : in Index; --Final_Col : in Index; --Starting_Row : in Index; --Starting_Col : in Index) return Real is Max_A_Val : Real := Zero; Sum, Scaling, tmp : Real := Zero; begin Max_A_Val := Zero; for Row in Starting_Row .. Final_Row loop for Col in Starting_Col .. Final_Col loop if Max_A_Val < Abs A(Row, Col) then Max_A_Val := Abs A(Row, Col); end if; end loop; end loop; Max_A_Val := Max_A_Val + Two ** (Real'Machine_Emin + 4); Scaling := One / Max_A_Val; Sum := Zero; for Row in Starting_Row .. Final_Row loop for Col in Starting_Col .. Final_Col loop tmp := Scaling * A(Row, Col); Sum := Sum + tmp * tmp; end loop; end loop; return Sqrt (Sum) * Max_A_Val; end Frobenius_Norm; ------------------------------------ -- Get_Error_in_QR_Decomposition -- ------------------------------------ procedure Get_Error_in_QR_Decomposition (A : in Matrix; R : in Matrix; Q : in Q_Matrix; Scale : in Col_Vector; Permute : in Permutation; Max_Error : out Real; Max_Error_F : out Real) is Err : Real; Min_Real : constant Real := 2.0 ** (Real'Machine_Emin + 2); Product_Vector, Col_of_R : Col_Vector := (others => Zero); Err_Matrix : Matrix; begin -- find error in A - Q*R -- The Columns of R have been permuted; unpermute before comparison of A with Q*R -- The Columns of R have been scaled. Before comparison of A with Q*R -- Must unscale each col of R by multiplying them with 1/Scale(Permute(Col). Max_Error := Zero; for Col in Starting_Col .. Final_Col loop Col_of_R := (others => Zero); for Row in Starting_Row .. Final_Row loop Col_of_R(Row) := R(Row, Col); end loop; Product_Vector := Q_x_Col_Vector (Q, Col_of_R); for Row in Starting_Row .. Final_Row loop Err := Abs (A(Row, Permute(Col)) - --Product_Vector(Row) / (Scale(Permute(Col)) + Min_Real)); Product_Vector(Row) / (Scale(Row) + Min_Real)); if Err > Max_Error then Max_Error := Err; end if; Err_Matrix(Row, Col) := Err; end loop; end loop; -- Froebenius norm fractional error = ||Err_Matrix|| / ||M|| Max_Error_F := Frobenius_Norm (Err_Matrix) / (Frobenius_Norm (A) + Min_Real); end Get_Error_in_QR_Decomposition; ------------------------------------ -- Get_Err_in_Reassembled_Q_and_A -- ------------------------------------ -- Get an explicit matrix version of the matrix Q. Call it V. procedure Get_Err_in_Reassembled_Q_and_A (A : in Matrix; R : in Matrix; Q : in Q_Matrix; Scale : in Col_Vector; Permute : in Permutation; Final_Row : in Row_Index; Final_Col : in Col_Index; Starting_Row : in Row_Index; Starting_Col : in Col_Index; Frobenius_QQ_Err : out Real; Frobenius_QR_Err : out Real; Max_Error_QQ : out Real; Max_Error_QR : out Real) is Err, S : Real; Min_Real : constant Real := +2.0 **(Real'Machine_Emin + 4); V, V_tr, Identity, Product_QQ : V_Matrix := (others => (others => Zero)); Sum : Real_Extended; Product_A : Matrix; subtype Row_Index_Subrange is Row_Index range Starting_Row .. Final_Row; begin for r in Row_Index_Subrange loop Identity(r, r) := 1.0; end loop; -- Find error in I - V*V' etc. -- Start V as identity matrix (V should be square. MxM == R_Index x R_Index) -- Turn V into and explicit version of Q by calling Q_x_V_Matrix -- (Q is an array of 2x2 rotation matrices.) V := Identity; Q_x_V_Matrix (Q, V); -- Turn V_tr into and explicit version of Q_tr by calling Q_trans..x_V_Matrix V_tr := Identity; Q_transpose_x_V_Matrix (Q, V_tr); -- Usually find that orthonormality of *Rows of V* and *Cols of V_tr* is best. -- Notation: V' == V_tr == transpose of V. for Col in Row_Index_Subrange loop for Row in Row_Index_Subrange loop Sum := 0.0; for j in Row_Index_Subrange loop --Sum := Sum + Real_Extended(V(j, Row)) * Real_Extended(V(j, Col)); --V'*V Sum := Sum + Real_Extended(V(Row, j)) * Real_Extended(V(Col, j)); --V*V' --Sum := Sum + V(Row, j) * V(Col, j); --V*V' has least err; rows of Q ortho --Sum := Sum + V_tr(j, Row)*V_tr(j, Col); --V_tr'*V_tr also least err; cols V_tr --Sum := Sum + V(Row, j) * V_tr(j, Col); --least err; --Sum := Sum + V_tr(Row, j) * V(j, Col); end loop; Product_QQ(Row, Col) := Real (Sum); end loop; end loop; -- get Product_QQ - Identity Max_Error_QQ := Zero; for Col in Row_Index_Subrange loop for Row in Row_Index_Subrange loop Err := Abs (Identity(Row, Col) - Product_QQ(Row, Col)); if Err > Max_Error_QQ then Max_Error_QQ := Err; end if; end loop; end loop; -- Get Frobenius norm of: Product_QQ - I: S := Zero; for Col in Row_Index_Subrange loop for Row in Row_Index_Subrange loop Err := Identity(Row, Col) - Product_QQ(Row, Col); S := S + Err * Err; end loop; end loop; Frobenius_QQ_Err := Sqrt(S) / Sqrt (-Real(Starting_Row) + Real(Final_Row) + 1.0); -- explicitly calculate Q*R by getting V*R == Q*R (V==Q). for Col in Starting_Col .. Final_Col loop for Row in Starting_Row .. Final_Row loop Sum := 0.0; for j in Starting_Row .. Final_Row loop Sum := Sum + Real_Extended(V(Row, j)) * Real_Extended(R(j, Col)); --V*R end loop; Product_A(Row, Col) := Real (Sum); end loop; end loop; -- recall that the actual decomposition is: A*Scale*Permute = Q*R Max_Error_QR := Zero; for Col in Starting_Col .. Final_Col loop for Row in Starting_Row .. Final_Row loop Err := Abs (A(Row, Permute(Col)) -- - Product_A(Row, Col) / (Scale(Permute(Col)) + Min_Real)); -- Scale > 0 - Product_A(Row, Col) / (Scale(Row) + Min_Real)); -- Scale > 0 if Err > Max_Error_QR then Max_Error_QR := Err; end if; end loop; end loop; -- resuse array Product_A to get error matrix Error := Product_A - A: for Col in Starting_Col .. Final_Col loop for Row in Starting_Row .. Final_Row loop Product_A(Row, Col) := A(Row, Permute(Col)) -- - Product_A(Row, Col) / (Scale(Permute(Col)) + Min_Real); -- Scale > 0 - Product_A(Row, Col) / (Scale(Row) + Min_Real); -- Scale > 0 end loop; end loop; Frobenius_QR_Err := Frobenius_Norm (Product_A) / (Frobenius_Norm (A) + Min_Real); end Get_Err_in_Reassembled_Q_and_A; ----------- -- Pause -- ----------- procedure Pause (s0,s1,s2,s3,s4,s5,s6,s7,s8,s9,s10,s11,s12 : string := "") is Continue : Character := ' '; begin New_Line; if S0 /= "" then put_line (S0); end if; if S1 /= "" then put_line (S1); end if; if S2 /= "" then put_line (S2); end if; if S3 /= "" then put_line (S3); end if; if S4 /= "" then put_line (S4); end if; if S5 /= "" then put_line (S5); end if; if S6 /= "" then put_line (S6); end if; if S7 /= "" then put_line (S7); end if; if S8 /= "" then put_line (S8); end if; if S9 /= "" then put_line (S9); end if; if S10 /= "" then put_line (S10); end if; if S11 /= "" then put_line (S11); end if; if S12 /= "" then put_line (S12); end if; new_line; begin Put ("Enter a character to continue: "); Get_Immediate (Continue); exception when others => null; end; end pause; begin Pause( "Test 1: QR decomposition of matrix A. The QR decomposition of A is", "successful if two identities are satisfied: Q'*Q = I and Q*R = A. If 15", "digit Reals are used, then we expect the error in the calculation of A = Q*R to", "be about 1 part in 10**15. In other words ||Q*R - A|| / ||A|| should be", "around 10**(-15). Here ||*|| denotes the Frobenius Norm. Other matrix norms", "give slightly different answers, so its an order of magnitude estimate. The", "Q matrix is a list of 2x2 Givens rotations. Most operations (eg. equation", "solving) use this representation of Q for best accuracy.", " ", "The tests are repeated using an explicit matrix for Q. The error in the", "QR decomposition of A, i.e. ||Q*R - A|| / ||A|| is recalculated and printed", "below so that you can see the increase in error." ); for Chosen_Matrix in Matrix_Id loop --for Chosen_Matrix in kahan .. kahan loop --for Chosen_Matrix in kahan_col_scaled_2 .. kahan_col_scaled_2 loop --for Chosen_Matrix in kahan .. kahan_col_scaled_2 loop --for Chosen_Matrix in kahan .. kahan_row_scaled loop Init_Matrix (A, Chosen_Matrix, Index'First, Index'Last); R := A; -- A remains original A. Only R is input. QR_Decompose (A => R, -- A has now been tranformed into the R matrix Q => Q, Row_Scalings => Scale, Col_Permutation => Permute, Final_Row => Final_Row, Final_Col => Final_Col, Starting_Row => Starting_Row, Starting_Col => Starting_Col); --declare Row : Row_Index := Starting_Row; begin --for Col in Starting_Col .. Final_Col loop --put(R(Col, Col)); -- this is the R matrix but it has not been unscaled yet. --if Row < Row_Index'Last then Row := Row + 1; end if; --end loop; --end; if true then new_line; put("For matrix A of type "); put(Matrix_id'Image(Chosen_Matrix)); put(":"); new_line; put ("Min 3 diag elements:"); --for i in Starting_Col .. Final_Col loop for i in Final_Col-2 .. Final_Col loop put (r(i,i)); end loop; new_line(1); end if; --goto endies; Get_Err_in_Reassembled_Q_and_A (A, R, Q, Scale, Permute, Final_Row, Final_Col, Starting_Row, Starting_Col, Frobenius_QQ_Err, Frobenius_QR_Err, Max_Error_qq, Max_Error_qr); Get_Error_in_QR_Decomposition (A, R, Q, Scale, Permute, Max_Error, Frobenius_QR_Err_0); -- Froebenius norm fractional error: -- Max_Error_F = ||Err_Matrix|| / ||A|| new_line; put("For matrix A of type "); put(Matrix_id'Image(Chosen_Matrix)); put(":"); new_line; put(" Err in I-Q'*Q (Q = explicit matrix) is ||I-Q'*Q|| / ||I|| ="); put(Frobenius_QQ_Err); new_line; put(" Err in A-Q*R (Q = explicit matrix) is ||A-Q*R || / ||A|| ="); put(Frobenius_QR_Err); new_line; put(" Err in A-Q*R (Q = Givens rotation) is ||A-Q*R || / ||A|| ="); put(Frobenius_QR_Err_0); new_line; <<endies>> null; end loop; end givens_qr_tst_1;
DrenfongWong/tkm-rpc
Ada
77
ads
package Tkmrpc.Operation_Handlers.Ees is end Tkmrpc.Operation_Handlers.Ees;
Fabien-Chouteau/lvgl-ada
Ada
9,701
ads
with Lv.Style; with Lv.Objx.Page; with Lv.Objx.Label; package Lv.Objx.Textarea is subtype Instance is Obj_T; Cursor_Last : constant := 16#7FFF#; type Cursor_Type_T is (Cursor_None, Cursor_Line, Cursor_Block, Cursor_Outline, Cursor_Underline, Cursor_Hidden); type Style_T is (Style_Bg, Style_Sb, Style_Cursor); -- Create a text area objects -- @param par pointer to an object, it will be the parent of the new text area -- @param copy pointer to a text area object, if not NULL then the new object will be copied from it -- @return pointer to the created text area function Create (Par : Obj_T; Copy : Instance) return Instance; -- Insert a character to the current cursor position. -- To add a wide char, e.g. 'Á' use `lv_txt_encoded_conv_wc('Á')` -- @param self pointer to a text area object -- @param c a character (e.g. 'a') procedure Add_Char (Self : Instance; C : Uint32_T); -- Insert a text to the current cursor position -- @param self pointer to a text area object -- @param txt a '\0' terminated string to insert procedure Add_Text (Self : Instance; Txt : C_String_Ptr); -- Delete a the left character from the current cursor position -- @param self pointer to a text area object procedure Del_Char (Self : Instance); ---------------------- -- Setter functions -- ---------------------- -- Set the text of a text area -- @param self pointer to a text area -- @param txt pointer to the text procedure Set_Text (Self : Instance; Txt : C_String_Ptr); -- Set the cursor position -- @param obj pointer to a text area object -- @param pos the new cursor position in character index -- < 0 : index from the end of the text -- LV_TA_CURSOR_LAST: go after the last character procedure Set_Cursor_Pos (Self : Instance; Pos : Int16_T); -- Set the cursor type. -- @param self pointer to a text area object -- @param cur_type: element of 'lv_cursor_type_t' procedure Set_Cursor_Type (Self : Instance; Cur_Type : Cursor_Type_T); -- Enable/Disable password mode -- @param self pointer to a text area object -- @param pwd_en true: enable, false: disable procedure Set_Pwd_Mode (Self : Instance; Pwd_En : U_Bool); -- Configure the text area to one line or back to normal -- @param self pointer to a Text area object -- @param en true: one line, false: normal procedure Set_One_Line (Self : Instance; En : U_Bool); -- Set the alignment of the text area. -- In one line mode the text can be scrolled only with `LV_LABEL_ALIGN_LEFT`. -- This function should be called if the size of text area changes. -- @param self pointer to a text are object -- @param align the desired alignment from `lv_label_align_t`. (LV_LABEL_ALIGN_LEFT/CENTER/RIGHT) procedure Set_Text_Align (Self : Instance; Align : Label.Align_T); -- Set a list of characters. Only these characters will be accepted by the text area -- @param self pointer to Text Area -- @param list list of characters. Only the pointer is saved. E.g. "+-.,0123456789" procedure Set_Accepted_Chars (Self : Instance; List : C_String_Ptr); -- Set max length of a Text Area. -- @param self pointer to Text Area -- @param num the maximal number of characters can be added (`lv_ta_set_text` ignores it) procedure Set_Max_Length (Self : Instance; Num : Uint16_T); -- Set an action to call when the Text area is clicked -- @param self pointer to a Text area -- @param action a function pointer procedure Set_Action (Self : Instance; Action : Action_Func_T); -- Set the scroll bar mode of a text area -- @param self pointer to a text area object -- @param sb_mode the new mode from 'lv_page_sb_mode_t' enum procedure Set_Sb_Mode (Self : Instance; Mode : Page.Mode_T); -- Set a style of a text area -- @param self pointer to a text area object -- @param type which style should be set -- @param style pointer to a style procedure Set_Style (Self : Instance; Type_P : Style_T; Style : Lv.Style.Style); ---------------------- -- Getter functions -- ---------------------- -- Get the text of a text area. In password mode it gives the real text (not '*'s). -- @param self pointer to a text area object -- @return pointer to the text function Text (Self : Instance) return C_String_Ptr; -- Get the label of a text area -- @param self pointer to a text area object -- @return pointer to the label object function Label (Self : Instance) return Label.Instance; -- Get the current cursor position in character index -- @param self pointer to a text area object -- @return the cursor position function Cursor_Pos (Self : Instance) return Uint16_T; -- Get the current cursor visibility. -- @param self pointer to a text area object -- @return true: the cursor is drawn, false: the cursor is hidden function Cursor_Show (Self : Instance) return U_Bool; -- Get the current cursor type. -- @param self pointer to a text area object -- @return element of 'lv_cursor_type_t' function Cursor_Type (Self : Instance) return Cursor_Type_T; -- Get the password mode attribute -- @param self pointer to a text area object -- @return true: password mode is enabled, false: disabled function Pwd_Mode (Self : Instance) return U_Bool; -- Get the one line configuration attribute -- @param self pointer to a text area object -- @return true: one line configuration is enabled, false: disabled function One_Line (Self : Instance) return U_Bool; -- Get a list of accepted characters. -- @param self pointer to Text Area -- @return list of accented characters. function Accepted_Chars (Self : Instance) return C_String_Ptr; -- Set max length of a Text Area. -- @param self pointer to Text Area -- @return the maximal number of characters to be add function Max_Length (Self : Instance) return Uint16_T; -- Set an action to call when the Text area is clicked -- @param self pointer to a Text area -- @param action a function pointer function Action (Self : Instance) return Action_Func_T; -- Get the scroll bar mode of a text area -- @param self pointer to a text area object -- @return scrollbar mode from 'lv_page_sb_mode_t' enum function Sb_Mode (Self : Instance) return Page.Mode_T; -- Get a style of a text area -- @param self pointer to a text area object -- @param type which style should be get -- @return style pointer to a style function Style (Self : Instance; Type_P : Style_T) return Lv.Style.Style; -- Move the cursor one character right -- @param self pointer to a text area object procedure Cursor_Right (Self : Instance); -- Move the cursor one character left -- @param self pointer to a text area object procedure Cursor_Left (Self : Instance); -- Move the cursor one line down -- @param self pointer to a text area object procedure Cursor_Down (Self : Instance); -- Move the cursor one line up -- @param self pointer to a text area object procedure Cursor_Up (Self : Instance); ------------- -- Imports -- ------------- pragma Import (C, Create, "lv_ta_create"); pragma Import (C, Add_Char, "lv_ta_add_char"); pragma Import (C, Add_Text, "lv_ta_add_text"); pragma Import (C, Del_Char, "lv_ta_del_char"); pragma Import (C, Set_Text, "lv_ta_set_text"); pragma Import (C, Set_Cursor_Pos, "lv_ta_set_cursor_pos"); pragma Import (C, Set_Cursor_Type, "lv_ta_set_cursor_type"); pragma Import (C, Set_Pwd_Mode, "lv_ta_set_pwd_mode"); pragma Import (C, Set_One_Line, "lv_ta_set_one_line"); pragma Import (C, Set_Text_Align, "lv_ta_set_text_align"); pragma Import (C, Set_Accepted_Chars, "lv_ta_set_accepted_chars"); pragma Import (C, Set_Max_Length, "lv_ta_set_max_length"); pragma Import (C, Set_Action, "lv_ta_set_action_inline"); pragma Import (C, Set_Sb_Mode, "lv_ta_set_sb_mode_inline"); pragma Import (C, Set_Style, "lv_ta_set_style"); pragma Import (C, Text, "lv_ta_get_text"); pragma Import (C, Label, "lv_ta_get_label"); pragma Import (C, Cursor_Pos, "lv_ta_get_cursor_pos"); pragma Import (C, Cursor_Show, "lv_ta_get_cursor_show"); pragma Import (C, Cursor_Type, "lv_ta_get_cursor_type"); pragma Import (C, Pwd_Mode, "lv_ta_get_pwd_mode"); pragma Import (C, One_Line, "lv_ta_get_one_line"); pragma Import (C, Accepted_Chars, "lv_ta_get_accepted_chars"); pragma Import (C, Max_Length, "lv_ta_get_max_length"); pragma Import (C, Action, "lv_ta_get_action_inline"); pragma Import (C, Sb_Mode, "lv_ta_get_sb_mode_inline"); pragma Import (C, Style, "lv_ta_get_style"); pragma Import (C, Cursor_Right, "lv_ta_cursor_right"); pragma Import (C, Cursor_Left, "lv_ta_cursor_left"); pragma Import (C, Cursor_Down, "lv_ta_cursor_down"); pragma Import (C, Cursor_Up, "lv_ta_cursor_up"); for Cursor_Type_T'Size use 8; for Cursor_Type_T use (Cursor_None => 0, Cursor_Line => 1, Cursor_Block => 2, Cursor_Outline => 3, Cursor_Underline => 4, Cursor_Hidden => 8); for Style_T'Size use 8; for Style_T use (Style_Bg => 0, Style_Sb => 1, Style_Cursor => 2); end Lv.Objx.Textarea;
zhmu/ananas
Ada
4,844
ads
------------------------------------------------------------------------------ -- -- -- GNAT COMPILER COMPONENTS -- -- -- -- E X P _ S E L -- -- -- -- S p e c -- -- -- -- Copyright (C) 1992-2022, Free Software Foundation, Inc. -- -- -- -- GNAT is free software; you can redistribute it and/or modify it under -- -- terms of the GNU General Public License as published by the Free Soft- -- -- ware Foundation; either version 3, or (at your option) any later ver- -- -- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -- -- for more details. You should have received a copy of the GNU General -- -- Public License distributed with GNAT; see file COPYING3. If not, go to -- -- http://www.gnu.org/licenses for a complete copy of the license. -- -- -- -- GNAT was originally developed by the GNAT team at New York University. -- -- Extensive contributions were provided by Ada Core Technologies Inc. -- -- -- ------------------------------------------------------------------------------ -- Routines used in Chapter 9 for the expansion of dispatching triggers in -- select statements (Ada 2005: AI-345) with Types; use Types; package Exp_Sel is function Build_Abort_Block (Loc : Source_Ptr; Abr_Blk_Ent : Entity_Id; Cln_Blk_Ent : Entity_Id; Blk : Node_Id) return Node_Id; -- Generate: -- begin -- Blk -- exception -- when Abort_Signal => null; -- end; -- Abr_Blk_Ent is the name of the generated block, Cln_Blk_Ent is the name -- of the encapsulated cleanup block, Blk is the actual block name. -- The exception handler code is built by Build_Abort_Block_Handler. function Build_Abort_Block_Handler (Loc : Source_Ptr) return Node_Id; -- Generate: -- when others => -- null; -- This is an exception handler to stop propagation of aborts, without -- modifying the deferral level. function Build_B (Loc : Source_Ptr; Decls : List_Id) return Entity_Id; -- Generate: -- B : Boolean := False; -- Append the object declaration to the list and return its defining -- identifier. function Build_C (Loc : Source_Ptr; Decls : List_Id) return Entity_Id; -- Generate: -- C : Ada.Tags.Prim_Op_Kind; -- Append the object declaration to the list and return its defining -- identifier. function Build_Cleanup_Block (Loc : Source_Ptr; Blk_Ent : Entity_Id; Stmts : List_Id; Clean_Ent : Entity_Id) return Node_Id; -- Generate: -- declare -- procedure _clean is -- begin -- ... -- end _clean; -- begin -- Stmts -- at end -- _clean; -- end; -- Blk_Ent is the name of the generated block, Stmts is the list of -- encapsulated statements and Clean_Ent is the parameter to the -- _clean procedure. function Build_K (Loc : Source_Ptr; Decls : List_Id; Obj : Entity_Id) return Entity_Id; -- Generate -- K : Ada.Tags.Tagged_Kind := -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (Obj)); -- where Obj is the pointer to a secondary table. Append the object -- declaration to the list and return its defining identifier. function Build_S (Loc : Source_Ptr; Decls : List_Id) return Entity_Id; -- Generate: -- S : Integer; -- Append the object declaration to the list and return its defining -- identifier. function Build_S_Assignment (Loc : Source_Ptr; S : Entity_Id; Obj : Entity_Id; Call_Ent : Entity_Id) return Node_Id; -- Generate: -- S := Ada.Tags.Get_Offset_Index ( -- Ada.Tags.Tag (Obj), DT_Position (Call_Ent)); -- where Obj is the pointer to a secondary table, Call_Ent is the entity -- of the dispatching call name. Return the generated assignment. end Exp_Sel;
nerilex/ada-util
Ada
4,584
adb
----------------------------------------------------------------------- -- json -- JSON Reader -- Copyright (C) 2010, 2011, 2014 Stephane Carrez -- Written by Stephane Carrez ([email protected]) -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. ----------------------------------------------------------------------- with Ada.Strings.Unbounded; with Ada.Text_IO; with Ada.Command_Line; with Util.Serialize.IO.JSON; with Ada.Containers; with Mapping; with Util.Serialize.Mappers.Vector_Mapper; with Util.Streams.Texts; with Util.Streams.Buffered; procedure Json is use Util.Streams.Buffered; use Ada.Strings.Unbounded; use type Mapping.Person_Access; use type Ada.Containers.Count_Type; Reader : Util.Serialize.IO.JSON.Parser; Count : constant Natural := Ada.Command_Line.Argument_Count; package Person_Vector_Mapper is new Util.Serialize.Mappers.Vector_Mapper (Vectors => Person_Vector, Element_Mapper => Person_Mapper); subtype Person_Vector_Context is Person_Vector_Mapper.Vector_Data; -- Mapping for a list of Person records (stored as a Vector). Person_Vector_Mapping : aliased Person_Vector_Mapper.Mapper; procedure Print (P : in Mapping.Person_Vector.Cursor); procedure Print (P : in Mapping.Person); procedure Print (P : in Mapping.Person) is begin Ada.Text_IO.Put_Line ("Name : " & To_String (P.Name)); Ada.Text_IO.Put_Line ("first_name : " & To_String (P.First_Name)); Ada.Text_IO.Put_Line ("last_name : " & To_String (P.Last_Name)); Ada.Text_IO.Put_Line ("Age : " & Natural'Image (P.Age)); Ada.Text_IO.Put_Line ("Street : " & To_String (P.Addr.Street)); Ada.Text_IO.Put_Line ("City : " & To_String (P.Addr.City)); Ada.Text_IO.Put_Line ("Zip : " & Natural'Image (P.Addr.Zip)); Ada.Text_IO.Put_Line ("Country : " & To_String (P.Addr.Country)); Ada.Text_IO.Put_Line ("Info : " & To_String (P.Addr.Info.Name) & "=" & To_String (P.Addr.Info.Value)); end Print; procedure Print (P : in Mapping.Person_Vector.Cursor) is begin Print (Mapping.Person_Vector.Element (P)); end Print; begin if Count = 0 then Ada.Text_IO.Put_Line ("Usage: json file..."); return; end if; Person_Vector_Mapping.Set_Mapping (Mapping.Get_Person_Mapper); Reader.Add_Mapping ("/list", Mapping.Get_Person_Vector_Mapper.all'Access); Reader.Add_Mapping ("/person", Mapping.Get_Person_Mapper.all'Access); for I in 1 .. Count loop declare S : constant String := Ada.Command_Line.Argument (I); List : aliased Mapping.Person_Vector.Vector; P : aliased Mapping.Person; begin Mapping.Person_Vector_Mapper.Set_Context (Reader, List'Unchecked_Access); Mapping.Person_Mapper.Set_Context (Reader, P'Unchecked_Access); Reader.Parse (S); -- The list now contains our elements. List.Iterate (Process => Print'Access); if List.Length = 0 then Print (P); end if; declare Output : Util.Serialize.IO.JSON.Output_Stream; begin Output.Initialize (Size => 10000); Mapping.Get_Person_Mapper.Write (Output, P); Ada.Text_IO.Put_Line ("Person: " & Util.Streams.Texts.To_String (Buffered_Stream (Output))); end; declare Output : Util.Serialize.IO.JSON.Output_Stream; begin Output.Initialize (Size => 10000); Output.Write ("{""list"":"); Mapping.Get_Person_Vector_Mapper.Write (Output, List); Output.Write ("}"); Ada.Text_IO.Put_Line ("IO:"); Ada.Text_IO.Put_Line (Util.Streams.Texts.To_String (Buffered_Stream (Output))); end; end; end loop; end Json;
SSOCsoft/Log_Reporter
Ada
42,127
adb
with --NSO.Helpers, NSO.Types, Interfaces, Ada.Strings.Unbounded, Ada.Characters.Latin_1, Ada.Tags.Generic_Dispatching_Constructor, Ada.Characters.Conversions; with Ada.Containers; -- NSO.Types; Package Body NSO.JSON is use Ada.Characters.Conversions, Ada.Characters; Procedure Apply( Object : in Instance'Class ) is Begin if Object in Null_Object then On_Null; elsif Object in True_Object or Object in False_Object then On_Boolean( Object in True_Object ); elsif Object in String_Object then On_String( String_Object(Object).Element.Element ); elsif Object in Number_Object then On_Number( Number_Object(Object).Element ); elsif Object in Array_Object then Declare Procedure Operate( Cursor : Value_Array.Cursor ) is Idx : Natural renames Value_Array.To_Index(Cursor); Val : Instance'Class renames Value_Array.Element(Cursor); Begin On_Array( Idx, Val ); End Operate; Begin Array_Object(Object).Element.Iterate( Operate'Access ); End; elsif Object in Object_Object then Declare Procedure Operate( Cursor : Name_Value_Pairs.Cursor ) is Key : String renames Name_Value_Pairs.Key(Cursor); Val : Instance'Class renames Name_Value_Pairs.Element(Cursor); Begin On_Object( Key, Val ); End Operate; Begin Object_Object(Object).Element.Iterate( Operate'Access ); End; end if; End Apply; Subtype ASCII_Control_Character is Character with Static_Predicate => ASCII_Control_Character in Latin_1.NUL..Latin_1.US|Latin_1.DEL; Subtype ISO_6429_Control_Character is Character with Static_Predicate => ISO_6429_Control_Character in Latin_1.Reserved_128..Latin_1.APC; Subtype Whitespace is Character with Static_Predicate => Whitespace in Latin_1.HT|Latin_1.Space|Latin_1.No_Break_Space; Subtype Control_Character is Character with Static_Predicate => Control_Character in ASCII_Control_Character | ISO_6429_Control_Character; Package Constructors is Use Ada.Streams, NSO.Types; -- Use Ada.Strings.Unbounded; Type Parameter( Stream : not null access Root_Stream_Class ) is record -- Stream : --not null access NSO.Types.Root_Stream_Class; -- not null access Ada.Streams.Root_Stream_Type'Class; Buffer : Nullable_Character := Null; --Unbounded_String := To_Unbounded_String(""); end record; -- Type Parameter is record -- Stream : --not null access NSO.Types.Root_Stream_Class; -- not null access Ada.Streams.Root_Stream_Type'Class; -- Buffer : Nullable_Character := Null; -- --Unbounded_String := To_Unbounded_String(""); -- end record; Function Expect( C : Character; From : not null access Parameter ) return Boolean is (if From.Buffer /= Null then From.Buffer.All = C) with Inline; Function Expect( S : String; From : not null access Parameter ) return Boolean is (for some C of S => Expect(C, From)) with Inline; -- Function Expect( S : String; From : not null access Parameter ) return Character -- with Inline; function Constructor (Params : not null access Parameter) return Null_Object with Pre => Expect( 'n', Params ); function Constructor (Params : not null access Parameter) return False_Object with Pre => Expect( 'f', Params ); function Constructor (Params : not null access Parameter) return True_Object with Pre => Expect( 't', Params ); function Constructor (Params : not null access Parameter) return String_Object with Pre => Expect( '"', Params ); function Constructor (Params : not null access Parameter) return Number_Object with Pre => Expect( "-0123456789", Params ); function Constructor (Params : not null access Parameter) return Array_Object with Pre => Expect( '[', Params ); function Constructor (Params : not null access Parameter) return Object_Object with Pre => Expect( '{', Params ); -- Generic -- with Function Next( Stream : not null access Ada.Streams.Root_Stream_Type'Class ) return Character is <>; Function Value_Constructor(Stream : not null access Root_Stream_Type'Class) return Instance'Class; Function Value_Constructor(Params : not null access Parameter) return Instance'Class; Private -- Consumes characters from the stream until a non-whitespace character is encountered. Function Consume_Whitespace( Stream : not null access Root_Stream_Type'Class ) return Character with Post => Consume_Whitespace'Result not in Whitespace; Function Consume_Whitespace( P : not null access Parameter ) return Character with Pre => P.Buffer = Null, Post => Consume_Whitespace'Result not in Whitespace; -- This returns the tail of a string. Function "-"( Input : String ) return String is ( Input(Positive'Succ(Input'First)..Input'Last) ) with Inline, Pure_Function; -- Asserts that the next element in the stream is the given character. -- Raises PARSE_ERROR if it does not. Generic Context : Parameter; Function Expect_Character( Element : Character ) return Boolean with Inline; -- Asserts that the next elemente in the stream are those of the given string. -- Raises PARSE_ERROR if it does not. Generic Context : Parameter; Procedure Expect_String( Element : String ) with Inline; -- This function ensures theat the Value is the next item in the stream, -- it accounts for an unused buffer, as well as checks the buffer's own -- content if it is used. Procedure Check (Param : not null access Parameter; Value : String) with Pre => Value'Length in Positive; -- If Params.Buffer is empty, it fills it and returns the result, -- otherwise it simply returns the contents of the buffer. -- -- NOTE: This will not consume current contents of the buffer, but -- may consume a character from the stream. Function Buffer(Params : in out Parameter) Return Character with Inline; Function Buffer(Params : not null access Parameter) Return Character with Inline; End Constructors; Package Body Constructors is Use NSO.Types; Function Next_Character( Stream : not null access Root_Stream_Class ) return Reference_Character is ( New Character'(Character'Input(Stream)) ) with Inline; Function Make_Param( Stream : not null access Ada.Streams.Root_Stream_Type'Class ) return Parameter is Begin Return Result : Constant Parameter := ( Buffer => Next_Character( Stream ), Stream => Stream ); End Make_Param; Function Buffer(Params : not null access Parameter) Return Character is ( Buffer( Params.All ) ); Function Buffer(Params : in out Parameter) Return Character is Empty : Constant Boolean := Params.Buffer = Null; Begin Return Result : Constant Character := (if not Empty then Params.Buffer.All else Consume_Whitespace(Params.Stream)) do if Empty then Params.Buffer := New Character'( Result ); end if; end return; End Buffer; Function Value_Constructor(Params : not null access Parameter) return Instance'Class is -- If Params.Buffer is empty, it fills it and returns the result, -- otherwise it simply returns the contents of the buffer. Function Buffer return Character with Inline is Empty : Constant Boolean := Params.Buffer = Null; Begin Return Result : Constant Character := (if not Empty then Params.Buffer.All else Consume_Whitespace(Params.Stream)) do if Empty then Params.Buffer := New Character'( Result ); end if; end return; End Buffer; C : Character renames Buffer; Begin -- Here we switch on the character in the buffer, constructing the -- appropriate object. Return Result : Constant Instance'Class := (case C is when '{' => Object_Object'(Constructor(Params)), when '[' => Array_Object' (Constructor(Params)), when '0'..'9' | '-' => Number_Object'(Constructor(Params)), when '"' => String_Object'(Constructor(Params)), when 't' => True_Object' (Constructor(Params)), when 'f' => False_Object' (Constructor(Params)), when 'n' => Null_Object' (Constructor(Params)), when others => raise Parse_Error with "'" & C & "' is an invalid character." ); End Value_Constructor; Function Value_Constructor(Stream : not null access Root_Stream_Type'Class) return Instance'Class is use Constructors; Param : Aliased Parameter:= Make_Param( Stream ); C : Character renames Param.Buffer.All; Begin Return Result : Constant Instance'Class := Value_Constructor(Param'Unchecked_Access); -- (case C is -- when '{' => Object_Object'(Constructor(Param'Access)), -- when '[' => Array_Object' (Constructor(Param'Access)), -- when '0'..'9' -- | '-' => Number_Object'(Constructor(Param'Access)), -- when '"' => String_Object'(Constructor(Param'Access)), -- when 't' => True_Object' (Constructor(Param'Access)), -- when 'f' => False_Object' (Constructor(Param'Access)), -- when 'n' => Null_Object' (Constructor(Param'Access)), -- when others => raise Parse_Error -- with "'" & C & "' is an invalid character." -- ); End Value_Constructor; Function Expect_Character( Element : Character ) return Boolean is Item : Character renames Character'Input(Context.Stream); Begin Return Result : Constant Boolean := Item = Element or else raise Parse_Error with "'"&Element&"' expected, but '" &Item& "' found."; End Expect_Character; Procedure Expect_String( Element : String ) is Function Expect is new Expect_Character(Context); Result : Constant Boolean := (for all C of Element => Expect(C)); Begin Null; End Expect_String; Function Consume_Whitespace( Stream : not null access Root_Stream_Type'Class ) return Character is Begin Return Result : Character do Loop Result:= Character'Input( Stream ); exit when Result not in Whitespace; End Loop; End Return; End Consume_Whitespace; Function Consume_Whitespace( P : not null access Parameter ) return Character is (Consume_Whitespace(P.Stream)); -- Begin -- Return Result : Character do -- Loop -- Result:= Character'Input( P.Stream ); -- exit when Result not in Whitespace; -- End Loop; -- End Return; -- End Consume_Whitespace; Procedure Check (Param : not null access Parameter; Value : String) is Procedure Expect is new Expect_String(Param.all); Begin -- Handle the empty-buffer by matching the next non-whitespace -- character with the head of the given string. if Param.Buffer = Null then Declare Element : Character renames Value(Value'First); Item : Character renames Consume_Whitespace(Param); Begin if Element /= Item then Raise Parse_Error with "'"&Element&"' expected, but '" &Item& "' found."; end if; End; -- Handle the tail. Expect( -Value ); -- Handle the case where the buffer matches the head of the string. elsif Param.Buffer.All = Value(Value'First) then -- Handle the tail. Expect( -Value ); else -- Buffer not the expected value. Raise Parse_Error with "'"& Value(Value'First) &"' expected, but '" & Param.Buffer.All & "' found."; end if; End Check; function Constructor (Params : not null access Parameter) return Null_Object is Procedure Expect is new Expect_String(Params.all); Begin Return Result : Constant Null_Object := (Value_Type => VK_Null) do Check( Params, "null" ); End return; End Constructor; function Constructor (Params : not null access Parameter) return False_Object is Procedure Expect is new Expect_String(Params.all); Begin Return Result : Constant False_Object := (Value_Type => VK_False) do Check( Params, "false"); End return; End Constructor; function Constructor (Params : not null access Parameter) return True_Object is Procedure Expect is new Expect_String(Params.all); Begin Return Result : Constant True_Object := (Value_Type => VK_True) do Check( Params, "true"); End return; End Constructor; function Constructor (Params : not null access Parameter) return String_Object is Use Ada.Strings.Unbounded, String_Holder; Working : Unbounded_String := To_Unbounded_String(""); Escape : Boolean := False; Subtype Escape_Character is Character with Static_Predicate => Escape_Character in '"' | '\' | '/' | 'b' | 'f' | 'n' | 'r' | 't' | 'u'; Procedure Append( Item : Character ) with Inline is Begin Append( New_Item => Item, Source => Working ); End Append; Begin Check( Params, (1 => '"') ); Return Result : String_Object := (Value_Type => VK_String, Element => Empty_Holder) do -- Read the string from the stream. READ_STRING: Loop Declare C : Character renames Character'Input( Params.Stream ); Begin -- Here we handle all escapes, except for the hex-code, -- which we will do later, due to it intrinsically being -- referencial to points outside Latin-1. -- NOTE: If we wanted a wholly conformant implementation -- then we need a string-form of Unicode. if Escape then Escape:= False; case Escape_Character'(C) is when '"' => Append( Latin_1.Quotation ); when '\' => Append( Latin_1.Reverse_Solidus ); when '/' => Append( Latin_1.Solidus ); when 'b' => Append( Latin_1.BS ); when 'f' => Append( Latin_1.FF ); when 'n' => Append( Latin_1.LF ); when 'r' => Append( Latin_1.CR ); when 't' => Append( Latin_1.HT ); when 'u' => -- Four-hex escape-value next. Append( New_Item => "\u", Source => Working ); end case; elsif C = '\' then Escape:= True; elsif C = '"' then Exit READ_STRING; else Append( C ); end if; End; End Loop READ_STRING; -- Here we handle the hex-value escape-codes; because we use a -- plain Latin-1 string, we have to HANDLE_HEX_ESCAPES: Declare Procedure Hex_Fixup( Item : in out Unbounded_String; Index : in Positive ) with Pre => Index in 1..Length(Working)-4 is Low : Constant Positive := Index+2; High : Constant Positive := Index+5; Hex_Value : String renames Slice(Working, Low, High); Chr_Value : Interfaces.Unsigned_32 renames Interfaces.Unsigned_32'Value("16#"& Hex_Value &'#'); Temp : Constant Wide_Wide_Character := Wide_Wide_Character'Val( Chr_Value ); Ch : Character renames To_Character(Temp,Latin_1.NUL); Begin if Is_Character( Temp ) then -- Replace the slash. Replace_Element(Item, Index, Ch); -- Delete the remaining escape sequence. Delete(Item, Positive'Pred(Low), High); else -- Delete the entire sequence. Delete(Item, Index, High); end if; End Hex_Fixup; Index : Natural:= Natural'First; Begin HEX_LOOP: Loop Index:= Ada.Strings.Unbounded.Index(Working, "\u"); Exit HEX_LOOP when Index not in Positive; Hex_Fixup( Working, Index ); End Loop HEX_LOOP; End HANDLE_HEX_ESCAPES; Result.Element.Replace_Element( To_String(Working) ); End return; End Constructor; function Constructor (Params : not null access Parameter) return Number_Object is Function Next return Character is (Character'Input( Params.Stream )) with Inline; Function Leading_0( Is_Negative : Boolean ) return Boolean; Generic Terminator : in out Character; Function Digit_Sequence return String; Function Get_Fraction return String; Function Get_Exponent return String; Subtype Digit is Character range '0'..'9'; Subtype Number_Character is Character with Static_Predicate => Number_Character in Digit|'+'|'-'|'.'|'e'|'E'; Subtype Digit_1_to_9 is Digit range '1'..'9'; Function Leading_0( Is_Negative : Boolean ) return Boolean is Item : Character renames Params.Buffer.All; Begin if Is_Negative then Item:= Next; end if; if Item not in Digit then Raise Parse_Error with "Digit expected, but '"& Item &"' found."; end if; Return Item = '0'; End Leading_0; Function Digit_Sequence return String is C : Character renames Next; Begin if C not in Digit then Terminator:= C; Return ""; else Return C & Digit_Sequence; end if; End Digit_Sequence; Negative : Constant Boolean := Buffer(Params) = '-'; C : Character renames Params.Buffer.All; Lead_0 : Boolean renames Leading_0(Negative); Function Sequence is new Digit_Sequence( C ); Function Get_Exponent return String is (if C not in 'e'|'E' then Raise Parse_Error with "'E' or 'e' expected, but '"& C &"' found." else 'E' & Sequence ); Function Get_Fraction return String is (if C /= '.' then Raise Parse_Error with "'.' expected, but '"& C &"' found." else '.' & Sequence ); Function Get_Tail return String is (case Number_Character'(C) is when 'e' | 'E' => Get_Exponent, when '.' => Get_Fraction & Get_Tail, when others => "" ); -- Buffer : Character renames Params.Buffer.All; -- Begin -- if Buffer = '.' then -- declare -- Fraction : String renames Get_Fraction; -- begin -- Return Fraction & -- (if Buffer not in 'e'|'E' then "" else Get_Exponent); -- end; -- elsif Buffer in 'e' | 'E' then -- Return Get_Exponent; -- else -- Return ""; -- end if; -- End Get_Tail; Function Get_Head return String is (if Leading_0(Negative) then "0" else C & Sequence); Begin Return Result : Number_Object := (Value_Type => VK_Number, Element => 0.0) do Declare Head : String renames Get_Head; Tail : String renames Get_Tail; Begin Result.Element:= Number'Value( Head & Tail ); End; End return; End Constructor; -- (raise Program_Error with "Unilplemented."); function Constructor (Params : not null access Parameter) return Array_Object is use Value_Array; Function Next(P : not null access Root_Stream_Type'Class:= Params.Stream) return Character renames Consume_Whitespace; Begin Check( Params, (1 => '[') ); Return Result : Array_Object := (Value_Type => VK_Array, Element => Empty_Vector) do -- Read a comma-separated list of name-value paris separated with colon. READ_VALUE: Loop Declare P : Aliased Parameter := (Buffer => New Character'(Next), Stream => Params.Stream); C : Character renames P.Buffer.All; Function Value(Params : not null access Parameter := P'Access) return Instance'class renames Value_Constructor; Begin Case C is -- Here we need to contend with the array ending. -- (Esp. a possibly empty array.) when ']' => exit READ_VALUE; -- Here we handle a separator by re-starting the read, -- discarding the comma from the stream. when ',' => Null; -- At this point, we have ensured that no non-value -- characters are in the stream, and may now get the -- actual value. when Others => Result.Element.Append( Value ); end case; End; End Loop READ_VALUE; End return; End Constructor; function Constructor (Params : not null access Parameter) return Object_Object is use Name_Value_Pairs; Function Next(P : not null access Root_Stream_Type'Class:= Params.Stream) return Character renames Consume_Whitespace; Begin Check( Params, (1 => '{') ); Return Result : Object_Object := (Value_Type => VK_Object, Element => Empty_Map) do -- Read a comma-separated list of values. READ_NAME_VALUE_PAIR: Loop Declare P : Aliased Parameter := (Buffer => New Character'(Next), Stream => Params.Stream); C : Character renames P.Buffer.All; Function Value(Params : not null access Parameter := P'Access) return Instance'class renames Value_Constructor; Begin Case C is -- Here we need to contend with the array ending. -- (Esp. a possibly empty array.) when '}' => exit READ_NAME_VALUE_PAIR; -- Here we handle a separator by re-starting the read, -- discarding the comma from the stream. when ',' => Null; -- At this point, we have ensured sequence-marker -- characters have been handled. -- actual value. when '"' => READ_NAME: Declare String_Value : Constant String_Object := Constructor( P'Access ); Name : String renames String_Value.Element.Element; Begin C:= Next(Params.Stream); if C /= ':' then raise Parse_Error with "':' expected, but '" &C& "' found."; else P.Buffer:= Null; end if; READ_VALUE: Declare Value : Instance'Class renames JSON_Class_Input( P.Stream ); Begin Result.Element.Include( Name, Value ); End READ_VALUE; End READ_NAME; when others => Raise Parse_Error with "'"& '"' &"' expected, but '" & C & "' found."; end case; End; End Loop READ_NAME_VALUE_PAIR; end return; End Constructor; -- (raise Program_Error with "Unilplemented."); End Constructors; -- generic -- type T (<>) is abstract tagged limited private; -- type Parameters (<>) is limited private; -- with function Constructor (Params : not null access Parameters) return T -- is abstract; -- function Ada.Tags.Generic_Dispatching_Constructor -- (The_Tag : Tag; -- Params : not null access Parameters) return T'Class; ------------ -- NULL -- ------------ Function "-"(Object : Null_Object) return String is ("null"); Function Value(Object : Null_Object) return Wide_String is ("null"); Overriding Function Kind(Object : Null_Object) return Value_Kind is (Object.Value_Type); ------------- -- FALSE -- ------------- Function "-"(Object : False_Object) return String is ("false"); Function Value( Object : False_Object ) return Boolean is (False); Function Value(Object : False_Object) return Wide_String is ("false"); Overriding Function Kind(Object : False_Object) return Value_Kind is (Object.Value_Type); ------------ -- TRUE -- ------------ Function "-"(Object : True_Object) return String is ("true"); Function Value( Object : True_Object ) return Boolean is (True); Function Value(Object : True_Object) return Wide_String is ("true"); Overriding Function Kind(Object : True_Object) return Value_Kind is (Object.Value_Type); -------------- -- STRING -- -------------- Function "-"(Object : String_Object) return String is (Object.Element.Element); Function Value(Object : String_Object) return Wide_Wide_String is ( "IMPLEMENT ME"); --Object.Element.Element ); Overriding Function Kind(Object : String_Object) return Value_Kind is (Object.Value_Type); -------------- -- NUMBER -- -------------- Function "-"(Object : Number_Object) return String is Image : String renames Number'Image( Object.Element ); First : Constant Positive:= Image'First; Blank : Constant Boolean:= Image(First) = ' '; Begin Return (if not Blank then Image else Image(Positive'Succ(First)..Image'Last) ); End "-"; Function Value(Object : Number_Object) return Number is (Object.Element); Overriding Function Kind(Object : Number_Object) return Value_Kind is (Object.Value_Type); ------------- -- ARRAY -- ------------- Function "-"(Object : Array_Object) return String is Use Ada.Strings.Unbounded; Function As_String( List : Value_Array.Vector ) return Unbounded_String is Begin Return Result : Unbounded_String := To_Unbounded_String("") do Declare Last : Value_Array.Extended_Index renames List.Last_Index; Procedure Get_Strings( Cursor : Value_Array.Cursor ) is Use Value_Array; Item : Instance'Class renames Element(Cursor); Value : String renames "-"( Item ); Finished : Constant Boolean := To_Index(Cursor) = Last; Begin Append(New_Item => Value, Source => Result); if not Finished then Append(New_Item => ',', Source => Result); end if; End Get_Strings; Begin List.Iterate( Get_Strings'Access ); End; End return; End As_String; Begin Return '[' & To_String(As_String(Object.Element)) & ']'; End; Procedure Append ( Object : in out Array_Object; Value : Instance'Class ) is Begin Object.Element.Append( Value ); End Append; Procedure Prepend( Object : in out Array_Object; Value : Instance'Class ) is Begin Object.Element.Prepend( Value ); End Prepend; Function Value(Object : Array_Object) return Value_Array.Vector is (Object.Element); Overriding Function Kind(Object : Array_Object) return Value_Kind is (Object.Value_Type); -------------- -- OBJECT -- -------------- Function "-"(Object : Object_Object) return String is Use Ada.Strings.Unbounded; Function As_String( List : Name_Value_Pairs.Map ) return Unbounded_String is Begin Return Result : Unbounded_String := To_Unbounded_String("") do if Integer(List.Length) not in Positive then return; end if; Declare Last_Key : String renames List.Last_Key; Procedure Get_Strings( Cursor : Name_Value_Pairs.Cursor ) is Package NVP renames Name_Value_Pairs; Key : String renames NVP.Key( Cursor ); Value : Instance'Class renames NVP.Element(Cursor); Finished : Constant Boolean := Key = Last_Key; Begin Append(New_Item => Key, Source => Result); Append(New_Item => ':', Source => Result); Append(New_Item => -Value, Source => Result); if not Finished then Append(New_Item => ',', Source => Result); end if; End Get_Strings; Begin List.Iterate( Get_Strings'Access ); End; End return; End As_String; Begin Return '{' & To_String(As_String(Object.Element)) & '}'; End "-"; Function Value(Object : Object_Object) return Name_Value_Pairs.Map is (Object.Element); Function Value( Object : Object_Object; Name : String ) return Instance'Class is ( Object.Element( Name ) ); -- ( Object.Element( To_Wide_Wide_String(Name) ) ); -- Function Value( Object : Object_Object; Name : String_Object ) return Instance is -- ( Object.Element(Name.Value) ); Generic Type A_Type(<>) is private; with Function Make( X : A_Type ) Return Instance'Class is <>; Procedure Generic_Value(Object : in out Object_Object; Name : String; Value : A_Type ) with Inline; Procedure Generic_Value(Object : in out Object_Object; Name : String; Value : A_Type ) is Begin Object.Element.Include( New_Item => Make( Value ), Key => Name ); End Generic_Value; Function Make_Integer( X : Integer ) return Instance'Class is ( Make( Number(X) ) ); Function Make_Float( X : Float ) return Instance'Class is ( Make( Number(X) ) ); Procedure Value_Instance is new Generic_Value( Integer, Make_Integer ); Procedure Value_Instance is new Generic_Value( Float, Make_Float ); Procedure Value_Instance is new Generic_Value( Boolean ); Procedure Value_Instance is new Generic_Value( String ); Procedure Value_Instance is new Generic_Value( Number ); Procedure Value(Object : in out Object_Object; Name : String; Value : Boolean ) renames Value_Instance; Procedure Value(Object : in out Object_Object; Name : String; Value : Integer ) renames Value_Instance; Procedure Value(Object : in out Object_Object; Name : String; Value : Float ) renames Value_Instance; Procedure Value(Object : in out Object_Object; Name : String; Value : String ) renames Value_Instance; Procedure Value(Object : in out Object_Object; Name : String; Value : Number ) renames Value_Instance; Procedure Value(Object : in out Object_Object; Name : String; Value : Instance'Class ) is Begin if Object.Element.Contains( Name ) then Object.Element(Name):= Value; else Object.Element.Include( New_Item => Value, Key => Name ); end if; End Value; Overriding Function Kind(Object : Object_Object) return Value_Kind is (Object.Value_Type); ----------------- -- CONVERSIONS -- ----------------- Function "+"(Right : String) return Wide_Wide_String renames To_Wide_Wide_String; Function "+"(Right : Wide_Wide_String) return String_Holder.Holder is ( String_Holder.To_Holder( To_String(Right) ) ); --renames String_Holder.To_Holder; Function "+"(Right : String) return String_Holder.Holder is ( +Wide_Wide_String'(+Right) ) with Inline; ---------- -- MAKE -- ---------- Function Make return Instance'Class is ( Null_Object'(Value_Type => VK_Null) ); Function Make ( Item : String ) return Instance'Class is ( String_Object'(Value_Type => VK_String, Element => +Item) ); Function Make ( Item : Number ) return Instance'Class is ( Number_Object'(Value_Type => VK_Number, Element => Item) ); Function Make ( Item : Boolean ) return Instance'Class is (if Item then True_Object' (Value_Type => VK_True ) else False_Object'(Value_Type => VK_False) ); Function Make_Array( Length : Natural:= 0; Default : Number := 0.0 ) return Instance'Class is Use Ada.Containers; Count : Constant Count_Type:= Count_Type(Length); Value : Constant Number_Object:= Number_Object'(VK_Number, Default ); Function Constructor return Array_Object with Inline is Begin Return Result : Array_Object := Array_Object'(Value_Type => VK_Array, Element => Value_Array.Empty_Vector) do Result.Element.Reserve_Capacity( Count ); Result.Element.Append( Value, Count ); End return; End Constructor; Begin Return Result : Constant Instance'Class := Constructor; End Make_Array; Function Make_Object return Instance'Class is Use Name_Value_Pairs; Begin Return Result : Instance'Class:= Object_Object'( Value_Type => VK_Object, Element => Empty_Map ); End Make_Object; procedure JSON_Class_Output( Stream : not null access Ada.Streams.Root_Stream_Type'Class; Item : in Instance'Class) is Begin null; End JSON_Class_Output; Function JSON_Class_Input (Stream : not null access Ada.Streams.Root_Stream_Type'Class) return Instance'Class --is renames Constructors.Value_Constructor; -- -- Function Next return Character is -- -- Begin -- -- Return Result : Character do -- -- Loop -- -- Result:= Character'Input( Stream ); -- -- Exit when Result not in Whitespace -- -- and Result not in Control_Character; -- -- End Loop; -- -- end return; -- -- End Next; -- Begin -- declare -- Use Constructors; -- Param : Aliased Parameter:= -- Parameter'(Buffer => New Character'(Next), Stream => Stream); -- C : Character renames Param.Buffer.All; -- begin -- Return Result : Instance'Class := -- (case C is -- when '{' => Object_Object'(Constructor(Param'Access)), -- when '[' => Array_Object' (Constructor(Param'Access)), -- when '0'..'9' -- | '-' => Number_Object'(Constructor(Param'Access)), -- when '"' => String_Object'(Constructor(Param'Access)), -- when 't' => True_Object' (Constructor(Param'Access)), -- when 'f' => False_Object' (Constructor(Param'Access)), -- when 'n' => Null_Object' (Constructor(Param'Access)), -- when others => raise Parse_Error -- with "'" & C & "' is an invalid character." -- ); -- end; -- End JSON_Class_Input; Function Constant_Reference(Object : in Object_Object; Key : in String ) return String is Begin Do_Index: Declare Index : Instance'Class renames Object.Element(Key); Begin Return Result : Constant String := (if Index in String_Object then -String_Object( Index ) else To_String( Index )); End Do_Index; -- Exception -- when Name_Error => Raise Bad_Index; End Constant_Reference; Function Array_Constant(Object : in Array_Object; Key : in Natural ) return Instance'Class is Begin Return Object.Element(Key); -- Exception -- when Name_Error => Raise Bad_Index; End Array_Constant; Function "**"(Left : Instance'Class; Right : String ) return String is (if Left in Object_Object and then Object_Object(Left).Element.Contains(Right) then To_String( Object_Object(Left).Element(Right) ) else "" ); Function "**"(Left : Instance'Class; Right : Natural ) return Instance'Class is (if Left in Array_Object and then Natural(Array_Object(Left).Element.Length) > Right then Array_Object(Left).Element(Right) else Null_Object'(Value_Type => VK_Null) ); Procedure Include(Object : in out Object_Object; Name : String; Value : Instance'Class ) is Begin Object.Element.Include(Key => Name, New_Item => Value); End Include; Procedure Include(Left : in out Object_Object; Right : in Object_Object ) is Package NVP renames Name_Value_Pairs; Begin For C in Right.Element.Iterate loop Left.Element.Include(New_Item => NVP.Element(C), Key => NVP.Key(C)); end loop; End Include; Function Exists(Object : in out Object_Object; Name : String) return Boolean is ( Object.Element.Contains(Name) ); End NSO.JSON;
reznikmm/matreshka
Ada
4,083
ads
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- Open Document Toolkit -- -- -- -- Runtime Library Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2014, Vadim Godunko <[email protected]> -- -- All rights reserved. -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions -- -- are met: -- -- -- -- * Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- -- -- * Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in the -- -- documentation and/or other materials provided with the distribution. -- -- -- -- * Neither the name of the Vadim Godunko, IE nor the names of its -- -- contributors may be used to endorse or promote products derived from -- -- this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -- -- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED -- -- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -- -- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -- -- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -- -- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -- -- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- -- ------------------------------------------------------------------------------ -- $Revision$ $Date$ ------------------------------------------------------------------------------ with ODF.DOM.Chart_Axis_Label_Position_Attributes; package Matreshka.ODF_Chart.Axis_Label_Position_Attributes is type Chart_Axis_Label_Position_Attribute_Node is new Matreshka.ODF_Chart.Abstract_Chart_Attribute_Node and ODF.DOM.Chart_Axis_Label_Position_Attributes.ODF_Chart_Axis_Label_Position_Attribute with null record; overriding function Create (Parameters : not null access Matreshka.DOM_Attributes.Attribute_L2_Parameters) return Chart_Axis_Label_Position_Attribute_Node; overriding function Get_Local_Name (Self : not null access constant Chart_Axis_Label_Position_Attribute_Node) return League.Strings.Universal_String; end Matreshka.ODF_Chart.Axis_Label_Position_Attributes;
micahwelf/FLTK-Ada
Ada
757
ads
package FLTK.Widgets.Boxes is type Box is new Widget with private; type Box_Reference (Data : not null access Box'Class) is limited null record with Implicit_Dereference => Data; package Forge is function Create (X, Y, W, H : in Integer; Text : in String) return Box; end Forge; procedure Draw (This : in out Box); function Handle (This : in out Box; Event : in Event_Kind) return Event_Outcome; private type Box is new Widget with null record; overriding procedure Finalize (This : in out Box); pragma Inline (Draw); pragma Inline (Handle); end FLTK.Widgets.Boxes;
faelys/natools
Ada
2,204
ads
------------------------------------------------------------------------------ -- Copyright (c) 2014, Natacha Porté -- -- -- -- Permission to use, copy, modify, and distribute this software for any -- -- purpose with or without fee is hereby granted, provided that the above -- -- copyright notice and this permission notice appear in all copies. -- -- -- -- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -- -- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -- -- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -- -- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -- -- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -- -- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -- -- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -- ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ -- Natools.S_Expressions.Cache_Tests provides tests for generic memeory -- -- cache in Natools.S_Expressions.Generic_Caches and its default -- -- instantiation. -- ------------------------------------------------------------------------------ with Natools.Tests; package Natools.S_Expressions.Cache_Tests is package NT renames Natools.Tests; procedure All_Tests (Report : in out NT.Reporter'Class); procedure Debug_Instantiation (Report : in out NT.Reporter'Class); procedure Default_Instantiation (Report : in out NT.Reporter'Class); procedure Descriptor_Interface (Report : in out NT.Reporter'Class); procedure Duplication (Report : in out NT.Reporter'Class); procedure Lockable_Interface (Report : in out NT.Reporter'Class); procedure Replayable_Interface (Report : in out NT.Reporter'Class); end Natools.S_Expressions.Cache_Tests;
zhmu/ananas
Ada
3,135
ads
------------------------------------------------------------------------------ -- -- -- GNAT RUN-TIME COMPONENTS -- -- -- -- S Y S T E M . I M G _ B I U -- -- -- -- S p e c -- -- -- -- Copyright (C) 1992-2022, Free Software Foundation, Inc. -- -- -- -- GNAT is free software; you can redistribute it and/or modify it under -- -- terms of the GNU General Public License as published by the Free Soft- -- -- ware Foundation; either version 3, or (at your option) any later ver- -- -- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- -- or FITNESS FOR A PARTICULAR PURPOSE. -- -- -- -- As a special exception under Section 7 of GPL version 3, you are granted -- -- additional permissions described in the GCC Runtime Library Exception, -- -- version 3.1, as published by the Free Software Foundation. -- -- -- -- You should have received a copy of the GNU General Public License and -- -- a copy of the GCC Runtime Library Exception along with this program; -- -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- -- <http://www.gnu.org/licenses/>. -- -- -- -- GNAT was originally developed by the GNAT team at New York University. -- -- Extensive contributions were provided by Ada Core Technologies Inc. -- -- -- ------------------------------------------------------------------------------ -- Contains the routine for computing the image in based format of signed and -- unsigned integers up to Integer for use by Text_IO.Integer_IO and -- Text_IO.Modular_IO. with System.Image_B; with System.Unsigned_Types; package System.Img_BIU is pragma Pure; subtype Unsigned is Unsigned_Types.Unsigned; package Impl is new Image_B (Integer, Unsigned); procedure Set_Image_Based_Integer (V : Integer; B : Natural; W : Integer; S : out String; P : in out Natural) renames Impl.Set_Image_Based_Integer; procedure Set_Image_Based_Unsigned (V : Unsigned; B : Natural; W : Integer; S : out String; P : in out Natural) renames Impl.Set_Image_Based_Unsigned; end System.Img_BIU;
PThierry/ewok-kernel
Ada
4,722
adb
-- -- Copyright 2018 The wookey project team <[email protected]> -- - Ryad Benadjila -- - Arnauld Michelizza -- - Mathieu Renard -- - Philippe Thierry -- - Philippe Trebuchet -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- with soc.exti; use soc.exti; with soc.nvic; with soc.syscfg; with soc.gpio; with ewok.exported.gpios; use ewok.exported.gpios; with ewok.exti.handler; package body ewok.exti with spark_mode => off is procedure init is begin ewok.exti.handler.init; soc.exti.init; end init; procedure enable (ref : in ewok.exported.gpios.t_gpio_ref) is line : soc.exti.t_exti_line_index; begin line := soc.exti.t_exti_line_index'val (soc.gpio.t_gpio_pin_index'pos (ref.pin)); soc.exti.enable (line); case ref.pin is when 0 => soc.nvic.enable_irq (soc.nvic.EXTI_Line_0); when 1 => soc.nvic.enable_irq (soc.nvic.EXTI_Line_1); when 2 => soc.nvic.enable_irq (soc.nvic.EXTI_Line_2); when 3 => soc.nvic.enable_irq (soc.nvic.EXTI_Line_3); when 4 => soc.nvic.enable_irq (soc.nvic.EXTI_Line_4); when 5 .. 9 => soc.nvic.enable_irq (soc.nvic.EXTI_Line_5_9); when 10 .. 15 => soc.nvic.enable_irq (soc.nvic.EXTI_Line_10_15); end case; end enable; procedure disable (ref : in ewok.exported.gpios.t_gpio_ref) is line : soc.exti.t_exti_line_index; begin line := soc.exti.t_exti_line_index'val (soc.gpio.t_gpio_pin_index'pos (ref.pin)); soc.exti.disable (line); end disable; function is_used (ref : ewok.exported.gpios.t_gpio_ref) return boolean is line : constant soc.exti.t_exti_line_index := soc.exti.t_exti_line_index'val (soc.gpio.t_gpio_pin_index'pos (ref.pin)); begin return exti_line_registered (line) or soc.exti.is_enabled (line); end is_used; procedure register (conf : in ewok.exported.gpios.t_gpio_config_access; success : out boolean) is line : constant soc.exti.t_exti_line_index := soc.exti.t_exti_line_index'val (soc.gpio.t_gpio_pin_index'pos (conf.all.kref.pin)); begin -- Is EXTI setting required? if not conf.all.settings.set_exti then success := true; return; end if; -- Is EXTI line already registered? if exti_line_registered (line) then success := false; return; end if; -- If the line is already set, thus it's already used. -- We return in error. if soc.exti.is_enabled (line) then success := false; return; end if; -- Configuring the triggers case conf.all.exti_trigger is when GPIO_EXTI_TRIGGER_NONE => success := true; return; when GPIO_EXTI_TRIGGER_RISE => soc.exti.EXTI.RTSR.line(line) := TRIGGER_ENABLED; when GPIO_EXTI_TRIGGER_FALL => soc.exti.EXTI.FTSR.line(line) := TRIGGER_ENABLED; when GPIO_EXTI_TRIGGER_BOTH => soc.exti.EXTI.RTSR.line(line) := TRIGGER_ENABLED; soc.exti.EXTI.FTSR.line(line) := TRIGGER_ENABLED; end case; -- Configuring the SYSCFG register soc.syscfg.set_exti_port (conf.all.kref.pin, conf.all.kref.port); exti_line_registered (line) := true; success := true; end register; procedure release (conf : in ewok.exported.gpios.t_gpio_config_access) is line : constant soc.exti.t_exti_line_index := soc.exti.t_exti_line_index'val (soc.gpio.t_gpio_pin_index'pos (conf.all.kref.pin)); begin if not conf.all.settings.set_exti then return; end if; if not exti_line_registered (line) then return; end if; if not soc.exti.is_enabled (line) then return; end if; if conf.all.exti_trigger = GPIO_EXTI_TRIGGER_NONE then return; end if; soc.exti.disable (line); exti_line_registered (line) := false; end release; end ewok.exti;
ekoeppen/STM32_Generic_Ada_Drivers
Ada
3,924
ads
pragma Style_Checks (Off); -- This spec has been automatically generated from STM32L0x3.svd pragma Restrictions (No_Elaboration_Code); with System; package STM32_SVD.IWDG is pragma Preelaborate; --------------- -- Registers -- --------------- subtype KR_KEY_Field is STM32_SVD.UInt16; -- Key register type KR_Register is record -- Write-only. Key value (write only, read 0x0000) KEY : KR_KEY_Field := 16#0#; -- unspecified Reserved_16_31 : STM32_SVD.UInt16 := 16#0#; end record with Volatile_Full_Access, Object_Size => 32, Bit_Order => System.Low_Order_First; for KR_Register use record KEY at 0 range 0 .. 15; Reserved_16_31 at 0 range 16 .. 31; end record; subtype PR_PR_Field is STM32_SVD.UInt3; -- Prescaler register type PR_Register is record -- Prescaler divider PR : PR_PR_Field := 16#0#; -- unspecified Reserved_3_31 : STM32_SVD.UInt29 := 16#0#; end record with Volatile_Full_Access, Object_Size => 32, Bit_Order => System.Low_Order_First; for PR_Register use record PR at 0 range 0 .. 2; Reserved_3_31 at 0 range 3 .. 31; end record; subtype RLR_RL_Field is STM32_SVD.UInt12; -- Reload register type RLR_Register is record -- Watchdog counter reload value RL : RLR_RL_Field := 16#FFF#; -- unspecified Reserved_12_31 : STM32_SVD.UInt20 := 16#0#; end record with Volatile_Full_Access, Object_Size => 32, Bit_Order => System.Low_Order_First; for RLR_Register use record RL at 0 range 0 .. 11; Reserved_12_31 at 0 range 12 .. 31; end record; subtype SR_PVU_Field is STM32_SVD.Bit; subtype SR_RVU_Field is STM32_SVD.Bit; subtype SR_WVU_Field is STM32_SVD.Bit; -- Status register type SR_Register is record -- Read-only. Watchdog prescaler value update PVU : SR_PVU_Field; -- Read-only. Watchdog counter reload value update RVU : SR_RVU_Field; -- Read-only. Watchdog counter window value update WVU : SR_WVU_Field; -- unspecified Reserved_3_31 : STM32_SVD.UInt29; end record with Volatile_Full_Access, Object_Size => 32, Bit_Order => System.Low_Order_First; for SR_Register use record PVU at 0 range 0 .. 0; RVU at 0 range 1 .. 1; WVU at 0 range 2 .. 2; Reserved_3_31 at 0 range 3 .. 31; end record; subtype WINR_WIN_Field is STM32_SVD.UInt12; -- Window register type WINR_Register is record -- Watchdog counter window value WIN : WINR_WIN_Field := 16#FFF#; -- unspecified Reserved_12_31 : STM32_SVD.UInt20 := 16#0#; end record with Volatile_Full_Access, Object_Size => 32, Bit_Order => System.Low_Order_First; for WINR_Register use record WIN at 0 range 0 .. 11; Reserved_12_31 at 0 range 12 .. 31; end record; ----------------- -- Peripherals -- ----------------- -- Independent watchdog type IWDG_Peripheral is record -- Key register KR : aliased KR_Register; -- Prescaler register PR : aliased PR_Register; -- Reload register RLR : aliased RLR_Register; -- Status register SR : aliased SR_Register; -- Window register WINR : aliased WINR_Register; end record with Volatile; for IWDG_Peripheral use record KR at 16#0# range 0 .. 31; PR at 16#4# range 0 .. 31; RLR at 16#8# range 0 .. 31; SR at 16#C# range 0 .. 31; WINR at 16#10# range 0 .. 31; end record; -- Independent watchdog IWDG_Periph : aliased IWDG_Peripheral with Import, Address => IWDG_Base; end STM32_SVD.IWDG;
reznikmm/matreshka
Ada
4,647
adb
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- Open Document Toolkit -- -- -- -- Runtime Library Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2014, Vadim Godunko <[email protected]> -- -- All rights reserved. -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions -- -- are met: -- -- -- -- * Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- -- -- * Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in the -- -- documentation and/or other materials provided with the distribution. -- -- -- -- * Neither the name of the Vadim Godunko, IE nor the names of its -- -- contributors may be used to endorse or promote products derived from -- -- this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -- -- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED -- -- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -- -- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -- -- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -- -- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -- -- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- -- ------------------------------------------------------------------------------ -- $Revision$ $Date$ ------------------------------------------------------------------------------ with Matreshka.DOM_Documents; with Matreshka.ODF_String_Constants; with ODF.DOM.Iterators; with ODF.DOM.Visitors; package body Matreshka.ODF_Meta.Character_Count_Attributes is ------------ -- Create -- ------------ overriding function Create (Parameters : not null access Matreshka.DOM_Attributes.Attribute_L2_Parameters) return Meta_Character_Count_Attribute_Node is begin return Self : Meta_Character_Count_Attribute_Node do Matreshka.ODF_Meta.Constructors.Initialize (Self'Unchecked_Access, Parameters.Document, Matreshka.ODF_String_Constants.Meta_Prefix); end return; end Create; -------------------- -- Get_Local_Name -- -------------------- overriding function Get_Local_Name (Self : not null access constant Meta_Character_Count_Attribute_Node) return League.Strings.Universal_String is pragma Unreferenced (Self); begin return Matreshka.ODF_String_Constants.Character_Count_Attribute; end Get_Local_Name; begin Matreshka.DOM_Documents.Register_Attribute (Matreshka.ODF_String_Constants.Meta_URI, Matreshka.ODF_String_Constants.Character_Count_Attribute, Meta_Character_Count_Attribute_Node'Tag); end Matreshka.ODF_Meta.Character_Count_Attributes;
zhmu/ananas
Ada
1,555
adb
-- { dg-do run } with Init9; use Init9; with Ada.Numerics; use Ada.Numerics; with Text_IO; use Text_IO; with Dump; procedure P9 is Local_R1 : R1; Local_R2 : R2; begin Put ("My_R1 :"); Dump (My_R1'Address, R1'Max_Size_In_Storage_Elements); New_Line; -- { dg-output "My_R1 : 18 2d 44 54 fb 21 09 40.*\n" } Put ("My_R2 :"); Dump (My_R2'Address, R2'Max_Size_In_Storage_Elements); New_Line; -- { dg-output "My_R2 : 40 09 21 fb 54 44 2d 18.*\n" } Local_R1 := My_R1; Put ("Local_R1 :"); Dump (Local_R1'Address, R1'Max_Size_In_Storage_Elements); New_Line; -- { dg-output "Local_R1 : 18 2d 44 54 fb 21 09 40.*\n" } Local_R2 := My_R2; Put ("Local_R2 :"); Dump (Local_R2'Address, R2'Max_Size_In_Storage_Elements); New_Line; -- { dg-output "Local_R2 : 40 09 21 fb 54 44 2d 18.*\n" } Local_R1.F := Pi; Put ("Local_R1 :"); Dump (Local_R1'Address, R1'Max_Size_In_Storage_Elements); New_Line; -- { dg-output "Local_R1 : 18 2d 44 54 fb 21 09 40.*\n" } Local_R2.F := Pi; Put ("Local_R2 :"); Dump (Local_R2'Address, R2'Max_Size_In_Storage_Elements); New_Line; -- { dg-output "Local_R2 : 40 09 21 fb 54 44 2d 18.*\n" } Local_R1.F := Local_R2.F; Put ("Local_R1 :"); Dump (Local_R1'Address, R1'Max_Size_In_Storage_Elements); New_Line; -- { dg-output "Local_R1 : 18 2d 44 54 fb 21 09 40.*\n" } Local_R2.F := Local_R1.F; Put ("Local_R2 :"); Dump (Local_R2'Address, R2'Max_Size_In_Storage_Elements); New_Line; -- { dg-output "Local_R2 : 40 09 21 fb 54 44 2d 18.*\n" } end;
reznikmm/matreshka
Ada
4,664
ads
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- Open Document Toolkit -- -- -- -- Runtime Library Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2014, Vadim Godunko <[email protected]> -- -- All rights reserved. -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions -- -- are met: -- -- -- -- * Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- -- -- * Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in the -- -- documentation and/or other materials provided with the distribution. -- -- -- -- * Neither the name of the Vadim Godunko, IE nor the names of its -- -- contributors may be used to endorse or promote products derived from -- -- this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -- -- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED -- -- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -- -- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -- -- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -- -- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -- -- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- -- ------------------------------------------------------------------------------ -- $Revision$ $Date$ ------------------------------------------------------------------------------ with XML.DOM.Visitors; with ODF.DOM.Table_Body_Elements; package Matreshka.ODF_Table.Body_Elements is type Table_Body_Element_Node is new Matreshka.ODF_Table.Abstract_Table_Element_Node and ODF.DOM.Table_Body_Elements.ODF_Table_Body with null record; overriding function Create (Parameters : not null access Matreshka.DOM_Elements.Element_L2_Parameters) return Table_Body_Element_Node; overriding function Get_Local_Name (Self : not null access constant Table_Body_Element_Node) return League.Strings.Universal_String; overriding procedure Enter_Node (Self : not null access Table_Body_Element_Node; Visitor : in out XML.DOM.Visitors.Abstract_Visitor'Class; Control : in out XML.DOM.Visitors.Traverse_Control); overriding procedure Leave_Node (Self : not null access Table_Body_Element_Node; Visitor : in out XML.DOM.Visitors.Abstract_Visitor'Class; Control : in out XML.DOM.Visitors.Traverse_Control); overriding procedure Visit_Node (Self : not null access Table_Body_Element_Node; Iterator : in out XML.DOM.Visitors.Abstract_Iterator'Class; Visitor : in out XML.DOM.Visitors.Abstract_Visitor'Class; Control : in out XML.DOM.Visitors.Traverse_Control); end Matreshka.ODF_Table.Body_Elements;
reznikmm/matreshka
Ada
4,209
adb
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- Open Document Toolkit -- -- -- -- Runtime Library Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2013, Vadim Godunko <[email protected]> -- -- All rights reserved. -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions -- -- are met: -- -- -- -- * Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- -- -- * Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in the -- -- documentation and/or other materials provided with the distribution. -- -- -- -- * Neither the name of the Vadim Godunko, IE nor the names of its -- -- contributors may be used to endorse or promote products derived from -- -- this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -- -- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED -- -- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -- -- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -- -- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -- -- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -- -- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- -- ------------------------------------------------------------------------------ -- $Revision$ $Date$ ------------------------------------------------------------------------------ with Matreshka.DOM_Nodes; with XML.DOM.Attributes.Internals; package body ODF.DOM.Attributes.FO.Language.Internals is ------------ -- Create -- ------------ function Create (Node : Matreshka.ODF_Attributes.FO.Language.FO_Language_Access) return ODF.DOM.Attributes.FO.Language.ODF_FO_Language is begin return (XML.DOM.Attributes.Internals.Create (Matreshka.DOM_Nodes.Attribute_Access (Node)) with null record); end Create; ---------- -- Wrap -- ---------- function Wrap (Node : Matreshka.ODF_Attributes.FO.Language.FO_Language_Access) return ODF.DOM.Attributes.FO.Language.ODF_FO_Language is begin return (XML.DOM.Attributes.Internals.Wrap (Matreshka.DOM_Nodes.Attribute_Access (Node)) with null record); end Wrap; end ODF.DOM.Attributes.FO.Language.Internals;
ekoeppen/MSP430_Generic_Ada_Drivers
Ada
7,585
ads
-- This spec has been automatically generated from out.svd pragma Restrictions (No_Elaboration_Code); pragma Ada_2012; pragma Style_Checks (Off); with System; -- Timer0_A3 package MSP430_SVD.TIMER_0_A3 is pragma Preelaborate; --------------- -- Registers -- --------------- -- Timer A mode control 1 type TA0CTL_MC_Field is (-- Timer A mode control: 0 - Stop Mc_0, -- Timer A mode control: 1 - Up to CCR0 Mc_1, -- Timer A mode control: 2 - Continous up Mc_2, -- Timer A mode control: 3 - Up/Down Mc_3) with Size => 2; for TA0CTL_MC_Field use (Mc_0 => 0, Mc_1 => 1, Mc_2 => 2, Mc_3 => 3); -- Timer A clock input divider 1 type TA0CTL_ID_Field is (-- Timer A input divider: 0 - /1 Id_0, -- Timer A input divider: 1 - /2 Id_1, -- Timer A input divider: 2 - /4 Id_2, -- Timer A input divider: 3 - /8 Id_3) with Size => 2; for TA0CTL_ID_Field use (Id_0 => 0, Id_1 => 1, Id_2 => 2, Id_3 => 3); -- Timer A clock source select 1 type TA0CTL_TASSEL_Field is (-- Timer A clock source select: 0 - TACLK Tassel_0, -- Timer A clock source select: 1 - ACLK Tassel_1, -- Timer A clock source select: 2 - SMCLK Tassel_2, -- Timer A clock source select: 3 - INCLK Tassel_3) with Size => 2; for TA0CTL_TASSEL_Field use (Tassel_0 => 0, Tassel_1 => 1, Tassel_2 => 2, Tassel_3 => 3); -- Timer0_A3 Control type TA0CTL_Register is record -- Timer A counter interrupt flag TAIFG : MSP430_SVD.Bit := 16#0#; -- Timer A counter interrupt enable TAIE : MSP430_SVD.Bit := 16#0#; -- Timer A counter clear TACLR : MSP430_SVD.Bit := 16#0#; -- unspecified Reserved_3_3 : MSP430_SVD.Bit := 16#0#; -- Timer A mode control 1 MC : TA0CTL_MC_Field := MSP430_SVD.TIMER_0_A3.Mc_0; -- Timer A clock input divider 1 ID : TA0CTL_ID_Field := MSP430_SVD.TIMER_0_A3.Id_0; -- Timer A clock source select 1 TASSEL : TA0CTL_TASSEL_Field := MSP430_SVD.TIMER_0_A3.Tassel_0; -- unspecified Reserved_10_15 : MSP430_SVD.UInt6 := 16#0#; end record with Volatile_Full_Access, Object_Size => 16, Bit_Order => System.Low_Order_First; for TA0CTL_Register use record TAIFG at 0 range 0 .. 0; TAIE at 0 range 1 .. 1; TACLR at 0 range 2 .. 2; Reserved_3_3 at 0 range 3 .. 3; MC at 0 range 4 .. 5; ID at 0 range 6 .. 7; TASSEL at 0 range 8 .. 9; Reserved_10_15 at 0 range 10 .. 15; end record; -- Output mode 2 type TA0CCTL0_OUTMOD_Field is (-- PWM output mode: 0 - output only Outmod_0, -- PWM output mode: 1 - set Outmod_1, -- PWM output mode: 2 - PWM toggle/reset Outmod_2, -- PWM output mode: 3 - PWM set/reset Outmod_3, -- PWM output mode: 4 - toggle Outmod_4, -- PWM output mode: 5 - Reset Outmod_5, -- PWM output mode: 6 - PWM toggle/set Outmod_6, -- PWM output mode: 7 - PWM reset/set Outmod_7) with Size => 3; for TA0CCTL0_OUTMOD_Field use (Outmod_0 => 0, Outmod_1 => 1, Outmod_2 => 2, Outmod_3 => 3, Outmod_4 => 4, Outmod_5 => 5, Outmod_6 => 6, Outmod_7 => 7); -- Capture input select 1 type TA0CCTL0_CCIS_Field is (-- Capture input select: 0 - CCIxA Ccis_0, -- Capture input select: 1 - CCIxB Ccis_1, -- Capture input select: 2 - GND Ccis_2, -- Capture input select: 3 - Vcc Ccis_3) with Size => 2; for TA0CCTL0_CCIS_Field use (Ccis_0 => 0, Ccis_1 => 1, Ccis_2 => 2, Ccis_3 => 3); -- Capture mode 1 type TA0CCTL0_CM_Field is (-- Capture mode: 0 - disabled Cm_0, -- Capture mode: 1 - pos. edge Cm_1, -- Capture mode: 1 - neg. edge Cm_2, -- Capture mode: 1 - both edges Cm_3) with Size => 2; for TA0CCTL0_CM_Field use (Cm_0 => 0, Cm_1 => 1, Cm_2 => 2, Cm_3 => 3); -- Timer0_A3 Capture/Compare Control 0 type TA0CCTL_Register is record -- Capture/compare interrupt flag CCIFG : MSP430_SVD.Bit := 16#0#; -- Capture/compare overflow flag COV : MSP430_SVD.Bit := 16#0#; -- PWM Output signal if output mode 0 OUT_k : MSP430_SVD.Bit := 16#0#; -- Capture input signal (read) CCI : MSP430_SVD.Bit := 16#0#; -- Capture/compare interrupt enable CCIE : MSP430_SVD.Bit := 16#0#; -- Output mode 2 OUTMOD : TA0CCTL0_OUTMOD_Field := MSP430_SVD.TIMER_0_A3.Outmod_0; -- Capture mode: 1 /Compare mode : 0 CAP : MSP430_SVD.Bit := 16#0#; -- unspecified Reserved_9_9 : MSP430_SVD.Bit := 16#0#; -- Latched capture signal (read) SCCI : MSP430_SVD.Bit := 16#0#; -- Capture sychronize SCS : MSP430_SVD.Bit := 16#0#; -- Capture input select 1 CCIS : TA0CCTL0_CCIS_Field := MSP430_SVD.TIMER_0_A3.Ccis_0; -- Capture mode 1 CM : TA0CCTL0_CM_Field := MSP430_SVD.TIMER_0_A3.Cm_0; end record with Volatile_Full_Access, Object_Size => 16, Bit_Order => System.Low_Order_First; for TA0CCTL_Register use record CCIFG at 0 range 0 .. 0; COV at 0 range 1 .. 1; OUT_k at 0 range 2 .. 2; CCI at 0 range 3 .. 3; CCIE at 0 range 4 .. 4; OUTMOD at 0 range 5 .. 7; CAP at 0 range 8 .. 8; Reserved_9_9 at 0 range 9 .. 9; SCCI at 0 range 10 .. 10; SCS at 0 range 11 .. 11; CCIS at 0 range 12 .. 13; CM at 0 range 14 .. 15; end record; ----------------- -- Peripherals -- ----------------- -- Timer0_A3 type TIMER_0_A3_Peripheral is record -- Timer0_A3 Interrupt Vector Word TA0IV : aliased MSP430_SVD.UInt16; -- Timer0_A3 Control TA0CTL : aliased TA0CTL_Register; -- Timer0_A3 Capture/Compare Control 0 TA0CCTL0 : aliased TA0CCTL_Register; -- Timer0_A3 Capture/Compare Control 1 TA0CCTL1 : aliased TA0CCTL_Register; -- Timer0_A3 Capture/Compare Control 2 TA0CCTL2 : aliased TA0CCTL_Register; -- Timer0_A3 Counter Register TA0R : aliased MSP430_SVD.UInt16; -- Timer0_A3 Capture/Compare 0 TA0CCR0 : aliased MSP430_SVD.UInt16; -- Timer0_A3 Capture/Compare 1 TA0CCR1 : aliased MSP430_SVD.UInt16; -- Timer0_A3 Capture/Compare 2 TA0CCR2 : aliased MSP430_SVD.UInt16; end record with Volatile; for TIMER_0_A3_Peripheral use record TA0IV at 16#0# range 0 .. 15; TA0CTL at 16#32# range 0 .. 15; TA0CCTL0 at 16#34# range 0 .. 15; TA0CCTL1 at 16#36# range 0 .. 15; TA0CCTL2 at 16#38# range 0 .. 15; TA0R at 16#42# range 0 .. 15; TA0CCR0 at 16#44# range 0 .. 15; TA0CCR1 at 16#46# range 0 .. 15; TA0CCR2 at 16#48# range 0 .. 15; end record; -- Timer0_A3 TIMER_0_A3_Periph : aliased TIMER_0_A3_Peripheral with Import, Address => TIMER_0_A3_Base; end MSP430_SVD.TIMER_0_A3;
zhmu/ananas
Ada
9,129
ads
------------------------------------------------------------------------------ -- -- -- GNAT COMPILER COMPONENTS -- -- -- -- G H O S T -- -- -- -- S p e c -- -- -- -- Copyright (C) 2014-2022, Free Software Foundation, Inc. -- -- -- -- GNAT is free software; you can redistribute it and/or modify it under -- -- terms of the GNU General Public License as published by the Free Soft- -- -- ware Foundation; either version 3, or (at your option) any later ver- -- -- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -- -- for more details. You should have received a copy of the GNU General -- -- Public License distributed with GNAT; see file COPYING3. If not, go to -- -- http://www.gnu.org/licenses for a complete copy of the license. -- -- -- -- GNAT was originally developed by the GNAT team at New York University. -- -- Extensive contributions were provided by Ada Core Technologies Inc. -- -- -- ------------------------------------------------------------------------------ -- This package contains routines that deal with the static and runtime -- semantics of Ghost entities. with Opt; use Opt; with Types; use Types; package Ghost is procedure Check_Ghost_Completion (Prev_Id : Entity_Id; Compl_Id : Entity_Id); -- Verify that the Ghost policy of initial entity Prev_Id is compatible -- with the Ghost policy of completing entity Compl_Id. Emit an error if -- this is not the case. procedure Check_Ghost_Context (Ghost_Id : Entity_Id; Ghost_Ref : Node_Id); -- Determine whether node Ghost_Ref appears within a Ghost-friendly context -- where Ghost entity Ghost_Id can safely reside. procedure Check_Ghost_Overriding (Subp : Entity_Id; Overridden_Subp : Entity_Id); -- Verify that the Ghost policy of parent subprogram Overridden_Subp is -- compatible with the Ghost policy of overriding subprogram Subp. Emit -- an error if this is not the case. procedure Check_Ghost_Primitive (Prim : Entity_Id; Typ : Entity_Id); -- Verify that the Ghost policy of primitive operation Prim is the same as -- the Ghost policy of tagged type Typ. Emit an error if this is not the -- case. procedure Check_Ghost_Refinement (State : Node_Id; State_Id : Entity_Id; Constit : Node_Id; Constit_Id : Entity_Id); -- Verify that the Ghost policy of constituent Constit_Id is compatible -- with the Ghost policy of abstract state State_I. procedure Check_Ghost_Type (Typ : Entity_Id); -- Verify that Ghost type Typ is neither concurrent, nor effectively -- volatile. function Implements_Ghost_Interface (Typ : Entity_Id) return Boolean; -- Determine whether type Typ implements at least one Ghost interface procedure Initialize; -- Initialize internal tables procedure Install_Ghost_Region (Mode : Ghost_Mode_Type; N : Node_Id); pragma Inline (Install_Ghost_Region); -- Install a Ghost region described by mode Mode and ignored region start -- node N. function Is_Ghost_Assignment (N : Node_Id) return Boolean; -- Determine whether arbitrary node N denotes an assignment statement whose -- target is a Ghost entity. function Is_Ghost_Declaration (N : Node_Id) return Boolean; -- Determine whether arbitrary node N denotes a declaration which defines -- a Ghost entity. function Is_Ghost_Pragma (N : Node_Id) return Boolean; -- Determine whether arbitrary node N denotes a pragma which encloses a -- Ghost entity or is associated with a Ghost entity. function Is_Ghost_Procedure_Call (N : Node_Id) return Boolean; -- Determine whether arbitrary node N denotes a procedure call invoking a -- Ghost procedure. function Is_Ignored_Ghost_Unit (N : Node_Id) return Boolean; -- Determine whether compilation unit N is subject to pragma Ghost with -- policy Ignore. procedure Lock; -- Lock internal tables before calling backend procedure Mark_And_Set_Ghost_Assignment (N : Node_Id); -- Mark assignment statement N as Ghost when: -- -- * The left hand side denotes a Ghost entity -- -- Install the Ghost mode of the assignment statement. This routine starts -- a Ghost region and must be used with routine Restore_Ghost_Region. procedure Mark_And_Set_Ghost_Body (N : Node_Id; Spec_Id : Entity_Id); -- Mark package or subprogram body N as Ghost when: -- -- * The body is subject to pragma Ghost -- -- * The body completes a previous declaration whose spec denoted by -- Spec_Id is a Ghost entity. -- -- * The body appears within a Ghost region -- -- Install the Ghost mode of the body. This routine starts a Ghost region -- and must be used with routine Restore_Ghost_Region. procedure Mark_And_Set_Ghost_Completion (N : Node_Id; Prev_Id : Entity_Id); -- Mark completion N of a deferred constant or private type [extension] -- Ghost when: -- -- * The entity of the previous declaration denoted by Prev_Id is Ghost -- -- * The completion appears within a Ghost region -- -- Install the Ghost mode of the completion. This routine starts a Ghost -- region and must be used with routine Restore_Ghost_Region. procedure Mark_And_Set_Ghost_Declaration (N : Node_Id); -- Mark declaration N as Ghost when: -- -- * The declaration is subject to pragma Ghost -- -- * The declaration denotes a child package or subprogram and the parent -- is a Ghost unit. -- -- * The declaration appears within a Ghost region -- -- Install the Ghost mode of the declaration. This routine starts a Ghost -- region and must be used with routine Restore_Ghost_Region. procedure Mark_And_Set_Ghost_Instantiation (N : Node_Id; Gen_Id : Entity_Id); -- Mark instantiation N as Ghost when: -- -- * The instantiation is subject to pragma Ghost -- -- * The generic template denoted by Gen_Id is Ghost -- -- * The instantiation appears within a Ghost region -- -- Install the Ghost mode of the instantiation. This routine starts a Ghost -- region and must be used with routine Restore_Ghost_Region. procedure Mark_And_Set_Ghost_Procedure_Call (N : Node_Id); -- Mark procedure call N as Ghost when: -- -- * The procedure being invoked is a Ghost entity -- -- Install the Ghost mode of the procedure call. This routine starts a -- Ghost region and must be used with routine Restore_Ghost_Region. procedure Mark_Ghost_Clause (N : Node_Id); -- Mark use package, use type, or with clause N as Ghost when: -- -- * The clause mentions a Ghost entity procedure Mark_Ghost_Pragma (N : Node_Id; Id : Entity_Id); -- Mark pragma N as Ghost when: -- -- * The pragma encloses Ghost entity Id -- -- * The pragma is associated with Ghost entity Id procedure Mark_Ghost_Renaming (N : Node_Id; Id : Entity_Id); -- Mark renaming declaration N as Ghost when: -- -- * Renamed entity Id denotes a Ghost entity procedure Remove_Ignored_Ghost_Code; -- Remove all code marked as ignored Ghost from the trees of all qualifying -- units (SPARK RM 6.9(4)). -- -- WARNING: this is a separate front end pass, care should be taken to keep -- it optimized. procedure Restore_Ghost_Region (Mode : Ghost_Mode_Type; N : Node_Id); pragma Inline (Restore_Ghost_Region); -- Restore a Ghost region to a previous state described by mode Mode and -- ignored region start node N. This routine must be used in conjunction -- with the following routines: -- -- Install_Ghost_Region -- Mark_And_Set_xxx -- Set_Ghost_Mode procedure Set_Ghost_Mode (N : Node_Or_Entity_Id); -- Install the Ghost mode of arbitrary node N. This routine starts a Ghost -- region and must be used with routine Restore_Ghost_Region. procedure Set_Is_Ghost_Entity (Id : Entity_Id); -- Set the relevant Ghost attributes of entity Id depending on the current -- Ghost assertion policy in effect. end Ghost;
reznikmm/matreshka
Ada
4,741
ads
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- Open Document Toolkit -- -- -- -- Runtime Library Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2014, Vadim Godunko <[email protected]> -- -- All rights reserved. -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions -- -- are met: -- -- -- -- * Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- -- -- * Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in the -- -- documentation and/or other materials provided with the distribution. -- -- -- -- * Neither the name of the Vadim Godunko, IE nor the names of its -- -- contributors may be used to endorse or promote products derived from -- -- this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -- -- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED -- -- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -- -- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -- -- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -- -- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -- -- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- -- ------------------------------------------------------------------------------ -- $Revision$ $Date$ ------------------------------------------------------------------------------ with League.Strings; with Matreshka.DOM_Attributes; with Matreshka.DOM_Elements; with Matreshka.DOM_Nodes; package Matreshka.ODF_XForms is type Abstract_XForms_Attribute_Node is abstract new Matreshka.DOM_Attributes.Abstract_Attribute_L2_Node with record Prefix : League.Strings.Universal_String; end record; overriding function Get_Namespace_URI (Self : not null access constant Abstract_XForms_Attribute_Node) return League.Strings.Universal_String; type Abstract_XForms_Element_Node is abstract new Matreshka.DOM_Elements.Abstract_Element_Node with record Prefix : League.Strings.Universal_String; end record; overriding function Get_Namespace_URI (Self : not null access constant Abstract_XForms_Element_Node) return League.Strings.Universal_String; package Constructors is procedure Initialize (Self : not null access Abstract_XForms_Attribute_Node'Class; Document : not null Matreshka.DOM_Nodes.Document_Access; Prefix : League.Strings.Universal_String) with Inline => True; procedure Initialize (Self : not null access Abstract_XForms_Element_Node'Class; Document : not null Matreshka.DOM_Nodes.Document_Access; Prefix : League.Strings.Universal_String) with Inline => True; end Constructors; end Matreshka.ODF_XForms;
jquorning/iNow
Ada
4,349
adb
pragma License (Restricted); -- -- Copyright (C) 2020 Jesper Quorning All Rights Reserved. -- -- The author disclaims copyright to this source code. In place of -- a legal notice, here is a blessing: -- -- May you do good and not evil. -- May you find forgiveness for yourself and forgive others. -- May you share freely, not taking more than you give. -- ----------------------------------------------------------------------------- -- Output to terminal screen -- with Ada.Text_IO; with Ada.Strings.Unbounded; with Commands; with Database.Events; with Database.Jobs; with Navigate; with Decoration; with Status; with Setup; package body Terminal_IO is procedure Put_Jobs is use Ada.Text_IO; use Navigate; use Types; begin if List.Set.Is_Empty then Put_Line ("<< No Jobs >>"); return; end if; for Index in List.Set.First_Index .. List.Set.Last_Index loop declare use Ada.Strings.Unbounded; Pair : Ref_Pair renames List.Refs (Index); Desc : Job_Desc renames List.Set (Index); TITLE : String renames To_String (Desc.Title); IS_DONE : constant Boolean := Database.Events.Is_Done (Desc.Id); STATE : constant Status.State_Type := (if IS_DONE then Status.Done else Status.Fresh); STAT : constant Status.Status_Type := (STATE, True, True); begin -- Current job marking Put (Decoration.Current_Image (STAT)); -- if Desc.Id = List.Current then -- Put (Symbols.UTF8 (Symbols.Black_Right_Pointing_Index)); -- else -- Put (" "); -- end if; Put (" "); -- Indent for Indent in 1 .. Pair.Level loop Put (" "); end loop; -- DONE star Put (Decoration.Status_Image (STAT)); -- if Database.Events.Is_Done (Desc.Id) then -- Put (Symbols.UTF8 (Symbols.Black_Star)); -- else -- Put (Symbols.UTF8 (Symbols.White_Star)); -- end if; Put (" "); -- Reference indication Put (String (Pair.Ref)); Put (" "); -- Job title Put (Decoration.Title_Image (Status => STAT, Title => TITLE)); -- Put (Ada.Strings.Unbounded.To_String (Desc.Title)); New_Line; end; end loop; end Put_Jobs; procedure Show_Job (Job : in Types.Job_Id) is use Ada.Text_IO, Ada.Strings.Unbounded; Info : constant Types.Job_Info := Database.Jobs.Get_Job_Info (Job); Events : constant Database.Events.Event_Lists.Vector := Database.Events.Get_Job_Events (Job); Done : constant Boolean := Database.Events.Is_Done (Job); Done_Image : constant String := Boolean'Image (Done); begin Put_Line (To_String (Info.Title) & " (Id" & Job'Img & ")"); Put_Line ("Parent (Id" & Info.Parent'Img & ")"); Put_Line ("Owner (" & To_String (Info.Owner) & ")"); Put_Line ("Status DONE: " & Done_Image); New_Line; for Event of Events loop Put (To_String (Event.Stamp)); Put (" "); Put (To_String (Event.Kind)); New_Line; end loop; end Show_Job; procedure Put_Help is use Ada.Text_IO; use Ada.Strings.Unbounded; begin for Line of Commands.Help_Lines loop Set_Col (1); Put (To_String (Line.Command)); Set_Col (33); Put_Line (To_String (Line.Comment)); end loop; end Put_Help; procedure Put_Error (Text : in String) is begin Ada.Text_IO.Put_Line (Text); end Put_Error; procedure Put_Banner is use Ada.Text_IO; use Setup; Image : constant String := (Program_Name & " " & Program_Version & " " & Build_ISO8601_UTC); Hline : constant String (Image'Range) := (others => '='); begin Put_Line (Image); Put_Line (Hline); Put_Line ("(type help to show help text)"); end Put_Banner; procedure Put_Path is begin Ada.Text_IO.Put_Line (Navigate.Path_Image); end Put_Path; end Terminal_IO;
MinimSecure/unum-sdk
Ada
919
adb
-- Copyright 2018-2019 Free Software Foundation, Inc. -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 3 of the License, or -- (at your option) any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program. If not, see <http://www.gnu.org/licenses/>. package body Pck is procedure Do_Nothing (A : System.Address) is begin null; end Do_Nothing; function Ident (S : String) return String is begin return S; end Ident; end Pck;
faelys/natools
Ada
17,674
ads
------------------------------------------------------------------------------ -- Copyright (c) 2014-2017, Natacha Porté -- -- -- -- Permission to use, copy, modify, and distribute this software for any -- -- purpose with or without fee is hereby granted, provided that the above -- -- copyright notice and this permission notice appear in all copies. -- -- -- -- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -- -- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -- -- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -- -- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -- -- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -- -- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -- -- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -- ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ -- Natools.Constant_Indefinite_Ordered_Sets provides an implementation of -- -- indefinite ordered maps with immutable mapping, based on a sorted array. -- -- This makes it task-safe as long as the mapping is only read. -- -- -- -- All the types exposed have referential semantics, in that assignment is -- -- cheap and uses the same actual object. It is as task-safe as the current -- -- implementation of Natools.References. -- -- Cursors also hold a reference, which is used to identify the parent map, -- -- so after an assignment or a call to Clear or Move, the link between the -- -- map object and the cursor is broken, but the cursor is still usable and -- -- behaves as the original version of the maps. -- -- -- -- There are two types defined here, depending on their restrictions and -- -- safety against concurrent accesses: -- -- * Constant_Map cannot be changed in any way, but is completely -- -- task-safe (unless some referential magic is performed, like -- -- tampering checks in standard containers) -- -- * Updatable_Map allows read-write operations on stored elements, but -- -- it is up to the client to ensure there operations are task-safe, -- -- e.g. by using an atomic or protected Element_Type. -- -- -- -- Insertion and deletion primitives are provided as function rather than -- -- procedures, to emphasize that they actually create a new map with the -- -- requested change. Since most of the map is blindly duplicated, they are -- -- all in O(n) time, which makes them a quite inefficient way to build -- -- maps. For a significant number of changes, it's probably better to go -- -- through an unsafe map. -- -- -- -- All the subprograms here have the semantics of standard indefinite -- -- ordered maps (see ARM A.18.6), except for tampering, which becomes -- -- irrelevant. -- ------------------------------------------------------------------------------ with Ada.Containers.Indefinite_Ordered_Maps; with Ada.Iterator_Interfaces; private with Ada.Finalization; private with Ada.Unchecked_Deallocation; private with Natools.References; private with Natools.Storage_Pools; generic type Key_Type (<>) is private; type Element_Type (<>) is private; with function "<" (Left, Right : Key_Type) return Boolean is <>; with function "=" (Left, Right : Element_Type) return Boolean is <>; package Natools.Constant_Indefinite_Ordered_Maps is pragma Preelaborate; package Unsafe_Maps is new Ada.Containers.Indefinite_Ordered_Maps (Key_Type, Element_Type); type Cursor is private; -- with Type_Invariant => Is_Valid (Cursor); pragma Preelaborable_Initialization (Cursor); No_Element : constant Cursor; procedure Clear (Position : in out Cursor); function Is_Valid (Position : Cursor) return Boolean; function Has_Element (Position : Cursor) return Boolean; function Element (Position : Cursor) return Element_Type with Pre => Has_Element (Position) or else raise Constraint_Error; function Key (Position : Cursor) return Key_Type with Pre => Has_Element (Position) or else raise Constraint_Error; procedure Query_Element (Position : in Cursor; Process : not null access procedure (Key : in Key_Type; Element : in Element_Type)) with Pre => Has_Element (Position) or else raise Constraint_Error; function Next (Position : Cursor) return Cursor; procedure Next (Position : in out Cursor); function Previous (Position : Cursor) return Cursor; procedure Previous (Position : in out Cursor); function "<" (Left, Right : Cursor) return Boolean with Pre => (Has_Element (Left) and then Has_Element (Right)) or else raise Constraint_Error; function ">" (Left, Right : Cursor) return Boolean with Pre => (Has_Element (Left) and then Has_Element (Right)) or else raise Constraint_Error; function "<" (Left : Cursor; Right : Key_Type) return Boolean with Pre => Has_Element (Left) or else raise Constraint_Error; function ">" (Left : Cursor; Right : Key_Type) return Boolean with Pre => Has_Element (Left) or else raise Constraint_Error; function "<" (Left : Key_Type; Right : Cursor) return Boolean with Pre => Has_Element (Right) or else raise Constraint_Error; function ">" (Left : Key_Type; Right : Cursor) return Boolean with Pre => Has_Element (Right) or else raise Constraint_Error; function Rank (Position : Cursor) return Ada.Containers.Count_Type; -- Return 1-based numeric position of the element designated by Position -- or zero when Position is empty. package Map_Iterator_Interfaces is new Ada.Iterator_Interfaces (Cursor, Has_Element); type Constant_Map is tagged private; -- TODO: add aspects when they don't put GNAT in an infinite loop -- with Constant_Indexing => Constant_Reference, -- Default_Iterator => Iterate, -- Iterator_Element => Element_Type; pragma Preelaborable_Initialization (Constant_Map); procedure Clear (Container : in out Constant_Map); function Create (Source : Unsafe_Maps.Map) return Constant_Map; procedure Move (Target : in out Constant_Map; Source : in out Constant_Map); procedure Replace (Container : in out Constant_Map; New_Items : in Unsafe_Maps.Map); function To_Unsafe_Map (Container : Constant_Map) return Unsafe_Maps.Map; function Is_Related (Container : Constant_Map; Position : Cursor) return Boolean; function "=" (Left, Right : Constant_Map) return Boolean; function Length (Container : Constant_Map) return Ada.Containers.Count_Type; function Is_Empty (Container : Constant_Map) return Boolean; function First (Container : Constant_Map) return Cursor; function First_Element (Container : Constant_Map) return Element_Type with Pre => (not Is_Empty (Container)) or else raise Constraint_Error; function First_Key (Container : Constant_Map) return Key_Type with Pre => (not Is_Empty (Container)) or else raise Constraint_Error; function Last (Container : Constant_Map) return Cursor; function Last_Element (Container : Constant_Map) return Element_Type with Pre => (not Is_Empty (Container)) or else raise Constraint_Error; function Last_Key (Container : Constant_Map) return Key_Type with Pre => (not Is_Empty (Container)) or else raise Constraint_Error; function Find (Container : Constant_Map; Key : Key_Type) return Cursor; function Element (Container : Constant_Map; Key : Key_Type) return Element_Type; function Floor (Container : Constant_Map; Key : Key_Type) return Cursor; function Ceiling (Container : Constant_Map; Key : Key_Type) return Cursor; function Contains (Container : Constant_Map; Key : Key_Type) return Boolean; procedure Iterate (Container : in Constant_Map; Process : not null access procedure (Position : in Cursor)); procedure Reverse_Iterate (Container : in Constant_Map; Process : not null access procedure (Position : in Cursor)); function Iterate (Container : in Constant_Map) return Map_Iterator_Interfaces.Reversible_Iterator'Class; function Iterate (Container : in Constant_Map; Start : in Cursor) return Map_Iterator_Interfaces.Reversible_Iterator'Class; function Iterate (Container : in Constant_Map; First, Last : in Cursor) return Map_Iterator_Interfaces.Reversible_Iterator'Class; type Constant_Reference_Type (Element : not null access constant Element_Type) is private with Implicit_Dereference => Element; function Constant_Reference (Container : aliased in Constant_Map; Position : in Cursor) return Constant_Reference_Type; function Constant_Reference (Container : aliased in Constant_Map; Key : in Key_Type) return Constant_Reference_Type; function Insert (Source : in Constant_Map; Key : in Key_Type; New_Item : in Element_Type; Position : out Cursor; Inserted : out Boolean) return Constant_Map; function Insert (Source : in Constant_Map; Key : in Key_Type; New_Item : in Element_Type) return Constant_Map; function Include (Source : in Constant_Map; Key : in Key_Type; New_Item : in Element_Type) return Constant_Map; function Replace (Source : in Constant_Map; Key : in Key_Type; New_Item : in Element_Type) return Constant_Map; function Replace_Element (Source : in Constant_Map; Position : in Cursor; New_Item : in Element_Type) return Constant_Map; function Replace_Element (Source : in Constant_Map; Position : in Cursor; New_Item : in Element_Type; New_Position : out Cursor) return Constant_Map; function Exclude (Source : in Constant_Map; Key : in Key_Type) return Constant_Map; function Delete (Source : in Constant_Map; Key : in Key_Type) return Constant_Map; function Delete (Source : in Constant_Map; Position : in Cursor) return Constant_Map; type Updatable_Map is new Constant_Map with private with Constant_Indexing => Constant_Reference_For_Bugged_GNAT, Variable_Indexing => Reference, Default_Iterator => Iterate, Iterator_Element => Element_Type; pragma Preelaborable_Initialization (Updatable_Map); function Constant_Reference_For_Bugged_GNAT (Container : aliased in Updatable_Map; Position : in Cursor) return Constant_Reference_Type; function Constant_Reference_For_Bugged_GNAT (Container : aliased in Updatable_Map; Key : in Key_Type) return Constant_Reference_Type; procedure Update_Element (Container : in out Updatable_Map; Position : in Cursor; Process : not null access procedure (Key : in Key_Type; Element : in out Element_Type)) with Pre => (Has_Element (Position) or else raise Constraint_Error) and then (Is_Related (Container, Position) or else raise Program_Error); type Reference_Type (Element : not null access Element_Type) is private with Implicit_Dereference => Element; function Reference (Container : aliased in out Updatable_Map; Position : in Cursor) return Reference_Type; function Reference (Container : aliased in out Updatable_Map; Key : in Key_Type) return Reference_Type; Empty_Constant_Map : constant Constant_Map; Empty_Updatable_Map : constant Updatable_Map; private type Key_Access is access Key_Type; type Element_Access is access Element_Type; type Node is record Key : not null Key_Access; Element : not null Element_Access; end record; use type Ada.Containers.Count_Type; subtype Count_Type is Ada.Containers.Count_Type; subtype Index_Type is Count_Type range 1 .. Count_Type'Last; type Node_Array is array (Index_Type range <>) of Node; procedure Free is new Ada.Unchecked_Deallocation (Key_Type, Key_Access); procedure Free is new Ada.Unchecked_Deallocation (Element_Type, Element_Access); type Backend_Array (Size : Index_Type) -- cannot be empty is new Ada.Finalization.Limited_Controlled with record Nodes : Node_Array (1 .. Size); Finalized : Boolean := False; end record; function Create (Size : Index_Type; Key_Factory : not null access function (Index : Index_Type) return Key_Type; Element_Factory : not null access function (Index : Index_Type) return Element_Type) return Backend_Array; overriding procedure Finalize (Object : in out Backend_Array); package Backend_Refs is new References (Backend_Array, Storage_Pools.Access_In_Default_Pool'Storage_Pool, Storage_Pools.Access_In_Default_Pool'Storage_Pool); function Make_Backend (Size : Count_Type; Key_Factory : not null access function (Index : Index_Type) return Key_Type; Element_Factory : not null access function (Index : Index_Type) return Element_Type) return Backend_Refs.Immutable_Reference; function Make_Backend (Map : Unsafe_Maps.Map) return Backend_Refs.Immutable_Reference; procedure Search (Nodes : in Node_Array; Key : in Key_Type; Floor : out Count_Type; Ceiling : out Count_Type); type Constant_Map is tagged record Backend : Backend_Refs.Immutable_Reference; end record; function Is_Empty (Container : Constant_Map) return Boolean is (Container.Backend.Is_Empty); type Updatable_Map is new Constant_Map with null record; type Cursor (Is_Empty : Boolean := True) is record case Is_Empty is when True => null; when False => Index : Index_Type; Backend : Backend_Refs.Immutable_Reference; end case; end record; function Is_Valid (Position : Cursor) return Boolean is (Position.Is_Empty or else (not Position.Backend.Is_Empty and then Position.Index <= Position.Backend.Query.Data.Size)); function Has_Element (Position : Cursor) return Boolean is (not Position.Is_Empty); function Is_Related (Container : Constant_Map; Position : Cursor) return Boolean is (Backend_Refs."=" (Container.Backend, Position.Backend)); type Constant_Reference_Type (Element : not null access constant Element_Type) is record Backend : Backend_Refs.Immutable_Reference; end record; type Reference_Type (Element : not null access Element_Type) is record Backend : Backend_Refs.Immutable_Reference; end record; type Iterator is new Map_Iterator_Interfaces.Reversible_Iterator with record Backend : Backend_Refs.Immutable_Reference; Start : Cursor := No_Element; end record; overriding function First (Object : Iterator) return Cursor; overriding function Last (Object : Iterator) return Cursor; overriding function Next (Object : Iterator; Position : Cursor) return Cursor is (Next (Position)) with Pre => Position.Is_Empty or else Backend_Refs."=" (Position.Backend, Object.Backend); overriding function Previous (Object : Iterator; Position : Cursor) return Cursor is (Previous (Position)) with Pre => Position.Is_Empty or else Backend_Refs."=" (Position.Backend, Object.Backend); type Range_Iterator is new Map_Iterator_Interfaces.Reversible_Iterator with record Backend : Backend_Refs.Immutable_Reference; First_Position : Cursor; Last_Position : Cursor; end record; -- with Dynamic_Predicate => not Range_Iterator.Backend.Is_Empty -- and then Has_Element (Range_Iterator.First_Position) -- and then Has_Element (Range_Iterator.Last_Position) -- and then not Range_Iterator.First_Position -- > Range_Iterator.Last_Position; overriding function First (Object : Range_Iterator) return Cursor; overriding function Last (Object : Range_Iterator) return Cursor; overriding function Next (Object : Range_Iterator; Position : Cursor) return Cursor with Pre => Position.Is_Empty or else Backend_Refs."=" (Position.Backend, Object.Backend); overriding function Previous (Object : Range_Iterator; Position : Cursor) return Cursor with Pre => Position.Is_Empty or else Backend_Refs."=" (Position.Backend, Object.Backend); Empty_Constant_Map : constant Constant_Map := (Backend => <>); Empty_Updatable_Map : constant Updatable_Map := (Backend => <>); No_Element : constant Cursor := (Is_Empty => True); end Natools.Constant_Indefinite_Ordered_Maps;
osannolik/ada-canopen
Ada
2,536
adb
package body ACO.Utils.DS.Generic_Protected_Queue is procedure Put_Blocking (This : in out Protected_Queue; Item : in Item_Type) is Success : Boolean; begin This.Buffer.Put (Item, Success); if not Success then Ada.Synchronous_Task_Control.Suspend_Until_True (This.Non_Full); This.Buffer.Put (Item, Success); end if; Ada.Synchronous_Task_Control.Set_True (This.Non_Empty); end Put_Blocking; procedure Put (This : in out Protected_Queue; Item : in Item_Type; Success : out Boolean) is begin This.Buffer.Put (Item, Success); end Put; procedure Get_Blocking (This : in out Protected_Queue; Item : out Item_Type) is Success : Boolean; begin This.Buffer.Get (Item, Success); if not Success then Ada.Synchronous_Task_Control.Suspend_Until_True (This.Non_Empty); This.Buffer.Get (Item, Success); end if; Ada.Synchronous_Task_Control.Set_True (This.Non_Full); end Get_Blocking; procedure Get (This : in out Protected_Queue; Item : out Item_Type) is Success : Boolean; begin This.Buffer.Get (Item, Success); Ada.Synchronous_Task_Control.Set_True (This.Non_Full); end Get; function Count (This : Protected_Queue) return Natural is begin return This.Buffer.Nof_Items; end Count; function Is_Empty (This : Protected_Queue) return Boolean is begin return This.Buffer.Nof_Items = 0; end Is_Empty; function Is_Full (This : Protected_Queue) return Boolean is begin return This.Buffer.Nof_Items >= Maximum_Nof_Items; end Is_Full; protected body Buffer_Type is procedure Put (Item : in Item_Type; Success : out Boolean) is begin if Queue.Is_Full then Success := False; else Success := True; Queue.Put (Item); end if; end Put; procedure Get (Item : out Item_Type; Success : out Boolean) is begin if Queue.Is_Empty then Success := False; else Success := True; Queue.Get (Item); end if; end Get; function Nof_Items return Natural is begin return Queue.Length; end Nof_Items; end Buffer_Type; end ACO.Utils.DS.Generic_Protected_Queue;
reznikmm/matreshka
Ada
6,880
adb
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- Open Document Toolkit -- -- -- -- Runtime Library Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2014, Vadim Godunko <[email protected]> -- -- All rights reserved. -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions -- -- are met: -- -- -- -- * Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- -- -- * Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in the -- -- documentation and/or other materials provided with the distribution. -- -- -- -- * Neither the name of the Vadim Godunko, IE nor the names of its -- -- contributors may be used to endorse or promote products derived from -- -- this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -- -- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED -- -- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -- -- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -- -- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -- -- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -- -- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- -- ------------------------------------------------------------------------------ -- $Revision$ $Date$ ------------------------------------------------------------------------------ with Matreshka.DOM_Documents; with Matreshka.ODF_String_Constants; with ODF.DOM.Iterators; with ODF.DOM.Visitors; package body Matreshka.ODF_Text.Description_Elements is ------------ -- Create -- ------------ overriding function Create (Parameters : not null access Matreshka.DOM_Elements.Element_L2_Parameters) return Text_Description_Element_Node is begin return Self : Text_Description_Element_Node do Matreshka.ODF_Text.Constructors.Initialize (Self'Unchecked_Access, Parameters.Document, Matreshka.ODF_String_Constants.Text_Prefix); end return; end Create; ---------------- -- Enter_Node -- ---------------- overriding procedure Enter_Node (Self : not null access Text_Description_Element_Node; Visitor : in out XML.DOM.Visitors.Abstract_Visitor'Class; Control : in out XML.DOM.Visitors.Traverse_Control) is begin if Visitor in ODF.DOM.Visitors.Abstract_ODF_Visitor'Class then ODF.DOM.Visitors.Abstract_ODF_Visitor'Class (Visitor).Enter_Text_Description (ODF.DOM.Text_Description_Elements.ODF_Text_Description_Access (Self), Control); else Matreshka.DOM_Elements.Abstract_Element_Node (Self.all).Enter_Node (Visitor, Control); end if; end Enter_Node; -------------------- -- Get_Local_Name -- -------------------- overriding function Get_Local_Name (Self : not null access constant Text_Description_Element_Node) return League.Strings.Universal_String is pragma Unreferenced (Self); begin return Matreshka.ODF_String_Constants.Description_Element; end Get_Local_Name; ---------------- -- Leave_Node -- ---------------- overriding procedure Leave_Node (Self : not null access Text_Description_Element_Node; Visitor : in out XML.DOM.Visitors.Abstract_Visitor'Class; Control : in out XML.DOM.Visitors.Traverse_Control) is begin if Visitor in ODF.DOM.Visitors.Abstract_ODF_Visitor'Class then ODF.DOM.Visitors.Abstract_ODF_Visitor'Class (Visitor).Leave_Text_Description (ODF.DOM.Text_Description_Elements.ODF_Text_Description_Access (Self), Control); else Matreshka.DOM_Elements.Abstract_Element_Node (Self.all).Leave_Node (Visitor, Control); end if; end Leave_Node; ---------------- -- Visit_Node -- ---------------- overriding procedure Visit_Node (Self : not null access Text_Description_Element_Node; Iterator : in out XML.DOM.Visitors.Abstract_Iterator'Class; Visitor : in out XML.DOM.Visitors.Abstract_Visitor'Class; Control : in out XML.DOM.Visitors.Traverse_Control) is begin if Iterator in ODF.DOM.Iterators.Abstract_ODF_Iterator'Class then ODF.DOM.Iterators.Abstract_ODF_Iterator'Class (Iterator).Visit_Text_Description (Visitor, ODF.DOM.Text_Description_Elements.ODF_Text_Description_Access (Self), Control); else Matreshka.DOM_Elements.Abstract_Element_Node (Self.all).Visit_Node (Iterator, Visitor, Control); end if; end Visit_Node; begin Matreshka.DOM_Documents.Register_Element (Matreshka.ODF_String_Constants.Text_URI, Matreshka.ODF_String_Constants.Description_Element, Text_Description_Element_Node'Tag); end Matreshka.ODF_Text.Description_Elements;
persan/protobuf-ada
Ada
31
ads
package Jspb is end Jspb;
OneWingedShark/Byron
Ada
2,022
ads
Pragma Ada_2012; Pragma Assertion_Policy( Check ); With Lexington.Aux, Lexington.Token_Set_Pkg, Lexington.Token_Vector_Pkg, Ada.Strings.Wide_Wide_Maps; Package Lexington.Search is --Parts is a structure for splitting a string into three parts. -- --Parts as a Return Value: -- String_1 holds the portion prior to the match, String_2 holds the found -- character, and String_3 holds the portion subsequent the match; if none -- of the characters in the set match, then String_1 will hold a copy of Text. -- --NOTE: This means that Len_2 /= 0 ≡ match-found, then if Len_3 = 0 then -- we know the given match was the last character in the string. Type Parts( Len_1, Len_2, Len_3 : Natural ) is record String_1 : Wide_Wide_String(1..Len_1); String_2 : Wide_Wide_String(1..Len_2); String_3 : Wide_Wide_String(1..Len_3); end record; --Run is a structure for indicating an arbitrary number of tokens. Type Run( Extant : Boolean; Distance : Natural ) is null record; Function Index( Text : Wide_Wide_String; From : Positive; Set : Ada.Strings.Wide_Wide_Maps.Wide_Wide_Character_Set ) return Natural; Function Index( Vector : Lexington.Token_Vector_Pkg.Vector; From : Positive; ID : Lexington.Aux.Token_ID ) return Natural; Function Split( Text : Wide_Wide_String; On : Ada.Strings.Wide_Wide_Maps.Wide_Wide_Character_Set ) return Parts; Function Split( Text, On : Wide_Wide_String ) return Parts; -- *-- Function Arbitrary( -- *-- Container : Token_Vector_Pkg.Vector; -- *-- Index : Positive; -- *-- Items : Token_Set_Pkg.Set -- *-- ) return Run; Type ID_Sequence is Array(Positive range <>) of Lexington.Aux.Token_ID; End Lexington.Search;
strenkml/EE368
Ada
3,552
ads
with Ada.Numerics.Discrete_Random; with Ada.Containers.Vectors; with Ada.Finalization; use Ada.Containers; use Ada.Finalization; with Memory; use Memory; with Util; use Util; -- Base package for benchmarks. package Benchmark is -- An exception that is raised when an invalid argument is -- provided to a benchmark. Invalid_Argument : exception; -- An exception that is raised when an address is out of the -- range of valid addresses. Invalid_Address : exception; -- The base data type for benchmarks. type Benchmark_Type is abstract new Limited_Controlled with private; type Benchmark_Pointer is access all Benchmark_Type'Class; -- Set an argument to the benchmark. -- Benchmarks that have additional arguments should override this -- procedure and call it only if no benchmark-specific arguments were -- recognized. procedure Set_Argument(benchmark : in out Benchmark_Type; arg : in String); -- Set the memory for the benchmark to use. procedure Set_Memory(benchmark : in out Benchmark_Type'Class; mem : in Memory_Pointer); -- Reset the memory and random number generator. procedure Reset(benchmark : in out Benchmark_Type'Class; context : in Natural); -- The body of the benchmark. procedure Run(benchmark : in Benchmark_Type) is abstract; -- Destroy the benchmark. procedure Destroy(benchmark : in out Benchmark_Pointer); private package Random is new Ada.Numerics.Discrete_Random(Natural); package Data_Vectors is new Vectors(Natural, Integer); type Data_Pointer is access all Data_Vectors.Vector; type Benchmark_Type is abstract new Limited_Controlled with record generator : Random.Generator; mem : Memory.Memory_Pointer; data : Data_Pointer := null; spacing : Time_Type := 0; seed : Integer := 15; max_addr : Address_Type := 0; end record; overriding procedure Initialize(benchmark : in out Benchmark_Type); overriding procedure Finalize(benchmark : in out Benchmark_Type); -- Check if argument in arg matches name. -- This will '=' and all folloing characters in arg. function Check_Argument(arg : String; name : String) return Boolean; -- Extract the value from an argument (the part following '='). function Extract_Argument(arg : String) return String; -- Get a random number. function Get_Random(benchmark : Benchmark_Type'Class) return Natural; -- Simulate a memory read and return the integer stored at the address. function Read_Value(benchmark : Benchmark_Type'Class; address : Natural) return Integer; -- Simulate a memory write and set an integer to be stored at the address. procedure Write_Value(benchmark : in Benchmark_Type'Class; address : in Natural; value : in Integer); -- Simulate a memory read. procedure Read(benchmark : in Benchmark_Type'Class; address : in Address_Type; size : in Positive); -- Simulate a memory write. procedure Write(benchmark : in Benchmark_Type'Class; address : in Address_Type; size : in Positive); -- Simulate idle cycles. procedure Idle(benchmark : in Benchmark_Type'Class; cycles : in Time_Type); end Benchmark;
burratoo/Acton
Ada
1,327
ads
------------------------------------------------------------------------------ -- -- -- ACTON SCHEDULER AGENT -- -- -- -- ACTON.SCHEDULER_AGENTS.FIFO_WITHIN_PRIORITIES -- -- -- -- S p e c -- -- -- -- Copyright (C) 2010-2014, Patrick Bernardi -- ------------------------------------------------------------------------------ pragma Restrictions (No_Elaboration_Code); with Oak.Agent; use Oak.Agent; with System; use System; package Acton.Scheduler_Agents.FIFO_Within_Priorities_GNATBB with Preelaborate is procedure New_Scheduler_Agent (Agent : out Scheduler_Id; Min_Priority : in Any_Priority; Max_Priority : in Any_Priority); Agent_Name : constant String := "Fixed_Priority_Scheduler_Basic"; Stack_Size : constant := 1 * 1024; private end Acton.Scheduler_Agents.FIFO_Within_Priorities_GNATBB;
AdaCore/training_material
Ada
756
ads
with Sort_Types; use Sort_Types; package Sort is function Is_Sorted (Values : Nat_Array; From, To : Index) return Boolean is (for all I in From .. To - 1 => Values (I) <= Values (I + 1)) with Ghost; function Is_Sorted (Values : Nat_Array) return Boolean is (Is_Sorted (Values, Values'First, Values'Last)) with Ghost; Permutation : Permut_Array with Ghost; function Is_Perm (Left, Right : Nat_Array) return Boolean is (Is_Permutation_Array (Permutation) and then (for all J in Index => Right (J) = Left (Permutation (J)))) with Ghost; procedure Selection_Sort (Values : in out Nat_Array) with Post => Is_Sorted (Values) and then Is_Perm (Values'Old, Values); end Sort;
reznikmm/matreshka
Ada
3,709
ads
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- Open Document Toolkit -- -- -- -- Runtime Library Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2014, Vadim Godunko <[email protected]> -- -- All rights reserved. -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions -- -- are met: -- -- -- -- * Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- -- -- * Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in the -- -- documentation and/or other materials provided with the distribution. -- -- -- -- * Neither the name of the Vadim Godunko, IE nor the names of its -- -- contributors may be used to endorse or promote products derived from -- -- this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -- -- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED -- -- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -- -- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -- -- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -- -- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -- -- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- -- ------------------------------------------------------------------------------ -- $Revision$ $Date$ ------------------------------------------------------------------------------ with XML.DOM.Attributes; package ODF.DOM.Draw_Nav_Order_Attributes is pragma Preelaborate; type ODF_Draw_Nav_Order_Attribute is limited interface and XML.DOM.Attributes.DOM_Attribute; type ODF_Draw_Nav_Order_Attribute_Access is access all ODF_Draw_Nav_Order_Attribute'Class with Storage_Size => 0; end ODF.DOM.Draw_Nav_Order_Attributes;
kraileth/ravensource
Ada
472
adb
--- tools/configure/configure-tests-mysql.adb.orig 2021-08-30 10:37:26 UTC +++ tools/configure/configure-tests-mysql.adb @@ -223,7 +223,7 @@ package body Configure.Tests.MySQL is (MySQL_Library_Options, +"""-L" & Self.Switches.Libdir - & """, ""-lmysqlclient_r"""); + & """, ""-lmysqlclient_r"", ""-Wl,-rpath,@PREFIX@/lib/mysql"""); Self.Report_Status ("yes (command line)");
charlie5/lace
Ada
3,856
ads
with interfaces.C, System; package Freetype_C -- -- Provides core types for the Freetype C library. -- is use Interfaces; -- FT_UShort -- subtype FT_UShort is C.unsigned_short; type FT_UShort_array is array (C.Size_t range <>) of aliased FT_UShort; -- FT_Int -- subtype FT_Int is C.int; type FT_Int_array is array (C.Size_t range <>) of aliased FT_Int; -- FT_UInt -- subtype FT_UInt is C.unsigned; type FT_UInt_array is array (C.Size_t range <>) of aliased FT_UInt; -- FT_Long -- subtype FT_Long is C.long; type FT_Long_array is array (C.Size_t range <>) of aliased FT_Long; -- FT_ULong -- subtype FT_ULong is C.unsigned_long; type FT_ULong_array is array (C.Size_t range <>) of aliased FT_ULong; -- FT_Fixed -- subtype FT_Fixed is C.long; type FT_Fixed_array is array (C.Size_t range <>) of aliased FT_Fixed; -- FT_Pos -- subtype FT_Pos is C.long; type FT_Pos_array is array (C.Size_t range <>) of aliased FT_Pos; -- FT_Error -- subtype FT_Error is C.int; type FT_Error_array is array (C.Size_t range <>) of aliased FT_Error; -- FT_Encoding -- subtype FT_Encoding is C.unsigned; type FT_Encoding_array is array (C.Size_t range <>) of aliased FT_Encoding; -- FT_F26Dot6 -- subtype FT_F26Dot6 is C.long; type FT_F26Dot6_array is array (C.Size_t range <>) of aliased FT_F26Dot6; -- FT_Int32 -- subtype FT_Int32 is C.int; type FT_Int32_array is array (C.Size_t range <>) of aliased FT_Int32; -- FT_UInt32 -- subtype FT_UInt32 is C.unsigned; type FT_UInt32_array is array (C.Size_t range <>) of aliased FT_UInt32; -- FT_Render_Mode -- type FT_Render_Mode is (FT_RENDER_MODE_NORMAL, FT_RENDER_MODE_LIGHT, FT_RENDER_MODE_MONO, FT_RENDER_MODE_LCD, FT_RENDER_MODE_LCD_V, FT_RENDER_MODE_MAX); type FT_Render_Mode_array is array (C.Size_t range <>) of aliased FT_Render_Mode; -- FT_Outline -- subtype FT_Outline is System.Address; type FT_Outline_array is array (C.Size_t range <>) of aliased FT_Outline; -- FT_LibraryRec -- subtype FT_LibraryRec is System.Address; type FT_LibraryRec_array is array (C.Size_t range <>) of aliased FT_LibraryRec; -- FT_GlyphSlotRec -- subtype FT_GlyphSlotRec is System.Address; type FT_GlyphSlotRec_array is array (C.Size_t range <>) of aliased FT_GlyphSlotRec; -- FT_FaceRec -- subtype FT_FaceRec is System.Address; type FT_FaceRec_array is array (C.Size_t range <>) of aliased FT_FaceRec; -- FT_Kerning_Mode -- type FT_Kerning_Mode is (FT_KERNING_DEFAULT, FT_KERNING_UNFITTED, FT_KERNING_UNSCALED); type FT_Kerning_Mode_array is array (C.Size_t range <>) of aliased FT_Kerning_Mode; -- FT_SizeRec -- subtype FT_SizeRec is System.Address; type FT_SizeRec_array is array (C.Size_t range <>) of aliased FT_SizeRec; private for FT_Render_Mode use (FT_RENDER_MODE_NORMAL => 0, FT_RENDER_MODE_LIGHT => 1, FT_RENDER_MODE_MONO => 2, FT_RENDER_MODE_LCD => 3, FT_RENDER_MODE_LCD_V => 4, FT_RENDER_MODE_MAX => 5); pragma Convention (C, FT_Render_Mode); for FT_Kerning_Mode use (FT_KERNING_DEFAULT => 0, FT_KERNING_UNFITTED => 1, FT_KERNING_UNSCALED => 2); pragma Convention (C, FT_Kerning_Mode); end Freetype_C;
stcarrez/hestia
Ada
2,705
adb
----------------------------------------------------------------------- -- hestia-main -- Hestia main program -- Copyright (C) 2016, 2017, 2018 Stephane Carrez -- Written by Stephane Carrez ([email protected]) -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. ----------------------------------------------------------------------- with Ada.Real_Time; with STM32.Board; with HAL.Bitmap; with UI.Displays; with Hestia.Network; with Hestia.Display.Instances; with Hestia.Ports; -- The main EtherScope task must run at a lower priority as it takes care -- of displaying results on the screen while the EtherScope receiver's task -- waits for packets and analyzes them. All the hardware initialization must -- be done here because STM32.SDRAM is not protected against concurrent accesses. procedure Hestia.Main is -- with Priority => System.Priority'First is use type Ada.Real_Time.Time; use type Ada.Real_Time.Time_Span; -- Display refresh period. REFRESH_PERIOD : constant Ada.Real_Time.Time_Span := Ada.Real_Time.Milliseconds (500); -- The network processing deadline. Net_Deadline : Ada.Real_Time.Time; begin -- Initialize the display and draw the main/fixed frames in both buffers. UI.Displays.Initialize; Hestia.Ports.Initialize; -- Initialize and start the network stack. Hestia.Network.Initialize; UI.Displays.Push_Display (Hestia.Display.Instances.Display'Access); -- Loop to retrieve the analysis and display them. loop declare Now : constant Ada.Real_Time.Time := Ada.Real_Time.Clock; Buffer : constant HAL.Bitmap.Any_Bitmap_Buffer := STM32.Board.Display.Hidden_Buffer (1); Display : UI.Displays.Display_Access := UI.Displays.Current_Display; begin Display.Process_Event (Buffer.all, Now); -- Refresh the display only when it needs. Display := UI.Displays.Current_Display; if Display.Need_Refresh (Now) then Display.Refresh (Buffer.all); end if; Hestia.Network.Process (Net_Deadline); delay until Now + Ada.Real_Time.Milliseconds (100); end; end loop; end Hestia.Main;
pdaxrom/Kino2
Ada
5,711
adb
------------------------------------------------------------------------------ -- -- -- GNAT ncurses Binding Samples -- -- -- -- Sample.Curses_Demo.Attributes -- -- -- -- B O D Y -- -- -- ------------------------------------------------------------------------------ -- Copyright (c) 1998 Free Software Foundation, Inc. -- -- -- -- Permission is hereby granted, free of charge, to any person obtaining a -- -- copy of this software and associated documentation files (the -- -- "Software"), to deal in the Software without restriction, including -- -- without limitation the rights to use, copy, modify, merge, publish, -- -- distribute, distribute with modifications, sublicense, and/or sell -- -- copies of the Software, and to permit persons to whom the Software is -- -- furnished to do so, subject to the following conditions: -- -- -- -- The above copyright notice and this permission notice shall be included -- -- in all copies or substantial portions of the Software. -- -- -- -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -- -- OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -- -- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -- -- IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -- -- DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -- -- OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR -- -- THE USE OR OTHER DEALINGS IN THE SOFTWARE. -- -- -- -- Except as contained in this notice, the name(s) of the above copyright -- -- holders shall not be used in advertising or otherwise to promote the -- -- sale, use or other dealings in this Software without prior written -- -- authorization. -- ------------------------------------------------------------------------------ -- Author: Juergen Pfeifer, 1996 -- Contact: http://www.familiepfeifer.de/Contact.aspx?Lang=en -- Version Control -- $Revision: 1.11 $ -- Binding Version 01.00 ------------------------------------------------------------------------------ with Terminal_Interface.Curses; use Terminal_Interface.Curses; with Terminal_Interface.Curses.Panels; use Terminal_Interface.Curses.Panels; with Sample.Manifest; use Sample.Manifest; with Sample.Function_Key_Setting; use Sample.Function_Key_Setting; with Sample.Keyboard_Handler; use Sample.Keyboard_Handler; with Sample.Explanation; use Sample.Explanation; package body Sample.Curses_Demo.Attributes is procedure Demo is P : Panel := Create (Standard_Window); K : Real_Key_Code; begin Set_Meta_Mode; Set_KeyPad_Mode; Top (P); Push_Environment ("ATTRIBDEMO"); Default_Labels; Notepad ("ATTRIB-PAD00"); Set_Character_Attributes (Attr => (others => False)); Add (Line => 1, Column => Columns / 2 - 10, Str => "This is NORMAL"); Set_Character_Attributes (Attr => (Stand_Out => True, others => False)); Add (Line => 2, Column => Columns / 2 - 10, Str => "This is Stand_Out"); Set_Character_Attributes (Attr => (Under_Line => True, others => False)); Add (Line => 3, Column => Columns / 2 - 10, Str => "This is Under_Line"); Set_Character_Attributes (Attr => (Reverse_Video => True, others => False)); Add (Line => 4, Column => Columns / 2 - 10, Str => "This is Reverse_Video"); Set_Character_Attributes (Attr => (Blink => True, others => False)); Add (Line => 5, Column => Columns / 2 - 10, Str => "This is Blink"); Set_Character_Attributes (Attr => (Dim_Character => True, others => False)); Add (Line => 6, Column => Columns / 2 - 10, Str => "This is Dim_Character"); Set_Character_Attributes (Attr => (Bold_Character => True, others => False)); Add (Line => 7, Column => Columns / 2 - 10, Str => "This is Bold_Character"); Refresh_Without_Update; Update_Panels; Update_Screen; loop K := Get_Key; if K in Special_Key_Code'Range then case K is when QUIT_CODE => exit; when HELP_CODE => Explain_Context; when EXPLAIN_CODE => Explain ("ATTRIBKEYS"); when others => null; end case; end if; end loop; Pop_Environment; Clear; Refresh_Without_Update; Delete (P); Update_Panels; Update_Screen; end Demo; end Sample.Curses_Demo.Attributes;
zhmu/ananas
Ada
22,989
adb
------------------------------------------------------------------------------ -- -- -- GNAT RUN-TIME COMPONENTS -- -- -- -- ADA.NUMERICS.BIG_NUMBERS.BIG_REALS -- -- -- -- B o d y -- -- -- -- Copyright (C) 2019-2022, Free Software Foundation, Inc. -- -- -- -- GNAT is free software; you can redistribute it and/or modify it under -- -- terms of the GNU General Public License as published by the Free Soft- -- -- ware Foundation; either version 3, or (at your option) any later ver- -- -- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- -- or FITNESS FOR A PARTICULAR PURPOSE. -- -- -- -- As a special exception under Section 7 of GPL version 3, you are granted -- -- additional permissions described in the GCC Runtime Library Exception, -- -- version 3.1, as published by the Free Software Foundation. -- -- -- -- You should have received a copy of the GNU General Public License and -- -- a copy of the GCC Runtime Library Exception along with this program; -- -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- -- <http://www.gnu.org/licenses/>. -- -- -- -- GNAT was originally developed by the GNAT team at New York University. -- -- Extensive contributions were provided by Ada Core Technologies Inc. -- -- -- ------------------------------------------------------------------------------ with System.Unsigned_Types; use System.Unsigned_Types; package body Ada.Numerics.Big_Numbers.Big_Reals is use Big_Integers; procedure Normalize (Arg : in out Big_Real); -- Normalize Arg by ensuring that Arg.Den is always positive and that -- Arg.Num and Arg.Den always have a GCD of 1. -------------- -- Is_Valid -- -------------- function Is_Valid (Arg : Big_Real) return Boolean is (Is_Valid (Arg.Num) and Is_Valid (Arg.Den)); --------- -- "/" -- --------- function "/" (Num, Den : Valid_Big_Integer) return Valid_Big_Real is Result : Big_Real; begin if Den = To_Big_Integer (0) then raise Constraint_Error with "divide by zero"; end if; Result.Num := Num; Result.Den := Den; Normalize (Result); return Result; end "/"; --------------- -- Numerator -- --------------- function Numerator (Arg : Valid_Big_Real) return Valid_Big_Integer is (Arg.Num); ----------------- -- Denominator -- ----------------- function Denominator (Arg : Valid_Big_Real) return Big_Positive is (Arg.Den); --------- -- "=" -- --------- function "=" (L, R : Valid_Big_Real) return Boolean is (L.Num = R.Num and then L.Den = R.Den); --------- -- "<" -- --------- function "<" (L, R : Valid_Big_Real) return Boolean is (L.Num * R.Den < R.Num * L.Den); -- The denominator is guaranteed to be positive since Normalized is -- always called when constructing a Valid_Big_Real ---------- -- "<=" -- ---------- function "<=" (L, R : Valid_Big_Real) return Boolean is (not (R < L)); --------- -- ">" -- --------- function ">" (L, R : Valid_Big_Real) return Boolean is (R < L); ---------- -- ">=" -- ---------- function ">=" (L, R : Valid_Big_Real) return Boolean is (not (L < R)); ----------------------- -- Float_Conversions -- ----------------------- package body Float_Conversions is package Conv is new Big_Integers.Unsigned_Conversions (Long_Long_Unsigned); ----------------- -- To_Big_Real -- ----------------- -- We get the fractional representation of the floating-point number by -- multiplying Num'Fraction by 2.0**M, with M the size of the mantissa, -- which gives zero or a number in the range [2.0**(M-1)..2.0**M), which -- means that it is an integer N of M bits. The floating-point number is -- thus equal to N / 2**(M-E) where E is its Num'Exponent. function To_Big_Real (Arg : Num) return Valid_Big_Real is A : constant Num'Base := abs (Arg); E : constant Integer := Num'Exponent (A); F : constant Num'Base := Num'Fraction (A); M : constant Natural := Num'Machine_Mantissa; N, D : Big_Integer; begin pragma Assert (Num'Machine_Radix = 2); -- This implementation does not handle radix 16 pragma Assert (M <= 64); -- This implementation handles only 80-bit IEEE Extended or smaller N := Conv.To_Big_Integer (Long_Long_Unsigned (F * 2.0**M)); -- If E is smaller than M, the denominator is 2**(M-E) if E < M then D := To_Big_Integer (2) ** (M - E); -- Or else, if E is larger than M, multiply the numerator by 2**(E-M) elsif E > M then N := N * To_Big_Integer (2) ** (E - M); D := To_Big_Integer (1); -- Otherwise E is equal to M and the result is just N else D := To_Big_Integer (1); end if; return (if Arg >= 0.0 then N / D else -N / D); end To_Big_Real; ------------------- -- From_Big_Real -- ------------------- -- We get the (Frac, Exp) representation of the real number by finding -- the exponent E such that it lies in the range [2.0**(E-1)..2.0**E), -- multiplying the number by 2.0**(M-E) with M the size of the mantissa, -- and converting the result to integer N in the range [2**(M-1)..2**M) -- with rounding to nearest, ties to even, and finally call Num'Compose. -- This does not apply to the zero, for which we return 0.0 early. function From_Big_Real (Arg : Big_Real) return Num is M : constant Natural := Num'Machine_Mantissa; One : constant Big_Real := To_Real (1); Two : constant Big_Real := To_Real (2); Half : constant Big_Real := One / Two; TwoI : constant Big_Integer := To_Big_Integer (2); function Log2_Estimate (V : Big_Real) return Natural; -- Return an integer not larger than Log2 (V) for V >= 1.0 function Minus_Log2_Estimate (V : Big_Real) return Natural; -- Return an integer not larger than -Log2 (V) for V < 1.0 ------------------- -- Log2_Estimate -- ------------------- function Log2_Estimate (V : Big_Real) return Natural is Log : Natural := 1; Pow : Big_Real := Two; begin while V >= Pow loop Pow := Pow * Pow; Log := Log + Log; end loop; return Log / 2; end Log2_Estimate; ------------------------- -- Minus_Log2_Estimate -- ------------------------- function Minus_Log2_Estimate (V : Big_Real) return Natural is Log : Natural := 1; Pow : Big_Real := Half; begin while V <= Pow loop Pow := Pow * Pow; Log := Log + Log; end loop; return Log / 2; end Minus_Log2_Estimate; -- Local variables V : Big_Real := abs (Arg); E : Integer := 0; L : Integer; A, B, Q, X : Big_Integer; N : Long_Long_Unsigned; R : Num'Base; begin pragma Assert (Num'Machine_Radix = 2); -- This implementation does not handle radix 16 pragma Assert (M <= 64); -- This implementation handles only 80-bit IEEE Extended or smaller -- Protect from degenerate case if Numerator (V) = To_Big_Integer (0) then return 0.0; end if; -- Use a binary search to compute exponent E while V < Half loop L := Minus_Log2_Estimate (V); V := V * (Two ** L); E := E - L; end loop; -- The dissymetry with above is expected since we go below 2 while V >= One loop L := Log2_Estimate (V) + 1; V := V / (Two ** L); E := E + L; end loop; -- The multiplication by 2.0**(-E) has already been done in the loops V := V * To_Big_Real (TwoI ** M); -- Now go into the integer domain and divide A := Numerator (V); B := Denominator (V); Q := A / B; N := Conv.From_Big_Integer (Q); -- Round to nearest, ties to even, by comparing twice the remainder X := (A - Q * B) * TwoI; if X > B or else (X = B and then (N mod 2) = 1) then N := N + 1; -- If the adjusted quotient overflows the mantissa, scale up if N = 2**M then N := 1; E := E + 1; end if; end if; R := Num'Compose (Num'Base (N), E); return (if Numerator (Arg) >= To_Big_Integer (0) then R else -R); end From_Big_Real; end Float_Conversions; ----------------------- -- Fixed_Conversions -- ----------------------- package body Fixed_Conversions is package Float_Aux is new Float_Conversions (Long_Float); subtype LLLI is Long_Long_Long_Integer; subtype LLLU is Long_Long_Long_Unsigned; Too_Large : constant Boolean := Num'Small_Numerator > LLLU'Last or else Num'Small_Denominator > LLLU'Last; -- True if the Small is too large for Long_Long_Long_Unsigned, in which -- case we convert to/from Long_Float as an intermediate step. package Conv_I is new Big_Integers.Signed_Conversions (LLLI); package Conv_U is new Big_Integers.Unsigned_Conversions (LLLU); ----------------- -- To_Big_Real -- ----------------- -- We just compute V * N / D where V is the mantissa value of the fixed -- point number, and N resp. D is the numerator resp. the denominator of -- the Small of the fixed-point type. function To_Big_Real (Arg : Num) return Valid_Big_Real is N, D, V : Big_Integer; begin if Too_Large then return Float_Aux.To_Big_Real (Long_Float (Arg)); end if; N := Conv_U.To_Big_Integer (Num'Small_Numerator); D := Conv_U.To_Big_Integer (Num'Small_Denominator); V := Conv_I.To_Big_Integer (LLLI'Integer_Value (Arg)); return V * N / D; end To_Big_Real; ------------------- -- From_Big_Real -- ------------------- -- We first compute A / B = Arg * D / N where N resp. D is the numerator -- resp. the denominator of the Small of the fixed-point type. Then we -- divide A by B and convert the result to the mantissa value. function From_Big_Real (Arg : Big_Real) return Num is N, D, A, B, Q, X : Big_Integer; begin if Too_Large then return Num (Float_Aux.From_Big_Real (Arg)); end if; N := Conv_U.To_Big_Integer (Num'Small_Numerator); D := Conv_U.To_Big_Integer (Num'Small_Denominator); A := Numerator (Arg) * D; B := Denominator (Arg) * N; Q := A / B; -- Round to nearest, ties to away, by comparing twice the remainder X := (A - Q * B) * To_Big_Integer (2); if X >= B then Q := Q + To_Big_Integer (1); elsif X <= -B then Q := Q - To_Big_Integer (1); end if; return Num'Fixed_Value (Conv_I.From_Big_Integer (Q)); end From_Big_Real; end Fixed_Conversions; --------------- -- To_String -- --------------- function To_String (Arg : Valid_Big_Real; Fore : Field := 2; Aft : Field := 3; Exp : Field := 0) return String is Zero : constant Big_Integer := To_Big_Integer (0); Ten : constant Big_Integer := To_Big_Integer (10); function Leading_Padding (Str : String; Min_Length : Field; Char : Character := ' ') return String; -- Return padding of Char concatenated with Str so that the resulting -- string is at least Min_Length long. function Trailing_Padding (Str : String; Length : Field; Char : Character := '0') return String; -- Return Str with trailing Char removed, and if needed either -- truncated or concatenated with padding of Char so that the resulting -- string is Length long. function Image (N : Natural) return String; -- Return image of N, with no leading space. function Numerator_Image (Num : Big_Integer; After : Natural) return String; -- Return image of Num as a float value with After digits after the "." -- and taking Fore, Aft, Exp into account. ----------- -- Image -- ----------- function Image (N : Natural) return String is S : constant String := Natural'Image (N); begin return S (2 .. S'Last); end Image; --------------------- -- Leading_Padding -- --------------------- function Leading_Padding (Str : String; Min_Length : Field; Char : Character := ' ') return String is begin if Str = "" then return Leading_Padding ("0", Min_Length, Char); else return [1 .. Integer'Max (Integer (Min_Length) - Str'Length, 0) => Char] & Str; end if; end Leading_Padding; ---------------------- -- Trailing_Padding -- ---------------------- function Trailing_Padding (Str : String; Length : Field; Char : Character := '0') return String is begin if Str'Length > 0 and then Str (Str'Last) = Char then for J in reverse Str'Range loop if Str (J) /= '0' then return Trailing_Padding (Str (Str'First .. J), Length, Char); end if; end loop; end if; if Str'Length >= Length then return Str (Str'First .. Str'First + Length - 1); else return Str & [1 .. Integer'Max (Integer (Length) - Str'Length, 0) => Char]; end if; end Trailing_Padding; --------------------- -- Numerator_Image -- --------------------- function Numerator_Image (Num : Big_Integer; After : Natural) return String is Tmp : constant String := To_String (Num); Str : constant String (1 .. Tmp'Last - 1) := Tmp (2 .. Tmp'Last); Index : Integer; begin if After = 0 then return Leading_Padding (Str, Fore) & "." & Trailing_Padding ("0", Aft); else Index := Str'Last - After; if Index < 0 then return Leading_Padding ("0", Fore) & "." & Trailing_Padding ([1 .. -Index => '0'] & Str, Aft) & (if Exp = 0 then "" else "E+" & Image (Natural (Exp))); else return Leading_Padding (Str (Str'First .. Index), Fore) & "." & Trailing_Padding (Str (Index + 1 .. Str'Last), Aft) & (if Exp = 0 then "" else "E+" & Image (Natural (Exp))); end if; end if; end Numerator_Image; begin if Arg.Num < Zero then declare Str : String := To_String (-Arg, Fore, Aft, Exp); begin if Str (1) = ' ' then for J in 1 .. Str'Last - 1 loop if Str (J + 1) /= ' ' then Str (J) := '-'; exit; end if; end loop; return Str; else return '-' & Str; end if; end; else -- Compute Num * 10^Aft so that we get Aft significant digits -- in the integer part (rounded) to display. return Numerator_Image ((Arg.Num * Ten ** Aft) / Arg.Den, After => Exp + Aft); end if; end To_String; ----------------- -- From_String -- ----------------- function From_String (Arg : String) return Valid_Big_Real is Ten : constant Big_Integer := To_Big_Integer (10); Frac : Big_Integer; Exp : Integer := 0; Pow : Natural := 0; Index : Natural := 0; Last : Natural := Arg'Last; begin for J in reverse Arg'Range loop if Arg (J) in 'e' | 'E' then if Last /= Arg'Last then raise Constraint_Error with "multiple exponents specified"; end if; Last := J - 1; Exp := Integer'Value (Arg (J + 1 .. Arg'Last)); Pow := 0; elsif Arg (J) = '.' then Index := J - 1; exit; elsif Arg (J) /= '_' then Pow := Pow + 1; end if; end loop; if Index = 0 then raise Constraint_Error with "invalid real value"; end if; declare Result : Big_Real; begin Result.Den := Ten ** Pow; Result.Num := From_String (Arg (Arg'First .. Index)) * Result.Den; Frac := From_String (Arg (Index + 2 .. Last)); if Result.Num < To_Big_Integer (0) then Result.Num := Result.Num - Frac; else Result.Num := Result.Num + Frac; end if; if Exp > 0 then Result.Num := Result.Num * Ten ** Exp; elsif Exp < 0 then Result.Den := Result.Den * Ten ** (-Exp); end if; Normalize (Result); return Result; end; end From_String; -------------------------- -- From_Quotient_String -- -------------------------- function From_Quotient_String (Arg : String) return Valid_Big_Real is Index : Natural := 0; begin for J in Arg'First + 1 .. Arg'Last - 1 loop if Arg (J) = '/' then Index := J; exit; end if; end loop; if Index = 0 then raise Constraint_Error with "no quotient found"; end if; return Big_Integers.From_String (Arg (Arg'First .. Index - 1)) / Big_Integers.From_String (Arg (Index + 1 .. Arg'Last)); end From_Quotient_String; --------------- -- Put_Image -- --------------- procedure Put_Image (S : in out Root_Buffer_Type'Class; V : Big_Real) is -- This is implemented in terms of To_String. It might be more elegant -- and more efficient to do it the other way around, but this is the -- most expedient implementation for now. begin Strings.Text_Buffers.Put_UTF_8 (S, To_String (V)); end Put_Image; --------- -- "+" -- --------- function "+" (L : Valid_Big_Real) return Valid_Big_Real is Result : Big_Real; begin Result.Num := L.Num; Result.Den := L.Den; return Result; end "+"; --------- -- "-" -- --------- function "-" (L : Valid_Big_Real) return Valid_Big_Real is (Num => -L.Num, Den => L.Den); ----------- -- "abs" -- ----------- function "abs" (L : Valid_Big_Real) return Valid_Big_Real is (Num => abs L.Num, Den => L.Den); --------- -- "+" -- --------- function "+" (L, R : Valid_Big_Real) return Valid_Big_Real is Result : Big_Real; begin Result.Num := L.Num * R.Den + R.Num * L.Den; Result.Den := L.Den * R.Den; Normalize (Result); return Result; end "+"; --------- -- "-" -- --------- function "-" (L, R : Valid_Big_Real) return Valid_Big_Real is Result : Big_Real; begin Result.Num := L.Num * R.Den - R.Num * L.Den; Result.Den := L.Den * R.Den; Normalize (Result); return Result; end "-"; --------- -- "*" -- --------- function "*" (L, R : Valid_Big_Real) return Valid_Big_Real is Result : Big_Real; begin Result.Num := L.Num * R.Num; Result.Den := L.Den * R.Den; Normalize (Result); return Result; end "*"; --------- -- "/" -- --------- function "/" (L, R : Valid_Big_Real) return Valid_Big_Real is Result : Big_Real; begin Result.Num := L.Num * R.Den; Result.Den := L.Den * R.Num; Normalize (Result); return Result; end "/"; ---------- -- "**" -- ---------- function "**" (L : Valid_Big_Real; R : Integer) return Valid_Big_Real is Result : Big_Real; begin if R = 0 then Result.Num := To_Big_Integer (1); Result.Den := To_Big_Integer (1); else if R < 0 then Result.Num := L.Den ** (-R); Result.Den := L.Num ** (-R); else Result.Num := L.Num ** R; Result.Den := L.Den ** R; end if; Normalize (Result); end if; return Result; end "**"; --------- -- Min -- --------- function Min (L, R : Valid_Big_Real) return Valid_Big_Real is (if L < R then L else R); --------- -- Max -- --------- function Max (L, R : Valid_Big_Real) return Valid_Big_Real is (if L > R then L else R); --------------- -- Normalize -- --------------- procedure Normalize (Arg : in out Big_Real) is Zero : constant Big_Integer := To_Big_Integer (0); begin if Arg.Den < Zero then Arg.Num := -Arg.Num; Arg.Den := -Arg.Den; end if; if Arg.Num = Zero then Arg.Den := To_Big_Integer (1); else declare GCD : constant Big_Integer := Greatest_Common_Divisor (Arg.Num, Arg.Den); begin Arg.Num := Arg.Num / GCD; Arg.Den := Arg.Den / GCD; end; end if; end Normalize; end Ada.Numerics.Big_Numbers.Big_Reals;
charlie5/cBound
Ada
1,652
ads
-- This file is generated by SWIG. Please do not modify by hand. -- with Interfaces; with Interfaces.C; with Interfaces.C.Pointers; package xcb.xcb_glx_query_extensions_string_request_t is -- Item -- type Item is record major_opcode : aliased Interfaces.Unsigned_8; minor_opcode : aliased Interfaces.Unsigned_8; length : aliased Interfaces.Unsigned_16; screen : aliased Interfaces.Unsigned_32; end record; -- Item_Array -- type Item_Array is array (Interfaces.C .size_t range <>) of aliased xcb .xcb_glx_query_extensions_string_request_t .Item; -- Pointer -- package C_Pointers is new Interfaces.C.Pointers (Index => Interfaces.C.size_t, Element => xcb.xcb_glx_query_extensions_string_request_t.Item, Element_Array => xcb.xcb_glx_query_extensions_string_request_t.Item_Array, Default_Terminator => (others => <>)); subtype Pointer is C_Pointers.Pointer; -- Pointer_Array -- type Pointer_Array is array (Interfaces.C .size_t range <>) of aliased xcb .xcb_glx_query_extensions_string_request_t .Pointer; -- Pointer_Pointer -- package C_Pointer_Pointers is new Interfaces.C.Pointers (Index => Interfaces.C.size_t, Element => xcb.xcb_glx_query_extensions_string_request_t.Pointer, Element_Array => xcb.xcb_glx_query_extensions_string_request_t.Pointer_Array, Default_Terminator => null); subtype Pointer_Pointer is C_Pointer_Pointers.Pointer; end xcb.xcb_glx_query_extensions_string_request_t;
AaronC98/PlaneSystem
Ada
3,908
adb
------------------------------------------------------------------------------ -- Ada Web Server -- -- -- -- Copyright (C) 2003-2015, AdaCore -- -- -- -- This library is free software; you can redistribute it and/or modify -- -- it under terms of the GNU General Public License as published by the -- -- Free Software Foundation; either version 3, or (at your option) any -- -- later version. This library is distributed in the hope that it will be -- -- useful, but WITHOUT ANY WARRANTY; without even the implied warranty of -- -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -- -- -- -- -- -- -- -- -- -- -- -- 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/>. -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- ------------------------------------------------------------------------------ with Ada.Unchecked_Conversion; with Interfaces.C; with AWS.Net.SSL.Certificate.Impl; package body AWS.Net.SSL.Certificate is Pwd_Callback : Password_Callback; --------- -- Get -- --------- function Get (Socket : Socket_Type) return Object is begin return Impl.Get (Socket); end Get; ------------------ -- Get_Password -- ------------------ function Get_Password (Certificate_Filename : String) return String is begin if Pwd_Callback = null then return ""; else return Pwd_Callback (Certificate_Filename); end if; end Get_Password; ---------- -- Load -- ---------- function Load (Filename : String) return Object is begin return Impl.Load (Filename); end Load; --------------------------- -- Set_Password_Callback -- --------------------------- procedure Set_Password_Callback (Callback : Password_Callback) is begin Pwd_Callback := Callback; end Set_Password_Callback; ------------------------- -- Set_Verify_Callback -- ------------------------- procedure Set_Verify_Callback (Config : in out SSL.Config; Callback : Verify_Callback) is function To_Address is new Unchecked_Conversion (Net.SSL.Certificate.Verify_Callback, System.Address); begin Set_Verify_Callback (Config, To_Address (Callback)); end Set_Verify_Callback; -------------------- -- Status_Message -- -------------------- function Status_Message (Certificate : Object) return String is begin return Impl.Status_String (Interfaces.C.long (Certificate.Status)); end Status_Message; end AWS.Net.SSL.Certificate;
strenkml/EE368
Ada
87
ads
with Memory.Super; package Memory.Super_None is new Memory.Super(Natural, Get_Zero);
reznikmm/matreshka
Ada
6,547
adb
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- Localization, Internationalization, Globalization for Ada -- -- -- -- Tools Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2010, Vadim Godunko <[email protected]> -- -- All rights reserved. -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions -- -- are met: -- -- -- -- * Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- -- -- * Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in the -- -- documentation and/or other materials provided with the distribution. -- -- -- -- * Neither the name of the Vadim Godunko, IE nor the names of its -- -- contributors may be used to endorse or promote products derived from -- -- this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -- -- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED -- -- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -- -- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -- -- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -- -- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -- -- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- -- ------------------------------------------------------------------------------ -- $Revision$ $Date$ ------------------------------------------------------------------------------ with Ada.Characters.Conversions; with Ada.Characters.Handling; with GNAT.Regpat; with Asis.Declarations; with Asis.Definitions; with Asis.Elements; with Asis.Expressions; with Asis.Iterator; with Asis.Statements; with Asis.Text; package body Token_Extractor is type State_Information is null record; procedure Process_Ordinary_Type_Declaration (Element : Asis.Element); procedure Pre_Operation (Element : Asis.Element; Control : in out Asis.Traverse_Control; State : in out State_Information); procedure Post_Operation (Element : Asis.Element; Control : in out Asis.Traverse_Control; State : in out State_Information) is null; procedure Iterate is new Asis.Iterator.Traverse_Element (State_Information); function To_Upper (Item : Wide_String) return Wide_String; ------------- -- Extract -- ------------- procedure Extract (Element : Asis.Element) is Control : Asis.Traverse_Control := Asis.Continue; State : State_Information; begin Iterate (Element, Control, State); end Extract; ------------------- -- Pre_Operation -- ------------------- procedure Pre_Operation (Element : Asis.Element; Control : in out Asis.Traverse_Control; State : in out State_Information) is begin case Asis.Elements.Element_Kind (Element) is when Asis.A_Declaration => case Asis.Elements.Declaration_Kind (Element) is when Asis.An_Ordinary_Type_Declaration => Process_Ordinary_Type_Declaration (Element); when others => null; end case; when others => null; end case; end Pre_Operation; --------------------------------------- -- Process_Ordinary_Type_Declaration -- --------------------------------------- procedure Process_Ordinary_Type_Declaration (Element : Asis.Element) is Image : constant Wide_String := To_Upper (Asis.Declarations.Defining_Name_Image (Asis.Declarations.Names (Element) (1))); begin if Image = "TOKEN" then declare Literals : constant Asis.Element_List := Asis.Definitions.Enumeration_Literal_Declarations (Asis.Declarations.Type_Declaration_View (Element)); begin for J in Literals'Range loop declare Image : constant Wide_String := Asis.Declarations.Defining_Name_Image (Asis.Declarations.Names (Literals (J)) (1)); begin Tokens.Append (Ada.Strings.Wide_Unbounded.To_Unbounded_Wide_String (Image)); end; end loop; end; end if; end Process_Ordinary_Type_Declaration; -------------- -- To_Upper -- -------------- function To_Upper (Item : Wide_String) return Wide_String is begin return Ada.Characters.Conversions.To_Wide_String (Ada.Characters.Handling.To_Upper (Ada.Characters.Conversions.To_String (Item))); end To_Upper; end Token_Extractor;
reznikmm/matreshka
Ada
3,953
adb
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- Ada Modeling Framework -- -- -- -- Runtime Library Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2011, Vadim Godunko <[email protected]> -- -- All rights reserved. -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions -- -- are met: -- -- -- -- * Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- -- -- * Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in the -- -- documentation and/or other materials provided with the distribution. -- -- -- -- * Neither the name of the Vadim Godunko, IE nor the names of its -- -- contributors may be used to endorse or promote products derived from -- -- this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -- -- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED -- -- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -- -- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -- -- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -- -- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -- -- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- -- ------------------------------------------------------------------------------ -- $Revision$ $Date$ ------------------------------------------------------------------------------ package body AMF.Factories is ----------------- -- Create_Link -- ----------------- procedure Create_Link (Self : not null access Factory'Class; Association : not null access AMF.CMOF.Associations.CMOF_Association'Class; First_Element : not null AMF.Elements.Element_Access; Second_Element : not null AMF.Elements.Element_Access) is Aux : constant not null AMF.Links.Link_Access := Self.Create_Link (Association, First_Element, Second_Element); pragma Unreferenced (Aux); begin null; end Create_Link; end AMF.Factories;
stcarrez/ada-util
Ada
5,722
ads
----------------------------------------------------------------------- -- util-serialize-io-form -- x-www-form-urlencoded streams -- Copyright (C) 2018, 2022 Stephane Carrez -- Written by Stephane Carrez ([email protected]) -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. ----------------------------------------------------------------------- with Ada.Streams; with Util.Streams.Texts; package Util.Serialize.IO.Form is type Output_Stream is limited new Util.Serialize.IO.Output_Stream with private; procedure Initialize (Stream : in out Output_Stream; Output : in Util.Streams.Texts.Print_Stream_Access); -- Flush the buffer (if any) to the sink. overriding procedure Flush (Stream : in out Output_Stream); -- Close the sink. overriding procedure Close (Stream : in out Output_Stream); -- Write the buffer array to the output stream. overriding procedure Write (Stream : in out Output_Stream; Buffer : in Ada.Streams.Stream_Element_Array); -- Write the attribute name/value pair. overriding procedure Write_Attribute (Stream : in out Output_Stream; Name : in String; Value : in String); overriding procedure Write_Wide_Attribute (Stream : in out Output_Stream; Name : in String; Value : in Wide_Wide_String); overriding procedure Write_Attribute (Stream : in out Output_Stream; Name : in String; Value : in Integer); overriding procedure Write_Attribute (Stream : in out Output_Stream; Name : in String; Value : in Boolean); overriding procedure Write_Attribute (Stream : in out Output_Stream; Name : in String; Value : in Util.Beans.Objects.Object); -- Write the attribute with a null value. overriding procedure Write_Null_Attribute (Stream : in out Output_Stream; Name : in String); -- Write the entity value. overriding procedure Write_Entity (Stream : in out Output_Stream; Name : in String; Value : in String); overriding procedure Write_Wide_Entity (Stream : in out Output_Stream; Name : in String; Value : in Wide_Wide_String); overriding procedure Write_Entity (Stream : in out Output_Stream; Name : in String; Value : in Boolean); overriding procedure Write_Entity (Stream : in out Output_Stream; Name : in String; Value : in Integer); overriding procedure Write_Entity (Stream : in out Output_Stream; Name : in String; Value : in Ada.Calendar.Time); overriding procedure Write_Long_Entity (Stream : in out Output_Stream; Name : in String; Value : in Long_Long_Integer); overriding procedure Write_Long_Entity (Stream : in out Output_Stream; Name : in String; Value : in Long_Long_Float); overriding procedure Write_Enum_Entity (Stream : in out Output_Stream; Name : in String; Value : in String); overriding procedure Write_Entity (Stream : in out Output_Stream; Name : in String; Value : in Util.Beans.Objects.Object); -- Write an entity with a null value. overriding procedure Write_Null_Entity (Stream : in out Output_Stream; Name : in String); type Parser is new Serialize.IO.Parser with private; -- Parse the stream using the form parser. overriding procedure Parse (Handler : in out Parser; Stream : in out Util.Streams.Buffered.Input_Buffer_Stream'Class; Sink : in out Reader'Class); -- Get the current location (file and line) to report an error message. overriding function Get_Location (Handler : in Parser) return String; -- Read a form file and return an object. function Read (Path : in String) return Util.Beans.Objects.Object; private procedure Write_Escape (Stream : in out Output_Stream; Value : in String); type Output_Stream is limited new Util.Serialize.IO.Output_Stream with record Stream : Util.Streams.Texts.Print_Stream_Access; Has_Param : Boolean := False; end record; type Parser is new Util.Serialize.IO.Parser with record Token : Ada.Strings.Unbounded.Unbounded_String; Line_Number : Natural := 1; Has_Pending_Char : Boolean := False; Pending_Char : Character; end record; end Util.Serialize.IO.Form;
zrmyers/VulkanAda
Ada
1,848
ads
-------------------------------------------------------------------------------- -- MIT License -- -- Copyright (c) 2021 Zane Myers -- -- Permission is hereby granted, free of charge, to any person obtaining a copy -- of this software and associated documentation files (the "Software"), to deal -- in the Software without restriction, including without limitation the rights -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -- copies of the Software, and to permit persons to whom the Software is -- furnished to do so, subject to the following conditions: -- -- The above copyright notice and this permission notice shall be included in all -- copies or substantial portions of the Software. -- -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -- SOFTWARE. -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --< @group Vulkan Math Basic Types -------------------------------------------------------------------------------- --< @summary --< This package provides a single precision floating point matrix with 2 rows --< and 2 columns. -------------------------------------------------------------------------------- package Vulkan.Math.Mat4x2.Test is -- Test Harness for Mat4x2 regression tests procedure Test_Mat4x2; end Vulkan.Math.Mat4x2.Test;
albertklee/SPARKZumo
Ada
4,825
ads
-- pragma SPARK_Mode; with Types; use Types; with Interfaces.C; use Interfaces.C; -- @summary -- Interface to the robots 3-axis gyroscope -- -- @description -- This package exposes the interface to the robot's 3 axis gyroscope -- package Zumo_L3gd20h is -- The gain to apply to a sensor reading Gain : constant := 0.07; -- degrees/s/digit -- True if package is init'd Initd : Boolean := False; -- Inits the package. Pin muxing and whatnot. procedure Init with Global => (In_Out => Initd), Pre => not Initd, Post => Initd; -- Read the temperature of the sensor -- @return a byte value with the temperature function Read_Temp return signed_char with Pre => Initd; -- Read the status of the sensor -- @return a byte value with the status function Read_Status return Byte with Pre => Initd; -- Read the gyro of the sensor -- @param Data the read data from the sensor procedure Read_Gyro (Data : out Axis_Data) with Pre => Initd; L3GD20H_Exception : exception; private -- Reads the WHOAMI register from the sensor and compares it against -- the known value procedure Check_WHOAMI; -- The mapping of registers in the sensor -- @value WHO_AM_I Device identification register -- @value CTRL1 control 1 register -- @value CTRL2 control 2 register -- @value CTRL3 control 3 register -- @value CTRL4 control 4 register -- @value CTRL5 control 5 register -- @value REFERENCE Digital high pass filter reference value -- @value OUT_TEMP Temperature data (-1LSB/deg with 8 bit resolution). -- The value is expressed as two's complement. -- @value STATUS sensor status register -- @value OUT_X_L X-axis angular rate data low register -- @value OUT_X_H X-axis angular rate data high register -- @value OUT_Y_L Y-axis angular rate data low register -- @value OUT_Y_H Y-axis angular rate data high register -- @value OUT_Z_L Z-axis angular rate data low register -- @value OUT_Z_H Z-axis angular rate data high register -- @value FIFO_CTRL fifo control register -- @value FIFO_SRC stored data level in fifo type Reg_Index is (WHO_AM_I, CTRL1, CTRL2, CTRL3, CTRL4, CTRL5, REFERENCE, OUT_TEMP, STATUS, OUT_X_L, OUT_X_H, OUT_Y_L, OUT_Y_H, OUT_Z_L, OUT_Z_H, FIFO_CTRL, FIFO_SRC, IG_CFG, IG_SRC, IG_THS_XH, IG_THS_XL, IG_THS_YH, IG_THS_YL, IG_THS_ZH, IG_THS_ZL, IG_DURATION, LOW_ODR); -- Mapping of register enums to actual register addresses Regs : constant array (Reg_Index) of Byte := (WHO_AM_I => 16#0F#, CTRL1 => 16#20#, CTRL2 => 16#21#, CTRL3 => 16#22#, CTRL4 => 16#23#, CTRL5 => 16#24#, REFERENCE => 16#25#, OUT_TEMP => 16#26#, STATUS => 16#27#, OUT_X_L => 16#28#, OUT_X_H => 16#29#, OUT_Y_L => 16#2A#, OUT_Y_H => 16#2B#, OUT_Z_L => 16#2C#, OUT_Z_H => 16#2D#, FIFO_CTRL => 16#2E#, FIFO_SRC => 16#2F#, IG_CFG => 16#30#, IG_SRC => 16#31#, IG_THS_XH => 16#32#, IG_THS_XL => 16#33#, IG_THS_YH => 16#34#, IG_THS_YL => 16#35#, IG_THS_ZH => 16#36#, IG_THS_ZL => 16#37#, IG_DURATION => 16#38#, LOW_ODR => 16#39#); type Register_Bytes is record Register : Reg_Index; Value : Byte; end record; type Register_Byte_Array is array (Natural range <>) of Register_Bytes; end Zumo_L3gd20h;
stcarrez/jason
Ada
30,532
adb
----------------------------------------------------------------------- -- jason-tickets-beans -- Beans for module tickets -- Copyright (C) 2016, 2017, 2019 Stephane.Carrez -- Written by Stephane.Carrez ([email protected]) -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. ----------------------------------------------------------------------- with ADO.Utils; with ADO.Queries; with ADO.Sessions; with ADO.Datasets; with ADO.Parameters; with ADO.Statements; with ADO.Sessions.Entities; with AWA.Tags.Modules; with AWA.Users.Models; with AWA.Services.Contexts; with AWA.Comments.Beans; with AWA.Helpers.Selectors; with Jason.Projects.Models; package body Jason.Tickets.Beans is use type Ada.Strings.Unbounded.Unbounded_String; package ASC renames AWA.Services.Contexts; function Create_From_Status is new AWA.Helpers.Selectors.Create_From_Enum (Jason.Tickets.Models.Status_Type, "ticket_status"); function Create_From_Ticket_Type is new AWA.Helpers.Selectors.Create_From_Enum (Jason.Tickets.Models.Ticket_Type, "ticket_type"); procedure Append (Into : in out Ada.Strings.Unbounded.Unbounded_String; Value : in Jason.Tickets.Models.Status_Type); function To_Priority (Value : in Util.Beans.Objects.Object) return Integer; -- ------------------------------ -- Get a select item list which contains a list of ticket status. -- ------------------------------ function Create_Status_List (Module : in Jason.Tickets.Modules.Ticket_Module_Access) return Util.Beans.Basic.Readonly_Bean_Access is pragma Unreferenced (Module); use AWA.Helpers; begin return Selectors.Create_Selector_Bean (Bundle => "tickets", Context => null, Create => Create_From_Status'Access).all'Access; end Create_Status_List; -- ------------------------------ -- Get a select item list which contains a list of ticket types. -- ------------------------------ function Create_Type_List (Module : in Jason.Tickets.Modules.Ticket_Module_Access) return Util.Beans.Basic.Readonly_Bean_Access is pragma Unreferenced (Module); use AWA.Helpers; begin return Selectors.Create_Selector_Bean (Bundle => "tickets", Context => null, Create => Create_From_Ticket_Type'Access).all'Access; end Create_Type_List; -- ------------------------------ -- Create ticket action. -- ------------------------------ overriding procedure Create (Bean : in out Ticket_Bean; Outcome : in out Ada.Strings.Unbounded.Unbounded_String) is pragma Unreferenced (Outcome); begin Bean.Module.Create (Bean, Bean.Project.Get_Id); Bean.Tags.Update_Tags (Bean.Get_Id); end Create; -- Save ticket action. overriding procedure Save (Bean : in out Ticket_Bean; Outcome : in out Ada.Strings.Unbounded.Unbounded_String) is pragma Unreferenced (Outcome); begin Bean.Module.Save (Bean, Ada.Strings.Unbounded.To_String (Bean.Comment)); Bean.Tags.Update_Tags (Bean.Get_Id); end Save; -- Save ticket action. overriding procedure Save_Status (Bean : in out Ticket_Bean; Outcome : in out Ada.Strings.Unbounded.Unbounded_String) is pragma Unreferenced (Outcome); begin Bean.Module.Save (Bean, Ada.Strings.Unbounded.To_String (Bean.Comment)); end Save_Status; -- Load ticket action. overriding procedure Load (Bean : in out Ticket_Bean; Outcome : in out Ada.Strings.Unbounded.Unbounded_String) is use type AWA.Comments.Beans.Comment_List_Bean_Access; Comment_List : AWA.Comments.Beans.Comment_List_Bean_Access; begin Bean.Module.Load_Ticket (Bean, Bean.Project.all, Bean.Tags, Bean.Ticket_Id); Comment_List := AWA.Comments.Beans.Get_Comment_List_Bean ("ticketComments"); if Comment_List /= null then Comment_List.Load_Comments (Bean.Get_Id); end if; Outcome := Ada.Strings.Unbounded.To_Unbounded_String ("loaded"); end Load; -- ------------------------------ -- Get the value identified by the name. -- ------------------------------ overriding function Get_Value (From : in Ticket_Bean; Name : in String) return Util.Beans.Objects.Object is begin if Name = "project_id" then if From.Project.Is_Inserted then return ADO.Utils.To_Object (From.Project.Get_Id); else return ADO.Utils.To_Object (From.Project.Get_Id); end if; elsif Name = "ticket_id" or Name = "id" then if From.Is_Inserted or From.Is_Loaded then return ADO.Utils.To_Object (From.Get_Id); else return ADO.Utils.To_Object (From.Ticket_Id); end if; elsif Name = "tags" then return Util.Beans.Objects.To_Object (From.Tags_Bean, Util.Beans.Objects.STATIC); else return Jason.Tickets.Models.Ticket_Bean (From).Get_Value (Name); end if; end Get_Value; -- ------------------------------ -- Set the value identified by the name. -- ------------------------------ overriding procedure Set_Value (From : in out Ticket_Bean; Name : in String; Value : in Util.Beans.Objects.Object) is begin if Name = "project_id" and not Util.Beans.Objects.Is_Empty (Value) then From.Project.Set_Id (ADO.Utils.To_Identifier (Value)); elsif Name = "ticket_id" and not Util.Beans.Objects.Is_Empty (Value) then From.Ticket_Id := ADO.Utils.To_Identifier (Value); elsif Name = "id" and not Util.Beans.Objects.Is_Empty (Value) then From.Ticket_Id := ADO.Utils.To_Identifier (Value); From.Module.Load_Ticket (From, From.Project.all, From.Tags, From.Ticket_Id); else Jason.Tickets.Models.Ticket_Bean (From).Set_Value (Name, Value); end if; end Set_Value; -- ------------------------------ -- Create the Ticket_Bean bean instance. -- ------------------------------ function Create_Ticket_Bean (Module : in Jason.Tickets.Modules.Ticket_Module_Access) return Util.Beans.Basic.Readonly_Bean_Access is Object : constant Ticket_Bean_Access := new Ticket_Bean; begin Object.Module := Module; Object.Tags_Bean := Object.Tags'Access; Object.Tags.Set_Entity_Type (Jason.Tickets.Models.TICKET_TABLE); Object.Tags.Set_Permission ("ticket-update"); Object.Project := Jason.Projects.Beans.Get_Project_Bean ("project"); return Object.all'Access; end Create_Ticket_Bean; -- Get the value identified by the name. overriding function Get_Value (From : in Ticket_List_Bean; Name : in String) return Util.Beans.Objects.Object is Pos : Natural; begin if Name = "tags" then Pos := From.Tickets.Get_Row_Index; if Pos = 0 then return Util.Beans.Objects.Null_Object; end if; declare Item : constant Models.List_Info := From.Tickets.List.Element (Pos - 1); begin return From.Tags.Get_Tags (Item.Id); end; elsif Name = "page_count" then return Util.Beans.Objects.To_Object ((From.Count + From.Page_Size - 1) / From.Page_Size); elsif Name = "tickets" then return Util.Beans.Objects.To_Object (Value => From.Tickets_Bean, Storage => Util.Beans.Objects.STATIC); elsif Name = "status" then return Util.Beans.Objects.To_Object (From.Status_Filter); elsif Name = "priority" then if From.Priority_Filter = "" then return Util.Beans.Objects.To_Object (String '("all")); else return Util.Beans.Objects.To_Object (From.Priority_Filter); end if; elsif Name = "ticket_kind" and not From.Type_Filter then return Util.Beans.Objects.To_Object (String '("")); else return Jason.Tickets.Models.Ticket_List_Bean (From).Get_Value (Name); end if; end Get_Value; function To_Priority (Value : in Util.Beans.Objects.Object) return Integer is S : constant String := Util.Beans.Objects.To_String (Value); begin if S = "all" or S = "" then return 0; elsif S = "high" then return -3; elsif S = "medium" then return 4; elsif S = "low" then return 5; else return Integer'Value (S); end if; exception when Constraint_Error => return 0; end To_Priority; -- Set the value identified by the name. overriding procedure Set_Value (From : in out Ticket_List_Bean; Name : in String; Value : in Util.Beans.Objects.Object) is begin if Name = "priority" then From.Priority_Filter := Util.Beans.Objects.To_Unbounded_String (Value); From.Priority := To_Priority (Value); elsif Name = "ticket_kind" then if Util.Beans.Objects.To_String (Value) /= "all" and not Util.Beans.Objects.Is_Empty (Value) then From.Ticket_Kind := Jason.Tickets.Models.Ticket_Type_Objects.To_Value (Value); From.Type_Filter := True; else From.Type_Filter := False; end if; elsif Name = "status" then From.Status_Filter := Util.Beans.Objects.To_Unbounded_String (Value); if From.Status_Filter /= "all" and From.Status_Filter /= "pending" and From.Status_Filter /= "done" and From.Status_Filter /= "" then From.Status := Jason.Tickets.Models.Status_Type_Objects.To_Value (Value); end if; elsif not Util.Beans.Objects.Is_Empty (Value) or else Name = "tags" then Jason.Tickets.Models.Ticket_List_Bean (From).Set_Value (Name, Value); end if; end Set_Value; procedure Append (Into : in out Ada.Strings.Unbounded.Unbounded_String; Value : in Jason.Tickets.Models.Status_Type) is begin Ada.Strings.Unbounded.Append (Into, Natural'Image (Models.Status_Type'Pos (Value))); end Append; -- Load list of tickets. overriding procedure Load (Bean : in out Ticket_List_Bean; Outcome : in out Ada.Strings.Unbounded.Unbounded_String) is pragma Unreferenced (Outcome); use type ADO.Identifier; use Ada.Strings.Unbounded; use Jason.Tickets.Models; Ctx : constant ASC.Service_Context_Access := ASC.Current; User : constant ADO.Identifier := Ctx.Get_User_Identifier; Session : ADO.Sessions.Session := Bean.Module.Get_Session; Query : ADO.Queries.Context; Count_Query : ADO.Queries.Context; Tag_Id : ADO.Identifier; First : constant Natural := (Bean.Page - 1) * Bean.Page_Size; Filter : Ada.Strings.Unbounded.Unbounded_String; begin AWA.Tags.Modules.Find_Tag_Id (Session, Ada.Strings.Unbounded.To_String (Bean.Tag), Tag_Id); if Tag_Id /= ADO.NO_IDENTIFIER then Query.Set_Query (Jason.Tickets.Models.Query_List_Tag_Filter); Query.Bind_Param (Name => "tag", Value => Tag_Id); Count_Query.Set_Count_Query (Jason.Tickets.Models.Query_List_Tag_Filter); Count_Query.Bind_Param (Name => "tag", Value => Tag_Id); else Query.Set_Query (Jason.Tickets.Models.Query_List); Count_Query.Set_Count_Query (Jason.Tickets.Models.Query_List); end if; if Bean.Sort = "newest" then Query.Bind_Param (Name => "order1", Value => ADO.Parameters.Token '("ticket.create_date DESC")); elsif Bean.Sort = "oldest" then Query.Bind_Param (Name => "order1", Value => ADO.Parameters.Token '("ticket.create_date ASC")); elsif Bean.Sort = "recent" then Query.Bind_Param (Name => "order1", Value => ADO.Parameters.Token '("ticket.update_date DESC")); elsif Bean.Sort = "not-recent" then Query.Bind_Param (Name => "order1", Value => ADO.Parameters.Token '("ticket.update_date ASC")); else Query.Bind_Param (Name => "order1", Value => ADO.Parameters.Token '("ticket.ident DESC")); end if; if Bean.Priority /= 0 then if Bean.Priority > 0 then Ada.Strings.Unbounded.Append (Filter, "ticket.priority = "); Ada.Strings.Unbounded.Append (Filter, Natural'Image (Bean.Priority)); else Ada.Strings.Unbounded.Append (Filter, "ticket.priority <= "); Ada.Strings.Unbounded.Append (Filter, Natural'Image (-Bean.Priority)); end if; Ada.Strings.Unbounded.Append (Filter, " AND "); end if; if Bean.Type_Filter then Ada.Strings.Unbounded.Append (Filter, "ticket.ticket_type = "); Ada.Strings.Unbounded.Append (Filter, Natural'Image (Models.Ticket_Type'Pos (Bean.Ticket_Kind))); Ada.Strings.Unbounded.Append (Filter, " AND "); end if; if Bean.Status_Filter = "done" then Ada.Strings.Unbounded.Append (Filter, "(ticket.status = "); Append (Filter, Jason.Tickets.Models.CLOSED); Ada.Strings.Unbounded.Append (Filter, " OR ticket.status = "); Append (Filter, Jason.Tickets.Models.REJECTED); Ada.Strings.Unbounded.Append (Filter, ")"); elsif Bean.Status_Filter = "all" or Bean.Status_Filter = "" then Ada.Strings.Unbounded.Append (Filter, "ticket.status >= 0"); elsif Bean.Status_Filter = "pending" then Ada.Strings.Unbounded.Append (Filter, "ticket.status != "); Append (Filter, Jason.Tickets.Models.CLOSED); Ada.Strings.Unbounded.Append (Filter, " AND ticket.status != "); Append (Filter, Jason.Tickets.Models.REJECTED); else Ada.Strings.Unbounded.Append (Filter, "ticket.status = "); Append (Filter, Bean.Status); end if; Query.Bind_Param (Name => "ticket_filter", Value => ADO.Parameters.Token (To_String (Filter))); Count_Query.Bind_Param (Name => "ticket_filter", Value => ADO.Parameters.Token (To_String (Filter))); Query.Bind_Param (Name => "project_id", Value => Bean.Project_Id); Query.Bind_Param (Name => "first", Value => First); Query.Bind_Param (Name => "count", Value => Bean.Page_Size); Query.Bind_Param (Name => "user_id", Value => User); Count_Query.Bind_Param (Name => "project_id", Value => Bean.Project_Id); Count_Query.Bind_Param (Name => "user_id", Value => User); ADO.Sessions.Entities.Bind_Param (Params => Query, Name => "ticket_table", Table => Jason.Tickets.Models.TICKET_TABLE, Session => Session); ADO.Sessions.Entities.Bind_Param (Params => Query, Name => "project_table", Table => Jason.Projects.Models.PROJECT_TABLE, Session => Session); ADO.Sessions.Entities.Bind_Param (Params => Count_Query, Name => "ticket_table", Table => Jason.Tickets.Models.TICKET_TABLE, Session => Session); ADO.Sessions.Entities.Bind_Param (Params => Count_Query, Name => "project_table", Table => Jason.Projects.Models.PROJECT_TABLE, Session => Session); Jason.Tickets.Models.List (Bean.Tickets, Session, Query); Bean.Count := ADO.Datasets.Get_Count (Session, Count_Query); declare List : ADO.Utils.Identifier_Vector; Iter : Models.List_Info_Vectors.Cursor := Bean.Tickets.List.First; begin while Models.List_Info_Vectors.Has_Element (Iter) loop List.Append (Models.List_Info_Vectors.Element (Iter).Id); Models.List_Info_Vectors.Next (Iter); end loop; Bean.Tags.Load_Tags (Session, Jason.Tickets.Models.TICKET_TABLE.Table.all, List); end; end Load; -- Create the Tickets_List_Bean bean instance. function Create_Ticket_List_Bean (Module : in Jason.Tickets.Modules.Ticket_Module_Access) return Util.Beans.Basic.Readonly_Bean_Access is Object : constant Ticket_List_Bean_Access := new Ticket_List_Bean; begin Object.Module := Module; Object.Page_Size := 20; Object.Count := 0; Object.Page := 1; Object.Priority := 0; Object.Project_Id := ADO.NO_IDENTIFIER; Object.Status := Jason.Tickets.Models.OPEN; Object.Status_Filter := Ada.Strings.Unbounded.To_Unbounded_String ("pending"); Object.Tickets_Bean := Object.Tickets'Access; Object.Project := Jason.Projects.Beans.Get_Project_Bean ("project"); return Object.all'Access; end Create_Ticket_List_Bean; procedure Initialize (Object : in out Ticket_Raw_Stat_Bean) is begin Object.Low_Bean := Util.Beans.Objects.To_Object (Object.Low'Unchecked_Access, Util.Beans.Objects.STATIC); Object.High_Bean := Util.Beans.Objects.To_Object (Object.High'Unchecked_Access, Util.Beans.Objects.STATIC); Object.Medium_Bean := Util.Beans.Objects.To_Object (Object.Medium'Unchecked_Access, Util.Beans.Objects.STATIC); Object.Closed_Bean := Util.Beans.Objects.To_Object (Object.Closed'Unchecked_Access, Util.Beans.Objects.STATIC); end Initialize; -- ------------------------------ -- Get the value identified by the name. -- ------------------------------ overriding function Get_Value (From : in Ticket_Raw_Stat_Bean; Name : in String) return Util.Beans.Objects.Object is begin if Name = "low" then return From.Low_Bean; elsif Name = "medium" then return From.Medium_Bean; elsif Name = "high" then return From.High_Bean; elsif Name = "closed" then return From.Closed_Bean; elsif Name = "progress" then return Util.Beans.Objects.To_Object (From.Progress); else return Jason.Tickets.Models.Stat_Bean (From).Get_Value (Name); end if; end Get_Value; -- ------------------------------ -- Get the value identified by the name. -- ------------------------------ overriding function Get_Value (From : in Ticket_Report_Bean; Name : in String) return Util.Beans.Objects.Object is begin if name = "count" then return Util.Beans.Objects.To_Object (Natural (From.Report.Length)); elsif name = "total" then return From.Total_Bean; end if; return Util.Beans.Objects.Null_Object; end Get_Value; -- ------------------------------ -- Set the value identified by the name. -- ------------------------------ overriding procedure Set_Value (From : in out Ticket_Report_Bean; Name : in String; Value : in Util.Beans.Objects.Object) is begin null; end Set_Value; -- ------------------------------ -- Get the number of elements in the list. -- ------------------------------ function Get_Count (From : Ticket_Report_Bean) return Natural is begin return Natural (From.Report.Length); end Get_Count; -- ------------------------------ -- Set the current row index. Valid row indexes start at 1. -- ------------------------------ overriding procedure Set_Row_Index (From : in out Ticket_Report_Bean; Index : in Natural) is begin if Index = 1 then From.Current := From.Report.First; From.Current_Pos := Index; elsif Index = Natural (From.Report.Length) then From.Current := From.Report.Last; From.Current_Pos := Index; else while Index > From.Current_Pos and Ticket_Stat_Vectors.Has_Element (From.Current) loop Ticket_Stat_Vectors.Next (From.Current); From.Current_Pos := From.Current_Pos + 1; end loop; end if; Ticket_Stat_Bean (From.Element) := Ticket_Stat_Vectors.Element (From.Report, From.Current_Pos); end Set_Row_Index; -- ------------------------------ -- Get the element at the current row index. -- ------------------------------ overriding function Get_Row (From : in Ticket_Report_Bean) return Util.Beans.Objects.Object is begin return From.Row; end Get_Row; -- ------------------------------ -- Load the information for the tickets. -- ------------------------------ overriding procedure Load (Bean : in out Ticket_Report_Bean; Outcome : in out Ada.Strings.Unbounded.Unbounded_String) is pragma Unreferenced (Outcome); Session : constant ADO.Sessions.Session := Bean.Module.Get_Session; Query : ADO.Queries.Context; Empty : constant Jason.Tickets.Models.Stat_Bean := (Kind => Models.WORK, others => 0); Ctx : constant ASC.Service_Context_Access := ASC.Current; User : constant AWA.Users.Models.User_Ref := Ctx.Get_User; begin Query.Set_Query (Jason.Tickets.Models.Query_Stats); Query.Bind_Param ("project_id", Bean.Project.Get_Id); Query.Bind_Param ("user_id", User.Get_Id); ADO.Sessions.Entities.Bind_Param (Params => Query, Name => "project_table", Table => Jason.Projects.Models.PROJECT_TABLE, Session => Session); declare Stmt : ADO.Statements.Query_Statement := Session.Create_Statement (Query); begin Stmt.Execute; while Stmt.Has_Elements loop declare use Models; Status : constant Models.Status_Type := Status_Type'Val (Stmt.Get_Integer (0)); Kind : constant Models.Ticket_Type := Ticket_Type'Val (Stmt.Get_Integer (1)); Priority : constant Natural := Stmt.Get_Integer (2); Count : constant Natural := Stmt.Get_Integer (3); Time : constant Natural := Stmt.Get_Integer (4); Done : constant Natural := Stmt.Get_Integer (5); Remain : constant Natural := Stmt.Get_Integer (6); procedure Update (Key : in Models.Ticket_Type; Item : in out Ticket_Stat_Bean); procedure Update (Key : in Models.Ticket_Type; Item : in out Ticket_Stat_Bean) is pragma Unreferenced (Key); begin if Status = Models.CLOSED or Status = Models.REJECTED then Item.Closed.Count := Item.Closed.Count + Count; Item.Closed.Time := Item.Closed.Time + Time; Item.Closed.Done := Item.Closed.Done + Done; Item.Closed.Remain := Item.Closed.Remain + Remain; elsif Priority <= 3 then Item.High.Count := Item.High.Count + Count; Item.High.Time := Item.High.Time + Time; Item.High.Done := Item.High.Done + Done; Item.High.Remain := Item.High.Remain + Remain; elsif Priority > 4 then Item.Low.Count := Item.Low.Count + Count; Item.Low.Time := Item.Low.Time + Time; Item.Low.Done := Item.Low.Done + Done; Item.Low.Remain := Item.Low.Remain + Remain; else Item.Medium.Count := Item.Medium.Count + Count; Item.Medium.Time := Item.Medium.Time + Time; Item.Medium.Done := Item.Medium.Done + Done; Item.Medium.Remain := Item.Medium.Remain + Remain; end if; end Update; Pos : constant Ticket_Stat_Map.Cursor := Bean.List.Find (Kind); begin if Ticket_Stat_Map.Has_Element (Pos) then Bean.List.Update_Element (Pos, Update'Access); else declare T : Ticket_Stat_Bean; begin T.Kind := Kind; T.Count := 0; T.Time := 0; T.Remain := 0; T.High := Empty; T.Low := Empty; T.Medium := Empty; T.Closed := Empty; Update (Kind, T); Bean.List.Insert (Kind, T); end; end if; end; Stmt.Next; end loop; end; declare procedure Add (Into : in out Ticket_Raw_Stat_Bean; Value : in Ticket_Stat_Bean); procedure Add (Into : in out Ticket_Raw_Stat_Bean; Value : in Ticket_Stat_Bean) is begin Into.Count := Into.Count + Value.Count; Into.Done := Into.Done + Value.Done; Into.High.Count := Into.High.Count + Value.High.Count; Into.High.Time := Into.High.Time + Value.High.Time; Into.High.Remain := Into.High.Remain + Value.High.Remain; Into.High.Done := Into.High.Done + Value.High.Done; Into.Medium.Count := Into.Medium.Count + Value.Medium.Count; Into.Medium.Time := Into.Medium.Time + Value.Medium.Time; Into.Medium.Remain := Into.Medium.Remain + Value.Medium.Remain; Into.Medium.Done := Into.Medium.Done + Value.Medium.Done; Into.Low.Count := Into.Low.Count + Value.Low.Count; Into.Low.Time := Into.Low.Time + Value.Low.Time; Into.Low.Remain := Into.Low.Remain + Value.Low.Remain; Into.Low.Done := Into.Low.Done + Value.Low.Done; Into.Closed.Count := Into.Closed.Count + Value.Closed.Count; Into.Closed.Time := Into.Closed.Time + Value.Closed.Time; Into.Closed.Remain := Into.Closed.Remain + Value.Closed.Remain; Into.Closed.Done := Into.Closed.Done + Value.Closed.Done; Into.Remain := Into.Remain + Value.Remain; end Add; Iter : Ticket_Stat_Map.Cursor := Bean.List.First; Info : Ticket_Stat_Bean; Done : Integer; Remain : Integer; begin Bean.Total.Count := 0; Bean.Total.Remain := 0; Bean.Total.Time := 0; Bean.Total.High := Empty; Bean.Total.Medium := Empty; Bean.Total.Low := Empty; Bean.Total.Closed := Empty; while Ticket_Stat_Map.Has_Element (Iter) loop Info := Ticket_Stat_Map.Element (Iter); Done := Info.Low.Done + Info.Medium.Done + Info.High.Done + Info.Closed.Done; Remain := Info.Low.Remain + Info.Medium.Remain + Info.High.Remain + Info.Closed.Remain; if Done + Remain = 0 then Info.Progress := 100; else Info.Progress := (Done * 100) / (Done + Remain); end if; Add (Bean.Total, Info); Bean.Report.Append (Info); Ticket_Stat_Map.Next (Iter); end loop; Done := Bean.Total.Low.Done + Bean.Total.Medium.Done + Bean.Total.High.Done + Bean.Total.Closed.Done; Remain := Bean.Total.Low.Remain + Bean.Total.Medium.Remain + Bean.Total.High.Remain + Bean.Total.Closed.Remain; if Done + Remain = 0 then Bean.Total.Progress := 100; else Bean.Total.Progress := (Done * 100) / (Done + Remain); end if; -- Sort_Tasks.Sort (Into.Tasks); end; end Load; -- ------------------------------ -- Create the Tickets_Report_Bean bean instance. -- ------------------------------ function Create_Ticket_Report_Bean (Module : in Jason.Tickets.Modules.Ticket_Module_Access) return Util.Beans.Basic.Readonly_Bean_Access is Object : constant Ticket_Report_Bean_Access := new Ticket_Report_Bean; begin Object.Module := Module; Object.Project := Jason.Projects.Beans.Get_Project_Bean ("project"); Object.Row := Util.Beans.Objects.To_Object (Object.Element'Access, Util.Beans.Objects.STATIC); Object.Total_Bean := Util.Beans.Objects.To_Object (Object.Total'Access, Util.Beans.Objects.STATIC); Initialize (Object.Element); Initialize (Object.Total); return Object.all'Access; end Create_Ticket_Report_Bean; end Jason.Tickets.Beans;
reznikmm/matreshka
Ada
4,017
ads
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- Open Document Toolkit -- -- -- -- Runtime Library Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2014, Vadim Godunko <[email protected]> -- -- All rights reserved. -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions -- -- are met: -- -- -- -- * Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- -- -- * Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in the -- -- documentation and/or other materials provided with the distribution. -- -- -- -- * Neither the name of the Vadim Godunko, IE nor the names of its -- -- contributors may be used to endorse or promote products derived from -- -- this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -- -- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED -- -- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -- -- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -- -- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -- -- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -- -- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- -- ------------------------------------------------------------------------------ -- $Revision$ $Date$ ------------------------------------------------------------------------------ with ODF.DOM.Dr3d_Texture_Kind_Attributes; package Matreshka.ODF_Dr3d.Texture_Kind_Attributes is type Dr3d_Texture_Kind_Attribute_Node is new Matreshka.ODF_Dr3d.Abstract_Dr3d_Attribute_Node and ODF.DOM.Dr3d_Texture_Kind_Attributes.ODF_Dr3d_Texture_Kind_Attribute with null record; overriding function Create (Parameters : not null access Matreshka.DOM_Attributes.Attribute_L2_Parameters) return Dr3d_Texture_Kind_Attribute_Node; overriding function Get_Local_Name (Self : not null access constant Dr3d_Texture_Kind_Attribute_Node) return League.Strings.Universal_String; end Matreshka.ODF_Dr3d.Texture_Kind_Attributes;
reznikmm/increment
Ada
11,278
adb
-- Copyright (c) 2015-2017 Maxim Reznik <[email protected]> -- -- SPDX-License-Identifier: MIT -- License-Filename: LICENSE ------------------------------------------------------------- package body Incr.Lexers.Incremental is procedure Apply_Marking (Node : Nodes.Node_Access; Previous : Version_Trees.Version; Reference : Version_Trees.Version); procedure Mark_From (Token : Nodes.Tokens.Token_Access; Reference : Version_Trees.Version); procedure Lexing_Phase (Self : in out Incremental_Lexer); pragma Unreferenced (Lexing_Phase); function Find_Next_Region (Self : access Nodes.Node'Class) return Nodes.Tokens.Token_Access; ------------------- -- Apply_Marking -- ------------------- procedure Apply_Marking (Node : Nodes.Node_Access; Previous : Version_Trees.Version; Reference : Version_Trees.Version) is begin if Node.Is_Token and then Node.Local_Changes (Reference, Previous) then declare use type League.Strings.Universal_String; Token : constant Nodes.Tokens.Token_Access := Nodes.Tokens.Token_Access (Node); Current : constant League.Strings.Universal_String := Token.Text (Previous); Before : constant League.Strings.Universal_String := Token.Text (Reference); begin -- Handle textual changes. if Current /= Before then Mark_From (Token, Reference); end if; end; else -- Handle structural changes. for J in 1 .. Node.Arity loop declare use type Nodes.Node_Access; Now : constant Nodes.Node_Access := Node.Child (J, Previous); Before : constant Nodes.Node_Access := Node.Child (J, Reference); Token : Nodes.Tokens.Token_Access; begin if Now /= Before and Before /= null then Token := Before.First_Token (Reference); Mark_From (Token, Reference); Token := Before.Last_Token (Reference) .Next_Token (Reference); Mark_From (Token, Reference); end if; end; end loop; -- Recursively process any edits within this subtree. if Node.Nested_Changes (Reference, Previous) then for J in 1 .. Node.Arity loop declare use type Nodes.Node_Access; Now : constant Nodes.Node_Access := Node.Child (J, Previous); begin if Now /= null then Apply_Marking (Now, Previous, Reference); end if; end; end loop; end if; end if; end Apply_Marking; ---------------------- -- Find_Next_Region -- ---------------------- function Find_Next_Region (Self : access Nodes.Node'Class) return Nodes.Tokens.Token_Access is use type Nodes.Tokens.Token_Access; Now : constant Version_Trees.Version := Self.Document.History.Changing; begin if Self.Is_Token then if Self.Document.End_Of_Stream = Self or else Self.Get_Flag (Nodes.Need_Analysis) then return Nodes.Tokens.Token_Access (Self); end if; elsif Self.Nested_Changes (From => Now, To => Now) then return Find_Next_Region (Self.Child (1, Now)); end if; return Find_Next_Region (Self.Next_Subtree (Now)); end Find_Next_Region; --------------------- -- First_New_Token -- --------------------- function First_New_Token (Self : in out Incremental_Lexer; Token : Nodes.Tokens.Token_Access) return Nodes.Tokens.Token_Access is use type Nodes.Tokens.Token_Access; Ref : constant Version_Trees.Version := Self.Reference; begin -- Reset internal state of batch lexer by setting new source Self.Batch.Set_Source (Self'Unchecked_Access); if Token = Token.Document.Start_Of_Stream then Self.State := Lexers.Batch_Lexers.INITIAL; else Self.State := Token.Previous_Token (Ref).State (Ref); end if; Self.Batch.Set_Start_Condition (Self.State); -- Self.New_State defined in Next_New_Token Self.Prev_Token := (null, null); Self.Token := Token; Self.Count := 0; Self.Text := Self.Token.Text (Self.Previous); Self.Cursor.First (Self.Text); return Next_New_Token (Self); end First_New_Token; -------------- -- Get_Next -- -------------- overriding function Get_Next (Self : not null access Incremental_Lexer) return Wide_Wide_Character is use type Nodes.Tokens.Token_Access; Token : Nodes.Tokens.Token_Access; begin while not Self.Cursor.Has_Element loop Self.Count := Self.Count + Self.Token.Text (Self.Previous).Length; Self.State := Self.Token.State (Self.Previous); Token := Self.Token.Next_Token (Self.Previous); if Token = null then return Batch_Lexers.End_Of_Input; end if; if not Self.Token.Get_Flag (Nodes.Bottom_Up_Reused) then Self.Prev_Token (1) := Self.Prev_Token (2); Self.Prev_Token (2) := Self.Token; end if; Self.Token := Token; Self.Text := Self.Token.Text (Self.Previous); Self.Cursor.First (Self.Text); end loop; return Result : Wide_Wide_Character do Result := Self.Cursor.Element; Self.Cursor.Next; end return; end Get_Next; --------------------- -- Is_Synchronized -- --------------------- function Is_Synchronized (Self : Incremental_Lexer) return Boolean is use type Batch_Lexers.State; use type Nodes.Tokens.Token_Access; Token : constant Nodes.Tokens.Token_Access := Self.Token; begin if Self.Count /= 0 or Self.State /= Self.New_State then return False; end if; if Token = null then return True; end if; if Token.Get_Flag (Nodes.Need_Analysis) then return False; end if; if Token.Get_Flag (Nodes.Bottom_Up_Reused) then return False; end if; return True; end Is_Synchronized; ------------------ -- Lexing_Phase -- ------------------ procedure Lexing_Phase (Self : in out Incremental_Lexer) is use type Nodes.Tokens.Token_Access; Token : Nodes.Tokens.Token_Access := Find_Next_Region (Self.Document.Ultra_Root); begin while Token /= Self.Document.End_Of_Stream loop Token := First_New_Token (Self, Token); while not Is_Synchronized (Self) loop Token := Next_New_Token (Self); end loop; Token := Find_Next_Region (Self.Token); end loop; end Lexing_Phase; --------------- -- Mark_From -- --------------- procedure Mark_From (Token : Nodes.Tokens.Token_Access; Reference : Version_Trees.Version) is Next : Nodes.Tokens.Token_Access := Token; begin if Token.Exists (Reference) then for J in 0 .. Token.Lookback (Reference) loop Next.Set_Flag (Nodes.Need_Analysis); Next := Next.Previous_Token (Reference); end loop; else Token.Set_Flag (Nodes.Need_Analysis); end if; end Mark_From; -------------------- -- Next_New_Token -- -------------------- function Next_New_Token (Self : in out Incremental_Lexer) return Nodes.Tokens.Token_Access is function Could_Be_Reused (Token : Nodes.Tokens.Token_Access; Rule : Batch_Lexers.Rule_Index) return Boolean; --------------------- -- Could_Be_Reused -- --------------------- function Could_Be_Reused (Token : Nodes.Tokens.Token_Access; Rule : Batch_Lexers.Rule_Index) return Boolean is use type Nodes.Token_Kind; use type Nodes.Tokens.Token_Access; begin return Token /= null and then Token.Kind = Nodes.Token_Kind (Rule) and then not Token.Get_Flag (Nodes.Bottom_Up_Reused); end Could_Be_Reused; Value : League.Strings.Universal_String; Rule : Batch_Lexers.Rule_Index; Result : Nodes.Tokens.Token_Access; begin Self.Batch.Get_Token (Rule); Value := Self.Batch.Get_Text; Self.Count := Self.Count - Value.Length; Self.New_State := Self.Batch.Get_Start_Condition; if Could_Be_Reused (Self.Prev_Token (1), Rule) then Result := Self.Prev_Token (1); Result.Set_Text (Value); Result.Set_Local_Errors (False); -- Result.Set_State (Self.New_State); -- Result.Set_Lookahead (Self.Batch.Get_Token_Lookahead); Self.Prev_Token (1) := null; Result.Set_Flag (Nodes.Bottom_Up_Reused); elsif Could_Be_Reused (Self.Prev_Token (2), Rule) then Result := Self.Prev_Token (2); Result.Set_Text (Value); Result.Set_Local_Errors (False); -- Result.Set_State (Self.New_State); -- Result.Set_Lookahead (Self.Batch.Get_Token_Lookahead); Self.Prev_Token := (null, null); Result.Set_Flag (Nodes.Bottom_Up_Reused); elsif Could_Be_Reused (Self.Token, Rule) then Result := Self.Token; Result.Set_Text (Value); Result.Set_Local_Errors (False); -- Result.Set_State (Self.New_State); -- Result.Set_Lookahead (Self.Batch.Get_Token_Lookahead); Result.Set_Flag (Nodes.Bottom_Up_Reused); else Result := new Nodes.Tokens.Token (Self.Document); Nodes.Tokens.Constructors.Initialize (Result.all, Nodes.Token_Kind (Rule), Value, Self.New_State, Self.Batch.Get_Token_Lookahead); end if; return Result; end Next_New_Token; ---------------------- -- Prepare_Document -- ---------------------- not overriding procedure Prepare_Document (Self : in out Incremental_Lexer; Document : Documents.Document_Access; Reference : Version_Trees.Version) is Now : constant Version_Trees.Version := Document.History.Changing; begin Self.Document := Document; Self.Reference := Reference; Self.Previous := Document.History.Parent (Now); Apply_Marking (Self.Document.Ultra_Root, Previous => Self.Previous, Reference => Self.Reference); end Prepare_Document; --------------------- -- Set_Batch_Lexer -- --------------------- not overriding procedure Set_Batch_Lexer (Self : in out Incremental_Lexer; Lexer : Batch_Lexers.Batch_Lexer_Access) is begin Self.Batch := Lexer; end Set_Batch_Lexer; ------------------------ -- Synchronized_Token -- ------------------------ not overriding function Synchronized_Token (Self : Incremental_Lexer) return Nodes.Tokens.Token_Access is begin return Self.Token; end Synchronized_Token; end Incr.Lexers.Incremental;
AdaCore/libadalang
Ada
599
adb
with Ada.Task_Identification; procedure Test is procedure Foo (A : Integer) is null; procedure Foo (A : Boolean) is null; task type T is entry E; end T; task body T is begin Foo (E'Count); pragma Test_Statement; accept E do declare I : Ada.Task_Identification.Task_Id := E'Caller; pragma Test_Statement; begin null; end; end E; end T; Inst : T; begin Foo (Inst'Callable); pragma Test_Statement; Foo (Inst'Terminated); pragma Test_Statement; end Test;
onox/orka
Ada
1,025
ads
-- SPDX-License-Identifier: Apache-2.0 -- -- Copyright (c) 2017 onox <[email protected]> -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. package Orka.Atomics is pragma Pure; protected type Counter (Initial_Value : Natural) is pragma Lock_Free; procedure Add (Addition : Natural); procedure Increment; procedure Decrement (Zero : out Boolean); function Count return Natural; private Value : Natural := Initial_Value; end Counter; end Orka.Atomics;
reznikmm/matreshka
Ada
4,403
ads
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- Web Framework -- -- -- -- Tools Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2015, Vadim Godunko <[email protected]> -- -- All rights reserved. -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions -- -- are met: -- -- -- -- * Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- -- -- * Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in the -- -- documentation and/or other materials provided with the distribution. -- -- -- -- * Neither the name of the Vadim Godunko, IE nor the names of its -- -- contributors may be used to endorse or promote products derived from -- -- this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -- -- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED -- -- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -- -- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -- -- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -- -- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -- -- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- -- ------------------------------------------------------------------------------ -- $Revision$ $Date$ ------------------------------------------------------------------------------ with Asis; with Engines.Contexts; with League.Strings; package Properties.Declarations.Function_Declarations is function Call_Convention (Engine : access Engines.Contexts.Context; Element : Asis.Declaration; Name : Engines.Convention_Property) return Engines.Convention_Kind; function Code (Engine : access Engines.Contexts.Context; Element : Asis.Declaration; Name : Engines.Text_Property) return League.Strings.Universal_String; function Export (Engine : access Engines.Contexts.Context; Element : Asis.Declaration; Name : Engines.Boolean_Property) return Boolean; function Intrinsic_Name (Engine : access Engines.Contexts.Context; Element : Asis.Declaration; Name : Engines.Text_Property) return League.Strings.Universal_String; function Is_Dispatching (Engine : access Engines.Contexts.Context; Element : Asis.Declaration; Name : Engines.Boolean_Property) return Boolean; end Properties.Declarations.Function_Declarations;
micahwelf/FLTK-Ada
Ada
917
ads
package FLTK.Widgets.Buttons.Light.Radio is type Radio_Light_Button is new Light_Button with private; type Radio_Light_Button_Reference (Data : not null access Radio_Light_Button'Class) is limited null record with Implicit_Dereference => Data; package Forge is function Create (X, Y, W, H : in Integer; Text : in String) return Radio_Light_Button; end Forge; procedure Draw (This : in out Radio_Light_Button); function Handle (This : in out Radio_Light_Button; Event : in Event_Kind) return Event_Outcome; private type Radio_Light_Button is new Light_Button with null record; overriding procedure Finalize (This : in out Radio_Light_Button); pragma Inline (Draw); pragma Inline (Handle); end FLTK.Widgets.Buttons.Light.Radio;
zhmu/ananas
Ada
263
ads
with Equal4_Smart_Pointers; generic package Equal4_Controlled_Filter is type Object_T is private; function True return Object_T; private package Smart is new Equal4_Smart_Pointers; type Object_T is new Smart.Pointer; end Equal4_Controlled_Filter;
zhmu/ananas
Ada
229
ads
generic type Data_T is private; package Generic_Inst13_Pkg.Ops_G is type List_T is array (Positive range <>) of Data_T; function "or" (Left, Right : Data_T) return List_T is ((Left, Right)); end Generic_Inst13_Pkg.Ops_G;
ohenley/ada-util
Ada
1,164
ads
----------------------------------------------------------------------- -- util-streams-buffered-lzma-tests -- Unit tests for LZMA buffered streams -- Copyright (C) 2018 Stephane Carrez -- Written by Stephane Carrez ([email protected]) -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. ----------------------------------------------------------------------- with Util.Tests; package Util.Streams.Buffered.Lzma.Tests is procedure Add_Tests (Suite : in Util.Tests.Access_Test_Suite); type Test is new Util.Tests.Test with null record; procedure Test_Compress_Stream (T : in out Test); end Util.Streams.Buffered.Lzma.Tests;
charlie5/cBound
Ada
1,687
ads
-- This file is generated by SWIG. Please do not modify by hand. -- with Interfaces; with Interfaces.C; with Interfaces.C.Pointers; package xcb.xcb_glx_get_materialiv_request_t is -- Item -- type Item is record major_opcode : aliased Interfaces.Unsigned_8; minor_opcode : aliased Interfaces.Unsigned_8; length : aliased Interfaces.Unsigned_16; context_tag : aliased xcb.xcb_glx_context_tag_t; face : aliased Interfaces.Unsigned_32; pname : aliased Interfaces.Unsigned_32; end record; -- Item_Array -- type Item_Array is array (Interfaces.C .size_t range <>) of aliased xcb.xcb_glx_get_materialiv_request_t .Item; -- Pointer -- package C_Pointers is new Interfaces.C.Pointers (Index => Interfaces.C.size_t, Element => xcb.xcb_glx_get_materialiv_request_t.Item, Element_Array => xcb.xcb_glx_get_materialiv_request_t.Item_Array, Default_Terminator => (others => <>)); subtype Pointer is C_Pointers.Pointer; -- Pointer_Array -- type Pointer_Array is array (Interfaces.C .size_t range <>) of aliased xcb.xcb_glx_get_materialiv_request_t .Pointer; -- Pointer_Pointer -- package C_Pointer_Pointers is new Interfaces.C.Pointers (Index => Interfaces.C.size_t, Element => xcb.xcb_glx_get_materialiv_request_t.Pointer, Element_Array => xcb.xcb_glx_get_materialiv_request_t.Pointer_Array, Default_Terminator => null); subtype Pointer_Pointer is C_Pointer_Pointers.Pointer; end xcb.xcb_glx_get_materialiv_request_t;
burratoo/Acton
Ada
6,747
adb
------------------------------------------------------------------------------------------ -- -- -- OAK CORE SUPPORT PACKAGE -- -- FREESCALE e200 -- -- -- -- OAK.CORE_SUPPORT_PACKAGE.TASK_SUPPORT -- -- -- -- Copyright (C) 2010-2021, Patrick Bernardi -- -- -- ------------------------------------------------------------------------------------------ with System.Machine_Code; use System.Machine_Code; with Oak.Core_Support_Package.Interrupts; use Oak.Core_Support_Package.Interrupts; package body Oak.Core_Support_Package.Task_Support is -------------------------------- -- Initialise_Task_Enviroment -- -------------------------------- procedure Initialise_Task_Enviroment is begin null; end Initialise_Task_Enviroment; -------------------- -- Context_Switch -- -------------------- procedure Context_Switch is begin Asm ("sc", Volatile => True); end Context_Switch; ----------------------------- -- Context_Switch_From_Oak -- ------------------------------ procedure Context_Switch_From_Oak (Reason_For_Oak_To_Run : out Run_Reason; Message_Address : out Address) is begin Asm ("sc" & ASCII.LF & ASCII.HT & "mr %0, r3" & ASCII.LF & ASCII.HT & "mr %1, r4", Outputs => (Run_Reason'Asm_Output ("=r", Reason_For_Oak_To_Run), Address'Asm_Output ("=r", Message_Address)), Clobber => "r14, r15, r16, r17, r18, r19, r20, r21, r22, r23, r24," & " r25, r26, r27, r28, r29, r30, r31, cc, ctr, lr", Volatile => True); end Context_Switch_From_Oak; --------------------------- -- Context_Switch_To_Oak -- --------------------------- procedure Context_Switch_To_Oak (Reason_For_Run : in Run_Reason; Message : in out Oak_Message) is begin -- Since this will be inlined, explicitly move parameters into r3 and r4 Asm ("sc", Inputs => (Run_Reason'Asm_Input ("r", Reason_For_Run), Address'Asm_Input ("r", Message'Address)), Clobber => "r14, r15, r16, r17, r18, r19, r20, r21, r22, r23, r24," & " r25, r26, r27, r28, r29, r30, r31, cc, ctr, lr", Volatile => True); end Context_Switch_To_Oak; ------------------------------------------ -- Context_Switch_Save_Callee_Registers -- ------------------------------------------ procedure Context_Switch_Save_Callee_Registers is begin Asm ("sc", Volatile => True, Clobber => "r14, r15, r16, r17, r18, r19, r20, r21, r22, r23, r24, " & "r25, r26, r27, r28, r29, r30, r31, cc, ctr, lr"); end Context_Switch_Save_Callee_Registers; ------------------------------------------------ -- Context_Switch_Will_Be_To_Interrupted_Task -- ------------------------------------------------ procedure Context_Switch_Will_Be_To_Interrupted_Task is begin Asm ("mtivor8 %0" & ASCII.LF & ASCII.HT & "mtsprg2 %1", Inputs => (System.Address'Asm_Input ("r", Full_Context_Switch_To_Agent_Interrupt'Address), System.Address'Asm_Input ("r", Request_Context_Switch_To_Oak_Interrupt'Address)), Volatile => True); end Context_Switch_Will_Be_To_Interrupted_Task; ----------------------------------------------- -- Context_Switch_Will_Be_To_Agent -- ----------------------------------------------- procedure Context_Switch_Will_Be_To_Agent is begin Asm ("mtivor8 %0" & ASCII.LF & ASCII.HT & "mtsprg2 %1", Inputs => (System.Address'Asm_Input ("r", Request_Context_Switch_To_Agent_Interrupt'Address), System.Address'Asm_Input ("r", Request_Context_Switch_To_Oak_Interrupt'Address)), Volatile => True); end Context_Switch_Will_Be_To_Agent; ----------------------------------------- -- Context_Switch_Will_Switch_In_Place -- ----------------------------------------- procedure Context_Switch_Will_Switch_In_Place is begin Asm ("mtivor8 %0" & ASCII.LF & ASCII.HT & "mtsprg2 %1", Inputs => (System.Address'Asm_Input ("r", In_Place_Context_Switch_To_Agent_Interrupt'Address), System.Address'Asm_Input ("r", In_Place_Context_Switch_To_Oak_Interrupt'Address)), Volatile => True); end Context_Switch_Will_Switch_In_Place; ---------------------------- -- Enter_Barrier_Function -- ---------------------------- procedure Enter_Barrier_Function is begin -- Context_Switch_Will_Switch_In_Place; -- Context_Switch_Save_Callee_Registers; null; end Enter_Barrier_Function; --------------------------- -- Exit_Barrier_Function -- --------------------------- procedure Exit_Barrier_Function is begin -- Context_Switch; null; end Exit_Barrier_Function; --------------------------- -- Set_Oak_Wake_Up_Timer -- --------------------------- procedure Set_Oak_Wake_Up_Timer (Wake_Up_At : in Oak.Oak_Time.Time) is use Oak.Oak_Time; Decrementer_Value : Oak_Time.Time_Span; begin -- Do have a problem when the TBL overflows into the TBU -- Set decrementer to minimum value if clock is less than zero. Decrementer_Value := Wake_Up_At - Oak_Time.Clock; if Decrementer_Value <= Oak_Time.Time_Span_Zero then Decrementer_Value := Oak_Time.Time_Span_Unit; end if; Asm ("mtdec %L0", -- Load Wake Up Time into decrementer register Inputs => (Oak_Time.Time_Span'Asm_Input ("r", Decrementer_Value)), Volatile => True); end Set_Oak_Wake_Up_Timer; ------------------ -- Sleep_Agent -- ------------------ procedure Sleep_Agent_Run_Loop is begin -- On the e200 we do not have a sleep instruction so we just burn -- processor cycles looping loop null; end loop; end Sleep_Agent_Run_Loop; end Oak.Core_Support_Package.Task_Support;
kjseefried/coreland-cgbc
Ada
796
adb
with Ada.Strings; with CGBC.Bounded_Wide_Wide_Strings; with Test; procedure T_WWBstr_Append_L02 is package BS renames CGBC.Bounded_Wide_Wide_Strings; TC : Test.Context_t; S1 : BS.Bounded_String (8); begin Test.Initialize (Test_Context => TC, Program => "t_wwbstr_append_l02", Test_DB => "TEST_DB", Test_Results => "TEST_RESULTS"); BS.Append (S1, "ABCDEFG"); -- Does not require truncation. BS.Append (Source => S1, New_Item => "H", Drop => Ada.Strings.Left); Test.Check (TC, 2212, BS.Length (S1) = 8, "BS.Length (S1) = 8"); Test.Check (TC, 2213, BS.Maximum_Length (S1) = 8, "BS.Maximum_Length (S1) = 8"); Test.Check (TC, 2214, BS.To_String (S1) = "ABCDEFGH", "BS.To_String (S1) = ""ABCDEFGH"""); end T_WWBstr_Append_L02;
AdaCore/libadalang
Ada
164
ads
package Pkg.Child_Pkg is pragma Elaborate_Body; Origin_Pkg_Child_Pkg_Public : Integer; private Origin_Pkg_Child_Pkg_Private : Integer; end Pkg.Child_Pkg;
reznikmm/matreshka
Ada
3,659
ads
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- Open Document Toolkit -- -- -- -- Runtime Library Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2014, Vadim Godunko <[email protected]> -- -- All rights reserved. -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions -- -- are met: -- -- -- -- * Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- -- -- * Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in the -- -- documentation and/or other materials provided with the distribution. -- -- -- -- * Neither the name of the Vadim Godunko, IE nor the names of its -- -- contributors may be used to endorse or promote products derived from -- -- this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -- -- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED -- -- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -- -- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -- -- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -- -- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -- -- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- -- ------------------------------------------------------------------------------ -- $Revision$ $Date$ ------------------------------------------------------------------------------ with XML.DOM.Elements; package ODF.DOM.Draw_Polygon_Elements is pragma Preelaborate; type ODF_Draw_Polygon is limited interface and XML.DOM.Elements.DOM_Element; type ODF_Draw_Polygon_Access is access all ODF_Draw_Polygon'Class with Storage_Size => 0; end ODF.DOM.Draw_Polygon_Elements;
python36/vibecrypt
Ada
1,945
adb
package body raiden is procedure init_key(key_init : key_s) is begin for i in 0..3 loop key(i) := to_dword( byte(Character'pos(key_init(1 + 4 * i))), byte(Character'pos(key_init(2 + 4 * i))), byte(Character'pos(key_init(3 + 4 * i))), byte(Character'pos(key_init(4 + 4 * i)))); end loop; end init_key; procedure raiden_encrypt (m : in byte_array_8; c : out byte_array_8) is b0 : dword := to_dword(m(0), m(1), m(2), m(3)); b1 : dword := to_dword(m(4), m(5), m(6), m(7)); begin t_k := key; for i in 0..15 loop t_k(i mod 4) := (t_k(0) + t_k(1)) + (((t_k(2) + t_k(3)) xor dword_shift_left(t_k(0), integer(t_k(2) and 16#1F#)))); b0 := b0 + (dword_shift_left(t_k(i mod 4) + b1, 9) xor ((t_k(i mod 4) - b1) xor dword_shift_right((t_k(i mod 4) + b1), 14))); b1 := b1 + (dword_shift_left(t_k(i mod 4) + b0, 9) xor ((t_k(i mod 4) - b0) xor dword_shift_right((t_k(i mod 4) + b0), 14))); end loop; to_byte(b0, c(0), c(1), c(2), c(3)); to_byte(b1, c(4), c(5), c(6), c(7)); end raiden_encrypt; procedure raiden_decrypt (c : in byte_array_8; m : out byte_array_8) is b0 : dword := to_dword(c(0), c(1), c(2), c(3)); b1 : dword := to_dword(c(4), c(5), c(6), c(7)); subkeys : array (integer range 0..15) of dword; begin t_k := key; for i in 0..15 loop subkeys(i) := (t_k(0) + t_k(1)) + (((t_k(2) + t_k(3)) xor dword_shift_left(t_k(0), integer(t_k(2) and 16#1F#)))); t_k(i mod 4) := subkeys(i); end loop; for i in reverse 0..15 loop b1 := b1 - (dword_shift_left(subkeys(i) + b0, 9) xor ((subkeys(i) - b0) xor dword_shift_right((subkeys(i) + b0), 14))); b0 := b0 - (dword_shift_left(subkeys(i) + b1, 9) xor ((subkeys(i) - b1) xor dword_shift_right((subkeys(i) + b1), 14))); end loop; to_byte(b0, m(0), m(1), m(2), m(3)); to_byte(b1, m(4), m(5), m(6), m(7)); end raiden_decrypt; end raiden;
pombredanne/ravenadm
Ada
12,989
adb
-- This file is covered by the Internet Software Consortium (ISC) License -- Reference: License.txt with Ada.Command_Line; with Ada.Text_IO; with Parameters; with Pilot; with Unix; procedure Ravenadm is package CLI renames Ada.Command_Line; package TIO renames Ada.Text_IO; type mandate_type is (unset, help, dev, build, build_everything, force, test, test_everything, status, status_everything, configure, locate, purge, changeopts, checkports, portsnap, repository, list_subpackages, website); type dev_mandate is (unset, dump, makefile, distinfo, buildsheet, template, genindex, web); procedure scan_first_command_word; function scan_dev_command_word return dev_mandate; function get_arg (arg_number : Positive) return String; mandate : mandate_type := unset; low_rights : Boolean := False; procedure scan_first_command_word is first : constant String := CLI.Argument (1); begin if first = "help" then mandate := help; elsif first = "dev" then mandate := dev; elsif first = "build" then mandate := build; elsif first = "build-everything" then mandate := build_everything; elsif first = "force" then mandate := force; elsif first = "test" then mandate := test; elsif first = "test-everything" then mandate := test_everything; elsif first = "status" then mandate := status; elsif first = "status-everything" then mandate := status_everything; elsif first = "configure" then mandate := configure; elsif first = "locate" then mandate := locate; elsif first = "purge-distfiles" then mandate := purge; elsif first = "set-options" then mandate := changeopts; elsif first = "check-ports" then mandate := checkports; elsif first = "update-ports" then mandate := portsnap; elsif first = "generate-repository" then mandate := repository; elsif first = "subpackages" then mandate := list_subpackages; elsif first = "generate-website" then mandate := website; end if; end scan_first_command_word; function scan_dev_command_word return dev_mandate is -- Check argument count before calling second : constant String := CLI.Argument (2); begin if second = "dump" then return dump; elsif second = "makefile" then return makefile; elsif second = "distinfo" then return distinfo; elsif second = "buildsheet" then return buildsheet; elsif second = "template" then return template; elsif second = "generate-index" then return genindex; elsif second = "web" then return web; else return unset; end if; end scan_dev_command_word; function get_arg (arg_number : Positive) return String is begin if CLI.Argument_Count >= arg_number then return CLI.Argument (arg_number); else return ""; end if; end get_arg; begin if CLI.Argument_Count = 0 then Pilot.display_usage; return; end if; scan_first_command_word; if mandate = unset then Pilot.react_to_unknown_first_level_command (CLI.Argument (1)); return; end if; -------------------------------------------------------------------------------------------- -- Validation block start -------------------------------------------------------------------------------------------- if Pilot.already_running then return; end if; if not Parameters.load_configuration then return; end if; case mandate is when build | build_everything | test | status | status_everything => -- All commands involving replicant slaves if Pilot.launch_clash_detected then return; end if; when others => null; end case; case mandate is when build | build_everything | test => if Parameters.configuration.avec_ncurses and then not Pilot.TERM_defined_in_environment then return; end if; when others => null; end case; case mandate is when configure | help => null; when portsnap => if not Parameters.all_paths_valid (skip_mk_check => True) then return; end if; when others => if not Parameters.all_paths_valid (skip_mk_check => False) then return; end if; end case; case mandate is when help | locate | list_subpackages => null; low_rights := True; when others => if Pilot.insufficient_privileges then return; end if; end case; if Pilot.previous_run_mounts_detected and then not Pilot.old_mounts_successfully_removed then return; end if; if Pilot.previous_realfs_work_detected and then not Pilot.old_realfs_work_successfully_removed then return; end if; if Pilot.ravenexec_missing then return; end if; case mandate is when build | force | test | changeopts | list_subpackages => if not Pilot.store_origins (start_from => 2) then return; end if; when status => if CLI.Argument_Count > 1 then if not Pilot.store_origins (start_from => 2) then return; end if; end if; when others => null; end case; case mandate is when build | build_everything | force | test | test_everything | status | status_everything => Pilot.check_that_ravenadm_is_modern_enough; if not Pilot.slave_platform_determined then return; end if; when others => null; end case; if not low_rights then Pilot.create_pidfile; Unix.ignore_background_tty; end if; if mandate /= configure then Unix.cone_of_silence (deploy => True); end if; -------------------------------------------------------------------------------------------- -- Validation block end -------------------------------------------------------------------------------------------- case mandate is when status => -------------------------------- -- status command -------------------------------- if CLI.Argument_Count > 1 then if Pilot.install_compiler_packages and then Pilot.scan_stack_of_single_ports (always_build => False) and then Pilot.sanity_check_then_prefail (delete_first => False, dry_run => True) then Pilot.display_results_of_dry_run; end if; else null; -- reserved for upgrade_system_everything maybe end if; when status_everything => -------------------------------- -- status_everything command -------------------------------- if Pilot.install_compiler_packages and then Pilot.fully_scan_ports_tree and then Pilot.sanity_check_then_prefail (delete_first => False, dry_run => True) then Pilot.display_results_of_dry_run; end if; when build => -------------------------------- -- build command -------------------------------- if Pilot.install_compiler_packages and then Pilot.scan_stack_of_single_ports (always_build => False) and then Pilot.sanity_check_then_prefail (delete_first => False, dry_run => False) then Pilot.perform_bulk_run (testmode => False); end if; when build_everything => -------------------------------- -- build-everything command -------------------------------- if Pilot.install_compiler_packages and then Pilot.fully_scan_ports_tree and then Pilot.sanity_check_then_prefail (delete_first => False, dry_run => False) then Pilot.perform_bulk_run (testmode => False); end if; when test_everything => -------------------------------- -- test-everything command -------------------------------- if Pilot.install_compiler_packages and then Pilot.fully_scan_ports_tree and then Pilot.sanity_check_then_prefail (delete_first => True, dry_run => False) then Pilot.perform_bulk_run (testmode => True); end if; when website => -------------------------------- -- generate-website command -------------------------------- Pilot.generate_website; when force => -------------------------------- -- force command -------------------------------- if Pilot.install_compiler_packages and then Pilot.scan_stack_of_single_ports (always_build => False) and then Pilot.sanity_check_then_prefail (delete_first => True, dry_run => False) then Pilot.perform_bulk_run (testmode => False); end if; when dev => -------------------------------- -- dev command -------------------------------- if CLI.Argument_Count > 1 then declare dev_subcmd : dev_mandate := scan_dev_command_word; begin case dev_subcmd is when unset => Pilot.react_to_unknown_second_level_command (CLI.Argument (1), CLI.Argument (2)); when dump => Pilot.dump_ravensource (get_arg (3)); when distinfo => Pilot.generate_distinfo; when buildsheet => Pilot.generate_buildsheet (get_arg (3), get_arg (4)); when makefile => Pilot.generate_makefile (get_arg (3), get_arg (4)); when web => Pilot.generate_webpage (get_arg (3), get_arg (4)); when template => Pilot.print_spec_template (get_arg (3)); when genindex => Pilot.generate_ports_index; end case; end; else Pilot.react_to_unknown_second_level_command (CLI.Argument (1), ""); end if; when help => -------------------------------- -- help command -------------------------------- if CLI.Argument_Count > 1 then Pilot.launch_man_page (CLI.Argument (2)); else Pilot.show_short_help; end if; when test => -------------------------------- -- test command -------------------------------- if Pilot.install_compiler_packages and then Pilot.scan_stack_of_single_ports (always_build => True) and then Pilot.sanity_check_then_prefail (delete_first => True, dry_run => False) then if Pilot.interact_with_single_builder then Pilot.bulk_run_then_interact_with_final_port; else Pilot.perform_bulk_run (testmode => True); end if; end if; when configure => -------------------------------- -- configure -------------------------------- Pilot.launch_configure_menu; when locate => -------------------------------- -- locate -------------------------------- Pilot.locate (get_arg (2)); when list_subpackages => -------------------------------- -- subpackages -------------------------------- Pilot.list_subpackages; when purge => -------------------------------- -- purge-distfiles -------------------------------- Pilot.purge_distfiles; when changeopts => -------------------------------- -- set-options -------------------------------- Pilot.change_options; when checkports => -------------------------------- -- check-ports -------------------------------- Pilot.check_ravenports_version; when portsnap => -------------------------------- -- update-ports -------------------------------- Pilot.update_to_latest_ravenports; when repository => -------------------------------- -- generate-repository -------------------------------- Pilot.generate_repository; when unset => null; end case; Unix.cone_of_silence (deploy => False); if not low_rights then Pilot.destroy_pidfile; end if; end Ravenadm;
sungyeon/drake
Ada
4,283
adb
-- find circular dependency with Ada.Command_Line; with Ada.Containers.Indefinite_Ordered_Maps; with Ada.Containers.Indefinite_Ordered_Sets; with Ada.Directories; with Ada.Strings.Functions; with Ada.Strings.Unbounded; with Ada.Text_IO.Iterators; procedure cirdep is use type Ada.Strings.Unbounded.Unbounded_String; procedure Usage is begin Ada.Text_IO.Put_Line ("usage: cirdep --RTS=dir"); end Usage; RTS_Dir : Ada.Strings.Unbounded.Unbounded_String; begin -- arguments for I in Ada.Command_Line.Iterate loop declare Item : constant String := Ada.Command_Line.Argument (I); begin if Item'Length > 6 and then Item (Item'First .. Item'First + 5) = "--RTS=" then RTS_Dir := +Item (Item'First + 6 .. Item'Last); else Usage; return; end if; end; end loop; if RTS_Dir = Ada.Strings.Unbounded.Null_Unbounded_String then Usage; return; end if; declare package Unit_Sets is new Ada.Containers.Indefinite_Ordered_Sets (String); use type Unit_Sets.Set; package Unit_To_Unit_Sets_Maps is new Ada.Containers.Indefinite_Ordered_Maps (String, Unit_Sets.Set); Table : Unit_To_Unit_Sets_Maps.Map; begin -- reading for E of Ada.Directories.Entries ( Ada.Directories.Compose (RTS_Dir.Constant_Reference, "adalib"), "*.ali") loop declare Name : constant String := Ada.Directories.Base_Name (Ada.Directories.Simple_Name (E)); The_Set : Unit_Sets.Set; File : Ada.Text_IO.File_Type := Ada.Text_IO.Open (Ada.Text_IO.In_File, Ada.Directories.Full_Name (E)); begin for Line of Ada.Text_IO.Iterators.Lines (File) loop if Line'Length >= 2 and then Line (Line'First .. Line'First + 1) = "D " then declare Dep_Name : constant String := Line ( Line'First + 2 .. Ada.Strings.Functions.Index_Element (Line (Line'First + 2 .. Line'Last), '.') - 1); begin if Dep_Name /= Name then Unit_Sets.Include (The_Set, Dep_Name); end if; end; end if; end loop; Ada.Text_IO.Close (File); Unit_To_Unit_Sets_Maps.Insert (Table, Name, The_Set); end; end loop; -- removing separated units for I in Table.Iterate loop declare The_Set : Unit_Sets.Set renames Table.Reference (I); J : Unit_Sets.Cursor := The_Set.First; begin while Unit_Sets.Has_Element (J) loop declare Next : constant Unit_Sets.Cursor := Unit_Sets.Next (J); Dep_Name : constant String := The_Set.Constant_Reference (J); begin if not Unit_To_Unit_Sets_Maps.Contains (Table, Dep_Name) then Unit_Sets.Delete (The_Set, J); end if; J := Next; end; end loop; end; end loop; -- searching loop declare Changed : Boolean := False; begin for I in Table.Iterate loop declare Name : constant String := Unit_To_Unit_Sets_Maps.Key (I); The_Set : Unit_Sets.Set renames Table.Reference (I); begin for J in The_Set.Iterate loop declare Dep_Name : constant String := The_Set.Constant_Reference (J); The_Grandchildren : Unit_Sets.Set renames Table.Constant_Reference (Dep_Name); begin for K in The_Grandchildren.Iterate loop declare G_Dep_Name : constant String := The_Grandchildren.Constant_Reference (K); begin if G_Dep_Name /= Name and then not The_Set.Contains (G_Dep_Name) then Unit_Sets.Include (The_Set, G_Dep_Name); Changed := True; end if; end; end loop; end; end loop; end; end loop; exit when not Changed; end; end loop; -- detecting for I in Table.Iterate loop declare Name : constant String := Unit_To_Unit_Sets_Maps.Key (I); The_Set : Unit_Sets.Set renames Table.Constant_Reference (I); begin for J in The_Set.Iterate loop declare Dep_Name : constant String := The_Set.Constant_Reference (J); begin if Unit_Sets.Contains (Table.Constant_Reference (Dep_Name), Name) then Ada.Text_IO.Put (Name); Ada.Text_IO.Put (" <=> "); Ada.Text_IO.Put (The_Set.Constant_Reference (J)); Ada.Text_IO.New_Line; end if; end; end loop; end; end loop; end; end cirdep;
vikasbidhuri1995/DW1000
Ada
30,755
ads
------------------------------------------------------------------------------- -- Copyright (c) 2016 Daniel King -- -- Permission is hereby granted, free of charge, to any person obtaining a -- copy of this software and associated documentation files (the "Software"), -- to deal in the Software without restriction, including without limitation -- the rights to use, copy, modify, merge, publish, distribute, sublicense, -- and/or sell copies of the Software, and to permit persons to whom the -- Software is furnished to do so, subject to the following conditions: -- -- The above copyright notice and this permission notice shall be included in -- all copies or substantial portions of the Software. -- -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -- FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -- DEALINGS IN THE SOFTWARE. ------------------------------------------------------------------------------- with DW1000.Generic_RO_Register_Driver; with DW1000.Generic_WO_Register_Driver; with DW1000.Generic_RW_Register_Driver; with DW1000.Register_Types; with DW1000.Types; pragma Elaborate_All (DW1000.Generic_RO_Register_Driver); pragma Elaborate_All (DW1000.Generic_WO_Register_Driver); pragma Elaborate_All (DW1000.Generic_RW_Register_Driver); -- This package defines register driver instances for each of the DW1000 -- device registers to allow for typed reading and writing each register -- (or sub-register). -- -- Each register is typed, using the corresponding type defined in the package -- DW1000.Register_Types. These types allow for easy manipulation for the -- register's fields. -- -- Below is an example of modifying the receive and transmit channels from -- the CHAN_CTRL register (package names omitted for clarity): -- declare -- Reg : CHAN_CTRL_Type; -- begin -- CHAN_CTRL.Read(Reg); -- Reg.RX_CHAN := 5; -- Reg.TX_CHAN := 5; -- CHAN_CTRL.Write(Reg); -- end; package DW1000.Registers with SPARK_Mode => On is ---------------------------------------------------------------------------- -- Register IDs DEV_ID_Reg_ID : constant Types.Bits_6 := 16#00#; EUI_Reg_ID : constant Types.Bits_6 := 16#01#; PANADR_Reg_ID : constant Types.Bits_6 := 16#03#; SYS_CFG_Reg_ID : constant Types.Bits_6 := 16#04#; SYS_TIME_Reg_ID : constant Types.Bits_6 := 16#06#; TX_FCTRL_Reg_ID : constant Types.Bits_6 := 16#08#; TX_BUFFER_Reg_ID : constant Types.Bits_6 := 16#09#; DX_TIME_Reg_ID : constant Types.Bits_6 := 16#0A#; RX_FWTO_Reg_ID : constant Types.Bits_6 := 16#0C#; SYS_CTRL_Reg_ID : constant Types.Bits_6 := 16#0D#; SYS_MASK_Reg_ID : constant Types.Bits_6 := 16#0E#; SYS_STATUS_Reg_ID : constant Types.Bits_6 := 16#0F#; RX_FINFO_Reg_ID : constant Types.Bits_6 := 16#10#; RX_BUFFER_Reg_ID : constant Types.Bits_6 := 16#11#; RX_FQUAL_Reg_ID : constant Types.Bits_6 := 16#12#; RX_TTCKI_Reg_ID : constant Types.Bits_6 := 16#13#; RX_TTCKO_Reg_ID : constant Types.Bits_6 := 16#14#; RX_TIME_Reg_ID : constant Types.Bits_6 := 16#15#; TX_TIME_Reg_ID : constant Types.Bits_6 := 16#17#; TX_ANTD_Reg_ID : constant Types.Bits_6 := 16#18#; SYS_STATE_Reg_ID : constant Types.Bits_6 := 16#19#; ACK_RESP_T_Reg_ID : constant Types.Bits_6 := 16#1A#; RX_SNIFF_Reg_ID : constant Types.Bits_6 := 16#1D#; TX_POWER_Reg_ID : constant Types.Bits_6 := 16#1E#; CHAN_CTRL_Reg_ID : constant Types.Bits_6 := 16#1F#; USR_SFD_Reg_ID : constant Types.Bits_6 := 16#21#; AGC_CTRL_Reg_ID : constant Types.Bits_6 := 16#23#; EXT_SYNC_Reg_ID : constant Types.Bits_6 := 16#24#; ACC_MEM_Reg_ID : constant Types.Bits_6 := 16#25#; GPIO_CTRL_Reg_ID : constant Types.Bits_6 := 16#26#; DRX_CONF_Reg_ID : constant Types.Bits_6 := 16#27#; RF_CONF_Reg_ID : constant Types.Bits_6 := 16#28#; TX_CAL_Reg_ID : constant Types.Bits_6 := 16#2A#; FS_CTRL_Reg_ID : constant Types.Bits_6 := 16#2B#; AON_Reg_ID : constant Types.Bits_6 := 16#2C#; OTP_IF_Reg_ID : constant Types.Bits_6 := 16#2D#; LDE_CTRL_Reg_ID : constant Types.Bits_6 := 16#2E#; DIG_DIAG_Reg_ID : constant Types.Bits_6 := 16#2F#; PMSC_Reg_ID : constant Types.Bits_6 := 16#36#; ---------------------------------------------------------------------------- -- Sub-Register IDs AGC_CTRL1_Sub_Reg_ID : constant Types.Bits_15 := 16#02#; AGC_TUNE1_Sub_Reg_ID : constant Types.Bits_15 := 16#04#; AGC_TUNE2_Sub_Reg_ID : constant Types.Bits_15 := 16#0C#; AGC_TUNE3_Sub_Reg_ID : constant Types.Bits_15 := 16#12#; AGC_STAT1_Sub_Reg_ID : constant Types.Bits_15 := 16#1E#; EC_CTRL_Sub_Reg_ID : constant Types.Bits_15 := 16#00#; EC_RXTC_Sub_Reg_ID : constant Types.Bits_15 := 16#04#; EC_GOLP_Sub_Reg_ID : constant Types.Bits_15 := 16#08#; GPIO_MODE_Sub_Reg_ID : constant Types.Bits_15 := 16#00#; GPIO_DIR_Sub_Reg_ID : constant Types.Bits_15 := 16#08#; GPIO_DOUT_Sub_Reg_ID : constant Types.Bits_15 := 16#0C#; GPIO_IRQE_Sub_Reg_ID : constant Types.Bits_15 := 16#10#; GPIO_ISEN_Sub_Reg_ID : constant Types.Bits_15 := 16#14#; GPIO_IMODE_Sub_Reg_ID : constant Types.Bits_15 := 16#18#; GPIO_IBES_Sub_Reg_ID : constant Types.Bits_15 := 16#1C#; GPIO_ICLR_Sub_Reg_ID : constant Types.Bits_15 := 16#20#; GPIO_IDBE_Sub_Reg_ID : constant Types.Bits_15 := 16#24#; GPIO_RAW_Sub_Reg_ID : constant Types.Bits_15 := 16#28#; DRX_TUNE0b_Sub_Reg_ID : constant Types.Bits_15 := 16#02#; DRX_TUNE1a_Sub_Reg_ID : constant Types.Bits_15 := 16#04#; DRX_TUNE1b_Sub_Reg_ID : constant Types.Bits_15 := 16#06#; DRX_TUNE2_Sub_Reg_ID : constant Types.Bits_15 := 16#08#; DRX_SFDTOC_Sub_Reg_ID : constant Types.Bits_15 := 16#20#; DRX_PRETOC_Sub_Reg_ID : constant Types.Bits_15 := 16#24#; DRX_TUNE4H_Sub_Reg_ID : constant Types.Bits_15 := 16#26#; RXPACC_NOSAT_Sub_Reg_ID : constant Types.Bits_15 := 16#2C#; RF_CONF_Sub_Reg_ID : constant Types.Bits_15 := 16#00#; RF_RXCTRLH_Sub_Reg_ID : constant Types.Bits_15 := 16#0B#; RF_TXCTRL_Sub_Reg_ID : constant Types.Bits_15 := 16#0C#; RF_STATUS_Sub_Reg_ID : constant Types.Bits_15 := 16#2C#; LDOTUNE_Sub_Reg_ID : constant Types.Bits_15 := 16#30#; TC_SARC_Sub_Reg_ID : constant Types.Bits_15 := 16#00#; TC_SARL_Sub_Reg_ID : constant Types.Bits_15 := 16#03#; TC_SARW_Sub_Reg_ID : constant Types.Bits_15 := 16#06#; TC_PG_CTRL_Sub_Reg_ID : constant Types.Bits_15 := 16#08#; TC_PG_STATUS_Sub_Reg_ID : constant Types.Bits_15 := 16#09#; TC_PGDELAY_Sub_Reg_ID : constant Types.Bits_15 := 16#0B#; TC_PGTEST_Sub_Reg_ID : constant Types.Bits_15 := 16#0C#; FS_PLLCFG_Sub_Reg_ID : constant Types.Bits_15 := 16#07#; FS_PLLTUNE_Sub_Reg_ID : constant Types.Bits_15 := 16#0B#; FS_XTALT_Sub_Reg_ID : constant Types.Bits_15 := 16#0E#; AON_WCFG_Sub_Reg_ID : constant Types.Bits_15 := 16#00#; AON_CTRL_Sub_Reg_ID : constant Types.Bits_15 := 16#02#; AON_RDAT_Sub_Reg_ID : constant Types.Bits_15 := 16#03#; AON_ADDR_Sub_Reg_ID : constant Types.Bits_15 := 16#04#; AON_CFG0_Sub_Reg_ID : constant Types.Bits_15 := 16#06#; AON_CFG1_Sub_Reg_ID : constant Types.Bits_15 := 16#0A#; OTP_WDAT_Sub_Reg_ID : constant Types.Bits_15 := 16#00#; OTP_ADDR_Sub_Reg_ID : constant Types.Bits_15 := 16#04#; OTP_CTRL_Sub_Reg_ID : constant Types.Bits_15 := 16#06#; OTP_STAT_Sub_Reg_ID : constant Types.Bits_15 := 16#08#; OTP_RDAT_Sub_Reg_ID : constant Types.Bits_15 := 16#0A#; OTP_SRDAT_Sub_Reg_ID : constant Types.Bits_15 := 16#0E#; OTP_SF_Sub_Reg_ID : constant Types.Bits_15 := 16#12#; LDE_THRESH_Sub_Reg_ID : constant Types.Bits_15 := 16#0000#; LDE_CFG1_Sub_Reg_ID : constant Types.Bits_15 := 16#0806#; LDE_PPINDX_Sub_Reg_ID : constant Types.Bits_15 := 16#1000#; LDE_PPAMPL_Sub_Reg_ID : constant Types.Bits_15 := 16#1002#; LDE_RXANTD_Sub_Reg_ID : constant Types.Bits_15 := 16#1804#; LDE_CFG2_Sub_Reg_ID : constant Types.Bits_15 := 16#1806#; LDE_REPC_Sub_Reg_ID : constant Types.Bits_15 := 16#2804#; EVC_CTRL_Sub_Reg_ID : constant Types.Bits_15 := 16#00#; EVC_PHE_Sub_Reg_ID : constant Types.Bits_15 := 16#04#; EVC_RSE_Sub_Reg_ID : constant Types.Bits_15 := 16#06#; EVC_FCG_Sub_Reg_ID : constant Types.Bits_15 := 16#08#; EVC_FCE_Sub_Reg_ID : constant Types.Bits_15 := 16#0A#; EVC_FFR_Sub_Reg_ID : constant Types.Bits_15 := 16#0C#; EVC_OVR_Sub_Reg_ID : constant Types.Bits_15 := 16#0E#; EVC_STO_Sub_Reg_ID : constant Types.Bits_15 := 16#10#; EVC_PTO_Sub_Reg_ID : constant Types.Bits_15 := 16#12#; EVC_FWTO_Sub_Reg_ID : constant Types.Bits_15 := 16#14#; EVC_TXFS_Sub_Reg_ID : constant Types.Bits_15 := 16#16#; EVC_HPW_Sub_Reg_ID : constant Types.Bits_15 := 16#18#; EVC_TPW_Sub_Reg_ID : constant Types.Bits_15 := 16#1A#; DIAG_TMC_Sub_Reg_ID : constant Types.Bits_15 := 16#24#; PMSC_CTRL0_Sub_Reg_ID : constant Types.Bits_15 := 16#00#; PMSC_CTRL1_Sub_Reg_ID : constant Types.Bits_15 := 16#04#; PMSC_SNOZT_Sub_Reg_ID : constant Types.Bits_15 := 16#0C#; PMSC_TXFSEQ_Sub_Reg_ID : constant Types.Bits_15 := 16#26#; PMSC_LEDC_Sub_Reg_ID : constant Types.Bits_15 := 16#28#; ---------------------------------------------------------------------------- -- Register Definitions package DEV_ID is new DW1000.Generic_RO_Register_Driver (Register_Type => DW1000.Register_Types.DEV_ID_Type, Register_ID => DEV_ID_Reg_ID); package EUI is new DW1000.Generic_RW_Register_Driver (Register_Type => DW1000.Register_Types.EUI_Type, Register_ID => EUI_Reg_ID); package PANADR is new DW1000.Generic_RW_Register_Driver (Register_Type => DW1000.Register_Types.PANADR_Type, Register_ID => PANADR_Reg_ID); package SYS_CFG is new DW1000.Generic_RW_Register_Driver (Register_Type => DW1000.Register_Types.SYS_CFG_Type, Register_ID => SYS_CFG_Reg_ID); package SYS_TIME is new DW1000.Generic_RO_Register_Driver (Register_Type => DW1000.Register_Types.SYS_TIME_Type, Register_ID => SYS_TIME_Reg_ID); package TX_FCTRL is new DW1000.Generic_RW_Register_Driver (Register_Type => DW1000.Register_Types.TX_FCTRL_Type, Register_ID => TX_FCTRL_Reg_ID); package TX_BUFFER is new DW1000.Generic_WO_Register_Driver (Register_Type => DW1000.Register_Types.TX_BUFFER_Type, Register_ID => TX_BUFFER_Reg_ID); package DX_TIME is new DW1000.Generic_RW_Register_Driver (Register_Type => DW1000.Register_Types.DX_TIME_Type, Register_ID => DX_TIME_Reg_ID); package RX_FWTO is new DW1000.Generic_RW_Register_Driver (Register_Type => DW1000.Register_Types.RX_FWTO_Type, Register_ID => RX_FWTO_Reg_ID); package SYS_CTRL is new DW1000.Generic_RW_Register_Driver (Register_Type => DW1000.Register_Types.SYS_CTRL_Type, Register_ID => SYS_CTRL_Reg_ID); package SYS_MASK is new DW1000.Generic_RW_Register_Driver (Register_Type => DW1000.Register_Types.SYS_MASK_Type, Register_ID => SYS_MASK_Reg_ID); package SYS_STATUS is new DW1000.Generic_RW_Register_Driver (Register_Type => DW1000.Register_Types.SYS_STATUS_Type, Register_ID => SYS_STATUS_Reg_ID); package RX_FINFO is new DW1000.Generic_RO_Register_Driver (Register_Type => DW1000.Register_Types.RX_FINFO_Type, Register_ID => RX_FINFO_Reg_ID); package RX_BUFFER is new DW1000.Generic_RO_Register_Driver (Register_Type => DW1000.Register_Types.RX_BUFFER_Type, Register_ID => RX_BUFFER_Reg_ID); package RX_FQUAL is new DW1000.Generic_RO_Register_Driver (Register_Type => DW1000.Register_Types.RX_FQUAL_Type, Register_ID => RX_FQUAL_Reg_ID); package RX_TTCKI is new DW1000.Generic_RO_Register_Driver (Register_Type => DW1000.Register_Types.RX_TTCKI_Type, Register_ID => RX_TTCKI_Reg_ID); package RX_TTCKO is new DW1000.Generic_RO_Register_Driver (Register_Type => DW1000.Register_Types.RX_TTCKO_Type, Register_ID => RX_TTCKO_Reg_ID); package RX_TIME is new DW1000.Generic_RO_Register_Driver (Register_Type => DW1000.Register_Types.RX_TIME_Type, Register_ID => RX_TIME_Reg_ID); package TX_TIME is new DW1000.Generic_RO_Register_Driver (Register_Type => DW1000.Register_Types.TX_TIME_Type, Register_ID => TX_TIME_Reg_ID); package TX_ANTD is new DW1000.Generic_RW_Register_Driver (Register_Type => DW1000.Register_Types.TX_ANTD_Type, Register_ID => TX_ANTD_Reg_ID); package SYS_STATE is new DW1000.Generic_RO_Register_Driver (Register_Type => DW1000.Register_Types.SYS_STATUS_Type, Register_ID => SYS_STATE_Reg_ID); package ACK_RESP_T is new DW1000.Generic_RW_Register_Driver (Register_Type => DW1000.Register_Types.ACK_RESP_T_Type, Register_ID => ACK_RESP_T_Reg_ID); package RX_SNIFF is new DW1000.Generic_RW_Register_Driver (Register_Type => DW1000.Register_Types.RX_SNIFF_Type, Register_ID => RX_SNIFF_Reg_ID); package TX_POWER is new DW1000.Generic_RW_Register_Driver (Register_Type => DW1000.Register_Types.TX_POWER_Type, Register_ID => TX_POWER_Reg_ID); package CHAN_CTRL is new DW1000.Generic_RW_Register_Driver (Register_Type => DW1000.Register_Types.CHAN_CTRL_Type, Register_ID => CHAN_CTRL_Reg_ID); package USR_SFD is new DW1000.Generic_RW_Register_Driver (Register_Type => DW1000.Register_Types.USR_SFD_Type, Register_ID => USR_SFD_Reg_ID); package AGC_CTRL1 is new DW1000.Generic_RW_Register_Driver (Register_Type => DW1000.Register_Types.AGC_CTRL1_Type, Register_ID => AGC_CTRL_Reg_ID, Sub_Register => AGC_CTRL1_Sub_Reg_ID); package AGC_TUNE1 is new DW1000.Generic_RW_Register_Driver (Register_Type => DW1000.Register_Types.AGC_TUNE1_Type, Register_ID => AGC_CTRL_Reg_ID, Sub_Register => AGC_CTRL1_Sub_Reg_ID); package AGC_TUNE2 is new DW1000.Generic_RW_Register_Driver (Register_Type => DW1000.Register_Types.AGC_TUNE2_Type, Register_ID => AGC_CTRL_Reg_ID, Sub_Register => AGC_TUNE2_Sub_Reg_ID); package AGC_TUNE3 is new DW1000.Generic_RW_Register_Driver (Register_Type => DW1000.Register_Types.AGC_TUNE3_Type, Register_ID => AGC_CTRL_Reg_ID, Sub_Register => AGC_TUNE3_Sub_Reg_ID); package AGC_STAT1 is new DW1000.Generic_RO_Register_Driver (Register_Type => DW1000.Register_Types.AGC_STAT1_Type, Register_ID => AGC_CTRL_Reg_ID, Sub_Register => AGC_STAT1_Sub_Reg_ID); package EC_CTRL is new DW1000.Generic_RW_Register_Driver (Register_Type => DW1000.Register_Types.EC_CTRL_Type, Register_ID => EXT_SYNC_Reg_ID, Sub_Register => EC_CTRL_Sub_Reg_ID); package EC_RXTC is new DW1000.Generic_RO_Register_Driver (Register_Type => DW1000.Register_Types.EC_RXTC_Type, Register_ID => EXT_SYNC_Reg_ID, Sub_Register => EC_RXTC_Sub_Reg_ID); package EC_GOLP is new DW1000.Generic_RO_Register_Driver (Register_Type => DW1000.Register_Types.EC_GOLP_Type, Register_ID => EXT_SYNC_Reg_ID, Sub_Register => EC_GOLP_Sub_Reg_ID); package ACC_MEM is new DW1000.Generic_RO_Register_Driver (Register_Type => DW1000.Register_Types.ACC_MEM_Type, Register_ID => ACC_MEM_Reg_ID); package GPIO_MODE is new DW1000.Generic_RW_Register_Driver (Register_Type => DW1000.Register_Types.GPIO_MODE_Type, Register_ID => GPIO_CTRL_Reg_ID, Sub_Register => GPIO_MODE_Sub_Reg_ID); package GPIO_DIR is new DW1000.Generic_RW_Register_Driver (Register_Type => DW1000.Register_Types.GPIO_DIR_Type, Register_ID => GPIO_CTRL_Reg_ID, Sub_Register => GPIO_DIR_Sub_Reg_ID); package GPIO_DOUT is new DW1000.Generic_RW_Register_Driver (Register_Type => DW1000.Register_Types.GPIO_DOUT_Type, Register_ID => GPIO_CTRL_Reg_ID, Sub_Register => GPIO_DOUT_Sub_Reg_ID); package GPIO_IRQE is new DW1000.Generic_RW_Register_Driver (Register_Type => DW1000.Register_Types.GPIO_IRQE_Type, Register_ID => GPIO_CTRL_Reg_ID, Sub_Register => GPIO_IRQE_Sub_Reg_ID); package GPIO_ISEN is new DW1000.Generic_RW_Register_Driver (Register_Type => DW1000.Register_Types.GPIO_ISEN_Type, Register_ID => GPIO_CTRL_Reg_ID, Sub_Register => GPIO_ISEN_Sub_Reg_ID); package GPIO_IMODE is new DW1000.Generic_RW_Register_Driver (Register_Type => DW1000.Register_Types.GPIO_IMODE_Type, Register_ID => GPIO_CTRL_Reg_ID, Sub_Register => GPIO_IMODE_Sub_Reg_ID); package GPIO_IBES is new DW1000.Generic_RW_Register_Driver (Register_Type => DW1000.Register_Types.GPIO_IBES_Type, Register_ID => GPIO_CTRL_Reg_ID, Sub_Register => GPIO_IBES_Sub_Reg_ID); package GPIO_ICLR is new DW1000.Generic_RW_Register_Driver (Register_Type => DW1000.Register_Types.GPIO_ICLR_Type, Register_ID => GPIO_CTRL_Reg_ID, Sub_Register => GPIO_ICLR_Sub_Reg_ID); package GPIO_IDBE is new DW1000.Generic_RW_Register_Driver (Register_Type => DW1000.Register_Types.GPIO_IDBE_Type, Register_ID => GPIO_CTRL_Reg_ID, Sub_Register => GPIO_IDBE_Sub_Reg_ID); package GPIO_RAW is new DW1000.Generic_RO_Register_Driver (Register_Type => DW1000.Register_Types.GPIO_RAW_Type, Register_ID => GPIO_CTRL_Reg_ID, Sub_Register => GPIO_RAW_Sub_Reg_ID); package DRX_TUNE0b is new DW1000.Generic_RW_Register_Driver (Register_Type => DW1000.Register_Types.DRX_TUNE0b_Type, Register_ID => DRX_CONF_Reg_ID, Sub_Register => DRX_TUNE0b_Sub_Reg_ID); package DRX_TUNE1a is new DW1000.Generic_RW_Register_Driver (Register_Type => DW1000.Register_Types.DRX_TUNE1a_Type, Register_ID => DRX_CONF_Reg_ID, Sub_Register => DRX_TUNE1a_Sub_Reg_ID); package DRX_TUNE1b is new DW1000.Generic_RW_Register_Driver (Register_Type => DW1000.Register_Types.DRX_TUNE1b_Type, Register_ID => DRX_CONF_Reg_ID, Sub_Register => DRX_TUNE1b_Sub_Reg_ID); package DRX_TUNE2 is new DW1000.Generic_RW_Register_Driver (Register_Type => DW1000.Register_Types.DRX_TUNE2_Type, Register_ID => DRX_CONF_Reg_ID, Sub_Register => DRX_TUNE2_Sub_Reg_ID); package DRX_SFDTOC is new DW1000.Generic_RW_Register_Driver (Register_Type => DW1000.Register_Types.DRX_SFDTOC_Type, Register_ID => DRX_CONF_Reg_ID, Sub_Register => DRX_SFDTOC_Sub_Reg_ID); package DRX_PRETOC is new DW1000.Generic_RW_Register_Driver (Register_Type => DW1000.Register_Types.DRX_PRETOC_Type, Register_ID => DRX_CONF_Reg_ID, Sub_Register => DRX_PRETOC_Sub_Reg_ID); package DRX_TUNE4H is new DW1000.Generic_RW_Register_Driver (Register_Type => DW1000.Register_Types.DRX_TUNE4H_Type, Register_ID => DRX_CONF_Reg_ID, Sub_Register => DRX_TUNE4H_Sub_Reg_ID); package RXPACC_NOSAT is new DW1000.Generic_RO_Register_Driver (Register_Type => DW1000.Register_Types.RXPACC_NOSAT_Type, Register_ID => DRX_CONF_Reg_ID, Sub_Register => RXPACC_NOSAT_Sub_Reg_ID); package RF_CONF is new DW1000.Generic_RW_Register_Driver (Register_Type => DW1000.Register_Types.RF_CONF_Type, Register_ID => RF_CONF_Reg_ID, Sub_Register => RF_CONF_Sub_Reg_ID); package RF_RXCTRLH is new DW1000.Generic_RW_Register_Driver (Register_Type => DW1000.Register_Types.RF_RXCTRLH_Type, Register_ID => RF_CONF_Reg_ID, Sub_Register => RF_RXCTRLH_Sub_Reg_ID); package RF_TXCTRL is new DW1000.Generic_RW_Register_Driver (Register_Type => DW1000.Register_Types.RF_TXCTRL_Type, Register_ID => RF_CONF_Reg_ID, Sub_Register => RF_TXCTRL_Sub_Reg_ID); package RF_STATUS is new DW1000.Generic_RO_Register_Driver (Register_Type => DW1000.Register_Types.RF_STATUS_Type, Register_ID => RF_CONF_Reg_ID, Sub_Register => RF_STATUS_Sub_Reg_ID); package LDOTUNE is new DW1000.Generic_RW_Register_Driver (Register_Type => DW1000.Register_Types.LDOTUNE_Type, Register_ID => RF_CONF_Reg_ID, Sub_Register => LDOTUNE_Sub_Reg_ID); package TC_SARC is new DW1000.Generic_RW_Register_Driver (Register_Type => DW1000.Register_Types.TC_SARC_Type, Register_ID => TX_CAL_Reg_ID, Sub_Register => TC_SARC_Sub_Reg_ID); package TC_SARL is new DW1000.Generic_RO_Register_Driver (Register_Type => DW1000.Register_Types.TC_SARL_Type, Register_ID => TX_CAL_Reg_ID, Sub_Register => TC_SARL_Sub_Reg_ID); package TC_SARW is new DW1000.Generic_RO_Register_Driver (Register_Type => DW1000.Register_Types.TC_SARW_Type, Register_ID => TX_CAL_Reg_ID, Sub_Register => TC_SARW_Sub_Reg_ID); package TC_PG_CTRL is new DW1000.Generic_RO_Register_Driver (Register_Type => DW1000.Register_Types.TC_PG_CTRL_Type, Register_ID => TX_CAL_Reg_ID, Sub_Register => TC_PG_CTRL_Sub_Reg_ID); package TC_PG_STATUS is new DW1000.Generic_RW_Register_Driver (Register_Type => DW1000.Register_Types.TC_PG_STATUS_Type, Register_ID => TX_CAL_Reg_ID, Sub_Register => TC_PG_STATUS_Sub_Reg_ID); package TC_PGDELAY is new DW1000.Generic_RW_Register_Driver (Register_Type => DW1000.Register_Types.TC_PGDELAY_Type, Register_ID => TX_CAL_Reg_ID, Sub_Register => TC_PGDELAY_Sub_Reg_ID); package TC_PGTEST is new DW1000.Generic_RW_Register_Driver (Register_Type => DW1000.Register_Types.TC_PGTEST_Type, Register_ID => TX_CAL_Reg_ID, Sub_Register => TC_PGTEST_Sub_Reg_ID); package FS_PLLCFG is new DW1000.Generic_RW_Register_Driver (Register_Type => DW1000.Register_Types.FS_PLLCFG_Type, Register_ID => FS_CTRL_Reg_ID, Sub_Register => FS_PLLCFG_Sub_Reg_ID); package FS_PLLTUNE is new DW1000.Generic_RW_Register_Driver (Register_Type => DW1000.Register_Types.FS_PLLTUNE_Type, Register_ID => FS_CTRL_Reg_ID, Sub_Register => FS_PLLTUNE_Sub_Reg_ID); package FS_XTALT is new DW1000.Generic_RW_Register_Driver (Register_Type => DW1000.Register_Types.FS_XTALT_Type, Register_ID => FS_CTRL_Reg_ID, Sub_Register => FS_XTALT_Sub_Reg_ID); package AON_WCFG is new DW1000.Generic_RW_Register_Driver (Register_Type => DW1000.Register_Types.AON_WCFG_Type, Register_ID => AON_Reg_ID, Sub_Register => AON_WCFG_Sub_Reg_ID); package AON_CTRL is new DW1000.Generic_RW_Register_Driver (Register_Type => DW1000.Register_Types.AON_CTRL_Type, Register_ID => AON_Reg_ID, Sub_Register => AON_CTRL_Sub_Reg_ID); package AON_RDAT is new DW1000.Generic_RW_Register_Driver (Register_Type => DW1000.Register_Types.AON_RDAT_Type, Register_ID => AON_Reg_ID, Sub_Register => AON_RDAT_Sub_Reg_ID); package AON_ADDR is new DW1000.Generic_RW_Register_Driver (Register_Type => DW1000.Register_Types.AON_ADDR_Type, Register_ID => AON_Reg_ID, Sub_Register => AON_ADDR_Sub_Reg_ID); package AON_CFG0 is new DW1000.Generic_RW_Register_Driver (Register_Type => DW1000.Register_Types.AON_CFG0_Type, Register_ID => AON_Reg_ID, Sub_Register => AON_CFG0_Sub_Reg_ID); package AON_CFG1 is new DW1000.Generic_RW_Register_Driver (Register_Type => DW1000.Register_Types.AON_CFG1_Type, Register_ID => AON_Reg_ID, Sub_Register => AON_CFG1_Sub_Reg_ID); package OTP_WDAT is new DW1000.Generic_RW_Register_Driver (Register_Type => DW1000.Register_Types.OTP_WDAT_Type, Register_ID => OTP_IF_Reg_ID, Sub_Register => OTP_WDAT_Sub_Reg_ID); package OTP_ADDR is new DW1000.Generic_RW_Register_Driver (Register_Type => DW1000.Register_Types.OTP_ADDR_Type, Register_ID => OTP_IF_Reg_ID, Sub_Register => OTP_ADDR_Sub_Reg_ID); package OTP_CTRL is new DW1000.Generic_RW_Register_Driver (Register_Type => DW1000.Register_Types.OTP_CTRL_Type, Register_ID => OTP_IF_Reg_ID, Sub_Register => OTP_CTRL_Sub_Reg_ID); package OTP_STAT is new DW1000.Generic_RW_Register_Driver (Register_Type => DW1000.Register_Types.OTP_STAT_Type, Register_ID => OTP_IF_Reg_ID, Sub_Register => OTP_STAT_Sub_Reg_ID); package OTP_RDAT is new DW1000.Generic_RO_Register_Driver (Register_Type => DW1000.Register_Types.OTP_RDAT_Type, Register_ID => OTP_IF_Reg_ID, Sub_Register => OTP_RDAT_Sub_Reg_ID); package OTP_SRDAT is new DW1000.Generic_RW_Register_Driver (Register_Type => DW1000.Register_Types.OTP_SRDAT_Type, Register_ID => OTP_IF_Reg_ID, Sub_Register => OTP_SRDAT_Sub_Reg_ID); package OTP_SF is new DW1000.Generic_RW_Register_Driver (Register_Type => DW1000.Register_Types.OTP_SF_Type, Register_ID => OTP_IF_Reg_ID, Sub_Register => OTP_SF_Sub_Reg_ID); package LDE_THRESH is new DW1000.Generic_RO_Register_Driver (Register_Type => DW1000.Register_Types.LDE_THRESH_Type, Register_ID => LDE_CTRL_Reg_ID, Sub_Register => LDE_THRESH_Sub_Reg_ID); package LDE_CFG1 is new DW1000.Generic_RW_Register_Driver (Register_Type => DW1000.Register_Types.LDE_CFG1_Type, Register_ID => LDE_CTRL_Reg_ID, Sub_Register => LDE_CFG1_Sub_Reg_ID); package LDE_PPINDX is new DW1000.Generic_RO_Register_Driver (Register_Type => DW1000.Register_Types.LDE_PPINDX_Type, Register_ID => LDE_CTRL_Reg_ID, Sub_Register => LDE_PPINDX_Sub_Reg_ID); package LDE_PPAMPL is new DW1000.Generic_RO_Register_Driver (Register_Type => DW1000.Register_Types.LDE_PPAMPL_Type, Register_ID => LDE_CTRL_Reg_ID, Sub_Register => LDE_PPAMPL_Sub_Reg_ID); package LDE_RXANTD is new DW1000.Generic_RW_Register_Driver (Register_Type => DW1000.Register_Types.LDE_RXANTD_Type, Register_ID => LDE_CTRL_Reg_ID, Sub_Register => LDE_RXANTD_Sub_Reg_ID); package LDE_CFG2 is new DW1000.Generic_RW_Register_Driver (Register_Type => DW1000.Register_Types.LDE_CFG2_Type, Register_ID => LDE_CTRL_Reg_ID, Sub_Register => LDE_CFG2_Sub_Reg_ID); package LDE_REPC is new DW1000.Generic_RW_Register_Driver (Register_Type => DW1000.Register_Types.LDE_REPC_Type, Register_ID => LDE_CTRL_Reg_ID, Sub_Register => LDE_REPC_Sub_Reg_ID); package EVC_CTRL is new DW1000.Generic_RW_Register_Driver (Register_Type => DW1000.Register_Types.EVC_CTRL_Type, Register_ID => DIG_DIAG_Reg_ID, Sub_Register => EVC_CTRL_Sub_Reg_ID); package EVC_PHE is new DW1000.Generic_RO_Register_Driver (Register_Type => DW1000.Register_Types.EVC_PHE_Type, Register_ID => DIG_DIAG_Reg_ID, Sub_Register => EVC_PHE_Sub_Reg_ID); package EVC_RSE is new DW1000.Generic_RO_Register_Driver (Register_Type => DW1000.Register_Types.EVC_RSE_Type, Register_ID => DIG_DIAG_Reg_ID, Sub_Register => EVC_RSE_Sub_Reg_ID); package EVC_FCG is new DW1000.Generic_RO_Register_Driver (Register_Type => DW1000.Register_Types.EVC_FCG_Type, Register_ID => DIG_DIAG_Reg_ID, Sub_Register => EVC_FCG_Sub_Reg_ID); package EVC_FCE is new DW1000.Generic_RO_Register_Driver (Register_Type => DW1000.Register_Types.EVC_FCE_Type, Register_ID => DIG_DIAG_Reg_ID, Sub_Register => EVC_FCE_Sub_Reg_ID); package EVC_FFR is new DW1000.Generic_RO_Register_Driver (Register_Type => DW1000.Register_Types.EVC_FFR_Type, Register_ID => DIG_DIAG_Reg_ID, Sub_Register => EVC_FFR_Sub_Reg_ID); package EVC_OVR is new DW1000.Generic_RO_Register_Driver (Register_Type => DW1000.Register_Types.EVC_OVR_Type, Register_ID => DIG_DIAG_Reg_ID, Sub_Register => EVC_OVR_Sub_Reg_ID); package EVC_STO is new DW1000.Generic_RO_Register_Driver (Register_Type => DW1000.Register_Types.EVC_STO_Type, Register_ID => DIG_DIAG_Reg_ID, Sub_Register => EVC_STO_Sub_Reg_ID); package EVC_PTO is new DW1000.Generic_RO_Register_Driver (Register_Type => DW1000.Register_Types.EVC_PTO_Type, Register_ID => DIG_DIAG_Reg_ID, Sub_Register => EVC_PTO_Sub_Reg_ID); package EVC_FWTO is new DW1000.Generic_RO_Register_Driver (Register_Type => DW1000.Register_Types.EVC_FWTO_Type, Register_ID => DIG_DIAG_Reg_ID, Sub_Register => EVC_FWTO_Sub_Reg_ID); package EVC_TXFS is new DW1000.Generic_RO_Register_Driver (Register_Type => DW1000.Register_Types.EVC_TXFS_Type, Register_ID => DIG_DIAG_Reg_ID, Sub_Register => EVC_TXFS_Sub_Reg_ID); package EVC_HPW is new DW1000.Generic_RO_Register_Driver (Register_Type => DW1000.Register_Types.EVC_HPW_Type, Register_ID => DIG_DIAG_Reg_ID, Sub_Register => EVC_HPW_Sub_Reg_ID); package EVC_TPW is new DW1000.Generic_RO_Register_Driver (Register_Type => DW1000.Register_Types.EVC_TPW_Type, Register_ID => DIG_DIAG_Reg_ID, Sub_Register => EVC_TPW_Sub_Reg_ID); package DIAG_TMC is new DW1000.Generic_RW_Register_Driver (Register_Type => DW1000.Register_Types.DIAG_TMC_Type, Register_ID => DIG_DIAG_Reg_ID, Sub_Register => DIAG_TMC_Sub_Reg_ID); package PMSC_CTRL0 is new DW1000.Generic_RW_Register_Driver (Register_Type => DW1000.Register_Types.PMSC_CTRL0_Type, Register_ID => PMSC_Reg_ID, Sub_Register => PMSC_CTRL0_Sub_Reg_ID); package PMSC_CTRL1 is new DW1000.Generic_RW_Register_Driver (Register_Type => DW1000.Register_Types.PMSC_CTRL1_Type, Register_ID => PMSC_Reg_ID, Sub_Register => PMSC_CTRL1_Sub_Reg_ID); package PMSC_SNOZT is new DW1000.Generic_RW_Register_Driver (Register_Type => DW1000.Register_Types.PMSC_SNOZT_Type, Register_ID => PMSC_Reg_ID, Sub_Register => PMSC_SNOZT_Sub_Reg_ID); package PMSC_TXFSEQ is new DW1000.Generic_RW_Register_Driver (Register_Type => DW1000.Register_Types.PMSC_TXFSEQ_Type, Register_ID => PMSC_Reg_ID, Sub_Register => PMSC_TXFSEQ_Sub_Reg_ID); package PMSC_LEDC is new DW1000.Generic_RW_Register_Driver (Register_Type => DW1000.Register_Types.PMSC_LEDC_Type, Register_ID => PMSC_Reg_ID, Sub_Register => PMSC_LEDC_Sub_Reg_ID); end DW1000.Registers;
AdaCore/libadalang
Ada
37
ads
with Lib; package Root is end Root;
btmalone/alog
Ada
909
ads
------------------------------------------------------------------------ -- -- Copyright (c) 2018, Brendan T Malone All Rights Reserved. -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- ------------------------------------------------------------------------ with AUnit.Test_Suites; package Alog_Suite is function Suite return AUnit.Test_Suites.Access_Test_Suite; end Alog_Suite;
reznikmm/matreshka
Ada
4,680
adb
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- Open Document Toolkit -- -- -- -- Runtime Library Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2014, Vadim Godunko <[email protected]> -- -- All rights reserved. -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions -- -- are met: -- -- -- -- * Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- -- -- * Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in the -- -- documentation and/or other materials provided with the distribution. -- -- -- -- * Neither the name of the Vadim Godunko, IE nor the names of its -- -- contributors may be used to endorse or promote products derived from -- -- this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -- -- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED -- -- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -- -- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -- -- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -- -- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -- -- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- -- ------------------------------------------------------------------------------ -- $Revision$ $Date$ ------------------------------------------------------------------------------ with Matreshka.DOM_Documents; with Matreshka.ODF_String_Constants; with ODF.DOM.Iterators; with ODF.DOM.Visitors; package body Matreshka.ODF_Style.Font_Pitch_Complex_Attributes is ------------ -- Create -- ------------ overriding function Create (Parameters : not null access Matreshka.DOM_Attributes.Attribute_L2_Parameters) return Style_Font_Pitch_Complex_Attribute_Node is begin return Self : Style_Font_Pitch_Complex_Attribute_Node do Matreshka.ODF_Style.Constructors.Initialize (Self'Unchecked_Access, Parameters.Document, Matreshka.ODF_String_Constants.Style_Prefix); end return; end Create; -------------------- -- Get_Local_Name -- -------------------- overriding function Get_Local_Name (Self : not null access constant Style_Font_Pitch_Complex_Attribute_Node) return League.Strings.Universal_String is pragma Unreferenced (Self); begin return Matreshka.ODF_String_Constants.Font_Pitch_Complex_Attribute; end Get_Local_Name; begin Matreshka.DOM_Documents.Register_Attribute (Matreshka.ODF_String_Constants.Style_URI, Matreshka.ODF_String_Constants.Font_Pitch_Complex_Attribute, Style_Font_Pitch_Complex_Attribute_Node'Tag); end Matreshka.ODF_Style.Font_Pitch_Complex_Attributes;
melwyncarlo/ProjectEuler
Ada
303
adb
with Ada.Text_IO; with Ada.Integer_Text_IO; -- Copyright 2021 Melwyn Francis Carlo procedure A00X is use Ada.Text_IO; use Ada.Integer_Text_IO; Str : constant String (1 .. 12) := "Hello World "; Num : constant Integer := 2021; begin Put (Str); Put (Num, Width => 0); end A00X;
vpodzime/ada-util
Ada
27,158
adb
----------------------------------------------------------------------- -- util-serialize-io-json -- JSON Serialization Driver -- Copyright (C) 2010, 2011, 2012, 2016, 2017 Stephane Carrez -- Written by Stephane Carrez ([email protected]) -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. ----------------------------------------------------------------------- with Interfaces; with Ada.Characters.Latin_1; with Ada.Characters.Wide_Wide_Latin_1; with Ada.IO_Exceptions; with Util.Strings; with Util.Streams; with Util.Streams.Buffered; with Util.Dates.ISO8601; with Util.Beans.Objects.Readers; package body Util.Serialize.IO.JSON is use Ada.Strings.Unbounded; -- ----------------------- -- Set the target output stream. -- ----------------------- procedure Initialize (Stream : in out Output_Stream; Output : in Util.Streams.Texts.Print_Stream_Access) is begin Stream.Stream := Output; end Initialize; -- ----------------------- -- Flush the buffer (if any) to the sink. -- ----------------------- overriding procedure Flush (Stream : in out Output_Stream) is begin Stream.Stream.Flush; end Flush; -- ----------------------- -- Close the sink. -- ----------------------- overriding procedure Close (Stream : in out Output_Stream) is begin Stream.Stream.Close; end Close; -- ----------------------- -- Write the buffer array to the output stream. -- ----------------------- overriding procedure Write (Stream : in out Output_Stream; Buffer : in Ada.Streams.Stream_Element_Array) is begin Stream.Stream.Write (Buffer); end Write; -- ----------------------- -- Write a raw character on the stream. -- ----------------------- procedure Write (Stream : in out Output_Stream; Char : in Character) is begin Stream.Stream.Write (Char); end Write; -- ----------------------- -- Write a wide character on the stream doing some conversion if necessary. -- The default implementation translates the wide character to a UTF-8 sequence. -- ----------------------- procedure Write_Wide (Stream : in out Output_Stream; Item : in Wide_Wide_Character) is begin Stream.Stream.Write_Wide (Item); end Write_Wide; -- ----------------------- -- Write a raw string on the stream. -- ----------------------- procedure Write (Stream : in out Output_Stream; Item : in String) is begin Stream.Stream.Write (Item); end Write; -- ----------------------- -- Start a JSON document. This operation writes the initial JSON marker ('{'). -- ----------------------- procedure Start_Document (Stream : in out Output_Stream) is begin Node_Info_Stack.Push (Stream.Stack); Stream.Write ('{'); end Start_Document; -- ----------------------- -- Finish a JSON document by writing the final JSON marker ('}'). -- ----------------------- procedure End_Document (Stream : in out Output_Stream) is begin Stream.Write ('}'); end End_Document; -- ----------------------- -- Write the string as a quoted JSON string -- ----------------------- procedure Write_String (Stream : in out Output_Stream; Value : in String) is begin Stream.Write ('"'); for I in Value'Range loop declare C : constant Character := Value (I); begin if C = '"' then Stream.Write ("\"""); elsif C = '\' then Stream.Write ("\\"); elsif Character'Pos (C) >= 16#20# then Stream.Write (C); else case C is when Ada.Characters.Latin_1.BS => Stream.Write ("\b"); when Ada.Characters.Latin_1.VT => Stream.Write ("\f"); when Ada.Characters.Latin_1.LF => Stream.Write ("\n"); when Ada.Characters.Latin_1.CR => Stream.Write ("\r"); when Ada.Characters.Latin_1.HT => Stream.Write ("\t"); when others => Util.Streams.Texts.TR.To_Hex (Stream.Stream.all, C); end case; end if; end; end loop; Stream.Write ('"'); end Write_String; -- ----------------------- -- Write the value as a JSON string. Special characters are escaped using the JSON -- escape rules. -- ----------------------- procedure Write_Wide_String (Stream : in out Output_Stream; Value : in Wide_Wide_String) is begin Stream.Write ('"'); for I in Value'Range loop declare C : constant Wide_Wide_Character := Value (I); begin if C = '"' then Stream.Write ("\"""); elsif C = '\' then Stream.Write ("\\"); elsif Wide_Wide_Character'Pos (C) >= 16#20# then Util.Streams.Texts.Write_Char (Stream.Stream.all, C); else case C is when Ada.Characters.Wide_Wide_Latin_1.BS => Stream.Write ("\b"); when Ada.Characters.Wide_Wide_Latin_1.VT => Stream.Write ("\f"); when Ada.Characters.Wide_Wide_Latin_1.LF => Stream.Write ("\n"); when Ada.Characters.Wide_Wide_Latin_1.CR => Stream.Write ("\r"); when Ada.Characters.Wide_Wide_Latin_1.HT => Stream.Write ("\t"); when others => Util.Streams.Texts.WTR.To_Hex (Stream.Stream.all, C); end case; end if; end; end loop; Stream.Write ('"'); end Write_Wide_String; procedure Write_Field_Name (Stream : in out Output_Stream; Name : in String) is Current : constant access Node_Info := Node_Info_Stack.Current (Stream.Stack); begin if Current /= null then if Current.Has_Fields then Stream.Write (','); else Current.Has_Fields := True; end if; end if; if Name'Length > 0 and then (Current = null or else not Current.Is_Array) then Stream.Write_String (Name); Stream.Write (':'); end if; end Write_Field_Name; -- ----------------------- -- Start writing an object identified by the given name -- ----------------------- procedure Start_Entity (Stream : in out Output_Stream; Name : in String) is Current : access Node_Info := Node_Info_Stack.Current (Stream.Stack); begin Stream.Write_Field_Name (Name); Node_Info_Stack.Push (Stream.Stack); Current := Node_Info_Stack.Current (Stream.Stack); Current.Has_Fields := False; Current.Is_Array := False; Stream.Write ('{'); end Start_Entity; -- ----------------------- -- Finish writing an object identified by the given name -- ----------------------- procedure End_Entity (Stream : in out Output_Stream; Name : in String) is pragma Unreferenced (Name); begin Node_Info_Stack.Pop (Stream.Stack); Stream.Write ('}'); end End_Entity; -- ----------------------- -- Write the attribute name/value pair. -- ----------------------- overriding procedure Write_Attribute (Stream : in out Output_Stream; Name : in String; Value : in String) is begin Stream.Write_Field_Name (Name); Stream.Write_String (Value); end Write_Attribute; overriding procedure Write_Wide_Attribute (Stream : in out Output_Stream; Name : in String; Value : in Wide_Wide_String) is begin Stream.Write_Field_Name (Name); Stream.Write_Wide_String (Value); end Write_Wide_Attribute; overriding procedure Write_Attribute (Stream : in out Output_Stream; Name : in String; Value : in Integer) is begin Stream.Write_Field_Name (Name); Stream.Write (Integer'Image (Value)); end Write_Attribute; overriding procedure Write_Attribute (Stream : in out Output_Stream; Name : in String; Value : in Boolean) is begin Stream.Write_Field_Name (Name); if Value then Stream.Write ("true"); else Stream.Write ("false"); end if; end Write_Attribute; -- ----------------------- -- Write an attribute member from the current object -- ----------------------- procedure Write_Attribute (Stream : in out Output_Stream; Name : in String; Value : in Util.Beans.Objects.Object) is use Util.Beans.Objects; begin Stream.Write_Field_Name (Name); case Util.Beans.Objects.Get_Type (Value) is when TYPE_NULL => Stream.Write ("null"); when TYPE_BOOLEAN => if Util.Beans.Objects.To_Boolean (Value) then Stream.Write ("true"); else Stream.Write ("false"); end if; when TYPE_INTEGER => Stream.Stream.Write (Util.Beans.Objects.To_Long_Long_Integer (Value)); when others => Stream.Write_String (Util.Beans.Objects.To_String (Value)); end case; end Write_Attribute; -- ----------------------- -- Write an object value as an entity -- ----------------------- procedure Write_Entity (Stream : in out Output_Stream; Name : in String; Value : in Util.Beans.Objects.Object) is begin Stream.Write_Attribute (Name, Value); end Write_Entity; -- ----------------------- -- Write a JSON name/value pair (see Write_Attribute). -- ----------------------- overriding procedure Write_Entity (Stream : in out Output_Stream; Name : in String; Value : in String) is begin Stream.Write_Attribute (Name, Value); end Write_Entity; overriding procedure Write_Wide_Entity (Stream : in out Output_Stream; Name : in String; Value : in Wide_Wide_String) is begin Stream.Write_Wide_Attribute (Name, Value); end Write_Wide_Entity; -- ----------------------- -- Write a JSON name/value pair (see Write_Attribute). -- ----------------------- overriding procedure Write_Entity (Stream : in out Output_Stream; Name : in String; Value : in Integer) is begin Stream.Write_Attribute (Name, Value); end Write_Entity; overriding procedure Write_Entity (Stream : in out Output_Stream; Name : in String; Value : in Ada.Calendar.Time) is begin Stream.Write_Entity (Name, Util.Dates.ISO8601.Image (Value, Util.Dates.ISO8601.SUBSECOND)); end Write_Entity; overriding procedure Write_Entity (Stream : in out Output_Stream; Name : in String; Value : in Boolean) is begin Stream.Write_Attribute (Name, Value); end Write_Entity; overriding procedure Write_Long_Entity (Stream : in out Output_Stream; Name : in String; Value : in Long_Long_Integer) is begin Stream.Write_Field_Name (Name); Stream.Write (Long_Long_Integer'Image (Value)); end Write_Long_Entity; overriding procedure Write_Enum_Entity (Stream : in out Output_Stream; Name : in String; Value : in String) is begin Stream.Write_Entity (Name, Value); end Write_Enum_Entity; -- ----------------------- -- Start an array that will contain the specified number of elements -- Example: "list": [ -- ----------------------- overriding procedure Start_Array (Stream : in out Output_Stream; Name : in String) is Current : access Node_Info := Node_Info_Stack.Current (Stream.Stack); begin if Current /= null then if Current.Has_Fields then Stream.Write (','); else Current.Has_Fields := True; end if; end if; Node_Info_Stack.Push (Stream.Stack); Current := Node_Info_Stack.Current (Stream.Stack); Current.Has_Fields := False; Current.Is_Array := True; Stream.Write_String (Name); Stream.Write (':'); Stream.Write ('['); end Start_Array; -- ----------------------- -- Finishes an array -- ----------------------- overriding procedure End_Array (Stream : in out Output_Stream; Name : in String) is pragma Unreferenced (Name); begin Node_Info_Stack.Pop (Stream.Stack); Stream.Write (']'); end End_Array; -- ----------------------- -- Get the current location (file and line) to report an error message. -- ----------------------- function Get_Location (Handler : in Parser) return String is begin return Util.Strings.Image (Handler.Line_Number); end Get_Location; procedure Parse (Handler : in out Parser; Stream : in out Util.Streams.Buffered.Buffered_Stream'Class; Sink : in out Reader'Class) is -- Put back a token in the buffer. procedure Put_Back (P : in out Parser'Class; Token : in Token_Type); -- Parse the expression buffer to find the next token. procedure Peek (P : in out Parser'Class; Token : out Token_Type); function Hexdigit (C : in Character) return Interfaces.Unsigned_32; -- Parse a list of members -- members ::= pair | pair ',' members -- pair ::= string ':' value -- value ::= string | number | object | array | true | false | null procedure Parse_Pairs (P : in out Parser'Class); -- Parse a value -- value ::= string | number | object | array | true | false | null procedure Parse_Value (P : in out Parser'Class; Name : in String); -- ------------------------------ -- Parse a list of members -- members ::= pair | pair ',' members -- pair ::= string ':' value -- value ::= string | number | object | array | true | false | null -- ------------------------------ procedure Parse_Pairs (P : in out Parser'Class) is Current_Name : Unbounded_String; Token : Token_Type; begin loop Peek (P, Token); if Token /= T_STRING then Put_Back (P, Token); return; end if; Current_Name := P.Token; Peek (P, Token); if Token /= T_COLON then P.Error ("Missing ':'"); end if; Parse_Value (P, To_String (Current_Name)); Peek (P, Token); if Token /= T_COMMA then Put_Back (P, Token); return; end if; end loop; end Parse_Pairs; function Hexdigit (C : in Character) return Interfaces.Unsigned_32 is use type Interfaces.Unsigned_32; begin if C >= '0' and C <= '9' then return Character'Pos (C) - Character'Pos ('0'); elsif C >= 'a' and C <= 'f' then return Character'Pos (C) - Character'Pos ('a') + 10; elsif C >= 'A' and C <= 'F' then return Character'Pos (C) - Character'Pos ('A') + 10; else raise Constraint_Error with "Invalid hexdigit: " & C; end if; end Hexdigit; -- ------------------------------ -- Parse a value -- value ::= string | number | object | array | true | false | null -- ------------------------------ procedure Parse_Value (P : in out Parser'Class; Name : in String) is Token : Token_Type; Index : Natural; begin Peek (P, Token); case Token is when T_LEFT_BRACE => Sink.Start_Object (Name, P); Parse_Pairs (P); Peek (P, Token); if Token /= T_RIGHT_BRACE then P.Error ("Missing '}'"); end if; Sink.Finish_Object (Name, P); -- when T_LEFT_BRACKET => Sink.Start_Array (Name, P); Peek (P, Token); Index := 0; if Token /= T_RIGHT_BRACKET then Put_Back (P, Token); loop Parse_Value (P, Util.Strings.Image (Index)); Peek (P, Token); exit when Token = T_RIGHT_BRACKET; if Token /= T_COMMA then P.Error ("Missing ']'"); exit when Token = T_EOF; end if; Index := Index + 1; end loop; end if; Sink.Finish_Array (Name, Index, P); when T_NULL => Sink.Set_Member (Name, Util.Beans.Objects.Null_Object, P); when T_NUMBER => Sink.Set_Member (Name, Util.Beans.Objects.To_Object (P.Token), P); when T_STRING => Sink.Set_Member (Name, Util.Beans.Objects.To_Object (P.Token), P); when T_TRUE => Sink.Set_Member (Name, Util.Beans.Objects.To_Object (True), P); when T_FALSE => Sink.Set_Member (Name, Util.Beans.Objects.To_Object (False), P); when T_EOF => P.Error ("End of stream reached"); return; when others => P.Error ("Invalid token"); end case; end Parse_Value; -- ------------------------------ -- Put back a token in the buffer. -- ------------------------------ procedure Put_Back (P : in out Parser'Class; Token : in Token_Type) is begin P.Pending_Token := Token; end Put_Back; -- ------------------------------ -- Parse the expression buffer to find the next token. -- ------------------------------ procedure Peek (P : in out Parser'Class; Token : out Token_Type) is use Ada.Characters; C, C1 : Character; begin -- If a token was put back, return it. if P.Pending_Token /= T_EOF then Token := P.Pending_Token; P.Pending_Token := T_EOF; return; end if; if P.Has_Pending_Char then C := P.Pending_Char; else -- Skip white spaces loop Stream.Read (Char => C); if C = Ada.Characters.Latin_1.LF then P.Line_Number := P.Line_Number + 1; else exit when C /= ' ' and C /= Ada.Characters.Latin_1.CR and C /= Ada.Characters.Latin_1.HT; end if; end loop; end if; P.Has_Pending_Char := False; -- See what we have and continue parsing. case C is -- Literal string using double quotes -- Collect up to the end of the string and put -- the result in the parser token result. when '"' => Delete (P.Token, 1, Length (P.Token)); loop Stream.Read (Char => C1); if C1 = '\' then Stream.Read (Char => C1); case C1 is when '"' | '\' | '/' => null; when 'b' => C1 := Ada.Characters.Latin_1.BS; when 'f' => C1 := Ada.Characters.Latin_1.VT; when 'n' => C1 := Ada.Characters.Latin_1.LF; when 'r' => C1 := Ada.Characters.Latin_1.CR; when 't' => C1 := Ada.Characters.Latin_1.HT; when 'u' => declare use Interfaces; C2, C3, C4 : Character; Val : Interfaces.Unsigned_32; begin Stream.Read (Char => C1); Stream.Read (Char => C2); Stream.Read (Char => C3); Stream.Read (Char => C4); Val := Interfaces.Shift_Left (Hexdigit (C1), 12); Val := Val + Interfaces.Shift_Left (Hexdigit (C2), 8); Val := Val + Interfaces.Shift_Left (Hexdigit (C3), 4); Val := Val + Hexdigit (C4); -- Encode the value as an UTF-8 string. if Val >= 16#1000# then Append (P.Token, Character'Val (16#E0# or Shift_Right (Val, 12))); Val := Val and 16#0fff#; Append (P.Token, Character'Val (16#80# or Shift_Right (Val, 6))); Val := Val and 16#03f#; C1 := Character'Val (16#80# or Val); elsif Val >= 16#80# then Append (P.Token, Character'Val (16#C0# or Shift_Right (Val, 6))); Val := Val and 16#03f#; C1 := Character'Val (16#80# or Val); else C1 := Character'Val (Val); end if; end; when others => P.Error ("Invalid character '" & C1 & "' in \x sequence"); end case; elsif C1 = C then Token := T_STRING; return; end if; Append (P.Token, C1); end loop; -- Number when '-' | '0' .. '9' => Delete (P.Token, 1, Length (P.Token)); Append (P.Token, C); loop Stream.Read (Char => C); exit when C not in '0' .. '9'; Append (P.Token, C); end loop; if C = '.' then Append (P.Token, C); loop Stream.Read (Char => C); exit when C not in '0' .. '9'; Append (P.Token, C); end loop; end if; if C = 'e' or C = 'E' then Append (P.Token, C); Stream.Read (Char => C); if C = '+' or C = '-' then Append (P.Token, C); Stream.Read (Char => C); end if; loop Stream.Read (Char => C); exit when C not in '0' .. '9'; Append (P.Token, C); end loop; end if; if not (C in ' ' | Latin_1.HT | Latin_1.LF | Latin_1.CR) then P.Has_Pending_Char := True; P.Pending_Char := C; end if; Token := T_NUMBER; return; -- Parse a name composed of letters or digits. when 'a' .. 'z' | 'A' .. 'Z' => Delete (P.Token, 1, Length (P.Token)); Append (P.Token, C); loop Stream.Read (Char => C); exit when not (C in 'a' .. 'z' or C in 'A' .. 'Z' or C in '0' .. '9' or C = '_'); Append (P.Token, C); end loop; -- Putback the last character unless we can ignore it. if not (C in ' ' | Latin_1.HT | Latin_1.LF | Latin_1.CR) then P.Has_Pending_Char := True; P.Pending_Char := C; end if; -- and empty eq false ge gt le lt ne not null true case Element (P.Token, 1) is when 'n' | 'N' => if P.Token = "null" then Token := T_NULL; return; end if; when 'f' | 'F' => if P.Token = "false" then Token := T_FALSE; return; end if; when 't' | 'T' => if P.Token = "true" then Token := T_TRUE; return; end if; when others => null; end case; Token := T_UNKNOWN; return; when '{' => Token := T_LEFT_BRACE; return; when '}' => Token := T_RIGHT_BRACE; return; when '[' => Token := T_LEFT_BRACKET; return; when ']' => Token := T_RIGHT_BRACKET; return; when ':' => Token := T_COLON; return; when ',' => Token := T_COMMA; return; when others => Token := T_UNKNOWN; return; end case; exception when Ada.IO_Exceptions.Data_Error => Token := T_EOF; return; end Peek; begin Parse_Value (Handler, ""); end Parse; -- Read a JSON file and return an object. function Read (Path : in String) return Util.Beans.Objects.Object is P : Parser; R : Util.Beans.Objects.Readers.Reader; begin P.Parse (Path, R); return R.Get_Root; end Read; end Util.Serialize.IO.JSON;
hergin/ada2fuml
Ada
198
ads
package SomeClass is type SomeClass1 is record someAttribute : Integer := 1; end record; type SomeClass2 is record someAttribute2 : SomeClass1; end record; end SomeClass;
reznikmm/jwt
Ada
2,153
adb
-- Copyright (c) 2020 Maxim Reznik <[email protected]> -- -- SPDX-License-Identifier: MIT -- License-Filename: LICENSE ------------------------------------------------------------- with Ada.Streams; with League.Strings; with League.Base_Codecs; with JWS; procedure HS_256_Test is function "+" (Item : Wide_Wide_String) return League.Strings.Universal_String renames League.Strings.To_Universal_String; -- This data is from rfc7515 example. Header_Encoded : constant Wide_Wide_String := "eyJ0eXAiOiJKV1QiLA0KICJhbGciOiJIUzI1NiJ9"; Payload_Encoded : constant Wide_Wide_String := "eyJpc3MiOiJqb2UiLA0KICJleHAiOjEzMDA4MTkzODAsDQogImh0dHA6Ly9leGFt" & "cGxlLmNvbS9pc19yb290Ijp0cnVlfQ"; Signature_Encoded : constant Wide_Wide_String := "dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk"; Secret_Encoded : constant Wide_Wide_String := "AyM1SysPpbyDfgZld3umj1qzKObwVMkoqQ+EstJQLr/T+" & "1qS0gZH75aKtMN3Yj0iPS4hcgUuTwjAzZr1Z9CAow=="; Token : constant Wide_Wide_String := Header_Encoded & "." & Payload_Encoded & "." & Signature_Encoded; Secret : constant Ada.Streams.Stream_Element_Array := League.Base_Codecs.From_Base_64 (+Secret_Encoded).To_Stream_Element_Array; Backward_Token : constant Wide_Wide_String := "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9" & "." & Payload_Encoded & "." & "SfgggA-oZk7ztlq1i8Uz5VhmPmustakoDa9wAf8uHyQ"; Signature : JWS.JSON_Web_Signature; Ok : Boolean; Backward : JWS.JSON_Web_Signature; Result : League.Strings.Universal_String; begin Signature.Validate_Compact_Serialization (Value => +Token, Secret => Secret, Valid => Ok); pragma Assert (Ok, "Validation failed"); Backward.Create (Header => Signature.Header, Payload => Signature.Payload, Secret => Secret); -- Backward token differs from the original, because Header has more -- compact representation then original. Result := Backward.Compact_Serialization; pragma Assert (Result.To_Wide_Wide_String = Backward_Token, "Invalid Compact_Serialization"); end HS_256_Test;
reznikmm/matreshka
Ada
5,196
ads
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- Ada Modeling Framework -- -- -- -- Runtime Library Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2011-2012, Vadim Godunko <[email protected]> -- -- All rights reserved. -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions -- -- are met: -- -- -- -- * Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- -- -- * Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in the -- -- documentation and/or other materials provided with the distribution. -- -- -- -- * Neither the name of the Vadim Godunko, IE nor the names of its -- -- contributors may be used to endorse or promote products derived from -- -- this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -- -- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED -- -- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -- -- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -- -- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -- -- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -- -- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- -- ------------------------------------------------------------------------------ -- $Revision$ $Date$ ------------------------------------------------------------------------------ -- This file is generated, don't edit it. ------------------------------------------------------------------------------ with AMF.Generic_Collections; package AMF.UML.Deployed_Artifacts.Collections is pragma Preelaborate; package UML_Deployed_Artifact_Collections is new AMF.Generic_Collections (UML_Deployed_Artifact, UML_Deployed_Artifact_Access); type Set_Of_UML_Deployed_Artifact is new UML_Deployed_Artifact_Collections.Set with null record; Empty_Set_Of_UML_Deployed_Artifact : constant Set_Of_UML_Deployed_Artifact; type Ordered_Set_Of_UML_Deployed_Artifact is new UML_Deployed_Artifact_Collections.Ordered_Set with null record; Empty_Ordered_Set_Of_UML_Deployed_Artifact : constant Ordered_Set_Of_UML_Deployed_Artifact; type Bag_Of_UML_Deployed_Artifact is new UML_Deployed_Artifact_Collections.Bag with null record; Empty_Bag_Of_UML_Deployed_Artifact : constant Bag_Of_UML_Deployed_Artifact; type Sequence_Of_UML_Deployed_Artifact is new UML_Deployed_Artifact_Collections.Sequence with null record; Empty_Sequence_Of_UML_Deployed_Artifact : constant Sequence_Of_UML_Deployed_Artifact; private Empty_Set_Of_UML_Deployed_Artifact : constant Set_Of_UML_Deployed_Artifact := (UML_Deployed_Artifact_Collections.Set with null record); Empty_Ordered_Set_Of_UML_Deployed_Artifact : constant Ordered_Set_Of_UML_Deployed_Artifact := (UML_Deployed_Artifact_Collections.Ordered_Set with null record); Empty_Bag_Of_UML_Deployed_Artifact : constant Bag_Of_UML_Deployed_Artifact := (UML_Deployed_Artifact_Collections.Bag with null record); Empty_Sequence_Of_UML_Deployed_Artifact : constant Sequence_Of_UML_Deployed_Artifact := (UML_Deployed_Artifact_Collections.Sequence with null record); end AMF.UML.Deployed_Artifacts.Collections;
onox/orka
Ada
2,479
adb
-- SPDX-License-Identifier: Apache-2.0 -- -- Copyright (c) 2016 onox <[email protected]> -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. with GL.Types; with Orka.Contexts.AWT; with Orka.Rendering.Buffers; with Orka.Rendering.Drawing; with Orka.Rendering.Framebuffers; with Orka.Rendering.Programs.Modules; with Orka.Resources.Locations.Directories; with Orka.Windows; with AWT; procedure Orka_3_Module_Array is Context : constant Orka.Contexts.Context'Class := Orka.Contexts.AWT.Create_Context (Version => (4, 2), Flags => (Debug => True, others => False)); Window : constant Orka.Windows.Window'Class := Orka.Contexts.AWT.Create_Window (Context, Width => 500, Height => 500, Resizable => False); use Orka.Rendering.Buffers; use Orka.Rendering.Framebuffers; use Orka.Rendering.Programs; use Orka.Resources; Location_Shaders : constant Locations.Location_Ptr := Locations.Directories.Create_Location ("data/shaders"); Program_1 : Program := Create_Program (Modules.Module_Array'( Modules.Create_Module (Location_Shaders, FS => "test-3-module-1.frag"), Modules.Create_Module (Location_Shaders, VS => "test-3-module-2.vert", FS => "test-3-module-2.frag") )); FB_D : Framebuffer := Create_Default_Framebuffer (500, 500); use type Orka.Float_32; Vertices : constant Orka.Float_32_Array := (-0.5, -0.5, 0.5, -0.5, 0.0, 0.5); -- Upload Vertices data to VBO Buffer_1 : constant Buffer := Create_Buffer ((others => False), Vertices); begin FB_D.Set_Default_Values ((Color => (0.0, 0.0, 0.0, 1.0), others => <>)); Program_1.Use_Program; Buffer_1.Bind (Shader_Storage, 0); while not Window.Should_Close loop AWT.Process_Events (0.001); FB_D.Clear ((Color => True, others => False)); Orka.Rendering.Drawing.Draw (GL.Types.Triangles, 0, 3); Window.Swap_Buffers; end loop; end Orka_3_Module_Array;
MinimSecure/unum-sdk
Ada
786
adb
-- Copyright 2011-2019 Free Software Foundation, Inc. -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 3 of the License, or -- (at your option) any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program. If not, see <http://www.gnu.org/licenses/>. with Pck; use Pck; procedure Foo is begin Hello; There; end Foo;
stcarrez/ada-util
Ada
27,806
adb
----------------------------------------------------------------------- -- util-tests - Helper for writing unit tests -- Copyright (C) 2009, 2010, 2011, 2012, 2013, 2017, 2019, 2021, 2022, 2023 Stephane Carrez -- Written by Stephane Carrez ([email protected]) -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. ----------------------------------------------------------------------- with GNAT.Command_Line; with GNAT.Regpat; with GNAT.Traceback.Symbolic; with Ada.Command_Line; with Ada.Directories; with Ada.IO_Exceptions; with Ada.Text_IO; with Ada.Calendar.Formatting; with Ada.Exceptions; with Ada.Containers; with Util.Strings; with Util.Measures; with Util.Files; with Util.Log.Loggers; with Util.Processes; with Util.Streams.Buffered; with Util.Streams.Pipes; package body Util.Tests is Test_Properties : Util.Properties.Manager; Log : constant Util.Log.Loggers.Logger := Util.Log.Loggers.Create ("Util.Tests"); -- When a test uses external test files to match a result against a well -- defined content, it can be difficult to maintain those external files. -- The <b>Assert_Equal_Files</b> can automatically maintain the reference -- file by updating it with the lastest test result. -- -- Of course, using this mode means the test does not validate anything. Update_Test_Files : Boolean := False; -- The default timeout for a test case execution. Default_Timeout : Duration := 60.0; -- A prefix that is added to the test class names. Adding a prefix is useful when -- the same testsuite is executed several times with different configurations. It allows -- to track and identify the tests in different environments and have a global view -- in Jenkins. See option '-p prefix'. Harness_Prefix : Unbounded_String; -- Verbose flag activated by the '-v' option. Verbose_Flag : Boolean := False; -- When not empty, defines the name of the test that is enabled. Other tests are disabled. -- This is initialized by the -r test option. Enabled_Test : Unbounded_String; -- ------------------------------ -- Execute the command and get the output in a string. -- ------------------------------ procedure Execute (T : in out Test; Command : in String; Input : in String; Output : in String; Result : out Ada.Strings.Unbounded.Unbounded_String; Working_Directory : in String; Status : in Natural := 0; Source : String := GNAT.Source_Info.File; Line : Natural := GNAT.Source_Info.Line) is P : aliased Util.Streams.Pipes.Pipe_Stream; Buffer : Util.Streams.Buffered.Input_Buffer_Stream; begin if Input'Length > 0 then Log.Info ("Execute: {0} < {1}", Command, Input); elsif Output'Length > 0 then Log.Info ("Execute: {0} > {1}", Command, Output); else Log.Info ("Execute: {0}", Command); end if; P.Set_Input_Stream (Input); P.Set_Output_Stream (Output); if Working_Directory'Length > 0 then P.Set_Working_Directory (Working_Directory); end if; P.Open (Command, Util.Processes.READ_ALL); -- Write on the process input stream. Result := Ada.Strings.Unbounded.Null_Unbounded_String; Buffer.Initialize (P'Unchecked_Access, 8192); Buffer.Read (Result); P.Close; Ada.Text_IO.Put_Line (Ada.Strings.Unbounded.To_String (Result)); Log.Info ("Command result: {0}", Result); Util.Tests.Assert_Equals (T, Status, P.Get_Exit_Status, "Command '" & Command & "' failed", Source, Line); end Execute; procedure Execute (T : in out Test; Command : in String; Input : in String; Output : in String; Result : out Ada.Strings.Unbounded.Unbounded_String; Status : in Natural := 0; Source : String := GNAT.Source_Info.File; Line : Natural := GNAT.Source_Info.Line) is begin T.Execute (Command, Input, Output, Result, "", Status, Source, Line); end Execute; procedure Execute (T : in out Test; Command : in String; Result : out Ada.Strings.Unbounded.Unbounded_String; Status : in Natural := 0; Source : String := GNAT.Source_Info.File; Line : Natural := GNAT.Source_Info.Line) is begin T.Execute (Command, "", "", Result, "", Status, Source, Line); end Execute; procedure Execute (T : in out Test; Command : in String; Expect : in String; Status : in Natural := 0; Source : String := GNAT.Source_Info.File; Line : Natural := GNAT.Source_Info.Line) is Path : constant String := Util.Tests.Get_Path ("regtests/expect/" & Expect); Output : constant String := Util.Tests.Get_Test_Path (Expect); Result : Ada.Strings.Unbounded.Unbounded_String; begin T.Execute (Command, "", Output, Result, "", Status, Source, Line); Util.Tests.Assert_Equal_Files (T, Path, Output, "Command '" & Command & "' invalid output", Source, Line); end Execute; -- ------------------------------ -- Get a path to access a test file. -- ------------------------------ function Get_Path (File : String) return String is Dir : constant String := Get_Parameter ("test.dir", "."); begin return Dir & "/" & File; end Get_Path; -- ------------------------------ -- Get a path to create a test file. -- ------------------------------ function Get_Test_Path (File : String) return String is Dir : constant String := Get_Parameter ("test.result.dir", "regtests/results"); begin return Dir & "/" & File; end Get_Test_Path; -- ------------------------------ -- Get the timeout for the test execution. -- ------------------------------ function Get_Test_Timeout (Name : in String) return Duration is Prop_Name : constant String := "test.timeout." & Name; Value : constant String := Test_Properties.Get (Prop_Name, Duration'Image (Default_Timeout)); begin return Duration'Value (Value); exception when Constraint_Error => return Default_Timeout; end Get_Test_Timeout; -- ------------------------------ -- Get the testsuite harness prefix. This prefix is added to the test class name. -- By default it is empty. It is allows to execute the test harness on different -- environment (ex: MySQL or SQLlite) and be able to merge and collect the two result -- sets together. -- ------------------------------ function Get_Harness_Prefix return String is begin return To_String (Harness_Prefix); end Get_Harness_Prefix; -- ------------------------------ -- Get a test configuration parameter. -- ------------------------------ function Get_Parameter (Name : String; Default : String := "") return String is begin return Test_Properties.Get (Name, Default); end Get_Parameter; -- ------------------------------ -- Get the test configuration properties. -- ------------------------------ function Get_Properties return Util.Properties.Manager is begin return Test_Properties; end Get_Properties; -- ------------------------------ -- Get a new unique string -- ------------------------------ function Get_Uuid return String is Time : constant Ada.Calendar.Time := Ada.Calendar.Clock; Year : Ada.Calendar.Year_Number; Month : Ada.Calendar.Month_Number; Day : Ada.Calendar.Day_Number; T : Ada.Calendar.Day_Duration; V : Long_Long_Integer; begin Ada.Calendar.Split (Date => Time, Year => Year, Month => Month, Day => Day, Seconds => T); V := (Long_Long_Integer (Year) * 365 * 24 * 3600 * 1000) + (Long_Long_Integer (Month) * 31 * 24 * 3600 * 1000) + (Long_Long_Integer (Day) * 24 * 3600 * 1000) + (Long_Long_Integer (T * 1000)); return "U" & Util.Strings.Image (V); end Get_Uuid; -- ------------------------------ -- Get the verbose flag that can be activated with the <tt>-v</tt> option. -- ------------------------------ function Verbose return Boolean is begin return Verbose_Flag; end Verbose; -- ------------------------------ -- Returns True if the test with the given name is enabled. -- By default all the tests are enabled. When the -r test option is passed -- all the tests are disabled except the test specified by the -r option. -- ------------------------------ function Is_Test_Enabled (Name : in String) return Boolean is begin return Length (Enabled_Test) = 0 or else Enabled_Test = Name; end Is_Test_Enabled; -- ------------------------------ -- Check that the value matches what we expect. -- ------------------------------ procedure Assert_Equals (T : in Test'Class; Expect, Value : in Ada.Calendar.Time; Message : in String := "Test failed"; Source : String := GNAT.Source_Info.File; Line : Natural := GNAT.Source_Info.Line) is use Ada.Calendar.Formatting; use Ada.Calendar; begin T.Assert (Condition => Image (Expect) = Image (Value), Message => Message & ": expecting '" & Image (Expect) & "'" & " value was '" & Image (Value) & "'", Source => Source, Line => Line); end Assert_Equals; -- ------------------------------ -- Check that the value matches what we expect. -- ------------------------------ procedure Assert_Equals (T : in Test'Class; Expect, Value : in String; Message : in String := "Test failed"; Source : String := GNAT.Source_Info.File; Line : Natural := GNAT.Source_Info.Line) is begin T.Assert (Condition => Expect = Value, Message => Message & ": expecting '" & Expect & "'" & " value was '" & Value & "'", Source => Source, Line => Line); end Assert_Equals; -- ------------------------------ -- Check that the value matches what we expect. -- ------------------------------ procedure Assert_Equals (T : in Test'Class; Expect : in String; Value : in Unbounded_String; Message : in String := "Test failed"; Source : String := GNAT.Source_Info.File; Line : Natural := GNAT.Source_Info.Line) is begin Assert_Equals (T => T, Expect => Expect, Value => To_String (Value), Message => Message, Source => Source, Line => Line); end Assert_Equals; -- ------------------------------ -- Check that the value matches the regular expression -- ------------------------------ procedure Assert_Matches (T : in Test'Class; Pattern : in String; Value : in Unbounded_String; Message : in String := "Test failed"; Source : String := GNAT.Source_Info.File; Line : Natural := GNAT.Source_Info.Line) is begin Assert_Matches (T => T, Pattern => Pattern, Value => To_String (Value), Message => Message, Source => Source, Line => Line); end Assert_Matches; -- ------------------------------ -- Check that the value matches the regular expression -- ------------------------------ procedure Assert_Matches (T : in Test'Class; Pattern : in String; Value : in String; Message : in String := "Test failed"; Source : String := GNAT.Source_Info.File; Line : Natural := GNAT.Source_Info.Line) is use GNAT.Regpat; Regexp : constant Pattern_Matcher := Compile (Expression => Pattern, Flags => Multiple_Lines); begin T.Assert (Condition => Match (Regexp, Value), Message => Message & ". Value '" & Value & "': Does not Match '" & Pattern & "'", Source => Source, Line => Line); end Assert_Matches; -- ------------------------------ -- Check that the file exists. -- ------------------------------ procedure Assert_Exists (T : in Test'Class; File : in String; Message : in String := "Test failed"; Source : String := GNAT.Source_Info.File; Line : Natural := GNAT.Source_Info.Line) is begin T.Assert (Condition => Ada.Directories.Exists (File), Message => Message & ": file '" & File & "' does not exist", Source => Source, Line => Line); end Assert_Exists; -- ------------------------------ -- Check that two files are equal. This is intended to be used by -- tests that create files that are then checked against patterns. -- ------------------------------ procedure Assert_Equal_Files (T : in Test_Case'Class; Expect : in String; Test : in String; Message : in String := "Test failed"; Source : String := GNAT.Source_Info.File; Line : Natural := GNAT.Source_Info.Line) is use Util.Files; use type Ada.Containers.Count_Type; use type Util.Strings.Vectors.Vector; Expect_File : Util.Strings.Vectors.Vector; Test_File : Util.Strings.Vectors.Vector; Same : Boolean; begin begin if not Ada.Directories.Exists (Expect) then T.Assert (Condition => False, Message => "Expect file '" & Expect & "' does not exist", Source => Source, Line => Line); end if; Read_File (Path => Expect, Into => Expect_File); Read_File (Path => Test, Into => Test_File); exception when others => if Update_Test_Files then Ada.Directories.Copy_File (Source_Name => Test, Target_Name => Expect); else raise; end if; end; if Expect_File.Length /= Test_File.Length then if Update_Test_Files then Ada.Directories.Copy_File (Source_Name => Test, Target_Name => Expect); end if; -- Check file sizes Assert_Equals (T => T, Expect => Natural (Expect_File.Length), Value => Natural (Test_File.Length), Message => Message & ": Invalid number of lines", Source => Source, Line => Line); end if; Same := Expect_File = Test_File; if Same then return; end if; if Update_Test_Files then Ada.Directories.Copy_File (Source_Name => Test, Target_Name => Expect); end if; T.Assert (Condition => False, Message => Message & ": Content is different on some lines", Source => Source, Line => Line); end Assert_Equal_Files; -- ------------------------------ -- Check that two files are equal. This is intended to be used by -- tests that create files that are then checked against patterns. -- ------------------------------ procedure Assert_Equal_Files (T : in Test'Class; Expect : in String; Test : in String; Message : in String := "Test failed"; Source : String := GNAT.Source_Info.File; Line : Natural := GNAT.Source_Info.Line) is use Util.Files; use type Ada.Containers.Count_Type; use type Util.Strings.Vectors.Vector; Expect_File : Util.Strings.Vectors.Vector; Test_File : Util.Strings.Vectors.Vector; Same : Boolean; begin begin if not Ada.Directories.Exists (Expect) then T.Assert (Condition => False, Message => "Expect file '" & Expect & "' does not exist", Source => Source, Line => Line); end if; Read_File (Path => Expect, Into => Expect_File); Read_File (Path => Test, Into => Test_File); exception when others => if Update_Test_Files then Ada.Directories.Copy_File (Source_Name => Test, Target_Name => Expect); else raise; end if; end; if Expect_File.Length /= Test_File.Length then if Update_Test_Files then Ada.Directories.Copy_File (Source_Name => Test, Target_Name => Expect); end if; -- Check file sizes Assert_Equals (T => T, Expect => Natural (Expect_File.Length), Value => Natural (Test_File.Length), Message => Message & ": Invalid number of lines", Source => Source, Line => Line); end if; Same := Expect_File = Test_File; if Same then return; end if; if Update_Test_Files then Ada.Directories.Copy_File (Source_Name => Test, Target_Name => Expect); end if; Fail (T => T, Message => Message & ": Content is different on some lines", Source => Source, Line => Line); end Assert_Equal_Files; -- ------------------------------ -- Report a test failed. -- ------------------------------ procedure Fail (T : in Test'Class; Message : in String := "Test failed"; Source : in String := GNAT.Source_Info.File; Line : in Natural := GNAT.Source_Info.Line) is begin T.Assert (False, Message, Source, Line); end Fail; procedure Assert_Equal_Vectors (T : in Test'Class; Expect : in Util.Strings.Vectors.Vector; List : in Util.Strings.Vectors.Vector; Message : in String := "Test failed"; Source : String := GNAT.Source_Info.File; Line : Natural := GNAT.Source_Info.Line) is begin Assert_Equals (T => T, Expect => Natural (Expect.Length), Value => Natural (List.Length), Message => "Invalid length:" & Message, Source => Source, Line => Line); for I in 1 .. Natural (Expect.Length) loop Assert_Equals (T => T, Expect => Expect.Element (I), Value => List.Element (I), Message => "Bad value" & I'Image & ":" & Message, Source => Source, Line => Line); end loop; end Assert_Equal_Vectors; -- ------------------------------ -- Default initialization procedure. -- ------------------------------ procedure Initialize_Test (Props : in Util.Properties.Manager) is begin null; end Initialize_Test; -- ------------------------------ -- The main testsuite program. This launches the tests, collects the -- results, create performance logs and set the program exit status -- according to the testsuite execution status. -- -- The <b>Initialize</b> procedure is called before launching the unit tests. It is intended -- to configure the tests according to some external environment (paths, database access). -- -- The <b>Finish</b> procedure is called after the test suite has executed. -- ------------------------------ procedure Harness (Name : in String) is use GNAT.Command_Line; use Ada.Text_IO; use type Util.XUnit.Status; procedure Help; procedure Help is begin Put_Line ("Test harness: " & Name); Put ("Usage: harness [-l label] [-xml result.xml] [-t timeout] [-p prefix] [-v]" & "[-config file.properties] [-d dir] [-r testname]"); Put_Line ("[-update]"); Put_Line ("-l label Print the label in the test summary result"); Put_Line ("-xml file Produce an XML test report"); Put_Line ("-config file Specify a test configuration file"); Put_Line ("-d dir Change the current directory to <dir>"); Put_Line ("-t timeout Test execution timeout in seconds"); Put_Line ("-v Activate the verbose test flag"); Put_Line ("-p prefix Add the prefix to the test class names"); Put_Line ("-r testname Run only the tests for the given testsuite name"); Put_Line ("-update Update the test reference files if a file"); Put_Line (" is missing or the test generates another output"); Put_Line (" (See Assert_Equals_File)"); Ada.Command_Line.Set_Exit_Status (2); end Help; Perf : aliased Util.Measures.Measure_Set; Result : Util.XUnit.Status; XML : Boolean := False; Output : Ada.Strings.Unbounded.Unbounded_String; Chdir : Ada.Strings.Unbounded.Unbounded_String; Label : String (1 .. 16) := (others => ' '); begin loop case Getopt ("h u v l: x: t: p: c: config: d: r: update help xml: timeout:") is when ASCII.NUL => exit; when 'c' => declare Name : constant String := Parameter; begin Test_Properties.Load_Properties (Name); Default_Timeout := Get_Test_Timeout ("default"); exception when Ada.IO_Exceptions.Name_Error => Ada.Text_IO.Put_Line ("Cannot find configuration file: " & Name); Ada.Command_Line.Set_Exit_Status (2); return; end; when 'd' => Chdir := To_Unbounded_String (Parameter); when 'l' => if Parameter'Length > Label'Length then Label := Parameter (Parameter'First .. Parameter'First + Label'Length - 1); else Label := (others => ' '); Label (Label'First .. Label'First + Parameter'Length - 1) := Parameter; end if; when 'u' => Update_Test_Files := True; when 't' => begin Default_Timeout := Duration'Value (Parameter); exception when Constraint_Error => Ada.Text_IO.Put_Line ("Invalid timeout: " & Parameter); Ada.Command_Line.Set_Exit_Status (2); return; end; when 'r' => Enabled_Test := To_Unbounded_String (Parameter); when 'p' => Harness_Prefix := To_Unbounded_String (Parameter & " "); when 'v' => Verbose_Flag := True; when 'x' => XML := True; Output := To_Unbounded_String (Parameter); when others => Help; return; end case; end loop; -- Initialization is optional. Get the log configuration by reading the property -- file 'samples/log4j.properties'. The 'log.util' logger will use a DEBUG level -- and write the message in 'result.log'. Util.Log.Loggers.Initialize (Test_Properties); Initialize (Test_Properties); if Length (Chdir) /= 0 then begin Ada.Directories.Set_Directory (To_String (Chdir)); exception when Ada.IO_Exceptions.Name_Error => Put_Line ("Invalid directory " & To_String (Chdir)); Ada.Command_Line.Set_Exit_Status (1); return; end; end if; declare procedure Runner is new Util.XUnit.Harness (Suite); S : Util.Measures.Stamp; begin Util.Measures.Set_Current (Perf'Unchecked_Access); Runner (To_String (Output), XML, (if (for all C of Label => C = ' ') then "" else Label), Result); Util.Measures.Report (Perf, S, "Testsuite execution"); Util.Measures.Write (Perf, "Test measures", Name); end; Finish (Result); -- Program exit status reflects the testsuite result if Result /= Util.XUnit.Success then Ada.Command_Line.Set_Exit_Status (1); else Ada.Command_Line.Set_Exit_Status (0); end if; exception when Invalid_Switch => Put_Line ("Invalid Switch " & Full_Switch); Help; return; when Invalid_Parameter => Put_Line ("No parameter for " & Full_Switch); Help; return; when E : others => Put_Line ("Exception: " & Ada.Exceptions.Exception_Name (E)); Put_Line ("Message: " & Ada.Exceptions.Exception_Message (E)); Put_Line ("Stacktrace:"); Put_Line (GNAT.Traceback.Symbolic.Symbolic_Traceback (E)); Ada.Command_Line.Set_Exit_Status (4); end Harness; end Util.Tests;
stcarrez/ada-keystore
Ada
1,951
ads
----------------------------------------------------------------------- -- keystore-gpg_tests -- Test AKT with GPG2 -- Copyright (C) 2019, 2020, 2021, 2023 Stephane Carrez -- Written by Stephane Carrez ([email protected]) -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. ----------------------------------------------------------------------- with Util.Tests; package Keystore.GPG_Tests is procedure Add_Tests (Suite : in Util.Tests.Access_Test_Suite); type Test is new Util.Tests.Test with null record; -- Test the akt keystore creation. procedure Test_Create (T : in out Test); -- Test the akt keystore creation with missing parameter. procedure Test_Create_Bad_Usage (T : in out Test); -- Test the akt keystore for several users each having their own GPG key. procedure Test_Create_Multi_User (T : in out Test); -- Test the akt info command on the GPG protected keystore. procedure Test_Info (T : in out Test); -- Test the akt password-add command to add a GPG key to a keystore. procedure Test_Add_Password (T : in out Test); -- Test the akt password-remove command to remove a GPG key from the keystore. procedure Test_Remove_Password (T : in out Test); -- Test update content with store command procedure Test_Update_File (T : in out Test); -- Test when gpg execution fails procedure Test_GPG_Error (T : in out Test); end Keystore.GPG_Tests;
johnperry-math/hac
Ada
10,259
adb
with HAC_Sys.UErrors; use HAC_Sys.UErrors; -- with Sequential_IO; -- with Text_IO; with Ada.Strings.Fixed; use Ada.Strings.Fixed; package body HAC_Sys.PCode is -- type ObjData is ( -- TabT, -- ATabt, -- BTabt, -- CodeT, -- ECountT, -- EntryTABt, -- FatT, -- FcTabt, -- STabT, -- TCountT, -- TaskTabT); -- -- type TArraysTab is array (1 .. AMax) of ATabEntry; -- type TBlockTab is array (1 .. BMax) of BTabEntry; -- type TObjCode is array (0 .. CDMax) of Order; -- type TEntryTAB is array (0 .. EntryMax) of Index; -- type TTskDefTab is array (0 .. TaskMax) of Index; -- type TIdTab is array (0 .. TMax) of TabEntry; -- type TStringTab is array (0 .. SMax) of Character; -- type TFloatPtTab is array (1 .. C2Max) of Float; -- type SMAObject (O : ObjData) is record -- case O is -- when ATabt => ArraysTab : TArraysTab; -- when BTabt => BlockTab : TBlockTab; -- when CodeT => ObjCode : TObjCode; -- when ECountT => ECount : Integer; -- when EntryTABt => EntryTAB : TEntryTAB; -- when FatT => FileIOTab : FilDescr; -- when FcTabt => FloatPtTab : TFloatPtTab; -- when STabT => StringTab : TStringTab; -- when TabT => IdTab : TIdTab; -- when TaskTabT => TskDefTab : TTskDefTab; -- when TCountT => TCount : Integer; -- end case; -- end record; -- package OAIO is new Sequential_IO(SMAObject); -- use OAIO; -- ** The next three functions are almost identical. -- -- * Emit store an object code for an instruction with no -- * arguments, -- * Emit1 store an object code for an instruction with one -- * argument (Y), and -- * Emit2 store an object code for an instruction with two -- * arguments. -- * -- * Originally it was implemented as three procedures. -- * -- * Emit and Emit1 call Emit2 with 0 for unused arguments -- * -- * Manuel * function For_END (for_BEGIN : Opcode) return Opcode is begin case for_BEGIN is when k_FOR_Forward_Begin => return k_FOR_Forward_End; when k_FOR_Reverse_Begin => return k_FOR_Reverse_End; when others => return for_BEGIN; end case; end For_END; procedure Emit_Instruction ( OC : in out Object_Code_Table; LC : in out Integer; D : Debug_Info; FCT : Opcode; a : Operand_1_Type; B : Operand_2_Type ) is begin if LC = OC'Last then Fatal (Object_Code); end if; OC (LC).F := FCT; OC (LC).X := a; OC (LC).Y := B; OC (LC).D := D; LC := LC + 1; end Emit_Instruction; procedure Patch_Addresses ( OC : in out Object_Code_Table; dummy_address : Operand_2_Type ) is LC0 : Integer := OC'First; use Defs; use type HAC_Integer; begin while LC0 < OC'Last loop if OC (LC0).F in Jump_Opcode and then OC (LC0).Y = dummy_address then OC (LC0).Y := HAC_Integer (OC'Last); end if; LC0 := LC0 + 1; end loop; end Patch_Addresses; procedure Patch_Addresses ( OC : in out Object_Code_Table; PT : Patch_Table; Top : in out Natural ) is begin for Instruction_Address of PT (PT'First .. Top) loop OC (Integer (Instruction_Address)).Y := Operand_2_Type (OC'Last); end loop; Top := 0; end Patch_Addresses; procedure Feed_Patch_Table ( PT : in out Patch_Table; Top : in out Natural; LC : Integer ) is begin if Top < PT'Last then Top := Top + 1; else Fatal (PATCHING); end if; PT (Top) := Operand_2_Type (LC); end Feed_Patch_Table; procedure Dump ( OC : Object_Code_Table; Str_Const : String; Flt_Const : Defs.Float_Constants_Table_Type; Text : Ada.Text_IO.File_Type ) is use Ada.Text_IO; package Opcode_IO is new Enumeration_IO (Opcode); package Code_Pos_IO is new Integer_IO (Natural); package Operand1_IO is new Integer_IO (Operand_1_Type); package Operand2_IO is new Integer_IO (Operand_2_Type); SF_C : SF_Code; SP_C : SP_Code; Old_Y1, Old_Y2, Old_Y3, Old_Y4 : Operand_2_Type := 0; -- function Padded_Opcode (o : Opcode) return String is s : String (1 .. Opcode'Width); begin Opcode_IO.Put (s, o); return s; end Padded_Opcode; use Defs; use type Operand_2_Type; begin Put_Line (Text, "Position : Opcode " & (Opcode'Width - 7) * ' ' & "Lvl X " & "Addr/Val Y" & "; Approx. source location; Extra information"); Put_Line (Text, 90 * '-'); for i in OC'Range loop Code_Pos_IO.Put (Text, i); Put (Text, ": " & Padded_Opcode (OC (i).F)); Operand1_IO.Put (Text, OC (i).X, 5); Operand2_IO.Put (Text, OC (i).Y); Put (Text, "; "); Code_Pos_IO.Put (Text, OC (i).D.Line_Number); Put (Text, " " & Defs.To_String (OC (i).D.Full_Block_Id)); case OC (i).F is -- Extra information when k_Push_Float_Literal => Put (Text, "; " & HAC_Image (Flt_Const (Integer (OC (i).Y)))); when k_Variable_Initialization => Put (Text, "; " & Defs.Typen'Image (Defs.Typen'Val (OC (i).Y))); when k_Standard_Functions => SF_C := SF_Code'Val (OC (i).Y); Put (Text, "; " & SF_Code'Image (SF_C)); if SF_C = SF_Literal_to_VString then Put (Text, "; """ & Str_Const (Integer (Old_Y1) .. Integer (Old_Y1 + Old_Y2 - 1)) & '"'); end if; when k_File_I_O => SP_C := SP_Code'Val (OC (i).X); Put (Text, "; " & SP_Code'Image (SP_C)); case SP_C is when SP_Get .. SP_Get_Line => Put (Text, "; " & Defs.Typen'Image (Defs.Typen'Val (OC (i).Y))); when SP_Put .. SP_Put_Line => if Defs.Typen'Val (OC (i).Y) = Defs.String_Literals then Put (Text, "; """ & Str_Const (Integer (Old_Y3) .. Integer (Old_Y3 + Old_Y4 - 1)) & '"'); end if; when others => null; end case; when k_FOR_Release_Stack_After_End => Put (Text, "; after END LOOP of a FOR loop"); when others => null; end case; New_Line (Text); Old_Y4 := Old_Y3; Old_Y3 := Old_Y2; Old_Y2 := Old_Y1; Old_Y1 := OC (i).Y; end loop; end Dump; -------------------------------------------------------------SaveOBJ---- procedure SaveOBJ (FileName : String) is -- ObjFile: OAIO.File_Type; -- Buffer: SMAObject; begin -- Create( ObjFile, name => FileName & ".Obj"); -- -- FOR I IN 1.. AMax LOOP -- Buffer.ArraysTab(I) := ArraysTab(I); -- END LOOP; -- Write(ObjFile, Buffer); -- -- FOR I IN 1.. BMax LOOP -- Buffer.BlockTab(I) := BlockTab(I); -- END LOOP; -- Write(ObjFile, Buffer); -- -- FOR I IN 0.. CDMax LOOP -- Buffer.ObjCode(I) := ObjCode(I); -- END LOOP; -- Write(ObjFile, Buffer); -- -- Buffer.ECount := ECount; -- Write(ObjFile, Buffer); -- -- FOR I IN 0.. EntryMax LOOP -- Buffer.EntryTAB(I) := EntryTAB(I); -- END LOOP; -- Write(ObjFile, Buffer); -- -- --{Buffer.FileIOTab := FileIOTab;} --{ Error assigning file } -- -- FOR I IN 1.. C2Max LOOP -- Buffer.FloatPtTab(I) := FloatPtTab(I); -- END LOOP; -- Write(ObjFile, Buffer); -- -- FOR I IN 0.. SMax LOOP -- Buffer.StringTab(I) := StringTab(I); -- END LOOP; -- Write(ObjFile, Buffer); -- -- FOR I IN 0.. TMax LOOP -- Buffer.IdTab(I) := IdTab(I); -- END LOOP; -- Write(ObjFile, Buffer); -- -- FOR I IN 0.. TaskMax LOOP -- Buffer.TskDefTab(I) := TskDefTab(I); -- END LOOP; -- Write(ObjFile, Buffer); -- -- Buffer.TCount := TCount; -- Write(ObjFile, Buffer); -- -- Close(ObjFile); null; -- will be streamed... end SaveOBJ; ----------------------------------------------------------RestoreOBJ----} procedure RestoreOBJ (FileName : String) is -- ObjFile: OAIO.File_Type; -- Buffer: SMAObject; begin -- BEGIN -- Open(ObjFile, in_file, FileName & ".Obj"); -- EXCEPTION -- when others=> -- IF qDebug THEN -- Text_IO.Put_Line("Cannot find file : " & FileName & ".Obj"); -- END IF; -- raise Failure_1_0; -- END; -- -- Read(ObjFile, Buffer); -- FOR I IN 1.. AMax LOOP -- ArraysTab(I) := Buffer.ArraysTab(I); -- END LOOP; -- -- Read(ObjFile, Buffer); -- FOR I IN 1.. BMax LOOP -- BlockTab(I) := Buffer.BlockTab(I); -- END LOOP; -- -- Read(ObjFile, Buffer); -- FOR I IN 0.. CDMax LOOP -- ObjCode(I) := Buffer.ObjCode(I); -- END LOOP; -- -- Read(ObjFile, Buffer); -- ECount := Buffer.ECount; -- -- Read(ObjFile, Buffer); -- FOR I IN 0.. EntryMax LOOP -- EntryTAB(I) := Buffer.EntryTAB(I); -- END LOOP; -- -- Read(ObjFile, Buffer); -- --{FileIOTab := Buffer.FileIOTab;} --{ Error assigning file } -- Read(ObjFile, Buffer); -- FOR I IN 1.. C2Max LOOP -- FloatPtTab(I) := Buffer.FloatPtTab(I); -- END LOOP; -- -- Read(ObjFile, Buffer); -- FOR I IN 0.. SMax LOOP -- StringTab(I) := Buffer.StringTab(I); -- END LOOP; -- -- Read(ObjFile, Buffer); -- FOR I IN 0.. TMax LOOP -- IdTab(I) := Buffer.IdTab(I); -- END LOOP; -- -- Read(ObjFile, Buffer); -- FOR I IN 0.. TaskMax LOOP -- TskDefTab(I) := Buffer.TskDefTab(I); -- END LOOP; -- -- Read(ObjFile, Buffer); -- TCount := Buffer.TCount; -- -- Close(ObjFile); null; -- will be streamed... end RestoreOBJ; end HAC_Sys.PCode;
reznikmm/matreshka
Ada
3,953
ads
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- Open Document Toolkit -- -- -- -- Runtime Library Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2014, Vadim Godunko <[email protected]> -- -- All rights reserved. -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions -- -- are met: -- -- -- -- * Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- -- -- * Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in the -- -- documentation and/or other materials provided with the distribution. -- -- -- -- * Neither the name of the Vadim Godunko, IE nor the names of its -- -- contributors may be used to endorse or promote products derived from -- -- this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -- -- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED -- -- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -- -- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -- -- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -- -- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -- -- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- -- ------------------------------------------------------------------------------ -- $Revision$ $Date$ ------------------------------------------------------------------------------ with ODF.DOM.Form_Name_Attributes; package Matreshka.ODF_Form.Name_Attributes is type Form_Name_Attribute_Node is new Matreshka.ODF_Form.Abstract_Form_Attribute_Node and ODF.DOM.Form_Name_Attributes.ODF_Form_Name_Attribute with null record; overriding function Create (Parameters : not null access Matreshka.DOM_Attributes.Attribute_L2_Parameters) return Form_Name_Attribute_Node; overriding function Get_Local_Name (Self : not null access constant Form_Name_Attribute_Node) return League.Strings.Universal_String; end Matreshka.ODF_Form.Name_Attributes;
reznikmm/matreshka
Ada
3,704
ads
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- Open Document Toolkit -- -- -- -- Runtime Library Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2014, Vadim Godunko <[email protected]> -- -- All rights reserved. -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions -- -- are met: -- -- -- -- * Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- -- -- * Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in the -- -- documentation and/or other materials provided with the distribution. -- -- -- -- * Neither the name of the Vadim Godunko, IE nor the names of its -- -- contributors may be used to endorse or promote products derived from -- -- this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -- -- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED -- -- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -- -- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -- -- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -- -- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -- -- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- -- ------------------------------------------------------------------------------ -- $Revision$ $Date$ ------------------------------------------------------------------------------ with XML.DOM.Attributes; package ODF.DOM.Db_Media_Type_Attributes is pragma Preelaborate; type ODF_Db_Media_Type_Attribute is limited interface and XML.DOM.Attributes.DOM_Attribute; type ODF_Db_Media_Type_Attribute_Access is access all ODF_Db_Media_Type_Attribute'Class with Storage_Size => 0; end ODF.DOM.Db_Media_Type_Attributes;
Fabien-Chouteau/AGATE
Ada
2,480
ads
------------------------------------------------------------------------------ -- -- -- Copyright (C) 2017-2018, Fabien Chouteau -- -- -- -- 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. -- -- -- ------------------------------------------------------------------------------ private package AGATE.Scheduler.Context_Switch is procedure Switch; end AGATE.Scheduler.Context_Switch;
Gabriel-Degret/adalib
Ada
6,489
ads
-- Standard Ada library specification -- Copyright (c) 2003-2018 Maxim Reznik <[email protected]> -- Copyright (c) 2004-2016 AXE Consultants -- Copyright (c) 2004, 2005, 2006 Ada-Europe -- Copyright (c) 2000 The MITRE Corporation, Inc. -- Copyright (c) 1992, 1993, 1994, 1995 Intermetrics, Inc. -- SPDX-License-Identifier: BSD-3-Clause and LicenseRef-AdaReferenceManual --------------------------------------------------------------------------- package Interfaces.C is pragma Pure(C); -- Declarations based on C's <limits.h> CHAR_BIT : constant := implementation_defined; -- typically 8 SCHAR_MIN : constant := implementation_defined; -- typically -128 SCHAR_MAX : constant := implementation_defined; -- typically 127 UCHAR_MAX : constant := implementation_defined; -- typically 255 -- Signed and Unsigned Integers type int is range implementation_defined .. implementation_defined; type short is range implementation_defined .. implementation_defined; type long is range implementation_defined .. implementation_defined; type signed_char is range SCHAR_MIN .. SCHAR_MAX; for signed_char'Size use CHAR_BIT; type unsigned is mod implementation_defined; type unsigned_short is mod implementation_defined; type unsigned_long is mod implementation_defined; type unsigned_char is mod (UCHAR_MAX+1); for unsigned_char'Size use CHAR_BIT; subtype plain_char is unsigned_char; -- implementation_defined; type ptrdiff_t is range implementation_defined .. implementation_defined; type size_t is mod implementation_defined; -- Floating Point type C_float is digits implementation_defined; type double is digits implementation_defined; type long_double is digits implementation_defined; -- Characters and Strings type char is ('x'); -- implementation_defined character type; nul : constant char := implementation_defined; function To_C (Item : in Character) return char; function To_Ada (Item : in char) return Character; type char_array is array (size_t range <>) of aliased char; pragma Pack (char_array); for char_array'Component_Size use CHAR_BIT; function Is_Nul_Terminated (Item : in char_array) return Boolean; function To_C (Item : in String; Append_Nul : in Boolean := True) return char_array; function To_Ada (Item : in char_array; Trim_Nul : in Boolean := True) return String; procedure To_C (Item : in String; Target : out char_array; Count : out size_t; Append_Nul : in Boolean := True); procedure To_Ada (Item : in char_array; Target : out String; Count : out Natural; Trim_Nul : in Boolean := True); -- Wide Character and Wide String type wchar_t is (' '); -- implementation_defined char type; wide_nul : constant wchar_t := implementation_defined; function To_C (Item : in Wide_Character) return wchar_t; function To_Ada (Item : in wchar_t ) return Wide_Character; type wchar_array is array (size_t range <>) of aliased wchar_t; pragma Pack (wchar_array); function Is_Nul_Terminated (Item : in wchar_array) return Boolean; function To_C (Item : in Wide_String; Append_Nul : in Boolean := True) return wchar_array; function To_Ada (Item : in wchar_array; Trim_Nul : in Boolean := True) return Wide_String; procedure To_C (Item : in Wide_String; Target : out wchar_array; Count : out size_t; Append_Nul : in Boolean := True); procedure To_Ada (Item : in wchar_array; Target : out Wide_String; Count : out Natural; Trim_Nul : in Boolean := True); -- ISO/IEC 10646:2003 compatible types defined by ISO/IEC TR 19769:2004. type char16_t is ('x'); -- implementation_defined character type char16_nul : constant char16_t := implementation_defined; function To_C (Item : in Wide_Character) return char16_t; function To_Ada (Item : in char16_t) return Wide_Character; type char16_array is array (size_t range <>) of aliased char16_t; pragma Pack (char16_array); function Is_Nul_Terminated (Item : in char16_array) return Boolean; function To_C (Item : in Wide_String; Append_Nul : in Boolean := True) return char16_array; function To_Ada (Item : in char16_array; Trim_Nul : in Boolean := True) return Wide_String; procedure To_C (Item : in Wide_String; Target : out char16_array; Count : out size_t; Append_Nul : in Boolean := True); procedure To_Ada (Item : in char16_array; Target : out Wide_String; Count : out Natural; Trim_Nul : in Boolean := True); type char32_t is ('x'); -- implementation_defined character type char32_nul : constant char32_t := implementation_defined; function To_C (Item : in Wide_Wide_Character) return char32_t; function To_Ada (Item : in char32_t) return Wide_Wide_Character; type char32_array is array (size_t range <>) of aliased char32_t; pragma Pack (char32_array); function Is_Nul_Terminated (Item : in char32_array) return Boolean; function To_C (Item : in Wide_Wide_String; Append_Nul : in Boolean := True) return char32_array; function To_Ada (Item : in char32_array; Trim_Nul : in Boolean := True) return Wide_Wide_String; procedure To_C (Item : in Wide_Wide_String; Target : out char32_array; Count : out size_t; Append_Nul : in Boolean := True); procedure To_Ada (Item : in char32_array; Target : out Wide_Wide_String; Count : out Natural; Trim_Nul : in Boolean := True); Terminator_Error : exception; end Interfaces.C;
charlie5/cBound
Ada
1,968
ads
-- This file is generated by SWIG. Please do not modify by hand. -- with Interfaces; with Interfaces.C; with Interfaces.C.Pointers; package xcb.xcb_create_notify_event_t is -- Item -- type Item is record response_type : aliased Interfaces.Unsigned_8; pad0 : aliased Interfaces.Unsigned_8; sequence : aliased Interfaces.Unsigned_16; parent : aliased xcb.xcb_window_t; window : aliased xcb.xcb_window_t; x : aliased Interfaces.Integer_16; y : aliased Interfaces.Integer_16; width : aliased Interfaces.Unsigned_16; height : aliased Interfaces.Unsigned_16; border_width : aliased Interfaces.Unsigned_16; override_redirect : aliased Interfaces.Unsigned_8; pad1 : aliased Interfaces.Unsigned_8; end record; -- Item_Array -- type Item_Array is array (Interfaces.C.size_t range <>) of aliased xcb.xcb_create_notify_event_t .Item; -- Pointer -- package C_Pointers is new Interfaces.C.Pointers (Index => Interfaces.C.size_t, Element => xcb.xcb_create_notify_event_t.Item, Element_Array => xcb.xcb_create_notify_event_t.Item_Array, Default_Terminator => (others => <>)); subtype Pointer is C_Pointers.Pointer; -- Pointer_Array -- type Pointer_Array is array (Interfaces.C.size_t range <>) of aliased xcb.xcb_create_notify_event_t .Pointer; -- Pointer_Pointer -- package C_Pointer_Pointers is new Interfaces.C.Pointers (Index => Interfaces.C.size_t, Element => xcb.xcb_create_notify_event_t.Pointer, Element_Array => xcb.xcb_create_notify_event_t.Pointer_Array, Default_Terminator => null); subtype Pointer_Pointer is C_Pointer_Pointers.Pointer; end xcb.xcb_create_notify_event_t;
reznikmm/matreshka
Ada
6,938
adb
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- Open Document Toolkit -- -- -- -- Runtime Library Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2014, Vadim Godunko <[email protected]> -- -- All rights reserved. -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions -- -- are met: -- -- -- -- * Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- -- -- * Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in the -- -- documentation and/or other materials provided with the distribution. -- -- -- -- * Neither the name of the Vadim Godunko, IE nor the names of its -- -- contributors may be used to endorse or promote products derived from -- -- this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -- -- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED -- -- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -- -- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -- -- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -- -- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -- -- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- -- ------------------------------------------------------------------------------ -- $Revision$ $Date$ ------------------------------------------------------------------------------ with Matreshka.DOM_Documents; with Matreshka.ODF_String_Constants; with ODF.DOM.Iterators; with ODF.DOM.Visitors; package body Matreshka.ODF_Db.Filter_Statement_Elements is ------------ -- Create -- ------------ overriding function Create (Parameters : not null access Matreshka.DOM_Elements.Element_L2_Parameters) return Db_Filter_Statement_Element_Node is begin return Self : Db_Filter_Statement_Element_Node do Matreshka.ODF_Db.Constructors.Initialize (Self'Unchecked_Access, Parameters.Document, Matreshka.ODF_String_Constants.Db_Prefix); end return; end Create; ---------------- -- Enter_Node -- ---------------- overriding procedure Enter_Node (Self : not null access Db_Filter_Statement_Element_Node; Visitor : in out XML.DOM.Visitors.Abstract_Visitor'Class; Control : in out XML.DOM.Visitors.Traverse_Control) is begin if Visitor in ODF.DOM.Visitors.Abstract_ODF_Visitor'Class then ODF.DOM.Visitors.Abstract_ODF_Visitor'Class (Visitor).Enter_Db_Filter_Statement (ODF.DOM.Db_Filter_Statement_Elements.ODF_Db_Filter_Statement_Access (Self), Control); else Matreshka.DOM_Elements.Abstract_Element_Node (Self.all).Enter_Node (Visitor, Control); end if; end Enter_Node; -------------------- -- Get_Local_Name -- -------------------- overriding function Get_Local_Name (Self : not null access constant Db_Filter_Statement_Element_Node) return League.Strings.Universal_String is pragma Unreferenced (Self); begin return Matreshka.ODF_String_Constants.Filter_Statement_Element; end Get_Local_Name; ---------------- -- Leave_Node -- ---------------- overriding procedure Leave_Node (Self : not null access Db_Filter_Statement_Element_Node; Visitor : in out XML.DOM.Visitors.Abstract_Visitor'Class; Control : in out XML.DOM.Visitors.Traverse_Control) is begin if Visitor in ODF.DOM.Visitors.Abstract_ODF_Visitor'Class then ODF.DOM.Visitors.Abstract_ODF_Visitor'Class (Visitor).Leave_Db_Filter_Statement (ODF.DOM.Db_Filter_Statement_Elements.ODF_Db_Filter_Statement_Access (Self), Control); else Matreshka.DOM_Elements.Abstract_Element_Node (Self.all).Leave_Node (Visitor, Control); end if; end Leave_Node; ---------------- -- Visit_Node -- ---------------- overriding procedure Visit_Node (Self : not null access Db_Filter_Statement_Element_Node; Iterator : in out XML.DOM.Visitors.Abstract_Iterator'Class; Visitor : in out XML.DOM.Visitors.Abstract_Visitor'Class; Control : in out XML.DOM.Visitors.Traverse_Control) is begin if Iterator in ODF.DOM.Iterators.Abstract_ODF_Iterator'Class then ODF.DOM.Iterators.Abstract_ODF_Iterator'Class (Iterator).Visit_Db_Filter_Statement (Visitor, ODF.DOM.Db_Filter_Statement_Elements.ODF_Db_Filter_Statement_Access (Self), Control); else Matreshka.DOM_Elements.Abstract_Element_Node (Self.all).Visit_Node (Iterator, Visitor, Control); end if; end Visit_Node; begin Matreshka.DOM_Documents.Register_Element (Matreshka.ODF_String_Constants.Db_URI, Matreshka.ODF_String_Constants.Filter_Statement_Element, Db_Filter_Statement_Element_Node'Tag); end Matreshka.ODF_Db.Filter_Statement_Elements;
reznikmm/matreshka
Ada
6,841
adb
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- Open Document Toolkit -- -- -- -- Runtime Library Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2014, Vadim Godunko <[email protected]> -- -- All rights reserved. -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions -- -- are met: -- -- -- -- * Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- -- -- * Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in the -- -- documentation and/or other materials provided with the distribution. -- -- -- -- * Neither the name of the Vadim Godunko, IE nor the names of its -- -- contributors may be used to endorse or promote products derived from -- -- this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -- -- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED -- -- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -- -- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -- -- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -- -- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -- -- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- -- ------------------------------------------------------------------------------ -- $Revision$ $Date$ ------------------------------------------------------------------------------ with Matreshka.DOM_Documents; with Matreshka.ODF_String_Constants; with ODF.DOM.Iterators; with ODF.DOM.Visitors; package body Matreshka.ODF_Table.Movement_Elements is ------------ -- Create -- ------------ overriding function Create (Parameters : not null access Matreshka.DOM_Elements.Element_L2_Parameters) return Table_Movement_Element_Node is begin return Self : Table_Movement_Element_Node do Matreshka.ODF_Table.Constructors.Initialize (Self'Unchecked_Access, Parameters.Document, Matreshka.ODF_String_Constants.Table_Prefix); end return; end Create; ---------------- -- Enter_Node -- ---------------- overriding procedure Enter_Node (Self : not null access Table_Movement_Element_Node; Visitor : in out XML.DOM.Visitors.Abstract_Visitor'Class; Control : in out XML.DOM.Visitors.Traverse_Control) is begin if Visitor in ODF.DOM.Visitors.Abstract_ODF_Visitor'Class then ODF.DOM.Visitors.Abstract_ODF_Visitor'Class (Visitor).Enter_Table_Movement (ODF.DOM.Table_Movement_Elements.ODF_Table_Movement_Access (Self), Control); else Matreshka.DOM_Elements.Abstract_Element_Node (Self.all).Enter_Node (Visitor, Control); end if; end Enter_Node; -------------------- -- Get_Local_Name -- -------------------- overriding function Get_Local_Name (Self : not null access constant Table_Movement_Element_Node) return League.Strings.Universal_String is pragma Unreferenced (Self); begin return Matreshka.ODF_String_Constants.Movement_Element; end Get_Local_Name; ---------------- -- Leave_Node -- ---------------- overriding procedure Leave_Node (Self : not null access Table_Movement_Element_Node; Visitor : in out XML.DOM.Visitors.Abstract_Visitor'Class; Control : in out XML.DOM.Visitors.Traverse_Control) is begin if Visitor in ODF.DOM.Visitors.Abstract_ODF_Visitor'Class then ODF.DOM.Visitors.Abstract_ODF_Visitor'Class (Visitor).Leave_Table_Movement (ODF.DOM.Table_Movement_Elements.ODF_Table_Movement_Access (Self), Control); else Matreshka.DOM_Elements.Abstract_Element_Node (Self.all).Leave_Node (Visitor, Control); end if; end Leave_Node; ---------------- -- Visit_Node -- ---------------- overriding procedure Visit_Node (Self : not null access Table_Movement_Element_Node; Iterator : in out XML.DOM.Visitors.Abstract_Iterator'Class; Visitor : in out XML.DOM.Visitors.Abstract_Visitor'Class; Control : in out XML.DOM.Visitors.Traverse_Control) is begin if Iterator in ODF.DOM.Iterators.Abstract_ODF_Iterator'Class then ODF.DOM.Iterators.Abstract_ODF_Iterator'Class (Iterator).Visit_Table_Movement (Visitor, ODF.DOM.Table_Movement_Elements.ODF_Table_Movement_Access (Self), Control); else Matreshka.DOM_Elements.Abstract_Element_Node (Self.all).Visit_Node (Iterator, Visitor, Control); end if; end Visit_Node; begin Matreshka.DOM_Documents.Register_Element (Matreshka.ODF_String_Constants.Table_URI, Matreshka.ODF_String_Constants.Movement_Element, Table_Movement_Element_Node'Tag); end Matreshka.ODF_Table.Movement_Elements;
zhmu/ananas
Ada
428
adb
-- { dg-do compile } -- { dg-options "-gnatwa" } package body BIP_Exception is package body Constructors is function Initialize return T_C4_Scheduler is begin return T_C4_Scheduler'(T_Super with null record); end Initialize; end Constructors; overriding procedure V_Run (This : in T_C4_Scheduler) is pragma Unreferenced (This); begin null; end V_Run; end BIP_Exception;
stcarrez/dynamo
Ada
13,613
adb
------------------------------------------------------------------------------ -- -- -- ASIS-for-GNAT IMPLEMENTATION COMPONENTS -- -- -- -- A 4 G . G N A T _ I N T -- -- -- -- B o d y -- -- -- -- Copyright (C) 1995-2012, Free Software Foundation, Inc. -- -- -- -- ASIS-for-GNAT is free software; you can redistribute it and/or modify it -- -- under terms of the GNU General Public License as published by the Free -- -- Software Foundation; either version 2, or (at your option) any later -- -- version. ASIS-for-GNAT is distributed in the hope that it will be use- -- -- ful, but WITHOUT ANY WARRANTY; without even the implied warranty of MER- -- -- CHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General -- -- Public License for more details. You should have received a copy of the -- -- GNU General Public License distributed with ASIS-for-GNAT; see file -- -- COPYING. If not, write to the Free Software Foundation, 51 Franklin -- -- Street, Fifth Floor, Boston, MA 02110-1301, USA. -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- ASIS-for-GNAT was originally developed by the ASIS-for-GNAT team at the -- -- Software Engineering Laboratory of the Swiss Federal Institute of -- -- Technology (LGL-EPFL) in Lausanne, Switzerland, in cooperation with the -- -- Scientific Research Computer Center of Moscow State University (SRCC -- -- MSU), Russia, with funding partially provided by grants from the Swiss -- -- National Science Foundation and the Swiss Academy of Engineering -- -- Sciences. ASIS-for-GNAT is now maintained by AdaCore -- -- (http://www.adacore.com). -- -- -- ------------------------------------------------------------------------------ with Ada.Exceptions; with Ada.Strings.Fixed; use Ada.Strings.Fixed; with Ada.Text_IO; use Ada.Text_IO; with GNAT.Directory_Operations; use GNAT.Directory_Operations; with Asis.Errors; with Asis.Exceptions; use Asis.Exceptions; with Asis.Extensions; use Asis.Extensions; with A4G.A_Debug; use A4G.A_Debug; with A4G.A_Opt; use A4G.A_Opt; with A4G.A_Output; use A4G.A_Output; with A4G.Contt; use A4G.Contt; with A4G.Vcheck; use A4G.Vcheck; with Aspects; with Atree; with Csets; with Elists; with Fname; with Gnatvsn; with Lib; with Namet; with Nlists; with Opt; use Opt; with Repinfo; with Sem_Aux; with Sinput; with Stand; with Stringt; with Uintp; with Urealp; with Tree_IO; package body A4G.GNAT_Int is LT : String renames ASIS_Line_Terminator; Standard_GCC : constant String_Access := GNAT.OS_Lib.Locate_Exec_On_Path ("gcc"); ----------------- -- Create_Tree -- ----------------- procedure Create_Tree (Source_File : String_Access; Context : Context_Id; Is_Predefined : Boolean; Success : out Boolean) is begin if Is_Predefined then Compile (Source_File => Source_File, Args => (1 => GNAT_Flag), Success => Success, GCC => Gcc_To_Call (Context)); else Compile (Source_File => Source_File, Args => I_Options (Context), Success => Success, GCC => Gcc_To_Call (Context)); end if; exception when others => Raise_ASIS_Failed ("A4G.GNAT_Int.Create_Tree:" & LT & " check the path and environment settings for gcc!"); end Create_Tree; ------------- -- Execute -- ------------- function Execute (Program : String_Access; Args : Argument_List; Compiler_Out : String := ""; Display_Call : Boolean := A4G.A_Debug.Debug_Mode) return Boolean is Success : Boolean; Return_Code : Integer; Execute : String_Access := Program; begin if Execute = null then Execute := Standard_GCC; end if; if Display_Call then Put (Standard_Error, Execute.all); for J in Args'Range loop Put (Standard_Error, " "); Put (Standard_Error, Args (J).all); end loop; New_Line (Standard_Error); end if; if Execute = null then Ada.Exceptions.Raise_Exception (Program_Error'Identity, "A4G.GNAT_Int.Execute: Can not locate program to execute"); end if; if Compiler_Out /= "" then GNAT.OS_Lib.Spawn (Execute.all, Args, Compiler_Out, Success, Return_Code); Success := Return_Code = 0; else GNAT.OS_Lib.Spawn (Execute.all, Args, Success); end if; return Success; end Execute; ---------------------------------------------- -- General Interfaces between GNAT and ASIS -- ---------------------------------------------- function A_Time (T : Time_Stamp_Type) return Time is Year : Year_Number; Month : Month_Number; Day : Day_Number; Hours : Integer range 0 .. 23; Minutes : Integer range 0 .. 59; Seconds : Integer range 0 .. 59; Day_Time : Day_Duration; begin Split_Time_Stamp (TS => T, Year => Nat (Year), Month => Nat (Month), Day => Nat (Day), Hour => Nat (Hours), Minutes => Nat (Minutes), Seconds => Nat (Seconds)); Day_Time := Duration (Seconds + 60 * Minutes + 3600 * Hours); return Time_Of (Year, Month, Day, Day_Time); end A_Time; -------------------------------- -- Tree_In_With_Version_Check -- -------------------------------- procedure Tree_In_With_Version_Check (Desc : File_Descriptor; Cont : Context_Id; Success : out Boolean) is Cont_Mode : constant Context_Mode := Context_Processing_Mode (Cont); File_Closed : Boolean := False; ASIS_GNAT_V : constant String := Gnatvsn.Gnat_Version_String; First_A_Idx : Natural := ASIS_GNAT_V'First; Last_A_Idx : Natural; First_T_Idx : Natural; Last_T_Idx : Natural; begin Success := False; Tree_IO.Tree_Read_Initialize (Desc); Opt.Tree_Read; -- GNAT/ASIS version check first if Tree_ASIS_Version_Number /= Tree_IO.ASIS_Version_Number then Close (Desc, File_Closed); Ada.Exceptions.Raise_Exception (Program_Error'Identity, "Inconsistent versions of GNAT and ASIS"); end if; -- Check that ASIS Pro uses the tree created by GNAT Pro First_T_Idx := Tree_Version_String'First; if ASIS_GNAT_V (First_A_Idx .. First_A_Idx + 2) = "Pro" and then Tree_Version_String (First_T_Idx .. First_T_Idx + 2) /= "Pro" then Close (Desc, File_Closed); Ada.Exceptions.Raise_Exception (Program_Error'Identity, "ASIS Pro can be used with GNAT Pro only"); end if; if Strong_Version_Check then -- We check only the dates here! First_A_Idx := Index (Source => ASIS_GNAT_V, Pattern => "(") + 1; First_T_Idx := Index (Source => Tree_Version_String.all, Pattern => "(") + 1; Last_A_Idx := Index (Source => ASIS_GNAT_V, Pattern => ")") - 1; if Index (Source => ASIS_GNAT_V, Pattern => "-") /= 0 then Last_A_Idx := Index (Source => ASIS_GNAT_V, Pattern => "-") - 1; end if; Last_T_Idx := Index (Source => Tree_Version_String.all, Pattern => ")") - 1; if Index (Source => Tree_Version_String.all, Pattern => "-") /= 0 then Last_T_Idx := Index (Source => Tree_Version_String.all, Pattern => "-") - 1; end if; if ASIS_GNAT_V (First_A_Idx .. Last_A_Idx) /= Tree_Version_String (First_T_Idx .. Last_T_Idx) then Close (Desc, File_Closed); Ada.Exceptions.Raise_Exception (Program_Error'Identity, "Inconsistent versions of GNAT [" & Tree_Version_String.all & "] and ASIS [" & ASIS_GNAT_V & ']'); end if; end if; -- Check if we are in Ada 2012 mode and need aspects... -- if Opt.Ada_Version_Config = Ada_2012 then -- -- For now, reading aspects is protected by the debug '.A' flag -- Debug.Debug_Flag_Dot_AA := True; -- end if; if Operating_Mode /= Check_Semantics then if Cont_Mode = One_Tree then -- If in one-tree mode we can not read the only tree we have, -- there is no reason to continue, so raising an exception -- is the only choice: Close (Desc, File_Closed); -- We did not check File_Closed here, because the fact that the -- tree is not compile-only seems to be more important for ASIS Set_Error_Status (Status => Asis.Errors.Use_Error, Diagnosis => "Asis.Ada_Environments.Open:" & ASIS_Line_Terminator & "tree file " & Base_Name (A_Name_Buffer (1 .. A_Name_Len)) & " is not compile-only"); raise ASIS_Failed; elsif Cont_Mode = N_Trees or else Cont_Mode = All_Trees then -- no need to read the rest of this tree file, but -- we can continue even if we can not read some trees... ASIS_Warning (Message => "Asis.Ada_Environments.Open: " & ASIS_Line_Terminator & "tree file " & Base_Name (A_Name_Buffer (1 .. A_Name_Len)) & " is not compile-only, ignored", Error => Asis.Errors.Use_Error); end if; -- debug stuff... if (Debug_Flag_O or else Debug_Lib_Model or else Debug_Mode) and then Cont_Mode /= One_Tree and then Cont_Mode /= N_Trees then Put (Standard_Error, "The tree file "); Put (Standard_Error, Base_Name (A_Name_Buffer (1 .. A_Name_Len))); Put (Standard_Error, " is not compile-only"); New_Line (Standard_Error); end if; else Atree.Tree_Read; Elists.Tree_Read; Fname.Tree_Read; Lib.Tree_Read; Namet.Tree_Read; Nlists.Tree_Read; Sem_Aux.Tree_Read; Sinput.Tree_Read; Stand.Tree_Read; Stringt.Tree_Read; Uintp.Tree_Read; Urealp.Tree_Read; Repinfo.Tree_Read; Aspects.Tree_Read; Csets.Initialize; -- debug stuff... if Debug_Flag_O or else Debug_Lib_Model or else Debug_Mode then Put (Standard_Error, "The tree file "); Put (Standard_Error, Base_Name (A_Name_Buffer (1 .. A_Name_Len))); Put (Standard_Error, " is OK"); New_Line (Standard_Error); end if; Success := True; end if; Close (Desc, File_Closed); if not File_Closed then Raise_ASIS_Failed (Diagnosis => "Asis.Ada_Environments.Open: " & "Can not close tree file: " & Base_Name (A_Name_Buffer (1 .. A_Name_Len)) & ASIS_Line_Terminator & "disk is full or file may be used by other program", Stat => Asis.Errors.Data_Error); end if; exception when Tree_IO.Tree_Format_Error => Close (Desc, File_Closed); Ada.Exceptions.Raise_Exception (Program_Error'Identity, "Inconsistent versions of GNAT and ASIS"); end Tree_In_With_Version_Check; end A4G.GNAT_Int;